krb5: Store a digest context in the crypto structure
Creating and destroying an EVP_CTX_MD structure with every hash operation is very expensive. Speed things up by caching one within the krb5_crypto structure. krb5_crypto can already only be safely used by one thread at a time - adding a message digest context here shouldn't introduce any further threading risks. Users of the stashed context must be careful to ensure that they call no other hash functions whilst they are in the middle of using the context.
This commit is contained in:

committed by
Jeffrey Altman

parent
fa1e998b53
commit
e50faea7f0
@@ -85,6 +85,7 @@ time_hmac_evp(krb5_context context, size_t size, int iterations)
|
||||
struct _krb5_key_data kd;
|
||||
krb5_error_code ret;
|
||||
krb5_keyblock key;
|
||||
krb5_crypto crypto;
|
||||
char sha1_data[20];
|
||||
Checksum result;
|
||||
char *buf;
|
||||
@@ -110,9 +111,14 @@ time_hmac_evp(krb5_context context, size_t size, int iterations)
|
||||
kd.key = &key;
|
||||
kd.schedule = NULL;
|
||||
|
||||
ret = krb5_crypto_init(context, &key, ETYPE_AES128_CTS_HMAC_SHA1_96,
|
||||
&crypto);
|
||||
if (ret)
|
||||
krb5_err(context, 1, ret, "krb5_crypto_init");
|
||||
|
||||
for (i = 0; i < iterations; i++) {
|
||||
ret = _krb5_SP_HMAC_SHA1_checksum(context, &kd, 0,
|
||||
&iov, 1, &result);
|
||||
ret = _krb5_SP_HMAC_SHA1_checksum(context, crypto, &kd, 0,
|
||||
&iov, 1, &result);
|
||||
if (ret)
|
||||
krb5_err(context, 1, ret, "hmac: %d", i);
|
||||
}
|
||||
@@ -413,7 +419,7 @@ test_rfc2202(krb5_context context)
|
||||
iov.flags = KRB5_CRYPTO_TYPE_DATA;
|
||||
kd.key = &keyblock;
|
||||
kd.schedule = NULL;
|
||||
code = _krb5_SP_HMAC_SHA1_checksum(context, &kd, 0,
|
||||
code = _krb5_SP_HMAC_SHA1_checksum(context, NULL, &kd, 0,
|
||||
&iov, 1, &result);
|
||||
|
||||
if (code != 0)
|
||||
|
Reference in New Issue
Block a user