diff options
Diffstat (limited to 'usr/src/test/crypto-tests/tests')
5 files changed, 92 insertions, 31 deletions
diff --git a/usr/src/test/crypto-tests/tests/common/cryptotest.h b/usr/src/test/crypto-tests/tests/common/cryptotest.h index 3f091bc80c..e48ddced01 100644 --- a/usr/src/test/crypto-tests/tests/common/cryptotest.h +++ b/usr/src/test/crypto-tests/tests/common/cryptotest.h @@ -107,6 +107,15 @@ extern test_fg_t cryptotest_digest_fg; #define DECR_FG (&cryptotest_decr_fg) #define DIGEST_FG (&cryptotest_digest_fg) +/* + * KCF and PKCS11 use different structures for the CCM params (CK_AES_CCM_PARAMS + * and CK_CCM_PARAMS respectively. Each cryptotest_*.c file implements this + * for their respective structs. + */ +void ccm_init_params(void *, ulong_t, uchar_t *, ulong_t, uchar_t *, ulong_t, + ulong_t); +size_t ccm_param_len(void); + #ifdef __cplusplus } #endif diff --git a/usr/src/test/crypto-tests/tests/common/cryptotest_kcf.c b/usr/src/test/crypto-tests/tests/common/cryptotest_kcf.c index 525932206c..c4724613ea 100644 --- a/usr/src/test/crypto-tests/tests/common/cryptotest_kcf.c +++ b/usr/src/test/crypto-tests/tests/common/cryptotest_kcf.c @@ -439,3 +439,22 @@ digest_final(crypto_op_t *op) return (kcf_do_ioctl(CRYPTO_DIGEST_FINAL, (uint_t *)&final, "final")); } +void +ccm_init_params(void *buf, ulong_t ulDataLen, uchar_t *pNonce, + ulong_t ulNonceLen, uchar_t *pAAD, ulong_t ulAADLen, ulong_t ulMACLen) +{ + CK_AES_CCM_PARAMS *pp = buf; + + pp->ulDataSize = ulDataLen; + pp->nonce = pNonce; + pp->ulNonceSize = ulNonceLen; + pp->authData = pAAD; + pp->ulAuthDataSize = ulAADLen; + pp->ulMACSize = ulMACLen; +} + +size_t +ccm_param_len(void) +{ + return (sizeof (CK_AES_CCM_PARAMS)); +} diff --git a/usr/src/test/crypto-tests/tests/common/cryptotest_pkcs.c b/usr/src/test/crypto-tests/tests/common/cryptotest_pkcs.c index 6bedd08499..e28d00e759 100644 --- a/usr/src/test/crypto-tests/tests/common/cryptotest_pkcs.c +++ b/usr/src/test/crypto-tests/tests/common/cryptotest_pkcs.c @@ -452,3 +452,23 @@ digest_final(crypto_op_t *op) cryptotest_error("C_DigestFinal", rv); return (rv); } + +void +ccm_init_params(void *buf, ulong_t ulDataLen, uchar_t *pNonce, + ulong_t ulNonceLen, uchar_t *pAAD, ulong_t ulAADLen, ulong_t ulMACLen) +{ + CK_CCM_PARAMS *pp = buf; + + pp->ulDataLen = ulDataLen; + pp->pNonce = pNonce; + pp->ulNonceLen = ulNonceLen; + pp->pAAD = pAAD; + pp->ulAADLen = ulAADLen; + pp->ulMACLen = ulMACLen; +} + +size_t +ccm_param_len(void) +{ + return (sizeof (CK_CCM_PARAMS)); +} diff --git a/usr/src/test/crypto-tests/tests/modes/aes/Makefile.subdirs b/usr/src/test/crypto-tests/tests/modes/aes/Makefile.subdirs index fd431db1f5..4678b6c7f8 100644 --- a/usr/src/test/crypto-tests/tests/modes/aes/Makefile.subdirs +++ b/usr/src/test/crypto-tests/tests/modes/aes/Makefile.subdirs @@ -54,7 +54,8 @@ $(CMDS) := FILEMODE = 0555 LINTFLAGS += -xerroff=E_NAME_USED_NOT_DEF2 LINTFLAGS += -xerroff=E_NAME_DEF_NOT_USED2 -CPPFLAGS += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I$(COMMONDIR) -I$(SRC)/common/crypto/ +CPPFLAGS += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 +CPPFLAGS += -I$(COMMONDIR) -I$(SRC)/common/crypto/ all: $(PROGS) diff --git a/usr/src/test/crypto-tests/tests/modes/aes/ccm/aes_ccm.c b/usr/src/test/crypto-tests/tests/modes/aes/ccm/aes_ccm.c index a01129547e..91802aefdd 100644 --- a/usr/src/test/crypto-tests/tests/modes/aes/ccm/aes_ccm.c +++ b/usr/src/test/crypto-tests/tests/modes/aes/ccm/aes_ccm.c @@ -11,43 +11,49 @@ /* * Copyright 2015 Nexenta Systems, Inc. All rights reserved. + * Copyright 2018, Joyent, Inc. */ #include <strings.h> #include <stdio.h> - +#include <sys/debug.h> #include "cryptotest.h" #include "aes_ccm.h" +/* + * Size of param (in 8-byte chunks for alignment) large enough for both + * CK_CCM_PARAMS and CK_AES_CCM_PARAMS. + */ +#define PARAM_SIZE_64 8 + int main(void) { int errs = 0; int i; uint8_t N[1024]; - CK_AES_CCM_PARAMS param; - cryptotest_t args; + uint64_t param[PARAM_SIZE_64]; - bzero(¶m, sizeof (param)); + cryptotest_t args; args.out = N; - args.param = ¶m; args.outlen = sizeof (N); - args.plen = sizeof (param); args.mechname = SUN_CKM_AES_CCM; args.updatelen = 1; - param.authData = CCM_DATA1; args.key = CCM_KEY1; args.keylen = sizeof (CCM_KEY1); for (i = 0; i < 12; i++) { - param.ulMACSize = MACLEN[i]; - param.ulNonceSize = NONCELEN[i]; - param.ulAuthDataSize = AUTHLEN[i]; - param.ulDataSize = DATALEN[i] - AUTHLEN[i]; - param.nonce = NONCE[i]; + bzero(param, sizeof (param)); + ccm_init_params(param, DATALEN[i] - AUTHLEN[i], NONCE[i], + NONCELEN[i], CCM_DATA1, AUTHLEN[i], MACLEN[i]); + + args.param = param; + args.plen = ccm_param_len(); + + VERIFY3U(args.plen, <=, sizeof (param)); args.in = CCM_DATA1 + AUTHLEN[i]; args.inlen = DATALEN[i] - AUTHLEN[i]; @@ -60,12 +66,14 @@ main(void) args.key = CCM_KEY2; args.keylen = sizeof (CCM_KEY2); for (i = 12; i < 24; i++) { - param.ulMACSize = MACLEN[i]; - param.ulNonceSize = NONCELEN[i]; - param.ulAuthDataSize = AUTHLEN[i]; - param.ulDataSize = DATALEN[i] - AUTHLEN[i]; - param.nonce = NONCE[i]; - param.authData = DATA_2[i-12]; + bzero(param, sizeof (param)); + ccm_init_params(param, DATALEN[i] - AUTHLEN[i], NONCE[i], + NONCELEN[i], DATA_2[i-12], AUTHLEN[i], MACLEN[i]); + + args.param = param; + args.plen = ccm_param_len(); + + VERIFY3U(args.plen, <=, sizeof (param)); args.in = DATA_2[i-12] + AUTHLEN[i]; args.inlen = DATALEN[i] - AUTHLEN[i]; @@ -77,15 +85,17 @@ main(void) (void) fprintf(stderr, "\t\t\t=== decrypt ===\n----------\n\n"); - param.authData = CCM_DATA1; args.key = CCM_KEY1; args.keylen = sizeof (CCM_KEY1); for (i = 0; i < 12; i++) { - param.ulMACSize = MACLEN[i]; - param.ulNonceSize = NONCELEN[i]; - param.ulAuthDataSize = AUTHLEN[i]; - param.ulDataSize = RESLEN[i] - AUTHLEN[i]; - param.nonce = NONCE[i]; + bzero(param, sizeof (param)); + ccm_init_params(param, RESLEN[i] - AUTHLEN[i], NONCE[i], + NONCELEN[i], CCM_DATA1, AUTHLEN[i], MACLEN[i]); + + args.param = param; + args.plen = ccm_param_len(); + + VERIFY3U(args.plen, <=, sizeof (param)); args.in = RES[i] + AUTHLEN[i]; args.inlen = RESLEN[i] - AUTHLEN[i]; @@ -98,12 +108,14 @@ main(void) args.key = CCM_KEY2; args.keylen = sizeof (CCM_KEY2); for (i = 12; i < 24; i++) { - param.ulMACSize = MACLEN[i]; - param.ulNonceSize = NONCELEN[i]; - param.ulAuthDataSize = AUTHLEN[i]; - param.ulDataSize = RESLEN[i] - AUTHLEN[i]; - param.nonce = NONCE[i]; - param.authData = DATA_2[i-12]; + bzero(param, sizeof (param)); + ccm_init_params(param, RESLEN[i] - AUTHLEN[i], NONCE[i], + NONCELEN[i], DATA_2[i-12], AUTHLEN[i], MACLEN[i]); + + args.param = param; + args.plen = ccm_param_len(); + + VERIFY3U(args.plen, <=, sizeof (param)); args.in = RES[i] + AUTHLEN[i]; args.inlen = RESLEN[i] - AUTHLEN[i]; |
