我想在客户端使用tpm2完成消息的hmac签名,在服务器使用openssl对消息做验签。
于是我做了这样的验证:
echo "Hello world!" > message.txt
openssl rand -out hmac_key.bin 32
tpm2_createprimary -C o -g sha256 -G rsa2048 -c primary.ctx
tpm2_evictcontrol -C o -c primary.ctx 0x81000001
tpm2_import -C primary.ctx -u hmac_pub.pem -r hmac_pri.pem -i hmac_key.bin -G hmac
tpm2_load -C primary.ctx -u hmac_pub.pem -r hmac_pri.pem -c hmac.ctx
tpm2_evictcontrol -C o -c hmac.ctx 0x81010002
tpm2_hmac -c hmac.ctx -g sha256 -o message_hmac_tpm.bin message.txt
openssl dgst -sha256 -mac HMAC -macopt key:"$(xxd -p hmac_key.bin)" -out message_hmac_openssl.bin -binary message.txt
cmp message_hmac_tpm.bin message_hmac_openssl.bin
结果是:
message_hmac_tpm.bin message_hmac_openssl.bin differ: byte 1, line 1
两个签名结果文件的大小是一样的:
-rw-r--r-- 1 root root 32 Dec 12 18:11 message_hmac_openssl.bin
-rw-rw---- 1 root root 32 Dec 12 18:11 message_hmac_tpm.bin