Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/crypto/aes Remove now-needless AES-CCM fallback logic.



details:   https://anonhg.NetBSD.org/src/rev/0958c8424ca9
branches:  trunk
changeset: 974153:0958c8424ca9
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sat Jul 25 22:36:42 2020 +0000

description:
Remove now-needless AES-CCM fallback logic.

These paths are no longer exercised because all of the aes_impls now
do the AES-CCM operations.

diffstat:

 sys/crypto/aes/aes_impl.c     |  56 +++---------------------------------------
 sys/crypto/aes/aes_selftest.c |  13 +--------
 2 files changed, 7 insertions(+), 62 deletions(-)

diffs (156 lines):

diff -r ea18195ce7f3 -r 0958c8424ca9 sys/crypto/aes/aes_impl.c
--- a/sys/crypto/aes/aes_impl.c Sat Jul 25 22:36:06 2020 +0000
+++ b/sys/crypto/aes/aes_impl.c Sat Jul 25 22:36:42 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: aes_impl.c,v 1.6 2020/07/25 22:27:53 riastradh Exp $   */
+/*     $NetBSD: aes_impl.c,v 1.7 2020/07/25 22:36:42 riastradh Exp $   */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aes_impl.c,v 1.6 2020/07/25 22:27:53 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_impl.c,v 1.7 2020/07/25 22:36:42 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/kernel.h>
@@ -288,16 +288,6 @@
        aes_impl->ai_xts_dec(dec, in, out, nbytes, tweak, nrounds);
 }
 
-static void
-xor16(uint8_t *x, const uint8_t *a, const uint8_t *b)
-{
-
-       le32enc(x + 4*0, le32dec(a + 4*0) ^ le32dec(b + 4*0));
-       le32enc(x + 4*1, le32dec(a + 4*1) ^ le32dec(b + 4*1));
-       le32enc(x + 4*2, le32dec(a + 4*2) ^ le32dec(b + 4*2));
-       le32enc(x + 4*3, le32dec(a + 4*3) ^ le32dec(b + 4*3));
-}
-
 void
 aes_cbcmac_update1(const struct aesenc *enc, const uint8_t in[static 16],
     size_t nbytes, uint8_t auth[static 16], uint32_t nrounds)
@@ -307,15 +297,7 @@
        KASSERT(nbytes % 16 == 0);
 
        aes_guarantee_selected();
-       if (aes_impl->ai_cbcmac_update1) {
-               aes_impl->ai_cbcmac_update1(enc, in, nbytes, auth, nrounds);
-               return;
-       }
-
-       for (; nbytes; in += 16, nbytes -= 16) {
-               xor16(auth, auth, in);
-               aes_enc(enc, auth, auth, nrounds);
-       }
+       aes_impl->ai_cbcmac_update1(enc, in, nbytes, auth, nrounds);
 }
 
 void
@@ -323,26 +305,12 @@
     uint8_t out[static 16], size_t nbytes, uint8_t authctr[static 32],
     uint32_t nrounds)
 {
-       uint8_t *auth = authctr;
-       uint8_t *ctr = authctr + 16;
 
        KASSERT(nbytes);
        KASSERT(nbytes % 16 == 0);
 
        aes_guarantee_selected();
-       if (aes_impl->ai_ccm_enc1) {
-               aes_impl->ai_ccm_enc1(enc, in, out, nbytes, auth, nrounds);
-               return;
-       }
-
-       for (; nbytes; in += 16, out += 16, nbytes -= 16) {
-               xor16(auth, auth, in);
-               aes_enc(enc, auth, auth, nrounds);
-
-               be32enc(ctr + 12, 1 + be32dec(ctr + 12));
-               aes_enc(enc, ctr, out, nrounds);
-               xor16(out, out, in);
-       }
+       aes_impl->ai_ccm_enc1(enc, in, out, nbytes, authctr, nrounds);
 }
 
 void
@@ -350,26 +318,12 @@
     uint8_t out[static 16], size_t nbytes, uint8_t authctr[static 32],
     uint32_t nrounds)
 {
-       uint8_t *auth = authctr;
-       uint8_t *ctr = authctr + 16;
 
        KASSERT(nbytes);
        KASSERT(nbytes % 16 == 0);
 
        aes_guarantee_selected();
-       if (aes_impl->ai_ccm_dec1) {
-               aes_impl->ai_ccm_dec1(enc, in, out, nbytes, auth, nrounds);
-               return;
-       }
-
-       for (; nbytes >= 16; in += 16, out += 16, nbytes -= 16) {
-               be32enc(ctr + 12, 1 + be32dec(ctr + 12));
-               aes_enc(enc, ctr, out, nrounds);
-               xor16(out, out, in);
-
-               xor16(auth, auth, out);
-               aes_enc(enc, auth, auth, nrounds);
-       }
+       aes_impl->ai_ccm_dec1(enc, in, out, nbytes, authctr, nrounds);
 }
 
 /*
diff -r ea18195ce7f3 -r 0958c8424ca9 sys/crypto/aes/aes_selftest.c
--- a/sys/crypto/aes/aes_selftest.c     Sat Jul 25 22:36:06 2020 +0000
+++ b/sys/crypto/aes/aes_selftest.c     Sat Jul 25 22:36:42 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: aes_selftest.c,v 1.4 2020/07/25 22:27:53 riastradh Exp $       */
+/*     $NetBSD: aes_selftest.c,v 1.5 2020/07/25 22:36:42 riastradh Exp $       */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aes_selftest.c,v 1.4 2020/07/25 22:27:53 riastradh Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aes_selftest.c,v 1.5 2020/07/25 22:36:42 riastradh Exp $");
 
 #ifdef _KERNEL
 
@@ -424,9 +424,6 @@
        uint8_t auth[16];
        const unsigned nr = AES_128_NROUNDS;
 
-       if (impl->ai_cbcmac_update1 == NULL)
-               return 0;
-
        memset(auth, 0, sizeof auth);
 
        impl->ai_setenckey(&enc, key, nr);
@@ -500,9 +497,6 @@
        const unsigned nr = AES_128_NROUNDS;
        int result = 0;
 
-       if (impl->ai_ccm_enc1 == NULL)
-               return 0;
-
        impl->ai_setenckey(&enc, key, nr);
 
        memset(authctr, 0, 16);
@@ -521,9 +515,6 @@
                result |= aes_selftest_fail(impl, buf, ctxt, 48,
                    "AES-128 CCM ciphertext");
 
-       if (impl->ai_ccm_dec1 == NULL)
-               return result;
-
        memset(authctr, 0, 16);
        memcpy(authctr + 16, ctr0, 16);
 



Home | Main Index | Thread Index | Old Index