From 3eb603d0d810b9298f5624aaa8a293c4b51e4b2a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Fri, 26 Apr 2013 09:23:44 +0200
Subject: [PATCH] Use size_t rather than unsigned for all cipher-related
 functions.

---
 ChangeLog                       |  6 ++++++
 aes-decrypt-internal.c          |  2 +-
 aes-decrypt.c                   |  2 +-
 aes-encrypt-internal.c          |  2 +-
 aes-encrypt.c                   |  2 +-
 aes-internal.h                  |  4 ++--
 aes-set-decrypt-key.c           |  2 +-
 aes-set-encrypt-key.c           |  2 +-
 aes.h                           |  8 ++++----
 arcfour-crypt.c                 |  2 +-
 arcfour.c                       |  2 +-
 arcfour.h                       |  4 ++--
 arctwo.c                        | 12 ++++++------
 arctwo.h                        | 10 +++++-----
 blowfish.c                      |  6 +++---
 blowfish.h                      |  6 +++---
 camellia-crypt-internal.c       |  2 +-
 camellia-crypt.c                |  4 ++--
 camellia-internal.h             |  2 +-
 camellia-set-decrypt-key.c      |  2 +-
 camellia-set-encrypt-key.c      |  2 +-
 camellia.h                      |  6 +++---
 cast128.c                       |  6 +++---
 cast128.h                       |  6 +++---
 cbc.c                           | 10 +++++-----
 cbc.h                           |  8 ++++----
 ctr.c                           |  8 ++++----
 ctr.h                           |  4 ++--
 des.c                           | 12 ++++++------
 des.h                           | 12 ++++++------
 des3.c                          |  4 ++--
 examples/nettle-openssl.c       | 30 +++++++++++++++---------------
 gcm-aes.c                       |  8 ++++----
 gcm.c                           |  8 ++++----
 gcm.h                           | 14 +++++++-------
 nettle-internal.c               |  6 +++---
 nettle-meta.h                   |  6 +++---
 nettle-types.h                  |  4 ++--
 salsa20-crypt.c                 |  2 +-
 salsa20-set-key.c               |  2 +-
 salsa20.h                       |  6 +++---
 salsa20r12-crypt.c              |  6 +++---
 serpent-decrypt.c               |  2 +-
 serpent-encrypt.c               |  2 +-
 serpent-set-key.c               |  2 +-
 serpent.h                       |  6 +++---
 twofish.c                       |  6 +++---
 twofish.h                       |  6 +++---
 x86_64/aes-decrypt-internal.asm | 12 ++++++------
 x86_64/aes-encrypt-internal.asm | 12 ++++++------
 50 files changed, 153 insertions(+), 147 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index db3ed0e2..6dde9a7e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-04-26  Niels Möller  <nisse@lysator.liu.se>
+
+	* Many files: Use size_t rather than unsigned for data sizes.
+	* x86_64/aes-encrypt-internal.asm: Accept 64-bit length.
+	* x86_64/aes-decrypt-internal.asm: Likewise.
+
 2013-04-25  Niels Möller  <nisse@lysator.liu.se>
 
 	* configure.ac: Changed version number, to 2.8.
