Skip to content

Commit

Permalink
tpm2_hash: Change default hashing alg from sha1 to sha256
Browse files Browse the repository at this point in the history
Signed-off-by: Imran Desai <[email protected]>
  • Loading branch information
idesai committed Jan 25, 2024
1 parent 30ae31a commit 58d0129
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions test/integration/tests/hash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,25 @@ cleanup "no-shut-down"
# Test stdout output as well as no options.
# Validate that hash outputs are in hex as expected.
tpm_hash_val=`echo 1234 | tpm2 hash -C n --hex`
sha1sum_val=`echo 1234 | shasum -a 1 | cut -d\ -f 1-2 | tr -d '[:space:]'`
if [ "$tpm_hash_val" != "$sha1sum_val" ]; then
sha256sum_val=`echo 1234 | shasum -a 256 | cut -d\ -f 1-2 | tr -d '[:space:]'`
if [ "$tpm_hash_val" != "$sha256sum_val" ]; then
echo "Expected tpm and sha1sum to produce same hashes."
echo "Got:"
echo " tpm2 hash: $tpm_hash_val"
echo " sha1sum: $sha1sum_val"
echo " sha256sum: $sha256sum_val"
exit 1
fi

# Test a file that cannot be done in 1 update call.
# The tpm works on a 1024 block size.
dd if=/dev/urandom of=$hash_in_file bs=2093 count=1 2>/dev/null
tpm_hash_val=`tpm2 hash --hex $hash_in_file`
sha1sum_val=`shasum -a 1 $hash_in_file | cut -d\ -f 1-2 | tr -d '[:space:]'`
if [ "$tpm_hash_val" != "$sha1sum_val" ]; then
sha256sum_val=`shasum -a 256 $hash_in_file | cut -d\ -f 1-2 | tr -d '[:space:]'`
if [ "$tpm_hash_val" != "$sha256sum_val" ]; then
echo "Expected tpm and sha1sum to produce same hashes"
echo "Got:"
echo " tpm2 hash: $tpm_hash_val"
echo " sha1sum: $sha1sum_val"
echo " sha256sum: $sha256sum_val"
exit 1
fi

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct tpm_hash_ctx {

static tpm_hash_ctx ctx = {
.hierarchy_value = TPM2_RH_OWNER,
.halg = TPM2_ALG_SHA1,
.halg = TPM2_ALG_SHA256,
};

static tool_rc hash_and_save(ESYS_CONTEXT *context) {
Expand Down

0 comments on commit 58d0129

Please sign in to comment.