diff --git a/ChangeLog b/ChangeLog
index db3ed0e2c56973874097fe6be5e5979247335353..6dde9a7e113c2093fad70b4698a15aac7e281771 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 7236208dca3b935b377211b921759585be1190c3..af2891e9fc2582ebfd79465dba302cffae88e2e5 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 47fe3c10b23dd28c5e036ec10e93c7a559d36aa9..96862e4787018b6807926c2c364a65d6b00f7c03 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 9b16153cf8cccb896076115dc2e59a0c645c90b9..cf9d82475328b96543e796fe9fcaeddc74595334 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 60f803de13f4ebfecd3fffa6257dff7dc595ebf4..f28ac3197c2a9b7983eb7f379e1749e8f1ef191b 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 42fc4dec8c1e86fd60710542e8be463142bb0875..e361bde93e5bc1d7f6c58456aecbd6b20de41157 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 640e9455133f457b4e8fedbdb61c5c402364739c..04e4c992087b303278a911b0739c5f68e6eae6a1 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 e5494c86eb5493c7886337926f32a048c4a67a27..04f53270f38c8cef3ab54f63da0bcb6ae67601fd 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 b3482e2395b354b7e4954b508db6103fc9fd7535..b3bb965912b9e65070c4cfc20e4a7d8f824f69fc 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 d7f7c567983e9183b081d386e1a3b851ea200bf6..c8ebb9a9a2f89a04e08bfa9f8d22aabba41079fd 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 d7286e5eee093f8d9380fea52967b0906295ed42..0977d09217759a0e705b0e32ae40259ea418ea42 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 fb5399740a2d1d623e1a471f3214bb17ba1d7cc1..cedae8b10b16e4591748a5719c2cc16d5bf2f159 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 c4bc155199c7cde498aefbd517f10b77f5b65463..f5753a8c3d665f9c525ba66f4b628bf6e90b92ad 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 6f763bb95b865728e476c355fe8a737ba322018a..3f1a3be932e3f468d80053dd4aae6d9effdca85f 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 4be084f16aeb91cd2d937e0788eb176810e85846..0ffa332d60678bfb2c6461e7d1a53537ea294df6 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 02f9f7d7fd03d1de98da3498879361cdad3a4007..01ed0d377ce27d90314c0d5600555813f8109e45 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 21c52400324f8ea3a7d8502e04e94e91e3ec6ebd..6945323544f28631c62377678dc42bcc277d1435 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 ca5d72f3009a57b7cdde023df7ab21661184110d..def5d8456f184a40708cf3065daa5c064385fd4f 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 c0f67c8aed5b2d72378a7c994b4647d35a6eb8ae..ee41a44798515a903b039785c12ef787782d1d99 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 f1a5bb815e56c9792d195f0b5d5cd52a4aa17437..329fa3c9834ffa582d8e90c8a9eaa42f8807eadc 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 408ed7219b008c1cee958099ac5eed3fd029755b..7dd907753f8cb09b6bf7e6b2be3e5ec792219530 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 ed200727ca9b21ca36b3b93d9203ee26be740abc..c0b457617035e385b4b2ad3c3d537fdf26e88a51 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 512c55d2cc71a6e3ecd312883e822b93d247870c..ca7faac437bf884483260382fbe97f615901dfed 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 d10ec6027c86e502325252d7ba1d06bed5d6df6b..63636d2191eabaa8df8df2ef6fd5ab7582057714 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 e70619b3f45de0a94e9b71b422202c7b0939b383..16edd4dd6188740ec34341b23dead47017d301b9 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 8eef80361a66016c7de5347661aaf61feec1edac..eb01239c563ea1292dfaafe9515d90b2dced05a9 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 6b97030580a37e565f02e9df3eabc9b2db9e76ac..80a072b4aa1d02563fac798eb0ae0d9d5930c624 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 582a39458ec1162acf2eeb7d3e5d8545cd4672e2..14d520d3171bcca00e4a0cd3814bc1fe9d40aa8c 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 8bb1bef493c7b472ddbd31f82cc6bd6676e658bc..555f1e6cd8b40a99f5e2557458c5118de59606e7 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 df4d345ece3bac1737d1363fd45b40259dfb6695..edbdc14ed6d0fb86975dfedaecdb056fa6d7a1ad 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 b2183ffbabc6d746dd163f40f2e69d00984f4d65..84c7c1a7c1439a3b3ee9cf001ac13db2b4b0b2de 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 53c2025223fd8e37ee9914c36c5f1b05375febca..5805b66201826e9efc4a7cb3ef7ec0df1f8572f6 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 c88cb0dc77360b93afc40a223d3d3fb4b49a8fc5..194a0d823e105106ac968ca9fe8f47773975d9e9 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 8c69327789ad3dc5d260e9e0b152132437c42fbb..de5321e7210f944fd226f289aa9c48f5bc6ac87d 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 e201e98efb86e6b026d99170651be07a9321d626..b42c995781141d0fe11edf658068d3bd3346a13f 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 f271eac051a20d73738e2c68600aea26e2ff9032..5cd582884d0c9355a5e1fdbd803d06cb9565b6c9 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 16cc77bc703be7a5bbc36929bef77260186127f0..59f5c41e762267b9d6ae868c249822175917f0be 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 4d5e38ab260408b6f1f210de0614fc13c5d7ae38..5f7738e7ea20feaf583af1283689234bf4755bf4 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 82abceaabcbe8ee813f8e0512380f5f476ba02a2..29e92b3d13f318744329e391b2d500b1bd33b49e 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 da4d64328a6d767b525b20fc0d1af75c1d097aee..661aacc2d192d048bc734630af69539e716819de 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 be2662cf1c069bd553c6f9ee02142052af95978e..3ce1a93e8abaeed1b6a89a61b609022b53edb987 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 a845f1d3296fd8eec97399fa5244634160f2ffa6..98075bca2009625d3eb7d5eb72fedd6fedac0e55 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 a7ae661cb3096a203d92a9c045de5a2502a5a9da..ecf6ed7334113bb5691073cdeb1cb081f8615768 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 2c77f12da592efdb985ddb8691b26989e7547450..c29998afb3385bb2acc8b2d014ab1219884572d0 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 ae854fc4fa12ae881347370e34174165156213d3..ace575372eb85308ec0dbbfe56c78d2e4e181ba2 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 340104296bd3359d8994e5f26fecc771f5e29234..942628478c31df7eabb322c461932c454e234d1b 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 569a6278a471b0265678860fee57d502340da2b9..86530911ce79fad40849e0001f78da2faf2afe79 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 11e73a26c4b2bc4a509263a44cf0e5cd02cee309..321ae936c9de38dbd33b531dfcf7e48f62628a8e 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 0d4f2f92cff7da863634d5aedfe4f868cb9baca0..606b7c89e559dd69e1006e2001093d1665ea2476 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 4ae0ec858b07851106a50f023a61e31d3987c852..e1003c69941710e6e6c621f1867784fefaca8e54 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