summaryrefslogtreecommitdiffstats
path: root/src/lib/crypto
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2013-02-09 00:43:35 -0500
committerGreg Hudson <ghudson@mit.edu>2013-02-09 00:43:35 -0500
commit7905cd6a2eddbf264242bb2a85f811878b2da7ab (patch)
tree72b4028cbe0e399e1d293e2b718530913f0a2673 /src/lib/crypto
parent92e2bac0f38f7f60a8fc74b5964357212c4289e1 (diff)
downloadkrb5-7905cd6a2eddbf264242bb2a85f811878b2da7ab.tar.gz
krb5-7905cd6a2eddbf264242bb2a85f811878b2da7ab.tar.xz
krb5-7905cd6a2eddbf264242bb2a85f811878b2da7ab.zip
Add and use k5memdup, k5memdup0 helpers
Add k5-int.h static functions to duplicate byte ranges, optionally with a trailing zero byte, and set an error code like k5alloc does. Use them where they would shorten existing code.
Diffstat (limited to 'src/lib/crypto')
-rw-r--r--src/lib/crypto/krb/checksum_confounder.c9
-rw-r--r--src/lib/crypto/krb/derive.c3
-rw-r--r--src/lib/crypto/krb/enc_old.c3
3 files changed, 6 insertions, 9 deletions
diff --git a/src/lib/crypto/krb/checksum_confounder.c b/src/lib/crypto/krb/checksum_confounder.c
index 116b3c7ff0..afc473bfe3 100644
--- a/src/lib/crypto/krb/checksum_confounder.c
+++ b/src/lib/crypto/krb/checksum_confounder.c
@@ -41,10 +41,10 @@ mk_xorkey(krb5_key origkey, krb5_key *xorkey)
krb5_keyblock xorkeyblock;
size_t i = 0;
- xorbytes = malloc(origkey->keyblock.length);
+ xorbytes = k5memdup(origkey->keyblock.contents, origkey->keyblock.length,
+ &retval);
if (xorbytes == NULL)
- return ENOMEM;
- memcpy(xorbytes, origkey->keyblock.contents, origkey->keyblock.length);
+ return retval;
for (i = 0; i < origkey->keyblock.length; i++)
xorbytes[i] ^= 0xf0;
@@ -118,7 +118,7 @@ krb5_error_code krb5int_confounder_verify(const struct krb5_cksumtypes *ctp,
krb5_crypto_iov *hash_iov = NULL, iov;
size_t blocksize = ctp->enc->block_size, hashsize = ctp->hash->hashsize;
- plaintext = k5alloc(input->length, &ret);
+ plaintext = k5memdup(input->data, input->length, &ret);
if (plaintext == NULL)
return ret;
@@ -129,7 +129,6 @@ krb5_error_code krb5int_confounder_verify(const struct krb5_cksumtypes *ctp,
/* Decrypt the input checksum. */
iov.flags = KRB5_CRYPTO_TYPE_DATA;
iov.data = make_data(plaintext, input->length);
- memcpy(plaintext, input->data, input->length);
ret = ctp->enc->decrypt(xorkey, NULL, &iov, 1);
if (ret != 0)
goto cleanup;
diff --git a/src/lib/crypto/krb/derive.c b/src/lib/crypto/krb/derive.c
index 1509f42250..f15fec1a29 100644
--- a/src/lib/crypto/krb/derive.c
+++ b/src/lib/crypto/krb/derive.c
@@ -52,7 +52,7 @@ add_cached_dkey(krb5_key key, const krb5_data *constant,
dkent = malloc(sizeof(*dkent));
if (dkent == NULL)
goto cleanup;
- data = malloc(constant->length);
+ data = k5memdup(constant->data, constant->length, &ret);
if (data == NULL)
goto cleanup;
ret = krb5_k_create_key(NULL, dkeyblock, &dkey);
@@ -60,7 +60,6 @@ add_cached_dkey(krb5_key key, const krb5_data *constant,
goto cleanup;
/* Add the new entry to the list. */
- memcpy(data, constant->data, constant->length);
dkent->dkey = dkey;
dkent->constant.data = data;
dkent->constant.length = constant->length;
diff --git a/src/lib/crypto/krb/enc_old.c b/src/lib/crypto/krb/enc_old.c
index e7160b1692..b44a3994f0 100644
--- a/src/lib/crypto/krb/enc_old.c
+++ b/src/lib/crypto/krb/enc_old.c
@@ -166,10 +166,9 @@ krb5int_old_decrypt(const struct krb5_keytypes *ktp, krb5_key key,
/* Save the checksum, then zero it out in the plaintext. */
checksum = make_data(header->data.data + enc->block_size, hash->hashsize);
- saved_checksum = k5alloc(hash->hashsize, &ret);
+ saved_checksum = k5memdup(checksum.data, checksum.length, &ret);
if (saved_checksum == NULL)
goto cleanup;
- memcpy(saved_checksum, checksum.data, checksum.length);
memset(checksum.data, 0, checksum.length);
/*