Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tpm2_hash: Change default hashing alg from sha1 to sha256 #3342

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading