diff options
Diffstat (limited to 'core/fdrm/crypto')
-rw-r--r-- | core/fdrm/crypto/fx_crypt.cpp | 38 | ||||
-rw-r--r-- | core/fdrm/crypto/fx_crypt_aes.cpp | 8 | ||||
-rw-r--r-- | core/fdrm/crypto/fx_crypt_sha.cpp | 46 | ||||
-rw-r--r-- | core/fdrm/crypto/include/fx_crypt.h | 40 |
4 files changed, 66 insertions, 66 deletions
diff --git a/core/fdrm/crypto/fx_crypt.cpp b/core/fdrm/crypto/fx_crypt.cpp index d5cbdb5a82..f3665060f8 100644 --- a/core/fdrm/crypto/fx_crypt.cpp +++ b/core/fdrm/crypto/fx_crypt.cpp @@ -12,7 +12,7 @@ extern "C" { struct rc4_state { int x, y, m[256]; }; -void CRYPT_ArcFourSetup(void* context, const uint8_t* key, FX_DWORD length) { +void CRYPT_ArcFourSetup(void* context, const uint8_t* key, uint32_t length) { rc4_state* s = (rc4_state*)context; int i, j, k, *m, a; s->x = 0; @@ -32,7 +32,7 @@ void CRYPT_ArcFourSetup(void* context, const uint8_t* key, FX_DWORD length) { } } } -void CRYPT_ArcFourCrypt(void* context, unsigned char* data, FX_DWORD length) { +void CRYPT_ArcFourCrypt(void* context, unsigned char* data, uint32_t length) { struct rc4_state* s = (struct rc4_state*)context; int i, x, y, *m, a, b; x = s->x; @@ -50,24 +50,24 @@ void CRYPT_ArcFourCrypt(void* context, unsigned char* data, FX_DWORD length) { s->y = y; } void CRYPT_ArcFourCryptBlock(uint8_t* pData, - FX_DWORD size, + uint32_t size, const uint8_t* key, - FX_DWORD keylen) { + uint32_t keylen) { rc4_state s; CRYPT_ArcFourSetup(&s, key, keylen); CRYPT_ArcFourCrypt(&s, pData, size); } struct md5_context { - FX_DWORD total[2]; - FX_DWORD state[4]; + uint32_t total[2]; + uint32_t state[4]; uint8_t buffer[64]; }; #define GET_FX_DWORD(n, b, i) \ { \ - (n) = (FX_DWORD)((uint8_t*)b)[(i)] | \ - (((FX_DWORD)((uint8_t*)b)[(i) + 1]) << 8) | \ - (((FX_DWORD)((uint8_t*)b)[(i) + 2]) << 16) | \ - (((FX_DWORD)((uint8_t*)b)[(i) + 3]) << 24); \ + (n) = (uint32_t)((uint8_t*)b)[(i)] | \ + (((uint32_t)((uint8_t*)b)[(i) + 1]) << 8) | \ + (((uint32_t)((uint8_t*)b)[(i) + 2]) << 16) | \ + (((uint32_t)((uint8_t*)b)[(i) + 3]) << 24); \ } #define PUT_FX_DWORD(n, b, i) \ { \ @@ -77,7 +77,7 @@ struct md5_context { (((uint8_t*)b)[(i) + 3]) = (uint8_t)(((n) >> 24) & 0xFF); \ } void md5_process(struct md5_context* ctx, const uint8_t data[64]) { - FX_DWORD A, B, C, D, X[16]; + uint32_t A, B, C, D, X[16]; GET_FX_DWORD(X[0], data, 0); GET_FX_DWORD(X[1], data, 4); GET_FX_DWORD(X[2], data, 8); @@ -190,9 +190,9 @@ void CRYPT_MD5Start(void* context) { ctx->state[2] = 0x98BADCFE; ctx->state[3] = 0x10325476; } -void CRYPT_MD5Update(void* pctx, const uint8_t* input, FX_DWORD length) { +void CRYPT_MD5Update(void* pctx, const uint8_t* input, uint32_t length) { struct md5_context* ctx = (struct md5_context*)pctx; - FX_DWORD left, fill; + uint32_t left, fill; if (!length) { return; } @@ -224,7 +224,7 @@ const uint8_t md5_padding[64] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; void CRYPT_MD5Finish(void* pctx, uint8_t digest[16]) { struct md5_context* ctx = (struct md5_context*)pctx; - FX_DWORD last, padn; + uint32_t last, padn; uint8_t msglen[8]; PUT_FX_DWORD(ctx->total[0], msglen, 0); PUT_FX_DWORD(ctx->total[1], msglen, 4); @@ -238,7 +238,7 @@ void CRYPT_MD5Finish(void* pctx, uint8_t digest[16]) { PUT_FX_DWORD(ctx->state[3], digest, 12); } void CRYPT_MD5Generate(const uint8_t* input, - FX_DWORD length, + uint32_t length, uint8_t digest[16]) { md5_context ctx; CRYPT_MD5Start(&ctx); @@ -246,13 +246,13 @@ void CRYPT_MD5Generate(const uint8_t* input, CRYPT_MD5Finish(&ctx, digest); } static FX_BOOL (*g_PubKeyDecryptor)(const uint8_t* pData, - FX_DWORD size, + uint32_t size, uint8_t* data_buf, - FX_DWORD& data_len) = NULL; + uint32_t& data_len) = NULL; void CRYPT_SetPubKeyDecryptor(FX_BOOL (*func)(const uint8_t* pData, - FX_DWORD size, + uint32_t size, uint8_t* data_buf, - FX_DWORD& data_len)) { + uint32_t& data_len)) { g_PubKeyDecryptor = func; } #ifdef __cplusplus diff --git a/core/fdrm/crypto/fx_crypt_aes.cpp b/core/fdrm/crypto/fx_crypt_aes.cpp index b56d8fe33c..1a6eab4283 100644 --- a/core/fdrm/crypto/fx_crypt_aes.cpp +++ b/core/fdrm/crypto/fx_crypt_aes.cpp @@ -804,9 +804,9 @@ static void aes_encrypt_cbc(unsigned char* dest, FXSYS_memcpy(ctx->iv, iv, sizeof(iv)); } void CRYPT_AESSetKey(void* context, - FX_DWORD blocklen, + uint32_t blocklen, const uint8_t* key, - FX_DWORD keylen, + uint32_t keylen, FX_BOOL bEncrypt) { aes_setup((AESContext*)context, blocklen, key, keylen); } @@ -819,13 +819,13 @@ void CRYPT_AESSetIV(void* context, const uint8_t* iv) { void CRYPT_AESDecrypt(void* context, uint8_t* dest, const uint8_t* src, - FX_DWORD len) { + uint32_t len) { aes_decrypt_cbc(dest, src, len, (AESContext*)context); } void CRYPT_AESEncrypt(void* context, uint8_t* dest, const uint8_t* src, - FX_DWORD len) { + uint32_t len) { aes_encrypt_cbc(dest, src, len, (AESContext*)context); } #ifdef __cplusplus diff --git a/core/fdrm/crypto/fx_crypt_sha.cpp b/core/fdrm/crypto/fx_crypt_sha.cpp index 5f1558943d..28b3ce3739 100644 --- a/core/fdrm/crypto/fx_crypt_sha.cpp +++ b/core/fdrm/crypto/fx_crypt_sha.cpp @@ -84,7 +84,7 @@ void CRYPT_SHA1Start(void* context) { s->blkused = 0; s->lenhi = s->lenlo = 0; } -void CRYPT_SHA1Update(void* context, const uint8_t* data, FX_DWORD size) { +void CRYPT_SHA1Update(void* context, const uint8_t* data, uint32_t size) { SHA_State* s = (SHA_State*)context; unsigned char* q = (unsigned char*)data; unsigned int wordblock[16]; @@ -147,7 +147,7 @@ void CRYPT_SHA1Finish(void* context, uint8_t digest[20]) { } } void CRYPT_SHA1Generate(const uint8_t* data, - FX_DWORD size, + uint32_t size, uint8_t digest[20]) { SHA_State s; CRYPT_SHA1Start(&s); @@ -155,14 +155,14 @@ void CRYPT_SHA1Generate(const uint8_t* data, CRYPT_SHA1Finish(&s, digest); } typedef struct { - FX_DWORD total[2]; - FX_DWORD state[8]; + uint32_t total[2]; + uint32_t state[8]; uint8_t buffer[64]; } sha256_context; #define GET_FX_DWORD(n, b, i) \ { \ - (n) = ((FX_DWORD)(b)[(i)] << 24) | ((FX_DWORD)(b)[(i) + 1] << 16) | \ - ((FX_DWORD)(b)[(i) + 2] << 8) | ((FX_DWORD)(b)[(i) + 3]); \ + (n) = ((uint32_t)(b)[(i)] << 24) | ((uint32_t)(b)[(i) + 1] << 16) | \ + ((uint32_t)(b)[(i) + 2] << 8) | ((uint32_t)(b)[(i) + 3]); \ } #define PUT_FX_DWORD(n, b, i) \ { \ @@ -185,8 +185,8 @@ void CRYPT_SHA256Start(void* context) { ctx->state[7] = 0x5BE0CD19; } static void sha256_process(sha256_context* ctx, const uint8_t data[64]) { - FX_DWORD temp1, temp2, W[64]; - FX_DWORD A, B, C, D, E, F, G, H; + uint32_t temp1, temp2, W[64]; + uint32_t A, B, C, D, E, F, G, H; GET_FX_DWORD(W[0], data, 0); GET_FX_DWORD(W[1], data, 4); GET_FX_DWORD(W[2], data, 8); @@ -300,9 +300,9 @@ static void sha256_process(sha256_context* ctx, const uint8_t data[64]) { ctx->state[6] += G; ctx->state[7] += H; } -void CRYPT_SHA256Update(void* context, const uint8_t* input, FX_DWORD length) { +void CRYPT_SHA256Update(void* context, const uint8_t* input, uint32_t length) { sha256_context* ctx = (sha256_context*)context; - FX_DWORD left, fill; + uint32_t left, fill; if (!length) { return; } @@ -335,8 +335,8 @@ static const uint8_t sha256_padding[64] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; void CRYPT_SHA256Finish(void* context, uint8_t digest[32]) { sha256_context* ctx = (sha256_context*)context; - FX_DWORD last, padn; - FX_DWORD high, low; + uint32_t last, padn; + uint32_t high, low; uint8_t msglen[8]; high = (ctx->total[0] >> 29) | (ctx->total[1] << 3); low = (ctx->total[0] << 3); @@ -356,7 +356,7 @@ void CRYPT_SHA256Finish(void* context, uint8_t digest[32]) { PUT_FX_DWORD(ctx->state[7], digest, 28); } void CRYPT_SHA256Generate(const uint8_t* data, - FX_DWORD size, + uint32_t size, uint8_t digest[32]) { sha256_context ctx; CRYPT_SHA256Start(&ctx); @@ -546,13 +546,13 @@ static void sha384_process(sha384_context* ctx, const uint8_t data[128]) { ctx->state[6] += G; ctx->state[7] += H; } -void CRYPT_SHA384Update(void* context, const uint8_t* input, FX_DWORD length) { +void CRYPT_SHA384Update(void* context, const uint8_t* input, uint32_t length) { sha384_context* ctx = (sha384_context*)context; - FX_DWORD left, fill; + uint32_t left, fill; if (!length) { return; } - left = (FX_DWORD)ctx->total[0] & 0x7F; + left = (uint32_t)ctx->total[0] & 0x7F; fill = 128 - left; ctx->total[0] += length; if (ctx->total[0] < length) { @@ -576,7 +576,7 @@ void CRYPT_SHA384Update(void* context, const uint8_t* input, FX_DWORD length) { } void CRYPT_SHA384Finish(void* context, uint8_t digest[48]) { sha384_context* ctx = (sha384_context*)context; - FX_DWORD last, padn; + uint32_t last, padn; uint8_t msglen[16]; FXSYS_memset(msglen, 0, 16); uint64_t high, low; @@ -584,7 +584,7 @@ void CRYPT_SHA384Finish(void* context, uint8_t digest[48]) { low = (ctx->total[0] << 3); PUT_FX_64DWORD(high, msglen, 0); PUT_FX_64DWORD(low, msglen, 8); - last = (FX_DWORD)ctx->total[0] & 0x7F; + last = (uint32_t)ctx->total[0] & 0x7F; padn = (last < 112) ? (112 - last) : (240 - last); CRYPT_SHA384Update(ctx, sha384_padding, padn); CRYPT_SHA384Update(ctx, msglen, 16); @@ -596,7 +596,7 @@ void CRYPT_SHA384Finish(void* context, uint8_t digest[48]) { PUT_FX_64DWORD(ctx->state[5], digest, 40); } void CRYPT_SHA384Generate(const uint8_t* data, - FX_DWORD size, + uint32_t size, uint8_t digest[64]) { sha384_context context; CRYPT_SHA384Start(&context); @@ -618,12 +618,12 @@ void CRYPT_SHA512Start(void* context) { ctx->state[6] = FX_ato64i("1f83d9abfb41bd6b"); ctx->state[7] = FX_ato64i("5be0cd19137e2179"); } -void CRYPT_SHA512Update(void* context, const uint8_t* data, FX_DWORD size) { +void CRYPT_SHA512Update(void* context, const uint8_t* data, uint32_t size) { CRYPT_SHA384Update(context, data, size); } void CRYPT_SHA512Finish(void* context, uint8_t digest[64]) { sha384_context* ctx = (sha384_context*)context; - FX_DWORD last, padn; + uint32_t last, padn; uint8_t msglen[16]; FXSYS_memset(msglen, 0, 16); uint64_t high, low; @@ -631,7 +631,7 @@ void CRYPT_SHA512Finish(void* context, uint8_t digest[64]) { low = (ctx->total[0] << 3); PUT_FX_64DWORD(high, msglen, 0); PUT_FX_64DWORD(low, msglen, 8); - last = (FX_DWORD)ctx->total[0] & 0x7F; + last = (uint32_t)ctx->total[0] & 0x7F; padn = (last < 112) ? (112 - last) : (240 - last); CRYPT_SHA512Update(ctx, sha384_padding, padn); CRYPT_SHA512Update(ctx, msglen, 16); @@ -645,7 +645,7 @@ void CRYPT_SHA512Finish(void* context, uint8_t digest[64]) { PUT_FX_64DWORD(ctx->state[7], digest, 56); } void CRYPT_SHA512Generate(const uint8_t* data, - FX_DWORD size, + uint32_t size, uint8_t digest[64]) { sha384_context context; CRYPT_SHA512Start(&context); diff --git a/core/fdrm/crypto/include/fx_crypt.h b/core/fdrm/crypto/include/fx_crypt.h index 4563b7fa43..155def6f88 100644 --- a/core/fdrm/crypto/include/fx_crypt.h +++ b/core/fdrm/crypto/include/fx_crypt.h @@ -14,55 +14,55 @@ extern "C" { #endif void CRYPT_ArcFourCryptBlock(uint8_t* data, - FX_DWORD size, + uint32_t size, const uint8_t* key, - FX_DWORD keylen); -void CRYPT_ArcFourSetup(void* context, const uint8_t* key, FX_DWORD length); -void CRYPT_ArcFourCrypt(void* context, uint8_t* data, FX_DWORD size); + uint32_t keylen); +void CRYPT_ArcFourSetup(void* context, const uint8_t* key, uint32_t length); +void CRYPT_ArcFourCrypt(void* context, uint8_t* data, uint32_t size); void CRYPT_AESSetKey(void* context, - FX_DWORD blocklen, + uint32_t blocklen, const uint8_t* key, - FX_DWORD keylen, + uint32_t keylen, FX_BOOL bEncrypt); void CRYPT_AESSetIV(void* context, const uint8_t* iv); void CRYPT_AESDecrypt(void* context, uint8_t* dest, const uint8_t* src, - FX_DWORD size); + uint32_t size); void CRYPT_AESEncrypt(void* context, uint8_t* dest, const uint8_t* src, - FX_DWORD size); -void CRYPT_MD5Generate(const uint8_t* data, FX_DWORD size, uint8_t digest[16]); + uint32_t size); +void CRYPT_MD5Generate(const uint8_t* data, uint32_t size, uint8_t digest[16]); void CRYPT_MD5Start(void* context); -void CRYPT_MD5Update(void* context, const uint8_t* data, FX_DWORD size); +void CRYPT_MD5Update(void* context, const uint8_t* data, uint32_t size); void CRYPT_MD5Finish(void* context, uint8_t digest[16]); -void CRYPT_SHA1Generate(const uint8_t* data, FX_DWORD size, uint8_t digest[20]); +void CRYPT_SHA1Generate(const uint8_t* data, uint32_t size, uint8_t digest[20]); void CRYPT_SHA1Start(void* context); -void CRYPT_SHA1Update(void* context, const uint8_t* data, FX_DWORD size); +void CRYPT_SHA1Update(void* context, const uint8_t* data, uint32_t size); void CRYPT_SHA1Finish(void* context, uint8_t digest[20]); void CRYPT_SHA256Generate(const uint8_t* data, - FX_DWORD size, + uint32_t size, uint8_t digest[32]); void CRYPT_SHA256Start(void* context); -void CRYPT_SHA256Update(void* context, const uint8_t* data, FX_DWORD size); +void CRYPT_SHA256Update(void* context, const uint8_t* data, uint32_t size); void CRYPT_SHA256Finish(void* context, uint8_t digest[32]); void CRYPT_SHA384Start(void* context); -void CRYPT_SHA384Update(void* context, const uint8_t* data, FX_DWORD size); +void CRYPT_SHA384Update(void* context, const uint8_t* data, uint32_t size); void CRYPT_SHA384Finish(void* context, uint8_t digest[48]); void CRYPT_SHA384Generate(const uint8_t* data, - FX_DWORD size, + uint32_t size, uint8_t digest[48]); void CRYPT_SHA512Start(void* context); -void CRYPT_SHA512Update(void* context, const uint8_t* data, FX_DWORD size); +void CRYPT_SHA512Update(void* context, const uint8_t* data, uint32_t size); void CRYPT_SHA512Finish(void* context, uint8_t digest[64]); void CRYPT_SHA512Generate(const uint8_t* data, - FX_DWORD size, + uint32_t size, uint8_t digest[64]); void CRYPT_SetPubKeyDecryptor(FX_BOOL (*func)(const uint8_t* pData, - FX_DWORD size, + uint32_t size, uint8_t* data_buf, - FX_DWORD& data_len)); + uint32_t& data_len)); #ifdef __cplusplus }; |