svn rev #24236: branches/camellia-ccm/ src/lib/crypto/krb/ src/lib/crypto/krb/dk/

ghudson@MIT.EDU ghudson at MIT.EDU
Mon Aug 9 14:16:04 EDT 2010


http://src.mit.edu/fisheye/changelog/krb5/?cs=24236
Commit By: ghudson
Log Message:
Make the camellia-ccm cipher state just the counter value, for
consistency with the spec.  (Previously it was the whole counter block,
but only the counter value was used.)  To accomplish this, add methods
to allow enctypes to manage cipher state.  Non-CCM enctypes will simply
delegate these methods to the enc provider.



Changed Files:
U   branches/camellia-ccm/README.BRANCH
U   branches/camellia-ccm/src/lib/crypto/krb/dk/dk.h
U   branches/camellia-ccm/src/lib/crypto/krb/dk/dk_ccm.c
U   branches/camellia-ccm/src/lib/crypto/krb/etypes.c
U   branches/camellia-ccm/src/lib/crypto/krb/etypes.h
U   branches/camellia-ccm/src/lib/crypto/krb/state.c
Modified: branches/camellia-ccm/README.BRANCH
===================================================================
--- branches/camellia-ccm/README.BRANCH	2010-08-09 16:30:46 UTC (rev 24235)
+++ branches/camellia-ccm/README.BRANCH	2010-08-09 18:16:04 UTC (rev 24236)
@@ -38,6 +38,9 @@
     so that the inline no-copy variants can be used in concert with
     the special flags.
 
+  * Enctypes can now manage cipher state.  Non-CCM enctypes delegate
+    this job to the encryption provider methods.
+
   * There is now an encrypt_block helper function to perform
     single-block encryptions using the underlying block cipher when
     the enc-provider might be either a CBC-mode or counter-mode
@@ -82,7 +85,8 @@
 * lib/crypto/krb/rand2key/camellia_rand2key.c: camellia rand2key (same as AES)
 * lib/crypto/krb/Makefile.in: add include for camellia from back end
 * lib/crypto/krb/cksumtypes.c: add checksum types
-* lib/crypto/krb/etypes.c: add enctypes
+* lib/crypto/krb/etypes.h: add init_state/free_state methods to enctype struct
+* lib/crypto/krb/etypes.c: add new enctypes; add init_state/free_state methods
 * lib/crypto/krb/cksumtypes.h: add krb5int_cmac_checksum declaration
 * lib/crypto/krb/dk/checksum.c: renamed to checksum_hmac.c
 * lib/crypto/krb/dk/derive.c: add derive_random_sp800_108_cmac support
@@ -102,6 +106,7 @@
 * lib/crypto/krb/aead.c: block processing moved to aead.h
 * lib/crypto/krb/aead.h: block processing moved from aead.c
 * lib/crypto/krb/combine_keys.c: key derivation call site changes
+* lib/crypto/krb/state.c: use enctype init_state/free_state methods
 
 Tests
 * tests/dejagnu/config/default.exp: Camellia test pass

Modified: branches/camellia-ccm/src/lib/crypto/krb/dk/dk.h
===================================================================
--- branches/camellia-ccm/src/lib/crypto/krb/dk/dk.h	2010-08-09 16:30:46 UTC (rev 24235)
+++ branches/camellia-ccm/src/lib/crypto/krb/dk/dk.h	2010-08-09 18:16:04 UTC (rev 24236)
@@ -115,3 +115,11 @@
                          krb5_key key, krb5_keyusage usage,
                          const krb5_crypto_iov *data, size_t num_data,
                          krb5_data *output);
+
+krb5_error_code
+krb5int_dk_ccm_init_state(const struct krb5_keytypes *ktp,
+                          const krb5_keyblock *key, krb5_keyusage usage,
+                          krb5_data *out_state);
+
+void
+krb5int_dk_ccm_free_state(const struct krb5_keytypes *ktp, krb5_data *state);

