krb5 commit [krb5-1.12]: Add tests for krb5int_c_combine_keys
Tom Yu
tlyu at MIT.EDU
Fri Jun 27 12:34:52 EDT 2014
https://github.com/krb5/krb5/commit/fdd7eca3ada4b0a038850dd0207a70c7f1a8b59c
commit fdd7eca3ada4b0a038850dd0207a70c7f1a8b59c
Author: Greg Hudson <ghudson at mit.edu>
Date: Tue May 20 14:52:44 2014 -0400
Add tests for krb5int_c_combine_keys
krb5int_c_combine_keys is used only by SAM-2 preauth with neither the
send-encrypted-sad nor use-sad-as-key flags, so it isn't covered by
any automated function tests. Add some unit tests to make sure that
it works and returns the expected results for two randomly generated
test vectors.
(cherry picked from commit 6e8b2fba84df2ef74ce071330b4c3f843f4b7541)
ticket: 7914
version_fixed: 1.12.2
status: resolved
.gitignore | 1 +
src/lib/crypto/crypto_tests/Makefile.in | 11 +++-
src/lib/crypto/crypto_tests/deps | 10 ++++
src/lib/crypto/crypto_tests/t_combine.c | 80 +++++++++++++++++++++++++++++++
4 files changed, 99 insertions(+), 3 deletions(-)
diff --git a/.gitignore b/.gitignore
index c03bc6f..d287f7a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -141,6 +141,7 @@ testlog
/src/lib/crypto/crypto_tests/t_cksum5
/src/lib/crypto/crypto_tests/t_cksums
/src/lib/crypto/crypto_tests/t_cmac
+/src/lib/crypto/crypto_tests/t_combine
/src/lib/crypto/crypto_tests/t_crc
/src/lib/crypto/crypto_tests/t_cts
/src/lib/crypto/crypto_tests/t_decrypt
diff --git a/src/lib/crypto/crypto_tests/Makefile.in b/src/lib/crypto/crypto_tests/Makefile.in
index c3ecf2f..c92ecc8 100644
--- a/src/lib/crypto/crypto_tests/Makefile.in
+++ b/src/lib/crypto/crypto_tests/Makefile.in
@@ -24,7 +24,8 @@ EXTRADEPSRCS=\
$(srcdir)/t_short.c \
$(srcdir)/t_str2key.c \
$(srcdir)/t_derive.c \
- $(srcdir)/t_fork.c
+ $(srcdir)/t_fork.c \
+ $(srcdir)/t_combine.c
##DOS##BUILDTOP = ..\..\..
@@ -36,7 +37,7 @@ check-unix:: t_nfold t_encrypt t_decrypt t_prf t_prng t_cmac t_hmac \
aes-test \
camellia-test \
t_mddriver4 t_mddriver \
- t_crc t_cts t_short t_str2key t_derive t_fork t_cf2
+ t_crc t_cts t_short t_str2key t_derive t_fork t_cf2 t_combine
$(RUN_SETUP) $(VALGRIND) ./t_nfold
$(RUN_SETUP) $(VALGRIND) ./t_encrypt
$(RUN_SETUP) $(VALGRIND) ./t_decrypt
@@ -64,6 +65,7 @@ check-unix:: t_nfold t_encrypt t_decrypt t_prf t_prng t_cmac t_hmac \
$(RUN_SETUP) $(VALGRIND) ./t_fork
$(RUN_SETUP) $(VALGRIND) ./t_cf2 <$(srcdir)/t_cf2.in >t_cf2.output
diff t_cf2.output $(srcdir)/t_cf2.expected
+ $(RUN_SETUP) $(VALGRIND) ./t_combine
# $(RUN_SETUP) $(VALGRIND) ./t_pkcs5
t_nfold$(EXEEXT): t_nfold.$(OBJEXT) $(KRB5_BASE_DEPLIBS)
@@ -149,6 +151,9 @@ t_fork$(EXEEXT): t_fork.$(OBJEXT) $(KRB5_BASE_DEPLIBS)
t_cf2$(EXEEXT): t_cf2.$(OBJEXT) $(KRB5_BASE_DEPLIBS)
$(CC_LINK) -o $@ t_cf2.$(OBJEXT) $(KRB5_BASE_LIBS)
+t_combine$(EXEEXT): t_combine.$(OBJEXT) $(KRB5_BASE_DEPLIBS)
+ $(CC_LINK) -o $@ t_combine.$(OBJEXT) $(KRB5_BASE_LIBS)
+
clean::
$(RM) t_nfold.o t_nfold t_encrypt t_encrypt.o \
t_decrypt.o t_decrypt t_prng.o t_prng t_cmac.o t_cmac \
@@ -161,7 +166,7 @@ clean::
t_derive t_derive.o t_fork t_fork.o \
t_mddriver$(EXEEXT) $(OUTPRE)t_mddriver.$(OBJEXT) \
camellia-test camellia-test.o camellia-vt.txt \
- t_cf2 t_cf2.o t_cf2.output
+ t_cf2 t_cf2.o t_cf2.output t_combine.o t_combine
-$(RM) t_prng.output
-$(RM) t_prf.output
diff --git a/src/lib/crypto/crypto_tests/deps b/src/lib/crypto/crypto_tests/deps
index f804e54..31a98d5 100644
--- a/src/lib/crypto/crypto_tests/deps
+++ b/src/lib/crypto/crypto_tests/deps
@@ -246,3 +246,13 @@ $(OUTPRE)t_fork.$(OBJEXT): $(BUILDTOP)/include/autoconf.h \
$(top_srcdir)/include/krb5.h $(top_srcdir)/include/krb5/authdata_plugin.h \
$(top_srcdir)/include/krb5/plugin.h $(top_srcdir)/include/port-sockets.h \
$(top_srcdir)/include/socket-utils.h t_fork.c
+$(OUTPRE)t_combine.$(OBJEXT): $(BUILDTOP)/include/autoconf.h \
+ $(BUILDTOP)/include/krb5/krb5.h $(BUILDTOP)/include/osconf.h \
+ $(BUILDTOP)/include/profile.h $(COM_ERR_DEPS) $(top_srcdir)/include/k5-buf.h \
+ $(top_srcdir)/include/k5-err.h $(top_srcdir)/include/k5-gmt_mktime.h \
+ $(top_srcdir)/include/k5-int-pkinit.h $(top_srcdir)/include/k5-int.h \
+ $(top_srcdir)/include/k5-platform.h $(top_srcdir)/include/k5-plugin.h \
+ $(top_srcdir)/include/k5-thread.h $(top_srcdir)/include/k5-trace.h \
+ $(top_srcdir)/include/krb5.h $(top_srcdir)/include/krb5/authdata_plugin.h \
+ $(top_srcdir)/include/krb5/plugin.h $(top_srcdir)/include/port-sockets.h \
+ $(top_srcdir)/include/socket-utils.h t_combine.c
diff --git a/src/lib/crypto/crypto_tests/t_combine.c b/src/lib/crypto/crypto_tests/t_combine.c
new file mode 100644
index 0000000..89219c7
--- /dev/null
+++ b/src/lib/crypto/crypto_tests/t_combine.c
@@ -0,0 +1,80 @@
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/* lib/crypto/crypto_tests/t_combine.c - krb5int_c_combine_keys tests */
+/*
+ * Copyright (C) 2014 by the Massachusetts Institute of Technology.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "k5-int.h"
+
+unsigned char des_key1[] = "\x04\x86\xCD\x97\x61\xDF\xD6\x29";
+unsigned char des_key2[] = "\x1A\x54\x9B\x7F\xDC\x20\x83\x0E";
+unsigned char des_result[] = "\xC2\x13\x01\x52\x89\x26\xC4\xF7";
+
+unsigned char des3_key1[] = "\x10\xB6\x75\xD5\x5B\xD9\x6E\x73"
+ "\xFD\x54\xB3\x3D\x37\x52\xC1\x2A\xF7\x43\x91\xFE\x1C\x02\x37\x13";
+unsigned char des3_key2[] = "\xC8\xDA\x3E\xA7\xB6\x64\xAE\x7A"
+ "\xB5\x70\x2A\x29\xB3\xBF\x9B\xA8\x46\x7C\x5B\xA8\x8A\x46\x70\x10";
+unsigned char des3_result[] = "\x2F\x79\x97\x3E\x3E\xA4\x73\x1A"
+ "\xB9\x3D\xEF\x5E\x7C\x29\xFB\x2A\x68\x86\x1F\xC1\x85\x0E\x79\x92";
+
+int
+main(int argc, char **argv)
+{
+ krb5_keyblock kb1, kb2, result;
+
+ kb1.enctype = ENCTYPE_DES_CBC_CRC;
+ kb1.contents = des_key1;
+ kb1.length = 8;
+ kb2.enctype = ENCTYPE_DES_CBC_CRC;
+ kb2.contents = des_key2;
+ kb2.length = 8;
+ memset(&result, 0, sizeof(result));
+ if (krb5int_c_combine_keys(NULL, &kb1, &kb2, &result) != 0)
+ abort();
+ if (result.enctype != ENCTYPE_DES_CBC_CRC || result.length != 8 ||
+ memcmp(result.contents, des_result, 8) != 0)
+ abort();
+ krb5_free_keyblock_contents(NULL, &result);
+
+ kb1.enctype = ENCTYPE_DES3_CBC_SHA1;
+ kb1.contents = des3_key1;
+ kb1.length = 24;
+ kb2.enctype = ENCTYPE_DES3_CBC_SHA1;
+ kb2.contents = des3_key2;
+ kb2.length = 24;
+ memset(&result, 0, sizeof(result));
+ if (krb5int_c_combine_keys(NULL, &kb1, &kb2, &result) != 0)
+ abort();
+ if (result.enctype != ENCTYPE_DES3_CBC_SHA1 || result.length != 24 ||
+ memcmp(result.contents, des3_result, 24) != 0)
+ abort();
+ krb5_free_keyblock_contents(NULL, &result);
+
+ return 0;
+}
More information about the cvs-krb5
mailing list