svn rev #22941: branches/enc-perf/src/lib/crypto/openssl/ aes/ arcfour/ enc_provider/
ghudson@MIT.EDU
ghudson at MIT.EDU
Mon Oct 19 15:39:57 EDT 2009
http://src.mit.edu/fisheye/changelog/krb5/?cs=22941
Commit By: ghudson
Log Message:
Respecify OpenSSL back-end internals in terms of krb5_key.
Changed Files:
U branches/enc-perf/src/lib/crypto/openssl/aes/aes_s2k.c
U branches/enc-perf/src/lib/crypto/openssl/arcfour/arcfour.c
U branches/enc-perf/src/lib/crypto/openssl/arcfour/arcfour.h
U branches/enc-perf/src/lib/crypto/openssl/arcfour/arcfour_aead.c
U branches/enc-perf/src/lib/crypto/openssl/enc_provider/aes.c
U branches/enc-perf/src/lib/crypto/openssl/enc_provider/des.c
U branches/enc-perf/src/lib/crypto/openssl/enc_provider/des3.c
U branches/enc-perf/src/lib/crypto/openssl/enc_provider/rc4.c
U branches/enc-perf/src/lib/crypto/openssl/hmac.c
Modified: branches/enc-perf/src/lib/crypto/openssl/aes/aes_s2k.c
===================================================================
--- branches/enc-perf/src/lib/crypto/openssl/aes/aes_s2k.c 2009-10-19 19:15:03 UTC (rev 22940)
+++ branches/enc-perf/src/lib/crypto/openssl/aes/aes_s2k.c 2009-10-19 19:39:57 UTC (rev 22941)
@@ -44,6 +44,7 @@
unsigned long iter_count;
krb5_data out;
static const krb5_data usage = { KV5M_DATA, 8, "kerberos" };
+ krb5_key tempkey = NULL;
krb5_error_code err;
if (params) {
@@ -66,25 +67,25 @@
if (iter_count >= MAX_ITERATION_COUNT)
return KRB5_ERR_BAD_S2K_PARAMS;
- /*
- * Dense key space, no parity bits or anything, so take a shortcut
- * and use the key contents buffer for the generated bytes.
- */
+ /* Use the output keyblock contents for temporary space. */
out.data = (char *) key->contents;
out.length = key->length;
if (out.length != 16 && out.length != 32)
return KRB5_CRYPTO_INTERNAL;
err = krb5int_pbkdf2_hmac_sha1 (&out, iter_count, string, salt);
- if (err) {
- memset(out.data, 0, out.length);
- return err;
- }
+ if (err)
+ goto cleanup;
- err = krb5_derive_key (enc, key, key, &usage);
- if (err) {
- memset(out.data, 0, out.length);
- return err;
- }
- return 0;
+ err = krb5_k_create_key (NULL, key, &tempkey);
+ if (err)
+ goto cleanup;
+
+ err = krb5_derive_keyblock (enc, tempkey, key, &usage);
+
+cleanup:
+ if (err)
+ memset (out.data, 0, out.length);
+ krb5_k_free_key (NULL, tempkey);
+ return err;
}
Modified: branches/enc-perf/src/lib/crypto/openssl/arcfour/arcfour.c
===================================================================
--- branches/enc-perf/src/lib/crypto/openssl/arcfour/arcfour.c 2009-10-19 19:15:03 UTC (rev 22940)
+++ branches/enc-perf/src/lib/crypto/openssl/arcfour/arcfour.c 2009-10-19 19:39:57 UTC (rev 22941)
@@ -65,11 +65,12 @@
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;
@@ -84,7 +85,7 @@
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;
@@ -94,7 +95,7 @@
free(d1.data);
return (ENOMEM);
}
- k2 = *key;
+ k2 = key->keyblock;
k2.length=d2.length;
k2.contents=(void *) d2.data;
@@ -105,7 +106,7 @@
free(d2.data);
return (ENOMEM);
}
- k3 = *key;
+ k3 = key->keyblock;
k3.length=d3.length;
k3.contents= (void *) d3.data;
@@ -141,7 +142,7 @@
/* 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 {
@@ -152,7 +153,7 @@
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);
@@ -160,12 +161,20 @@
if (ret)
goto cleanup;
- krb5_hmac(hash, &k2, 1, &plaintext, &checksum);
+ ret = krb5int_hmac_keyblock(hash, &k2, 1, &plaintext, &checksum);
+ if (ret)
+ goto cleanup;
- krb5_hmac(hash, &k1, 1, &checksum, &d3);
+ ret = krb5int_hmac_keyblock(hash, &k1, 1, &checksum, &d3);
+ if (ret)
+ goto cleanup;
- ret=(*(enc->encrypt))(&k3, ivec, &plaintext, &ciphertext);
+ ret = krb5_k_create_key(NULL, &k3, &k3key);
+ if (ret)
+ goto cleanup;
+ ret=(*(enc->encrypt))(k3key, ivec, &plaintext, &ciphertext);
+
cleanup:
memset(d1.data, 0, d1.length);
memset(d2.data, 0, d2.length);
@@ -185,11 +194,12 @@
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;
@@ -204,7 +214,7 @@
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;
@@ -214,7 +224,7 @@
free(d1.data);
return (ENOMEM);
}
- k2 = *key;
+ k2 = key->keyblock;
k2.length=d2.length;
k2.contents= (void *) d2.data;
@@ -225,7 +235,7 @@
free(d2.data);
return (ENOMEM);
}
- k3 = *key;
+ k3 = key->keyblock;
k3.length=d3.length;
k3.contents= (void *) d3.data;
@@ -258,7 +268,7 @@
/* 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 {
@@ -271,18 +281,22 @@
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;
Modified: branches/enc-perf/src/lib/crypto/openssl/arcfour/arcfour.h
===================================================================
--- branches/enc-perf/src/lib/crypto/openssl/arcfour/arcfour.h 2009-10-19 19:15:03 UTC (rev 22940)
+++ branches/enc-perf/src/lib/crypto/openssl/arcfour/arcfour.h 2009-10-19 19:39:57 UTC (rev 22941)
@@ -10,7 +10,7 @@
extern
krb5_error_code krb5_arcfour_encrypt(const struct krb5_enc_provider *,
const struct krb5_hash_provider *,
- const krb5_keyblock *,
+ krb5_key,
krb5_keyusage,
const krb5_data *,
const krb5_data *,
@@ -19,7 +19,7 @@
extern
krb5_error_code krb5_arcfour_decrypt(const struct krb5_enc_provider *,
const struct krb5_hash_provider *,
- const krb5_keyblock *,
+ krb5_key,
krb5_keyusage,
const krb5_data *,
const krb5_data *,
@@ -34,10 +34,5 @@
extern const struct krb5_enc_provider krb5int_enc_arcfour;
extern const struct krb5_aead_provider krb5int_aead_arcfour;
- krb5_error_code krb5int_arcfour_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 /* ARCFOUR_H */
Modified: branches/enc-perf/src/lib/crypto/openssl/arcfour/arcfour_aead.c
===================================================================
--- branches/enc-perf/src/lib/crypto/openssl/arcfour/arcfour_aead.c 2009-10-19 19:15:03 UTC (rev 22940)
+++ branches/enc-perf/src/lib/crypto/openssl/arcfour/arcfour_aead.c 2009-10-19 19:39:57 UTC (rev 22941)
@@ -82,7 +82,7 @@
krb5int_arcfour_encrypt_iov(const struct krb5_aead_provider *aead,
const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
- const krb5_keyblock *key,
+ krb5_key key,
krb5_keyusage usage,
const krb5_data *ivec,
krb5_crypto_iov *data,
@@ -91,6 +91,7 @@
krb5_error_code ret;
krb5_crypto_iov *header, *trailer;
krb5_keyblock k1, k2, k3;
+ krb5_key k3key = NULL;
krb5_data d1, d2, d3;
krb5_data checksum, confounder, header_data;
krb5_keyusage ms_usage;
@@ -126,15 +127,15 @@
data[i].data.length = 0;
}
- ret = alloc_derived_key(enc, &k1, &d1, key);
+ ret = alloc_derived_key(enc, &k1, &d1, &key->keyblock);
if (ret != 0)
goto cleanup;
- ret = alloc_derived_key(enc, &k2, &d2, key);
+ ret = alloc_derived_key(enc, &k2, &d2, &key->keyblock);
if (ret != 0)
goto cleanup;
- ret = alloc_derived_key(enc, &k3, &d3, key);
+ ret = alloc_derived_key(enc, &k3, &d3, &key->keyblock);
if (ret != 0)
goto cleanup;
@@ -144,7 +145,7 @@
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 {
@@ -157,7 +158,7 @@
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);
header->data.length = hash->hashsize + CONFOUNDERLENGTH;
@@ -176,18 +177,22 @@
header->data.length -= hash->hashsize;
header->data.data += hash->hashsize;
- ret = krb5int_hmac_iov(hash, &k2, data, num_data, &checksum);
+ ret = krb5int_hmac_iov_keyblock(hash, &k2, data, num_data, &checksum);
if (ret != 0)
goto cleanup;
- ret = krb5_hmac(hash, &k1, 1, &checksum, &d3);
+ ret = krb5int_hmac_keyblock(hash, &k1, 1, &checksum, &d3);
if (ret != 0)
goto cleanup;
- ret = enc->encrypt_iov(&k3, ivec, data, num_data);
+ ret = krb5_k_create_key(NULL, &k3, &k3key);
if (ret != 0)
goto cleanup;
+ ret = enc->encrypt_iov(k3key, ivec, data, num_data);
+ if (ret != 0)
+ goto cleanup;
+
cleanup:
header->data = header_data; /* restore header pointers */
@@ -204,6 +209,7 @@
free(d3.data);
}
+ krb5_k_free_key(NULL, k3key);
return ret;
}
@@ -211,7 +217,7 @@
krb5int_arcfour_decrypt_iov(const struct krb5_aead_provider *aead,
const struct krb5_enc_provider *enc,
const struct krb5_hash_provider *hash,
- const krb5_keyblock *key,
+ krb5_key key,
krb5_keyusage usage,
const krb5_data *ivec,
krb5_crypto_iov *data,
@@ -220,6 +226,7 @@
krb5_error_code ret;
krb5_crypto_iov *header, *trailer;
krb5_keyblock k1, k2, k3;
+ krb5_key k3key = NULL;
krb5_data d1, d2, d3;
krb5_data checksum, header_data;
krb5_keyusage ms_usage;
@@ -240,15 +247,15 @@
if (trailer != NULL && trailer->data.length != 0)
return KRB5_BAD_MSIZE;
- ret = alloc_derived_key(enc, &k1, &d1, key);
+ ret = alloc_derived_key(enc, &k1, &d1, &key->keyblock);
if (ret != 0)
goto cleanup;
- ret = alloc_derived_key(enc, &k2, &d2, key);
+ ret = alloc_derived_key(enc, &k2, &d2, &key->keyblock);
if (ret != 0)
goto cleanup;
- ret = alloc_derived_key(enc, &k3, &d3, key);
+ ret = alloc_derived_key(enc, &k3, &d3, &key->keyblock);
if (ret != 0)
goto cleanup;
@@ -258,7 +265,7 @@
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, (unsigned char *)salt.data + 10);
} else {
@@ -271,7 +278,7 @@
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);
checksum.data = header->data.data;
@@ -281,18 +288,22 @@
header->data.length -= hash->hashsize;
header->data.data += hash->hashsize;
- ret = krb5_hmac(hash, &k1, 1, &checksum, &d3);
+ ret = krb5int_hmac_keyblock(hash, &k1, 1, &checksum, &d3);
if (ret != 0)
goto cleanup;
- ret = enc->decrypt_iov(&k3, ivec, data, num_data);
+ ret = krb5_k_create_key(NULL, &k3, &k3key);
if (ret != 0)
goto cleanup;
- ret = krb5int_hmac_iov(hash, &k2, data, num_data, &d1);
+ ret = enc->decrypt_iov(k3key, ivec, data, num_data);
if (ret != 0)
goto cleanup;
+ ret = krb5int_hmac_iov_keyblock(hash, &k2, data, num_data, &d1);
+ if (ret != 0)
+ goto cleanup;
+
if (memcmp(checksum.data, d1.data, hash->hashsize) != 0) {
ret = KRB5KRB_AP_ERR_BAD_INTEGRITY;
goto cleanup;
@@ -314,6 +325,7 @@
free(d3.data);
}
+ krb5_k_free_key(NULL, k3key);
return ret;
}
Modified: branches/enc-perf/src/lib/crypto/openssl/enc_provider/aes.c
===================================================================
--- branches/enc-perf/src/lib/crypto/openssl/enc_provider/aes.c 2009-10-19 19:15:03 UTC (rev 22940)
+++ branches/enc-perf/src/lib/crypto/openssl/enc_provider/aes.c 2009-10-19 19:39:57 UTC (rev 22941)
@@ -36,22 +36,22 @@
/* proto's */
static krb5_error_code
-cts_enc(const krb5_keyblock *key, const krb5_data *ivec,
+cts_enc(krb5_key key, const krb5_data *ivec,
const krb5_data *input, krb5_data *output);
static krb5_error_code
-cbc_enc(const krb5_keyblock *key, const krb5_data *ivec,
+cbc_enc(krb5_key key, const krb5_data *ivec,
const krb5_data *input, krb5_data *output);
static krb5_error_code
-cts_decr(const krb5_keyblock *key, const krb5_data *ivec,
+cts_decr(krb5_key key, const krb5_data *ivec,
const krb5_data *input, krb5_data *output);
static krb5_error_code
-cbc_decr(const krb5_keyblock *key, const krb5_data *ivec,
+cbc_decr(krb5_key key, const krb5_data *ivec,
const krb5_data *input, krb5_data *output);
static krb5_error_code
-cts_encr_iov(const krb5_keyblock *key, const krb5_data *ivec,
+cts_encr_iov(krb5_key key, const krb5_data *ivec,
krb5_crypto_iov *data, size_t num_data, size_t dlen);
static krb5_error_code
-cts_decr_iov(const krb5_keyblock *key, const krb5_data *ivec,
+cts_decr_iov(krb5_key key, const krb5_data *ivec,
krb5_crypto_iov *data, size_t num_data, size_t dlen);
#define NUM_BITS 8
@@ -69,7 +69,7 @@
}
static krb5_error_code
-cbc_enc(const krb5_keyblock *key, const krb5_data *ivec,
+cbc_enc(krb5_key key, const krb5_data *ivec,
const krb5_data *input, krb5_data *output)
{
int ret = 0, tmp_len = 0;
@@ -77,7 +77,7 @@
unsigned char *tmp_buf = NULL;
EVP_CIPHER_CTX ciph_ctx;
- key_buf = OPENSSL_malloc(key->length);
+ key_buf = OPENSSL_malloc(key->keyblock.length);
if (!key_buf)
return ENOMEM;
@@ -87,11 +87,11 @@
OPENSSL_free(key_buf);
return ENOMEM;
}
- memcpy(key_buf, key->contents, key->length);
+ memcpy(key_buf, key->keyblock.contents, key->keyblock.length);
EVP_CIPHER_CTX_init(&ciph_ctx);
- ret = EVP_EncryptInit_ex(&ciph_ctx, map_mode(key->length),
+ ret = EVP_EncryptInit_ex(&ciph_ctx, map_mode(key->keyblock.length),
NULL, key_buf, (ivec) ? (unsigned char*)ivec->data : NULL);
if (ret == 1){
@@ -112,7 +112,7 @@
ret = KRB5_CRYPTO_INTERNAL;
}
- memset(key_buf, 0, key->length);
+ memset(key_buf, 0, key->keyblock.length);
memset(tmp_buf, 0, input->length);
OPENSSL_free(key_buf);
OPENSSL_free(tmp_buf);
@@ -121,7 +121,7 @@
}
static krb5_error_code
-cbc_decr(const krb5_keyblock *key, const krb5_data *ivec,
+cbc_decr(krb5_key key, const krb5_data *ivec,
const krb5_data *input, krb5_data *output)
{
int ret = 0, tmp_len = 0;
@@ -129,7 +129,7 @@
unsigned char *tmp_buf = NULL;
EVP_CIPHER_CTX ciph_ctx;
- key_buf = OPENSSL_malloc(key->length);
+ key_buf = OPENSSL_malloc(key->keyblock.length);
if (!key_buf)
return ENOMEM;
@@ -139,11 +139,11 @@
OPENSSL_free(key_buf);
return ENOMEM;
}
- memcpy(key_buf, key->contents, key->length);
+ memcpy(key_buf, key->keyblock.contents, key->keyblock.length);
EVP_CIPHER_CTX_init(&ciph_ctx);
- ret = EVP_DecryptInit_ex(&ciph_ctx, map_mode(key->length),
+ ret = EVP_DecryptInit_ex(&ciph_ctx, map_mode(key->keyblock.length),
NULL, key_buf, (ivec) ? (unsigned char*)ivec->data : NULL);
if (ret == 1) {
EVP_CIPHER_CTX_set_padding(&ciph_ctx,0);
@@ -164,7 +164,7 @@
ret = KRB5_CRYPTO_INTERNAL;
}
- memset(key_buf, 0, key->length);
+ memset(key_buf, 0, key->keyblock.length);
memset(tmp_buf, 0, input->length);
OPENSSL_free(key_buf);
OPENSSL_free(tmp_buf);
@@ -173,7 +173,7 @@
}
static krb5_error_code
-cts_enc(const krb5_keyblock *key, const krb5_data *ivec,
+cts_enc(krb5_key key, const krb5_data *ivec,
const krb5_data *input, krb5_data *output)
{
int ret = 0, tmp_len = 0;
@@ -194,7 +194,8 @@
return ENOMEM;
tmp_len = input->length;
- AES_set_encrypt_key(key->contents, NUM_BITS * key->length, &enck);
+ AES_set_encrypt_key(key->keyblock.contents,
+ NUM_BITS * key->keyblock.length, &enck);
size = CRYPTO_cts128_encrypt((unsigned char *)input->data, tmp_buf,
input->length, &enck,
@@ -217,7 +218,7 @@
}
static krb5_error_code
-cts_decr(const krb5_keyblock *key, const krb5_data *ivec,
+cts_decr(krb5_key key, const krb5_data *ivec,
const krb5_data *input, krb5_data *output)
{
int ret = 0, tmp_len = 0;
@@ -238,7 +239,8 @@
return ENOMEM;
tmp_len = input->length;
- AES_set_decrypt_key(key->contents, NUM_BITS * key->length, &deck);
+ AES_set_decrypt_key(key->keyblock.contents,
+ NUM_BITS * key->keyblock.length, &deck);
size = CRYPTO_cts128_decrypt((unsigned char *)input->data, tmp_buf,
input->length, &deck,
@@ -261,7 +263,7 @@
}
static krb5_error_code
-cts_encr_iov(const krb5_keyblock *key,
+cts_encr_iov(krb5_key key,
const krb5_data *ivec,
krb5_crypto_iov *data,
size_t num_data, size_t dlen)
@@ -313,7 +315,8 @@
if (tlen > dlen) break;
}
- AES_set_encrypt_key(key->contents, NUM_BITS * key->length, &enck);
+ AES_set_encrypt_key(key->keyblock.contents,
+ NUM_BITS * key->keyblock.length, &enck);
size = CRYPTO_cts128_encrypt((unsigned char *)dbuf, oblock, dlen, &enck,
iv_cts, (cbc128_f)AES_cbc_encrypt);
@@ -336,7 +339,7 @@
}
static krb5_error_code
-cts_decr_iov(const krb5_keyblock *key,
+cts_decr_iov(krb5_key key,
const krb5_data *ivec,
krb5_crypto_iov *data,
size_t num_data, size_t dlen)
@@ -373,7 +376,8 @@
memset(oblock, 0, oblock_len);
memset(dbuf, 0, dlen);
- AES_set_decrypt_key(key->contents, NUM_BITS * key->length, &deck);
+ AES_set_decrypt_key(key->keyblock.contents,
+ NUM_BITS * key->keyblock.length, &deck);
tlen = 0;
for (;;) {
@@ -411,7 +415,7 @@
}
krb5_error_code
-krb5int_aes_encrypt(const krb5_keyblock *key, const krb5_data *ivec,
+krb5int_aes_encrypt(krb5_key key, const krb5_data *ivec,
const krb5_data *input, krb5_data *output)
{
int ret = 0;
@@ -426,7 +430,7 @@
}
krb5_error_code
-krb5int_aes_decrypt(const krb5_keyblock *key, const krb5_data *ivec,
+krb5int_aes_decrypt(krb5_key key, const krb5_data *ivec,
const krb5_data *input, krb5_data *output)
{
int ret = 0;
@@ -445,7 +449,7 @@
}
static krb5_error_code
-krb5int_aes_encrypt_iov(const krb5_keyblock *key,
+krb5int_aes_encrypt_iov(krb5_key key,
const krb5_data *ivec,
krb5_crypto_iov *data,
size_t num_data)
@@ -470,7 +474,7 @@
}
static krb5_error_code
-krb5int_aes_decrypt_iov(const krb5_keyblock *key,
+krb5int_aes_decrypt_iov(krb5_key key,
const krb5_data *ivec,
krb5_crypto_iov *data,
size_t num_data)
Modified: branches/enc-perf/src/lib/crypto/openssl/enc_provider/des.c
===================================================================
--- branches/enc-perf/src/lib/crypto/openssl/enc_provider/des.c 2009-10-19 19:15:03 UTC (rev 22940)
+++ branches/enc-perf/src/lib/crypto/openssl/enc_provider/des.c 2009-10-19 19:39:57 UTC (rev 22941)
@@ -11,11 +11,11 @@
#define DES_KEY_BYTES 7
static krb5_error_code
-validate(const krb5_keyblock *key, const krb5_data *ivec,
+validate(krb5_key key, const krb5_data *ivec,
const krb5_data *input, const krb5_data *output)
{
- /* key->enctype was checked by the caller */
- if (key->length != KRB5_MIT_DES_KEYSIZE)
+ /* key->keyblock.enctype was checked by the caller */
+ if (key->keyblock.length != KRB5_MIT_DES_KEYSIZE)
return(KRB5_BAD_KEYSIZE);
if ((input->length%8) != 0)
return(KRB5_BAD_MSIZE);
@@ -28,7 +28,7 @@
}
static krb5_error_code
-validate_iov(const krb5_keyblock *key, const krb5_data *ivec,
+validate_iov(krb5_key key, const krb5_data *ivec,
const krb5_crypto_iov *data, size_t num_data)
{
size_t i, input_length;
@@ -39,7 +39,7 @@
input_length += iov->data.length;
}
- if (key->length != KRB5_MIT_DES3_KEYSIZE)
+ if (key->keyblock.length != KRB5_MIT_DES3_KEYSIZE)
return(KRB5_BAD_KEYSIZE);
if ((input_length%DES_BLOCK_SIZE) != 0)
return(KRB5_BAD_MSIZE);
@@ -50,7 +50,7 @@
}
static krb5_error_code
-k5_des_encrypt(const krb5_keyblock *key, const krb5_data *ivec,
+k5_des_encrypt(krb5_key key, const krb5_data *ivec,
const krb5_data *input, krb5_data *output)
{
int ret = 0, tmp_len = 0;
@@ -63,8 +63,8 @@
if (ret)
return ret;
- keybuf=key->contents;
- keybuf[key->length] = '\0';
+ keybuf=key->keyblock.contents;
+ keybuf[key->keyblock.length] = '\0';
tmp_buf_len = output->length*2;
tmp_buf=OPENSSL_malloc(tmp_buf_len);
@@ -103,10 +103,10 @@
static krb5_error_code
-k5_des_decrypt(const krb5_keyblock *key, const krb5_data *ivec,
+k5_des_decrypt(krb5_key key, const krb5_data *ivec,
const krb5_data *input, krb5_data *output)
{
- /* key->enctype was checked by the caller */
+ /* key->keyblock.enctype was checked by the caller */
int ret = 0, tmp_len = 0;
unsigned char *keybuf = NULL;
unsigned char *tmp_buf;
@@ -116,8 +116,8 @@
if (ret)
return ret;
- keybuf=key->contents;
- keybuf[key->length] = '\0';
+ keybuf=key->keyblock.contents;
+ keybuf[key->keyblock.length] = '\0';
tmp_buf=OPENSSL_malloc(output->length);
if (!tmp_buf)
@@ -152,7 +152,7 @@
}
static krb5_error_code
-k5_des_encrypt_iov(const krb5_keyblock *key,
+k5_des_encrypt_iov(krb5_key key,
const krb5_data *ivec,
krb5_crypto_iov *data,
size_t num_data)
@@ -176,8 +176,8 @@
IOV_BLOCK_STATE_INIT(&input_pos);
IOV_BLOCK_STATE_INIT(&output_pos);
- keybuf=key->contents;
- keybuf[key->length] = '\0';
+ keybuf=key->keyblock.contents;
+ keybuf[key->keyblock.length] = '\0';
ret = validate_iov(key, ivec, data, num_data);
if (ret)
@@ -229,7 +229,7 @@
}
static krb5_error_code
-k5_des_decrypt_iov(const krb5_keyblock *key,
+k5_des_decrypt_iov(krb5_key key,
const krb5_data *ivec,
krb5_crypto_iov *data,
size_t num_data)
@@ -254,8 +254,8 @@
IOV_BLOCK_STATE_INIT(&input_pos);
IOV_BLOCK_STATE_INIT(&output_pos);
- keybuf=key->contents;
- keybuf[key->length] = '\0';
+ keybuf=key->keyblock.contents;
+ keybuf[key->keyblock.length] = '\0';
ret = validate_iov(key, ivec, data, num_data);
if (ret)
Modified: branches/enc-perf/src/lib/crypto/openssl/enc_provider/des3.c
===================================================================
--- branches/enc-perf/src/lib/crypto/openssl/enc_provider/des3.c 2009-10-19 19:15:03 UTC (rev 22940)
+++ branches/enc-perf/src/lib/crypto/openssl/enc_provider/des3.c 2009-10-19 19:39:57 UTC (rev 22941)
@@ -11,12 +11,12 @@
#define DES_BLOCK_SIZE 8
static krb5_error_code
-validate(const krb5_keyblock *key, const krb5_data *ivec,
+validate(krb5_key key, const krb5_data *ivec,
const krb5_data *input, const krb5_data *output)
{
- /* key->enctype was checked by the caller */
+ /* key->keyblock.enctype was checked by the caller */
- if (key->length != KRB5_MIT_DES3_KEYSIZE)
+ if (key->keyblock.length != KRB5_MIT_DES3_KEYSIZE)
return(KRB5_BAD_KEYSIZE);
if ((input->length%DES_BLOCK_SIZE) != 0)
return(KRB5_BAD_MSIZE);
@@ -29,7 +29,7 @@
}
static krb5_error_code
-validate_iov(const krb5_keyblock *key, const krb5_data *ivec,
+validate_iov(krb5_key key, const krb5_data *ivec,
const krb5_crypto_iov *data, size_t num_data)
{
size_t i, input_length;
@@ -40,7 +40,7 @@
input_length += iov->data.length;
}
- if (key->length != KRB5_MIT_DES3_KEYSIZE)
+ if (key->keyblock.length != KRB5_MIT_DES3_KEYSIZE)
return(KRB5_BAD_KEYSIZE);
if ((input_length%DES_BLOCK_SIZE) != 0)
return(KRB5_BAD_MSIZE);
@@ -51,7 +51,7 @@
}
static krb5_error_code
-k5_des3_encrypt(const krb5_keyblock *key, const krb5_data *ivec,
+k5_des3_encrypt(krb5_key key, const krb5_data *ivec,
const krb5_data *input, krb5_data *output)
{
int ret = 0, tmp_len = 0;
@@ -64,8 +64,8 @@
if (ret)
return ret;
- keybuf=key->contents;
- keybuf[key->length] = '\0';
+ keybuf=key->keyblock.contents;
+ keybuf[key->keyblock.length] = '\0';
tmp_buf_len = output->length * 2;
tmp_buf = OPENSSL_malloc(tmp_buf_len);
@@ -104,7 +104,7 @@
}
static krb5_error_code
-k5_des3_decrypt(const krb5_keyblock *key, const krb5_data *ivec,
+k5_des3_decrypt(krb5_key key, const krb5_data *ivec,
const krb5_data *input, krb5_data *output)
{
int ret = 0, tmp_len = 0;
@@ -117,8 +117,8 @@
if (ret)
return ret;
- keybuf=key->contents;
- keybuf[key->length] = '\0';
+ keybuf=key->keyblock.contents;
+ keybuf[key->keyblock.length] = '\0';
tmp_buf_len = output->length;
tmp_buf=OPENSSL_malloc(tmp_buf_len);
@@ -156,7 +156,7 @@
}
static krb5_error_code
-k5_des3_encrypt_iov(const krb5_keyblock *key,
+k5_des3_encrypt_iov(krb5_key key,
const krb5_data *ivec,
krb5_crypto_iov *data,
size_t num_data)
@@ -185,8 +185,8 @@
IOV_BLOCK_STATE_INIT(&input_pos);
IOV_BLOCK_STATE_INIT(&output_pos);
- keybuf=key->contents;
- keybuf[key->length] = '\0';
+ keybuf=key->keyblock.contents;
+ keybuf[key->keyblock.length] = '\0';
memset(oblock, 0, oblock_len);
@@ -236,7 +236,7 @@
}
static krb5_error_code
-k5_des3_decrypt_iov(const krb5_keyblock *key,
+k5_des3_decrypt_iov(krb5_key key,
const krb5_data *ivec,
krb5_crypto_iov *data,
size_t num_data)
@@ -265,8 +265,8 @@
IOV_BLOCK_STATE_INIT(&input_pos);
IOV_BLOCK_STATE_INIT(&output_pos);
- keybuf=key->contents;
- keybuf[key->length] = '\0';
+ keybuf=key->keyblock.contents;
+ keybuf[key->keyblock.length] = '\0';
memset(oblock, 0, oblock_len);
Modified: branches/enc-perf/src/lib/crypto/openssl/enc_provider/rc4.c
===================================================================
--- branches/enc-perf/src/lib/crypto/openssl/enc_provider/rc4.c 2009-10-19 19:15:03 UTC (rev 22940)
+++ branches/enc-perf/src/lib/crypto/openssl/enc_provider/rc4.c 2009-10-19 19:39:57 UTC (rev 22941)
@@ -15,7 +15,7 @@
/* prototypes */
static krb5_error_code
-k5_arcfour_docrypt(const krb5_keyblock *, const krb5_data *,
+k5_arcfour_docrypt(krb5_key, const krb5_data *,
const krb5_data *, krb5_data *);
static krb5_error_code
k5_arcfour_free_state ( krb5_data *state);
@@ -29,7 +29,7 @@
/* In-place rc4 crypto */
static krb5_error_code
-k5_arcfour_docrypt(const krb5_keyblock *key, const krb5_data *state,
+k5_arcfour_docrypt(krb5_key key, const krb5_data *state,
const krb5_data *input, krb5_data *output)
{
int ret = 0, tmp_len = 0;
@@ -37,14 +37,14 @@
unsigned char *tmp_buf = NULL;
EVP_CIPHER_CTX ciph_ctx;
- if (key->length != RC4_KEY_SIZE)
+ if (key->keyblock.length != RC4_KEY_SIZE)
return(KRB5_BAD_KEYSIZE);
if (input->length != output->length)
return(KRB5_BAD_MSIZE);
- keybuf=key->contents;
- keybuf[key->length] = '\0';
+ keybuf=key->keyblock.contents;
+ keybuf[key->keyblock.length] = '\0';
EVP_CIPHER_CTX_init(&ciph_ctx);
@@ -72,7 +72,7 @@
/* In-place IOV crypto */
static krb5_error_code
-k5_arcfour_docrypt_iov(const krb5_keyblock *key,
+k5_arcfour_docrypt_iov(krb5_key key,
const krb5_data *state,
krb5_crypto_iov *data,
size_t num_data)
@@ -84,8 +84,8 @@
krb5_crypto_iov *iov = NULL;
EVP_CIPHER_CTX ciph_ctx;
- keybuf=key->contents;
- keybuf[key->length] = '\0';
+ keybuf=key->keyblock.contents;
+ keybuf[key->keyblock.length] = '\0';
EVP_CIPHER_CTX_init(&ciph_ctx);
Modified: branches/enc-perf/src/lib/crypto/openssl/hmac.c
===================================================================
--- branches/enc-perf/src/lib/crypto/openssl/hmac.c 2009-10-19 19:15:03 UTC (rev 22940)
+++ branches/enc-perf/src/lib/crypto/openssl/hmac.c 2009-10-19 19:39:57 UTC (rev 22941)
@@ -32,8 +32,9 @@
}
krb5_error_code
-krb5_hmac(const struct krb5_hash_provider *hash, const krb5_keyblock *key,
- unsigned int icount, const krb5_data *input, krb5_data *output)
+krb5int_hmac_keyblock(const struct krb5_hash_provider *hash,
+ const krb5_keyblock *key, unsigned int icount,
+ const krb5_data *input, krb5_data *output)
{
unsigned int i = 0, md_len = 0;
unsigned char md[EVP_MAX_MD_SIZE];
@@ -72,8 +73,10 @@
}
krb5_error_code
-krb5int_hmac_iov(const struct krb5_hash_provider *hash, const krb5_keyblock *key,
- const krb5_crypto_iov *data, size_t num_data, krb5_data *output)
+krb5int_hmac_iov_keyblock(const struct krb5_hash_provider *hash,
+ const krb5_keyblock *key,
+ const krb5_crypto_iov *data, size_t num_data,
+ krb5_data *output)
{
krb5_data *sign_data;
size_t num_sign_data;
@@ -101,10 +104,25 @@
}
/* caller must store checksum in iov as it may be TYPE_TRAILER or TYPE_CHECKSUM */
- ret = krb5_hmac(hash, key, num_sign_data, sign_data, output);
+ ret = krb5int_hmac_keyblock(hash, key, num_sign_data, sign_data, output);
free(sign_data);
return ret;
}
+krb5_error_code
+krb5_hmac(const struct krb5_hash_provider *hash, krb5_key key,
+ unsigned int icount, const krb5_data *input, krb5_data *output)
+{
+ return krb5int_hmac_keyblock(hash, &key->keyblock, icount, input, output);
+}
+
+krb5_error_code
+krb5int_hmac_iov(const struct krb5_hash_provider *hash, krb5_key key,
+ const krb5_crypto_iov *data, size_t num_data,
+ krb5_data *output)
+{
+ return krb5int_hmac_iov_keyblock(hash, &key->keyblock, data, num_data,
+ output);
+}
More information about the cvs-krb5
mailing list