Modified: branches/camellia-ccm/src/lib/crypto/krb/dk/dk_ccm.c
===================================================================
--- branches/camellia-ccm/src/lib/crypto/krb/dk/dk_ccm.c	2010-08-09 16:30:46 UTC (rev 24235)
+++ branches/camellia-ccm/src/lib/crypto/krb/dk/dk_ccm.c	2010-08-09 18:16:04 UTC (rev 24236)
@@ -228,7 +228,7 @@
 
     /* Finally, the counter value. */
     if (state != NULL)
-        memcpy(&counter->data[1 + n], &state->data[1 + n], q);
+        memcpy(&counter->data[1 + n], state->data, q);
     else
         memset(&counter->data[1 + n], 0, q);
 
@@ -375,10 +375,10 @@
     if (ret != 0)
         goto cleanup;
 
-    /* Store the counter block as cipher state.  Subsequent encryptions will
-     * reuse the counter value but will generate a fresh nonce. */
+    /* Store the counter value as cipher state.  Subsequent encryptions will
+     * generate a fresh nonce. */
     if (state != NULL)
-        memcpy(state->data, counter.data, counter.length);
+        memcpy(state->data, counter.data + 1 + header_len, 15 - header_len);
 
 cleanup:
     free(sign_data);
@@ -544,10 +544,10 @@
         goto cleanup;
     }
 
-    /* Store the counter block as cipher state.  Subsequent decryptions will
-     * reuse the counter value but will generate a fresh nonce. */
+    /* Store the counter value as cipher state.  Subsequent encryptions will
+     * generate a fresh nonce. */
     if (state != NULL)
-        memcpy(state->data, counter.data, counter.length);
+        memcpy(state->data, counter.data + 1 + header_len, 15 - header_len);
 
 cleanup:
     free(made_cksum.data);
@@ -588,3 +588,23 @@
     return ret;
 }
 
+krb5_error_code
+krb5int_dk_ccm_init_state(const struct krb5_keytypes *ktp,
+                          const krb5_keyblock *key, krb5_keyusage usage,
+                          krb5_data *out_state)
+{
+    unsigned int header_len;
+
+    /* The cipher state is the q-byte block counter value. */
+    header_len = ktp->crypto_length(ktp, KRB5_CRYPTO_TYPE_HEADER);
+    return alloc_data(out_state, 15 - header_len);
+}
+
+void
+krb5int_dk_ccm_free_state(const struct krb5_keytypes *ktp,
+                          krb5_data *state)
+{
+    free(state->data);
+    state->data = NULL;
+    state->length = 0;
+}

Modified: branches/camellia-ccm/src/lib/crypto/krb/etypes.c
===================================================================
--- branches/camellia-ccm/src/lib/crypto/krb/etypes.c	2010-08-09 16:30:46 UTC (rev 24235)
+++ branches/camellia-ccm/src/lib/crypto/krb/etypes.c	2010-08-09 18:16:04 UTC (rev 24236)
@@ -50,6 +50,7 @@
       krb5int_old_crypto_length, krb5int_old_encrypt, krb5int_old_decrypt,
       krb5int_des_string_to_key,
       krb5int_des_prf,
+      krb5int_init_state_enc, krb5int_free_state_enc,
       CKSUMTYPE_RSA_MD5,
       ETYPE_WEAK },
     { ENCTYPE_DES_CBC_MD4,
@@ -59,6 +60,7 @@
       krb5int_old_crypto_length, krb5int_old_encrypt, krb5int_old_decrypt,
       krb5int_des_string_to_key,
       krb5int_des_prf,
+      krb5int_init_state_enc, krb5int_free_state_enc,
       CKSUMTYPE_RSA_MD4,
       ETYPE_WEAK },
     { ENCTYPE_DES_CBC_MD5,
@@ -68,6 +70,7 @@
       krb5int_old_crypto_length, krb5int_old_encrypt, krb5int_old_decrypt,
       krb5int_des_string_to_key,
       krb5int_des_prf,
+      krb5int_init_state_enc, krb5int_free_state_enc,
       CKSUMTYPE_RSA_MD5,
       ETYPE_WEAK },
     { ENCTYPE_DES_CBC_RAW,
@@ -77,6 +80,7 @@
       krb5int_raw_crypto_length, krb5int_raw_encrypt, krb5int_raw_decrypt,
       krb5int_des_string_to_key,
       krb5int_des_prf,
+      krb5int_init_state_enc, krb5int_free_state_enc,
       0,
       ETYPE_WEAK },
     { ENCTYPE_DES3_CBC_RAW,
@@ -86,6 +90,7 @@
       krb5int_raw_crypto_length, krb5int_raw_encrypt, krb5int_raw_decrypt,
       krb5int_dk_string_to_key,
       NULL, /*PRF*/
+      krb5int_init_state_enc, krb5int_free_state_enc,
       0,
       ETYPE_WEAK },
 
