diff options
| author | Greg Hudson <ghudson@mit.edu> | 2009-10-19 20:04:21 +0000 |
|---|---|---|
| committer | Greg Hudson <ghudson@mit.edu> | 2009-10-19 20:04:21 +0000 |
| commit | e6b93b7dd43bb765900b2db71641479b597844da (patch) | |
| tree | 2b6da09e37da6ca699a8cb43c87e8a4218132254 /src/lib/crypto/builtin/arcfour/arcfour.c | |
| parent | 04a5d19e61bedbb1da4db52334c00f7a54a9d5a8 (diff) | |
| download | krb5-e6b93b7dd43bb765900b2db71641479b597844da.tar.gz krb5-e6b93b7dd43bb765900b2db71641479b597844da.tar.xz krb5-e6b93b7dd43bb765900b2db71641479b597844da.zip | |
Implement new APIs to allow improved crypto performance
Merge branches/enc-perf to trunk. Adds the krb5_key opaque type, the
krb5_k_* APIs to use them, and caching of derived keys when krb5_k_*
functions are used. Updates the krb5 auth context and GSS id-rec to
use krb5_keys.
ticket: 6576
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@22944 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/crypto/builtin/arcfour/arcfour.c')
| -rw-r--r-- | src/lib/crypto/builtin/arcfour/arcfour.c | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/src/lib/crypto/builtin/arcfour/arcfour.c b/src/lib/crypto/builtin/arcfour/arcfour.c index e5cdfdc8c..150a7aa06 100644 --- a/src/lib/crypto/builtin/arcfour/arcfour.c +++ b/src/lib/crypto/builtin/arcfour/arcfour.c @@ -64,11 +64,12 @@ case 7: /* tgs-req authenticator */ krb5_error_code krb5_arcfour_encrypt(const struct krb5_enc_provider *enc, const struct krb5_hash_provider *hash, - const krb5_keyblock *key, krb5_keyusage usage, + krb5_key key, krb5_keyusage usage, const krb5_data *ivec, const krb5_data *input, krb5_data *output) { krb5_keyblock k1, k2, k3; + krb5_key k3key = NULL; krb5_data d1, d2, d3, salt, plaintext, checksum, ciphertext, confounder; krb5_keyusage ms_usage; size_t keylength, keybytes, blocksize, hashsize; @@ -83,7 +84,7 @@ krb5_arcfour_encrypt(const struct krb5_enc_provider *enc, d1.data=malloc(d1.length); if (d1.data == NULL) return (ENOMEM); - k1 = *key; + k1 = key->keyblock; k1.length=d1.length; k1.contents= (void *) d1.data; @@ -93,7 +94,7 @@ krb5_arcfour_encrypt(const struct krb5_enc_provider *enc, free(d1.data); return (ENOMEM); } - k2 = *key; + k2 = key->keyblock; k2.length=d2.length; k2.contents=(void *) d2.data; @@ -104,7 +105,7 @@ krb5_arcfour_encrypt(const struct krb5_enc_provider *enc, free(d2.data); return (ENOMEM); } - k3 = *key; + k3 = key->keyblock; k3.length=d3.length; k3.contents= (void *) d3.data; @@ -140,7 +141,7 @@ krb5_arcfour_encrypt(const struct krb5_enc_provider *enc, /* begin the encryption, computer K1 */ ms_usage=krb5int_arcfour_translate_usage(usage); - if (key->enctype == ENCTYPE_ARCFOUR_HMAC_EXP) { + if (key->keyblock.enctype == ENCTYPE_ARCFOUR_HMAC_EXP) { strncpy(salt.data, krb5int_arcfour_l40, salt.length); store_32_le(ms_usage, salt.data+10); } else { @@ -151,7 +152,7 @@ krb5_arcfour_encrypt(const struct krb5_enc_provider *enc, memcpy(k2.contents, k1.contents, k2.length); - if (key->enctype==ENCTYPE_ARCFOUR_HMAC_EXP) + if (key->keyblock.enctype==ENCTYPE_ARCFOUR_HMAC_EXP) memset(k1.contents+7, 0xab, 9); ret=krb5_c_random_make_octets(/* XXX */ 0, &confounder); @@ -159,11 +160,19 @@ krb5_arcfour_encrypt(const struct krb5_enc_provider *enc, if (ret) goto cleanup; - krb5_hmac(hash, &k2, 1, &plaintext, &checksum); + ret = krb5int_hmac_keyblock(hash, &k2, 1, &plaintext, &checksum); + if (ret) + goto cleanup; + + ret = krb5int_hmac_keyblock(hash, &k1, 1, &checksum, &d3); + if (ret) + goto cleanup; - krb5_hmac(hash, &k1, 1, &checksum, &d3); + ret = krb5_k_create_key(NULL, &k3, &k3key); + if (ret) + goto cleanup; - ret=(*(enc->encrypt))(&k3, ivec, &plaintext, &ciphertext); + ret=(*(enc->encrypt))(k3key, ivec, &plaintext, &ciphertext); cleanup: memset(d1.data, 0, d1.length); @@ -184,11 +193,12 @@ krb5_arcfour_encrypt(const struct krb5_enc_provider *enc, krb5_error_code krb5_arcfour_decrypt(const struct krb5_enc_provider *enc, const struct krb5_hash_provider *hash, - const krb5_keyblock *key, krb5_keyusage usage, + krb5_key key, krb5_keyusage usage, const krb5_data *ivec, const krb5_data *input, krb5_data *output) { krb5_keyblock k1,k2,k3; + krb5_key k3key; krb5_data d1,d2,d3,salt,ciphertext,plaintext,checksum; krb5_keyusage ms_usage; size_t keybytes, keylength, hashsize, blocksize; @@ -203,7 +213,7 @@ krb5_arcfour_decrypt(const struct krb5_enc_provider *enc, d1.data=malloc(d1.length); if (d1.data == NULL) return (ENOMEM); - k1 = *key; + k1 = key->keyblock; k1.length=d1.length; k1.contents= (void *) d1.data; @@ -213,7 +223,7 @@ krb5_arcfour_decrypt(const struct krb5_enc_provider *enc, free(d1.data); return (ENOMEM); } - k2 = *key; + k2 = key->keyblock; k2.length=d2.length; k2.contents= (void *) d2.data; @@ -224,7 +234,7 @@ krb5_arcfour_decrypt(const struct krb5_enc_provider *enc, free(d2.data); return (ENOMEM); } - k3 = *key; + k3 = key->keyblock; k3.length=d3.length; k3.contents= (void *) d3.data; @@ -257,7 +267,7 @@ krb5_arcfour_decrypt(const struct krb5_enc_provider *enc, /* We may have to try two ms_usage values; see below. */ do { /* compute the salt */ - if (key->enctype == ENCTYPE_ARCFOUR_HMAC_EXP) { + if (key->keyblock.enctype == ENCTYPE_ARCFOUR_HMAC_EXP) { strncpy(salt.data, krb5int_arcfour_l40, salt.length); store_32_le(ms_usage, salt.data + 10); } else { @@ -270,18 +280,22 @@ krb5_arcfour_decrypt(const struct krb5_enc_provider *enc, memcpy(k2.contents, k1.contents, k2.length); - if (key->enctype == ENCTYPE_ARCFOUR_HMAC_EXP) + if (key->keyblock.enctype == ENCTYPE_ARCFOUR_HMAC_EXP) memset(k1.contents + 7, 0xab, 9); - ret = krb5_hmac(hash, &k1, 1, &checksum, &d3); + ret = krb5int_hmac_keyblock(hash, &k1, 1, &checksum, &d3); if (ret) goto cleanup; - ret = (*(enc->decrypt))(&k3, ivec, &ciphertext, &plaintext); + ret = krb5_k_create_key(NULL, &k3, &k3key); + if (ret) + goto cleanup; + ret = (*(enc->decrypt))(k3key, ivec, &ciphertext, &plaintext); + krb5_k_free_key(NULL, k3key); if (ret) goto cleanup; - ret = krb5_hmac(hash, &k2, 1, &plaintext, &d1); + ret = krb5int_hmac_keyblock(hash, &k2, 1, &plaintext, &d1); if (ret) goto cleanup; |
