summaryrefslogtreecommitdiffstats
path: root/sys/opencrypto/cryptodev.c
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2006-05-17 18:24:17 +0000
committerpjd <pjd@FreeBSD.org>2006-05-17 18:24:17 +0000
commit4de9eb667b4c239151ad89537db3d68fbf193b2e (patch)
tree6848cf0a4407cc1594ae81c7a40694ee8056d6bd /sys/opencrypto/cryptodev.c
parenteaddfa446c9ad87aa799d5eb2a97f30296c3a243 (diff)
downloadFreeBSD-src-4de9eb667b4c239151ad89537db3d68fbf193b2e.zip
FreeBSD-src-4de9eb667b4c239151ad89537db3d68fbf193b2e.tar.gz
- Fix a very old bug in HMAC/SHA{384,512}. When HMAC is using SHA384
or SHA512, the blocksize is 128 bytes, not 64 bytes as anywhere else. The bug also exists in NetBSD, OpenBSD and various other independed implementations I look at. - We cannot decide which hash function to use for HMAC based on the key length, because any HMAC function can use any key length. To fix it split CRYPTO_SHA2_HMAC into three algorithm: CRYPTO_SHA2_256_HMAC, CRYPTO_SHA2_384_HMAC and CRYPTO_SHA2_512_HMAC. Those names are consistent with OpenBSD's naming. - Remove authsize field from auth_hash structure. - Allow consumer to define size of hash he wants to receive. This allows to use HMAC not only for IPsec, where 96 bits MAC is requested. The size of requested MAC is defined at newsession time in the cri_mlen field - when 0, entire MAC will be returned. - Add swcr_authprepare() function which prepares authentication key. - Allow to provide key for every authentication operation, not only at newsession time by honoring CRD_F_KEY_EXPLICIT flag. - Make giving key at newsession time optional - don't try to operate on it if its NULL. - Extend COPYBACK()/COPYDATA() macros to handle CRYPTO_BUF_CONTIG buffer type as well. - Accept CRYPTO_BUF_IOV buffer type in swcr_authcompute() as we have cuio_apply() now. - 16 bits for key length (SW_klen) is more than enough. Reviewed by: sam
Diffstat (limited to 'sys/opencrypto/cryptodev.c')
-rw-r--r--sys/opencrypto/cryptodev.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/sys/opencrypto/cryptodev.c b/sys/opencrypto/cryptodev.c
index 9c3490f..9c9ec29 100644
--- a/sys/opencrypto/cryptodev.c
+++ b/sys/opencrypto/cryptodev.c
@@ -190,25 +190,22 @@ cryptof_ioctl(
case 0:
break;
case CRYPTO_MD5_HMAC:
- thash = &auth_hash_hmac_md5_96;
+ thash = &auth_hash_hmac_md5;
break;
case CRYPTO_SHA1_HMAC:
- thash = &auth_hash_hmac_sha1_96;
+ thash = &auth_hash_hmac_sha1;
break;
- case CRYPTO_SHA2_HMAC:
- if (sop->mackeylen == auth_hash_hmac_sha2_256.keysize)
- thash = &auth_hash_hmac_sha2_256;
- else if (sop->mackeylen == auth_hash_hmac_sha2_384.keysize)
- thash = &auth_hash_hmac_sha2_384;
- else if (sop->mackeylen == auth_hash_hmac_sha2_512.keysize)
- thash = &auth_hash_hmac_sha2_512;
- else {
- mtx_unlock(&Giant);
- return (EINVAL);
- }
+ case CRYPTO_SHA2_256_HMAC:
+ thash = &auth_hash_hmac_sha2_256;
+ break;
+ case CRYPTO_SHA2_384_HMAC:
+ thash = &auth_hash_hmac_sha2_384;
+ break;
+ case CRYPTO_SHA2_512_HMAC:
+ thash = &auth_hash_hmac_sha2_512;
break;
case CRYPTO_RIPEMD160_HMAC:
- thash = &auth_hash_hmac_ripemd_160_96;
+ thash = &auth_hash_hmac_ripemd_160;
break;
#ifdef notdef
case CRYPTO_MD5:
@@ -471,7 +468,7 @@ cryptodev_op(
goto bail;
if (cop->mac &&
- (error = copyout(crp->crp_mac, cop->mac, cse->thash->authsize)))
+ (error = copyout(crp->crp_mac, cop->mac, cse->thash->hashsize)))
goto bail;
bail:
OpenPOWER on IntegriCloud