Convert chacha_test to GTest.
BUG=129 Change-Id: Ibbd6d0804a75cb17ff33f64d4cdf9ae80b26e9df Reviewed-on: https://boringssl-review.googlesource.com/13867 Reviewed-by: Steven Valdez <svaldez@google.com> Reviewed-by: David Benjamin <davidben@google.com> Commit-Queue: David Benjamin <davidben@google.com> CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
parent
1d5a570627
commit
b19b6626c5
@ -212,6 +212,7 @@ add_dependencies(all_tests refcount_test)
|
||||
add_executable(
|
||||
crypto_test
|
||||
|
||||
chacha/chacha_test.cc
|
||||
dh/dh_test.cc
|
||||
dsa/dsa_test.cc
|
||||
err/err_test.cc
|
||||
|
@ -42,16 +42,6 @@ add_library(
|
||||
${CHACHA_ARCH_SOURCES}
|
||||
)
|
||||
|
||||
add_executable(
|
||||
chacha_test
|
||||
|
||||
chacha_test.cc
|
||||
$<TARGET_OBJECTS:test_support>
|
||||
)
|
||||
|
||||
target_link_libraries(chacha_test crypto)
|
||||
add_dependencies(all_tests chacha_test)
|
||||
|
||||
perlasm(chacha-armv4.${ASM_EXT} asm/chacha-armv4.pl)
|
||||
perlasm(chacha-armv8.${ASM_EXT} asm/chacha-armv8.pl)
|
||||
perlasm(chacha-x86.${ASM_EXT} asm/chacha-x86.pl)
|
||||
|
@ -18,10 +18,13 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/chacha.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "../test/test_util.h"
|
||||
|
||||
|
||||
static const uint8_t kKey[32] = {
|
||||
@ -216,35 +219,18 @@ static const uint8_t kOutput[] = {
|
||||
static_assert(sizeof(kInput) == sizeof(kOutput),
|
||||
"Input and output lengths don't match.");
|
||||
|
||||
static bool TestChaCha20(size_t len) {
|
||||
std::unique_ptr<uint8_t[]> buf(new uint8_t[len]);
|
||||
CRYPTO_chacha_20(buf.get(), kInput, len, kKey, kNonce, kCounter);
|
||||
if (OPENSSL_memcmp(buf.get(), kOutput, len) != 0) {
|
||||
fprintf(stderr, "Mismatch at length %zu.\n", len);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Test in-place.
|
||||
OPENSSL_memcpy(buf.get(), kInput, len);
|
||||
CRYPTO_chacha_20(buf.get(), buf.get(), len, kKey, kNonce, kCounter);
|
||||
if (OPENSSL_memcmp(buf.get(), kOutput, len) != 0) {
|
||||
fprintf(stderr, "Mismatch at length %zu, in-place.\n", len);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
CRYPTO_library_init();
|
||||
|
||||
TEST(ChaChaTest, TestVector) {
|
||||
// Run the test with the test vector at all lengths.
|
||||
for (size_t len = 0; len <= sizeof(kInput); len++) {
|
||||
if (!TestChaCha20(len)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
SCOPED_TRACE(len);
|
||||
|
||||
printf("PASS\n");
|
||||
return 0;
|
||||
std::unique_ptr<uint8_t[]> buf(new uint8_t[len]);
|
||||
CRYPTO_chacha_20(buf.get(), kInput, len, kKey, kNonce, kCounter);
|
||||
EXPECT_EQ(Bytes(kOutput, len), Bytes(buf.get(), len));
|
||||
|
||||
// Test the in-place version.
|
||||
OPENSSL_memcpy(buf.get(), kInput, len);
|
||||
CRYPTO_chacha_20(buf.get(), buf.get(), len, kKey, kNonce, kCounter);
|
||||
EXPECT_EQ(Bytes(kOutput, len), Bytes(buf.get(), len));
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
["crypto/bio/bio_test"],
|
||||
["crypto/bn/bn_test", "crypto/bn/bn_tests.txt"],
|
||||
["crypto/bytestring/bytestring_test"],
|
||||
["crypto/chacha/chacha_test"],
|
||||
["crypto/cipher/aead_test", "aes-128-gcm", "crypto/cipher/test/aes_128_gcm_tests.txt"],
|
||||
["crypto/cipher/aead_test", "aes-256-gcm", "crypto/cipher/test/aes_256_gcm_tests.txt"],
|
||||
["crypto/cipher/aead_test", "aes-128-gcm-siv", "crypto/cipher/test/aes_128_gcm_siv_tests.txt"],
|
||||
|
Loading…
Reference in New Issue
Block a user