From 377a7a968b6a906f262a45abea9a563ffc471938 Mon Sep 17 00:00:00 2001 From: Naram Qashat Date: Mon, 24 Oct 2011 16:32:29 -0400 Subject: Fixed bug #1349 (m_sqlite compiles without error under FreeBSD), as well as use C99's stdint.h (or cstdint if available) to get (u)intX_t types instead of our stupid typedefs. pstdint.h included in case there is no cstdint or stdint.h available. --- modules/encryption/enc_sha1.cpp | 36 ++++++++++++++++----------------- modules/encryption/enc_sha256.cpp | 42 +++++++++++++++++++-------------------- 2 files changed, 39 insertions(+), 39 deletions(-) (limited to 'modules/encryption') diff --git a/modules/encryption/enc_sha1.cpp b/modules/encryption/enc_sha1.cpp index 4fe321bdc..a0854d762 100644 --- a/modules/encryption/enc_sha1.cpp +++ b/modules/encryption/enc_sha1.cpp @@ -18,27 +18,27 @@ A million repetitions of "a" struct SHA1_CTX { - uint32 state[5]; - uint32 count[2]; + uint32_t state[5]; + uint32_t count[2]; unsigned char buffer[64]; }; -void SHA1Transform(uint32 state[5], const unsigned char buffer[64]); +void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]); void SHA1Init(SHA1_CTX *context); -void SHA1Update(SHA1_CTX *context, const unsigned char *data, uint32 len); +void SHA1Update(SHA1_CTX *context, const unsigned char *data, uint32_t len); void SHA1Final(unsigned char digest[20], SHA1_CTX *context); -inline static uint32 rol(uint32 value, uint32 bits) { return (value << bits) | (value >> (32 - bits)); } +inline static uint32_t rol(uint32_t value, uint32_t bits) { return (value << bits) | (value >> (32 - bits)); } union CHAR64LONG16 { unsigned char c[64]; - uint32 l[16]; + uint32_t l[16]; }; /* blk0() and blk() perform the initial expand. */ /* I got the idea of expanding during the round function from SSLeay */ -inline static uint32 blk0(CHAR64LONG16 *block, uint32 i) +inline static uint32_t blk0(CHAR64LONG16 *block, uint32_t i) { #ifdef LITTLE_ENDIAN return block->l[i] = (rol(block->l[i], 24) & 0xFF00FF00) | (rol(block->l[i], 8) & 0x00FF00FF); @@ -46,20 +46,20 @@ inline static uint32 blk0(CHAR64LONG16 *block, uint32 i) return block->l[i]; #endif } -inline static uint32 blk(CHAR64LONG16 *block, uint32 i) { return block->l[i & 15] = rol(block->l[(i + 13) & 15] ^ block->l[(i + 8) & 15] ^ block->l[(i + 2) & 15] ^ block->l[i & 15],1); } +inline static uint32_t blk(CHAR64LONG16 *block, uint32_t i) { return block->l[i & 15] = rol(block->l[(i + 13) & 15] ^ block->l[(i + 8) & 15] ^ block->l[(i + 2) & 15] ^ block->l[i & 15],1); } /* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ -inline static void R0(CHAR64LONG16 *block, uint32 v, uint32 &w, uint32 x, uint32 y, uint32 &z, uint32 i) { z += ((w & (x ^ y)) ^ y) + blk0(block, i) + 0x5A827999 + rol(v, 5); w = rol(w, 30); } -inline static void R1(CHAR64LONG16 *block, uint32 v, uint32 &w, uint32 x, uint32 y, uint32 &z, uint32 i) { z += ((w & (x ^ y)) ^ y) + blk(block, i) + 0x5A827999 + rol(v, 5); w = rol(w, 30); } -inline static void R2(CHAR64LONG16 *block, uint32 v, uint32 &w, uint32 x, uint32 y, uint32 &z, uint32 i) { z += (w ^ x ^ y) + blk(block, i) + 0x6ED9EBA1 + rol(v, 5); w = rol(w, 30); } -inline static void R3(CHAR64LONG16 *block, uint32 v, uint32 &w, uint32 x, uint32 y, uint32 &z, uint32 i) { z += (((w | x) & y) | (w & x)) + blk(block, i) + 0x8F1BBCDC + rol(v, 5); w = rol(w, 30); } -inline static void R4(CHAR64LONG16 *block, uint32 v, uint32 &w, uint32 x, uint32 y, uint32 &z, uint32 i) { z += (w ^ x ^ y) + blk(block, i) + 0xCA62C1D6 + rol(v, 5); w = rol(w, 30); } +inline static void R0(CHAR64LONG16 *block, uint32_t v, uint32_t &w, uint32_t x, uint32_t y, uint32_t &z, uint32_t i) { z += ((w & (x ^ y)) ^ y) + blk0(block, i) + 0x5A827999 + rol(v, 5); w = rol(w, 30); } +inline static void R1(CHAR64LONG16 *block, uint32_t v, uint32_t &w, uint32_t x, uint32_t y, uint32_t &z, uint32_t i) { z += ((w & (x ^ y)) ^ y) + blk(block, i) + 0x5A827999 + rol(v, 5); w = rol(w, 30); } +inline static void R2(CHAR64LONG16 *block, uint32_t v, uint32_t &w, uint32_t x, uint32_t y, uint32_t &z, uint32_t i) { z += (w ^ x ^ y) + blk(block, i) + 0x6ED9EBA1 + rol(v, 5); w = rol(w, 30); } +inline static void R3(CHAR64LONG16 *block, uint32_t v, uint32_t &w, uint32_t x, uint32_t y, uint32_t &z, uint32_t i) { z += (((w | x) & y) | (w & x)) + blk(block, i) + 0x8F1BBCDC + rol(v, 5); w = rol(w, 30); } +inline static void R4(CHAR64LONG16 *block, uint32_t v, uint32_t &w, uint32_t x, uint32_t y, uint32_t &z, uint32_t i) { z += (w ^ x ^ y) + blk(block, i) + 0xCA62C1D6 + rol(v, 5); w = rol(w, 30); } /* Hash a single 512-bit block. This is the core of the algorithm. */ -void SHA1Transform(uint32 state[5], const unsigned char buffer[64]) +void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]) { - uint32 a, b, c, d, e; + uint32_t a, b, c, d, e; static unsigned char workspace[64]; CHAR64LONG16 *block = reinterpret_cast(workspace); memcpy(block, buffer, 64); @@ -115,9 +115,9 @@ void SHA1Init(SHA1_CTX *context) /* Run your data through this. */ -void SHA1Update(SHA1_CTX *context, const unsigned char *data, uint32 len) +void SHA1Update(SHA1_CTX *context, const unsigned char *data, uint32_t len) { - uint32 i, j; + uint32_t i, j; j = (context->count[0] >> 3) & 63; if ((context->count[0] += len << 3) < (len << 3)) @@ -140,7 +140,7 @@ void SHA1Update(SHA1_CTX *context, const unsigned char *data, uint32 len) void SHA1Final(unsigned char digest[21], SHA1_CTX *context) { - uint32 i; + uint32_t i; unsigned char finalcount[8]; for (i = 0; i < 8; ++i) diff --git a/modules/encryption/enc_sha256.cpp b/modules/encryption/enc_sha256.cpp index 3034f3731..38dc4a841 100644 --- a/modules/encryption/enc_sha256.cpp +++ b/modules/encryption/enc_sha256.cpp @@ -65,41 +65,41 @@ class SHA256Context unsigned tot_len; unsigned len; unsigned char block[2 * SHA256_BLOCK_SIZE]; - uint32 h[8]; + uint32_t h[8]; }; -inline static uint32 SHFR(uint32 x, uint32 n) { return x >> n; } -inline static uint32 ROTR(uint32 x, uint32 n) { return (x >> n) | (x << ((sizeof(x) << 3) - n)); } -inline static uint32 ROTL(uint32 x, uint32 n) { return (x << n) | (x >> ((sizeof(x) << 3) - n)); } -inline static uint32 CH(uint32 x, uint32 y, uint32 z) { return (x & y) ^ (~x & z); } -inline static uint32 MAJ(uint32 x, uint32 y, uint32 z) { return (x & y) ^ (x & z) ^ (y & z); } +inline static uint32_t SHFR(uint32_t x, uint32_t n) { return x >> n; } +inline static uint32_t ROTR(uint32_t x, uint32_t n) { return (x >> n) | (x << ((sizeof(x) << 3) - n)); } +inline static uint32_t ROTL(uint32_t x, uint32_t n) { return (x << n) | (x >> ((sizeof(x) << 3) - n)); } +inline static uint32_t CH(uint32_t x, uint32_t y, uint32_t z) { return (x & y) ^ (~x & z); } +inline static uint32_t MAJ(uint32_t x, uint32_t y, uint32_t z) { return (x & y) ^ (x & z) ^ (y & z); } -inline static uint32 SHA256_F1(uint32 x) { return ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22); } -inline static uint32 SHA256_F2(uint32 x) { return ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25); } -inline static uint32 SHA256_F3(uint32 x) { return ROTR(x, 7) ^ ROTR(x, 18) ^ SHFR(x, 3); } -inline static uint32 SHA256_F4(uint32 x) { return ROTR(x, 17) ^ ROTR(x, 19) ^ SHFR(x, 10); } +inline static uint32_t SHA256_F1(uint32_t x) { return ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22); } +inline static uint32_t SHA256_F2(uint32_t x) { return ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25); } +inline static uint32_t SHA256_F3(uint32_t x) { return ROTR(x, 7) ^ ROTR(x, 18) ^ SHFR(x, 3); } +inline static uint32_t SHA256_F4(uint32_t x) { return ROTR(x, 17) ^ ROTR(x, 19) ^ SHFR(x, 10); } inline static void UNPACK32(unsigned x, unsigned char *str) { - str[3] = static_cast(x); - str[2] = static_cast(x >> 8); - str[1] = static_cast(x >> 16); - str[0] = static_cast(x >> 24); + str[3] = static_cast(x); + str[2] = static_cast(x >> 8); + str[1] = static_cast(x >> 16); + str[0] = static_cast(x >> 24); } -inline static void PACK32(unsigned char *str, uint32 &x) +inline static void PACK32(unsigned char *str, uint32_t &x) { - x = static_cast(str[3]) | static_cast(str[2]) << 8 | static_cast(str[1]) << 16 | static_cast(str[0]) << 24; + x = static_cast(str[3]) | static_cast(str[2]) << 8 | static_cast(str[1]) << 16 | static_cast(str[0]) << 24; } /* Macros used for loops unrolling */ -inline static void SHA256_SCR(uint32 w[64], int i) +inline static void SHA256_SCR(uint32_t w[64], int i) { w[i] = SHA256_F4(w[i - 2]) + w[i - 7] + SHA256_F3(w[i - 15]) + w[i - 16]; } -uint32 sha256_k[64] = +uint32_t sha256_k[64] = { 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, @@ -163,7 +163,7 @@ class ESHA256 : public Module void SHA256Transform(SHA256Context *ctx, unsigned char *message, unsigned block_nb) { - uint32 w[64], wv[8]; + uint32_t w[64], wv[8]; unsigned char *sub_block; for (unsigned i = 1; i <= block_nb; ++i) { @@ -178,8 +178,8 @@ class ESHA256 : public Module wv[j] = ctx->h[j]; for (j = 0; j < 64; ++j) { - uint32 t1 = wv[7] + SHA256_F2(wv[4]) + CH(wv[4], wv[5], wv[6]) + sha256_k[j] + w[j]; - uint32 t2 = SHA256_F1(wv[0]) + MAJ(wv[0], wv[1], wv[2]); + uint32_t t1 = wv[7] + SHA256_F2(wv[4]) + CH(wv[4], wv[5], wv[6]) + sha256_k[j] + w[j]; + uint32_t t2 = SHA256_F1(wv[0]) + MAJ(wv[0], wv[1], wv[2]); wv[7] = wv[6]; wv[6] = wv[5]; wv[5] = wv[4]; -- cgit