Skip to content

Commit

Permalink
Convert hkdf_test to C++.
Browse files Browse the repository at this point in the history
Change-Id: I0e8a24367cd33fa4aed2ca15bd369b8697f538e6
Reviewed-on: https://boringssl-review.googlesource.com/12974
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
  • Loading branch information
davidben authored and agl committed Jan 4, 2017
1 parent d17d1da commit a17eb56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion crypto/hkdf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ add_library(
add_executable(
hkdf_test

hkdf_test.c
hkdf_test.cc

$<TARGET_OBJECTS:test_support>
)
Expand Down
17 changes: 8 additions & 9 deletions crypto/hkdf/hkdf_test.c → crypto/hkdf/hkdf_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "../test/test_util.h"


typedef struct {
struct HKDFTestVector {
const EVP_MD *(*md_func)(void);
const uint8_t ikm[80];
const size_t ikm_len;
Expand All @@ -36,10 +36,10 @@ typedef struct {
const size_t prk_len;
const size_t out_len;
const uint8_t out[82];
} hkdf_test_vector_t;
};

/* These test vectors are from RFC 5869. */
static const hkdf_test_vector_t kTests[] = {
static const HKDFTestVector kTests[] = {
{
EVP_sha256,
{
Expand Down Expand Up @@ -248,13 +248,12 @@ static const hkdf_test_vector_t kTests[] = {
};

int main(void) {
uint8_t buf[82], prk[EVP_MAX_MD_SIZE];
size_t i, prk_len;

CRYPTO_library_init();

for (i = 0; i < OPENSSL_ARRAY_SIZE(kTests); i++) {
const hkdf_test_vector_t *test = &kTests[i];
for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kTests); i++) {
const HKDFTestVector *test = &kTests[i];
uint8_t prk[EVP_MAX_MD_SIZE];
size_t prk_len;
if (!HKDF_extract(prk, &prk_len, test->md_func(), test->ikm, test->ikm_len,
test->salt, test->salt_len)) {
fprintf(stderr, "Call to HKDF_extract failed\n");
Expand All @@ -266,6 +265,7 @@ int main(void) {
fprintf(stderr, "%zu: Resulting PRK does not match test vector\n", i);
return 1;
}
uint8_t buf[82];
if (!HKDF_expand(buf, test->out_len, test->md_func(), prk, prk_len,
test->info, test->info_len)) {
fprintf(stderr, "Call to HKDF_expand failed\n");
Expand All @@ -292,6 +292,5 @@ int main(void) {
}

printf("PASS\n");
ERR_free_strings();
return 0;
}

0 comments on commit a17eb56

Please sign in to comment.