Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: mozilla/security/nss/lib/freebl/sha512.c

Issue 10961060: Update NSS to NSS 3.14 Beta 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/nss/
Patch Set: Add the NSS snapshot timestamp to README.chromium and nss-checkout.sh Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mozilla/security/nss/lib/freebl/sechash.h ('k') | mozilla/security/nss/lib/freebl/sha_fast.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * sha512.c - implementation of SHA224, SHA256, SHA384 and SHA512 2 * sha512.c - implementation of SHA224, SHA256, SHA384 and SHA512
3 * 3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public 4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* $Id: sha512.c,v 1.21 2012/07/27 20:00:39 wtc%google.com Exp $ */ 7 /* $Id: sha512.c,v 1.21 2012/07/27 20:00:39 wtc%google.com Exp $ */
8 8
9 #ifdef FREEBL_NO_DEPEND 9 #ifdef FREEBL_NO_DEPEND
10 #include "stubs.h" 10 #include "stubs.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 SHA256Context * 149 SHA256Context *
150 SHA256_NewContext(void) 150 SHA256_NewContext(void)
151 { 151 {
152 SHA256Context *ctx = PORT_New(SHA256Context); 152 SHA256Context *ctx = PORT_New(SHA256Context);
153 return ctx; 153 return ctx;
154 } 154 }
155 155
156 void 156 void
157 SHA256_DestroyContext(SHA256Context *ctx, PRBool freeit) 157 SHA256_DestroyContext(SHA256Context *ctx, PRBool freeit)
158 { 158 {
159 memset(ctx, 0, sizeof *ctx);
159 if (freeit) { 160 if (freeit) {
160 PORT_ZFree(ctx, sizeof *ctx); 161 PORT_Free(ctx);
161 } 162 }
162 } 163 }
163 164
164 void 165 void
165 SHA256_Begin(SHA256Context *ctx) 166 SHA256_Begin(SHA256Context *ctx)
166 { 167 {
167 memset(ctx, 0, sizeof *ctx); 168 memset(ctx, 0, sizeof *ctx);
168 memcpy(H, H256, sizeof H256); 169 memcpy(H, H256, sizeof H256);
169 } 170 }
170 171
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 SECStatus 465 SECStatus
465 SHA256_HashBuf(unsigned char *dest, const unsigned char *src, 466 SHA256_HashBuf(unsigned char *dest, const unsigned char *src,
466 uint32 src_length) 467 uint32 src_length)
467 { 468 {
468 SHA256Context ctx; 469 SHA256Context ctx;
469 unsigned int outLen; 470 unsigned int outLen;
470 471
471 SHA256_Begin(&ctx); 472 SHA256_Begin(&ctx);
472 SHA256_Update(&ctx, src, src_length); 473 SHA256_Update(&ctx, src, src_length);
473 SHA256_End(&ctx, dest, &outLen, SHA256_LENGTH); 474 SHA256_End(&ctx, dest, &outLen, SHA256_LENGTH);
475 memset(&ctx, 0, sizeof ctx);
474 476
475 return SECSuccess; 477 return SECSuccess;
476 } 478 }
477 479
478 480
479 SECStatus 481 SECStatus
480 SHA256_Hash(unsigned char *dest, const char *src) 482 SHA256_Hash(unsigned char *dest, const char *src)
481 { 483 {
482 return SHA256_HashBuf(dest, (const unsigned char *)src, PORT_Strlen(src)); 484 return SHA256_HashBuf(dest, (const unsigned char *)src, PORT_Strlen(src));
483 } 485 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 SECStatus 559 SECStatus
558 SHA224_HashBuf(unsigned char *dest, const unsigned char *src, 560 SHA224_HashBuf(unsigned char *dest, const unsigned char *src,
559 uint32 src_length) 561 uint32 src_length)
560 { 562 {
561 SHA256Context ctx; 563 SHA256Context ctx;
562 unsigned int outLen; 564 unsigned int outLen;
563 565
564 SHA224_Begin(&ctx); 566 SHA224_Begin(&ctx);
565 SHA256_Update(&ctx, src, src_length); 567 SHA256_Update(&ctx, src, src_length);
566 SHA256_End(&ctx, dest, &outLen, SHA224_LENGTH); 568 SHA256_End(&ctx, dest, &outLen, SHA224_LENGTH);
569 memset(&ctx, 0, sizeof ctx);
567 570
568 return SECSuccess; 571 return SECSuccess;
569 } 572 }
570 573
571 SECStatus 574 SECStatus
572 SHA224_Hash(unsigned char *dest, const char *src) 575 SHA224_Hash(unsigned char *dest, const char *src)
573 { 576 {
574 return SHA224_HashBuf(dest, (const unsigned char *)src, PORT_Strlen(src)); 577 return SHA224_HashBuf(dest, (const unsigned char *)src, PORT_Strlen(src));
575 } 578 }
576 579
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 SHA512Context * 783 SHA512Context *
781 SHA512_NewContext(void) 784 SHA512_NewContext(void)
782 { 785 {
783 SHA512Context *ctx = PORT_New(SHA512Context); 786 SHA512Context *ctx = PORT_New(SHA512Context);
784 return ctx; 787 return ctx;
785 } 788 }
786 789
787 void 790 void
788 SHA512_DestroyContext(SHA512Context *ctx, PRBool freeit) 791 SHA512_DestroyContext(SHA512Context *ctx, PRBool freeit)
789 { 792 {
793 memset(ctx, 0, sizeof *ctx);
790 if (freeit) { 794 if (freeit) {
791 PORT_ZFree(ctx, sizeof *ctx); 795 PORT_Free(ctx);
792 } 796 }
793 } 797 }
794 798
795 void 799 void
796 SHA512_Begin(SHA512Context *ctx) 800 SHA512_Begin(SHA512Context *ctx)
797 { 801 {
798 memset(ctx, 0, sizeof *ctx); 802 memset(ctx, 0, sizeof *ctx);
799 memcpy(H, H512, sizeof H512); 803 memcpy(H, H512, sizeof H512);
800 } 804 }
801 805
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 SECStatus 1231 SECStatus
1228 SHA512_HashBuf(unsigned char *dest, const unsigned char *src, 1232 SHA512_HashBuf(unsigned char *dest, const unsigned char *src,
1229 uint32 src_length) 1233 uint32 src_length)
1230 { 1234 {
1231 SHA512Context ctx; 1235 SHA512Context ctx;
1232 unsigned int outLen; 1236 unsigned int outLen;
1233 1237
1234 SHA512_Begin(&ctx); 1238 SHA512_Begin(&ctx);
1235 SHA512_Update(&ctx, src, src_length); 1239 SHA512_Update(&ctx, src, src_length);
1236 SHA512_End(&ctx, dest, &outLen, SHA512_LENGTH); 1240 SHA512_End(&ctx, dest, &outLen, SHA512_LENGTH);
1241 memset(&ctx, 0, sizeof ctx);
1237 1242
1238 return SECSuccess; 1243 return SECSuccess;
1239 } 1244 }
1240 1245
1241 1246
1242 SECStatus 1247 SECStatus
1243 SHA512_Hash(unsigned char *dest, const char *src) 1248 SHA512_Hash(unsigned char *dest, const char *src)
1244 { 1249 {
1245 return SHA512_HashBuf(dest, (const unsigned char *)src, PORT_Strlen(src)); 1250 return SHA512_HashBuf(dest, (const unsigned char *)src, PORT_Strlen(src));
1246 } 1251 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 SECStatus 1339 SECStatus
1335 SHA384_HashBuf(unsigned char *dest, const unsigned char *src, 1340 SHA384_HashBuf(unsigned char *dest, const unsigned char *src,
1336 uint32 src_length) 1341 uint32 src_length)
1337 { 1342 {
1338 SHA512Context ctx; 1343 SHA512Context ctx;
1339 unsigned int outLen; 1344 unsigned int outLen;
1340 1345
1341 SHA384_Begin(&ctx); 1346 SHA384_Begin(&ctx);
1342 SHA512_Update(&ctx, src, src_length); 1347 SHA512_Update(&ctx, src, src_length);
1343 SHA512_End(&ctx, dest, &outLen, SHA384_LENGTH); 1348 SHA512_End(&ctx, dest, &outLen, SHA384_LENGTH);
1349 memset(&ctx, 0, sizeof ctx);
1344 1350
1345 return SECSuccess; 1351 return SECSuccess;
1346 } 1352 }
1347 1353
1348 SECStatus 1354 SECStatus
1349 SHA384_Hash(unsigned char *dest, const char *src) 1355 SHA384_Hash(unsigned char *dest, const char *src)
1350 { 1356 {
1351 return SHA384_HashBuf(dest, (const unsigned char *)src, PORT_Strlen(src)); 1357 return SHA384_HashBuf(dest, (const unsigned char *)src, PORT_Strlen(src));
1352 } 1358 }
1353 1359
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1509 } 1515 }
1510 printf("done\n"); 1516 printf("done\n");
1511 } 1517 }
1512 return 0; 1518 return 0;
1513 } 1519 }
1514 1520
1515 void *PORT_Alloc(size_t len) { return malloc(len); } 1521 void *PORT_Alloc(size_t len) { return malloc(len); }
1516 void PORT_Free(void *ptr) { free(ptr); } 1522 void PORT_Free(void *ptr) { free(ptr); }
1517 void PORT_ZFree(void *ptr, size_t len) { memset(ptr, 0, len); free(ptr); } 1523 void PORT_ZFree(void *ptr, size_t len) { memset(ptr, 0, len); free(ptr); }
1518 #endif 1524 #endif
OLDNEW
« no previous file with comments | « mozilla/security/nss/lib/freebl/sechash.h ('k') | mozilla/security/nss/lib/freebl/sha_fast.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698