diff options
Diffstat (limited to 'firmware/2lib/2sha256.c')
-rw-r--r-- | firmware/2lib/2sha256.c | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/firmware/2lib/2sha256.c b/firmware/2lib/2sha256.c index c3612377..00441131 100644 --- a/firmware/2lib/2sha256.c +++ b/firmware/2lib/2sha256.c @@ -1,3 +1,8 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + /* SHA-256 and SHA-512 implementation based on code by Oliver Gay * <olivier.gay@a3.epfl.ch> under a BSD-style license. See below. */ @@ -37,6 +42,7 @@ #include "2common.h" #include "2sha.h" +#include "2sha_private.h" #include "2sysincludes.h" #define SHFR(x, n) (x >> n) @@ -50,22 +56,6 @@ #define SHA256_F3(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHFR(x, 3)) #define SHA256_F4(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHFR(x, 10)) -#define UNPACK32(x, str) \ - { \ - *((str) + 3) = (uint8_t) ((x) ); \ - *((str) + 2) = (uint8_t) ((x) >> 8); \ - *((str) + 1) = (uint8_t) ((x) >> 16); \ - *((str) + 0) = (uint8_t) ((x) >> 24); \ - } - -#define PACK32(str, x) \ - { \ - *(x) = ((uint32_t) *((str) + 3) ) \ - | ((uint32_t) *((str) + 2) << 8) \ - | ((uint32_t) *((str) + 1) << 16) \ - | ((uint32_t) *((str) + 0) << 24); \ - } - /* Macros used for loops unrolling */ #define SHA256_SCR(i) \ @@ -77,13 +67,13 @@ #define SHA256_EXP(a, b, c, d, e, f, g, h, j) \ { \ t1 = wv[h] + SHA256_F2(wv[e]) + CH(wv[e], wv[f], wv[g]) \ - + sha256_k[j] + w[j]; \ + + vb2_sha256_k[j] + w[j]; \ t2 = SHA256_F1(wv[a]) + MAJ(wv[a], wv[b], wv[c]); \ wv[d] += t1; \ wv[h] = t1 + t2; \ } -static const uint32_t sha256_h0[8] = { +const uint32_t vb2_sha256_h0[8] = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 }; @@ -93,7 +83,7 @@ static const uint32_t sha224_h0[8] = { 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 }; -static const uint32_t sha256_k[64] = { +const uint32_t vb2_sha256_k[64] = { 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, @@ -116,7 +106,7 @@ static const uint32_t sha256_k[64] = { void vb2_sha256_init(struct vb2_sha256_context *ctx, enum vb2_hash_algorithm algo) { - const uint32_t *h0 = algo == VB2_HASH_SHA224 ? sha224_h0 : sha256_h0; + const uint32_t *h0 = algo == VB2_HASH_SHA224 ? sha224_h0 : vb2_sha256_h0; #ifndef UNROLL_LOOPS int i; @@ -167,7 +157,7 @@ static void vb2_sha256_transform(struct vb2_sha256_context *ctx, for (j = 0; j < 64; j++) { t1 = wv[7] + SHA256_F2(wv[4]) + CH(wv[4], wv[5], wv[6]) - + sha256_k[j] + w[j]; + + vb2_sha256_k[j] + w[j]; t2 = SHA256_F1(wv[0]) + MAJ(wv[0], wv[1], wv[2]); wv[7] = wv[6]; wv[6] = wv[5]; |