summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason King <jason.king@joyent.com>2019-07-10 04:55:35 +0000
committerJason King <jason.king@joyent.com>2019-08-05 19:55:14 +0000
commitadd17634a6e3f59776d7cd5b8db46b8fed396be1 (patch)
treee7887a27d49020c464ba99c6e798517a51064e2d
parent31891197ecb87e2742aca4828b47451926228841 (diff)
downloadillumos-joyent-add17634a6e3f59776d7cd5b8db46b8fed396be1.tar.gz
OS-7881 Add HMAC_SHA1 crypto tests
-rw-r--r--usr/src/test/crypto-tests/runfiles/default.run11
-rw-r--r--usr/src/test/crypto-tests/tests/Makefile5
-rw-r--r--usr/src/test/crypto-tests/tests/hmac/Makefile115
-rw-r--r--usr/src/test/crypto-tests/tests/hmac/hmac_sha1.c207
-rw-r--r--usr/src/test/crypto-tests/tests/hmac/main.c58
5 files changed, 393 insertions, 3 deletions
diff --git a/usr/src/test/crypto-tests/runfiles/default.run b/usr/src/test/crypto-tests/runfiles/default.run
index e44c9d647a..61f5499e35 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']
+
+[/opt/crypto-tests/tests/hmac/kcf]
+pre = setup
+user = root
+tests = ['hmac_sha1']
+post = cleanup
diff --git a/usr/src/test/crypto-tests/tests/Makefile b/usr/src/test/crypto-tests/tests/Makefile
index 4b2dd162d2..16eab78dd5 100644
--- a/usr/src/test/crypto-tests/tests/Makefile
+++ b/usr/src/test/crypto-tests/tests/Makefile
@@ -11,12 +11,13 @@
#
# 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
modes: common
digest: common
+hmac: common
include $(SRC)/test/Makefile.com
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..f1f1c00314
--- /dev/null
+++ b/usr/src/test/crypto-tests/tests/hmac/Makefile
@@ -0,0 +1,115 @@
+#
+# 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.
+#
+
+include $(SRC)/cmd/Makefile.cmd
+include $(SRC)/test/Makefile.com
+include $(SRC)/cmd/Makefile.ctf
+
+ALGS = hmac_sha1
+CRYPTO = pkcs kcf
+
+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)
+
+ROOTOPTPKG = $(ROOT)/opt/crypto-tests
+TESTROOT = $(ROOTOPTPKG)/tests/hmac
+TESTDIR_pkcs = $(TESTROOT)/pkcs
+TESTDIR_kcf = $(TESTROOT)/kcf
+
+COMMONDIR = ../common
+
+$(CRYPTO:%=hmac_sha1_32_%) := OBJS = hmac_sha1.32.o
+$(CRYPTO:%=hmac_sha1_64_%) := OBJS = hmac_sha1.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
+
+$(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)
+
+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)
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[] = {
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65, 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);
+}