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)
static nettle_hash_update_func openssl_md5_update;
static void
openssl_md5_update(void *ctx,
unsigned length,
const uint8_t *src)
size_t length,
const uint8_t *src)
{
MD5_Update(ctx, src, length);
}
......@@ -317,7 +317,7 @@ openssl_md5_update(void *ctx,
static nettle_hash_digest_func openssl_md5_digest;
static void
openssl_md5_digest(void *ctx,
unsigned length, uint8_t *dst)
size_t length, uint8_t *dst)
{
assert(length == SHA_DIGEST_LENGTH);
MD5_Final(dst, ctx);
......@@ -344,7 +344,7 @@ openssl_sha1_init(void *ctx)
static nettle_hash_update_func openssl_sha1_update;
static void
openssl_sha1_update(void *ctx,
unsigned length,
size_t length,
const uint8_t *src)
{
SHA1_Update(ctx, src, length);
......@@ -353,7 +353,7 @@ openssl_sha1_update(void *ctx,
static nettle_hash_digest_func openssl_sha1_digest;
static void
openssl_sha1_digest(void *ctx,
unsigned length, uint8_t *dst)
size_t length, uint8_t *dst)
{
assert(length == SHA_DIGEST_LENGTH);
SHA1_Final(dst, ctx);
......
......@@ -43,7 +43,7 @@ gcm_aes_set_iv(struct gcm_aes_ctx *ctx,
}
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);
}
......@@ -64,7 +64,7 @@ gcm_aes_decrypt(struct gcm_aes_ctx *ctx,
void
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);
......
......@@ -349,7 +349,7 @@ gcm_set_key(struct gcm_key *key,
static void
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;
length -= GCM_BLOCK_SIZE, data += GCM_BLOCK_SIZE)
......@@ -412,7 +412,7 @@ gcm_set_iv(struct gcm_ctx *ctx, const struct gcm_key *key,
void
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->data_size == 0);
......@@ -488,7 +488,7 @@ gcm_decrypt(struct gcm_ctx *ctx, const struct gcm_key *key,
void
gcm_digest(struct gcm_ctx *ctx, const struct gcm_key *key,
void *cipher, nettle_crypt_func *f,
unsigned length, uint8_t *digest)
size_t length, uint8_t *digest)
{
uint8_t buffer[GCM_BLOCK_SIZE];
......
......@@ -98,7 +98,7 @@ gcm_set_iv(struct gcm_ctx *ctx, const struct gcm_key *key,
void
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
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,
void
gcm_digest(struct gcm_ctx *ctx, const struct gcm_key *key,
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) */
......@@ -166,7 +166,7 @@ gcm_aes_set_iv(struct gcm_aes_ctx *ctx,
void
gcm_aes_update(struct gcm_aes_ctx *ctx,
unsigned length, const uint8_t *data);
size_t length, const uint8_t *data);
void
gcm_aes_encrypt(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);
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
}
......
......@@ -525,7 +525,7 @@ gost_compute_sum_and_hash (struct gosthash94_ctx *ctx, const uint8_t *block)
*/
void
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;
ctx->length += length;
......@@ -564,7 +564,7 @@ gosthash94_update (struct gosthash94_ctx *ctx,
*/
void
gosthash94_digest (struct gosthash94_ctx *ctx,
unsigned length, uint8_t *result)
size_t length, uint8_t *result)
{
unsigned index = ctx->length & 31;
uint32_t msg32[8];
......
......@@ -77,9 +77,9 @@ struct gosthash94_ctx
void gosthash94_init(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,
unsigned length, uint8_t *result);
size_t length, uint8_t *result);
#ifdef __cplusplus
}
......
......@@ -31,21 +31,21 @@
void
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);
}
void
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);
}
void
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);
}
......@@ -31,21 +31,21 @@
void
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);
}
void
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);
}
void
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);
}
......@@ -31,21 +31,21 @@
void
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);
}
void
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);
}
void
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);
}
......@@ -31,14 +31,14 @@
void
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);
}
void
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);
}
......@@ -31,21 +31,21 @@
void
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);
}
void
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);
}
void
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);
}
......@@ -31,14 +31,14 @@
void
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);
}
void
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);
}
......@@ -31,21 +31,21 @@
void
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);
}
void
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);
}
void
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);
}
......@@ -43,7 +43,7 @@
void
hmac_set_key(void *outer, void *inner, void *state,
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_ALLOC(pad, hash->block_size);
......@@ -85,7 +85,7 @@ hmac_set_key(void *outer, void *inner, void *state,
void
hmac_update(void *state,
const struct nettle_hash *hash,
unsigned length, const uint8_t *data)
size_t length, const uint8_t *data)
{
hash->update(state, length, data);
}
......@@ -93,7 +93,7 @@ hmac_update(void *state,
void
hmac_digest(const void *outer, const void *inner, void *state,
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_ALLOC(digest, hash->digest_size);
......
......@@ -64,19 +64,19 @@ extern "C" {
void
hmac_set_key(void *outer, void *inner, void *state,
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
* hash update function. */
void
hmac_update(void *state,
const struct nettle_hash *hash,
unsigned length, const uint8_t *data);
size_t length, const uint8_t *data);
void
hmac_digest(const void *outer, const void *inner, void *state,
const struct nettle_hash *hash,
unsigned length, uint8_t *digest);
size_t length, uint8_t *digest);
#define HMAC_CTX(type) \
......@@ -97,15 +97,15 @@ struct hmac_md5_ctx HMAC_CTX(struct md5_ctx);
void
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
hmac_md5_update(struct hmac_md5_ctx *ctx,
unsigned length, const uint8_t *data);
size_t length, const uint8_t *data);
void
hmac_md5_digest(struct hmac_md5_ctx *ctx,
unsigned length, uint8_t *digest);
size_t length, uint8_t *digest);
/* hmac-ripemd160 */
......@@ -113,15 +113,15 @@ struct hmac_ripemd160_ctx HMAC_CTX(struct ripemd160_ctx);
void
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
hmac_ripemd160_update(struct hmac_ripemd160_ctx *ctx,
unsigned length, const uint8_t *data);
size_t length, const uint8_t *data);
void
hmac_ripemd160_digest(struct hmac_ripemd160_ctx *ctx,
unsigned length, uint8_t *digest);
size_t length, uint8_t *digest);
/* hmac-sha1 */
......@@ -129,71 +129,71 @@ struct hmac_sha1_ctx HMAC_CTX(struct sha1_ctx);
void
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
hmac_sha1_update(struct hmac_sha1_ctx *ctx,
unsigned length, const uint8_t *data);
size_t length, const uint8_t *data);
void
hmac_sha1_digest(struct hmac_sha1_ctx *ctx,
unsigned length, uint8_t *digest);
size_t length, uint8_t *digest);
/* hmac-sha256 */
struct hmac_sha256_ctx HMAC_CTX(struct sha256_ctx);
void
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
hmac_sha256_update(struct hmac_sha256_ctx *ctx,
unsigned length, const uint8_t *data);
size_t length, const uint8_t *data);
void
hmac_sha256_digest(struct hmac_sha256_ctx *ctx,
unsigned length, uint8_t *digest);
size_t length, uint8_t *digest);
/* hmac-sha224 */
#define hmac_sha224_ctx hmac_sha256_ctx
void
hmac_sha224_set_key(struct hmac_sha224_ctx *ctx,
unsigned key_length, const uint8_t *key);
size_t key_length, const uint8_t *key);
#define hmac_sha224_update nettle_hmac_sha256_update
void
hmac_sha224_digest(struct hmac_sha224_ctx *ctx,
unsigned length, uint8_t *digest);
size_t length, uint8_t *digest);
/* hmac-sha512 */
struct hmac_sha512_ctx HMAC_CTX(struct sha512_ctx);
void
hmac_sha512_set_key(struct hmac_sha512_ctx *ctx,
unsigned key_length, const uint8_t *key);
size_t key_length, const uint8_t *key);
void
hmac_sha512_update(struct hmac_sha512_ctx *ctx,
unsigned length, const uint8_t *data);
size_t length, const uint8_t *data);
void
hmac_sha512_digest(struct hmac_sha512_ctx *ctx,
unsigned length, uint8_t *digest);
size_t length, uint8_t *digest);
/* hmac-sha384 */
#define hmac_sha384_ctx hmac_sha512_ctx
void
hmac_sha384_set_key(struct hmac_sha512_ctx *ctx,
unsigned key_length, const uint8_t *key);
size_t key_length, const uint8_t *key);
#define hmac_sha384_update nettle_hmac_sha512_update
void
hmac_sha384_digest(struct hmac_sha512_ctx *ctx,
unsigned length, uint8_t *digest);
size_t length, uint8_t *digest);
#ifdef __cplusplus
}
......
......@@ -106,7 +106,7 @@ md2_init(struct md2_ctx *ctx)
void
md2_update(struct md2_ctx *ctx,
unsigned length,
size_t length,
const uint8_t *data)
{
MD_UPDATE(ctx, length, data, md2_transform, (void)0);
......@@ -114,7 +114,7 @@ md2_update(struct md2_ctx *ctx,
void
md2_digest(struct md2_ctx *ctx,
unsigned length,
size_t length,
uint8_t *digest)
{
unsigned left;
......
......@@ -53,12 +53,12 @@ md2_init(struct md2_ctx *ctx);
void
md2_update(struct md2_ctx *ctx,
unsigned length,
size_t length,
const uint8_t *data);
void
md2_digest(struct md2_ctx *ctx,
unsigned length,
size_t length,
uint8_t *digest);
......
......@@ -67,7 +67,7 @@ md4_init(struct md4_ctx *ctx)
void
md4_update(struct md4_ctx *ctx,
unsigned length,
size_t length,
const uint8_t *data)
{
MD_UPDATE(ctx, length, data, md4_compress, MD_INCR(ctx));
......@@ -75,7 +75,7 @@ md4_update(struct md4_ctx *ctx,
void
md4_digest(struct md4_ctx *ctx,
unsigned length,
size_t length,
uint8_t *digest)
{
uint32_t data[MD4_DATA_LENGTH];
......
......@@ -57,12 +57,12 @@ md4_init(struct md4_ctx *ctx);
void
md4_update(struct md4_ctx *ctx,
unsigned length,
size_t length,
const uint8_t *data);
void
md4_digest(struct md4_ctx *ctx,
unsigned length,
size_t length,
uint8_t *digest);
......
......@@ -57,7 +57,7 @@ md5_init(struct md5_ctx *ctx)
void
md5_update(struct md5_ctx *ctx,
unsigned length,
size_t length,
const uint8_t *data)
{
MD_UPDATE(ctx, length, data, COMPRESS, MD_INCR(ctx));
......@@ -65,7 +65,7 @@ md5_update(struct md5_ctx *ctx,
void
md5_digest(struct md5_ctx *ctx,
unsigned length,
size_t length,
uint8_t *digest)
{
uint32_t high, low;
......
......@@ -56,12 +56,12 @@ md5_init(struct md5_ctx *ctx);
void
md5_update(struct md5_ctx *ctx,
unsigned length,
size_t length,
const uint8_t *data);
void
md5_digest(struct md5_ctx *ctx,
unsigned length,
size_t length,
uint8_t *digest);
/* Internal compression function. STATE points to 4 uint32_t words,
......
......@@ -83,12 +83,12 @@ struct nettle_aead
{
const char *name;
unsigned context_size;
size_t context_size;
/* Block size of the input, and the size of the output digest */
unsigned block_size;
size_t block_size;
/* Suggested key size; other sizes are sometimes possible. */
unsigned key_size;
size_t key_size;
nettle_set_key_func *set_key;
nettle_set_key_func *set_iv;
......
......@@ -60,10 +60,10 @@ typedef void nettle_crypt_func(void *ctx,
/* Hash algorithms */
typedef void nettle_hash_init_func(void *ctx);
typedef void nettle_hash_update_func(void *ctx,
unsigned length,
size_t length,
const uint8_t *src);
typedef void nettle_hash_digest_func(void *ctx,
unsigned length, uint8_t *dst);
size_t length, uint8_t *dst);
/* ASCII armor codecs. NOTE: Experimental and subject to change. */
......
......@@ -165,13 +165,13 @@ ripemd160_init(struct ripemd160_ctx *ctx)
* of DATA with length LENGTH.
*/
void
ripemd160_update(struct ripemd160_ctx *ctx, unsigned length, const uint8_t *data)
ripemd160_update(struct ripemd160_ctx *ctx, size_t length, const uint8_t *data)
{
MD_UPDATE(ctx, length, data, COMPRESS, MD_INCR(ctx));
}
void
ripemd160_digest(struct ripemd160_ctx *ctx, unsigned length, uint8_t *digest)
ripemd160_digest(struct ripemd160_ctx *ctx, size_t length, uint8_t *digest)
{
uint32_t high, low;
......
......@@ -58,12 +58,12 @@ ripemd160_init(struct ripemd160_ctx *ctx);
void
ripemd160_update(struct ripemd160_ctx *ctx,
unsigned length,
size_t length,
const uint8_t *data);
void
ripemd160_digest(struct ripemd160_ctx *ctx,
unsigned length,
size_t length,
uint8_t *digest);
/* Internal compression function. STATE points to 5 uint32_t words,
......
......@@ -76,14 +76,14 @@ sha1_init(struct sha1_ctx *ctx)
void
sha1_update(struct sha1_ctx *ctx,
unsigned length, const uint8_t *data)
size_t length, const uint8_t *data)
{
MD_UPDATE (ctx, length, data, COMPRESS, MD_INCR(ctx));
}
void