summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fdrm/crypto/fx_crypt_sha.cpp130
1 files changed, 54 insertions, 76 deletions
diff --git a/core/fdrm/crypto/fx_crypt_sha.cpp b/core/fdrm/crypto/fx_crypt_sha.cpp
index d2745e82b1..49f77558f0 100644
--- a/core/fdrm/crypto/fx_crypt_sha.cpp
+++ b/core/fdrm/crypto/fx_crypt_sha.cpp
@@ -259,58 +259,36 @@ const uint8_t sha384_padding[128] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
-const char* const constants[] = {
- "428a2f98d728ae22", "7137449123ef65cd", "b5c0fbcfec4d3b2f",
- "e9b5dba58189dbbc", "3956c25bf348b538", "59f111f1b605d019",
- "923f82a4af194f9b", "ab1c5ed5da6d8118", "d807aa98a3030242",
- "12835b0145706fbe", "243185be4ee4b28c", "550c7dc3d5ffb4e2",
- "72be5d74f27b896f", "80deb1fe3b1696b1", "9bdc06a725c71235",
- "c19bf174cf692694", "e49b69c19ef14ad2", "efbe4786384f25e3",
- "0fc19dc68b8cd5b5", "240ca1cc77ac9c65", "2de92c6f592b0275",
- "4a7484aa6ea6e483", "5cb0a9dcbd41fbd4", "76f988da831153b5",
- "983e5152ee66dfab", "a831c66d2db43210", "b00327c898fb213f",
- "bf597fc7beef0ee4", "c6e00bf33da88fc2", "d5a79147930aa725",
- "06ca6351e003826f", "142929670a0e6e70", "27b70a8546d22ffc",
- "2e1b21385c26c926", "4d2c6dfc5ac42aed", "53380d139d95b3df",
- "650a73548baf63de", "766a0abb3c77b2a8", "81c2c92e47edaee6",
- "92722c851482353b", "a2bfe8a14cf10364", "a81a664bbc423001",
- "c24b8b70d0f89791", "c76c51a30654be30", "d192e819d6ef5218",
- "d69906245565a910", "f40e35855771202a", "106aa07032bbd1b8",
- "19a4c116b8d2d0c8", "1e376c085141ab53", "2748774cdf8eeb99",
- "34b0bcb5e19b48a8", "391c0cb3c5c95a63", "4ed8aa4ae3418acb",
- "5b9cca4f7763e373", "682e6ff3d6b2b8a3", "748f82ee5defb2fc",
- "78a5636f43172f60", "84c87814a1f0ab72", "8cc702081a6439ec",
- "90befffa23631e28", "a4506cebde82bde9", "bef9a3f7b2c67915",
- "c67178f2e372532b", "ca273eceea26619c", "d186b8c721c0c207",
- "eada7dd6cde0eb1e", "f57d4f7fee6ed178", "06f067aa72176fba",
- "0a637dc5a2c898a6", "113f9804bef90dae", "1b710b35131c471b",
- "28db77f523047d84", "32caab7b40c72493", "3c9ebe0a15c9bebc",
- "431d67c49c100d4c", "4cc5d4becb3e42b6", "597f299cfc657e2a",
- "5fcb6fab3ad6faec", "6c44198c4a475817",
+uint64_t const constants[] = {
+ 0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL, 0xb5c0fbcfec4d3b2fULL,
+ 0xe9b5dba58189dbbcULL, 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL,
+ 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL, 0xd807aa98a3030242ULL,
+ 0x12835b0145706fbeULL, 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL,
+ 0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL, 0x9bdc06a725c71235ULL,
+ 0xc19bf174cf692694ULL, 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL,
+ 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL, 0x2de92c6f592b0275ULL,
+ 0x4a7484aa6ea6e483ULL, 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL,
+ 0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL, 0xb00327c898fb213fULL,
+ 0xbf597fc7beef0ee4ULL, 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL,
+ 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL, 0x27b70a8546d22ffcULL,
+ 0x2e1b21385c26c926ULL, 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL,
+ 0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL, 0x81c2c92e47edaee6ULL,
+ 0x92722c851482353bULL, 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL,
+ 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL, 0xd192e819d6ef5218ULL,
+ 0xd69906245565a910ULL, 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL,
+ 0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL, 0x2748774cdf8eeb99ULL,
+ 0x34b0bcb5e19b48a8ULL, 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL,
+ 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL, 0x748f82ee5defb2fcULL,
+ 0x78a5636f43172f60ULL, 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL,
+ 0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL, 0xbef9a3f7b2c67915ULL,
+ 0xc67178f2e372532bULL, 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL,
+ 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL, 0x06f067aa72176fbaULL,
+ 0x0a637dc5a2c898a6ULL, 0x113f9804bef90daeULL, 0x1b710b35131c471bULL,
+ 0x28db77f523047d84ULL, 0x32caab7b40c72493ULL, 0x3c9ebe0a15c9bebcULL,
+ 0x431d67c49c100d4cULL, 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL,
+ 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL,
};
-uint64_t FX_ato64i(const char* str) {
- ASSERT(str);
- uint64_t ret = 0;
- int len = (int)FXSYS_strlen(str);
- len = len > 16 ? 16 : len;
- for (int i = 0; i < len; ++i) {
- if (i) {
- ret <<= 4;
- }
- if (str[i] >= '0' && str[i] <= '9') {
- ret |= (str[i] - '0') & 0xFF;
- } else if (str[i] >= 'a' && str[i] <= 'f') {
- ret |= (str[i] - 'a' + 10) & 0xFF;
- } else if (str[i] >= 'A' && str[i] <= 'F') {
- ret |= (str[i] - 'A' + 10) & 0xFF;
- } else {
- ASSERT(false);
- }
- }
- return ret;
-}
-
void sha384_process(CRYPT_sha384_context* ctx, const uint8_t data[128]) {
uint64_t temp1, temp2;
uint64_t A, B, C, D, E, F, G, H;
@@ -360,14 +338,14 @@ void sha384_process(CRYPT_sha384_context* ctx, const uint8_t data[128]) {
temp[6] = SHA384_R(i * 8 + 6);
temp[7] = SHA384_R(i * 8 + 7);
}
- SHA384_P(A, B, C, D, E, F, G, H, temp[0], FX_ato64i(constants[i * 8]));
- SHA384_P(H, A, B, C, D, E, F, G, temp[1], FX_ato64i(constants[i * 8 + 1]));
- SHA384_P(G, H, A, B, C, D, E, F, temp[2], FX_ato64i(constants[i * 8 + 2]));
- SHA384_P(F, G, H, A, B, C, D, E, temp[3], FX_ato64i(constants[i * 8 + 3]));
- SHA384_P(E, F, G, H, A, B, C, D, temp[4], FX_ato64i(constants[i * 8 + 4]));
- SHA384_P(D, E, F, G, H, A, B, C, temp[5], FX_ato64i(constants[i * 8 + 5]));
- SHA384_P(C, D, E, F, G, H, A, B, temp[6], FX_ato64i(constants[i * 8 + 6]));
- SHA384_P(B, C, D, E, F, G, H, A, temp[7], FX_ato64i(constants[i * 8 + 7]));
+ SHA384_P(A, B, C, D, E, F, G, H, temp[0], constants[i * 8]);
+ SHA384_P(H, A, B, C, D, E, F, G, temp[1], constants[i * 8 + 1]);
+ SHA384_P(G, H, A, B, C, D, E, F, temp[2], constants[i * 8 + 2]);
+ SHA384_P(F, G, H, A, B, C, D, E, temp[3], constants[i * 8 + 3]);
+ SHA384_P(E, F, G, H, A, B, C, D, temp[4], constants[i * 8 + 4]);
+ SHA384_P(D, E, F, G, H, A, B, C, temp[5], constants[i * 8 + 5]);
+ SHA384_P(C, D, E, F, G, H, A, B, temp[6], constants[i * 8 + 6]);
+ SHA384_P(B, C, D, E, F, G, H, A, temp[7], constants[i * 8 + 7]);
}
ctx->state[0] += A;
ctx->state[1] += B;
@@ -536,14 +514,14 @@ void CRYPT_SHA384Start(CRYPT_sha384_context* ctx) {
return;
memset(ctx, 0, sizeof(CRYPT_sha384_context));
- ctx->state[0] = FX_ato64i("cbbb9d5dc1059ed8");
- ctx->state[1] = FX_ato64i("629a292a367cd507");
- ctx->state[2] = FX_ato64i("9159015a3070dd17");
- ctx->state[3] = FX_ato64i("152fecd8f70e5939");
- ctx->state[4] = FX_ato64i("67332667ffc00b31");
- ctx->state[5] = FX_ato64i("8eb44a8768581511");
- ctx->state[6] = FX_ato64i("db0c2e0d64f98fa7");
- ctx->state[7] = FX_ato64i("47b5481dbefa4fa4");
+ ctx->state[0] = 0xcbbb9d5dc1059ed8ULL;
+ ctx->state[1] = 0x629a292a367cd507ULL;
+ ctx->state[2] = 0x9159015a3070dd17ULL;
+ ctx->state[3] = 0x152fecd8f70e5939ULL;
+ ctx->state[4] = 0x67332667ffc00b31ULL;
+ ctx->state[5] = 0x8eb44a8768581511ULL;
+ ctx->state[6] = 0xdb0c2e0d64f98fa7ULL;
+ ctx->state[7] = 0x47b5481dbefa4fa4ULL;
}
void CRYPT_SHA384Update(CRYPT_sha384_context* ctx,
@@ -605,19 +583,19 @@ void CRYPT_SHA384Generate(const uint8_t* data,
}
void CRYPT_SHA512Start(void* context) {
- if (!context) {
+ if (!context)
return;
- }
+
CRYPT_sha384_context* ctx = (CRYPT_sha384_context*)context;
memset(ctx, 0, sizeof(CRYPT_sha384_context));
- ctx->state[0] = FX_ato64i("6a09e667f3bcc908");
- ctx->state[1] = FX_ato64i("bb67ae8584caa73b");
- ctx->state[2] = FX_ato64i("3c6ef372fe94f82b");
- ctx->state[3] = FX_ato64i("a54ff53a5f1d36f1");
- ctx->state[4] = FX_ato64i("510e527fade682d1");
- ctx->state[5] = FX_ato64i("9b05688c2b3e6c1f");
- ctx->state[6] = FX_ato64i("1f83d9abfb41bd6b");
- ctx->state[7] = FX_ato64i("5be0cd19137e2179");
+ ctx->state[0] = 0xa09e667f3bcc908ULL;
+ ctx->state[1] = 0xb67ae8584caa73bULL;
+ ctx->state[2] = 0xc6ef372fe94f82bULL;
+ ctx->state[3] = 0x54ff53a5f1d36f1ULL;
+ ctx->state[4] = 0x10e527fade682d1ULL;
+ ctx->state[5] = 0xb05688c2b3e6c1fULL;
+ ctx->state[6] = 0xf83d9abfb41bd6bULL;
+ ctx->state[7] = 0xbe0cd19137e2179ULL;
}
void CRYPT_SHA512Update(void* context, const uint8_t* data, uint32_t size) {