@@ -97,6 +102,7 @@
       krb5int_dk_crypto_length, krb5int_dk_encrypt, krb5int_dk_decrypt,
       krb5int_dk_string_to_key,
       krb5int_dk_prf,
+      krb5int_init_state_enc, krb5int_free_state_enc,
       CKSUMTYPE_HMAC_SHA1_DES3,
       0 /*flags*/ },
 
@@ -107,6 +113,7 @@
       krb5int_dk_crypto_length, krb5int_dk_encrypt, krb5int_dk_decrypt,
       krb5int_dk_string_to_key,
       NULL, /*PRF*/
+      krb5int_init_state_enc, krb5int_free_state_enc,
       0,
       ETYPE_WEAK },
     { ENCTYPE_ARCFOUR_HMAC,
@@ -118,6 +125,7 @@
       krb5int_arcfour_crypto_length, krb5int_arcfour_encrypt,
       krb5int_arcfour_decrypt, krb5int_arcfour_string_to_key,
       krb5int_arcfour_prf, /*PRF*/
+      krb5int_init_state_enc, krb5int_free_state_enc,
       CKSUMTYPE_HMAC_MD5_ARCFOUR,
       0 /*flags*/ },
     { ENCTYPE_ARCFOUR_HMAC_EXP,
@@ -129,6 +137,7 @@
       krb5int_arcfour_crypto_length, krb5int_arcfour_encrypt,
       krb5int_arcfour_decrypt, krb5int_arcfour_string_to_key,
       krb5int_arcfour_prf, /*PRF*/
+      krb5int_init_state_enc, krb5int_free_state_enc,
       CKSUMTYPE_HMAC_MD5_ARCFOUR,
       ETYPE_WEAK
     },
@@ -141,6 +150,7 @@
       krb5int_aes_crypto_length, krb5int_dk_encrypt, krb5int_dk_decrypt,
       krb5int_aes_string_to_key,
       krb5int_dk_prf,
+      krb5int_init_state_enc, krb5int_free_state_enc,
       CKSUMTYPE_HMAC_SHA1_96_AES128,
       0 /*flags*/ },
     { ENCTYPE_AES256_CTS_HMAC_SHA1_96,
@@ -151,6 +161,7 @@
       krb5int_aes_crypto_length, krb5int_dk_encrypt, krb5int_dk_decrypt,
       krb5int_aes_string_to_key,
       krb5int_dk_prf,
+      krb5int_init_state_enc, krb5int_free_state_enc,
       CKSUMTYPE_HMAC_SHA1_96_AES256,
       0 /*flags*/ },
     { ENCTYPE_CAMELLIA128_CCM_128,
@@ -161,6 +172,7 @@
       krb5int_dk_ccm_crypto_length, krb5int_dk_ccm_encrypt, krb5int_dk_ccm_decrypt,
       krb5int_camellia_ccm_string_to_key,
       krb5int_dk_cmac_prf,
+      krb5int_dk_ccm_init_state, krb5int_dk_ccm_free_state,
       CKSUMTYPE_CMAC_128_CAMELLIA128,
       0 /*flags*/ },
     { ENCTYPE_CAMELLIA256_CCM_128,
@@ -171,6 +183,7 @@
       krb5int_dk_ccm_crypto_length, krb5int_dk_ccm_encrypt, krb5int_dk_ccm_decrypt,
       krb5int_camellia_ccm_string_to_key,
       krb5int_dk_cmac_prf,
+      krb5int_dk_ccm_init_state, krb5int_dk_ccm_free_state,
       CKSUMTYPE_CMAC_128_CAMELLIA256,
       0 /*flags */ },
 };

