]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Add tests for krb5int_c_combine_keys
authorGreg Hudson <ghudson@mit.edu>
Tue, 20 May 2014 18:52:44 +0000 (14:52 -0400)
committerTom Yu <tlyu@mit.edu>
Fri, 27 Jun 2014 16:32:05 +0000 (12:32 -0400)
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
src/lib/crypto/crypto_tests/Makefile.in
src/lib/crypto/crypto_tests/deps
src/lib/crypto/crypto_tests/t_combine.c [new file with mode: 0644]

index c03bc6f4fa5c95bee5f76418a4fe9dd8b723a726..d287f7aa877fffd3ac04dd642e39bcede57b0ae7 100644 (file)
@@ -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
index c3ecf2f1be764b4f348aa7af7fd93c769a830c1f..c92ecc8a154c315f213f5f85b94d5edb06c49c58 100644 (file)
@@ -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
index f804e542a7386e5923d86c061de9b6677ab0ebf0..31a98d5c470805141c3afc0f450b147911aa7a5d 100644 (file)
@@ -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 (file)
index 0000000..89219c7
--- /dev/null
@@ -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;
+}