Chromium Code Reviews| 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 memcpy(dest, src, sizeof *dest); | |
| 476 } | |
|
davidben
2016/03/08 22:12:03
Nit: Probably this should be mirroring the origina
asanka
2016/03/10 16:48:09
Done. I blame 'git cl format' for this one, since
| |
| 477 | |
| 474 /* Comment out unused code, mostly the SHA384 and SHA512 implementations. */ | 478 /* Comment out unused code, mostly the SHA384 and SHA512 implementations. */ |
| 475 #if 0 | 479 #if 0 |
| 476 SECStatus | 480 SECStatus |
| 477 SHA256_HashBuf(unsigned char *dest, const unsigned char *src, | 481 SHA256_HashBuf(unsigned char *dest, const unsigned char *src, |
| 478 unsigned int src_length) | 482 unsigned int src_length) |
| 479 { | 483 { |
| 480 SHA256Context ctx; | 484 SHA256Context ctx; |
| 481 unsigned int outLen; | 485 unsigned int outLen; |
| 482 | 486 |
| 483 SHA256_Begin(&ctx); | 487 SHA256_Begin(&ctx); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 512 | 516 |
| 513 SHA256Context * | 517 SHA256Context * |
| 514 SHA256_Resurrect(unsigned char *space, void *arg) | 518 SHA256_Resurrect(unsigned char *space, void *arg) |
| 515 { | 519 { |
| 516 SHA256Context *ctx = SHA256_NewContext(); | 520 SHA256Context *ctx = SHA256_NewContext(); |
| 517 if (ctx) | 521 if (ctx) |
| 518 PORT_Memcpy(ctx, space, sizeof *ctx); | 522 PORT_Memcpy(ctx, space, sizeof *ctx); |
| 519 return ctx; | 523 return ctx; |
| 520 } | 524 } |
| 521 | 525 |
| 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 ================= */ | 526 /* ======= SHA512 and SHA384 common constants and defines ================= */ |
| 529 | 527 |
| 530 /* common #defines for SHA512 and SHA384 */ | 528 /* common #defines for SHA512 and SHA384 */ |
| 531 #if defined(HAVE_LONG_LONG) | 529 #if defined(HAVE_LONG_LONG) |
| 532 #define ROTR64(x,n) ((x >> n) | (x << (64 - n))) | 530 #define ROTR64(x,n) ((x >> n) | (x << (64 - n))) |
| 533 #define ROTL64(x,n) ((x << n) | (x >> (64 - n))) | 531 #define ROTL64(x,n) ((x << n) | (x >> (64 - n))) |
| 534 | 532 |
| 535 #define S0(x) (ROTR64(x,28) ^ ROTR64(x,34) ^ ROTR64(x,39)) | 533 #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)) | 534 #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)) | 535 #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 { | 1380 } else { |
| 1383 while (i-- > 0) { | 1381 while (i-- > 0) { |
| 1384 time512(); | 1382 time512(); |
| 1385 } | 1383 } |
| 1386 printf("done\n"); | 1384 printf("done\n"); |
| 1387 } | 1385 } |
| 1388 return 0; | 1386 return 0; |
| 1389 } | 1387 } |
| 1390 | 1388 |
| 1391 #endif | 1389 #endif |
| OLD | NEW |