Changeset 2888
- Timestamp:
- Mar 2, 2012 11:20:59 PM (15 months ago)
- File:
-
- 1 edited
-
cpu/x86/pc/olpc/security.fth (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cpu/x86/pc/olpc/security.fth
r2865 r2888 194 194 /sig buffer: sig-buf 195 195 196 \ hex-decode decodes a hexadecimal signature string, storing it in 197 \ binary form at sig-buf. It returns the adr,len of the binary string. 198 199 : hex-decode ( hex$ -- true | sig$ false ) 200 sig-buf -rot ( adr hex$ ) 201 bounds ?do ( adr ) 202 i 2 push-hex $number pop-base if ( adr ) 203 2drop true unloop exit 204 then ( adr n ) 205 over c! 1+ ( adr' ) 206 2 +loop ( adr ) 207 sig-buf tuck - false ( sig$ false ) 196 h# 10e constant /key 197 /key buffer: key-buf 198 199 \ $hex-decode decodes a hexadecimal signature string, storing it in 200 \ binary form at adr, returning adr,len of the binary string and false. 201 \ It returns true if hex$ is too long for the binary buffer length 202 \ maxlen or if hex$ contains a non-hexadecimal character. 203 204 : $hex-decode ( hex$ adr maxlen -- true | binary$ false ) 205 2* third < if ( hex$ adr ) 206 3drop true exit ( -- true ) 207 then ( hex$ adr ) 208 dup 2swap ( adr adr hex$ ) 209 bounds ?do ( adr nextadr ) 210 i 2 push-hex $number pop-base if ( adr nextadr ) 211 2drop true unloop exit ( -- true ) 212 then ( adr nextadr n ) 213 over c! 1+ ( adr nextadr' ) 214 2 +loop ( adr nextadr ) 215 over - false ( binary$ false ) 208 216 ; 209 217 … … 231 239 bl left-parse-string 2drop ( rem$ ) \ Discard hash name 232 240 bl left-parse-string 2nip ( key$ ) \ Get key signature 233 /sig 2* min hex-decode if ( key$ ) 234 2drop true ( true ) 235 exit 236 then ( binary-key$ ) 237 false ( binary-key$ false ) 241 242 key-buf /key $hex-decode ( true | binary-key$ false ) 238 243 ; 239 244 … … 473 478 \ Check that the keyid matches our pubkey 474 479 bl left-parse-string ( line$' keyid$ ) 475 /sig 2* min hex-decode if( line$ )480 key-buf /key $hex-decode if ( line$ ) 476 481 2drop false exit 477 then ( line$ binary-key $ )482 then ( line$ binary-keyid$ ) 478 483 479 484 key-in-list? 0= if ( line$ ) 480 485 2drop false exit 481 486 then ( line$ ) 487 \ Now thiskey$ contains the full key$ that was matched by keyid$ 482 488 483 489 \ Check that the signature occupies the rest of the line … … 488 494 then ( sig$ ) 489 495 490 dup /sig 2* <> if ( sig$ ) 491 2drop false exit 492 then ( sig$ ) 493 494 hex-decode if ( ) 496 sig-buf /sig $hex-decode if ( ) 495 497 false exit 496 498 then ( binary-sig$ ) 497 499 500 dup /sig <> if ( binary-sig$ ) 501 2drop false exit 502 then ( binary-sig$ ) 503 498 504 \ Cryptographically verify the data against the signature 499 505 2>r 0 signed-data$ 2r> thiskey$ exp-hashname$ signature-bad? 0= 500 506 ; 501 502 h# 10e constant /key503 /key buffer: keybuf504 507 505 508 0 0 2value sig02-key$ … … 518 521 \ the first one 519 522 bl left-parse-string ( line$' pubkey$ ) 520 hex-decode if ( line$ ) 521 2drop false unloop exit 523 524 key-buf /key $hex-decode if ( line$ ) 525 2drop false unloop exit ( -- false ) 522 526 then ( line$ binary-key$ ) 523 527 524 i if ( line$ binary-key$ ) 525 dup /key <> if ( line$ binary-key$ ) 526 4drop false unloop exit 527 then ( line$ binary-key$ ) 528 tuck keybuf swap move ( line$ binary-keylen ) 529 keybuf swap ( line$ binary-key$' ) 530 else ( line$ binary-keyid$ ) 528 dup /key <> if ( line$ binary-keyid$ ) 529 \ If the length is shorter than a full key, it's a keyid 530 \ which we look for in our key list 531 531 key-in-list? 0= if ( line$ ) 532 532 2drop false unloop exit … … 545 545 bl left-parse-string ( line$ sig$) 546 546 547 dup /sig 2* <> if ( line$ sig$ ) 547 sig-buf /sig $hex-decode if ( line$ ) 548 2drop false unloop exit ( -- false ) 549 then ( line$ binary-sig$ ) 550 551 dup /sig <> if ( line$ binary-sig$ ) 548 552 4drop false unloop exit 549 then ( line sig$ ) 550 551 hex-decode if ( line$ ) 552 2drop false unloop exit 553 then ( line$ binary-sig$ ) 553 then ( line binary-sig$ ) 554 554 555 555 2>r ( line$' r: binary-sig$ ) … … 1348 1348 date-bad? if ." The RTC is not set correctly" cr exit then 1349 1349 time&date >iso8601$ " md" $add-tag 1350 ; 1351 1352 \ The following is for compatibility with the script fsverify.fth . 1353 \ fs-verify only needs h#20 bytes, that being the length of a sha256 hash 1354 \ in binary form, but we give it h#100 as that is the previous length of 1355 \ hex-decode's buffer. Since buffer: uses lazy allocation, we won't waste 1356 \ space unless compat-buf is actually used. 1357 1358 h# 100 constant /compat-buf \ Large enough for sha512 1359 /compat-buf buffer: compat-buf 1360 1361 : hex-decode ( hex$ -- true | binary$ false ) 1362 compat-buf /compat-buf $hex-decode 1350 1363 ; 1351 1364
Note: See TracChangeset
for help on using the changeset viewer.
