]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Avoid >= 32 bit shifts when size_t is only 32 bits.
authorNiels Möller <nisse@lysator.liu.se>
Sat, 3 May 2014 07:52:23 +0000 (09:52 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Sat, 3 May 2014 07:52:23 +0000 (09:52 +0200)
ChangeLog
ccm.c
configure.ac

index de6cacc079cdf12fc12c1ccd1002bb4bac6a1c5f..7cdf88d8f3aee1c7e20959724fb6510e77b0bae1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2014-05-03  Niels Möller  <nisse@lysator.liu.se>
 
+       * configure.ac: Check for SIZEOF_SIZE_T.
+       * ccm.c (ccm_set_nonce): Skip code for 64-bit encoding when size_t
+       is only 32 bits.
+
        * nettle.texinfo (CCM): Document new ccm macros and constants.
        Describe ccm restrictions.
 
diff --git a/ccm.c b/ccm.c
index 5ca6e054570bf0085197b217a2f96fc99ff43bfe..c5ff790873883eec6eeb2bcbbe82b035821a286c 100644 (file)
--- a/ccm.c
+++ b/ccm.c
@@ -135,6 +135,7 @@ ccm_set_nonce(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
   /* Encrypt B0 (with the adata flag), and input L(a) to the CBC-MAC. */
   ctx->tag.b[CCM_OFFSET_FLAGS] |= CCM_FLAG_ADATA;
   f(cipher, CCM_BLOCK_SIZE, ctx->tag.b, ctx->tag.b);
+#if SIZEOF_SIZE_T > 4
   if (authlen >= (0x01ULL << 32)) {
     /* Encode L(a) as 0xff || 0xff || <64-bit integer> */
     ctx->tag.b[ctx->blength++] ^= 0xff;
@@ -146,13 +147,15 @@ ccm_set_nonce(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
     ctx->tag.b[ctx->blength++] ^= (authlen >> 24) & 0xff;
     ctx->tag.b[ctx->blength++] ^= (authlen >> 16) & 0xff;
   }
-  else if (authlen >= ((0x1ULL << 16) - (0x1ULL << 8))) {
-    /* Encode L(a) as 0xff || 0xfe || <32-bit integer> */
-    ctx->tag.b[ctx->blength++] ^= 0xff;
-    ctx->tag.b[ctx->blength++] ^= 0xfe;
-    ctx->tag.b[ctx->blength++] ^= (authlen >> 24) & 0xff;
-    ctx->tag.b[ctx->blength++] ^= (authlen >> 16) & 0xff;
-  }
+  else
+#endif
+    if (authlen >= ((0x1ULL << 16) - (0x1ULL << 8))) {
+      /* Encode L(a) as 0xff || 0xfe || <32-bit integer> */
+      ctx->tag.b[ctx->blength++] ^= 0xff;
+      ctx->tag.b[ctx->blength++] ^= 0xfe;
+      ctx->tag.b[ctx->blength++] ^= (authlen >> 24) & 0xff;
+      ctx->tag.b[ctx->blength++] ^= (authlen >> 16) & 0xff;
+    }
   ctx->tag.b[ctx->blength++] ^= (authlen >> 8) & 0xff;
   ctx->tag.b[ctx->blength++] ^= (authlen >> 0) & 0xff;
 }
index 81c9c8d919ebbff7bb87f9422092f44cd03fa154..4aac181233f9d267e21f468b44cf2a325cb598a6 100644 (file)
@@ -630,6 +630,7 @@ AC_TYPE_UID_T
 AC_TYPE_SIZE_T
 AC_HEADER_TIME
 AC_CHECK_SIZEOF(long)
+AC_CHECK_SIZEOF(size_t)
 
 AC_CHECK_HEADERS([openssl/blowfish.h openssl/des.h openssl/cast.h openssl/aes.h openssl/ecdsa.h],,
 [enable_openssl=no