Update to support OEMCrypto v16 with ODK
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "common/aes_cbc_util.h"
|
||||
|
||||
#include "testing/gmock.h"
|
||||
#include "testing/gunit.h"
|
||||
|
||||
@@ -29,16 +30,18 @@ namespace crypto_util {
|
||||
|
||||
TEST(CryptoUtilTest, EncryptAndDecryptAesCbc) {
|
||||
std::string plain_text("Foo");
|
||||
std::string ciphertext = EncryptAesCbc(std::string(kKey, kKey + sizeof(kKey)),
|
||||
std::string(kIv, kIv + sizeof(kIv)), plain_text);
|
||||
std::string ciphertext =
|
||||
EncryptAesCbc(std::string(kKey, kKey + sizeof(kKey)),
|
||||
std::string(kIv, kIv + sizeof(kIv)), plain_text);
|
||||
std::string expected_ciphertext(
|
||||
"\xCF\x1A\x3\x1C\x9C\x8C\xB9Z\xEC\xC0\x17\xDCRxX\xD7");
|
||||
ASSERT_EQ(0, ciphertext.size() % 16);
|
||||
ASSERT_GT(ciphertext.size(), plain_text.size());
|
||||
ASSERT_EQ(expected_ciphertext, ciphertext);
|
||||
|
||||
std::string decrypted = DecryptAesCbc(std::string(kKey, kKey + sizeof(kKey)),
|
||||
std::string(kIv, kIv + sizeof(kIv)), ciphertext);
|
||||
std::string decrypted =
|
||||
DecryptAesCbc(std::string(kKey, kKey + sizeof(kKey)),
|
||||
std::string(kIv, kIv + sizeof(kIv)), ciphertext);
|
||||
ASSERT_EQ(plain_text, decrypted);
|
||||
}
|
||||
|
||||
@@ -65,28 +68,29 @@ TEST(CryptoUtilTest, DecryptAesCbcNoPad) {
|
||||
};
|
||||
|
||||
std::string decrypted = DecryptAesCbcNoPad(
|
||||
std::string(kKey, kKey + sizeof(kKey)), std::string(kIv, kIv + sizeof(kIv)),
|
||||
std::string(kKey, kKey + sizeof(kKey)),
|
||||
std::string(kIv, kIv + sizeof(kIv)),
|
||||
std::string(kCiphertext, kCiphertext + sizeof(kCiphertext)));
|
||||
ASSERT_EQ(std::string(kExpectedPlaintext,
|
||||
kExpectedPlaintext + sizeof(kExpectedPlaintext)),
|
||||
kExpectedPlaintext + sizeof(kExpectedPlaintext)),
|
||||
decrypted);
|
||||
|
||||
std::string dummy_iv;
|
||||
decrypted = DecryptAesCbcNoPad(
|
||||
std::string(kKey, kKey + sizeof(kKey)), dummy_iv,
|
||||
std::string(kCiphertext, kCiphertext + sizeof(kCiphertext)));
|
||||
ASSERT_EQ(
|
||||
std::string(kExpectedPlaintextEmptyIv,
|
||||
kExpectedPlaintextEmptyIv + sizeof(kExpectedPlaintextEmptyIv)),
|
||||
decrypted);
|
||||
ASSERT_EQ(std::string(
|
||||
kExpectedPlaintextEmptyIv,
|
||||
kExpectedPlaintextEmptyIv + sizeof(kExpectedPlaintextEmptyIv)),
|
||||
decrypted);
|
||||
}
|
||||
|
||||
TEST(CryptoUtilTest, TestFailedEncrypt) {
|
||||
// Test with bogus initialization vector.
|
||||
std::string plain_text("Foo");
|
||||
std::string bogus_iv("bogus");
|
||||
std::string ciphertext =
|
||||
EncryptAesCbc(std::string(kKey, kKey + sizeof(kKey)), bogus_iv, plain_text);
|
||||
std::string ciphertext = EncryptAesCbc(std::string(kKey, kKey + sizeof(kKey)),
|
||||
bogus_iv, plain_text);
|
||||
ASSERT_EQ(ciphertext.size(), 0);
|
||||
|
||||
// Test with bogus key.
|
||||
@@ -124,14 +128,15 @@ TEST(CryptoUtilTest, TestFailedEncryptNoPad) {
|
||||
TEST(CryptoUtilTest, TestFailedDecrypt) {
|
||||
// First, encrypt the data.
|
||||
std::string plain_text("Foo");
|
||||
std::string ciphertext = EncryptAesCbc(std::string(kKey, kKey + sizeof(kKey)),
|
||||
std::string(kIv, kIv + sizeof(kIv)), plain_text);
|
||||
std::string ciphertext =
|
||||
EncryptAesCbc(std::string(kKey, kKey + sizeof(kKey)),
|
||||
std::string(kIv, kIv + sizeof(kIv)), plain_text);
|
||||
ASSERT_NE(ciphertext.size(), 0);
|
||||
|
||||
// Test Decrypt with bogus iv.
|
||||
std::string bogus_iv("bogus");
|
||||
plain_text =
|
||||
DecryptAesCbc(std::string(kKey, kKey + sizeof(kKey)), bogus_iv, ciphertext);
|
||||
plain_text = DecryptAesCbc(std::string(kKey, kKey + sizeof(kKey)), bogus_iv,
|
||||
ciphertext);
|
||||
ASSERT_EQ(plain_text.size(), 0);
|
||||
|
||||
// Test Decrypt with bogus key.
|
||||
|
||||
Reference in New Issue
Block a user