diff --git a/aes-decrypt-internal.c b/aes-decrypt-internal.c
index 7236208d..af2891e9 100644
--- a/aes-decrypt-internal.c
+++ b/aes-decrypt-internal.c
@@ -35,7 +35,7 @@
 void
 _nettle_aes_decrypt(const struct aes_ctx *ctx,
 		    const struct aes_table *T,
-		    unsigned length, uint8_t *dst,
+		    size_t length, uint8_t *dst,
 		    const uint8_t *src)
 {
   FOR_BLOCKS(length, dst, src, AES_BLOCK_SIZE)
diff --git a/aes-decrypt.c b/aes-decrypt.c
index 47fe3c10..96862e47 100644
--- a/aes-decrypt.c
+++ b/aes-decrypt.c
@@ -338,7 +338,7 @@ _aes_decrypt_table =
 
 void
 aes_decrypt(const struct aes_ctx *ctx,
-	    unsigned length, uint8_t *dst,
+	    size_t length, uint8_t *dst,
 	    const uint8_t *src)
 {
   assert(!(length % AES_BLOCK_SIZE) );
diff --git a/aes-encrypt-internal.c b/aes-encrypt-internal.c
index 9b16153c..cf9d8247 100644
--- a/aes-encrypt-internal.c
+++ b/aes-encrypt-internal.c
@@ -35,7 +35,7 @@
 void
 _nettle_aes_encrypt(const struct aes_ctx *ctx,
 		    const struct aes_table *T,
-		    unsigned length, uint8_t *dst,
+		    size_t length, uint8_t *dst,
 		    const uint8_t *src)
 {
   FOR_BLOCKS(length, dst, src, AES_BLOCK_SIZE)
diff --git a/aes-encrypt.c b/aes-encrypt.c
index 60f803de..f28ac319 100644
--- a/aes-encrypt.c
+++ b/aes-encrypt.c
@@ -36,7 +36,7 @@
    For PIC code, the details can be complex and system dependent. */
 void
 aes_encrypt(const struct aes_ctx *ctx,
-	    unsigned length, uint8_t *dst,
+	    size_t length, uint8_t *dst,
 	    const uint8_t *src)
 {
   assert(!(length % AES_BLOCK_SIZE) );
diff --git a/aes-internal.h b/aes-internal.h
index 42fc4dec..e361bde9 100644
--- a/aes-internal.h
+++ b/aes-internal.h
@@ -53,13 +53,13 @@ struct aes_table
 void
 _aes_encrypt(const struct aes_ctx *ctx,
 	     const struct aes_table *T,
-	     unsigned length, uint8_t *dst,
+	     size_t length, uint8_t *dst,
 	     const uint8_t *src);
 
 void
 _aes_decrypt(const struct aes_ctx *ctx,
 	     const struct aes_table *T,
-	     unsigned length, uint8_t *dst,
+	     size_t length, uint8_t *dst,
 	     const uint8_t *src);
 
 /* Macros */
diff --git a/aes-set-decrypt-key.c b/aes-set-decrypt-key.c
index 640e9455..04e4c992 100644
--- a/aes-set-decrypt-key.c
+++ b/aes-set-decrypt-key.c
@@ -161,7 +161,7 @@ aes_invert_key(struct aes_ctx *dst,
 
 void
 aes_set_decrypt_key(struct aes_ctx *ctx,
-		    unsigned keysize, const uint8_t *key)
+		    size_t keysize, const uint8_t *key)
 {
   /* We first create subkeys for encryption,
    * then modify the subkeys for decryption. */
diff --git a/aes-set-encrypt-key.c b/aes-set-encrypt-key.c
index e5494c86..04f53270 100644
--- a/aes-set-encrypt-key.c
+++ b/aes-set-encrypt-key.c
@@ -36,7 +36,7 @@
 
 void
 aes_set_encrypt_key(struct aes_ctx *ctx,
-		    unsigned keysize, const uint8_t *key)
+		    size_t keysize, const uint8_t *key)
 {
   static const uint8_t rcon[10] = {
     0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x1b,0x36,
diff --git a/aes.h b/aes.h
index b3482e23..b3bb9659 100644
--- a/aes.h
+++ b/aes.h
@@ -59,11 +59,11 @@ struct aes_ctx
 
 void
 aes_set_encrypt_key(struct aes_ctx *ctx,
-		    unsigned length, const uint8_t *key);
+		    size_t length, const uint8_t *key);
 
 void
 aes_set_decrypt_key(struct aes_ctx *ctx,
-		   unsigned length, const uint8_t *key);
+		   size_t length, const uint8_t *key);
 
 void
 aes_invert_key(struct aes_ctx *dst,
@@ -71,11 +71,11 @@ aes_invert_key(struct aes_ctx *dst,
 
 void
 aes_encrypt(const struct aes_ctx *ctx,
-	    unsigned length, uint8_t *dst,
+	    size_t length, uint8_t *dst,
 	    const uint8_t *src);
 void
 aes_decrypt(const struct aes_ctx *ctx,
-	    unsigned length, uint8_t *dst,
+	    size_t length, uint8_t *dst,
 	    const uint8_t *src);
 
 #ifdef __cplusplus
diff --git a/arcfour-crypt.c b/arcfour-crypt.c
index d7f7c567..c8ebb9a9 100644
--- a/arcfour-crypt.c
+++ b/arcfour-crypt.c
@@ -33,7 +33,7 @@
 
 void
 arcfour_crypt(struct arcfour_ctx *ctx,
-	      unsigned length, uint8_t *dst,
+	      size_t length, uint8_t *dst,
 	      const uint8_t *src)
 {
   register uint8_t i, j;
diff --git a/arcfour.c b/arcfour.c
index d7286e5e..0977d092 100644
--- a/arcfour.c
+++ b/arcfour.c
@@ -35,7 +35,7 @@
 
 void
 arcfour_set_key(struct arcfour_ctx *ctx,
-		unsigned length, const uint8_t *key)
+		size_t length, const uint8_t *key)
 {
   unsigned i, j, k;
   
diff --git a/arcfour.h b/arcfour.h
index fb539974..cedae8b1 100644
--- a/arcfour.h
+++ b/arcfour.h
@@ -51,11 +51,11 @@ struct arcfour_ctx
 
 void
 arcfour_set_key(struct arcfour_ctx *ctx,
-		unsigned length, const uint8_t *key);
+		size_t length, const uint8_t *key);
 
 void
 arcfour_crypt(struct arcfour_ctx *ctx,
-	      unsigned length, uint8_t *dst,
+	      size_t length, uint8_t *dst,
 	      const uint8_t *src);
 
 #ifdef __cplusplus
diff --git a/arctwo.c b/arctwo.c
index c4bc1551..f5753a8c 100644
--- a/arctwo.c
+++ b/arctwo.c
@@ -85,7 +85,7 @@ static const uint8_t arctwo_sbox[] = {
 
 void
 arctwo_encrypt (struct arctwo_ctx *ctx,
-		unsigned length, uint8_t *dst, const uint8_t *src)
+		size_t length, uint8_t *dst, const uint8_t *src)
 {
   FOR_BLOCKS (length, dst, src, ARCTWO_BLOCK_SIZE)
   {
@@ -130,7 +130,7 @@ arctwo_encrypt (struct arctwo_ctx *ctx,
 
 void
 arctwo_decrypt (struct arctwo_ctx *ctx,
-		unsigned length, uint8_t *dst, const uint8_t *src)
+		size_t length, uint8_t *dst, const uint8_t *src)
 {
   FOR_BLOCKS (length, dst, src, ARCTWO_BLOCK_SIZE)
   {
@@ -176,9 +176,9 @@ arctwo_decrypt (struct arctwo_ctx *ctx,
 
 void
 arctwo_set_key_ekb (struct arctwo_ctx *ctx,
-		    unsigned length, const uint8_t *key, unsigned ekb)
+		    size_t length, const uint8_t *key, unsigned ekb)
 {
-  unsigned i;
+  size_t i;
   /* Expanded key, treated as octets */
   uint8_t S[128];
   uint8_t x;
@@ -217,14 +217,14 @@ arctwo_set_key_ekb (struct arctwo_ctx *ctx,
 }
 
 void
-arctwo_set_key (struct arctwo_ctx *ctx, unsigned length, const uint8_t *key)
+arctwo_set_key (struct arctwo_ctx *ctx, size_t length, const uint8_t *key)
 {
   arctwo_set_key_ekb (ctx, length, key, 8 * length);
 }
 
 void
 arctwo_set_key_gutmann (struct arctwo_ctx *ctx,
-			unsigned length, const uint8_t *key)
+			size_t length, const uint8_t *key)
 {
   arctwo_set_key_ekb (ctx, length, key, 0);
 }
diff --git a/arctwo.h b/arctwo.h
index 6f763bb9..3f1a3be9 100644
--- a/arctwo.h
+++ b/arctwo.h
@@ -57,23 +57,23 @@ struct arctwo_ctx
    as an explicit argument. 0 means maximum key bits. */
 void
 arctwo_set_key_ekb (struct arctwo_ctx *ctx,
-		    unsigned length, const uint8_t * key, unsigned ekb);
+		    size_t length, const uint8_t * key, unsigned ekb);
 
 /* Equvivalent to arctwo_set_key_ekb, with ekb = 8 * length */
 void
-arctwo_set_key (struct arctwo_ctx *ctx, unsigned length, const uint8_t *key);
+arctwo_set_key (struct arctwo_ctx *ctx, size_t length, const uint8_t *key);
 
 /* Equvivalent to arctwo_set_key_ekb, with ekb = 1024 */
 void
 arctwo_set_key_gutmann (struct arctwo_ctx *ctx,
-			unsigned length, const uint8_t *key);
+			size_t length, const uint8_t *key);
 
 void
 arctwo_encrypt (struct arctwo_ctx *ctx,
-		unsigned length, uint8_t *dst, const uint8_t *src);
+		size_t length, uint8_t *dst, const uint8_t *src);
 void
 arctwo_decrypt (struct arctwo_ctx *ctx,
-		unsigned length, uint8_t *dst, const uint8_t *src);
+		size_t length, uint8_t *dst, const uint8_t *src);
 
 #ifdef __cplusplus
 }
diff --git a/blowfish.c b/blowfish.c
index 4be084f1..0ffa332d 100644
--- a/blowfish.c
+++ b/blowfish.c
@@ -321,7 +321,7 @@ decrypt (const struct blowfish_ctx *ctx, uint32_t * ret_xl, uint32_t * ret_xr)
 
 void
 blowfish_encrypt (const struct blowfish_ctx *ctx,
-		  unsigned length, uint8_t * dst, const uint8_t * src)
+		  size_t length, uint8_t * dst, const uint8_t * src)
 {
   FOR_BLOCKS (length, dst, src, BLOWFISH_BLOCK_SIZE)
     {
@@ -343,7 +343,7 @@ blowfish_encrypt (const struct blowfish_ctx *ctx,
 
 void
 blowfish_decrypt (const struct blowfish_ctx *ctx,
-		  unsigned length, uint8_t * dst, const uint8_t * src)
+		  size_t length, uint8_t * dst, const uint8_t * src)
 {
   FOR_BLOCKS (length, dst, src, BLOWFISH_BLOCK_SIZE)
     {
@@ -365,7 +365,7 @@ blowfish_decrypt (const struct blowfish_ctx *ctx,
 
 int
 blowfish_set_key (struct blowfish_ctx *ctx,
-		  unsigned length, const uint8_t * key)
+		  size_t length, const uint8_t * key)
 {
   int i, j;
   uint32_t data, datal, datar;
diff --git a/blowfish.h b/blowfish.h
index 02f9f7d7..01ed0d37 100644
--- a/blowfish.h
+++ b/blowfish.h
@@ -58,15 +58,15 @@ struct blowfish_ctx
  * On error, returns 0 and sets ctx->status to BLOWFISH_WEAK_KEY. */
 int
 blowfish_set_key(struct blowfish_ctx *ctx,
-                 unsigned length, const uint8_t *key);
+                 size_t length, const uint8_t *key);
 
 void
 blowfish_encrypt(const struct blowfish_ctx *ctx,
-                 unsigned length, uint8_t *dst,
+                 size_t length, uint8_t *dst,
                  const uint8_t *src);
 void
 blowfish_decrypt(const struct blowfish_ctx *ctx,
-                 unsigned length, uint8_t *dst,
+                 size_t length, uint8_t *dst,
                  const uint8_t *src);
 
 #ifdef __cplusplus
diff --git a/camellia-crypt-internal.c b/camellia-crypt-internal.c
index 21c52400..69453235 100644
--- a/camellia-crypt-internal.c
+++ b/camellia-crypt-internal.c
@@ -125,7 +125,7 @@
 void
 _camellia_crypt(const struct camellia_ctx *ctx,
 		const struct camellia_table *T,
-		unsigned length, uint8_t *dst,
+		size_t length, uint8_t *dst,
 		const uint8_t *src)
 {
   FOR_BLOCKS(length, dst, src, CAMELLIA_BLOCK_SIZE)
diff --git a/camellia-crypt.c b/camellia-crypt.c
index ca5d72f3..def5d845 100644
--- a/camellia-crypt.c
+++ b/camellia-crypt.c
@@ -36,8 +36,8 @@
    For PIC code, the details can be complex and system dependent. */
 void
 camellia_crypt(const struct camellia_ctx *ctx,
-		 unsigned length, uint8_t *dst,
-	    const uint8_t *src)
+	       size_t length, uint8_t *dst,
+	       const uint8_t *src)
 {
   assert(!(length % CAMELLIA_BLOCK_SIZE) );
   _camellia_crypt(ctx, &_camellia_table,
diff --git a/camellia-internal.h b/camellia-internal.h
index c0f67c8a..ee41a447 100644
--- a/camellia-internal.h
+++ b/camellia-internal.h
@@ -63,7 +63,7 @@ struct camellia_table
 void
 _camellia_crypt(const struct camellia_ctx *ctx,
 		const struct camellia_table *T,
-		unsigned length, uint8_t *dst,
+		size_t length, uint8_t *dst,
 		const uint8_t *src);
 
 extern const struct camellia_table _camellia_table;
diff --git a/camellia-set-decrypt-key.c b/camellia-set-decrypt-key.c
index f1a5bb81..329fa3c9 100644
--- a/camellia-set-decrypt-key.c
+++ b/camellia-set-decrypt-key.c
@@ -54,7 +54,7 @@ camellia_invert_key(struct camellia_ctx *dst,
 
 void
 camellia_set_decrypt_key(struct camellia_ctx *ctx,
-			 unsigned length, const uint8_t *key)
+			 size_t length, const uint8_t *key)
 {
   camellia_set_encrypt_key(ctx, length, key);
   camellia_invert_key(ctx, ctx);
diff --git a/camellia-set-encrypt-key.c b/camellia-set-encrypt-key.c
index 408ed721..7dd90775 100644
--- a/camellia-set-encrypt-key.c
+++ b/camellia-set-encrypt-key.c
@@ -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;
 
diff --git a/camellia.h b/camellia.h
index ed200727..c0b45761 100644
--- a/camellia.h
+++ b/camellia.h
@@ -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
 }
diff --git a/cast128.c b/cast128.c
index 512c55d2..ca7faac4 100644
--- a/cast128.c
+++ b/cast128.c
@@ -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;
diff --git a/cast128.h b/cast128.h
index d10ec602..63636d21 100644
--- a/cast128.h
+++ b/cast128.h
@@ -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
diff --git a/cbc.c b/cbc.c
index e70619b3..16edd4dd 100644
--- a/cbc.c
+++ b/cbc.c
@@ -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;
diff --git a/cbc.h b/cbc.h
index 8eef8036..eb01239c 100644
--- a/cbc.h
+++ b/cbc.h
@@ -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) \
diff --git a/ctr.c b/ctr.c
index 6b970305..80a072b4 100644
--- a/ctr.c
+++ b/ctr.c
@@ -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);
 
diff --git a/ctr.h b/ctr.h
index 582a3945..14d520d3 100644
--- a/ctr.h
+++ b/ctr.h
@@ -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) \
diff --git a/des.c b/des.c
index 8bb1bef4..555f1e6c 100644
--- a/des.c
+++ b/des.c
@@ -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));
diff --git a/des.h b/des.h
index df4d345e..edbdc14e 100644
--- a/des.h
+++ b/des.h
@@ -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
diff --git a/des3.c b/des3.c
index b2183ffb..84c7c1a7 100644
--- a/des3.c
+++ b/des3.c
@@ -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],
diff --git a/examples/nettle-openssl.c b/examples/nettle-openssl.c
index 53c20252..5805b662 100644
--- a/examples/nettle-openssl.c
+++ b/examples/nettle-openssl.c
@@ -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));
diff --git a/gcm-aes.c b/gcm-aes.c
index c88cb0dc..194a0d82 100644
--- a/gcm-aes.c
+++ b/gcm-aes.c
@@ -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);
 }
