aboutsummaryrefslogtreecommitdiff
path: root/sys/mips/cavium
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2020-03-27 18:25:23 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2020-03-27 18:25:23 +0000
commitc03414326909ed7a740be3ba63fbbef01fe513a8 (patch)
tree9067f28738df03bb4b685773c52ba32517468212 /sys/mips/cavium
parent4d94781b4d9e03b8dbd6604d7e2280d342d3cf7e (diff)
downloadsrc-c03414326909ed7a740be3ba63fbbef01fe513a8.tar.gz
src-c03414326909ed7a740be3ba63fbbef01fe513a8.zip
Refactor driver and consumer interfaces for OCF (in-kernel crypto).
- The linked list of cryptoini structures used in session initialization is replaced with a new flat structure: struct crypto_session_params. This session includes a new mode to define how the other fields should be interpreted. Available modes include: - COMPRESS (for compression/decompression) - CIPHER (for simply encryption/decryption) - DIGEST (computing and verifying digests) - AEAD (combined auth and encryption such as AES-GCM and AES-CCM) - ETA (combined auth and encryption using encrypt-then-authenticate) Additional modes could be added in the future (e.g. if we wanted to support TLS MtE for AES-CBC in the kernel we could add a new mode for that. TLS modes might also affect how AAD is interpreted, etc.) The flat structure also includes the key lengths and algorithms as before. However, code doesn't have to walk the linked list and switch on the algorithm to determine which key is the auth key vs encryption key. The 'csp_auth_*' fields are always used for auth keys and settings and 'csp_cipher_*' for cipher. (Compression algorithms are stored in csp_cipher_alg.) - Drivers no longer register a list of supported algorithms. This doesn't quite work when you factor in modes (e.g. a driver might support both AES-CBC and SHA2-256-HMAC separately but not combined for ETA). Instead, a new 'crypto_probesession' method has been added to the kobj interface for symmteric crypto drivers. This method returns a negative value on success (similar to how device_probe works) and the crypto framework uses this value to pick the "best" driver. There are three constants for hardware (e.g. ccr), accelerated software (e.g. aesni), and plain software (cryptosoft) that give preference in that order. One effect of this is that if you request only hardware when creating a new session, you will no longer get a session using accelerated software. Another effect is that the default setting to disallow software crypto via /dev/crypto now disables accelerated software. Once a driver is chosen, 'crypto_newsession' is invoked as before. - Crypto operations are now solely described by the flat 'cryptop' structure. The linked list of descriptors has been removed. A separate enum has been added to describe the type of data buffer in use instead of using CRYPTO_F_* flags to make it easier to add more types in the future if needed (e.g. wired userspace buffers for zero-copy). It will also make it easier to re-introduce separate input and output buffers (in-kernel TLS would benefit from this). Try to make the flags related to IV handling less insane: - CRYPTO_F_IV_SEPARATE means that the IV is stored in the 'crp_iv' member of the operation structure. If this flag is not set, the IV is stored in the data buffer at the 'crp_iv_start' offset. - CRYPTO_F_IV_GENERATE means that a random IV should be generated and stored into the data buffer. This cannot be used with CRYPTO_F_IV_SEPARATE. If a consumer wants to deal with explicit vs implicit IVs, etc. it can always generate the IV however it needs and store partial IVs in the buffer and the full IV/nonce in crp_iv and set CRYPTO_F_IV_SEPARATE. The layout of the buffer is now described via fields in cryptop. crp_aad_start and crp_aad_length define the boundaries of any AAD. Previously with GCM and CCM you defined an auth crd with this range, but for ETA your auth crd had to span both the AAD and plaintext (and they had to be adjacent). crp_payload_start and crp_payload_length define the boundaries of the plaintext/ciphertext. Modes that only do a single operation (COMPRESS, CIPHER, DIGEST) should only use this region and leave the AAD region empty. If a digest is present (or should be generated), it's starting location is marked by crp_digest_start. Instead of using the CRD_F_ENCRYPT flag to determine the direction of the operation, cryptop now includes an 'op' field defining the operation to perform. For digests I've added a new VERIFY digest mode which assumes a digest is present in the input and fails the request with EBADMSG if it doesn't match the internally-computed digest. GCM and CCM already assumed this, and the new AEAD mode requires this for decryption. The new ETA mode now also requires this for decryption, so IPsec and GELI no longer do their own authentication verification. Simple DIGEST operations can also do this, though there are no in-tree consumers. To eventually support some refcounting to close races, the session cookie is now passed to crypto_getop() and clients should no longer set crp_sesssion directly. - Assymteric crypto operation structures should be allocated via crypto_getkreq() and freed via crypto_freekreq(). This permits the crypto layer to track open asym requests and close races with a driver trying to unregister while asym requests are in flight. - crypto_copyback, crypto_copydata, crypto_apply, and crypto_contiguous_subsegment now accept the 'crp' object as the first parameter instead of individual members. This makes it easier to deal with different buffer types in the future as well as separate input and output buffers. It's also simpler for driver writers to use. - bus_dmamap_load_crp() loads a DMA mapping for a crypto buffer. This understands the various types of buffers so that drivers that use DMA do not have to be aware of different buffer types. - Helper routines now exist to build an auth context for HMAC IPAD and OPAD. This reduces some duplicated work among drivers. - Key buffers are now treated as const throughout the framework and in device drivers. However, session key buffers provided when a session is created are expected to remain alive for the duration of the session. - GCM and CCM sessions now only specify a cipher algorithm and a cipher key. The redundant auth information is not needed or used. - For cryptosoft, split up the code a bit such that the 'process' callback now invokes a function pointer in the session. This function pointer is set based on the mode (in effect) though it simplifies a few edge cases that would otherwise be in the switch in 'process'. It does split up GCM vs CCM which I think is more readable even if there is some duplication. - I changed /dev/crypto to support GMAC requests using CRYPTO_AES_NIST_GMAC as an auth algorithm and updated cryptocheck to work with it. - Combined cipher and auth sessions via /dev/crypto now always use ETA mode. The COP_F_CIPHER_FIRST flag is now a no-op that is ignored. This was actually documented as being true in crypto(4) before, but the code had not implemented this before I added the CIPHER_FIRST flag. - I have not yet updated /dev/crypto to be aware of explicit modes for sessions. I will probably do that at some point in the future as well as teach it about IV/nonce and tag lengths for AEAD so we can support all of the NIST KAT tests for GCM and CCM. - I've split up the exising crypto.9 manpage into several pages of which many are written from scratch. - I have converted all drivers and consumers in the tree and verified that they compile, but I have not tested all of them. I have tested the following drivers: - cryptosoft - aesni (AES only) - blake2 - ccr and the following consumers: - cryptodev - IPsec - ktls_ocf - GELI (lightly) I have not tested the following: - ccp - aesni with sha - hifn - kgssapi_krb5 - ubsec - padlock - safe - armv8_crypto (aarch64) - glxsb (i386) - sec (ppc) - cesa (armv7) - cryptocteon (mips64) - nlmsec (mips64) Discussed with: cem Relnotes: yes Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D23677
Notes
Notes: svn path=/head/; revision=359374
Diffstat (limited to 'sys/mips/cavium')
-rw-r--r--sys/mips/cavium/cryptocteon/cavium_crypto.c180
-rw-r--r--sys/mips/cavium/cryptocteon/cryptocteon.c449
-rw-r--r--sys/mips/cavium/cryptocteon/cryptocteonvar.h12
3 files changed, 309 insertions, 332 deletions
diff --git a/sys/mips/cavium/cryptocteon/cavium_crypto.c b/sys/mips/cavium/cryptocteon/cavium_crypto.c
index 6ff0e6f58440..e68a2757b466 100644
--- a/sys/mips/cavium/cryptocteon/cavium_crypto.c
+++ b/sys/mips/cavium/cryptocteon/cavium_crypto.c
@@ -328,7 +328,7 @@ octo_des_cbc_encrypt(
struct iovec *iov, size_t iovcnt, size_t iovlen,
int auth_off, int auth_len,
int crypt_off, int crypt_len,
- int icv_off, uint8_t *ivp)
+ uint8_t *icv, uint8_t *ivp)
{
uint64_t *data;
int data_i, data_l;
@@ -339,8 +339,8 @@ octo_des_cbc_encrypt(
(crypt_off & 0x7) || (crypt_off + crypt_len > iovlen))) {
dprintf("%s: Bad parameters od=%p iov=%p iovlen=%jd "
"auth_off=%d auth_len=%d crypt_off=%d crypt_len=%d "
- "icv_off=%d ivp=%p\n", __func__, od, iov, iovlen,
- auth_off, auth_len, crypt_off, crypt_len, icv_off, ivp);
+ "icv=%p ivp=%p\n", __func__, od, iov, iovlen,
+ auth_off, auth_len, crypt_off, crypt_len, icv, ivp);
return -EINVAL;
}
@@ -387,7 +387,7 @@ octo_des_cbc_decrypt(
struct iovec *iov, size_t iovcnt, size_t iovlen,
int auth_off, int auth_len,
int crypt_off, int crypt_len,
- int icv_off, uint8_t *ivp)
+ uint8_t *icv, uint8_t *ivp)
{
uint64_t *data;
int data_i, data_l;
@@ -398,8 +398,8 @@ octo_des_cbc_decrypt(
(crypt_off & 0x7) || (crypt_off + crypt_len > iovlen))) {
dprintf("%s: Bad parameters od=%p iov=%p iovlen=%jd "
"auth_off=%d auth_len=%d crypt_off=%d crypt_len=%d "
- "icv_off=%d ivp=%p\n", __func__, od, iov, iovlen,
- auth_off, auth_len, crypt_off, crypt_len, icv_off, ivp);
+ "icv=%p ivp=%p\n", __func__, od, iov, iovlen,
+ auth_off, auth_len, crypt_off, crypt_len, icv, ivp);
return -EINVAL;
}
@@ -447,7 +447,7 @@ octo_aes_cbc_encrypt(
struct iovec *iov, size_t iovcnt, size_t iovlen,
int auth_off, int auth_len,
int crypt_off, int crypt_len,
- int icv_off, uint8_t *ivp)
+ uint8_t *icv, uint8_t *ivp)
{
uint64_t *data, *pdata;
int data_i, data_l;
@@ -458,8 +458,8 @@ octo_aes_cbc_encrypt(
(crypt_off & 0x7) || (crypt_off + crypt_len > iovlen))) {
dprintf("%s: Bad parameters od=%p iov=%p iovlen=%jd "
"auth_off=%d auth_len=%d crypt_off=%d crypt_len=%d "
- "icv_off=%d ivp=%p\n", __func__, od, iov, iovlen,
- auth_off, auth_len, crypt_off, crypt_len, icv_off, ivp);
+ "icv=%p ivp=%p\n", __func__, od, iov, iovlen,
+ auth_off, auth_len, crypt_off, crypt_len, icv, ivp);
return -EINVAL;
}
@@ -516,7 +516,7 @@ octo_aes_cbc_decrypt(
struct iovec *iov, size_t iovcnt, size_t iovlen,
int auth_off, int auth_len,
int crypt_off, int crypt_len,
- int icv_off, uint8_t *ivp)
+ uint8_t *icv, uint8_t *ivp)
{
uint64_t *data, *pdata;
int data_i, data_l;
@@ -527,8 +527,8 @@ octo_aes_cbc_decrypt(
(crypt_off & 0x7) || (crypt_off + crypt_len > iovlen))) {
dprintf("%s: Bad parameters od=%p iov=%p iovlen=%jd "
"auth_off=%d auth_len=%d crypt_off=%d crypt_len=%d "
- "icv_off=%d ivp=%p\n", __func__, od, iov, iovlen,
- auth_off, auth_len, crypt_off, crypt_len, icv_off, ivp);
+ "icv=%p ivp=%p\n", __func__, od, iov, iovlen,
+ auth_off, auth_len, crypt_off, crypt_len, icv, ivp);
return -EINVAL;
}
@@ -587,7 +587,7 @@ octo_null_md5_encrypt(
struct iovec *iov, size_t iovcnt, size_t iovlen,
int auth_off, int auth_len,
int crypt_off, int crypt_len,
- int icv_off, uint8_t *ivp)
+ uint8_t *icv, uint8_t *ivp)
{
int next = 0;
uint64_t *data;
@@ -600,8 +600,8 @@ octo_null_md5_encrypt(
(auth_off & 0x7) || (auth_off + auth_len > iovlen))) {
dprintf("%s: Bad parameters od=%p iov=%p iovlen=%jd "
"auth_off=%d auth_len=%d crypt_off=%d crypt_len=%d "
- "icv_off=%d ivp=%p\n", __func__, od, iov, iovlen,
- auth_off, auth_len, crypt_off, crypt_len, icv_off, ivp);
+ "icv=%p ivp=%p\n", __func__, od, iov, iovlen,
+ auth_off, auth_len, crypt_off, crypt_len, icv, ivp);
return -EINVAL;
}
@@ -667,13 +667,9 @@ octo_null_md5_encrypt(
CVMX_MT_HSH_STARTMD5(tmp1);
/* save the HMAC */
- IOV_INIT(iov, data, data_i, data_l);
- while (icv_off > 0) {
- IOV_CONSUME(iov, data, data_i, data_l);
- icv_off -= 8;
- }
+ data = (uint64_t *)icv;
CVMX_MF_HSH_IV(*data, 0);
- IOV_CONSUME(iov, data, data_i, data_l);
+ data++;
CVMX_MF_HSH_IV(tmp1, 1);
*(uint32_t *)data = (uint32_t) (tmp1 >> 32);
@@ -689,7 +685,7 @@ octo_null_sha1_encrypt(
struct iovec *iov, size_t iovcnt, size_t iovlen,
int auth_off, int auth_len,
int crypt_off, int crypt_len,
- int icv_off, uint8_t *ivp)
+ uint8_t *icv, uint8_t *ivp)
{
int next = 0;
uint64_t *data;
@@ -702,8 +698,8 @@ octo_null_sha1_encrypt(
(auth_off & 0x7) || (auth_off + auth_len > iovlen))) {
dprintf("%s: Bad parameters od=%p iov=%p iovlen=%jd "
"auth_off=%d auth_len=%d crypt_off=%d crypt_len=%d "
- "icv_off=%d ivp=%p\n", __func__, od, iov, iovlen,
- auth_off, auth_len, crypt_off, crypt_len, icv_off, ivp);
+ "icv=%p ivp=%p\n", __func__, od, iov, iovlen,
+ auth_off, auth_len, crypt_off, crypt_len, icv, ivp);
return -EINVAL;
}
@@ -772,13 +768,9 @@ octo_null_sha1_encrypt(
CVMX_MT_HSH_STARTSHA((uint64_t) ((64 + 20) << 3));
/* save the HMAC */
- IOV_INIT(iov, data, data_i, data_l);
- while (icv_off > 0) {
- IOV_CONSUME(iov, data, data_i, data_l);
- icv_off -= 8;
- }
+ data = (uint64_t *)icv;
CVMX_MF_HSH_IV(*data, 0);
- IOV_CONSUME(iov, data, data_i, data_l);
+ data++;
CVMX_MF_HSH_IV(tmp1, 1);
*(uint32_t *)data = (uint32_t) (tmp1 >> 32);
@@ -794,7 +786,7 @@ octo_des_cbc_md5_encrypt(
struct iovec *iov, size_t iovcnt, size_t iovlen,
int auth_off, int auth_len,
int crypt_off, int crypt_len,
- int icv_off, uint8_t *ivp)
+ uint8_t *icv, uint8_t *ivp)
{
int next = 0;
union {
@@ -815,8 +807,8 @@ octo_des_cbc_md5_encrypt(
(auth_off & 0x3) || (auth_off + auth_len > iovlen))) {
dprintf("%s: Bad parameters od=%p iov=%p iovlen=%jd "
"auth_off=%d auth_len=%d crypt_off=%d crypt_len=%d "
- "icv_off=%d ivp=%p\n", __func__, od, iov, iovlen,
- auth_off, auth_len, crypt_off, crypt_len, icv_off, ivp);
+ "icv=%p ivp=%p\n", __func__, od, iov, iovlen,
+ auth_off, auth_len, crypt_off, crypt_len, icv, ivp);
return -EINVAL;
}
@@ -920,16 +912,12 @@ octo_des_cbc_md5_encrypt(
CVMX_MT_HSH_STARTMD5(tmp1);
/* save the HMAC */
- IOV_INIT(iov, data32, data_i, data_l);
- while (icv_off > 0) {
- IOV_CONSUME(iov, data32, data_i, data_l);
- icv_off -= 4;
- }
+ data32 = (uint32_t *)icv;
CVMX_MF_HSH_IV(tmp1, 0);
*data32 = (uint32_t) (tmp1 >> 32);
- IOV_CONSUME(iov, data32, data_i, data_l);
+ data32++;
*data32 = (uint32_t) tmp1;
- IOV_CONSUME(iov, data32, data_i, data_l);
+ data32++;
CVMX_MF_HSH_IV(tmp1, 1);
*data32 = (uint32_t) (tmp1 >> 32);
@@ -942,7 +930,7 @@ octo_des_cbc_md5_decrypt(
struct iovec *iov, size_t iovcnt, size_t iovlen,
int auth_off, int auth_len,
int crypt_off, int crypt_len,
- int icv_off, uint8_t *ivp)
+ uint8_t *icv, uint8_t *ivp)
{
int next = 0;
union {
@@ -963,8 +951,8 @@ octo_des_cbc_md5_decrypt(
(auth_off & 0x3) || (auth_off + auth_len > iovlen))) {
dprintf("%s: Bad parameters od=%p iov=%p iovlen=%jd "
"auth_off=%d auth_len=%d crypt_off=%d crypt_len=%d "
- "icv_off=%d ivp=%p\n", __func__, od, iov, iovlen,
- auth_off, auth_len, crypt_off, crypt_len, icv_off, ivp);
+ "icv=%p ivp=%p\n", __func__, od, iov, iovlen,
+ auth_off, auth_len, crypt_off, crypt_len, icv, ivp);
return -EINVAL;
}
@@ -1068,16 +1056,12 @@ octo_des_cbc_md5_decrypt(
CVMX_MT_HSH_STARTMD5(tmp1);
/* save the HMAC */
- IOV_INIT(iov, data32, data_i, data_l);
- while (icv_off > 0) {
- IOV_CONSUME(iov, data32, data_i, data_l);
- icv_off -= 4;
- }
+ data32 = (uint32_t *)icv;
CVMX_MF_HSH_IV(tmp1, 0);
*data32 = (uint32_t) (tmp1 >> 32);
- IOV_CONSUME(iov, data32, data_i, data_l);
+ data32++;
*data32 = (uint32_t) tmp1;
- IOV_CONSUME(iov, data32, data_i, data_l);
+ data32++;
CVMX_MF_HSH_IV(tmp1, 1);
*data32 = (uint32_t) (tmp1 >> 32);
@@ -1093,7 +1077,7 @@ octo_des_cbc_sha1_encrypt(
struct iovec *iov, size_t iovcnt, size_t iovlen,
int auth_off, int auth_len,
int crypt_off, int crypt_len,
- int icv_off, uint8_t *ivp)
+ uint8_t *icv, uint8_t *ivp)
{
int next = 0;
union {
@@ -1114,8 +1098,8 @@ octo_des_cbc_sha1_encrypt(
(auth_off & 0x3) || (auth_off + auth_len > iovlen))) {
dprintf("%s: Bad parameters od=%p iov=%p iovlen=%jd "
"auth_off=%d auth_len=%d crypt_off=%d crypt_len=%d "
- "icv_off=%d ivp=%p\n", __func__, od, iov, iovlen,
- auth_off, auth_len, crypt_off, crypt_len, icv_off, ivp);
+ "icv=%p ivp=%p\n", __func__, od, iov, iovlen,
+ auth_off, auth_len, crypt_off, crypt_len, icv, ivp);
return -EINVAL;
}
@@ -1222,16 +1206,12 @@ octo_des_cbc_sha1_encrypt(
CVMX_MT_HSH_STARTSHA((uint64_t) ((64 + 20) << 3));
/* save the HMAC */
- IOV_INIT(iov, data32, data_i, data_l);
- while (icv_off > 0) {
- IOV_CONSUME(iov, data32, data_i, data_l);
- icv_off -= 4;
- }
+ data32 = (uint32_t *)icv;
CVMX_MF_HSH_IV(tmp1, 0);
*data32 = (uint32_t) (tmp1 >> 32);
- IOV_CONSUME(iov, data32, data_i, data_l);
+ data32++;
*data32 = (uint32_t) tmp1;
- IOV_CONSUME(iov, data32, data_i, data_l);
+ data32++;
CVMX_MF_HSH_IV(tmp1, 1);
*data32 = (uint32_t) (tmp1 >> 32);
@@ -1244,7 +1224,7 @@ octo_des_cbc_sha1_decrypt(
struct iovec *iov, size_t iovcnt, size_t iovlen,
int auth_off, int auth_len,
int crypt_off, int crypt_len,
- int icv_off, uint8_t *ivp)
+ uint8_t *icv, uint8_t *ivp)
{
int next = 0;
union {
@@ -1265,8 +1245,8 @@ octo_des_cbc_sha1_decrypt(
(auth_off & 0x3) || (auth_off + auth_len > iovlen))) {
dprintf("%s: Bad parameters od=%p iov=%p iovlen=%jd "
"auth_off=%d auth_len=%d crypt_off=%d crypt_len=%d "
- "icv_off=%d ivp=%p\n", __func__, od, iov, iovlen,
- auth_off, auth_len, crypt_off, crypt_len, icv_off, ivp);
+ "icv=%p ivp=%p\n", __func__, od, iov, iovlen,
+ auth_off, auth_len, crypt_off, crypt_len, icv, ivp);
return -EINVAL;
}
@@ -1372,16 +1352,12 @@ octo_des_cbc_sha1_decrypt(
CVMX_MT_HSH_DATZ(6);
CVMX_MT_HSH_STARTSHA((uint64_t) ((64 + 20) << 3));
/* save the HMAC */
- IOV_INIT(iov, data32, data_i, data_l);
- while (icv_off > 0) {
- IOV_CONSUME(iov, data32, data_i, data_l);
- icv_off -= 4;
- }
+ data32 = (uint32_t *)icv;
CVMX_MF_HSH_IV(tmp1, 0);
*data32 = (uint32_t) (tmp1 >> 32);
- IOV_CONSUME(iov, data32, data_i, data_l);
+ data32++;
*data32 = (uint32_t) tmp1;
- IOV_CONSUME(iov, data32, data_i, data_l);
+ data32++;
CVMX_MF_HSH_IV(tmp1, 1);
*data32 = (uint32_t) (tmp1 >> 32);
@@ -1397,7 +1373,7 @@ octo_aes_cbc_md5_encrypt(
struct iovec *iov, size_t iovcnt, size_t iovlen,
int auth_off, int auth_len,
int crypt_off, int crypt_len,
- int icv_off, uint8_t *ivp)
+ uint8_t *icv, uint8_t *ivp)
{
int next = 0;
union {
@@ -1419,8 +1395,8 @@ octo_aes_cbc_md5_encrypt(
(auth_off & 0x3) || (auth_off + auth_len > iovlen))) {
dprintf("%s: Bad parameters od=%p iov=%p iovlen=%jd "
"auth_off=%d auth_len=%d crypt_off=%d crypt_len=%d "
- "icv_off=%d ivp=%p\n", __func__, od, iov, iovlen,
- auth_off, auth_len, crypt_off, crypt_len, icv_off, ivp);
+ "icv=%p ivp=%p\n", __func__, od, iov, iovlen,
+ auth_off, auth_len, crypt_off, crypt_len, icv, ivp);
return -EINVAL;
}
@@ -1552,16 +1528,12 @@ octo_aes_cbc_md5_encrypt(
CVMX_MT_HSH_STARTMD5(tmp1);
/* save the HMAC */
- IOV_INIT(iov, data32, data_i, data_l);
- while (icv_off > 0) {
- IOV_CONSUME(iov, data32, data_i, data_l);
- icv_off -= 4;
- }
+ data32 = (uint32_t *)icv;
CVMX_MF_HSH_IV(tmp1, 0);
*data32 = (uint32_t) (tmp1 >> 32);
- IOV_CONSUME(iov, data32, data_i, data_l);
+ data32++;
*data32 = (uint32_t) tmp1;
- IOV_CONSUME(iov, data32, data_i, data_l);
+ data32++;
CVMX_MF_HSH_IV(tmp1, 1);
*data32 = (uint32_t) (tmp1 >> 32);
@@ -1574,7 +1546,7 @@ octo_aes_cbc_md5_decrypt(
struct iovec *iov, size_t iovcnt, size_t iovlen,
int auth_off, int auth_len,
int crypt_off, int crypt_len,
- int icv_off, uint8_t *ivp)
+ uint8_t *icv, uint8_t *ivp)
{
int next = 0;
union {
@@ -1596,8 +1568,8 @@ octo_aes_cbc_md5_decrypt(
(auth_off & 0x3) || (auth_off + auth_len > iovlen))) {
dprintf("%s: Bad parameters od=%p iov=%p iovlen=%jd "
"auth_off=%d auth_len=%d crypt_off=%d crypt_len=%d "
- "icv_off=%d ivp=%p\n", __func__, od, iov, iovlen,
- auth_off, auth_len, crypt_off, crypt_len, icv_off, ivp);
+ "icv=%p ivp=%p\n", __func__, od, iov, iovlen,
+ auth_off, auth_len, crypt_off, crypt_len, icv, ivp);
return -EINVAL;
}
@@ -1725,16 +1697,12 @@ octo_aes_cbc_md5_decrypt(
CVMX_MT_HSH_STARTMD5(tmp1);
/* save the HMAC */
- IOV_INIT(iov, data32, data_i, data_l);
- while (icv_off > 0) {
- IOV_CONSUME(iov, data32, data_i, data_l);
- icv_off -= 4;
- }
+ data32 = (uint32_t *)icv;
CVMX_MF_HSH_IV(tmp1, 0);
*data32 = (uint32_t) (tmp1 >> 32);
- IOV_CONSUME(iov, data32, data_i, data_l);
+ data32++;
*data32 = (uint32_t) tmp1;
- IOV_CONSUME(iov, data32, data_i, data_l);
+ data32++;
CVMX_MF_HSH_IV(tmp1, 1);
*data32 = (uint32_t) (tmp1 >> 32);
@@ -1750,7 +1718,7 @@ octo_aes_cbc_sha1_encrypt(
struct iovec *iov, size_t iovcnt, size_t iovlen,
int auth_off, int auth_len,
int crypt_off, int crypt_len,
- int icv_off, uint8_t *ivp)
+ uint8_t *icv, uint8_t *ivp)
{
int next = 0;
union {
@@ -1772,8 +1740,8 @@ octo_aes_cbc_sha1_encrypt(
(auth_off & 0x3) || (auth_off + auth_len > iovlen))) {
dprintf("%s: Bad parameters od=%p iov=%p iovlen=%jd "
"auth_off=%d auth_len=%d crypt_off=%d crypt_len=%d "
- "icv_off=%d ivp=%p\n", __func__, od, iov, iovlen,
- auth_off, auth_len, crypt_off, crypt_len, icv_off, ivp);
+ "icv=%p ivp=%p\n", __func__, od, iov, iovlen,
+ auth_off, auth_len, crypt_off, crypt_len, icv, ivp);
return -EINVAL;
}
@@ -1924,16 +1892,12 @@ octo_aes_cbc_sha1_encrypt(
#endif
/* save the HMAC */
- IOV_INIT(iov, data32, data_i, data_l);
- while (icv_off > 0) {
- IOV_CONSUME(iov, data32, data_i, data_l);
- icv_off -= 4;
- }
+ data32 = (uint32_t *)icv;
CVMX_MF_HSH_IV(tmp1, 0);
*data32 = (uint32_t) (tmp1 >> 32);
- IOV_CONSUME(iov, data32, data_i, data_l);
+ data32++;
*data32 = (uint32_t) tmp1;
- IOV_CONSUME(iov, data32, data_i, data_l);
+ data32++;
CVMX_MF_HSH_IV(tmp1, 1);
*data32 = (uint32_t) (tmp1 >> 32);
@@ -1946,7 +1910,7 @@ octo_aes_cbc_sha1_decrypt(
struct iovec *iov, size_t iovcnt, size_t iovlen,
int auth_off, int auth_len,
int crypt_off, int crypt_len,
- int icv_off, uint8_t *ivp)
+ uint8_t *icv, uint8_t *ivp)
{
int next = 0;
union {
@@ -1968,8 +1932,8 @@ octo_aes_cbc_sha1_decrypt(
(auth_off & 0x3) || (auth_off + auth_len > iovlen))) {
dprintf("%s: Bad parameters od=%p iov=%p iovlen=%jd "
"auth_off=%d auth_len=%d crypt_off=%d crypt_len=%d "
- "icv_off=%d ivp=%p\n", __func__, od, iov, iovlen,
- auth_off, auth_len, crypt_off, crypt_len, icv_off, ivp);
+ "icv=%p ivp=%p\n", __func__, od, iov, iovlen,
+ auth_off, auth_len, crypt_off, crypt_len, icv, ivp);
return -EINVAL;
}
@@ -2119,16 +2083,12 @@ octo_aes_cbc_sha1_decrypt(
#endif
/* save the HMAC */
- IOV_INIT(iov, data32, data_i, data_l);
- while (icv_off > 0) {
- IOV_CONSUME(iov, data32, data_i, data_l);
- icv_off -= 4;
- }
+ data32 = (uint32_t *)icv;
CVMX_MF_HSH_IV(tmp1, 0);
*data32 = (uint32_t) (tmp1 >> 32);
- IOV_CONSUME(iov, data32, data_i, data_l);
+ data32++;
*data32 = (uint32_t) tmp1;
- IOV_CONSUME(iov, data32, data_i, data_l);
+ data32++;
CVMX_MF_HSH_IV(tmp1, 1);
*data32 = (uint32_t) (tmp1 >> 32);
diff --git a/sys/mips/cavium/cryptocteon/cryptocteon.c b/sys/mips/cavium/cryptocteon/cryptocteon.c
index d79394054a92..2e1535fd2308 100644
--- a/sys/mips/cavium/cryptocteon/cryptocteon.c
+++ b/sys/mips/cavium/cryptocteon/cryptocteon.c
@@ -59,7 +59,10 @@ static int cryptocteon_probe(device_t);
static int cryptocteon_attach(device_t);
static int cryptocteon_process(device_t, struct cryptop *, int);
-static int cryptocteon_newsession(device_t, crypto_session_t, struct cryptoini *);
+static int cryptocteon_probesession(device_t,
+ const struct crypto_session_params *);
+static int cryptocteon_newsession(device_t, crypto_session_t,
+ const struct crypto_session_params *);
static void
cryptocteon_identify(driver_t *drv, device_t parent)
@@ -89,168 +92,187 @@ cryptocteon_attach(device_t dev)
return (ENXIO);
}
- crypto_register(sc->sc_cid, CRYPTO_MD5_HMAC, 0, 0);
- crypto_register(sc->sc_cid, CRYPTO_SHA1_HMAC, 0, 0);
- crypto_register(sc->sc_cid, CRYPTO_DES_CBC, 0, 0);
- crypto_register(sc->sc_cid, CRYPTO_3DES_CBC, 0, 0);
- crypto_register(sc->sc_cid, CRYPTO_AES_CBC, 0, 0);
-
return (0);
}
-/*
- * Generate a new octo session. We artifically limit it to a single
- * hash/cipher or hash-cipher combo just to make it easier, most callers
- * do not expect more than this anyway.
- */
-static int
-cryptocteon_newsession(device_t dev, crypto_session_t cses,
- struct cryptoini *cri)
+static bool
+cryptocteon_auth_supported(const struct crypto_session_params *csp)
{
- struct cryptoini *c, *encini = NULL, *macini = NULL;
- struct cryptocteon_softc *sc;
- struct octo_sess *ocd;
- int i;
+ u_int hash_len;
- sc = device_get_softc(dev);
+ switch (csp->csp_auth_alg) {
+ case CRYPTO_MD5_HMAC:
+ hash_len = MD5_HASH_LEN;
+ break;
+ case CRYPTO_SHA1_HMAC:
+ hash_len = SHA1_HASH_LEN;
+ break;
+ default:
+ return (false);
+ }
- if (cri == NULL || sc == NULL)
- return (EINVAL);
+ if (csp->csp_auth_klen > hash_len)
+ return (false);
+ return (true);
+}
- /*
- * To keep it simple, we only handle hash, cipher or hash/cipher in a
- * session, you cannot currently do multiple ciphers/hashes in one
- * session even though it would be possibel to code this driver to
- * handle it.
- */
- for (i = 0, c = cri; c && i < 2; i++) {
- if (c->cri_alg == CRYPTO_MD5_HMAC ||
- c->cri_alg == CRYPTO_SHA1_HMAC ||
- c->cri_alg == CRYPTO_NULL_HMAC) {
- if (macini) {
- break;
- }
- macini = c;
- }
- if (c->cri_alg == CRYPTO_DES_CBC ||
- c->cri_alg == CRYPTO_3DES_CBC ||
- c->cri_alg == CRYPTO_AES_CBC ||
- c->cri_alg == CRYPTO_NULL_CBC) {
- if (encini) {
- break;
- }
- encini = c;
- }
- c = c->cri_next;
- }
- if (!macini && !encini) {
- dprintf("%s,%d - EINVAL bad cipher/hash or combination\n",
- __FILE__, __LINE__);
- return EINVAL;
- }
- if (c) {
- dprintf("%s,%d - EINVAL cannot handle chained cipher/hash combos\n",
- __FILE__, __LINE__);
- return EINVAL;
+static bool
+cryptocteon_cipher_supported(const struct crypto_session_params *csp)
+{
+
+ switch (csp->csp_cipher_alg) {
+ case CRYPTO_DES_CBC:
+ case CRYPTO_3DES_CBC:
+ if (csp->csp_ivlen != 8)
+ return (false);
+ if (csp->csp_cipher_klen != 8 &&
+ csp->csp_cipher_klen != 24)
+ return (false);
+ break;
+ case CRYPTO_AES_CBC:
+ if (csp->csp_ivlen != 16)
+ return (false);
+ if (csp->csp_cipher_klen != 16 &&
+ csp->csp_cipher_klen != 24 &&
+ csp->csp_cipher_klen != 32)
+ return (false);
+ break;
+ default:
+ return (false);
}
- /*
- * So we have something we can do, lets setup the session
- */
- ocd = crypto_get_driver_session(cses);
+ return (true);
+}
- if (encini && encini->cri_key) {
- ocd->octo_encklen = (encini->cri_klen + 7) / 8;
- memcpy(ocd->octo_enckey, encini->cri_key, ocd->octo_encklen);
- }
+static int
+cryptocteon_probesession(device_t dev, const struct crypto_session_params *csp)
+{
- if (macini && macini->cri_key) {
- ocd->octo_macklen = (macini->cri_klen + 7) / 8;
- memcpy(ocd->octo_mackey, macini->cri_key, ocd->octo_macklen);
+ if (csp->csp_flags != 0)
+ return (EINVAL);
+ switch (csp->csp_mode) {
+ case CSP_MODE_DIGEST:
+ if (!cryptocteon_auth_supported(csp))
+ return (EINVAL);
+ break;
+ case CSP_MODE_CIPHER:
+ if (!cryptocteon_cipher_supported(csp))
+ return (EINVAL);
+ break;
+ case CSP_MODE_ETA:
+ if (!cryptocteon_auth_supported(csp) ||
+ !cryptocteon_cipher_supported(csp))
+ return (EINVAL);
+ break;
+ default:
+ return (EINVAL);
}
+ return (CRYPTODEV_PROBE_ACCEL_SOFTWARE);
+}
- ocd->octo_mlen = 0;
- if (encini && encini->cri_mlen)
- ocd->octo_mlen = encini->cri_mlen;
- else if (macini && macini->cri_mlen)
- ocd->octo_mlen = macini->cri_mlen;
- else
- ocd->octo_mlen = 12;
+static void
+cryptocteon_calc_hash(const struct crypto_session_params *csp, const char *key,
+ struct octo_sess *ocd)
+{
+ char hash_key[SHA1_HASH_LEN];
- /*
- * point c at the enc if it exists, otherwise the mac
- */
- c = encini ? encini : macini;
+ memset(hash_key, 0, sizeof(hash_key));
+ memcpy(hash_key, key, csp->csp_auth_klen);
+ octo_calc_hash(csp->csp_auth_alg == CRYPTO_SHA1_HMAC, hash_key,
+ ocd->octo_hminner, ocd->octo_hmouter);
+}
- switch (c->cri_alg) {
- case CRYPTO_DES_CBC:
- case CRYPTO_3DES_CBC:
- ocd->octo_ivsize = 8;
- switch (macini ? macini->cri_alg : -1) {
+/* Generate a new octo session. */
+static int
+cryptocteon_newsession(device_t dev, crypto_session_t cses,
+ const struct crypto_session_params *csp)
+{
+ struct cryptocteon_softc *sc;
+ struct octo_sess *ocd;
+
+ sc = device_get_softc(dev);
+
+ ocd = crypto_get_driver_session(cses);
+
+ ocd->octo_encklen = csp->csp_cipher_klen;
+ if (csp->csp_cipher_key != NULL)
+ memcpy(ocd->octo_enckey, csp->csp_cipher_key,
+ ocd->octo_encklen);
+
+ if (csp->csp_auth_key != NULL)
+ cryptocteon_calc_hash(csp, csp->csp_auth_key, ocd);
+
+ ocd->octo_mlen = csp->csp_auth_mlen;
+ if (csp->csp_auth_mlen == 0) {
+ switch (csp->csp_auth_alg) {
case CRYPTO_MD5_HMAC:
- ocd->octo_encrypt = octo_des_cbc_md5_encrypt;
- ocd->octo_decrypt = octo_des_cbc_md5_decrypt;
- octo_calc_hash(0, macini->cri_key, ocd->octo_hminner,
- ocd->octo_hmouter);
+ ocd->octo_mlen = MD5_HASH_LEN;
break;
case CRYPTO_SHA1_HMAC:
- ocd->octo_encrypt = octo_des_cbc_sha1_encrypt;
- ocd->octo_decrypt = octo_des_cbc_sha1_encrypt;
- octo_calc_hash(1, macini->cri_key, ocd->octo_hminner,
- ocd->octo_hmouter);
- break;
- case -1:
- ocd->octo_encrypt = octo_des_cbc_encrypt;
- ocd->octo_decrypt = octo_des_cbc_decrypt;
+ ocd->octo_mlen = SHA1_HASH_LEN;
break;
- default:
- dprintf("%s,%d: EINVALn", __FILE__, __LINE__);
- return EINVAL;
}
- break;
- case CRYPTO_AES_CBC:
- ocd->octo_ivsize = 16;
- switch (macini ? macini->cri_alg : -1) {
+ }
+
+ switch (csp->csp_mode) {
+ case CSP_MODE_DIGEST:
+ switch (csp->csp_auth_alg) {
case CRYPTO_MD5_HMAC:
- ocd->octo_encrypt = octo_aes_cbc_md5_encrypt;
- ocd->octo_decrypt = octo_aes_cbc_md5_decrypt;
- octo_calc_hash(0, macini->cri_key, ocd->octo_hminner,
- ocd->octo_hmouter);
+ ocd->octo_encrypt = octo_null_md5_encrypt;
+ ocd->octo_decrypt = octo_null_md5_encrypt;
break;
case CRYPTO_SHA1_HMAC:
- ocd->octo_encrypt = octo_aes_cbc_sha1_encrypt;
- ocd->octo_decrypt = octo_aes_cbc_sha1_decrypt;
- octo_calc_hash(1, macini->cri_key, ocd->octo_hminner,
- ocd->octo_hmouter);
+ ocd->octo_encrypt = octo_null_sha1_encrypt;
+ ocd->octo_decrypt = octo_null_sha1_encrypt;
+ break;
+ }
+ break;
+ case CSP_MODE_CIPHER:
+ switch (csp->csp_cipher_alg) {
+ case CRYPTO_DES_CBC:
+ case CRYPTO_3DES_CBC:
+ ocd->octo_encrypt = octo_des_cbc_encrypt;
+ ocd->octo_decrypt = octo_des_cbc_decrypt;
break;
- case -1:
+ case CRYPTO_AES_CBC:
ocd->octo_encrypt = octo_aes_cbc_encrypt;
ocd->octo_decrypt = octo_aes_cbc_decrypt;
break;
- default:
- dprintf("%s,%d: EINVALn", __FILE__, __LINE__);
- return EINVAL;
}
break;
- case CRYPTO_MD5_HMAC:
- ocd->octo_encrypt = octo_null_md5_encrypt;
- ocd->octo_decrypt = octo_null_md5_encrypt;
- octo_calc_hash(0, macini->cri_key, ocd->octo_hminner,
- ocd->octo_hmouter);
- break;
- case CRYPTO_SHA1_HMAC:
- ocd->octo_encrypt = octo_null_sha1_encrypt;
- ocd->octo_decrypt = octo_null_sha1_encrypt;
- octo_calc_hash(1, macini->cri_key, ocd->octo_hminner,
- ocd->octo_hmouter);
+ case CSP_MODE_ETA:
+ switch (csp->csp_cipher_alg) {
+ case CRYPTO_DES_CBC:
+ case CRYPTO_3DES_CBC:
+ switch (csp->csp_auth_alg) {
+ case CRYPTO_MD5_HMAC:
+ ocd->octo_encrypt = octo_des_cbc_md5_encrypt;
+ ocd->octo_decrypt = octo_des_cbc_md5_decrypt;
+ break;
+ case CRYPTO_SHA1_HMAC:
+ ocd->octo_encrypt = octo_des_cbc_sha1_encrypt;
+ ocd->octo_decrypt = octo_des_cbc_sha1_encrypt;
+ break;
+ }
+ break;
+ case CRYPTO_AES_CBC:
+ switch (csp->csp_auth_alg) {
+ case CRYPTO_MD5_HMAC:
+ ocd->octo_encrypt = octo_aes_cbc_md5_encrypt;
+ ocd->octo_decrypt = octo_aes_cbc_md5_decrypt;
+ break;
+ case CRYPTO_SHA1_HMAC:
+ ocd->octo_encrypt = octo_aes_cbc_sha1_encrypt;
+ ocd->octo_decrypt = octo_aes_cbc_sha1_decrypt;
+ break;
+ }
+ break;
+ }
break;
- default:
- dprintf("%s,%d: EINVALn", __FILE__, __LINE__);
- return EINVAL;
}
- ocd->octo_encalg = encini ? encini->cri_alg : -1;
- ocd->octo_macalg = macini ? macini->cri_alg : -1;
+ KASSERT(ocd->octo_encrypt != NULL && ocd->octo_decrypt != NULL,
+ ("%s: missing function pointers", __func__));
return (0);
}
@@ -261,106 +283,107 @@ cryptocteon_newsession(device_t dev, crypto_session_t cses,
static int
cryptocteon_process(device_t dev, struct cryptop *crp, int hint)
{
- struct cryptodesc *crd;
+ const struct crypto_session_params *csp;
struct octo_sess *od;
size_t iovcnt, iovlen;
struct mbuf *m = NULL;
struct uio *uiop = NULL;
- struct cryptodesc *enccrd = NULL, *maccrd = NULL;
unsigned char *ivp = NULL;
- unsigned char iv_data[HASH_MAX_LEN];
- int auth_off = 0, auth_len = 0, crypt_off = 0, crypt_len = 0, icv_off = 0;
+ unsigned char iv_data[16];
+ unsigned char icv[SHA1_HASH_LEN], icv2[SHA1_HASH_LEN];
+ int auth_off, auth_len, crypt_off, crypt_len;
struct cryptocteon_softc *sc;
sc = device_get_softc(dev);
- if (sc == NULL || crp == NULL)
- return EINVAL;
-
crp->crp_etype = 0;
- if (crp->crp_desc == NULL || crp->crp_buf == NULL) {
- dprintf("%s,%d: EINVAL\n", __FILE__, __LINE__);
- crp->crp_etype = EINVAL;
+ od = crypto_get_driver_session(crp->crp_session);
+ csp = crypto_get_params(crp->crp_session);
+
+ /*
+ * The crypto routines assume that the regions to auth and
+ * cipher are exactly 8 byte multiples and aligned on 8
+ * byte logical boundaries within the iovecs.
+ */
+ if (crp->crp_aad_length % 8 != 0 || crp->crp_payload_length % 8 != 0) {
+ crp->crp_etype = EFBIG;
+ goto done;
+ }
+
+ /*
+ * As currently written, the crypto routines assume the AAD and
+ * payload are adjacent.
+ */
+ if (crp->crp_aad_length != 0 && crp->crp_payload_start !=
+ crp->crp_aad_start + crp->crp_aad_length) {
+ crp->crp_etype = EFBIG;
goto done;
}
- od = crypto_get_driver_session(crp->crp_session);
+ crypt_off = crp->crp_payload_start;
+ crypt_len = crp->crp_payload_length;
+ if (crp->crp_aad_length != 0) {
+ auth_off = crp->crp_aad_start;
+ auth_len = crp->crp_aad_length + crp->crp_payload_length;
+ } else {
+ auth_off = crypt_off;
+ auth_len = crypt_len;
+ }
/*
* do some error checking outside of the loop for m and IOV processing
* this leaves us with valid m or uiop pointers for later
*/
- if (crp->crp_flags & CRYPTO_F_IMBUF) {
+ switch (crp->crp_buf_type) {
+ case CRYPTO_BUF_MBUF:
+ {
unsigned frags;
- m = (struct mbuf *) crp->crp_buf;
+ m = crp->crp_mbuf;
for (frags = 0; m != NULL; frags++)
m = m->m_next;
if (frags >= UIO_MAXIOV) {
printf("%s,%d: %d frags > UIO_MAXIOV", __FILE__, __LINE__, frags);
+ crp->crp_etype = EFBIG;
goto done;
}
- m = (struct mbuf *) crp->crp_buf;
- } else if (crp->crp_flags & CRYPTO_F_IOV) {
- uiop = (struct uio *) crp->crp_buf;
+ m = crp->crp_mbuf;
+ break;
+ }
+ case CRYPTO_BUF_UIO:
+ uiop = crp->crp_uio;
if (uiop->uio_iovcnt > UIO_MAXIOV) {
printf("%s,%d: %d uio_iovcnt > UIO_MAXIOV", __FILE__, __LINE__,
uiop->uio_iovcnt);
+ crp->crp_etype = EFBIG;
goto done;
}
+ break;
}
- /* point our enccrd and maccrd appropriately */
- crd = crp->crp_desc;
- if (crd->crd_alg == od->octo_encalg)
- enccrd = crd;
- if (crd->crd_alg == od->octo_macalg)
- maccrd = crd;
- crd = crd->crd_next;
- if (crd) {
- if (crd->crd_alg == od->octo_encalg)
- enccrd = crd;
- if (crd->crd_alg == od->octo_macalg)
- maccrd = crd;
- crd = crd->crd_next;
- }
- if (crd) {
- crp->crp_etype = EINVAL;
- dprintf("%s,%d: ENOENT - descriptors do not match session\n",
- __FILE__, __LINE__);
- goto done;
- }
-
- if (enccrd) {
- if (enccrd->crd_flags & CRD_F_IV_EXPLICIT) {
- ivp = enccrd->crd_iv;
- } else {
+ if (csp->csp_cipher_alg != 0) {
+ if (crp->crp_flags & CRYPTO_F_IV_GENERATE) {
+ arc4rand(iv_data, csp->csp_ivlen, 0);
+ crypto_copyback(crp, crp->crp_iv_start, csp->csp_ivlen,
+ iv_data);
+ ivp = iv_data;
+ } else if (crp->crp_flags & CRYPTO_F_IV_SEPARATE)
+ ivp = crp->crp_iv;
+ else {
+ crypto_copydata(crp, crp->crp_iv_start, csp->csp_ivlen,
+ iv_data);
ivp = iv_data;
- crypto_copydata(crp->crp_flags, crp->crp_buf,
- enccrd->crd_inject, od->octo_ivsize, (caddr_t) ivp);
- }
-
- if (maccrd) {
- auth_off = maccrd->crd_skip;
- auth_len = maccrd->crd_len;
- icv_off = maccrd->crd_inject;
}
-
- crypt_off = enccrd->crd_skip;
- crypt_len = enccrd->crd_len;
- } else { /* if (maccrd) */
- auth_off = maccrd->crd_skip;
- auth_len = maccrd->crd_len;
- icv_off = maccrd->crd_inject;
}
/*
* setup the I/O vector to cover the buffer
*/
- if (crp->crp_flags & CRYPTO_F_IMBUF) {
+ switch (crp->crp_buf_type) {
+ case CRYPTO_BUF_MBUF:
iovcnt = 0;
iovlen = 0;
@@ -371,7 +394,8 @@ cryptocteon_process(device_t dev, struct cryptop *crp, int hint)
m = m->m_next;
iovlen += od->octo_iov[iovcnt++].iov_len;
}
- } else if (crp->crp_flags & CRYPTO_F_IOV) {
+ break;
+ case CRYPTO_BUF_UIO:
iovlen = 0;
for (iovcnt = 0; iovcnt < uiop->uio_iovcnt; iovcnt++) {
od->octo_iov[iovcnt].iov_base = uiop->uio_iov[iovcnt].iov_base;
@@ -379,44 +403,44 @@ cryptocteon_process(device_t dev, struct cryptop *crp, int hint)
iovlen += od->octo_iov[iovcnt].iov_len;
}
- } else {
+ break;
+ case CRYPTO_BUF_CONTIG:
iovlen = crp->crp_ilen;
od->octo_iov[0].iov_base = crp->crp_buf;
od->octo_iov[0].iov_len = crp->crp_ilen;
iovcnt = 1;
+ break;
+ default:
+ panic("can't happen");
}
/*
* setup a new explicit key
*/
- if (enccrd) {
- if (enccrd->crd_flags & CRD_F_KEY_EXPLICIT) {
- od->octo_encklen = (enccrd->crd_klen + 7) / 8;
- memcpy(od->octo_enckey, enccrd->crd_key, od->octo_encklen);
- }
- }
- if (maccrd) {
- if (maccrd->crd_flags & CRD_F_KEY_EXPLICIT) {
- od->octo_macklen = (maccrd->crd_klen + 7) / 8;
- memcpy(od->octo_mackey, maccrd->crd_key, od->octo_macklen);
- od->octo_mackey_set = 0;
- }
- if (!od->octo_mackey_set) {
- octo_calc_hash(maccrd->crd_alg == CRYPTO_MD5_HMAC ? 0 : 1,
- maccrd->crd_key, od->octo_hminner, od->octo_hmouter);
- od->octo_mackey_set = 1;
- }
- }
+ if (crp->crp_cipher_key != NULL)
+ memcpy(od->octo_enckey, crp->crp_cipher_key, od->octo_encklen);
+ if (crp->crp_auth_key != NULL)
+ cryptocteon_calc_hash(csp, crp->crp_auth_key, od);
- if (!enccrd || (enccrd->crd_flags & CRD_F_ENCRYPT))
+ if (CRYPTO_OP_IS_ENCRYPT(crp->crp_op))
(*od->octo_encrypt)(od, od->octo_iov, iovcnt, iovlen,
- auth_off, auth_len, crypt_off, crypt_len, icv_off, ivp);
+ auth_off, auth_len, crypt_off, crypt_len, icv, ivp);
else
(*od->octo_decrypt)(od, od->octo_iov, iovcnt, iovlen,
- auth_off, auth_len, crypt_off, crypt_len, icv_off, ivp);
-
+ auth_off, auth_len, crypt_off, crypt_len, icv, ivp);
+
+ if (csp->csp_auth_alg != 0) {
+ if (crp->crp_op & CRYPTO_OP_VERIFY_DIGEST) {
+ crypto_copydata(crp, crp->crp_digest_start,
+ od->octo_mlen, icv2);
+ if (timingsafe_bcmp(icv, icv2, od->octo_mlen) != 0)
+ crp->crp_etype = EBADMSG;
+ } else
+ crypto_copyback(crp, crp->crp_digest_start,
+ od->octo_mlen, icv);
+ }
done:
crypto_done(crp);
return (0);
@@ -429,6 +453,7 @@ static device_method_t cryptocteon_methods[] = {
DEVMETHOD(device_attach, cryptocteon_attach),
/* crypto device methods */
+ DEVMETHOD(cryptodev_probesession, cryptocteon_probesession),
DEVMETHOD(cryptodev_newsession, cryptocteon_newsession),
DEVMETHOD(cryptodev_process, cryptocteon_process),
diff --git a/sys/mips/cavium/cryptocteon/cryptocteonvar.h b/sys/mips/cavium/cryptocteon/cryptocteonvar.h
index e722298d899e..e7bc445deefb 100644
--- a/sys/mips/cavium/cryptocteon/cryptocteonvar.h
+++ b/sys/mips/cavium/cryptocteon/cryptocteonvar.h
@@ -34,23 +34,15 @@
struct octo_sess;
-typedef int octo_encrypt_t(struct octo_sess *od, struct iovec *iov, size_t iovcnt, size_t iovlen, int auth_off, int auth_len, int crypt_off, int crypt_len, int icv_off, uint8_t *ivp);
-typedef int octo_decrypt_t(struct octo_sess *od, struct iovec *iov, size_t iovcnt, size_t iovlen, int auth_off, int auth_len, int crypt_off, int crypt_len, int icv_off, uint8_t *ivp);
+typedef int octo_encrypt_t(struct octo_sess *od, struct iovec *iov, size_t iovcnt, size_t iovlen, int auth_off, int auth_len, int crypt_off, int crypt_len, uint8_t *icv, uint8_t *ivp);
+typedef int octo_decrypt_t(struct octo_sess *od, struct iovec *iov, size_t iovcnt, size_t iovlen, int auth_off, int auth_len, int crypt_off, int crypt_len, uint8_t *icv, uint8_t *ivp);
struct octo_sess {
- int octo_encalg;
#define MAX_CIPHER_KEYLEN 64
char octo_enckey[MAX_CIPHER_KEYLEN];
int octo_encklen;
- int octo_macalg;
- #define MAX_HASH_KEYLEN 64
- char octo_mackey[MAX_HASH_KEYLEN];
- int octo_macklen;
- int octo_mackey_set;
-
int octo_mlen;
- int octo_ivsize;
octo_encrypt_t *octo_encrypt;
octo_decrypt_t *octo_decrypt;