Commit b8bfc32f authored by Niels Möller's avatar Niels Möller

Use size_t rather than unsigned for all hash-related functions.

parent fc05e544
...@@ -308,8 +308,8 @@ openssl_md5_init(void *ctx) ...@@ -308,8 +308,8 @@ openssl_md5_init(void *ctx)
static nettle_hash_update_func openssl_md5_update; static nettle_hash_update_func openssl_md5_update;
static void static void
openssl_md5_update(void *ctx, openssl_md5_update(void *ctx,
unsigned length, size_t length,
const uint8_t *src) const uint8_t *src)
{ {
MD5_Update(ctx, src, length); MD5_Update(ctx, src, length);
} }
...@@ -317,7 +317,7 @@ openssl_md5_update(void *ctx, ...@@ -317,7 +317,7 @@ openssl_md5_update(void *ctx,
static nettle_hash_digest_func openssl_md5_digest; static nettle_hash_digest_func openssl_md5_digest;
static void static void
openssl_md5_digest(void *ctx, openssl_md5_digest(void *ctx,
unsigned length, uint8_t *dst) size_t length, uint8_t *dst)
{ {
assert(length == SHA_DIGEST_LENGTH); assert(length == SHA_DIGEST_LENGTH);
MD5_Final(dst, ctx); MD5_Final(dst, ctx);
...@@ -344,7 +344,7 @@ openssl_sha1_init(void *ctx) ...@@ -344,7 +344,7 @@ openssl_sha1_init(void *ctx)
static nettle_hash_update_func openssl_sha1_update; static nettle_hash_update_func openssl_sha1_update;
static void static void
openssl_sha1_update(void *ctx, openssl_sha1_update(void *ctx,
unsigned length, size_t length,
const uint8_t *src) const uint8_t *src)
{ {
SHA1_Update(ctx, src, length); SHA1_Update(ctx, src, length);
...@@ -353,7 +353,7 @@ openssl_sha1_update(void *ctx, ...@@ -353,7 +353,7 @@ openssl_sha1_update(void *ctx,
static nettle_hash_digest_func openssl_sha1_digest; static nettle_hash_digest_func openssl_sha1_digest;
static void static void
openssl_sha1_digest(void *ctx, openssl_sha1_digest(void *ctx,
unsigned length, uint8_t *dst) size_t length, uint8_t *dst)
{ {
assert(length == SHA_DIGEST_LENGTH); assert(length == SHA_DIGEST_LENGTH);
SHA1_Final(dst, ctx); SHA1_Final(dst, ctx);
......
...@@ -43,7 +43,7 @@ gcm_aes_set_iv(struct gcm_aes_ctx *ctx, ...@@ -43,7 +43,7 @@ gcm_aes_set_iv(struct gcm_aes_ctx *ctx,
} }
void void
gcm_aes_update(struct gcm_aes_ctx *ctx, unsigned length, const uint8_t *data) gcm_aes_update(struct gcm_aes_ctx *ctx, size_t length, const uint8_t *data)
{ {
GCM_UPDATE(ctx, length, data); GCM_UPDATE(ctx, length, data);
} }
...@@ -64,7 +64,7 @@ gcm_aes_decrypt(struct gcm_aes_ctx *ctx, ...@@ -64,7 +64,7 @@ gcm_aes_decrypt(struct gcm_aes_ctx *ctx,
void void
gcm_aes_digest(struct gcm_aes_ctx *ctx, gcm_aes_digest(struct gcm_aes_ctx *ctx,
unsigned length, uint8_t *digest) size_t length, uint8_t *digest)
{ {
GCM_DIGEST(ctx, aes_encrypt, length, digest); GCM_DIGEST(ctx, aes_encrypt, length, digest);
......
...@@ -349,7 +349,7 @@ gcm_set_key(struct gcm_key *key, ...@@ -349,7 +349,7 @@ gcm_set_key(struct gcm_key *key,
static void static void
gcm_hash(const struct gcm_key *key, union gcm_block *x, gcm_hash(const struct gcm_key *key, union gcm_block *x,
unsigned length, const uint8_t *data) size_t length, const uint8_t *data)
{ {
for (; length >= GCM_BLOCK_SIZE; for (; length >= GCM_BLOCK_SIZE;
length -= GCM_BLOCK_SIZE, data += GCM_BLOCK_SIZE) length -= GCM_BLOCK_SIZE, data += GCM_BLOCK_SIZE)
...@@ -412,7 +412,7 @@ gcm_set_iv(struct gcm_ctx *ctx, const struct gcm_key *key, ...@@ -412,7 +412,7 @@ gcm_set_iv(struct gcm_ctx *ctx, const struct gcm_key *key,
void void
gcm_update(struct gcm_ctx *ctx, const struct gcm_key *key, gcm_update(struct gcm_ctx *ctx, const struct gcm_key *key,
unsigned length, const uint8_t *data) size_t length, const uint8_t *data)
{ {
assert(ctx->auth_size % GCM_BLOCK_SIZE == 0); assert(ctx->auth_size % GCM_BLOCK_SIZE == 0);
assert(ctx->data_size == 0); assert(ctx->data_size == 0);
...@@ -488,7 +488,7 @@ gcm_decrypt(struct gcm_ctx *ctx, const struct gcm_key *key, ...@@ -488,7 +488,7 @@ gcm_decrypt(struct gcm_ctx *ctx, const struct gcm_key *key,
void void
gcm_digest(struct gcm_ctx *ctx, const struct gcm_key *key, gcm_digest(struct gcm_ctx *ctx, const struct gcm_key *key,
void *cipher, nettle_crypt_func *f, void *cipher, nettle_crypt_func *f,
unsigned length, uint8_t *digest) size_t length, uint8_t *digest)
{ {
uint8_t buffer[GCM_BLOCK_SIZE]; uint8_t buffer[GCM_BLOCK_SIZE];
......
...@@ -98,7 +98,7 @@ gcm_set_iv(struct gcm_ctx *ctx, const struct gcm_key *key, ...@@ -98,7 +98,7 @@ gcm_set_iv(struct gcm_ctx *ctx, const struct gcm_key *key,
void void
gcm_update(struct gcm_ctx *ctx, const struct gcm_key *key, gcm_update(struct gcm_ctx *ctx, const struct gcm_key *key,
unsigned length, const uint8_t *data); size_t length, const uint8_t *data);
void void
gcm_encrypt(struct gcm_ctx *ctx, const struct gcm_key *key, gcm_encrypt(struct gcm_ctx *ctx, const struct gcm_key *key,
...@@ -113,7 +113,7 @@ gcm_decrypt(struct gcm_ctx *ctx, const struct gcm_key *key, ...@@ -113,7 +113,7 @@ gcm_decrypt(struct gcm_ctx *ctx, const struct gcm_key *key,
void void
gcm_digest(struct gcm_ctx *ctx, const struct gcm_key *key, gcm_digest(struct gcm_ctx *ctx, const struct gcm_key *key,
void *cipher, nettle_crypt_func *f, void *cipher, nettle_crypt_func *f,
unsigned length, uint8_t *digest); size_t length, uint8_t *digest);
/* Convenience macrology (not sure how useful it is) */ /* Convenience macrology (not sure how useful it is) */
...@@ -166,7 +166,7 @@ gcm_aes_set_iv(struct gcm_aes_ctx *ctx, ...@@ -166,7 +166,7 @@ gcm_aes_set_iv(struct gcm_aes_ctx *ctx,
void void
gcm_aes_update(struct gcm_aes_ctx *ctx, gcm_aes_update(struct gcm_aes_ctx *ctx,
unsigned length, const uint8_t *data); size_t length, const uint8_t *data);
void void
gcm_aes_encrypt(struct gcm_aes_ctx *ctx, gcm_aes_encrypt(struct gcm_aes_ctx *ctx,
...@@ -177,7 +177,7 @@ gcm_aes_decrypt(struct gcm_aes_ctx *ctx, ...@@ -177,7 +177,7 @@ gcm_aes_decrypt(struct gcm_aes_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src); size_t length, uint8_t *dst, const uint8_t *src);
void void
gcm_aes_digest(struct gcm_aes_ctx *ctx, unsigned length, uint8_t *digest); gcm_aes_digest(struct gcm_aes_ctx *ctx, size_t length, uint8_t *digest);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -525,7 +525,7 @@ gost_compute_sum_and_hash (struct gosthash94_ctx *ctx, const uint8_t *block) ...@@ -525,7 +525,7 @@ gost_compute_sum_and_hash (struct gosthash94_ctx *ctx, const uint8_t *block)
*/ */
void void
gosthash94_update (struct gosthash94_ctx *ctx, gosthash94_update (struct gosthash94_ctx *ctx,
unsigned length, const uint8_t *msg) size_t length, const uint8_t *msg)
{ {
unsigned index = (unsigned) ctx->length & 31; unsigned index = (unsigned) ctx->length & 31;
ctx->length += length; ctx->length += length;
...@@ -564,7 +564,7 @@ gosthash94_update (struct gosthash94_ctx *ctx, ...@@ -564,7 +564,7 @@ gosthash94_update (struct gosthash94_ctx *ctx,
*/ */
void void
gosthash94_digest (struct gosthash94_ctx *ctx, gosthash94_digest (struct gosthash94_ctx *ctx,
unsigned length, uint8_t *result) size_t length, uint8_t *result)
{ {
unsigned index = ctx->length & 31; unsigned index = ctx->length & 31;
uint32_t msg32[8]; uint32_t msg32[8];
......
...@@ -77,9 +77,9 @@ struct gosthash94_ctx ...@@ -77,9 +77,9 @@ struct gosthash94_ctx
void gosthash94_init(struct gosthash94_ctx *ctx); void gosthash94_init(struct gosthash94_ctx *ctx);
void gosthash94_update(struct gosthash94_ctx *ctx, void gosthash94_update(struct gosthash94_ctx *ctx,
unsigned length, const uint8_t *msg); size_t length, const uint8_t *msg);
void gosthash94_digest(struct gosthash94_ctx *ctx, void gosthash94_digest(struct gosthash94_ctx *ctx,
unsigned length, uint8_t *result); size_t length, uint8_t *result);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -31,21 +31,21 @@ ...@@ -31,21 +31,21 @@
void void
hmac_md5_set_key(struct hmac_md5_ctx *ctx, hmac_md5_set_key(struct hmac_md5_ctx *ctx,
unsigned key_length, const uint8_t *key) size_t key_length, const uint8_t *key)
{ {
HMAC_SET_KEY(ctx, &nettle_md5, key_length, key); HMAC_SET_KEY(ctx, &nettle_md5, key_length, key);
} }
void void
hmac_md5_update(struct hmac_md5_ctx *ctx, hmac_md5_update(struct hmac_md5_ctx *ctx,
unsigned length, const uint8_t *data) size_t length, const uint8_t *data)
{ {
md5_update(&ctx->state, length, data); md5_update(&ctx->state, length, data);
} }
void void
hmac_md5_digest(struct hmac_md5_ctx *ctx, hmac_md5_digest(struct hmac_md5_ctx *ctx,
unsigned length, uint8_t *digest) size_t length, uint8_t *digest)
{ {
HMAC_DIGEST(ctx, &nettle_md5, length, digest); HMAC_DIGEST(ctx, &nettle_md5, length, digest);
} }
...@@ -31,21 +31,21 @@ ...@@ -31,21 +31,21 @@
void void
hmac_ripemd160_set_key(struct hmac_ripemd160_ctx *ctx, hmac_ripemd160_set_key(struct hmac_ripemd160_ctx *ctx,
unsigned key_length, const uint8_t *key) size_t key_length, const uint8_t *key)
{ {
HMAC_SET_KEY(ctx, &nettle_ripemd160, key_length, key); HMAC_SET_KEY(ctx, &nettle_ripemd160, key_length, key);
} }
void void
hmac_ripemd160_update(struct hmac_ripemd160_ctx *ctx, hmac_ripemd160_update(struct hmac_ripemd160_ctx *ctx,
unsigned length, const uint8_t *data) size_t length, const uint8_t *data)
{ {
ripemd160_update(&ctx->state, length, data); ripemd160_update(&ctx->state, length, data);
} }
void void
hmac_ripemd160_digest(struct hmac_ripemd160_ctx *ctx, hmac_ripemd160_digest(struct hmac_ripemd160_ctx *ctx,
unsigned length, uint8_t *digest) size_t length, uint8_t *digest)
{ {
HMAC_DIGEST(ctx, &nettle_ripemd160, length, digest); HMAC_DIGEST(ctx, &nettle_ripemd160, length, digest);
} }
...@@ -31,21 +31,21 @@ ...@@ -31,21 +31,21 @@
void void
hmac_sha1_set_key(struct hmac_sha1_ctx *ctx, hmac_sha1_set_key(struct hmac_sha1_ctx *ctx,
unsigned key_length, const uint8_t *key) size_t key_length, const uint8_t *key)
{ {
HMAC_SET_KEY(ctx, &nettle_sha1, key_length, key); HMAC_SET_KEY(ctx, &nettle_sha1, key_length, key);
} }
void void
hmac_sha1_update(struct hmac_sha1_ctx *ctx, hmac_sha1_update(struct hmac_sha1_ctx *ctx,
unsigned length, const uint8_t *data) size_t length, const uint8_t *data)
{ {
sha1_update(&ctx->state, length, data); sha1_update(&ctx->state, length, data);
} }
void void
hmac_sha1_digest(struct hmac_sha1_ctx *ctx, hmac_sha1_digest(struct hmac_sha1_ctx *ctx,
unsigned length, uint8_t *digest) size_t length, uint8_t *digest)
{ {
HMAC_DIGEST(ctx, &nettle_sha1, length, digest); HMAC_DIGEST(ctx, &nettle_sha1, length, digest);
} }
...@@ -31,14 +31,14 @@ ...@@ -31,14 +31,14 @@
void void
hmac_sha224_set_key(struct hmac_sha224_ctx *ctx, hmac_sha224_set_key(struct hmac_sha224_ctx *ctx,
unsigned key_length, const uint8_t *key) size_t key_length, const uint8_t *key)
{ {
HMAC_SET_KEY(ctx, &nettle_sha224, key_length, key); HMAC_SET_KEY(ctx, &nettle_sha224, key_length, key);
} }
void void
hmac_sha224_digest(struct hmac_sha224_ctx *ctx, hmac_sha224_digest(struct hmac_sha224_ctx *ctx,
unsigned length, uint8_t *digest) size_t length, uint8_t *digest)
{ {
HMAC_DIGEST(ctx, &nettle_sha224, length, digest); HMAC_DIGEST(ctx, &nettle_sha224, length, digest);
} }
...@@ -31,21 +31,21 @@ ...@@ -31,21 +31,21 @@
void void
hmac_sha256_set_key(struct hmac_sha256_ctx *ctx, hmac_sha256_set_key(struct hmac_sha256_ctx *ctx,
unsigned key_length, const uint8_t *key) size_t key_length, const uint8_t *key)
{ {
HMAC_SET_KEY(ctx, &nettle_sha256, key_length, key); HMAC_SET_KEY(ctx, &nettle_sha256, key_length, key);
} }
void void
hmac_sha256_update(struct hmac_sha256_ctx *ctx, hmac_sha256_update(struct hmac_sha256_ctx *ctx,
unsigned length, const uint8_t *data) size_t length, const uint8_t *data)
{ {
sha256_update(&ctx->state, length, data); sha256_update(&ctx->state, length, data);
} }
void void
hmac_sha256_digest(struct hmac_sha256_ctx *ctx, hmac_sha256_digest(struct hmac_sha256_ctx *ctx,
unsigned length, uint8_t *digest) size_t length, uint8_t *digest)
{ {
HMAC_DIGEST(ctx, &nettle_sha256, length, digest); HMAC_DIGEST(ctx, &nettle_sha256, length, digest);
} }
...@@ -31,14 +31,14 @@ ...@@ -31,14 +31,14 @@
void void
hmac_sha384_set_key(struct hmac_sha512_ctx *ctx, hmac_sha384_set_key(struct hmac_sha512_ctx *ctx,
unsigned key_length, const uint8_t *key) size_t key_length, const uint8_t *key)
{ {
HMAC_SET_KEY(ctx, &nettle_sha384, key_length, key); HMAC_SET_KEY(ctx, &nettle_sha384, key_length, key);
} }
void void
hmac_sha384_digest(struct hmac_sha512_ctx *ctx, hmac_sha384_digest(struct hmac_sha512_ctx *ctx,
unsigned length, uint8_t *digest) size_t length, uint8_t *digest)
{ {
HMAC_DIGEST(ctx, &nettle_sha384, length, digest); HMAC_DIGEST(ctx, &nettle_sha384, length, digest);
} }
...@@ -31,21 +31,21 @@ ...@@ -31,21 +31,21 @@
void void
hmac_sha512_set_key(struct hmac_sha512_ctx *ctx, hmac_sha512_set_key(struct hmac_sha512_ctx *ctx,
unsigned key_length, const uint8_t *key) size_t key_length, const uint8_t *key)
{ {
HMAC_SET_KEY(ctx, &nettle_sha512, key_length, key); HMAC_SET_KEY(ctx, &nettle_sha512, key_length, key);
} }
void void
hmac_sha512_update(struct hmac_sha512_ctx *ctx, hmac_sha512_update(struct hmac_sha512_ctx *ctx,
unsigned length, const uint8_t *data) size_t length, const uint8_t *data)
{ {
sha512_update(&ctx->state, length, data); sha512_update(&ctx->state, length, data);
} }
void void
hmac_sha512_digest(struct hmac_sha512_ctx *ctx, hmac_sha512_digest(struct hmac_sha512_ctx *ctx,
unsigned length, uint8_t *digest) size_t length, uint8_t *digest)
{ {
HMAC_DIGEST(ctx, &nettle_sha512, length, digest); HMAC_DIGEST(ctx, &nettle_sha512, length, digest);
} }
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
void void
hmac_set_key(void *outer, void *inner, void *state, hmac_set_key(void *outer, void *inner, void *state,
const struct nettle_hash *hash, const struct nettle_hash *hash,
unsigned key_length, const uint8_t *key) size_t key_length, const uint8_t *key)
{ {
TMP_DECL(pad, uint8_t, NETTLE_MAX_HASH_BLOCK_SIZE); TMP_DECL(pad, uint8_t, NETTLE_MAX_HASH_BLOCK_SIZE);
TMP_ALLOC(pad, hash->block_size); TMP_ALLOC(pad, hash->block_size);
...@@ -85,7 +85,7 @@ hmac_set_key(void *outer, void *inner, void *state, ...@@ -85,7 +85,7 @@ hmac_set_key(void *outer, void *inner, void *state,
void void
hmac_update(void *state, hmac_update(void *state,
const struct nettle_hash *hash, const struct nettle_hash *hash,
unsigned length, const uint8_t *data) size_t length, const uint8_t *data)
{ {
hash->update(state, length, data); hash->update(state, length, data);
} }
...@@ -93,7 +93,7 @@ hmac_update(void *state, ...@@ -93,7 +93,7 @@ hmac_update(void *state,
void void
hmac_digest(const void *outer, const void *inner, void *state, hmac_digest(const void *outer, const void *inner, void *state,
const struct nettle_hash *hash, const struct nettle_hash *hash,
unsigned length, uint8_t *dst) size_t length, uint8_t *dst)
{ {
TMP_DECL(digest, uint8_t, NETTLE_MAX_HASH_DIGEST_SIZE); TMP_DECL(digest, uint8_t, NETTLE_MAX_HASH_DIGEST_SIZE);
TMP_ALLOC(digest, hash->digest_size); TMP_ALLOC(digest, hash->digest_size);
......
...@@ -64,19 +64,19 @@ extern "C" { ...@@ -64,19 +64,19 @@ extern "C" {
void void
hmac_set_key(void *outer, void *inner, void *state, hmac_set_key(void *outer, void *inner, void *state,
const struct nettle_hash *hash, const struct nettle_hash *hash,
unsigned length, const uint8_t *key); size_t length, const uint8_t *key);
/* This function is not strictly needed, it's s just the same as the /* This function is not strictly needed, it's s just the same as the
* hash update function. */ * hash update function. */
void void
hmac_update(void *state, hmac_update(void *state,
const struct nettle_hash *hash, const struct nettle_hash *hash,
unsigned length, const uint8_t *data); size_t length, const uint8_t *data);
void void
hmac_digest(const void *outer, const void *inner, void *state, hmac_digest(const void *outer, const void *inner, void *state,
const struct nettle_hash *hash, const struct nettle_hash *hash,
unsigned length, uint8_t *digest); size_t length, uint8_t *digest);
#define HMAC_CTX(type) \ #define HMAC_CTX(type) \
...@@ -97,15 +97,15 @@ struct hmac_md5_ctx HMAC_CTX(struct md5_ctx); ...@@ -97,15 +97,15 @@ struct hmac_md5_ctx HMAC_CTX(struct md5_ctx);
void void
hmac_md5_set_key(struct hmac_md5_ctx *ctx, hmac_md5_set_key(struct hmac_md5_ctx *ctx,
unsigned key_length, const uint8_t *key); size_t key_length, const uint8_t *key);
void void
hmac_md5_update(struct hmac_md5_ctx *ctx, hmac_md5_update(struct hmac_md5_ctx *ctx,
unsigned length, const uint8_t *data); size_t length, const uint8_t *data);
void void
hmac_md5_digest(struct hmac_md5_ctx *ctx, hmac_md5_digest(struct hmac_md5_ctx *ctx,
unsigned length, uint8_t *digest); size_t length, uint8_t *digest);
/* hmac-ripemd160 */ /* hmac-ripemd160 */
...@@ -113,15 +113,15 @@ struct hmac_ripemd160_ctx HMAC_CTX(struct ripemd160_ctx); ...@@ -113,15 +113,15 @@ struct hmac_ripemd160_ctx HMAC_CTX(struct ripemd160_ctx);
void void
hmac_ripemd160_set_key(struct hmac_ripemd160_ctx *ctx, hmac_ripemd160_set_key(struct hmac_ripemd160_ctx *ctx,
unsigned key_length, const uint8_t *key); size_t key_length, const uint8_t *key);
void void
hmac_ripemd160_update(struct hmac_ripemd160_ctx *ctx, hmac_ripemd160_update(struct hmac_ripemd160_ctx *ctx,
unsigned length, const uint8_t *data); size_t length, const uint8_t *data);
void void
hmac_ripemd160_digest(struct hmac_ripemd160_ctx *ctx, hmac_ripemd160_digest(struct hmac_ripemd160_ctx *ctx,
unsigned length, uint8_t *digest); size_t length, uint8_t *digest);
/* hmac-sha1 */ /* hmac-sha1 */
...@@ -129,71 +129,71 @@ struct hmac_sha1_ctx HMAC_CTX(struct sha1_ctx); ...@@ -129,71 +129,71 @@ struct hmac_sha1_ctx HMAC_CTX(struct sha1_ctx);
void void
hmac_sha1_set_key(struct hmac_sha1_ctx *ctx, hmac_sha1_set_key(struct hmac_sha1_ctx *ctx,
unsigned key_length, const uint8_t *key); size_t key_length, const uint8_t *key);
void void
hmac_sha1_update(struct hmac_sha1_ctx *ctx, hmac_sha1_update(struct hmac_sha1_ctx *ctx,
unsigned length, const uint8_t *data); size_t length, const uint8_t *data);
void void
hmac_sha1_digest(struct hmac_sha1_ctx *ctx, hmac_sha1_digest(struct hmac_sha1_ctx *ctx,
unsigned length, uint8_t *digest); size_t length, uint8_t *digest);
/* hmac-sha256 */ /* hmac-sha256 */
struct hmac_sha256_ctx HMAC_CTX(struct sha256_ctx); struct hmac_sha256_ctx HMAC_CTX(struct sha256_ctx);
void void
hmac_sha256_set_key(struct hmac_sha256_ctx *ctx, hmac_sha256_set_key(struct hmac_sha256_ctx *ctx,
unsigned key_length, const uint8_t *key); size_t key_length, const uint8_t *key);
void void
hmac_sha256_update(struct hmac_sha256_ctx *ctx, hmac_sha256_update(struct hmac_sha256_ctx *ctx,
unsigned length, const uint8_t *data); size_t length, const uint8_t *data);
void