diff --git a/gcm.c b/gcm.c
index 8c693277..de5321e7 100644
--- a/gcm.c
+++ b/gcm.c
@@ -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);
 
diff --git a/gcm.h b/gcm.h
index e201e98e..b42c9957 100644
--- a/gcm.h
+++ b/gcm.h
@@ -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);
diff --git a/nettle-internal.c b/nettle-internal.c
index f271eac0..5cd58288 100644
--- a/nettle-internal.c
+++ b/nettle-internal.c
@@ -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);
diff --git a/nettle-meta.h b/nettle-meta.h
index 16cc77bc..59f5c41e 100644
--- a/nettle-meta.h
+++ b/nettle-meta.h
@@ -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;
diff --git a/nettle-types.h b/nettle-types.h
index 4d5e38ab..5f7738e7 100644
--- a/nettle-types.h
+++ b/nettle-types.h
@@ -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 */
diff --git a/salsa20-crypt.c b/salsa20-crypt.c
index 82abceaa..29e92b3d 100644
--- a/salsa20-crypt.c
+++ b/salsa20-crypt.c
@@ -42,7 +42,7 @@
 
 void
 salsa20_crypt(struct salsa20_ctx *ctx,
-	      unsigned length,
+	      size_t length,
 	      uint8_t *c,
 	      const uint8_t *m)
 {
diff --git a/salsa20-set-key.c b/salsa20-set-key.c
index da4d6432..661aacc2 100644
--- a/salsa20-set-key.c
+++ b/salsa20-set-key.c
@@ -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" */
diff --git a/salsa20.h b/salsa20.h
index be2662cf..3ce1a93e 100644
--- a/salsa20.h
+++ b/salsa20.h
@@ -68,19 +68,19 @@ struct salsa20_ctx
 
 void
 salsa20_set_key(struct salsa20_ctx *ctx,
-		unsigned length, const uint8_t *key);
+		size_t length, const uint8_t *key);
 
 void
 salsa20_set_iv(struct salsa20_ctx *ctx, const uint8_t *iv);
 
 void
 salsa20_crypt(struct salsa20_ctx *ctx,
-	      unsigned length, uint8_t *dst,
+	      size_t length, uint8_t *dst,
 	      const uint8_t *src);
 
 void
 salsa20r12_crypt(struct salsa20_ctx *ctx,
-		 unsigned length, uint8_t *dst,
+		 size_t length, uint8_t *dst,
 		 const uint8_t *src);
 
 void
