summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagendra modadugu <ngm@google.com>2016-01-28 09:25:51 -0800
committerchrome-bot <chrome-bot@chromium.org>2016-01-28 14:16:19 -0800
commit26bbc59b4629f44a93b87ed8c21e5f80699c7779 (patch)
tree854955a3e08d0fcea5d4d5e5a7dfed3ba03ae27a
parentd60d263b83181aee7544f6e24afa13e441a45177 (diff)
downloadchrome-ec-26bbc59b4629f44a93b87ed8c21e5f80699c7779.tar.gz
Fix bug in software sha256_hash()
The implementation for sha256_hash() copied and incorrect number of bytes to the output. This change provides a fix and a test. TEST=added test case BRANCH=none BUG=chrome-os-partner:43025,chrome-os-partner:47524 Change-Id: I74e98c6f5005a14dd5c0ca19ea7540622dd6c7d7 Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/324391 Commit-Ready: Nagendra Modadugu <ngm@google.com> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Bill Richardson <wfrichar@chromium.org>
-rw-r--r--chip/g/dcrypto/sha256.c5
-rw-r--r--test/tpm_test/hash_test.py2
2 files changed, 3 insertions, 4 deletions
diff --git a/chip/g/dcrypto/sha256.c b/chip/g/dcrypto/sha256.c
index 20d813bc9d..c884ff2a4a 100644
--- a/chip/g/dcrypto/sha256.c
+++ b/chip/g/dcrypto/sha256.c
@@ -61,10 +61,7 @@ static const uint8_t *sha256_hash(const uint8_t *data, uint32_t len,
sha256_init(&ctx);
sha256_update(&ctx, data, len);
- sha256_final(&ctx);
-
- memcpy(digest, ctx.u.sw_sha256.buf, SHA256_DIGEST_WORDS);
-
+ memcpy(digest, sha256_final(&ctx), SHA256_DIGEST_BYTES);
return digest;
}
diff --git a/test/tpm_test/hash_test.py b/test/tpm_test/hash_test.py
index fd8d0f4184..a5a1e522c7 100644
--- a/test/tpm_test/hash_test.py
+++ b/test/tpm_test/hash_test.py
@@ -37,6 +37,8 @@ test_inputs = (
(MODE_SHA256, 'start', 1, 'some more text, this time for sha256'),
(MODE_SHA256, 'cont', 1, 'some more text, this time for sha256'),
(MODE_SHA256, 'start', 2, 'this could be anything, we just need to'),
+ (MODE_SHA1, 'single', 3, 'interleave a SHA1 single calculation'),
+ (MODE_SHA256, 'single', 3, 'interleave a SHA256 single calculation'),
(MODE_SHA1, 'start', 3, 'let\'s interleave a sha1 calculation'),
(MODE_SHA256, 'cont', 2, 'fill up a second context with something'),
(MODE_SHA256, 'cont', 1, 'let\'s feed some more into context 1'),