Commit 3eb603d0 authored by Niels Möller's avatar Niels Möller
Browse files

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

parent 2b49c179
......@@ -87,7 +87,7 @@
void
camellia_set_encrypt_key(struct camellia_ctx *ctx,
unsigned length, const uint8_t *key)
size_t length, const uint8_t *key)
{
uint64_t k0, k1;
......
......@@ -61,11 +61,11 @@ struct camellia_ctx
void
camellia_set_encrypt_key(struct camellia_ctx *ctx,
unsigned length, const uint8_t *key);
size_t length, const uint8_t *key);
void
camellia_set_decrypt_key(struct camellia_ctx *ctx,
unsigned length, const uint8_t *key);
size_t length, const uint8_t *key);
void
camellia_invert_key(struct camellia_ctx *dst,
......@@ -73,7 +73,7 @@ camellia_invert_key(struct camellia_ctx *dst,
void
camellia_crypt(const struct camellia_ctx *ctx,
unsigned length, uint8_t *dst,
size_t length, uint8_t *dst,
const uint8_t *src);
#ifdef __cplusplus
}
......
......@@ -72,7 +72,7 @@
void
cast128_encrypt(const struct cast128_ctx *ctx,
unsigned length, uint8_t *dst,
size_t length, uint8_t *dst,
const uint8_t *src)
{
FOR_BLOCKS(length, dst, src, CAST128_BLOCK_SIZE)
......@@ -116,7 +116,7 @@ cast128_encrypt(const struct cast128_ctx *ctx,
void
cast128_decrypt(const struct cast128_ctx *ctx,
unsigned length, uint8_t *dst,
size_t length, uint8_t *dst,
const uint8_t *src)
{
FOR_BLOCKS(length, dst, src, CAST128_BLOCK_SIZE)
......@@ -161,7 +161,7 @@ cast128_decrypt(const struct cast128_ctx *ctx,
void
cast128_set_key(struct cast128_ctx *ctx,
unsigned keybytes, const uint8_t *rawkey)
size_t keybytes, const uint8_t *rawkey)
{
uint32_t t[4], z[4], x[4];
unsigned i;
......
......@@ -59,15 +59,15 @@ struct cast128_ctx
void
cast128_set_key(struct cast128_ctx *ctx,
unsigned length, const uint8_t *key);
size_t length, const uint8_t *key);
void
cast128_encrypt(const struct cast128_ctx *ctx,
unsigned length, uint8_t *dst,
size_t length, uint8_t *dst,
const uint8_t *src);
void
cast128_decrypt(const struct cast128_ctx *ctx,
unsigned length, uint8_t *dst,
size_t length, uint8_t *dst,
const uint8_t *src);
#ifdef __cplusplus
......
......@@ -38,8 +38,8 @@
void
cbc_encrypt(void *ctx, nettle_crypt_func *f,
unsigned block_size, uint8_t *iv,
unsigned length, uint8_t *dst,
size_t block_size, uint8_t *iv,
size_t length, uint8_t *dst,
const uint8_t *src)
{
assert(!(length % block_size));
......@@ -57,8 +57,8 @@ cbc_encrypt(void *ctx, nettle_crypt_func *f,
void
cbc_decrypt(void *ctx, nettle_crypt_func *f,
unsigned block_size, uint8_t *iv,
unsigned length, uint8_t *dst,
size_t block_size, uint8_t *iv,
size_t length, uint8_t *dst,
const uint8_t *src)
{
assert(!(length % block_size));
......@@ -90,7 +90,7 @@ cbc_decrypt(void *ctx, nettle_crypt_func *f,
TMP_DECL(buffer, uint8_t, CBC_BUFFER_LIMIT);
TMP_DECL(initial_iv, uint8_t, NETTLE_MAX_CIPHER_BLOCK_SIZE);
unsigned buffer_size;
size_t buffer_size;
if (length <= CBC_BUFFER_LIMIT)
buffer_size = length;
......
......@@ -38,14 +38,14 @@ extern "C" {
void
cbc_encrypt(void *ctx, nettle_crypt_func *f,
unsigned block_size, uint8_t *iv,
unsigned length, uint8_t *dst,
size_t block_size, uint8_t *iv,
size_t length, uint8_t *dst,
const uint8_t *src);
void
cbc_decrypt(void *ctx, nettle_crypt_func *f,
unsigned block_size, uint8_t *iv,
unsigned length, uint8_t *dst,
size_t block_size, uint8_t *iv,
size_t length, uint8_t *dst,
const uint8_t *src);
#define CBC_CTX(type, size) \
......
......@@ -41,8 +41,8 @@
void
ctr_crypt(void *ctx, nettle_crypt_func *f,
unsigned block_size, uint8_t *ctr,
unsigned length, uint8_t *dst,
size_t block_size, uint8_t *ctr,
size_t length, uint8_t *dst,
const uint8_t *src)
{
if (src != dst)
......@@ -55,7 +55,7 @@ ctr_crypt(void *ctx, nettle_crypt_func *f,
}
else
{
unsigned left;
size_t left;
uint8_t *p;
for (p = dst, left = length;
......@@ -85,7 +85,7 @@ ctr_crypt(void *ctx, nettle_crypt_func *f,
if (length > block_size)
{
TMP_DECL(buffer, uint8_t, NBLOCKS * NETTLE_MAX_CIPHER_BLOCK_SIZE);
unsigned chunk = NBLOCKS * block_size;
size_t chunk = NBLOCKS * block_size;
TMP_ALLOC(buffer, chunk);
......
......@@ -38,8 +38,8 @@ extern "C" {
void
ctr_crypt(void *ctx, nettle_crypt_func *f,
unsigned block_size, uint8_t *ctr,
unsigned length, uint8_t *dst,
size_t block_size, uint8_t *ctr,
size_t length, uint8_t *dst,
const uint8_t *src);
#define CTR_CTX(type, size) \
......
......@@ -65,9 +65,9 @@ parity_16[16] =
#define PARITY(x) (parity_16[(x)&0xf] ^ parity_16[((x)>>4) & 0xf])
int
des_check_parity(unsigned length, const uint8_t *key)
des_check_parity(size_t length, const uint8_t *key)
{
unsigned i;
size_t i;
for (i = 0; i<length; i++)
if (!PARITY(key[i]))
return 0;
......@@ -76,10 +76,10 @@ des_check_parity(unsigned length, const uint8_t *key)
}
void
des_fix_parity(unsigned length, uint8_t *dst,
des_fix_parity(size_t length, uint8_t *dst,
const uint8_t *src)
{
unsigned i;
size_t i;
for (i = 0; i<length; i++)
dst[i] = src[i] ^ PARITY(src[i]) ^ 1;
}
......@@ -265,7 +265,7 @@ des_set_key(struct des_ctx *ctx, const uint8_t *key)
void
des_encrypt(const struct des_ctx *ctx,
unsigned length, uint8_t *dst,
size_t length, uint8_t *dst,
const uint8_t *src)
{
assert(!(length % DES_BLOCK_SIZE));
......@@ -281,7 +281,7 @@ des_encrypt(const struct des_ctx *ctx,
void
des_decrypt(const struct des_ctx *ctx,
unsigned length, uint8_t *dst,
size_t length, uint8_t *dst,
const uint8_t *src)
{
assert(!(length % DES_BLOCK_SIZE));
......
......@@ -68,18 +68,18 @@ des_set_key(struct des_ctx *ctx, const uint8_t *key);
void
des_encrypt(const struct des_ctx *ctx,
unsigned length, uint8_t *dst,
size_t length, uint8_t *dst,
const uint8_t *src);
void
des_decrypt(const struct des_ctx *ctx,
unsigned length, uint8_t *dst,
size_t length, uint8_t *dst,
const uint8_t *src);
int
des_check_parity(unsigned length, const uint8_t *key);
des_check_parity(size_t length, const uint8_t *key);
void
des_fix_parity(unsigned length, uint8_t *dst,
des_fix_parity(size_t length, uint8_t *dst,
const uint8_t *src);
#define DES3_KEY_SIZE 24
......@@ -97,11 +97,11 @@ des3_set_key(struct des3_ctx *ctx, const uint8_t *key);
void
des3_encrypt(const struct des3_ctx *ctx,
unsigned length, uint8_t *dst,
size_t length, uint8_t *dst,
const uint8_t *src);
void
des3_decrypt(const struct des3_ctx *ctx,
unsigned length, uint8_t *dst,
size_t length, uint8_t *dst,
const uint8_t *src);
#ifdef __cplusplus
......
......@@ -49,7 +49,7 @@ des3_set_key(struct des3_ctx *ctx, const uint8_t *key)
void
des3_encrypt(const struct des3_ctx *ctx,
unsigned length, uint8_t *dst,
size_t length, uint8_t *dst,
const uint8_t *src)
{
des_encrypt(&ctx->des[0],
......@@ -62,7 +62,7 @@ des3_encrypt(const struct des3_ctx *ctx,
void
des3_decrypt(const struct des3_ctx *ctx,
unsigned length, uint8_t *dst,
size_t length, uint8_t *dst,
const uint8_t *src)
{
des_decrypt(&ctx->des[2],
......
......@@ -52,21 +52,21 @@
/* AES */
static nettle_set_key_func openssl_aes_set_encrypt_key;
static void
openssl_aes_set_encrypt_key(void *ctx, unsigned length, const uint8_t *key)
openssl_aes_set_encrypt_key(void *ctx, size_t length, const uint8_t *key)
{
AES_set_encrypt_key(key, length * 8, ctx);
}
static nettle_set_key_func openssl_aes_set_decrypt_key;
static void
openssl_aes_set_decrypt_key(void *ctx, unsigned length, const uint8_t *key)
openssl_aes_set_decrypt_key(void *ctx, size_t length, const uint8_t *key)
{
AES_set_decrypt_key(key, length * 8, ctx);
}
static nettle_crypt_func openssl_aes_encrypt;
static void
openssl_aes_encrypt(void *ctx, unsigned length,
openssl_aes_encrypt(void *ctx, size_t length,
uint8_t *dst, const uint8_t *src)
{
assert (!(length % AES_BLOCK_SIZE));
......@@ -81,7 +81,7 @@ openssl_aes_encrypt(void *ctx, unsigned length,
static nettle_crypt_func openssl_aes_decrypt;
static void
openssl_aes_decrypt(void *ctx, unsigned length,
openssl_aes_decrypt(void *ctx, size_t length,
uint8_t *dst, const uint8_t *src)
{
assert (!(length % AES_BLOCK_SIZE));
......@@ -127,14 +127,14 @@ nettle_openssl_aes256 = {
/* Arcfour */
static nettle_set_key_func openssl_arcfour_set_key;
static void
openssl_arcfour_set_key(void *ctx, unsigned length, const uint8_t *key)
openssl_arcfour_set_key(void *ctx, size_t length, const uint8_t *key)
{
RC4_set_key(ctx, length, key);
}
static nettle_crypt_func openssl_arcfour_crypt;
static void
openssl_arcfour_crypt(void *ctx, unsigned length,
openssl_arcfour_crypt(void *ctx, size_t length,
uint8_t *dst, const uint8_t *src)
{
RC4(ctx, length, src, dst);
......@@ -151,14 +151,14 @@ nettle_openssl_arcfour128 = {
/* Blowfish */
static nettle_set_key_func openssl_bf_set_key;
static void
openssl_bf_set_key(void *ctx, unsigned length, const uint8_t *key)
openssl_bf_set_key(void *ctx, size_t length, const uint8_t *key)
{
BF_set_key(ctx, length, key);
}
static nettle_crypt_func openssl_bf_encrypt;
static void
openssl_bf_encrypt(void *ctx, unsigned length,
openssl_bf_encrypt(void *ctx, size_t length,
uint8_t *dst, const uint8_t *src)
{
assert (!(length % BF_BLOCK));
......@@ -173,7 +173,7 @@ openssl_bf_encrypt(void *ctx, unsigned length,
static nettle_crypt_func openssl_bf_decrypt;
static void
openssl_bf_decrypt(void *ctx, unsigned length,
openssl_bf_decrypt(void *ctx, size_t length,
uint8_t *dst, const uint8_t *src)
{
assert (!(length % BF_BLOCK));
......@@ -198,7 +198,7 @@ nettle_openssl_blowfish128 = {
/* DES */
static nettle_set_key_func openssl_des_set_key;
static void
openssl_des_set_key(void *ctx, unsigned length, const uint8_t *key)
openssl_des_set_key(void *ctx, size_t length, const uint8_t *key)
{
assert(length == 8);
/* Not sure what "unchecked" means. We want to ignore parity bits,
......@@ -212,7 +212,7 @@ openssl_des_set_key(void *ctx, unsigned length, const uint8_t *key)
static nettle_crypt_func openssl_des_encrypt;
static void
openssl_des_encrypt(void *ctx, unsigned length,
openssl_des_encrypt(void *ctx, size_t length,
uint8_t *dst, const uint8_t *src)
{
assert (!(length % DES_BLOCK_SIZE));
......@@ -227,7 +227,7 @@ openssl_des_encrypt(void *ctx, unsigned length,
static nettle_crypt_func openssl_des_decrypt;
static void
openssl_des_decrypt(void *ctx, unsigned length,
openssl_des_decrypt(void *ctx, size_t length,
uint8_t *dst, const uint8_t *src)
{
assert (!(length % DES_BLOCK_SIZE));
......@@ -252,14 +252,14 @@ nettle_openssl_des = {
/* Cast128 */
static nettle_set_key_func openssl_cast_set_key;
static void
openssl_cast_set_key(void *ctx, unsigned length, const uint8_t *key)
openssl_cast_set_key(void *ctx, size_t length, const uint8_t *key)
{
CAST_set_key(ctx, length, key);
}
static nettle_crypt_func openssl_cast_encrypt;
static void
openssl_cast_encrypt(void *ctx, unsigned length,
openssl_cast_encrypt(void *ctx, size_t length,
uint8_t *dst, const uint8_t *src)
{
assert (!(length % CAST_BLOCK));
......@@ -274,7 +274,7 @@ openssl_cast_encrypt(void *ctx, unsigned length,
static nettle_crypt_func openssl_cast_decrypt;
static void
openssl_cast_decrypt(void *ctx, unsigned length,
openssl_cast_decrypt(void *ctx, size_t length,
uint8_t *dst, const uint8_t *src)
{
assert (!(length % CAST_BLOCK));
......
......@@ -30,14 +30,14 @@
#include "gcm.h"
void
gcm_aes_set_key(struct gcm_aes_ctx *ctx, unsigned length, const uint8_t *key)
gcm_aes_set_key(struct gcm_aes_ctx *ctx, size_t length, const uint8_t *key)
{
GCM_SET_KEY(ctx, aes_set_encrypt_key, aes_encrypt, length, key);
}
void
gcm_aes_set_iv(struct gcm_aes_ctx *ctx,
unsigned length, const uint8_t *iv)
size_t length, const uint8_t *iv)
{
GCM_SET_IV(ctx, length, iv);
}
......@@ -50,14 +50,14 @@ gcm_aes_update(struct gcm_aes_ctx *ctx, unsigned length, const uint8_t *data)
void
gcm_aes_encrypt(struct gcm_aes_ctx *ctx,
unsigned length, uint8_t *dst, const uint8_t *src)
size_t length, uint8_t *dst, const uint8_t *src)
{
GCM_ENCRYPT(ctx, aes_encrypt, length, dst, src);
}
void
gcm_aes_decrypt(struct gcm_aes_ctx *ctx,
unsigned length, uint8_t *dst, const uint8_t *src)
size_t length, uint8_t *dst, const uint8_t *src)
{
GCM_DECRYPT(ctx, aes_encrypt, length, dst, src);
}
......
......@@ -385,7 +385,7 @@ gcm_hash_sizes(const struct gcm_key *key, union gcm_block *x,
*/
void
gcm_set_iv(struct gcm_ctx *ctx, const struct gcm_key *key,
unsigned length, const uint8_t *iv)
size_t length, const uint8_t *iv)
{
if (length == GCM_IV_SIZE)
{
......@@ -424,7 +424,7 @@ gcm_update(struct gcm_ctx *ctx, const struct gcm_key *key,
static void
gcm_crypt(struct gcm_ctx *ctx, void *cipher, nettle_crypt_func *f,
unsigned length, uint8_t *dst, const uint8_t *src)
size_t length, uint8_t *dst, const uint8_t *src)
{
uint8_t buffer[GCM_BLOCK_SIZE];
......@@ -462,7 +462,7 @@ gcm_crypt(struct gcm_ctx *ctx, void *cipher, nettle_crypt_func *f,
void
gcm_encrypt (struct gcm_ctx *ctx, const struct gcm_key *key,
void *cipher, nettle_crypt_func *f,
unsigned length, uint8_t *dst, const uint8_t *src)
size_t length, uint8_t *dst, const uint8_t *src)
{
assert(ctx->data_size % GCM_BLOCK_SIZE == 0);
......@@ -475,7 +475,7 @@ gcm_encrypt (struct gcm_ctx *ctx, const struct gcm_key *key,
void
gcm_decrypt(struct gcm_ctx *ctx, const struct gcm_key *key,
void *cipher, nettle_crypt_func *f,
unsigned length, uint8_t *dst, const uint8_t *src)
size_t length, uint8_t *dst, const uint8_t *src)
{
assert(ctx->data_size % GCM_BLOCK_SIZE == 0);
......
......@@ -94,7 +94,7 @@ gcm_set_key(struct gcm_key *key,
void
gcm_set_iv(struct gcm_ctx *ctx, const struct gcm_key *key,
unsigned length, const uint8_t *iv);
size_t length, const uint8_t *iv);
void
gcm_update(struct gcm_ctx *ctx, const struct gcm_key *key,
......@@ -103,12 +103,12 @@ gcm_update(struct gcm_ctx *ctx, const struct gcm_key *key,
void
gcm_encrypt(struct gcm_ctx *ctx, const struct gcm_key *key,
void *cipher, nettle_crypt_func *f,
unsigned length, uint8_t *dst, const uint8_t *src);
size_t length, uint8_t *dst, const uint8_t *src);
void
gcm_decrypt(struct gcm_ctx *ctx, const struct gcm_key *key,
void *cipher, nettle_crypt_func *f,
unsigned length, uint8_t *dst, const uint8_t *src);
size_t length, uint8_t *dst, const uint8_t *src);
void
gcm_digest(struct gcm_ctx *ctx, const struct gcm_key *key,
......@@ -158,11 +158,11 @@ struct gcm_aes_ctx GCM_CTX(struct aes_ctx);
void
gcm_aes_set_key(struct gcm_aes_ctx *ctx,
unsigned length, const uint8_t *key);
size_t length, const uint8_t *key);
void
gcm_aes_set_iv(struct gcm_aes_ctx *ctx,
unsigned length, const uint8_t *iv);
size_t length, const uint8_t *iv);
void
gcm_aes_update(struct gcm_aes_ctx *ctx,
......@@ -170,11 +170,11 @@ gcm_aes_update(struct gcm_aes_ctx *ctx,
void
gcm_aes_encrypt(struct gcm_aes_ctx *ctx,
unsigned length, uint8_t *dst, const uint8_t *src);
size_t length, uint8_t *dst, const uint8_t *src);
void
gcm_aes_decrypt(struct gcm_aes_ctx *ctx,
unsigned length, uint8_t *dst, const uint8_t *src);
size_t length, uint8_t *dst, const uint8_t *src);
void
gcm_aes_digest(struct gcm_aes_ctx *ctx, unsigned length, uint8_t *digest);
......
......@@ -40,14 +40,14 @@
/* DES uses a different signature for the key set function. We ignore
the return value indicating weak keys. */
static void
des_set_key_hack(void *ctx, unsigned length, const uint8_t *key)
des_set_key_hack(void *ctx, size_t length, const uint8_t *key)
{
assert(length == DES_KEY_SIZE);
des_set_key(ctx, key);
}
static void
des3_set_key_hack(void *ctx, unsigned length, const uint8_t *key)
des3_set_key_hack(void *ctx, size_t length, const uint8_t *key)
{
assert(length == DES3_KEY_SIZE);
des3_set_key(ctx, key);
......@@ -80,7 +80,7 @@ nettle_blowfish128 = _NETTLE_CIPHER(blowfish, BLOWFISH, 128);
/* Sets a fix zero iv. For benchmarking only. */
static void
salsa20_set_key_hack(void *ctx, unsigned length, const uint8_t *key)
salsa20_set_key_hack(void *ctx, size_t length, const uint8_t *key)
{
static const uint8_t iv[SALSA20_IV_SIZE];
salsa20_set_key (ctx, length, key);
......
......@@ -37,13 +37,13 @@ struct nettle_cipher
{
const char *name;
unsigned context_size;
size_t context_size;
/* Zero for stream ciphers */
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_encrypt_key;
nettle_set_key_func *set_decrypt_key;
......
......@@ -44,7 +44,7 @@ typedef void *nettle_realloc_func(void *ctx, void *p, unsigned length);
/* Ciphers */
typedef void nettle_set_key_func(void *ctx,
unsigned length,
size_t length,
const uint8_t *key);
/* Uses a void * for cipher contexts.
......@@ -54,7 +54,7 @@ typedef void nettle_set_key_func(void *ctx,
internal state changes during the encryption. */
typedef void nettle_crypt_func(void *ctx,
unsigned length, uint8_t *dst,
size_t length, uint8_t *dst,
const uint8_t *src);
/* Hash algorithms */
......
......@@ -42,7 +42,7 @@
void
salsa20_crypt(struct salsa20_ctx *ctx,
unsigned length,
size_t length,
uint8_t *c,
const uint8_t *m)
{
......
......@@ -41,7 +41,7 @@
void
salsa20_set_key(struct salsa20_ctx *ctx,
unsigned length, const uint8_t *key)
size_t length, const uint8_t *key)
{
static const uint32_t sigma[4] = {
/* "expand 32-byte k" */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment