| OLD | NEW |
| 1 /* | 1 /* |
| 2 * sha512.c - implementation of SHA256, SHA384 and SHA512 | 2 * sha512.c - implementation of SHA256, SHA384 and SHA512 |
| 3 * | 3 * |
| 4 * ***** BEGIN LICENSE BLOCK ***** | 4 * ***** BEGIN LICENSE BLOCK ***** |
| 5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 6 * | 6 * |
| 7 * The contents of this file are subject to the Mozilla Public License Version | 7 * The contents of this file are subject to the Mozilla Public License Version |
| 8 * 1.1 (the "License"); you may not use this file except in compliance with | 8 * 1.1 (the "License"); you may not use this file except in compliance with |
| 9 * the License. You may obtain a copy of the License at | 9 * the License. You may obtain a copy of the License at |
| 10 * http://www.mozilla.org/MPL/ | 10 * http://www.mozilla.org/MPL/ |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 BYTESWAP4(H[5]); | 464 BYTESWAP4(H[5]); |
| 465 BYTESWAP4(H[6]); | 465 BYTESWAP4(H[6]); |
| 466 BYTESWAP4(H[7]); | 466 BYTESWAP4(H[7]); |
| 467 #endif | 467 #endif |
| 468 padLen = PR_MIN(SHA256_LENGTH, maxDigestLen); | 468 padLen = PR_MIN(SHA256_LENGTH, maxDigestLen); |
| 469 memcpy(digest, H, padLen); | 469 memcpy(digest, H, padLen); |
| 470 if (digestLen) | 470 if (digestLen) |
| 471 *digestLen = padLen; | 471 *digestLen = padLen; |
| 472 } | 472 } |
| 473 | 473 |
| 474 void SHA256_Clone(SHA256Context *dest, SHA256Context *src) |
| 475 { |
| 476 memcpy(dest, src, sizeof *dest); |
| 477 } |
| 478 |
| 474 /* Comment out unused code, mostly the SHA384 and SHA512 implementations. */ | 479 /* Comment out unused code, mostly the SHA384 and SHA512 implementations. */ |
| 475 #if 0 | 480 #if 0 |
| 476 SECStatus | 481 SECStatus |
| 477 SHA256_HashBuf(unsigned char *dest, const unsigned char *src, | 482 SHA256_HashBuf(unsigned char *dest, const unsigned char *src, |
| 478 unsigned int src_length) | 483 unsigned int src_length) |
| 479 { | 484 { |
| 480 SHA256Context ctx; | 485 SHA256Context ctx; |
| 481 unsigned int outLen; | 486 unsigned int outLen; |
| 482 | 487 |
| 483 SHA256_Begin(&ctx); | 488 SHA256_Begin(&ctx); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 512 | 517 |
| 513 SHA256Context * | 518 SHA256Context * |
| 514 SHA256_Resurrect(unsigned char *space, void *arg) | 519 SHA256_Resurrect(unsigned char *space, void *arg) |
| 515 { | 520 { |
| 516 SHA256Context *ctx = SHA256_NewContext(); | 521 SHA256Context *ctx = SHA256_NewContext(); |
| 517 if (ctx) | 522 if (ctx) |
| 518 PORT_Memcpy(ctx, space, sizeof *ctx); | 523 PORT_Memcpy(ctx, space, sizeof *ctx); |
| 519 return ctx; | 524 return ctx; |
| 520 } | 525 } |
| 521 | 526 |
| 522 void SHA256_Clone(SHA256Context *dest, SHA256Context *src) | |
| 523 { | |
| 524 memcpy(dest, src, sizeof *dest); | |
| 525 } | |
| 526 | |
| 527 | |
| 528 /* ======= SHA512 and SHA384 common constants and defines ================= */ | 527 /* ======= SHA512 and SHA384 common constants and defines ================= */ |
| 529 | 528 |
| 530 /* common #defines for SHA512 and SHA384 */ | 529 /* common #defines for SHA512 and SHA384 */ |
| 531 #if defined(HAVE_LONG_LONG) | 530 #if defined(HAVE_LONG_LONG) |
| 532 #define ROTR64(x,n) ((x >> n) | (x << (64 - n))) | 531 #define ROTR64(x,n) ((x >> n) | (x << (64 - n))) |
| 533 #define ROTL64(x,n) ((x << n) | (x >> (64 - n))) | 532 #define ROTL64(x,n) ((x << n) | (x >> (64 - n))) |
| 534 | 533 |
| 535 #define S0(x) (ROTR64(x,28) ^ ROTR64(x,34) ^ ROTR64(x,39)) | 534 #define S0(x) (ROTR64(x,28) ^ ROTR64(x,34) ^ ROTR64(x,39)) |
| 536 #define S1(x) (ROTR64(x,14) ^ ROTR64(x,18) ^ ROTR64(x,41)) | 535 #define S1(x) (ROTR64(x,14) ^ ROTR64(x,18) ^ ROTR64(x,41)) |
| 537 #define s0(x) (t1 = x, ROTR64(t1, 1) ^ ROTR64(t1, 8) ^ SHR(t1,7)) | 536 #define s0(x) (t1 = x, ROTR64(t1, 1) ^ ROTR64(t1, 8) ^ SHR(t1,7)) |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1382 } else { | 1381 } else { |
| 1383 while (i-- > 0) { | 1382 while (i-- > 0) { |
| 1384 time512(); | 1383 time512(); |
| 1385 } | 1384 } |
| 1386 printf("done\n"); | 1385 printf("done\n"); |
| 1387 } | 1386 } |
| 1388 return 0; | 1387 return 0; |
| 1389 } | 1388 } |
| 1390 | 1389 |
| 1391 #endif | 1390 #endif |
| OLD | NEW |