Fossil SCM

Add the --size argument to the sha3sum command.

drh 2017-02-26 16:30 trunk
Commit ccdafa2a93e7bcefa1b4d0ea7474f9ce84c690f2
1 file changed +14 -2
+14 -2
--- src/sha3.c
+++ src/sha3.c
@@ -366,11 +366,11 @@
366366
** in bits and should be one of 224, 256, 384, or 512. Or iSize
367367
** can be zero to use the default hash size of 224 bits.
368368
*/
369369
static void SHA3Init(SHA3Context *p, int iSize){
370370
memset(p, 0, sizeof(*p));
371
- if( iSize>=256 && iSize<=512 ){
371
+ if( iSize>=128 && iSize<=512 ){
372372
p->nRate = (1600 - ((iSize + 31)&~31)*2)/8;
373373
}else{
374374
p->nRate = 144;
375375
}
376376
#if SHA3_BYTEORDER==1234
@@ -500,11 +500,11 @@
500500
/*
501501
** Add the content of a blob to the incremental SHA3 checksum.
502502
*/
503503
void sha3sum_step_blob(Blob *p){
504504
assert( incrInit );
505
- SHA3Update(&incrCtx, blob_buffer(p), blob_size(p));
505
+ SHA3Update(&incrCtx, (unsigned char*)blob_buffer(p), blob_size(p));
506506
}
507507
508508
/*
509509
** Finish the incremental SHA3 checksum. Store the result in blob pOut
510510
** if pOut!=0. Also return a pointer to the result.
@@ -612,10 +612,12 @@
612612
**
613613
** --228 Compute a SHA3-228 hash (the default)
614614
** --256 Compute a SHA3-256 hash
615615
** --384 Compute a SHA3-384 hash
616616
** --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.
617619
*/
618620
void sha3sum_test(void){
619621
int i;
620622
Blob in;
621623
Blob cksum;
@@ -623,10 +625,20 @@
623625
624626
if( find_option("228",0,0)!=0 ) iSize = 228;
625627
else if( find_option("256",0,0)!=0 ) iSize = 256;
626628
else if( find_option("384",0,0)!=0 ) iSize = 384;
627629
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
+ }
628640
verify_all_options();
629641
630642
for(i=2; i<g.argc; i++){
631643
blob_init(&cksum, "************** not found ***************", -1);
632644
if( g.argv[i][0]=='-' && g.argv[i][1]==0 ){
633645
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button