From 83b94e13d92d4a2102b390eb0c4f66ecd83db918 Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Mon, 11 May 2009 20:55:57 +0000 Subject: [PATCH] pull up r22298 from trunk ------------------------------------------------------------------------ r22298 | hartmans | 2009-04-30 16:17:42 -0400 (Thu, 30 Apr 2009) | 10 lines Changed paths: M /trunk/src/lib/crypto/des/Makefile.in M /trunk/src/lib/crypto/des/des_int.h A /trunk/src/lib/crypto/des/des_prf.c (from /trunk/src/lib/crypto/dk/dk_prf.c:22295) M /trunk/src/lib/crypto/etypes.c M /trunk/src/lib/crypto/t_cf2.comments M /trunk/src/lib/crypto/t_cf2.expected M /trunk/src/lib/crypto/t_cf2.in ticket: 5587 Tags: pullup Implement DES and 3DES PRF. Patch fromKAMADA Ken'ichi Currently the DES and 3DES PRF output 16-byte results. This is consistent with RFC 3961, but we need to confirm it is consistent with Heimdal and WG decisions. See IETF 74 minutes for some discussion of the concern as it applies to AES and thus possibly all simplified profile enctypes. ticket: 5587 version_fixed: 1.7 git-svn-id: svn://anonsvn.mit.edu/krb5/branches/krb5-1-7@22335 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/crypto/des/Makefile.in | 3 ++ src/lib/crypto/des/des_int.h | 6 +++- src/lib/crypto/des/des_prf.c | 54 ++++++++++++++++++++++++++++++++++ src/lib/crypto/etypes.c | 23 ++++++++------- src/lib/crypto/t_cf2.comments | 2 ++ src/lib/crypto/t_cf2.expected | 2 ++ src/lib/crypto/t_cf2.in | 10 +++++++ 7 files changed, 88 insertions(+), 12 deletions(-) create mode 100644 src/lib/crypto/des/des_prf.c diff --git a/src/lib/crypto/des/Makefile.in b/src/lib/crypto/des/Makefile.in index d9e8d15f3..ef700a74d 100644 --- a/src/lib/crypto/des/Makefile.in +++ b/src/lib/crypto/des/Makefile.in @@ -18,6 +18,7 @@ STLIBOBJS=\ d3_cbc.o \ d3_aead.o \ d3_kysched.o \ + des_prf.o \ f_aead.o \ f_cbc.o \ f_cksum.o \ @@ -32,6 +33,7 @@ OBJS= $(OUTPRE)afsstring2key.$(OBJEXT) \ $(OUTPRE)d3_cbc.$(OBJEXT) \ $(OUTPRE)d3_aead.$(OBJEXT) \ $(OUTPRE)d3_kysched.$(OBJEXT) \ + $(OUTPRE)des_prf.$(OBJEXT) \ $(OUTPRE)f_aead.$(OBJEXT) \ $(OUTPRE)f_cbc.$(OBJEXT) \ $(OUTPRE)f_cksum.$(OBJEXT) \ @@ -46,6 +48,7 @@ SRCS= $(srcdir)/afsstring2key.c \ $(srcdir)/d3_cbc.c \ $(srcdir)/d3_aead.c \ $(srcdir)/d3_kysched.c \ + $(srcdir)/des_prf.c \ $(srcdir)/f_aead.c \ $(srcdir)/f_cbc.c \ $(srcdir)/f_cksum.c \ diff --git a/src/lib/crypto/des/des_int.h b/src/lib/crypto/des/des_int.h index db0e6765a..4a1d52ae3 100644 --- a/src/lib/crypto/des/des_int.h +++ b/src/lib/crypto/des/des_int.h @@ -374,5 +374,9 @@ extern krb5_error_code mit_des_set_random_generator_seed extern krb5_error_code mit_des_set_random_sequence_number (const krb5_data * sequence, krb5_pointer random_state); - +krb5_error_code +krb5int_des_prf (const struct krb5_enc_provider *enc, + const struct krb5_hash_provider *hash, + const krb5_keyblock *key, + const krb5_data *in, krb5_data *out); #endif /*DES_INTERNAL_DEFS*/ diff --git a/src/lib/crypto/des/des_prf.c b/src/lib/crypto/des/des_prf.c new file mode 100644 index 000000000..9bb1085c3 --- /dev/null +++ b/src/lib/crypto/des/des_prf.c @@ -0,0 +1,54 @@ +/* + * lib/crypto/des/des_prf.c + * + * Copyright (C) 2004, 2009 by the Massachusetts Institute of Technology. + * All rights reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + * + * + * This file contains an implementation of the RFC 3961 PRF for + * des-cbc-crc, des-cbc-md4, and des-cbc-md5 enctypes. + */ + +#include "k5-int.h" +#include "../hash_provider/hash_provider.h" /* XXX is this ok? */ + +krb5_error_code +krb5int_des_prf (const struct krb5_enc_provider *enc, + const struct krb5_hash_provider *hash, + const krb5_keyblock *key, + const krb5_data *in, krb5_data *out) +{ + krb5_data tmp; + krb5_error_code ret = 0; + + hash = &krb5int_hash_md5; /* MD5 is always used. */ + tmp.length = hash->hashsize; + tmp.data = malloc(hash->hashsize); + if (tmp.data == NULL) + return ENOMEM; + ret = hash->hash(1, in, &tmp); + if (ret == 0) + ret = enc->encrypt(key, NULL, &tmp, out); + free(tmp.data); + return ret; +} diff --git a/src/lib/crypto/etypes.c b/src/lib/crypto/etypes.c index debf585fa..c44ee413e 100644 --- a/src/lib/crypto/etypes.c +++ b/src/lib/crypto/etypes.c @@ -33,6 +33,7 @@ #include "dk.h" #include "arcfour.h" #include "aes_s2k.h" +#include "des/des_int.h" /* these will be linear searched. if they ever get big, a binary search or hash table would be better, which means these would need @@ -44,47 +45,47 @@ const struct krb5_keytypes krb5_enctypes_list[] = { { ENCTYPE_DES_CBC_CRC, "des-cbc-crc", { 0 }, "DES cbc mode with CRC-32", &krb5int_enc_des, &krb5int_hash_crc32, - 8, + 16, krb5_old_encrypt_length, krb5_old_encrypt, krb5_old_decrypt, krb5int_des_string_to_key, - NULL, /*PRF*/ + krb5int_des_prf, CKSUMTYPE_RSA_MD5, NULL, /*AEAD*/ ETYPE_WEAK }, { ENCTYPE_DES_CBC_MD4, "des-cbc-md4", { 0 }, "DES cbc mode with RSA-MD4", &krb5int_enc_des, &krb5int_hash_md4, - 8, + 16, krb5_old_encrypt_length, krb5_old_encrypt, krb5_old_decrypt, krb5int_des_string_to_key, - NULL, /*PRF*/ + krb5int_des_prf, CKSUMTYPE_RSA_MD4, NULL, /*AEAD*/ ETYPE_WEAK }, { ENCTYPE_DES_CBC_MD5, "des-cbc-md5", { "des" }, "DES cbc mode with RSA-MD5", &krb5int_enc_des, &krb5int_hash_md5, - 8, + 16, krb5_old_encrypt_length, krb5_old_encrypt, krb5_old_decrypt, krb5int_des_string_to_key, - NULL, /*PRF*/ + krb5int_des_prf, CKSUMTYPE_RSA_MD5, NULL, /*AEAD*/ ETYPE_WEAK }, { ENCTYPE_DES_CBC_RAW, "des-cbc-raw", { 0 }, "DES cbc mode raw", &krb5int_enc_des, NULL, - 8, + 16, krb5_raw_encrypt_length, krb5_raw_encrypt, krb5_raw_decrypt, krb5int_des_string_to_key, - NULL, /*PRF*/ + krb5int_des_prf, 0, &krb5int_aead_raw, ETYPE_WEAK }, { ENCTYPE_DES3_CBC_RAW, "des3-cbc-raw", { 0 }, "Triple DES cbc mode raw", &krb5int_enc_des3, NULL, - 8, + 16, krb5_raw_encrypt_length, krb5_raw_encrypt, krb5_raw_decrypt, krb5int_dk_string_to_key, NULL, /*PRF*/ @@ -96,10 +97,10 @@ const struct krb5_keytypes krb5_enctypes_list[] = { "des3-cbc-sha1", { "des3-hmac-sha1", "des3-cbc-sha1-kd" }, "Triple DES cbc mode with HMAC/sha1", &krb5int_enc_des3, &krb5int_hash_sha1, - 8, + 16, krb5_dk_encrypt_length, krb5_dk_encrypt, krb5_dk_decrypt, krb5int_dk_string_to_key, - NULL, /*PRF*/ + krb5int_dk_prf, CKSUMTYPE_HMAC_SHA1_DES3, &krb5int_aead_dk, 0 /*flags*/ }, diff --git a/src/lib/crypto/t_cf2.comments b/src/lib/crypto/t_cf2.comments index 4f01e7964..504dc3173 100644 --- a/src/lib/crypto/t_cf2.comments +++ b/src/lib/crypto/t_cf2.comments @@ -1,3 +1,5 @@ The first test mirrors the first two tests in t_prf.in. The second test mirrors the following four tests in t_prf.in. + +The third and fourth tests are simple tests of the DES and 3DES PRF. diff --git a/src/lib/crypto/t_cf2.expected b/src/lib/crypto/t_cf2.expected index 104c6c4a0..709791121 100644 --- a/src/lib/crypto/t_cf2.expected +++ b/src/lib/crypto/t_cf2.expected @@ -1,2 +1,4 @@ 97df97e4b798b29eb31ed7280287a92a 4d6ca4e629785c1f01baf55e2e548566b9617ae3a96868c337cb93b5e72b1c7b +43bae3738c9467e6 +e58f9eb643862c13ad38e529313462a7f73e62834fe54a01 diff --git a/src/lib/crypto/t_cf2.in b/src/lib/crypto/t_cf2.in index d06fd5621..b951e4c0e 100644 --- a/src/lib/crypto/t_cf2.in +++ b/src/lib/crypto/t_cf2.in @@ -8,3 +8,13 @@ key1 key2 a b +1 +key1 +key2 +a +b +16 +key1 +key2 +a +b -- 2.26.2