diff --git a/salsa20r12-crypt.c b/salsa20r12-crypt.c
index a845f1d3..98075bca 100644
--- a/salsa20r12-crypt.c
+++ b/salsa20r12-crypt.c
@@ -42,9 +42,9 @@
 
 void
 salsa20r12_crypt(struct salsa20_ctx *ctx,
-	      unsigned length,
-	      uint8_t *c,
-	      const uint8_t *m)
+		 size_t length,
+		 uint8_t *c,
+		 const uint8_t *m)
 {
   uint32_t x[_SALSA20_INPUT_LENGTH];
 
diff --git a/serpent-decrypt.c b/serpent-decrypt.c
index a7ae661c..ecf6ed73 100644
--- a/serpent-decrypt.c
+++ b/serpent-decrypt.c
@@ -461,7 +461,7 @@
 
 void
 serpent_decrypt (const struct serpent_ctx *ctx,
-		 unsigned length, uint8_t * dst, const uint8_t * src)
+		 size_t length, uint8_t * dst, const uint8_t * src)
 {
   assert( !(length % SERPENT_BLOCK_SIZE));
 
diff --git a/serpent-encrypt.c b/serpent-encrypt.c
index 2c77f12d..c29998af 100644
--- a/serpent-encrypt.c
+++ b/serpent-encrypt.c
@@ -434,7 +434,7 @@
 
 void
 serpent_encrypt (const struct serpent_ctx *ctx,
-		 unsigned length, uint8_t * dst, const uint8_t * src)
+		 size_t length, uint8_t * dst, const uint8_t * src)
 {
   assert( !(length % SERPENT_BLOCK_SIZE));
   
diff --git a/serpent-set-key.c b/serpent-set-key.c
index ae854fc4..ace57537 100644
--- a/serpent-set-key.c
+++ b/serpent-set-key.c
@@ -316,7 +316,7 @@ serpent_key_pad (const uint8_t *key, unsigned int key_length,
 /* Initialize CONTEXT with the key KEY of KEY_LENGTH bits.  */
 void
 serpent_set_key (struct serpent_ctx *ctx,
-		 unsigned length, const uint8_t * key)
+		 size_t length, const uint8_t * key)
 {
   uint32_t w[8];
   uint32_t (*keys)[4];
diff --git a/serpent.h b/serpent.h
index 34010429..94262847 100644
--- a/serpent.h
+++ b/serpent.h
@@ -63,15 +63,15 @@ struct serpent_ctx
 
 void
 serpent_set_key(struct serpent_ctx *ctx,
-                unsigned length, const uint8_t *key);
+                size_t length, const uint8_t *key);
 
 void
 serpent_encrypt(const struct serpent_ctx *ctx,
-                unsigned length, uint8_t *dst,
+                size_t length, uint8_t *dst,
                 const uint8_t *src);
 void
 serpent_decrypt(const struct serpent_ctx *ctx,
-                unsigned length, uint8_t *dst,
+                size_t length, uint8_t *dst,
                 const uint8_t *src);
 
 #ifdef __cplusplus
diff --git a/twofish.c b/twofish.c
index 569a6278..86530911 100644
--- a/twofish.c
+++ b/twofish.c
@@ -275,7 +275,7 @@ h(int k, uint8_t x, uint32_t l0, uint32_t l1, uint32_t l2, uint32_t l3)
 
 void
 twofish_set_key(struct twofish_ctx *context,
-		unsigned keysize, const uint8_t *key)
+		size_t keysize, const uint8_t *key)
 {
   uint8_t key_copy[32];
   uint32_t m[8], s[4], t;
@@ -338,7 +338,7 @@ twofish_set_key(struct twofish_ctx *context,
 
 void
 twofish_encrypt(const struct twofish_ctx *context,
-		unsigned length,
+		size_t length,
 		uint8_t *ciphertext,
 		const uint8_t *plaintext)
 {
@@ -408,7 +408,7 @@ twofish_encrypt(const struct twofish_ctx *context,
 
 void
 twofish_decrypt(const struct twofish_ctx *context,
-		unsigned length,
+		size_t length,
 		uint8_t *plaintext,
 		const uint8_t *ciphertext)
 
diff --git a/twofish.h b/twofish.h
index 11e73a26..321ae936 100644
--- a/twofish.h
+++ b/twofish.h
@@ -60,15 +60,15 @@ struct twofish_ctx
 
 void
 twofish_set_key(struct twofish_ctx *ctx,
-		unsigned length, const uint8_t *key);
+		size_t length, const uint8_t *key);
 
 void
 twofish_encrypt(const struct twofish_ctx *ctx,
-		unsigned length, uint8_t *dst,
+		size_t length, uint8_t *dst,
 		const uint8_t *src);
 void
 twofish_decrypt(const struct twofish_ctx *ctx,
-		unsigned length, uint8_t *dst,
+		size_t length, uint8_t *dst,
 		const uint8_t *src);
 
 #ifdef __cplusplus
diff --git a/x86_64/aes-decrypt-internal.asm b/x86_64/aes-decrypt-internal.asm
index 0d4f2f92..606b7c89 100644
--- a/x86_64/aes-decrypt-internal.asm
+++ b/x86_64/aes-decrypt-internal.asm
@@ -33,14 +33,14 @@ define(<TC>,<%r12d>)
 
 define(<CTX>,	<%rdi>)
 define(<TABLE>,	<%rsi>)
-define(<PARAM_LENGTH>,<%edx>)		C Length is only 32 bits
+define(<PARAM_LENGTH>,<%rdx>)
 define(<PARAM_DST>,	<%rcx>)
 define(<SRC>,	<%r8>)
 
 define(<DST>, <%r9>) 
 define(<KEY>,<%r14>)
 define(<COUNT>,	<%r15d>)
-define(<BLOCK_COUNT>, <%r13d>)
+define(<BLOCK_COUNT>, <%r13>)
 
 C Must correspond to an old-style register, for movzb from %ah--%dh to
 C work.
@@ -50,7 +50,7 @@ define(<TMP>,<%rbp>)
 	
 	C _aes_decrypt(struct aes_context *ctx, 
 	C	       const struct aes_table *T,
-	C	       unsigned length, uint8_t *dst,
+	C	       size_t length, uint8_t *dst,
 	C	       uint8_t *src)
 	.text
 	ALIGN(16)
@@ -68,8 +68,8 @@ PROLOGUE(_nettle_aes_decrypt)
 	push	%r15	
 
 	mov	PARAM_DST, DST
-	movl	PARAM_LENGTH, BLOCK_COUNT
-	shrl	$4, BLOCK_COUNT
+	mov	PARAM_LENGTH, BLOCK_COUNT
+	shr	$4, BLOCK_COUNT
 .Lblock_loop:
 	mov	CTX,KEY
 	
@@ -119,7 +119,7 @@ PROLOGUE(_nettle_aes_decrypt)
 	AES_STORE(TA,TB,TC,SD, KEY, DST)
 	
 	add	$16, DST
-	decl	BLOCK_COUNT
+	dec	BLOCK_COUNT
 
 	jnz	.Lblock_loop
 
diff --git a/x86_64/aes-encrypt-internal.asm b/x86_64/aes-encrypt-internal.asm
index 4ae0ec85..e1003c69 100644
--- a/x86_64/aes-encrypt-internal.asm
+++ b/x86_64/aes-encrypt-internal.asm
@@ -33,14 +33,14 @@ define(<TC>,<%r12d>)
 
 define(<CTX>,	<%rdi>)
 define(<TABLE>,	<%rsi>)
-define(<PARAM_LENGTH>,<%edx>)		C Length is only 32 bits
+define(<PARAM_LENGTH>,<%rdx>)
 define(<PARAM_DST>,	<%rcx>)
 define(<SRC>,	<%r8>)
 
 define(<DST>, <%r9>) 
 define(<KEY>,<%r14>)
 define(<COUNT>,	<%r15d>)
-define(<BLOCK_COUNT>, <%r13d>)
+define(<BLOCK_COUNT>, <%r13>)
 
 C Must correspond to an old-style register, for movzb from %ah--%dh to
 C work.
@@ -50,7 +50,7 @@ define(<TMP>,<%rbp>)
 	
 	C _aes_encrypt(struct aes_context *ctx, 
 	C	       const struct aes_table *T,
-	C	       unsigned length, uint8_t *dst,
+	C	       size_t length, uint8_t *dst,
 	C	       uint8_t *src)
 	.text
 	ALIGN(16)
@@ -68,8 +68,8 @@ PROLOGUE(_nettle_aes_encrypt)
 	push	%r15	
 
 	mov	PARAM_DST, DST
-	movl	PARAM_LENGTH, BLOCK_COUNT
-	shrl	$4, BLOCK_COUNT
+	mov	PARAM_LENGTH, BLOCK_COUNT
+	shr	$4, BLOCK_COUNT
 .Lblock_loop:
 	mov	CTX,KEY
 	
@@ -119,7 +119,7 @@ PROLOGUE(_nettle_aes_encrypt)
 	AES_STORE(TA,TB,TC,SD, KEY, DST)
 	
 	add	$16, DST
-	decl	BLOCK_COUNT
+	dec	BLOCK_COUNT
 
 	jnz	.Lblock_loop
 
-- 
GitLab