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

Side by Side Diff: src/platform/vboot_reference/crypto/sha2.c

Issue 744002: Vboot Reference: Make length types explicitly sized. (Closed)
Patch Set: Created 10 years, 9 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
OLDNEW
1 /* SHA-256 and SHA-512 implementation based on code by Oliver Gay 1 /* SHA-256 and SHA-512 implementation based on code by Oliver Gay
2 * <olivier.gay@a3.epfl.ch> under a BSD-style license. See below. 2 * <olivier.gay@a3.epfl.ch> under a BSD-style license. See below.
3 */ 3 */
4 4
5 /* 5 /*
6 * FIPS 180-2 SHA-224/256/384/512 implementation 6 * FIPS 180-2 SHA-224/256/384/512 implementation
7 * Last update: 02/02/2007 7 * Last update: 02/02/2007
8 * Issue date: 04/30/2005 8 * Issue date: 04/30/2005
9 * 9 *
10 * Copyright (C) 2005, 2007 Olivier Gay <olivier.gay@a3.epfl.ch> 10 * Copyright (C) 2005, 2007 Olivier Gay <olivier.gay@a3.epfl.ch>
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 ctx->h[0] += wv[0]; ctx->h[1] += wv[1]; 325 ctx->h[0] += wv[0]; ctx->h[1] += wv[1];
326 ctx->h[2] += wv[2]; ctx->h[3] += wv[3]; 326 ctx->h[2] += wv[2]; ctx->h[3] += wv[3];
327 ctx->h[4] += wv[4]; ctx->h[5] += wv[5]; 327 ctx->h[4] += wv[4]; ctx->h[5] += wv[5];
328 ctx->h[6] += wv[6]; ctx->h[7] += wv[7]; 328 ctx->h[6] += wv[6]; ctx->h[7] += wv[7];
329 #endif /* !UNROLL_LOOPS */ 329 #endif /* !UNROLL_LOOPS */
330 } 330 }
331 } 331 }
332 332
333 333
334 334
335 void SHA256_update(SHA256_CTX* ctx, const uint8_t* data, int len) { 335 void SHA256_update(SHA256_CTX* ctx, const uint8_t* data, uint64_t len) {
336 unsigned int block_nb; 336 unsigned int block_nb;
337 unsigned int new_len, rem_len, tmp_len; 337 unsigned int new_len, rem_len, tmp_len;
338 const uint8_t *shifted_data; 338 const uint8_t *shifted_data;
339 339
340 tmp_len = SHA256_BLOCK_SIZE - ctx->len; 340 tmp_len = SHA256_BLOCK_SIZE - ctx->len;
341 rem_len = len < tmp_len ? len : tmp_len; 341 rem_len = len < tmp_len ? len : tmp_len;
342 342
343 memcpy(&ctx->block[ctx->len], data, rem_len); 343 memcpy(&ctx->block[ctx->len], data, rem_len);
344 344
345 if (ctx->len + len < SHA256_BLOCK_SIZE) { 345 if (ctx->len + len < SHA256_BLOCK_SIZE) {
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 ctx->h[0] += wv[0]; ctx->h[1] += wv[1]; 513 ctx->h[0] += wv[0]; ctx->h[1] += wv[1];
514 ctx->h[2] += wv[2]; ctx->h[3] += wv[3]; 514 ctx->h[2] += wv[2]; ctx->h[3] += wv[3];
515 ctx->h[4] += wv[4]; ctx->h[5] += wv[5]; 515 ctx->h[4] += wv[4]; ctx->h[5] += wv[5];
516 ctx->h[6] += wv[6]; ctx->h[7] += wv[7]; 516 ctx->h[6] += wv[6]; ctx->h[7] += wv[7];
517 #endif /* !UNROLL_LOOPS */ 517 #endif /* !UNROLL_LOOPS */
518 } 518 }
519 } 519 }
520 520
521 521
522 void SHA512_update(SHA512_CTX* ctx, const uint8_t* data, 522 void SHA512_update(SHA512_CTX* ctx, const uint8_t* data,
523 int len) { 523 uint64_t len) {
524 unsigned int block_nb; 524 unsigned int block_nb;
525 unsigned int new_len, rem_len, tmp_len; 525 unsigned int new_len, rem_len, tmp_len;
526 const uint8_t* shifted_data; 526 const uint8_t* shifted_data;
527 527
528 tmp_len = SHA512_BLOCK_SIZE - ctx->len; 528 tmp_len = SHA512_BLOCK_SIZE - ctx->len;
529 rem_len = len < tmp_len ? len : tmp_len; 529 rem_len = len < tmp_len ? len : tmp_len;
530 530
531 memcpy(&ctx->block[ctx->len], data, rem_len); 531 memcpy(&ctx->block[ctx->len], data, rem_len);
532 532
533 if (ctx->len + len < SHA512_BLOCK_SIZE) { 533 if (ctx->len + len < SHA512_BLOCK_SIZE) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 UNPACK64(ctx->h[6], &ctx->buf[48]); 588 UNPACK64(ctx->h[6], &ctx->buf[48]);
589 UNPACK64(ctx->h[7], &ctx->buf[56]); 589 UNPACK64(ctx->h[7], &ctx->buf[56]);
590 #endif /* !UNROLL_LOOPS */ 590 #endif /* !UNROLL_LOOPS */
591 591
592 return ctx->buf; 592 return ctx->buf;
593 } 593 }
594 594
595 595
596 596
597 /* Convenient functions. */ 597 /* Convenient functions. */
598 uint8_t* SHA256(const uint8_t* data, int len, uint8_t* digest) { 598 uint8_t* SHA256(const uint8_t* data, uint64_t len, uint8_t* digest) {
599 const uint8_t* p; 599 const uint8_t* p;
600 int i; 600 int i;
601 SHA256_CTX ctx; 601 SHA256_CTX ctx;
602 SHA256_init(&ctx); 602 SHA256_init(&ctx);
603 SHA256_update(&ctx, data, len); 603 SHA256_update(&ctx, data, len);
604 p = SHA256_final(&ctx); 604 p = SHA256_final(&ctx);
605 for (i = 0; i < SHA256_DIGEST_SIZE; ++i) { 605 for (i = 0; i < SHA256_DIGEST_SIZE; ++i) {
606 digest[i] = *p++; 606 digest[i] = *p++;
607 } 607 }
608 return digest; 608 return digest;
609 } 609 }
610 610
611 611
612 uint8_t* SHA512(const uint8_t* data, int len, uint8_t* digest) { 612 uint8_t* SHA512(const uint8_t* data, uint64_t len, uint8_t* digest) {
613 const uint8_t* p; 613 const uint8_t* p;
614 int i; 614 int i;
615 SHA512_CTX ctx; 615 SHA512_CTX ctx;
616 SHA512_init(&ctx); 616 SHA512_init(&ctx);
617 SHA512_update(&ctx, data, len); 617 SHA512_update(&ctx, data, len);
618 p = SHA512_final(&ctx); 618 p = SHA512_final(&ctx);
619 for (i = 0; i < SHA512_DIGEST_SIZE; ++i) { 619 for (i = 0; i < SHA512_DIGEST_SIZE; ++i) {
620 digest[i] = *p++; 620 digest[i] = *p++;
621 } 621 }
622 return digest; 622 return digest;
623 } 623 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698