Fossil SCM
Add the --size argument to the sha3sum command.
Commit
ccdafa2a93e7bcefa1b4d0ea7474f9ce84c690f2
Parent
493321d44f314d3…
1 file changed
+14
-2
+14
-2
| --- src/sha3.c | ||
| +++ src/sha3.c | ||
| @@ -366,11 +366,11 @@ | ||
| 366 | 366 | ** in bits and should be one of 224, 256, 384, or 512. Or iSize |
| 367 | 367 | ** can be zero to use the default hash size of 224 bits. |
| 368 | 368 | */ |
| 369 | 369 | static void SHA3Init(SHA3Context *p, int iSize){ |
| 370 | 370 | memset(p, 0, sizeof(*p)); |
| 371 | - if( iSize>=256 && iSize<=512 ){ | |
| 371 | + if( iSize>=128 && iSize<=512 ){ | |
| 372 | 372 | p->nRate = (1600 - ((iSize + 31)&~31)*2)/8; |
| 373 | 373 | }else{ |
| 374 | 374 | p->nRate = 144; |
| 375 | 375 | } |
| 376 | 376 | #if SHA3_BYTEORDER==1234 |
| @@ -500,11 +500,11 @@ | ||
| 500 | 500 | /* |
| 501 | 501 | ** Add the content of a blob to the incremental SHA3 checksum. |
| 502 | 502 | */ |
| 503 | 503 | void sha3sum_step_blob(Blob *p){ |
| 504 | 504 | assert( incrInit ); |
| 505 | - SHA3Update(&incrCtx, blob_buffer(p), blob_size(p)); | |
| 505 | + SHA3Update(&incrCtx, (unsigned char*)blob_buffer(p), blob_size(p)); | |
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | /* |
| 509 | 509 | ** Finish the incremental SHA3 checksum. Store the result in blob pOut |
| 510 | 510 | ** if pOut!=0. Also return a pointer to the result. |
| @@ -612,10 +612,12 @@ | ||
| 612 | 612 | ** |
| 613 | 613 | ** --228 Compute a SHA3-228 hash (the default) |
| 614 | 614 | ** --256 Compute a SHA3-256 hash |
| 615 | 615 | ** --384 Compute a SHA3-384 hash |
| 616 | 616 | ** --512 Compute a SHA3-512 hash |
| 617 | +** --size N An N-bit hash. N must be a multiple of 32 between 128 | |
| 618 | +** and 512. | |
| 617 | 619 | */ |
| 618 | 620 | void sha3sum_test(void){ |
| 619 | 621 | int i; |
| 620 | 622 | Blob in; |
| 621 | 623 | Blob cksum; |
| @@ -623,10 +625,20 @@ | ||
| 623 | 625 | |
| 624 | 626 | if( find_option("228",0,0)!=0 ) iSize = 228; |
| 625 | 627 | else if( find_option("256",0,0)!=0 ) iSize = 256; |
| 626 | 628 | else if( find_option("384",0,0)!=0 ) iSize = 384; |
| 627 | 629 | else if( find_option("512",0,0)!=0 ) iSize = 512; |
| 630 | + else{ | |
| 631 | + const char *zN = find_option("size",0,1); | |
| 632 | + if( zN!=0 ){ | |
| 633 | + int n = atoi(zN); | |
| 634 | + if( n%32!=0 || n<128 || n>512 ){ | |
| 635 | + fossil_fatal("--size must be a multiple of 64 between 128 and 512"); | |
| 636 | + } | |
| 637 | + iSize = n; | |
| 638 | + } | |
| 639 | + } | |
| 628 | 640 | verify_all_options(); |
| 629 | 641 | |
| 630 | 642 | for(i=2; i<g.argc; i++){ |
| 631 | 643 | blob_init(&cksum, "************** not found ***************", -1); |
| 632 | 644 | if( g.argv[i][0]=='-' && g.argv[i][1]==0 ){ |
| 633 | 645 |
| --- src/sha3.c | |
| +++ src/sha3.c | |
| @@ -366,11 +366,11 @@ | |
| 366 | ** in bits and should be one of 224, 256, 384, or 512. Or iSize |
| 367 | ** can be zero to use the default hash size of 224 bits. |
| 368 | */ |
| 369 | static void SHA3Init(SHA3Context *p, int iSize){ |
| 370 | memset(p, 0, sizeof(*p)); |
| 371 | if( iSize>=256 && iSize<=512 ){ |
| 372 | p->nRate = (1600 - ((iSize + 31)&~31)*2)/8; |
| 373 | }else{ |
| 374 | p->nRate = 144; |
| 375 | } |
| 376 | #if SHA3_BYTEORDER==1234 |
| @@ -500,11 +500,11 @@ | |
| 500 | /* |
| 501 | ** Add the content of a blob to the incremental SHA3 checksum. |
| 502 | */ |
| 503 | void sha3sum_step_blob(Blob *p){ |
| 504 | assert( incrInit ); |
| 505 | SHA3Update(&incrCtx, blob_buffer(p), blob_size(p)); |
| 506 | } |
| 507 | |
| 508 | /* |
| 509 | ** Finish the incremental SHA3 checksum. Store the result in blob pOut |
| 510 | ** if pOut!=0. Also return a pointer to the result. |
| @@ -612,10 +612,12 @@ | |
| 612 | ** |
| 613 | ** --228 Compute a SHA3-228 hash (the default) |
| 614 | ** --256 Compute a SHA3-256 hash |
| 615 | ** --384 Compute a SHA3-384 hash |
| 616 | ** --512 Compute a SHA3-512 hash |
| 617 | */ |
| 618 | void sha3sum_test(void){ |
| 619 | int i; |
| 620 | Blob in; |
| 621 | Blob cksum; |
| @@ -623,10 +625,20 @@ | |
| 623 | |
| 624 | if( find_option("228",0,0)!=0 ) iSize = 228; |
| 625 | else if( find_option("256",0,0)!=0 ) iSize = 256; |
| 626 | else if( find_option("384",0,0)!=0 ) iSize = 384; |
| 627 | else if( find_option("512",0,0)!=0 ) iSize = 512; |
| 628 | verify_all_options(); |
| 629 | |
| 630 | for(i=2; i<g.argc; i++){ |
| 631 | blob_init(&cksum, "************** not found ***************", -1); |
| 632 | if( g.argv[i][0]=='-' && g.argv[i][1]==0 ){ |
| 633 |
| --- src/sha3.c | |
| +++ src/sha3.c | |
| @@ -366,11 +366,11 @@ | |
| 366 | ** in bits and should be one of 224, 256, 384, or 512. Or iSize |
| 367 | ** can be zero to use the default hash size of 224 bits. |
| 368 | */ |
| 369 | static void SHA3Init(SHA3Context *p, int iSize){ |
| 370 | memset(p, 0, sizeof(*p)); |
| 371 | if( iSize>=128 && iSize<=512 ){ |
| 372 | p->nRate = (1600 - ((iSize + 31)&~31)*2)/8; |
| 373 | }else{ |
| 374 | p->nRate = 144; |
| 375 | } |
| 376 | #if SHA3_BYTEORDER==1234 |
| @@ -500,11 +500,11 @@ | |
| 500 | /* |
| 501 | ** Add the content of a blob to the incremental SHA3 checksum. |
| 502 | */ |
| 503 | void sha3sum_step_blob(Blob *p){ |
| 504 | assert( incrInit ); |
| 505 | SHA3Update(&incrCtx, (unsigned char*)blob_buffer(p), blob_size(p)); |
| 506 | } |
| 507 | |
| 508 | /* |
| 509 | ** Finish the incremental SHA3 checksum. Store the result in blob pOut |
| 510 | ** if pOut!=0. Also return a pointer to the result. |
| @@ -612,10 +612,12 @@ | |
| 612 | ** |
| 613 | ** --228 Compute a SHA3-228 hash (the default) |
| 614 | ** --256 Compute a SHA3-256 hash |
| 615 | ** --384 Compute a SHA3-384 hash |
| 616 | ** --512 Compute a SHA3-512 hash |
| 617 | ** --size N An N-bit hash. N must be a multiple of 32 between 128 |
| 618 | ** and 512. |
| 619 | */ |
| 620 | void sha3sum_test(void){ |
| 621 | int i; |
| 622 | Blob in; |
| 623 | Blob cksum; |
| @@ -623,10 +625,20 @@ | |
| 625 | |
| 626 | if( find_option("228",0,0)!=0 ) iSize = 228; |
| 627 | else if( find_option("256",0,0)!=0 ) iSize = 256; |
| 628 | else if( find_option("384",0,0)!=0 ) iSize = 384; |
| 629 | else if( find_option("512",0,0)!=0 ) iSize = 512; |
| 630 | else{ |
| 631 | const char *zN = find_option("size",0,1); |
| 632 | if( zN!=0 ){ |
| 633 | int n = atoi(zN); |
| 634 | if( n%32!=0 || n<128 || n>512 ){ |
| 635 | fossil_fatal("--size must be a multiple of 64 between 128 and 512"); |
| 636 | } |
| 637 | iSize = n; |
| 638 | } |
| 639 | } |
| 640 | verify_all_options(); |
| 641 | |
| 642 | for(i=2; i<g.argc; i++){ |
| 643 | blob_init(&cksum, "************** not found ***************", -1); |
| 644 | if( g.argv[i][0]=='-' && g.argv[i][1]==0 ){ |
| 645 |