Fossil

Check-in [ccdafa2a]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the --size argument to the sha3sum command.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ccdafa2a93e7bcefa1b4d0ea7474f9ce84c690f2
User & Date: drh 2017-02-26 16:30:44
Context
2017-02-27
14:46
The smallest SHA3 hash size is 224 bits, not 228 bits. check-in: 5ed8477b user: drh tags: trunk
13:07
Improvement to the way auxiliary tables are initially dropped on a rebuild. check-in: a31944e6 user: drh tags: fossil-2.0
2017-02-26
16:30
Add the --size argument to the sha3sum command. check-in: ccdafa2a user: drh tags: trunk
2017-02-25
20:33
Optimizations to the SHA3 algorithm. check-in: 493321d4 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/sha3.c.

   364    364   /*
   365    365   ** Initialize a new hash.  iSize determines the size of the hash
   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
   377    377     /* Known to be little-endian at compile-time. No-op */
   378    378   #elif SHA3_BYTEORDER==4321
................................................................................
   498    498   }
   499    499   
   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.
   511    511   **
   512    512   ** This resets the incremental checksum preparing for the next round
................................................................................
   610    610   **
   611    611   ** Options:
   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;
   622    624     int iSize = 224;
   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         blob_read_from_channel(&in, stdin, -1);
   634    646         sha3sum_blob(&in, iSize, &cksum);