tls: code shrink
authorDenys Vlasenko <vda.linux@googlemail.com>
Sun, 25 Nov 2018 13:03:59 +0000 (14:03 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sun, 25 Nov 2018 13:03:59 +0000 (14:03 +0100)
function                                             old     new   delta
aesgcm_GHASH                                         223     196     -27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
networking/tls.c
networking/tls_aesgcm.c

index 7bdd580180a81a0a0b2545d1aafb8ebe6cb6a90c..85a4e21dd3e852ccb188c1975125090ae9a8bd58 100644 (file)
@@ -867,7 +867,6 @@ static void xwrite_encrypted_aesgcm(tls_state_t *tls, unsigned size, unsigned ty
        xorbuf_aligned_AES_BLOCK_SIZE(authtag, scratch);
 
        memcpy(buf, authtag, sizeof(authtag));
-#undef COUNTER
 
        /* Write out */
        xhdr = (void*)(tls->outbuf + OUTBUF_PFX - 8 - RECHDR_LEN);
@@ -881,6 +880,7 @@ static void xwrite_encrypted_aesgcm(tls_state_t *tls, unsigned size, unsigned ty
        dump_raw_out(">> %s\n", xhdr, size);
        xwrite(tls->ofd, xhdr, size);
        dbg("wrote %u bytes\n", size);
+#undef COUNTER
 }
 
 static void xwrite_encrypted(tls_state_t *tls, unsigned size, unsigned type)
index 32ca40260bcba6cc6fbdb28f9513ca8fe7e85b9e..688df85fb619148d07c37adbd14ac92cd56770ff 100644 (file)
@@ -87,8 +87,8 @@ void FAST_FUNC aesgcm_GHASH(byte* h,
 )
 {
     byte x[AES_BLOCK_SIZE] ALIGNED_long;
-    byte scratch[AES_BLOCK_SIZE] ALIGNED_long;
-    word32 blocks, partial;
+//    byte scratch[AES_BLOCK_SIZE] ALIGNED_long;
+    unsigned blocks, partial;
     //was: byte* h = aes->H;
 
     //XMEMSET(x, 0, AES_BLOCK_SIZE);
@@ -133,9 +133,17 @@ void FAST_FUNC aesgcm_GHASH(byte* h,
     }
 
     /* Hash in the lengths of A and C in bits */
-    FlattenSzInBits(&scratch[0], aSz);
-    FlattenSzInBits(&scratch[8], cSz);
-    xorbuf_aligned_AES_BLOCK_SIZE(x, scratch);
+    //FlattenSzInBits(&scratch[0], aSz);
+    //FlattenSzInBits(&scratch[8], cSz);
+    //xorbuf_aligned_AES_BLOCK_SIZE(x, scratch);
+    // simpler:
+#define P32(v) ((uint32_t*)v)
+  //P32(x)[0] ^= 0;
+    P32(x)[1] ^= SWAP_BE32(aSz * 8);
+  //P32(x)[2] ^= 0;
+    P32(x)[3] ^= SWAP_BE32(cSz * 8);
+#undef P32
+
     GMULT(x, h);
 
     /* Copy the result into s. */