Author: jhb
Date: Mon Feb 26 22:12:31 2018
New Revision: 330041
URL: https://svnweb.freebsd.org/changeset/base/330041

Log:
  Move ccr_aes_getdeckey() from ccr(4) to the cxgbe(4) driver.
  
  This routine will also be used by the TOE module to manage TLS keys.
  
  Sponsored by: Chelsio Communications

Modified:
  head/sys/dev/cxgbe/adapter.h
  head/sys/dev/cxgbe/crypto/t4_crypto.c
  head/sys/dev/cxgbe/t4_main.c

Modified: head/sys/dev/cxgbe/adapter.h
==============================================================================
--- head/sys/dev/cxgbe/adapter.h        Mon Feb 26 21:56:06 2018        
(r330040)
+++ head/sys/dev/cxgbe/adapter.h        Mon Feb 26 22:12:31 2018        
(r330041)
@@ -1138,6 +1138,7 @@ void t4_os_link_changed(struct port_info *);
 void t4_iterate(void (*)(struct adapter *, void *), void *);
 void t4_init_devnames(struct adapter *);
 void t4_add_adapter(struct adapter *);
+void t4_aes_getdeckey(void *, const void *, unsigned int);
 int t4_detach_common(device_t);
 int t4_filter_rpl(struct sge_iq *, const struct rss_header *, struct mbuf *);
 int t4_map_bars_0_and_4(struct adapter *);

Modified: head/sys/dev/cxgbe/crypto/t4_crypto.c
==============================================================================
--- head/sys/dev/cxgbe/crypto/t4_crypto.c       Mon Feb 26 21:56:06 2018        
(r330040)
+++ head/sys/dev/cxgbe/crypto/t4_crypto.c       Mon Feb 26 22:12:31 2018        
(r330041)
@@ -1821,46 +1821,7 @@ ccr_aes_check_keylen(int alg, int klen)
        return (0);
 }
 
-/*
- * Borrowed from cesa_prep_aes_key().  We should perhaps have a public
- * function to generate this instead.
- *
- * NB: The crypto engine wants the words in the decryption key in reverse
- * order.
- */
 static void
-ccr_aes_getdeckey(void *dec_key, const void *enc_key, unsigned int kbits)
-{
-       uint32_t ek[4 * (RIJNDAEL_MAXNR + 1)];
-       uint32_t *dkey;
-       int i;
-
-       rijndaelKeySetupEnc(ek, enc_key, kbits);
-       dkey = dec_key;
-       dkey += (kbits / 8) / 4;
-
-       switch (kbits) {
-       case 128:
-               for (i = 0; i < 4; i++)
-                       *--dkey = htobe32(ek[4 * 10 + i]);
-               break;
-       case 192:
-               for (i = 0; i < 2; i++)
-                       *--dkey = htobe32(ek[4 * 11 + 2 + i]);
-               for (i = 0; i < 4; i++)
-                       *--dkey = htobe32(ek[4 * 12 + i]);
-               break;
-       case 256:
-               for (i = 0; i < 4; i++)
-                       *--dkey = htobe32(ek[4 * 13 + i]);
-               for (i = 0; i < 4; i++)
-                       *--dkey = htobe32(ek[4 * 14 + i]);
-               break;
-       }
-       MPASS(dkey == dec_key);
-}
-
-static void
 ccr_aes_setkey(struct ccr_session *s, int alg, const void *key, int klen)
 {
        unsigned int ck_size, iopad_size, kctx_flits, kctx_len, kbits, mk_size;
@@ -1889,7 +1850,7 @@ ccr_aes_setkey(struct ccr_session *s, int alg, const v
        switch (alg) {
        case CRYPTO_AES_CBC:
        case CRYPTO_AES_XTS:
-               ccr_aes_getdeckey(s->blkcipher.deckey, key, kbits);
+               t4_aes_getdeckey(s->blkcipher.deckey, key, kbits);
                break;
        }
 

Modified: head/sys/dev/cxgbe/t4_main.c
==============================================================================
--- head/sys/dev/cxgbe/t4_main.c        Mon Feb 26 21:56:06 2018        
(r330040)
+++ head/sys/dev/cxgbe/t4_main.c        Mon Feb 26 22:12:31 2018        
(r330041)
@@ -67,6 +67,7 @@ __FBSDID("$FreeBSD$");
 #include <machine/cputypes.h>
 #include <vm/vm.h>
 #include <vm/pmap.h>
+#include <crypto/rijndael/rijndael.h>
 #endif
 #ifdef DDB
 #include <ddb/ddb.h>
@@ -10183,6 +10184,44 @@ DB_FUNC(tcb, db_show_t4tcb, db_t4_table, CS_OWN, NULL)
        t4_dump_tcb(device_get_softc(dev), tid);
 }
 #endif
+
+/*
+ * Borrowed from cesa_prep_aes_key().
+ *
+ * NB: The crypto engine wants the words in the decryption key in reverse
+ * order.
+ */
+void
+t4_aes_getdeckey(void *dec_key, const void *enc_key, unsigned int kbits)
+{
+       uint32_t ek[4 * (RIJNDAEL_MAXNR + 1)];
+       uint32_t *dkey;
+       int i;
+
+       rijndaelKeySetupEnc(ek, enc_key, kbits);
+       dkey = dec_key;
+       dkey += (kbits / 8) / 4;
+
+       switch (kbits) {
+       case 128:
+               for (i = 0; i < 4; i++)
+                       *--dkey = htobe32(ek[4 * 10 + i]);
+               break;
+       case 192:
+               for (i = 0; i < 2; i++)
+                       *--dkey = htobe32(ek[4 * 11 + 2 + i]);
+               for (i = 0; i < 4; i++)
+                       *--dkey = htobe32(ek[4 * 12 + i]);
+               break;
+       case 256:
+               for (i = 0; i < 4; i++)
+                       *--dkey = htobe32(ek[4 * 13 + i]);
+               for (i = 0; i < 4; i++)
+                       *--dkey = htobe32(ek[4 * 14 + i]);
+               break;
+       }
+       MPASS(dkey == dec_key);
+}
 
 static struct sx mlu;  /* mod load unload */
 SX_SYSINIT(cxgbe_mlu, &mlu, "cxgbe mod load/unload");
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to