diff options
author | Greg Hudson <ghudson@mit.edu> | 2014-05-20 14:52:44 -0400 |
---|---|---|
committer | Tom Yu <tlyu@mit.edu> | 2015-02-06 17:45:59 -0500 |
commit | a6dde5302783a59d958e1fdafd53b22fa627b158 (patch) | |
tree | 1e09160dbaeeaeefaa913e1276b74e297051e322 | |
parent | 60e6d8c3695dbdd2c1f0d7a737c68a408dc084b3 (diff) | |
download | krb5-a6dde5302783a59d958e1fdafd53b22fa627b158.zip krb5-a6dde5302783a59d958e1fdafd53b22fa627b158.tar.gz krb5-a6dde5302783a59d958e1fdafd53b22fa627b158.tar.bz2 |
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.
(back ported from commit 6e8b2fba84df2ef74ce071330b4c3f843f4b7541)
ticket: 8099 (new)
version_fixed: 1.11.6
status: resolved
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | src/lib/crypto/crypto_tests/Makefile.in | 11 | ||||
-rw-r--r-- | src/lib/crypto/crypto_tests/t_combine.c | 80 |
3 files changed, 89 insertions, 3 deletions
@@ -136,6 +136,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 58e1c48..08fa0e5 100644 --- a/src/lib/crypto/crypto_tests/Makefile.in +++ b/src/lib/crypto/crypto_tests/Makefile.in @@ -28,7 +28,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 = ..\..\.. @@ -40,7 +41,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 @@ -68,6 +69,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) @@ -153,6 +155,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 \ @@ -165,7 +170,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/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; +} |