Modified: branches/camellia-ccm/src/lib/crypto/krb/etypes.h
===================================================================
--- branches/camellia-ccm/src/lib/crypto/krb/etypes.h	2010-08-09 16:30:46 UTC (rev 24235)
+++ branches/camellia-ccm/src/lib/crypto/krb/etypes.h	2010-08-09 18:16:04 UTC (rev 24236)
@@ -52,6 +52,14 @@
                                     krb5_key key,
                                     const krb5_data *in, krb5_data *out);
 
+typedef krb5_error_code (*init_state_func)(const struct krb5_keytypes *ktp,
+                                           const krb5_keyblock *key,
+                                           krb5_keyusage keyusage,
+                                           krb5_data *out_state);
+
+typedef void (*free_state_func)(const struct krb5_keytypes *ktp,
+                                krb5_data *state);
+
 struct krb5_keytypes {
     krb5_enctype etype;
     char *name;
@@ -65,6 +73,8 @@
     crypt_func decrypt;
     str2key_func str2key;
     prf_func prf;
+    init_state_func init_state;
+    free_state_func free_state;
     krb5_cksumtype required_ctype;
     krb5_flags flags;
 };
@@ -109,4 +119,12 @@
         return enc->encrypt(key, 0, &iov, 1);
 }
 
+krb5_error_code
+krb5int_init_state_enc(const struct krb5_keytypes *ktp,
+                       const krb5_keyblock *key, krb5_keyusage keyusage,
+                       krb5_data *out_state);
+
+void
+krb5int_free_state_enc(const struct krb5_keytypes *ktp, krb5_data *state);
+
 #endif

Modified: branches/camellia-ccm/src/lib/crypto/krb/state.c
===================================================================
--- branches/camellia-ccm/src/lib/crypto/krb/state.c	2010-08-09 16:30:46 UTC (rev 24235)
+++ branches/camellia-ccm/src/lib/crypto/krb/state.c	2010-08-09 18:16:04 UTC (rev 24236)
@@ -36,6 +36,22 @@
 #include "k5-int.h"
 #include "etypes.h"
 
+/* Most enctypes delegate cipher state handling to the enc provider by using
+ * this function as their init_state methods. */
+krb5_error_code
+krb5int_init_state_enc(const struct krb5_keytypes *ktp,
+                       const krb5_keyblock *key, krb5_keyusage keyusage,
+                       krb5_data *out_state)
+{
+    return ktp->enc->init_state(key, keyusage, out_state);
+}
+
+void
+krb5int_free_state_enc(const struct krb5_keytypes *ktp, krb5_data *state)
+{
+    (void)ktp->enc->free_state(state);
+}
+
 krb5_error_code KRB5_CALLCONV
 krb5_c_init_state (krb5_context context, const krb5_keyblock *key,
                    krb5_keyusage keyusage, krb5_data *new_state)
@@ -45,7 +61,7 @@
     ktp = find_enctype(key->enctype);
     if (ktp == NULL)
         return KRB5_BAD_ENCTYPE;
-    return ktp->enc->init_state(key, keyusage, new_state);
+    return ktp->init_state(ktp, key, keyusage, new_state);
 }
 
 krb5_error_code KRB5_CALLCONV
@@ -57,5 +73,6 @@
     ktp = find_enctype(key->enctype);
     if (ktp == NULL)
         return KRB5_BAD_ENCTYPE;
-    return ktp->enc->free_state(state);
+    ktp->free_state(ktp, state);
+    return 0;
 }




More information about the cvs-krb5 mailing list