Commit 94bae335 authored by Niels Möller's avatar Niels Möller
Browse files

Use size_t in testsuite.

parent 47eae4be
...@@ -9,7 +9,7 @@ test_invert(const struct tstring *key, ...@@ -9,7 +9,7 @@ test_invert(const struct tstring *key,
struct aes_ctx encrypt; struct aes_ctx encrypt;
struct aes_ctx decrypt; struct aes_ctx decrypt;
uint8_t *data = xalloc(cleartext->length); uint8_t *data = xalloc(cleartext->length);
unsigned length; size_t length;
ASSERT (cleartext->length == ciphertext->length); ASSERT (cleartext->length == ciphertext->length);
length = cleartext->length; length = cleartext->length;
......
...@@ -31,7 +31,7 @@ test_arctwo(unsigned ekb, ...@@ -31,7 +31,7 @@ test_arctwo(unsigned ekb,
{ {
struct arctwo_ctx ctx; struct arctwo_ctx ctx;
uint8_t *data; uint8_t *data;
unsigned length; size_t length;
ASSERT (cleartext->length == ciphertext->length); ASSERT (cleartext->length == ciphertext->length);
length = cleartext->length; length = cleartext->length;
......
...@@ -9,7 +9,7 @@ test_invert(const struct tstring *key, ...@@ -9,7 +9,7 @@ test_invert(const struct tstring *key,
struct camellia_ctx encrypt; struct camellia_ctx encrypt;
struct camellia_ctx decrypt; struct camellia_ctx decrypt;
uint8_t *data; uint8_t *data;
unsigned length; size_t length;
ASSERT (cleartext->length == ciphertext->length); ASSERT (cleartext->length == ciphertext->length);
length = cleartext->length; length = cleartext->length;
......
...@@ -9,7 +9,7 @@ test_des(const struct tstring *key, int expected_parity, ...@@ -9,7 +9,7 @@ test_des(const struct tstring *key, int expected_parity,
{ {
struct des_ctx ctx; struct des_ctx ctx;
uint8_t *data; uint8_t *data;
unsigned length; size_t length;
ASSERT (cleartext->length == ciphertext->length); ASSERT (cleartext->length == ciphertext->length);
length = cleartext->length; length = cleartext->length;
......
...@@ -28,7 +28,7 @@ test_salsa20_stream(const struct tstring *key, ...@@ -28,7 +28,7 @@ test_salsa20_stream(const struct tstring *key,
uint8_t data[STREAM_LENGTH + 1]; uint8_t data[STREAM_LENGTH + 1];
uint8_t stream[STREAM_LENGTH + 1]; uint8_t stream[STREAM_LENGTH + 1];
uint8_t xor[SALSA20_BLOCK_SIZE]; uint8_t xor[SALSA20_BLOCK_SIZE];
unsigned j; size_t j;
ASSERT (iv->length == SALSA20_IV_SIZE); ASSERT (iv->length == SALSA20_IV_SIZE);
ASSERT (ciphertext->length == 4*SALSA20_BLOCK_SIZE); ASSERT (ciphertext->length == 4*SALSA20_BLOCK_SIZE);
...@@ -97,7 +97,8 @@ test_salsa20_stream(const struct tstring *key, ...@@ -97,7 +97,8 @@ test_salsa20_stream(const struct tstring *key,
if (!MEMEQ(j, data, stream)) if (!MEMEQ(j, data, stream))
{ {
fprintf(stderr, "Encrypt failed for length %u:\n", j); fprintf(stderr, "Encrypt failed for length %lu:\n",
(unsigned long) j);
fprintf(stderr, "\nOutput: "); fprintf(stderr, "\nOutput: ");
print_hex(j, data); print_hex(j, data);
fprintf(stderr, "\nExpected:"); fprintf(stderr, "\nExpected:");
...@@ -107,7 +108,8 @@ test_salsa20_stream(const struct tstring *key, ...@@ -107,7 +108,8 @@ test_salsa20_stream(const struct tstring *key,
} }
if (!memzero_p (data + j, STREAM_LENGTH + 1 - j)) if (!memzero_p (data + j, STREAM_LENGTH + 1 - j))
{ {
fprintf(stderr, "Encrypt failed for length %u, wrote too much:\n", j); fprintf(stderr, "Encrypt failed for length %lu, wrote too much:\n",
(unsigned long) j);
fprintf(stderr, "\nOutput: "); fprintf(stderr, "\nOutput: ");
print_hex(STREAM_LENGTH + 1 - j, data + j); print_hex(STREAM_LENGTH + 1 - j, data + j);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
...@@ -128,7 +130,7 @@ _test_salsa20(salsa20_func *crypt, ...@@ -128,7 +130,7 @@ _test_salsa20(salsa20_func *crypt,
{ {
struct salsa20_ctx ctx; struct salsa20_ctx ctx;
uint8_t *data; uint8_t *data;
unsigned length; size_t length;
ASSERT (cleartext->length == ciphertext->length); ASSERT (cleartext->length == ciphertext->length);
length = cleartext->length; length = cleartext->length;
...@@ -143,7 +145,8 @@ _test_salsa20(salsa20_func *crypt, ...@@ -143,7 +145,8 @@ _test_salsa20(salsa20_func *crypt,
crypt(&ctx, length, data, cleartext->data); crypt(&ctx, length, data, cleartext->data);
if (data[length] != 17) if (data[length] != 17)
{ {
fprintf(stderr, "Encrypt of %u bytes wrote too much!\nInput:", length); fprintf(stderr, "Encrypt of %lu bytes wrote too much!\nInput:",
(unsigned long) length);
tstring_print_hex(cleartext); tstring_print_hex(cleartext);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
FAIL(); FAIL();
......
...@@ -6,7 +6,7 @@ tstring_hex_reverse (const char *hex) ...@@ -6,7 +6,7 @@ tstring_hex_reverse (const char *hex)
{ {
struct tstring *s = tstring_hex (hex); struct tstring *s = tstring_hex (hex);
uint8_t *p; uint8_t *p;
unsigned length, i; size_t length, i;
length = s->length; length = s->length;
p = s->data; p = s->data;
......
...@@ -63,7 +63,7 @@ xalloc(size_t size) ...@@ -63,7 +63,7 @@ xalloc(size_t size)
static struct tstring *tstring_first = NULL; static struct tstring *tstring_first = NULL;
struct tstring * struct tstring *
tstring_alloc (unsigned length) tstring_alloc (size_t length)
{ {
struct tstring *s = xalloc(sizeof(struct tstring) + length - 1); struct tstring *s = xalloc(sizeof(struct tstring) + length - 1);
s->length = length; s->length = length;
...@@ -84,19 +84,19 @@ tstring_clear(void) ...@@ -84,19 +84,19 @@ tstring_clear(void)
} }
struct tstring * struct tstring *
tstring_data(unsigned length, const char *data) tstring_data(size_t length, const char *data)
{ {
struct tstring *s = tstring_alloc (length); struct tstring *s = tstring_alloc (length);
memcpy (s->data, data, length); memcpy (s->data, data, length);
return s; return s;
} }
static unsigned static size_t
decode_hex_length(const char *h) decode_hex_length(const char *h)
{ {
const unsigned char *hex = (const unsigned char *) h; const unsigned char *hex = (const unsigned char *) h;
unsigned count; size_t count;
unsigned i; size_t i;
for (count = i = 0; hex[i]; i++) for (count = i = 0; hex[i]; i++)
{ {
...@@ -116,7 +116,7 @@ static void ...@@ -116,7 +116,7 @@ static void
decode_hex(uint8_t *dst, const char *h) decode_hex(uint8_t *dst, const char *h)
{ {
const unsigned char *hex = (const unsigned char *) h; const unsigned char *hex = (const unsigned char *) h;
unsigned i = 0; size_t i = 0;
for (;;) for (;;)
{ {
...@@ -147,7 +147,7 @@ struct tstring * ...@@ -147,7 +147,7 @@ struct tstring *
tstring_hex(const char *hex) tstring_hex(const char *hex)
{ {
struct tstring *s; struct tstring *s;
unsigned length = decode_hex_length(hex); size_t length = decode_hex_length(hex);
s = tstring_alloc(length); s = tstring_alloc(length);
...@@ -162,9 +162,9 @@ tstring_print_hex(const struct tstring *s) ...@@ -162,9 +162,9 @@ tstring_print_hex(const struct tstring *s)
} }
void void
print_hex(unsigned length, const uint8_t *data) print_hex(size_t length, const uint8_t *data)
{ {
unsigned i; size_t i;
for (i = 0; i < length; i++) for (i = 0; i < length; i++)
{ {
...@@ -215,7 +215,7 @@ test_cipher(const struct nettle_cipher *cipher, ...@@ -215,7 +215,7 @@ test_cipher(const struct nettle_cipher *cipher,
{ {
void *ctx = xalloc(cipher->context_size); void *ctx = xalloc(cipher->context_size);
uint8_t *data = xalloc(cleartext->length); uint8_t *data = xalloc(cleartext->length);
unsigned length; size_t length;
ASSERT (cleartext->length == ciphertext->length); ASSERT (cleartext->length == ciphertext->length);
length = cleartext->length; length = cleartext->length;
...@@ -262,7 +262,7 @@ test_cipher_cbc(const struct nettle_cipher *cipher, ...@@ -262,7 +262,7 @@ test_cipher_cbc(const struct nettle_cipher *cipher,
void *ctx = xalloc(cipher->context_size); void *ctx = xalloc(cipher->context_size);
uint8_t *data; uint8_t *data;
uint8_t *iv = xalloc(cipher->block_size); uint8_t *iv = xalloc(cipher->block_size);
unsigned length; size_t length;
ASSERT (cleartext->length == ciphertext->length); ASSERT (cleartext->length == ciphertext->length);
length = cleartext->length; length = cleartext->length;
...@@ -323,8 +323,8 @@ test_cipher_ctr(const struct nettle_cipher *cipher, ...@@ -323,8 +323,8 @@ test_cipher_ctr(const struct nettle_cipher *cipher,
uint8_t *data; uint8_t *data;
uint8_t *ctr = xalloc(cipher->block_size); uint8_t *ctr = xalloc(cipher->block_size);
uint8_t *octr = xalloc(cipher->block_size); uint8_t *octr = xalloc(cipher->block_size);
unsigned length; size_t length, nblocks;
unsigned low, nblocks; unsigned low;
ASSERT (cleartext->length == ciphertext->length); ASSERT (cleartext->length == ciphertext->length);
length = cleartext->length; length = cleartext->length;
...@@ -397,11 +397,11 @@ test_cipher_stream(const struct nettle_cipher *cipher, ...@@ -397,11 +397,11 @@ test_cipher_stream(const struct nettle_cipher *cipher,
const struct tstring *cleartext, const struct tstring *cleartext,
const struct tstring *ciphertext) const struct tstring *ciphertext)
{ {
unsigned block; size_t block;
void *ctx = xalloc(cipher->context_size); void *ctx = xalloc(cipher->context_size);
uint8_t *data; uint8_t *data;
unsigned length; size_t length;
ASSERT (cleartext->length == ciphertext->length); ASSERT (cleartext->length == ciphertext->length);
length = cleartext->length; length = cleartext->length;
...@@ -410,7 +410,7 @@ test_cipher_stream(const struct nettle_cipher *cipher, ...@@ -410,7 +410,7 @@ test_cipher_stream(const struct nettle_cipher *cipher,
for (block = 1; block <= length; block++) for (block = 1; block <= length; block++)
{ {
unsigned i; size_t i;
memset(data, 0x17, length + 1); memset(data, 0x17, length + 1);
cipher->set_encrypt_key(ctx, key->length, key->data); cipher->set_encrypt_key(ctx, key->length, key->data);
...@@ -426,7 +426,8 @@ test_cipher_stream(const struct nettle_cipher *cipher, ...@@ -426,7 +426,8 @@ test_cipher_stream(const struct nettle_cipher *cipher,
if (!MEMEQ(length, data, ciphertext->data)) if (!MEMEQ(length, data, ciphertext->data))
{ {
fprintf(stderr, "Encrypt failed, block size %d\nInput:", block); fprintf(stderr, "Encrypt failed, block size %lu\nInput:",
(unsigned long) block);
tstring_print_hex(cleartext); tstring_print_hex(cleartext);
fprintf(stderr, "\nOutput: "); fprintf(stderr, "\nOutput: ");
print_hex(length, data); print_hex(length, data);
...@@ -470,7 +471,7 @@ test_aead(const struct nettle_aead *aead, ...@@ -470,7 +471,7 @@ test_aead(const struct nettle_aead *aead,
void *ctx = xalloc(aead->context_size); void *ctx = xalloc(aead->context_size);
uint8_t *data; uint8_t *data;
uint8_t *buffer = xalloc(aead->block_size); uint8_t *buffer = xalloc(aead->block_size);
unsigned length; size_t length;
ASSERT (cleartext->length == ciphertext->length); ASSERT (cleartext->length == ciphertext->length);
length = cleartext->length; length = cleartext->length;
...@@ -574,14 +575,14 @@ test_hash(const struct nettle_hash *hash, ...@@ -574,14 +575,14 @@ test_hash(const struct nettle_hash *hash,
void void
test_hash_large(const struct nettle_hash *hash, test_hash_large(const struct nettle_hash *hash,
unsigned count, unsigned length, size_t count, size_t length,
uint8_t c, uint8_t c,
const struct tstring *digest) const struct tstring *digest)
{ {
void *ctx = xalloc(hash->context_size); void *ctx = xalloc(hash->context_size);
uint8_t *buffer = xalloc(hash->digest_size); uint8_t *buffer = xalloc(hash->digest_size);
uint8_t *data = xalloc(length); uint8_t *data = xalloc(length);
unsigned i; size_t i;
ASSERT (digest->length == hash->digest_size); ASSERT (digest->length == hash->digest_size);
...@@ -603,7 +604,7 @@ test_hash_large(const struct nettle_hash *hash, ...@@ -603,7 +604,7 @@ test_hash_large(const struct nettle_hash *hash,
void void
test_armor(const struct nettle_armor *armor, test_armor(const struct nettle_armor *armor,
unsigned data_length, size_t data_length,
const uint8_t *data, const uint8_t *data,
const uint8_t *ascii) const uint8_t *ascii)
{ {
......
...@@ -43,18 +43,18 @@ xalloc(size_t size); ...@@ -43,18 +43,18 @@ xalloc(size_t size);
struct tstring { struct tstring {
struct tstring *next; struct tstring *next;
unsigned length; size_t length;
uint8_t data[1]; uint8_t data[1];
}; };
struct tstring * struct tstring *
tstring_alloc (unsigned length); tstring_alloc (size_t length);
void void
tstring_clear(void); tstring_clear(void);
struct tstring * struct tstring *
tstring_data(unsigned length, const char *data); tstring_data(size_t length, const char *data);
struct tstring * struct tstring *
tstring_hex(const char *hex); tstring_hex(const char *hex);
...@@ -65,7 +65,7 @@ tstring_print_hex(const struct tstring *s); ...@@ -65,7 +65,7 @@ tstring_print_hex(const struct tstring *s);
/* Decodes a NUL-terminated hex string. */ /* Decodes a NUL-terminated hex string. */
void void
print_hex(unsigned length, const uint8_t *data); print_hex(size_t length, const uint8_t *data);
/* The main program */ /* The main program */
void void
...@@ -145,13 +145,13 @@ test_hash(const struct nettle_hash *hash, ...@@ -145,13 +145,13 @@ test_hash(const struct nettle_hash *hash,
void void
test_hash_large(const struct nettle_hash *hash, test_hash_large(const struct nettle_hash *hash,
unsigned count, unsigned length, size_t count, size_t length,
uint8_t c, uint8_t c,
const struct tstring *digest); const struct tstring *digest);
void void
test_armor(const struct nettle_armor *armor, test_armor(const struct nettle_armor *armor,
unsigned data_length, size_t data_length,
const uint8_t *data, const uint8_t *data,
const uint8_t *ascii); const uint8_t *ascii);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
static void static void
update (void *ctx, nettle_hash_update_func *f, update (void *ctx, nettle_hash_update_func *f,
const struct tstring *msg, const struct tstring *msg,
unsigned length) size_t length)
{ {
for (; length > msg->length; length -= msg->length) for (; length > msg->length; length -= msg->length)
f(ctx, msg->length, msg->data); f(ctx, msg->length, msg->data);
...@@ -18,8 +18,8 @@ update (void *ctx, nettle_hash_update_func *f, ...@@ -18,8 +18,8 @@ update (void *ctx, nettle_hash_update_func *f,
static void static void
check_digest (const char *name, void *ctx, nettle_hash_digest_func *f, check_digest (const char *name, void *ctx, nettle_hash_digest_func *f,
const struct tstring *msg, unsigned length, const struct tstring *msg, size_t length,
unsigned tag_length, const uint8_t *ref) size_t tag_length, const uint8_t *ref)
{ {
uint8_t tag[16]; uint8_t tag[16];
f(ctx, tag_length, tag); f(ctx, tag_length, tag);
...@@ -27,7 +27,7 @@ check_digest (const char *name, void *ctx, nettle_hash_digest_func *f, ...@@ -27,7 +27,7 @@ check_digest (const char *name, void *ctx, nettle_hash_digest_func *f,
{ {
printf ("%s failed\n", name); printf ("%s failed\n", name);
printf ("msg: "); print_hex (msg->length, msg->data); printf ("msg: "); print_hex (msg->length, msg->data);
printf ("length: %u\n", length); printf ("length: %lu\n", (unsigned long) length);
printf ("tag: "); print_hex (tag_length, tag); printf ("tag: "); print_hex (tag_length, tag);
printf ("ref: "); print_hex (tag_length, ref); printf ("ref: "); print_hex (tag_length, ref);
abort (); abort ();
...@@ -39,7 +39,7 @@ static void ...@@ -39,7 +39,7 @@ static void
test_umac (const struct tstring *key, test_umac (const struct tstring *key,
const struct tstring *nonce, const struct tstring *nonce,
const struct tstring *msg, const struct tstring *msg,
unsigned length, size_t length,
const struct tstring *ref32, const struct tstring *ref32,
const struct tstring *ref64, const struct tstring *ref64,
const struct tstring *ref128) const struct tstring *ref128)
...@@ -91,7 +91,7 @@ static void ...@@ -91,7 +91,7 @@ static void
test_align(const struct tstring *key, test_align(const struct tstring *key,
const struct tstring *nonce, const struct tstring *nonce,
const struct tstring *msg, const struct tstring *msg,
unsigned length, size_t length,
const struct tstring *ref32, const struct tstring *ref32,
const struct tstring *ref64, const struct tstring *ref64,
const struct tstring *ref128) const struct tstring *ref128)
...@@ -106,7 +106,7 @@ test_align(const struct tstring *key, ...@@ -106,7 +106,7 @@ test_align(const struct tstring *key,
struct umac128_ctx ctx128; struct umac128_ctx ctx128;
uint8_t *input; uint8_t *input;
unsigned i; size_t i;
memset(buffer, 17, length + 16); memset(buffer, 17, length + 16);
input = buffer + offset; input = buffer + offset;
......
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