2010年5月6日 星期四

Why MAC may be different?

很奇怪的陳述。實驗了一下,好像並不會如它所說:


CryptoPP::HMAC hmac(key, CryptoPP::SHA256::DIGESTSIZE);

hmac.CalculateDigest(mac_output, in_data, length);
output_hex("HMAC-internal #1", mac_output, CryptoPP::SHA256::DIGESTSIZE);

hmac.CalculateDigest(mac_output, in_data, length);
output_hex("HMAC-internal #2", mac_output, CryptoPP::SHA256::DIGESTSIZE);

hmac.CalculateDigest(mac_output, in_data, length);
output_hex("HMAC-internal #3", mac_output, CryptoPP::SHA256::DIGESTSIZE);

hmac.CalculateDigest(mac_output, in_data, length);
output_hex("HMAC-internal #4", mac_output, CryptoPP::SHA256::DIGESTSIZE);

hmac.CalculateDigest(mac_output, in_data, length);
output_hex("HMAC-internal #5", mac_output, CryptoPP::SHA256::DIGESTSIZE);

看起來,5 個 mac_output 內容都一樣。

參考來源:

"Applying a MAC to the same input twice generally does not produce the same authentication code. Hence, verifying a MAC is not equivalent to calling CalculateDigest() and then manually comparing the calculated hash with the supplied one. Rather, either Verify or VerifyDigest must be used to verify a MAC."
- http://www.cryptopp.com/wiki/User_Guide:_cryptlib.h (在「Google 網頁註解」中檢視)

沒有留言:

張貼留言