diff options
author | Jason King <jason.king@joyent.com> | 2019-07-10 04:55:35 +0000 |
---|---|---|
committer | Gordon Ross <gwr@nexenta.com> | 2019-11-04 08:18:58 -0500 |
commit | faeaba889049371f163f3deb6efd690dbc986e3d (patch) | |
tree | f397ab67b93042136aa895031e431585b65659d5 | |
parent | c00e8e9ee0eb7384f171971ad938063426b731f7 (diff) | |
download | illumos-joyent-faeaba889049371f163f3deb6efd690dbc986e3d.tar.gz |
11823 Add HMAC_SHA1 crypto tests
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Mike Gerdts <mike.gerdts@joyent.com>
Reviewed by: John Levon <john.levon@joyent.com>
Reviewed by: Ryan Zezeski <rpz@joyent.com>
Approved by: Gordon Ross <gwr@nexenta.com>
18 files changed, 510 insertions, 221 deletions
diff --git a/usr/src/pkg/manifests/system-test-cryptotest.mf b/usr/src/pkg/manifests/system-test-cryptotest.mf index 0d2fea276f..723180d417 100644 --- a/usr/src/pkg/manifests/system-test-cryptotest.mf +++ b/usr/src/pkg/manifests/system-test-cryptotest.mf @@ -32,6 +32,9 @@ dir path=opt/crypto-tests/tests/aes/pkcs group=root mode=0755 owner=root dir path=opt/crypto-tests/tests/digest dir path=opt/crypto-tests/tests/digest/kcf dir path=opt/crypto-tests/tests/digest/pkcs +dir path=opt/crypto-tests/tests/hmac +dir path=opt/crypto-tests/tests/hmac/kcf +dir path=opt/crypto-tests/tests/hmac/pkcs file path=opt/crypto-tests/README mode=0444 file path=opt/crypto-tests/bin/cryptotest mode=0555 file path=opt/crypto-tests/runfiles/default.run mode=0444 @@ -202,6 +205,12 @@ file opt/crypto-tests/tests/digest/pkcs/sha512_32 \ file opt/crypto-tests/tests/digest/pkcs/sha512_64 \ path=opt/crypto-tests/tests/digest/pkcs/sha512_64 group=root mode=0555 \ owner=root +file path=opt/crypto-tests/tests/hmac/kcf/cleanup mode=0555 +file path=opt/crypto-tests/tests/hmac/kcf/hmac_sha1_32 mode=0555 +file path=opt/crypto-tests/tests/hmac/kcf/hmac_sha1_64 mode=0555 +file path=opt/crypto-tests/tests/hmac/kcf/setup mode=0555 +file path=opt/crypto-tests/tests/hmac/pkcs/hmac_sha1_32 mode=0555 +file path=opt/crypto-tests/tests/hmac/pkcs/hmac_sha1_64 mode=0555 license cr_Sun license=cr_Sun license lic_CDDL license=lic_CDDL depend fmri=driver/crypto/dprov type=require diff --git a/usr/src/test/crypto-tests/cmd/kcf/Makefile b/usr/src/test/crypto-tests/cmd/kcf/Makefile index 3964744d24..8681cbd647 100644 --- a/usr/src/test/crypto-tests/cmd/kcf/Makefile +++ b/usr/src/test/crypto-tests/cmd/kcf/Makefile @@ -12,7 +12,7 @@ # # Copyright (c) 2012 by Delphix. All rights reserved. # Copyright 2015 Nexenta Systems, Inc. All rights reserved. -# Copyright (c) 2018, Joyent, Inc. +# Copyright 2019 Joyent, Inc. # include $(SRC)/Makefile.master @@ -21,11 +21,17 @@ include $(SRC)/test/Makefile.com ROOTOPTPKG = $(ROOT)/opt/crypto-tests ROOTAES = $(ROOTOPTPKG)/tests/aes/kcf ROOTDIGEST = $(ROOTOPTPKG)/tests/digest/kcf -ROOTDIRS = $(ROOTAES) $(ROOTDIGEST) +ROOTHMAC = $(ROOTOPTPKG)/tests/hmac/kcf + +ROOTDIRS = $(ROOTAES) $(ROOTDIGEST) $(ROOTHMAC) PROGS = cleanup setup -CMDS = $(PROGS:%=$(ROOTAES)/%) $(PROGS:%=$(ROOTDIGEST)/%) +CMDS = \ + $(PROGS:%=$(ROOTAES)/%) \ + $(PROGS:%=$(ROOTDIGEST)/%) \ + $(PROGS:%=$(ROOTHMAC)/%) + $(CMDS) := FILEMODE = 0555 all lint clean clobber: @@ -41,3 +47,5 @@ $(ROOTAES)/%: %.ksh $(INS.rename) $(ROOTDIGEST)/%: %.ksh $(INS.rename) +$(ROOTHMAC)/%: %.ksh + $(INS.rename) diff --git a/usr/src/test/crypto-tests/runfiles/default.run b/usr/src/test/crypto-tests/runfiles/default.run index e44c9d647a..7a8f913e43 100644 --- a/usr/src/test/crypto-tests/runfiles/default.run +++ b/usr/src/test/crypto-tests/runfiles/default.run @@ -12,7 +12,7 @@ # # Copyright (c) 2012 by Delphix. All rights reserved. # Copyright 2015 Nexenta Systems, Inc. All rights reserved. -# Copyright 2019, Joyent, Inc. +# Copyright 2019 Joyent, Inc. # [DEFAULT] @@ -52,3 +52,12 @@ tests = ['sha1_32', 'sha256_32', 'sha384_32', 'sha512_32', 'sha512_224_32', 'sha1_64', 'sha256_64', 'sha384_64', 'sha512_64', 'sha512_224_64', 'sha512_256_64', 'md5_64' ] post = cleanup + +[/opt/crypto-tests/tests/hmac/pkcs] +tests = ['hmac_sha1_32', 'hmac_sha1_64'] + +[/opt/crypto-tests/tests/hmac/kcf] +pre = setup +user = root +tests = ['hmac_sha1_32', 'hmac_sha1_64'] +post = cleanup diff --git a/usr/src/test/crypto-tests/tests/Makefile b/usr/src/test/crypto-tests/tests/Makefile index 4b2dd162d2..0c35c9f7cf 100644 --- a/usr/src/test/crypto-tests/tests/Makefile +++ b/usr/src/test/crypto-tests/tests/Makefile @@ -11,12 +11,15 @@ # # Copyright 2015 Nexenta Systems, Inc. All rights reserved. -# Copyright 2018, Joyent, Inc. +# Copyright 2019 Joyent, Inc. # -SUBDIRS = modes common digest +SUBDIRS = modes common digest hmac + +all: $(SUBDIRS) modes: common digest: common +hmac: common include $(SRC)/test/Makefile.com diff --git a/usr/src/test/crypto-tests/tests/Makefile.crypto b/usr/src/test/crypto-tests/tests/Makefile.crypto new file mode 100644 index 0000000000..8d7396fa64 --- /dev/null +++ b/usr/src/test/crypto-tests/tests/Makefile.crypto @@ -0,0 +1,112 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright (c) 2012 by Delphix. All rights reserved. +# Copyright 2015 Nexenta Systems, Inc. All rights reserved. +# Copyright 2019 Joyent, Inc. +# + +include $(SRC)/cmd/Makefile.cmd +include $(SRC)/test/Makefile.com +include $(SRC)/cmd/Makefile.ctf + +PROGS_32 = $(CRYPTO:%=$(BASEPROG)_32_%) +PROGS_64 = $(CRYPTO:%=$(BASEPROG)_64_%) +PROGS = $(PROGS_32) $(PROGS_64) + +COMMON_OBJS_32 = $(COMMON_OBJS:%.o=%.32.o) +COMMON_OBJS_64 = $(COMMON_OBJS:%.o=%.64.o) + +# Some tests may only be relevant for PKCS#11 or KCF. One can use +# a statement like 'CRYPTO_kcf = $(POUND_SIGN)' in a test's Makefile to +# disable creation of tests for a given framework. For an example, see +# modes/aes/cbc_pad/Makefile +$(CRYPTO_pkcs)PROGS_pkcs = $(BASEPROG:%=%_32_pkcs) $(BASEPROG:%=%_64_pkcs) +$(CRYPTO_kcf)PROGS_kcf = $(BASEPROG:%=%_32_kcf) $(BASEPROG:%=%_64_kcf) + +# $(TESTROOT) must be set by whatever includes this file +$(CRYPTO_pkcs)TESTDIR_pkcs = $(TESTROOT)/pkcs +$(CRYPTO_kcf)TESTDIR_kcf = $(TESTROOT)/kcf + +COMMONDIR = $(SRC)/test/crypto-tests/tests/common +$(PROGS_32) := OBJS += $(BASEPROG:%=%.32.o) $(COMMON_OBJS_32) +$(PROGS_64) := OBJS += $(BASEPROG:%=%.64.o) $(COMMON_OBJS_64) +$(PROGS_32) := OBJS += $(COMMONDIR)/testfuncs.32.o +$(PROGS_64) := OBJS += $(COMMONDIR)/testfuncs.64.o +$(CRYPTO_pkcs)$(BASEPROG)_32_pkcs := OBJS += $(COMMONDIR)/cryptotest_pkcs.32.o +$(CRYPTO_pkcs)$(BASEPROG)_64_pkcs := OBJS += $(COMMONDIR)/cryptotest_pkcs.64.o +$(CRYPTO_kcf)$(BASEPROG)_32_kcf := OBJS += $(COMMONDIR)/cryptotest_kcf.32.o +$(CRYPTO_kcf)$(BASEPROG)_64_kcf := OBJS += $(COMMONDIR)/cryptotest_kcf.64.o + +$(CRYPTO_pkcs)$(PROGS_pkcs) := LDLIBS += -lpkcs11 -lcryptoutil + +CSTD = $(CSTD_GNU99) + +$(CRYPTO_pkcs)CMDS_pkcs = $(PROGS_pkcs:%_pkcs=$(TESTDIR_pkcs)/%) +$(CRYPTO_kcf)CMDS_kcf = $(PROGS_kcf:%_kcf=$(TESTDIR_kcf)/%) +CMDS = $(CMDS_pkcs) $(CMDS_kcf) + +$(CMDS) := FILEMODE = 0555 + +CPPFLAGS += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 +CPPFLAGS += -I$(COMMONDIR) -I$(SRC)/common/crypto/ + +all: $(PROGS) + +%_32_pkcs: %.32.o $(COMMON_OBJS_32) + $(LINK.c) $(OBJS) -o $@ $(LDLIBS) + $(POST_PROCESS) + +%_64_pkcs: %.64.o $(COMMON_OBJS_64) + $(LINK64.c) $(OBJS) -o $@ $(LDLIBS) + $(POST_PROCESS) + +%_32_kcf: %.32.o $(COMMON_OBJS_32) + $(LINK.c) $(OBJS) -o $@ $(LDLIBS) + $(POST_PROCESS) + +%_64_kcf: %.64.o $(COMMON_OBJS_64) + $(LINK64.c) $(OBJS) -o $@ $(LDLIBS) + $(POST_PROCESS) + +%.32.o: %.c + $(COMPILE.c) -o $@ $< + $(POST_PROCESS_O) + +%.64.o: %.c + $(COMPILE64.c) -o $@ $< + $(POST_PROCESS_O) + +install: all $(CMDS) + +clobber: clean + -$(RM) $(PROGS) + +clean: + -$(RM) *.o $(COMMON_OBJS_32) $(COMMON_OBJS_64) + +$(CMDS): $(TESTDIR_pkcs) $(TESTDIR_kcf) $(PROGS) + +$(TESTDIR_pkcs) $(TESTDIR_kcf): + $(INS.dir) + +$(TESTDIR_pkcs)/%_32: %_32_pkcs + $(INS.rename) + +$(TESTDIR_pkcs)/%_64: %_64_pkcs + $(INS.rename) + +$(TESTDIR_kcf)/%_32: %_32_kcf + $(INS.rename) + +$(TESTDIR_kcf)/%_64: %_64_kcf + $(INS.rename) diff --git a/usr/src/test/crypto-tests/tests/digest/Makefile b/usr/src/test/crypto-tests/tests/digest/Makefile index f4e1acc80b..a5732aa375 100644 --- a/usr/src/test/crypto-tests/tests/digest/Makefile +++ b/usr/src/test/crypto-tests/tests/digest/Makefile @@ -10,132 +10,21 @@ # # -# Copyright 2018, Joyent, Inc. +# Copyright 2019 Joyent, Inc. # -include $(SRC)/cmd/Makefile.cmd -include $(SRC)/test/Makefile.com -include $(SRC)/cmd/Makefile.ctf +ALGS = sha1 sha256 sha384 sha512 sha512_224 sha512_256 md5 -ALGS = sha1 sha256 sha384 sha512 sha512_224 sha512_256 md5 -CRYPTO = pkcs kcf +all := TARGET = all +install := TARGET = install +clean := TARGET = clean +clobber := TARGET = clobber -PROGS_pkcs_32 = $(ALGS:%=%_32_pkcs) -PROGS_pkcs_64 = $(ALGS:%=%_64_pkcs) -PROGS_kcf_32 = $(ALGS:%=%_32_kcf) -PROGS_kcf_64 = $(ALGS:%=%_64_kcf) -PROGS_pkcs = $(PROGS_pkcs_32) $(PROGS_pkcs_64) -PROGS_kcf = $(PROGS_kcf_32) $(PROGS_kcf_64) -PROGS_32 = $(PROGS_pkcs_32) $(PROGS_kcf_32) -PROGS_64 = $(PROGS_pkcs_64) $(PROGS_kcf_64) -PROGS = $(PROGS_32) $(PROGS_64) +.KEEP_STATE: -ROOTOPTPKG = $(ROOT)/opt/crypto-tests -TESTROOT = $(ROOTOPTPKG)/tests/digest -TESTDIR_pkcs = $(TESTROOT)/pkcs -TESTDIR_kcf = $(TESTROOT)/kcf +all clean clobber install: $(ALGS) -COMMONDIR = ../common +$(ALGS): FRC + $(MAKE) -e -f Makefile.digest BASEPROG=$@ $(TARGET) -$(CRYPTO:%=sha1_32_%) := OBJS = sha1.32.o -$(CRYPTO:%=sha256_32_%) := OBJS = sha256.32.o -$(CRYPTO:%=sha384_32_%) := OBJS = sha384.32.o -$(CRYPTO:%=sha512_32_%) := OBJS = sha512.32.o -$(CRYPTO:%=sha512_224_32_%) := OBJS = sha512_224.32.o -$(CRYPTO:%=sha512_256_32_%) := OBJS = sha512_256.32.o -$(CRYPTO:%=md5_32_%) := OBJS = md5.32.o - -$(CRYPTO:%=sha1_64_%) := OBJS = sha1.64.o -$(CRYPTO:%=sha256_64_%) := OBJS = sha256.64.o -$(CRYPTO:%=sha384_64_%) := OBJS = sha384.64.o -$(CRYPTO:%=sha512_64_%) := OBJS = sha512.64.o -$(CRYPTO:%=sha512_224_64_%) := OBJS = sha512_224.64.o -$(CRYPTO:%=sha512_256_64_%) := OBJS = sha512_256.64.o -$(CRYPTO:%=md5_64_%) := OBJS = md5.64.o - -$(PROGS_32) := OBJS_COMMON = main.32.o $(COMMONDIR)/testfuncs.32.o -$(PROGS_64) := OBJS_COMMON = main.64.o $(COMMONDIR)/testfuncs.64.o -$(PROGS_pkcs_32) := OBJS_COMMON += $(COMMONDIR)/cryptotest_pkcs.32.o -$(PROGS_pkcs_64) := OBJS_COMMON += $(COMMONDIR)/cryptotest_pkcs.64.o -$(PROGS_kcf_32) := OBJS_COMMON += $(COMMONDIR)/cryptotest_kcf.32.o -$(PROGS_kcf_64) := OBJS_COMMON += $(COMMONDIR)/cryptotest_kcf.64.o - -CSTD = $(CSTD_GNU99) - -CPPFLAGS += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -CPPFLAGS += -I$(COMMONDIR) -I$(SRC)/common/crypto - -LINTFLAGS += -xerroff=E_NAME_USED_NOT_DEF2 -LINTFLAGS += -xerroff=E_NAME_DEF_NOT_USED2 - -$(PROGS_pkcs) := LDLIBS += -lpkcs11 -lcryptoutil - -CMDS_pkcs = $(PROGS_pkcs:%_pkcs=$(TESTDIR_pkcs)/%) -CMDS_kcf = $(PROGS_kcf:%_kcf=$(TESTDIR_kcf)/%) -CMDS = $(CMDS_pkcs) $(CMDS_kcf) - -$(CMDS) := FILEMODE = 0555 - -all: $(PROGS) - -$(PROGS): main.32.o main.64.o - -%_32_pkcs: %.32.o - $(LINK.c) -o $@ $(OBJS) $(OBJS_COMMON) $(LDLIBS) - $(POST_PROCESS) - -%_64_pkcs: %.64.o - $(LINK64.c) -o $@ $(OBJS) $(OBJS_COMMON) $(LDLIBS) - $(POST_PROCESS) - -%_32_kcf: %.32.o - $(LINK.c) -o $@ $(OBJS) $(OBJS_COMMON) $(LDLIBS) - $(POST_PROCESS) - -%_64_kcf: %.64.o - $(LINK64.c) -o $@ $(OBJS) $(OBJS_COMMON) $(LDLIBS) - $(POST_PROCESS) - -%.32.o: %.c - $(COMPILE.c) -o $@ $< - $(POST_PROCESS_O) - -%.64.o: %.c - $(COMPILE64.c) -o $@ $< - $(POST_PROCESS_O) - - -install: all $(CMDS) - -lint: $(CRYPTO:%=lint_%) -lint_pkcs: $(ALGS:%=lint_pkcs_%) -lint_kcf: $(ALGS_kcf:%=lint_kcf_%) - -lint_pkcs_%: - $(LINT.c) main.c $(@:lint_pkcs_%=%.c) $(OBJS_COMMON:%.o=%.c) $(LDLIBS) - -lint_pcf_%: - $(LINT.c) main.c $(@:lint_kcf_%=%.c) $(OBJS_COMMON:%.o=%.c) $(LDLIBS) - -clobber: clean - -$(RM) $(PROGS) - -clean: - -$(RM) $(ALGS:%=%.32.o) $(ALGS:%=%.64.o) main.32.o main.64.o - -$(CMDS): $(TESTDIR_pkcs) $(TESTDIR_kcf) $(PROGS) - -$(TESTDIR_pkcs) $(TESTDIR_kcf): - $(INS.dir) - -$(TESTDIR_pkcs)/%_32: %_32_pkcs - $(INS.rename) - -$(TESTDIR_pkcs)/%_64: %_64_pkcs - $(INS.rename) - -$(TESTDIR_kcf)/%_32: %_32_kcf - $(INS.rename) - -$(TESTDIR_kcf)/%_64: %_64_kcf - $(INS.rename) +FRC: diff --git a/usr/src/test/crypto-tests/tests/digest/Makefile.digest b/usr/src/test/crypto-tests/tests/digest/Makefile.digest new file mode 100644 index 0000000000..1507ebc656 --- /dev/null +++ b/usr/src/test/crypto-tests/tests/digest/Makefile.digest @@ -0,0 +1,21 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2019 Joyent, Inc. +# + +CRYPTO = pkcs kcf +COMMON_OBJS = main.o + +TESTROOT = $(ROOT)/opt/crypto-tests/tests/digest + +include $(SRC)/test/crypto-tests/tests/Makefile.crypto diff --git a/usr/src/test/crypto-tests/tests/hmac/Makefile b/usr/src/test/crypto-tests/tests/hmac/Makefile new file mode 100644 index 0000000000..d2600902b6 --- /dev/null +++ b/usr/src/test/crypto-tests/tests/hmac/Makefile @@ -0,0 +1,30 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2019 Joyent, Inc. +# + +ALGS = hmac_sha1 + +all := TARGET = all +install := TARGET = install +clean := TARGET = clean +clobber := TARGET = clobber + +.KEEP_STATE: + +all clean clobber install: $(ALGS) + +$(ALGS): FRC + $(MAKE) -e -f Makefile.hmac BASEPROG=$@ $(TARGET) + +FRC: diff --git a/usr/src/test/crypto-tests/tests/hmac/Makefile.hmac b/usr/src/test/crypto-tests/tests/hmac/Makefile.hmac new file mode 100644 index 0000000000..cad21ea9dc --- /dev/null +++ b/usr/src/test/crypto-tests/tests/hmac/Makefile.hmac @@ -0,0 +1,21 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2019 Joyent, Inc. +# + +CRYPTO = pkcs kcf +COMMON_OBJS = main.o + +TESTROOT = $(ROOT)/opt/crypto-tests/tests/hmac + +include $(SRC)/test/crypto-tests/tests/Makefile.crypto diff --git a/usr/src/test/crypto-tests/tests/hmac/hmac_sha1.c b/usr/src/test/crypto-tests/tests/hmac/hmac_sha1.c new file mode 100644 index 0000000000..be52211a57 --- /dev/null +++ b/usr/src/test/crypto-tests/tests/hmac/hmac_sha1.c @@ -0,0 +1,207 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License (), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2019 Joyent, Inc. + */ + +#include <sys/crypto/ioctl.h> +#include <sys/sha1.h> + +/* + * Test data from RFC2202 + */ + +static uint8_t KEY0[] = { + 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + 0x0b, 0x0b, 0x0b, 0x0b +}; + +/* "Hi There" */ +static uint8_t DATA0[] = { 0x48, 0x69, 0x20, 0x54, 0x68, 0x65, 0x72, 0x65 }; + +static uint8_t HMAC0[] = { + 0xb6, 0x17, 0x31, 0x86, 0x55, 0x05, 0x72, 0x64, + 0xe2, 0x8b, 0xc0, 0xb6, 0xfb, 0x37, 0x8c, 0x8e, + 0xf1, 0x46, 0xbe, 0x00 +}; + + +/* "Jefe" */ +static uint8_t KEY1[] = { 0x4a, 0x65, 0x66, 0x65 }; + +/* "what do ya want for nothing?" */ +static uint8_t DATA1[] = { + 0x77, 0x68, 0x61, 0x74, 0x20, 0x64, 0x6f, 0x20, + 0x79, 0x61, 0x20, 0x77, 0x61, 0x6e, 0x74, 0x20, + 0x66, 0x6f, 0x72, 0x20, 0x6e, 0x6f, 0x74, 0x68, + 0x69, 0x6e, 0x67, 0x3f +}; + +static uint8_t HMAC1[] = { + 0xef, 0xfc, 0xdf, 0x6a, 0xe5, 0xeb, 0x2f, 0xa2, + 0xd2, 0x74, 0x16, 0xd5, 0xf1, 0x84, 0xdf, 0x9c, + 0x25, 0x9a, 0x7c, 0x79 +}; + + +static uint8_t KEY2[] = { + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa +}; + +static uint8_t DATA2[] = { + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd +}; + +static uint8_t HMAC2[] = { + 0x12, 0x5d, 0x73, 0x42, 0xb9, 0xac, 0x11, 0xcd, + 0x91, 0xa3, 0x9a, 0xf4, 0x8a, 0xa1, 0x7b, 0x4f, + 0x63, 0xf1, 0x75, 0xd3 +}; + + +static uint8_t KEY3[] = { + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x19 +}; + +static uint8_t DATA3[] = { + 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, + 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, + 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, + 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, + 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, + 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, + 0xcd, 0xcd +}; + +static uint8_t HMAC3[] = { + 0x4c, 0x90, 0x07, 0xf4, 0x02, 0x62, 0x50, 0xc6, + 0xbc, 0x84, 0x14, 0xf9, 0xbf, 0x50, 0xc8, 0x6c, + 0x2d, 0x72, 0x35, 0xda +}; + + +static uint8_t KEY4[] = { + 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, + 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, + 0x0c, 0x0c, 0x0c, 0x0c +}; + +/* "Test With Truncation" */ +static uint8_t DATA4[] = { + 0x54, 0x65, 0x73, 0x74, 0x20, 0x57, 0x69, 0x74, + 0x68, 0x20, 0x54, 0x72, 0x75, 0x6e, 0x63, 0x61, + 0x74, 0x69, 0x6f, 0x6e +}; + +static uint8_t HMAC4[] = { + 0x4c, 0x1a, 0x03, 0x42, 0x4b, 0x55, 0xe0, 0x7f, + 0xe7, 0xf2, 0x7b, 0xe1, 0xd5, 0x8b, 0xb9, 0x32, + 0x4a, 0x9a, 0x5a, 0x04 +}; + + +static uint8_t KEY5[] = { + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa +}; + +/* "Test Using Larger Than Block-Size Key - Hash Key First" */ +static uint8_t DATA5[] = { + 0x54, 0x65, 0x73, 0x74, 0x20, 0x55, 0x73, 0x69, + 0x6e, 0x67, 0x20, 0x4c, 0x61, 0x72, 0x67, 0x65, + 0x72, 0x20, 0x54, 0x68, 0x61, 0x6e, 0x20, 0x42, + 0x6c, 0x6f, 0x63, 0x6b, 0x2d, 0x53, 0x69, 0x7a, + 0x65, 0x20, 0x4b, 0x65, 0x79, 0x20, 0x2d, 0x20, + 0x48, 0x61, 0x73, 0x68, 0x20, 0x4b, 0x65, 0x79, + 0x20, 0x46, 0x69, 0x72, 0x73, 0x74 +}; + +static uint8_t HMAC5[] = { + 0xaa, 0x4a, 0xe5, 0xe1, 0x52, 0x72, 0xd0, 0x0e, + 0x95, 0x70, 0x56, 0x37, 0xce, 0x8a, 0x3b, 0x55, + 0xed, 0x40, 0x21, 0x12 +}; + + +static uint8_t KEY6[] = { + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa +}; + +/* + * "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data" + */ +static uint8_t DATA6[] = { + 0x54, 0x65, 0x73, 0x74, 0x20, 0x55, 0x73, 0x69, + 0x6e, 0x67, 0x20, 0x4c, 0x61, 0x72, 0x67, 0x65, + 0x72, 0x20, 0x54, 0x68, 0x61, 0x6e, 0x20, 0x42, + 0x6c, 0x6f, 0x63, 0x6b, 0x2d, 0x53, 0x69, 0x7a, + 0x65, 0x20, 0x4b, 0x65, 0x79, 0x20, 0x61, 0x6e, + 0x64, 0x20, 0x4c, 0x61, 0x72, 0x67, 0x65, 0x72, + 0x20, 0x54, 0x68, 0x61, 0x6e, 0x20, 0x4f, 0x6e, + 0x65, 0x20, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x2d, + 0x53, 0x69, 0x7a, 0x65, 0x20, 0x44, 0x61, 0x74, + 0x61 +}; +static uint8_t HMAC6[] = { + 0xe8, 0xe9, 0x9d, 0x0f, 0x45, 0x23, 0x7d, 0x78, + 0x6d, 0x6b, 0xba, 0xa7, 0x96, 0x5c, 0x78, 0x08, + 0xbb, 0xff, 0x1a, 0x91 +}; + +uint8_t *DATA[] = { DATA0, DATA1, DATA2, DATA3, DATA4, DATA5, DATA6 }; + +size_t DATALEN[] = { + sizeof (DATA0), sizeof (DATA1), sizeof (DATA2), sizeof (DATA3), + sizeof (DATA4), sizeof (DATA5), sizeof (DATA6) +}; + +uint8_t *KEY[] = { KEY0, KEY1, KEY2, KEY3, KEY4, KEY5, KEY6 }; + +size_t KEYLEN[] = { + sizeof (KEY0), sizeof (KEY1), sizeof (KEY2), sizeof (KEY3), + sizeof (KEY4), sizeof (KEY5), sizeof (KEY6) +}; + +uint8_t *HMAC[] = { HMAC0, HMAC1, HMAC2, HMAC3, HMAC4, HMAC5, HMAC6 }; + +char *mechname = SUN_CKM_SHA1_HMAC; +size_t msgcount = 7; +size_t hmac_len = SHA1_DIGEST_LENGTH; diff --git a/usr/src/test/crypto-tests/tests/hmac/main.c b/usr/src/test/crypto-tests/tests/hmac/main.c new file mode 100644 index 0000000000..137cdb2801 --- /dev/null +++ b/usr/src/test/crypto-tests/tests/hmac/main.c @@ -0,0 +1,58 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2015 Nexenta Systems, Inc. All rights reserved. + * Copyright 2019 Joyent, Inc. + */ + +#include <stdio.h> + +#include "cryptotest.h" + +extern char *mechname; +extern uint8_t *KEY[]; +extern size_t KEYLEN[]; +extern uint8_t *DATA[]; +extern size_t DATALEN[]; +extern uint8_t *HMAC[]; +extern size_t hmac_len; +extern size_t msgcount; + +int +main(void) +{ + int errs = 0; + int i; + uint8_t N[1024]; + cryptotest_t args = { + .out = N, + .outlen = sizeof (N), + .plen = 0, + .mechname = mechname, + .updatelen = 1 + }; + + for (i = 0; i < msgcount; i++) { + args.key = KEY[i]; + args.keylen = KEYLEN[i]; + + args.in = DATA[i]; + args.inlen = DATALEN[i]; + + errs += run_test(&args, HMAC[i], hmac_len, MAC_FG); + (void) fprintf(stderr, "----------\n"); + } + if (errs != 0) + (void) fprintf(stderr, "%d tests failed\n", errs); + + return (errs); +} 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 6544b885e6..34149179e6 100644 --- a/usr/src/test/crypto-tests/tests/modes/aes/Makefile.subdirs +++ b/usr/src/test/crypto-tests/tests/modes/aes/Makefile.subdirs @@ -10,99 +10,9 @@ # # -# Copyright (c) 2012 by Delphix. All rights reserved. -# Copyright 2015 Nexenta Systems, Inc. All rights reserved. -# Copyright (c) 2018, Joyent, Inc. +# Copyright 2019 Joyent, Inc. # -include $(SRC)/cmd/Makefile.cmd -include $(SRC)/test/Makefile.com -include $(SRC)/cmd/Makefile.ctf +TESTROOT = $(ROOT)/opt/crypto-tests/tests/aes -CRYPTO = pkcs kcf -PROGS_32 = $(CRYPTO:%=$(BASEPROG)_32_%) -PROGS_64 = $(CRYPTO:%=$(BASEPROG)_64_%) -PROGS = $(PROGS_32) $(PROGS_64) -PROGS_pkcs = $(BASEPROG:%=%_32_pkcs) $(BASEPROG:%=%_64_pkcs) -PROGS_kcf = $(BASEPROG:%=%_32_kcf) $(BASEPROG:%=%_64_kcf) - -ROOTOPTPKG = $(ROOT)/opt/crypto-tests -TESTROOT = $(ROOTOPTPKG)/tests/aes -TESTDIR_pkcs = $(TESTROOT)/pkcs -TESTDIR_kcf = $(TESTROOT)/kcf - -COMMONDIR = ../../../common -$(PROGS_32) := OBJS += $(COMMONDIR)/testfuncs.32.o -$(PROGS_64) := OBJS += $(COMMONDIR)/testfuncs.64.o -$(PROGS_32) := OBJS += $(BASEPROG:%=%.32.o) -$(PROGS_64) := OBJS += $(BASEPROG:%=%.64.o) -$(BASEPROG)_32_pkcs := OBJS += $(COMMONDIR)/cryptotest_pkcs.32.o -$(BASEPROG)_64_pkcs := OBJS += $(COMMONDIR)/cryptotest_pkcs.64.o -$(BASEPROG)_32_kcf := OBJS += $(COMMONDIR)/cryptotest_kcf.32.o -$(BASEPROG)_64_kcf := OBJS += $(COMMONDIR)/cryptotest_kcf.64.o - -$(PROGS_pkcs) := LDLIBS += -lpkcs11 -lcryptoutil - -CSTD = $(CSTD_GNU99) - -CMDS_pkcs = $(PROGS_pkcs:%_pkcs=$(TESTDIR_pkcs)/%) -CMDS_kcf = $(PROGS_kcf:%_kcf=$(TESTDIR_kcf)/%) -CMDS = $(CMDS_pkcs) $(CMDS_kcf) - -$(CMDS) := FILEMODE = 0555 - -CPPFLAGS += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -CPPFLAGS += -I$(COMMONDIR) -I$(SRC)/common/crypto/ - -all: $(PROGS) - -%_32_pkcs: %.32.o - $(LINK.c) $(OBJS) -o $@ $(LDLIBS) - $(POST_PROCESS) - -%_64_pkcs: %.64.o - $(LINK64.c) $(OBJS) -o $@ $(LDLIBS) - $(POST_PROCESS) - -%_32_kcf: %.32.o - $(LINK.c) $(OBJS) -o $@ $(LDLIBS) - $(POST_PROCESS) - -%_64_kcf: %.64.o - $(LINK64.c) $(OBJS) -o $@ $(LDLIBS) - $(POST_PROCESS) - -%.32.o: %.c - $(COMPILE.c) -o $@ $< - $(POST_PROCESS_O) - -%.64.o: %.c - $(COMPILE64.c) -o $@ $< - $(POST_PROCESS_O) - - echo $(CMDS_kcf) - -install: all $(CMDS) - -clobber: clean - -$(RM) $(PROGS) - -clean: - -$(RM) *.o - -$(CMDS): $(TESTDIR_pkcs) $(TESTDIR_kcf) $(PROGS) - -$(TESTDIR_pkcs) $(TESTDIR_kcf): - $(INS.dir) - -$(TESTDIR_pkcs)/%_32: %_32_pkcs - $(INS.rename) - -$(TESTDIR_pkcs)/%_64: %_64_pkcs - $(INS.rename) - -$(TESTDIR_kcf)/%_32: %_32_kcf - $(INS.rename) - -$(TESTDIR_kcf)/%_64: %_64_kcf - $(INS.rename) +include $(SRC)/test/crypto-tests/tests/Makefile.crypto diff --git a/usr/src/test/crypto-tests/tests/modes/aes/cbc/Makefile b/usr/src/test/crypto-tests/tests/modes/aes/cbc/Makefile index e7e36b988c..a0ac134243 100644 --- a/usr/src/test/crypto-tests/tests/modes/aes/cbc/Makefile +++ b/usr/src/test/crypto-tests/tests/modes/aes/cbc/Makefile @@ -12,9 +12,11 @@ # # Copyright (c) 2012 by Delphix. All rights reserved. # Copyright 2015 Nexenta Systems, Inc. All rights reserved. +# Copyright 2019 Joyent, Inc. # BASEPROG = aes_cbc +CRYPTO = pkcs kcf include $(SRC)/cmd/Makefile.cmd include ../Makefile.subdirs diff --git a/usr/src/test/crypto-tests/tests/modes/aes/ccm/Makefile b/usr/src/test/crypto-tests/tests/modes/aes/ccm/Makefile index ab91c27fda..204deed70c 100644 --- a/usr/src/test/crypto-tests/tests/modes/aes/ccm/Makefile +++ b/usr/src/test/crypto-tests/tests/modes/aes/ccm/Makefile @@ -12,9 +12,11 @@ # # Copyright (c) 2012 by Delphix. All rights reserved. # Copyright 2015 Nexenta Systems, Inc. All rights reserved. +# Copyright 2019 Joyent, Inc. # BASEPROG = aes_ccm +CRYPTO = pkcs kcf include $(SRC)/cmd/Makefile.cmd include ../Makefile.subdirs diff --git a/usr/src/test/crypto-tests/tests/modes/aes/cmac/Makefile b/usr/src/test/crypto-tests/tests/modes/aes/cmac/Makefile index 4c99aad1b6..c989c9068c 100644 --- a/usr/src/test/crypto-tests/tests/modes/aes/cmac/Makefile +++ b/usr/src/test/crypto-tests/tests/modes/aes/cmac/Makefile @@ -12,9 +12,11 @@ # # Copyright (c) 2012 by Delphix. All rights reserved. # Copyright 2015 Nexenta Systems, Inc. All rights reserved. +# Copyright 2019 Joyent, Inc. # BASEPROG = aes_cmac +CRYPTO = pkcs kcf include $(SRC)/cmd/Makefile.cmd include ../Makefile.subdirs diff --git a/usr/src/test/crypto-tests/tests/modes/aes/ctr/Makefile b/usr/src/test/crypto-tests/tests/modes/aes/ctr/Makefile index adc2a9cb52..e19dfe4215 100644 --- a/usr/src/test/crypto-tests/tests/modes/aes/ctr/Makefile +++ b/usr/src/test/crypto-tests/tests/modes/aes/ctr/Makefile @@ -12,9 +12,11 @@ # # Copyright (c) 2012 by Delphix. All rights reserved. # Copyright 2015 Nexenta Systems, Inc. All rights reserved. +# Copyright 2019 Joyent, Inc. # BASEPROG = aes_ctr +CRYPTO = pkcs kcf include $(SRC)/cmd/Makefile.cmd include ../Makefile.subdirs diff --git a/usr/src/test/crypto-tests/tests/modes/aes/ecb/Makefile b/usr/src/test/crypto-tests/tests/modes/aes/ecb/Makefile index d413f18329..ce4b90115b 100644 --- a/usr/src/test/crypto-tests/tests/modes/aes/ecb/Makefile +++ b/usr/src/test/crypto-tests/tests/modes/aes/ecb/Makefile @@ -12,9 +12,11 @@ # # Copyright (c) 2012 by Delphix. All rights reserved. # Copyright 2015 Nexenta Systems, Inc. All rights reserved. +# Copyright 2019 Joyent, Inc. # BASEPROG = aes_ecb +CRYPTO = pkcs kcf include $(SRC)/cmd/Makefile.cmd include ../Makefile.subdirs diff --git a/usr/src/test/crypto-tests/tests/modes/aes/gcm/Makefile b/usr/src/test/crypto-tests/tests/modes/aes/gcm/Makefile index 2cef165155..bd33defb96 100644 --- a/usr/src/test/crypto-tests/tests/modes/aes/gcm/Makefile +++ b/usr/src/test/crypto-tests/tests/modes/aes/gcm/Makefile @@ -12,9 +12,11 @@ # # Copyright (c) 2012 by Delphix. All rights reserved. # Copyright 2015 Nexenta Systems, Inc. All rights reserved. +# Copyright 2019 Joyent, Inc. # BASEPROG = aes_gcm +CRYPTO = pkcs kcf include $(SRC)/cmd/Makefile.cmd include ../Makefile.subdirs |