Blame SOURCES/Add-vector-support-to-k5_sha256.patch

665228
From c886bef63a4820d12fbc956f62747840fba8a88e Mon Sep 17 00:00:00 2001
665228
From: Greg Hudson <ghudson@mit.edu>
665228
Date: Sat, 3 Feb 2018 20:53:42 -0500
665228
Subject: [PATCH] Add vector support to k5_sha256()
665228
665228
Add a length argument so that multiple krb5_data values can be passed
665228
to k5_sha256(), for efficient computation of SHA-256 hashes over
665228
concatenations of data values.
665228
665228
(cherry picked from commit 4f3373e8c55b3e9bdfb5b065e07214c5816c85fa)
665228
---
665228
 src/include/k5-int.h                 | 4 ++--
665228
 src/lib/crypto/builtin/sha2/sha256.c | 6 ++++--
665228
 src/lib/crypto/crypto_tests/t_sha2.c | 2 +-
665228
 src/lib/crypto/openssl/sha256.c      | 6 ++++--
665228
 src/lib/krb5/rcache/rc_conv.c        | 2 +-
665228
 5 files changed, 12 insertions(+), 8 deletions(-)
665228
665228
diff --git a/src/include/k5-int.h b/src/include/k5-int.h
665228
index 10b034037..7c549bce2 100644
665228
--- a/src/include/k5-int.h
665228
+++ b/src/include/k5-int.h
665228
@@ -634,9 +634,9 @@ krb5int_arcfour_gsscrypt(const krb5_keyblock *keyblock, krb5_keyusage usage,
665228
 
665228
 #define K5_SHA256_HASHLEN (256 / 8)
665228
 
665228
-/* Write the SHA-256 hash of in to out. */
665228
+/* Write the SHA-256 hash of in (containing n elements) to out. */
665228
 krb5_error_code
665228
-k5_sha256(const krb5_data *in, uint8_t out[K5_SHA256_HASHLEN]);
665228
+k5_sha256(const krb5_data *in, size_t n, uint8_t out[K5_SHA256_HASHLEN]);
665228
 
665228
 /*
665228
  * Attempt to zero memory in a way that compilers won't optimize out.
665228
diff --git a/src/lib/crypto/builtin/sha2/sha256.c b/src/lib/crypto/builtin/sha2/sha256.c
665228
index e34bed575..4b5fe10a3 100644
665228
--- a/src/lib/crypto/builtin/sha2/sha256.c
665228
+++ b/src/lib/crypto/builtin/sha2/sha256.c
665228
@@ -257,12 +257,14 @@ k5_sha256_final(void *res, SHA256_CTX *m)
665228
 }
665228
 
665228
 krb5_error_code
665228
-k5_sha256(const krb5_data *in, uint8_t out[K5_SHA256_HASHLEN])
665228
+k5_sha256(const krb5_data *in, size_t n, uint8_t out[K5_SHA256_HASHLEN])
665228
 {
665228
     SHA256_CTX ctx;
665228
+    size_t i;
665228
 
665228
     k5_sha256_init(&ctx;;
665228
-    k5_sha256_update(&ctx, in->data, in->length);
665228
+    for (i = 0; i < n; i++)
665228
+        k5_sha256_update(&ctx, in[i].data, in[i].length);
665228
     k5_sha256_final(out, &ctx;;
665228
     return 0;
665228
 }
665228
diff --git a/src/lib/crypto/crypto_tests/t_sha2.c b/src/lib/crypto/crypto_tests/t_sha2.c
665228
index 12f32869b..e6fa58498 100644
665228
--- a/src/lib/crypto/crypto_tests/t_sha2.c
665228
+++ b/src/lib/crypto/crypto_tests/t_sha2.c
665228
@@ -125,7 +125,7 @@ hash_test(const struct krb5_hash_provider *hash, struct test *tests)
665228
 
665228
 	    if (hash == &krb5int_hash_sha256) {
665228
 		/* Try again using k5_sha256(). */
665228
-		if (k5_sha256(&iov.data, (uint8_t *)hval.data) != 0)
665228
+		if (k5_sha256(&iov.data, 1, (uint8_t *)hval.data) != 0)
665228
 		    abort();
665228
 		if (memcmp(hval.data, t->hash, hval.length) != 0)
665228
 		    abort();
665228
diff --git a/src/lib/crypto/openssl/sha256.c b/src/lib/crypto/openssl/sha256.c
665228
index fa095d472..0edd8b7ba 100644
665228
--- a/src/lib/crypto/openssl/sha256.c
665228
+++ b/src/lib/crypto/openssl/sha256.c
665228
@@ -34,16 +34,18 @@
665228
 #include <openssl/evp.h>
665228
 
665228
 krb5_error_code
665228
-k5_sha256(const krb5_data *in, uint8_t out[K5_SHA256_HASHLEN])
665228
+k5_sha256(const krb5_data *in, size_t n, uint8_t out[K5_SHA256_HASHLEN])
665228
 {
665228
     EVP_MD_CTX *ctx;
665228
+    size_t i;
665228
     int ok;
665228
 
665228
     ctx = EVP_MD_CTX_new();
665228
     if (ctx == NULL)
665228
         return ENOMEM;
665228
     ok = EVP_DigestInit_ex(ctx, EVP_sha256(), NULL);
665228
-    ok = ok && EVP_DigestUpdate(ctx, in->data, in->length);
665228
+    for (i = 0; i < n; i++)
665228
+        ok = ok && EVP_DigestUpdate(ctx, in[i].data, in[i].length);
665228
     ok = ok && EVP_DigestFinal_ex(ctx, out, NULL);
665228
     EVP_MD_CTX_free(ctx);
665228
     return ok ? 0 : ENOMEM;
665228
diff --git a/src/lib/krb5/rcache/rc_conv.c b/src/lib/krb5/rcache/rc_conv.c
665228
index 0e021f5d8..f2fe528ac 100644
665228
--- a/src/lib/krb5/rcache/rc_conv.c
665228
+++ b/src/lib/krb5/rcache/rc_conv.c
665228
@@ -58,7 +58,7 @@ krb5_rc_hash_message(krb5_context context, const krb5_data *message,
665228
     *out = NULL;
665228
 
665228
     /* Calculate the binary checksum. */
665228
-    retval = k5_sha256(message, cksum);
665228
+    retval = k5_sha256(message, 1, cksum);
665228
     if (retval)
665228
         return retval;
665228