From owner-svn-src-head@freebsd.org Mon Feb 26 22:12:32 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5775DF27368; Mon, 26 Feb 2018 22:12:32 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 0D6046CEE7; Mon, 26 Feb 2018 22:12:32 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 076202164F; Mon, 26 Feb 2018 22:12:32 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1QMCVcP015294; Mon, 26 Feb 2018 22:12:31 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1QMCVUW015291; Mon, 26 Feb 2018 22:12:31 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201802262212.w1QMCVUW015291@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Mon, 26 Feb 2018 22:12:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r330041 - in head/sys/dev/cxgbe: . crypto X-SVN-Group: head X-SVN-Commit-Author: jhb X-SVN-Commit-Paths: in head/sys/dev/cxgbe: . crypto X-SVN-Commit-Revision: 330041 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Feb 2018 22:12:32 -0000 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 #include #include +#include #endif #ifdef DDB #include @@ -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");