Ignore:
Timestamp:
Oct 25, 2007, 12:19:05 AM (17 years ago)
Author:
rainer
Message:

Reentrant checksum/hash functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/cutest_sh_tiger0.c

    r107 r133  
    6767  char * actual;
    6868  char * expected;
     69  char hashbuf[KEYBUF_SIZE];
    6970
    7071  input  = "";
    71   actual = sh_tiger_hash(input, TIGER_DATA, strlen(input));
     72  actual = sh_tiger_hash(input, TIGER_DATA, strlen(input), hashbuf, sizeof(hashbuf));
    7273  expected = "24F0130C63AC933216166E76B1BB925FF373DE2D49584E7A";
    7374  CuAssertStrEquals(tc, expected, actual);
    7475
    7576  input  = "abc";
    76   actual = sh_tiger_hash(input, TIGER_DATA, strlen(input));
     77  actual = sh_tiger_hash(input, TIGER_DATA, strlen(input), hashbuf, sizeof(hashbuf));
    7778  expected = "F258C1E88414AB2A527AB541FFC5B8BF935F7B951C132951";
    7879  CuAssertStrEquals(tc, expected, actual);
    7980 
    8081  input  = "Tiger";
    81   actual = sh_tiger_hash(input, TIGER_DATA, strlen(input));
     82  actual = sh_tiger_hash(input, TIGER_DATA, strlen(input), hashbuf, sizeof(hashbuf));
    8283  expected = "9F00F599072300DD276ABB38C8EB6DEC37790C116F9D2BDF";
    8384  CuAssertStrEquals(tc, expected, actual);
    8485 
    8586  input  = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-";
    86   actual = sh_tiger_hash(input, TIGER_DATA, strlen(input));
     87  actual = sh_tiger_hash(input, TIGER_DATA, strlen(input), hashbuf, sizeof(hashbuf));
    8788  expected = "87FB2A9083851CF7470D2CF810E6DF9EB586445034A5A386";
    8889  CuAssertStrEquals(tc, expected, actual);
    8990 
    9091  input  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ=abcdefghijklmnopqrstuvwxyz+0123456789";
    91   actual = sh_tiger_hash(input, TIGER_DATA, strlen(input));
     92  actual = sh_tiger_hash(input, TIGER_DATA, strlen(input), hashbuf, sizeof(hashbuf));
    9293  expected = "467DB80863EBCE488DF1CD1261655DE957896565975F9197";
    9394  CuAssertStrEquals(tc, expected, actual);
    9495 
    9596  input  = "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham";
    96   actual = sh_tiger_hash(input, TIGER_DATA, strlen(input));
     97  actual = sh_tiger_hash(input, TIGER_DATA, strlen(input), hashbuf, sizeof(hashbuf));
    9798  expected = "0C410A042968868A1671DA5A3FD29A725EC1E457D3CDB303";
    9899  CuAssertStrEquals(tc, expected, actual);
    99100 
    100101  input  = "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham, proceedings of Fast Software Encryption 3, Cambridge.";
    101   actual = sh_tiger_hash(input, TIGER_DATA, strlen(input));
     102  actual = sh_tiger_hash(input, TIGER_DATA, strlen(input), hashbuf, sizeof(hashbuf));
    102103  expected = "EBF591D5AFA655CE7F22894FF87F54AC89C811B6B0DA3193";
    103104  CuAssertStrEquals(tc, expected, actual);
    104105 
    105106  input  = "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham, proceedings of Fast Software Encryption 3, Cambridge, 1996.";
    106   actual = sh_tiger_hash(input, TIGER_DATA, strlen(input));
     107  actual = sh_tiger_hash(input, TIGER_DATA, strlen(input), hashbuf, sizeof(hashbuf));
    107108  expected = "3D9AEB03D1BD1A6357B2774DFD6D5B24DD68151D503974FC";
    108109  CuAssertStrEquals(tc, expected, actual);
    109110 
    110111  input  = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-";
    111   actual = sh_tiger_hash(input, TIGER_DATA, strlen(input));
     112  actual = sh_tiger_hash(input, TIGER_DATA, strlen(input), hashbuf, sizeof(hashbuf));
    112113  expected = "00B83EB4E53440C576AC6AAEE0A7485825FD15E70A59FFE4";
    113114  CuAssertStrEquals(tc, expected, actual);
     
    121122  char * actual;
    122123  char * expected;
     124  char hashbuf[KEYBUF_SIZE];
    123125
    124126  init();
     
    139141  /* same result as GnuPG 1.0.6 (gpg --load-extension tiger --print-md TIGER192)
    140142   */
    141   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, TIGER_NOLIM, 0);
     143  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
    142144  expected = "0E9321614C966A33608C2A15F156E0435CACFD1213B9F095";
    143145  CuAssertStrEquals(tc, expected, actual);
     
    145147  rval_open = sl_open_fastread ("cutest_foo", SL_YESPRIV);
    146148  CuAssertTrue(tc, rval_open >= 0);
    147   tiger_fd  = rval_open;
    148 
    149   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, TIGER_NOLIM, 0);
     149
     150  actual = sh_tiger_generic_hash("cutest_foo", rval_open, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
    150151  expected = "0E9321614C966A33608C2A15F156E0435CACFD1213B9F095";
    151152  CuAssertStrEquals(tc, expected, actual);
     
    159160  rval_open = sl_open_fastread ("cutest_foo", SL_YESPRIV);
    160161  CuAssertTrue(tc, rval_open >= 0);
    161   tiger_fd  = rval_open;
    162162
    163163  /* same result as GNU md5sum
    164164   */
    165   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, TIGER_NOLIM, 0);
     165  actual = sh_tiger_generic_hash("cutest_foo", rval_open, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
    166166  expected = "AEEC4DDA496BCFBA691F4E8863BA84C00000000000000000";
    167167  CuAssertStrEquals(tc, expected, actual);
     
    175175  rval_open = sl_open_fastread ("cutest_foo", SL_YESPRIV);
    176176  CuAssertTrue(tc, rval_open >= 0);
    177   tiger_fd  = rval_open;
    178177
    179178  /* same result as gpg --print-md SHA1
    180179   */
    181   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, TIGER_NOLIM, 0);
     180  actual = sh_tiger_generic_hash("cutest_foo", rval_open, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
    182181  expected = "2FE65D1D995B8F8BC8B13F798C07E7E935A787ED00000000";
    183182  CuAssertStrEquals(tc, expected, actual);
     
    205204  /* same result as GnuPG 1.0.6 (gpg --load-extension tiger --print-md TIGER192)
    206205   */
    207   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, TIGER_NOLIM, 0);
     206  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
    208207  expected = "F987845A0EA784367BF9E4DB09014995810F27C99C891734";
    209208  CuAssertStrEquals(tc, expected, actual);
     
    228227  /* same result as GnuPG 1.0.6 (gpg --load-extension tiger --print-md TIGER192)
    229228   */
    230   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, TIGER_NOLIM, 0);
     229  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
    231230  expected = "75B98A7AE257A230189828A40792E30B4038D286479CC7B8";
    232231  CuAssertStrEquals(tc, expected, actual);
     
    246245  char * actual;
    247246  char * expected;
     247  char hashbuf[KEYBUF_SIZE];
    248248
    249249  char * teststring = "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham, proceedings of Fast Software Encryption 3, Cambridge, 1996.\n";
     
    268268  /* same as GnuPG 1.0.6 (gpg --load-extension tiger --print-md TIGER192)
    269269   */
    270   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 0, 0);
     270  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 0, 0, hashbuf, sizeof(hashbuf));
    271271  expected = "24F0130C63AC933216166E76B1BB925FF373DE2D49584E7A";
    272272  CuAssertStrEquals(tc, expected, actual);
    273273
    274   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, testlen, 0);
     274  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, testlen, 0, hashbuf, sizeof(hashbuf));
    275275  expected = "75B98A7AE257A230189828A40792E30B4038D286479CC7B8";
    276276  CuAssertStrEquals(tc, expected, actual);
    277277
    278   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 2*testlen, 0);
     278  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 2*testlen, 0, hashbuf, sizeof(hashbuf));
    279279  expected = "B5B4FB97B01ADB58794D87A6A01B2368852FA764BD93AB90";
    280280  CuAssertStrEquals(tc, expected, actual);
    281281
    282   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, TIGER_NOLIM, 0);
     282  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
    283283  expected = "B5B4FB97B01ADB58794D87A6A01B2368852FA764BD93AB90";
    284284  CuAssertStrEquals(tc, expected, actual);
     
    291291  CuAssertTrue(tc, result == 0);
    292292
    293   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, testlen, 0);
     293  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, testlen, 0, hashbuf, sizeof(hashbuf));
    294294  expected = "75B98A7AE257A230189828A40792E30B4038D286479CC7B8";
    295295  CuAssertStrEquals(tc, expected, actual);
    296296
    297   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 2*testlen, 0);
     297  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 2*testlen, 0, hashbuf, sizeof(hashbuf));
    298298  expected = "B5B4FB97B01ADB58794D87A6A01B2368852FA764BD93AB90";
    299299  CuAssertStrEquals(tc, expected, actual);
    300300
    301   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 3*testlen, 0);
     301  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 3*testlen, 0, hashbuf, sizeof(hashbuf));
    302302  expected = "D0EE1A9956CAB22D84B51A5E0C093B724828C6A1F9CBDB7F";
    303303  CuAssertStrEquals(tc, expected, actual);
    304304
    305   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, TIGER_NOLIM, 0);
     305  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
    306306  expected = "D0EE1A9956CAB22D84B51A5E0C093B724828C6A1F9CBDB7F";
    307307  CuAssertStrEquals(tc, expected, actual);
    308308
    309   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 5, 0);
     309  actual = sh_tiger_generic_hash("cutest_foo", TIGER_FILE, 5, 0, hashbuf, sizeof(hashbuf));
    310310  expected = "9F00F599072300DD276ABB38C8EB6DEC37790C116F9D2BDF";
    311311  CuAssertStrEquals(tc, expected, actual);
     
    318318  rval_open = sl_open_fastread ("cutest_foo", SL_YESPRIV);
    319319  CuAssertTrue(tc, rval_open >= 0);
    320   tiger_fd  = rval_open;
    321 
    322   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, testlen, 0);
     320
     321  actual = sh_tiger_generic_hash("cutest_foo", rval_open, testlen, 0, hashbuf, sizeof(hashbuf));
    323322  expected = "11E7E7EA486136273606BEE57C71F34B0000000000000000";
    324323  CuAssertStrEquals(tc, expected, actual);
     
    327326  CuAssertTrue(tc, rval_open >= 0);
    328327
    329   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 2*testlen, 0);
     328  actual = sh_tiger_generic_hash("cutest_foo", rval_open, 2*testlen, 0, hashbuf, sizeof(hashbuf));
    330329  expected = "D49DAD474095D467E2E5EFCB2DC23A770000000000000000";
    331330  CuAssertStrEquals(tc, expected, actual);
     
    334333  CuAssertTrue(tc, rval_open >= 0);
    335334
    336   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 3*testlen, 0);
     335  actual = sh_tiger_generic_hash("cutest_foo", rval_open, 3*testlen, 0, hashbuf, sizeof(hashbuf));
    337336  expected = "00A1F1C5EDDCCFC430D3862FDA94593E0000000000000000";
    338337  CuAssertStrEquals(tc, expected, actual);
     
    341340  CuAssertTrue(tc, rval_open >= 0);
    342341
    343   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, TIGER_NOLIM, 0);
     342  actual = sh_tiger_generic_hash("cutest_foo", rval_open, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
    344343  expected = "00A1F1C5EDDCCFC430D3862FDA94593E0000000000000000";
    345344  CuAssertStrEquals(tc, expected, actual);
     
    354353  CuAssertTrue(tc, rval_open >= 0);
    355354
    356   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, testlen, 0);
     355  actual = sh_tiger_generic_hash("cutest_foo", rval_open, testlen, 0, hashbuf, sizeof(hashbuf));
    357356  expected = "F37DB4344CCD140EE315179E9A27512FB4704F0F00000000";
    358357  CuAssertStrEquals(tc, expected, actual);
     
    361360  CuAssertTrue(tc, rval_open >= 0);
    362361
    363   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 2*testlen, 0);
     362  actual = sh_tiger_generic_hash("cutest_foo", rval_open, 2*testlen, 0, hashbuf, sizeof(hashbuf));
    364363  expected = "D2AD5FC366452D81400BAC31F96269DEEF314BC200000000";
    365364  CuAssertStrEquals(tc, expected, actual);
     
    368367  CuAssertTrue(tc, rval_open >= 0);
    369368
    370   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, 3*testlen, 0);
     369  actual = sh_tiger_generic_hash("cutest_foo", rval_open, 3*testlen, 0, hashbuf, sizeof(hashbuf));
    371370  expected = "FAA937EF3389C7E786EB0F1006D049D7AEA7B7B600000000";
    372371  CuAssertStrEquals(tc, expected, actual);
     
    375374  CuAssertTrue(tc, rval_open >= 0);
    376375
    377   actual = sh_tiger_generic_hash("cutest_foo", TIGER_FD, TIGER_NOLIM, 0);
     376  actual = sh_tiger_generic_hash("cutest_foo", rval_open, TIGER_NOLIM, 0, hashbuf, sizeof(hashbuf));
    378377  expected = "FAA937EF3389C7E786EB0F1006D049D7AEA7B7B600000000";
    379378  CuAssertStrEquals(tc, expected, actual);
Note: See TracChangeset for help on using the changeset viewer.