OLD | NEW |
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 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 #ifndef UNROLL_LOOPS | 371 #ifndef UNROLL_LOOPS |
372 int i; | 372 int i; |
373 #endif | 373 #endif |
374 | 374 |
375 block_nb = (1 + ((SHA256_BLOCK_SIZE - 9) | 375 block_nb = (1 + ((SHA256_BLOCK_SIZE - 9) |
376 < (ctx->len % SHA256_BLOCK_SIZE))); | 376 < (ctx->len % SHA256_BLOCK_SIZE))); |
377 | 377 |
378 len_b = (ctx->tot_len + ctx->len) << 3; | 378 len_b = (ctx->tot_len + ctx->len) << 3; |
379 pm_len = block_nb << 6; | 379 pm_len = block_nb << 6; |
380 | 380 |
381 memset(ctx->block + ctx->len, 0, pm_len - ctx->len); | 381 Memset(ctx->block + ctx->len, 0, pm_len - ctx->len); |
382 ctx->block[ctx->len] = 0x80; | 382 ctx->block[ctx->len] = 0x80; |
383 UNPACK32(len_b, ctx->block + pm_len - 4); | 383 UNPACK32(len_b, ctx->block + pm_len - 4); |
384 | 384 |
385 SHA256_transform(ctx, ctx->block, block_nb); | 385 SHA256_transform(ctx, ctx->block, block_nb); |
386 | 386 |
387 #ifndef UNROLL_LOOPS | 387 #ifndef UNROLL_LOOPS |
388 for (i = 0 ; i < 8; i++) { | 388 for (i = 0 ; i < 8; i++) { |
389 UNPACK32(ctx->h[i], &ctx->buf[i << 2]); | 389 UNPACK32(ctx->h[i], &ctx->buf[i << 2]); |
390 } | 390 } |
391 #else | 391 #else |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 #ifndef UNROLL_LOOPS | 561 #ifndef UNROLL_LOOPS |
562 int i; | 562 int i; |
563 #endif | 563 #endif |
564 | 564 |
565 block_nb = 1 + ((SHA512_BLOCK_SIZE - 17) | 565 block_nb = 1 + ((SHA512_BLOCK_SIZE - 17) |
566 < (ctx->len % SHA512_BLOCK_SIZE)); | 566 < (ctx->len % SHA512_BLOCK_SIZE)); |
567 | 567 |
568 len_b = (ctx->tot_len + ctx->len) << 3; | 568 len_b = (ctx->tot_len + ctx->len) << 3; |
569 pm_len = block_nb << 7; | 569 pm_len = block_nb << 7; |
570 | 570 |
571 memset(ctx->block + ctx->len, 0, pm_len - ctx->len); | 571 Memset(ctx->block + ctx->len, 0, pm_len - ctx->len); |
572 ctx->block[ctx->len] = 0x80; | 572 ctx->block[ctx->len] = 0x80; |
573 UNPACK32(len_b, ctx->block + pm_len - 4); | 573 UNPACK32(len_b, ctx->block + pm_len - 4); |
574 | 574 |
575 SHA512_transform(ctx, ctx->block, block_nb); | 575 SHA512_transform(ctx, ctx->block, block_nb); |
576 | 576 |
577 #ifndef UNROLL_LOOPS | 577 #ifndef UNROLL_LOOPS |
578 for (i = 0 ; i < 8; i++) { | 578 for (i = 0 ; i < 8; i++) { |
579 UNPACK64(ctx->h[i], &ctx->buf[i << 3]); | 579 UNPACK64(ctx->h[i], &ctx->buf[i << 3]); |
580 } | 580 } |
581 #else | 581 #else |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } |
OLD | NEW |