Ignore:
Timestamp:
Jan 9, 2008, 10:49:15 PM (17 years ago)
Author:
katerina
Message:

Checksum functions modified to return length of file hashed. Fixes ticket #85 (GrowingLogfiles bug).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/cutest_sh_tiger0.c

    r137 r151  
    135135  char * expected;
    136136  char hashbuf[KEYBUF_SIZE];
     137  UINT64  length;
    137138
    138139  init();
     
    153154  /* same result as GnuPG 1.0.6 (gpg --load-extension tiger --print-md TIGER192)
    154155   */
    155   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
     156  length = TIGER_NOLIM;
     157  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, &length, 0, hashbuf, sizeof(hashbuf));
    156158  expected = "0E9321614C966A33608C2A15F156E0435CACFD1213B9F095";
    157159  CuAssertStrEquals(tc, expected, actual);
     
    160162  CuAssertTrue(tc, rval_open >= 0);
    161163
    162   actual = sh_tiger_generic_hash("cutest_foo", rval_open, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
     164  length = TIGER_NOLIM;
     165  actual = sh_tiger_generic_hash("cutest_foo", rval_open, &length, 0, hashbuf, sizeof(hashbuf));
    163166  expected = "0E9321614C966A33608C2A15F156E0435CACFD1213B9F095";
    164167  CuAssertStrEquals(tc, expected, actual);
     
    175178  /* same result as GNU md5sum
    176179   */
    177   actual = sh_tiger_generic_hash("cutest_foo", rval_open, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
     180  length = TIGER_NOLIM;
     181  actual = sh_tiger_generic_hash("cutest_foo", rval_open, &length, 0, hashbuf, sizeof(hashbuf));
    178182  expected = "AEEC4DDA496BCFBA691F4E8863BA84C00000000000000000";
    179183  CuAssertStrEquals(tc, expected, actual);
     
    190194  /* same result as gpg --print-md SHA1
    191195   */
    192   actual = sh_tiger_generic_hash("cutest_foo", rval_open, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
     196  length = TIGER_NOLIM;
     197  actual = sh_tiger_generic_hash("cutest_foo", rval_open, &length, 0, hashbuf, sizeof(hashbuf));
    193198  expected = "2FE65D1D995B8F8BC8B13F798C07E7E935A787ED00000000";
    194199  CuAssertStrEquals(tc, expected, actual);
     
    216221  /* same result as GnuPG 1.0.6 (gpg --load-extension tiger --print-md TIGER192)
    217222   */
    218   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
     223  length = TIGER_NOLIM;
     224  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, &length, 0, hashbuf, sizeof(hashbuf));
    219225  expected = "F987845A0EA784367BF9E4DB09014995810F27C99C891734";
    220226  CuAssertStrEquals(tc, expected, actual);
     
    239245  /* same result as GnuPG 1.0.6 (gpg --load-extension tiger --print-md TIGER192)
    240246   */
    241   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
     247  length = TIGER_NOLIM;
     248  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, &length, 0, hashbuf, sizeof(hashbuf));
    242249  expected = "75B98A7AE257A230189828A40792E30B4038D286479CC7B8";
    243250  CuAssertStrEquals(tc, expected, actual);
     
    258265  char * expected;
    259266  char hashbuf[KEYBUF_SIZE];
     267  UINT64  length;
    260268
    261269  char * teststring = "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham, proceedings of Fast Software Encryption 3, Cambridge, 1996.\n";
    262   int    testlen = strlen(teststring);
     270  size_t    testlen = strlen(teststring);
    263271
    264272  init();
     
    280288  /* same as GnuPG 1.0.6 (gpg --load-extension tiger --print-md TIGER192)
    281289   */
    282   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 0, 0, hashbuf, sizeof(hashbuf));
     290  length = 0;
     291  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, &length, 0, hashbuf, sizeof(hashbuf));
    283292  expected = "24F0130C63AC933216166E76B1BB925FF373DE2D49584E7A";
    284293  CuAssertStrEquals(tc, expected, actual);
    285 
    286   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, testlen, 0, hashbuf, sizeof(hashbuf));
     294  CuAssertTrue(tc, 0 == length);
     295
     296  length = testlen;
     297  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, &length, 0, hashbuf, sizeof(hashbuf));
    287298  expected = "75B98A7AE257A230189828A40792E30B4038D286479CC7B8";
    288299  CuAssertStrEquals(tc, expected, actual);
    289 
    290   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 2*testlen, 0, hashbuf, sizeof(hashbuf));
     300  CuAssertTrue(tc, testlen == length);
     301
     302  length = 2*testlen;
     303  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, &length, 0, hashbuf, sizeof(hashbuf));
    291304  expected = "B5B4FB97B01ADB58794D87A6A01B2368852FA764BD93AB90";
    292305  CuAssertStrEquals(tc, expected, actual);
    293 
    294   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
     306  CuAssertTrue(tc, 2*testlen == length);
     307
     308  length = TIGER_NOLIM;
     309  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, &length, 0, hashbuf, sizeof(hashbuf));
    295310  expected = "B5B4FB97B01ADB58794D87A6A01B2368852FA764BD93AB90";
    296311  CuAssertStrEquals(tc, expected, actual);
     312  CuAssertTrue(tc, 2*testlen == length);
    297313
    298314  fp = fopen("cutest_foo", "a");
     
    303319  CuAssertTrue(tc, result == 0);
    304320
    305   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, testlen, 0, hashbuf, sizeof(hashbuf));
     321  length = testlen;
     322  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, &length, 0, hashbuf, sizeof(hashbuf));
    306323  expected = "75B98A7AE257A230189828A40792E30B4038D286479CC7B8";
    307324  CuAssertStrEquals(tc, expected, actual);
    308 
    309   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 2*testlen, 0, hashbuf, sizeof(hashbuf));
     325  CuAssertTrue(tc, testlen == length);
     326
     327  length = 2*testlen;
     328  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, &length, 0, hashbuf, sizeof(hashbuf));
    310329  expected = "B5B4FB97B01ADB58794D87A6A01B2368852FA764BD93AB90";
    311330  CuAssertStrEquals(tc, expected, actual);
    312 
    313   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 3*testlen, 0, hashbuf, sizeof(hashbuf));
     331  CuAssertTrue(tc, 2*testlen == length);
     332
     333  length = 3*testlen;
     334  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, &length, 0, hashbuf, sizeof(hashbuf));
    314335  expected = "D0EE1A9956CAB22D84B51A5E0C093B724828C6A1F9CBDB7F";
    315336  CuAssertStrEquals(tc, expected, actual);
    316 
    317   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
     337  CuAssertTrue(tc, 3*testlen == length);
     338
     339  length = TIGER_NOLIM;
     340  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, &length, 0, hashbuf, sizeof(hashbuf));
    318341  expected = "D0EE1A9956CAB22D84B51A5E0C093B724828C6A1F9CBDB7F";
    319342  CuAssertStrEquals(tc, expected, actual);
    320 
    321   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 5, 0, hashbuf, sizeof(hashbuf));
     343  CuAssertTrue(tc, 3*testlen == length);
     344
     345  length = 5;
     346  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, &length, 0, hashbuf, sizeof(hashbuf));
    322347  expected = "9F00F599072300DD276ABB38C8EB6DEC37790C116F9D2BDF";
    323348  CuAssertStrEquals(tc, expected, actual);
     349  CuAssertTrue(tc, 5 == length);
    324350
    325351  /* same results as GNU md5sum */
     
    331357  CuAssertTrue(tc, rval_open >= 0);
    332358
    333   actual = sh_tiger_generic_hash("cutest_foo", rval_open, testlen, 0, hashbuf, sizeof(hashbuf));
     359  length = testlen;
     360  actual = sh_tiger_generic_hash("cutest_foo", rval_open, &length, 0, hashbuf, sizeof(hashbuf));
    334361  expected = "11E7E7EA486136273606BEE57C71F34B0000000000000000";
    335362  CuAssertStrEquals(tc, expected, actual);
    336 
    337   result = sl_rewind(rval_open);
    338   CuAssertTrue(tc, rval_open >= 0);
    339 
    340   actual = sh_tiger_generic_hash("cutest_foo", rval_open, 2*testlen, 0, hashbuf, sizeof(hashbuf));
     363  CuAssertTrue(tc, testlen == length);
     364
     365  result = sl_rewind(rval_open);
     366  CuAssertTrue(tc, rval_open >= 0);
     367
     368  length = 2*testlen;
     369  actual = sh_tiger_generic_hash("cutest_foo", rval_open, &length, 0, hashbuf, sizeof(hashbuf));
    341370  expected = "D49DAD474095D467E2E5EFCB2DC23A770000000000000000";
    342371  CuAssertStrEquals(tc, expected, actual);
    343 
    344   result = sl_rewind(rval_open);
    345   CuAssertTrue(tc, rval_open >= 0);
    346 
    347   actual = sh_tiger_generic_hash("cutest_foo", rval_open, 3*testlen, 0, hashbuf, sizeof(hashbuf));
     372  CuAssertTrue(tc, 2*testlen == length);
     373
     374  result = sl_rewind(rval_open);
     375  CuAssertTrue(tc, rval_open >= 0);
     376
     377  length = 3*testlen;
     378  actual = sh_tiger_generic_hash("cutest_foo", rval_open, &length, 0, hashbuf, sizeof(hashbuf));
    348379  expected = "00A1F1C5EDDCCFC430D3862FDA94593E0000000000000000";
    349380  CuAssertStrEquals(tc, expected, actual);
    350 
    351   result = sl_rewind(rval_open);
    352   CuAssertTrue(tc, rval_open >= 0);
    353 
    354   actual = sh_tiger_generic_hash("cutest_foo", rval_open, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
     381  CuAssertTrue(tc, 3*testlen == length);
     382
     383  result = sl_rewind(rval_open);
     384  CuAssertTrue(tc, rval_open >= 0);
     385
     386  length = TIGER_NOLIM;
     387  actual = sh_tiger_generic_hash("cutest_foo", rval_open, &length, 0, hashbuf, sizeof(hashbuf));
    355388  expected = "00A1F1C5EDDCCFC430D3862FDA94593E0000000000000000";
    356389  CuAssertStrEquals(tc, expected, actual);
     390  CuAssertTrue(tc, 3*testlen == length);
    357391
    358392  /* same result as gpg --print-md SHA1
     
    365399  CuAssertTrue(tc, rval_open >= 0);
    366400
    367   actual = sh_tiger_generic_hash("cutest_foo", rval_open, testlen, 0, hashbuf, sizeof(hashbuf));
     401  length = testlen;
     402  actual = sh_tiger_generic_hash("cutest_foo", rval_open, &length, 0, hashbuf, sizeof(hashbuf));
    368403  expected = "F37DB4344CCD140EE315179E9A27512FB4704F0F00000000";
    369404  CuAssertStrEquals(tc, expected, actual);
    370 
    371   result = sl_rewind(rval_open);
    372   CuAssertTrue(tc, rval_open >= 0);
    373 
    374   actual = sh_tiger_generic_hash("cutest_foo", rval_open, 2*testlen, 0, hashbuf, sizeof(hashbuf));
     405  CuAssertTrue(tc, testlen == length);
     406
     407  result = sl_rewind(rval_open);
     408  CuAssertTrue(tc, rval_open >= 0);
     409
     410  length = 2*testlen;
     411  actual = sh_tiger_generic_hash("cutest_foo", rval_open, &length, 0, hashbuf, sizeof(hashbuf));
    375412  expected = "D2AD5FC366452D81400BAC31F96269DEEF314BC200000000";
    376413  CuAssertStrEquals(tc, expected, actual);
    377 
    378   result = sl_rewind(rval_open);
    379   CuAssertTrue(tc, rval_open >= 0);
    380 
    381   actual = sh_tiger_generic_hash("cutest_foo", rval_open, 3*testlen, 0, hashbuf, sizeof(hashbuf));
     414  CuAssertTrue(tc, 2*testlen == length);
     415
     416  result = sl_rewind(rval_open);
     417  CuAssertTrue(tc, rval_open >= 0);
     418
     419  length = 3*testlen;
     420  actual = sh_tiger_generic_hash("cutest_foo", rval_open, &length, 0, hashbuf, sizeof(hashbuf));
    382421  expected = "FAA937EF3389C7E786EB0F1006D049D7AEA7B7B600000000";
    383422  CuAssertStrEquals(tc, expected, actual);
    384 
    385   result = sl_rewind(rval_open);
    386   CuAssertTrue(tc, rval_open >= 0);
    387 
    388   actual = sh_tiger_generic_hash("cutest_foo", rval_open, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
     423  CuAssertTrue(tc, 3*testlen == length);
     424
     425  result = sl_rewind(rval_open);
     426  CuAssertTrue(tc, rval_open >= 0);
     427
     428  length = TIGER_NOLIM;
     429  actual = sh_tiger_generic_hash("cutest_foo", rval_open, &length, 0, hashbuf, sizeof(hashbuf));
    389430  expected = "FAA937EF3389C7E786EB0F1006D049D7AEA7B7B600000000";
    390431  CuAssertStrEquals(tc, expected, actual);
     432  CuAssertTrue(tc, 3*testlen == length);
    391433
    392434  result = sl_close(rval_open);
Note: See TracChangeset for help on using the changeset viewer.