Avoid implicit types conversions and magic constants

This commit is contained in:
Frank Denis
2017-03-01 08:21:02 +01:00
parent 02565ad4c8
commit ed57801379
4 changed files with 20 additions and 20 deletions
@@ -151,7 +151,7 @@ static const uint8_t PAD[64] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
static void
SHA256_Pad(crypto_hash_sha256_state *state, uint32_t tmp32[72])
SHA256_Pad(crypto_hash_sha256_state *state, uint32_t tmp32[64 + 8])
{
uint64_t r;
uint64_t i;
@@ -190,16 +190,16 @@ int
crypto_hash_sha256_update(crypto_hash_sha256_state *state,
const unsigned char *in, unsigned long long inlen)
{
uint32_t tmp32[72];
uint64_t i;
uint64_t r;
uint32_t tmp32[64 + 8];
unsigned long long i;
unsigned long long r;
if (inlen <= 0U) {
return 0;
}
r = (state->count >> 3) & 0x3f;
state->count += (uint64_t)(inlen) << 3;
r = (unsigned long long) ((state->count >> 3) & 0x3f);
state->count += ((uint64_t) inlen) << 3;
if (inlen < 64 - r) {
for (i = 0; i < inlen; i++) {
state->buf[r + i] = in[i];
@@ -230,7 +230,7 @@ crypto_hash_sha256_update(crypto_hash_sha256_state *state,
int
crypto_hash_sha256_final(crypto_hash_sha256_state *state, unsigned char *out)
{
uint32_t tmp32[72];
uint32_t tmp32[64 + 8];
SHA256_Pad(state, tmp32);
be32enc_vect(out, state->state, 32);
@@ -170,7 +170,7 @@ static const uint8_t PAD[128] = {
};
static void
SHA512_Pad(crypto_hash_sha512_state *state, uint64_t tmp64[88])
SHA512_Pad(crypto_hash_sha512_state *state, uint64_t tmp64[80 + 8])
{
uint64_t r;
uint64_t i;
@@ -210,15 +210,15 @@ int
crypto_hash_sha512_update(crypto_hash_sha512_state *state,
const unsigned char *in, unsigned long long inlen)
{
uint64_t tmp64[88];
uint64_t bitlen[2];
uint64_t i;
uint64_t r;
uint64_t tmp64[80 + 8];
uint64_t bitlen[2];
unsigned long long i;
unsigned long long r;
if (inlen <= 0U) {
return 0;
}
r = (state->count[1] >> 3) & 0x7f;
r = (unsigned long long) ((state->count[1] >> 3) & 0x7f);
bitlen[1] = ((uint64_t) inlen) << 3;
bitlen[0] = ((uint64_t) inlen) >> 61;
@@ -256,7 +256,7 @@ crypto_hash_sha512_update(crypto_hash_sha512_state *state,
int
crypto_hash_sha512_final(crypto_hash_sha512_state *state, unsigned char *out)
{
uint64_t tmp64[88];
uint64_t tmp64[80 + 8];
SHA512_Pad(state, tmp64);
be64enc_vect(out, state->state, 64);
@@ -22,9 +22,9 @@ extern "C" {
#endif
typedef struct crypto_hash_sha256_state {
uint32_t state[8];
uint64_t count;
unsigned char buf[64];
uint32_t state[8];
uint64_t count;
uint8_t buf[64];
} crypto_hash_sha256_state;
SODIUM_EXPORT
size_t crypto_hash_sha256_statebytes(void);
@@ -22,9 +22,9 @@ extern "C" {
#endif
typedef struct crypto_hash_sha512_state {
uint64_t state[8];
uint64_t count[2];
unsigned char buf[128];
uint64_t state[8];
uint64_t count[2];
uint8_t buf[128];
} crypto_hash_sha512_state;
SODIUM_EXPORT
size_t crypto_hash_sha512_statebytes(void);