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
This commit is contained in:
parent
1832e4d5e2
commit
fef2b66bec
@ -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 *);
|
||||
|
@ -1821,45 +1821,6 @@ 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)
|
||||
{
|
||||
@ -1889,7 +1850,7 @@ ccr_aes_setkey(struct ccr_session *s, int alg, const void *key, int klen)
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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>
|
||||
@ -10184,6 +10185,44 @@ DB_FUNC(tcb, db_show_t4tcb, db_t4_table, CS_OWN, NULL)
|
||||
}
|
||||
#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");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user