Add crypto/fipsoracle.
This CL adds utility code to process NIST CAVP test vectors using the
existing FileTest code.
Also add binaries for processing AESAVS (AES) and GCMVS (AES-GCM) vector
files.
Change-Id: I8e5ebf751d7d4b5504bbb52f3e087b0065babbe0
Reviewed-on: https://boringssl-review.googlesource.com/15484
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/fipsoracle/CMakeLists.txt b/crypto/fipsoracle/CMakeLists.txt
new file mode 100644
index 0000000..71b2ee1
--- /dev/null
+++ b/crypto/fipsoracle/CMakeLists.txt
@@ -0,0 +1,24 @@
+include_directories(../../include)
+
+if (FIPS)
+ add_executable(
+ cavp_aes_test
+
+ cavp_aes_test.cc
+ cavp_test_util.h
+ cavp_test_util.cc
+ $<TARGET_OBJECTS:test_support>
+ )
+
+ add_executable(
+ cavp_aes_gcm_test
+
+ cavp_aes_gcm_test.cc
+ cavp_test_util.h
+ cavp_test_util.cc
+ $<TARGET_OBJECTS:test_support>
+ )
+
+ target_link_libraries(cavp_aes_test crypto)
+ target_link_libraries(cavp_aes_gcm_test crypto)
+endif()
diff --git a/crypto/fipsoracle/cavp_aes_gcm_test.cc b/crypto/fipsoracle/cavp_aes_gcm_test.cc
new file mode 100644
index 0000000..171a4e7
--- /dev/null
+++ b/crypto/fipsoracle/cavp_aes_gcm_test.cc
@@ -0,0 +1,211 @@
+/* Copyright (c) 2017, Google Inc.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
+
+// cavp_aes_gcm_test processes a NIST CAVP AES GCM test vector request file and
+// emits the corresponding response. An optional sample vector file can be
+// passed to verify the result.
+
+#include <stdlib.h>
+
+#include <openssl/aead.h>
+#include <openssl/cipher.h>
+#include <openssl/crypto.h>
+#include <openssl/err.h>
+
+#include "../test/file_test.h"
+#include "cavp_test_util.h"
+
+
+struct TestCtx {
+ const EVP_AEAD *aead;
+ std::unique_ptr<FileTest> response_sample;
+};
+
+static const EVP_AEAD *GetAEAD(const std::string &name, const bool enc) {
+ if (name == "aes-128-gcm") {
+ return EVP_aead_aes_128_gcm_fips_testonly();
+ } else if (name == "aes-256-gcm") {
+ return EVP_aead_aes_256_gcm_fips_testonly();
+ }
+ return nullptr;
+}
+
+static bool TestAEADEncrypt(FileTest *t, void *arg) {
+ TestCtx *ctx = reinterpret_cast<TestCtx *>(arg);
+
+ std::string key_len_str, iv_len_str, pt_len_str, aad_len_str, tag_len_str;
+ if (!t->GetInstruction(&key_len_str, "Keylen") ||
+ !t->GetInstruction(&iv_len_str, "IVlen") ||
+ !t->GetInstruction(&pt_len_str, "PTlen") ||
+ !t->GetInstruction(&aad_len_str, "AADlen") ||
+ !t->GetInstruction(&tag_len_str, "Taglen")) {
+ return false;
+ }
+
+ std::string count;
+ std::vector<uint8_t> key, iv, pt, aad, tag, ct;
+ if (!t->GetAttribute(&count, "Count") ||
+ !t->GetBytes(&key, "Key") ||
+ !t->GetBytes(&aad, "AAD") ||
+ !t->GetBytes(&pt, "PT") ||
+ key.size() * 8 != strtoul(key_len_str.c_str(), nullptr, 0) ||
+ pt.size() * 8 != strtoul(pt_len_str.c_str(), nullptr, 0) ||
+ aad.size() * 8 != strtoul(aad_len_str.c_str(), nullptr, 0)) {
+ return false;
+ }
+
+ size_t tag_len = strtoul(tag_len_str.c_str(), nullptr, 0) / 8;
+ if (!AEADEncrypt(ctx->aead, &ct, &tag, tag_len, key, pt, aad, &iv)) {
+ return false;
+ }
+ printf("%s", t->CurrentTestToString().c_str());
+ printf("IV = %s\r\n", EncodeHex(iv.data(), iv.size()).c_str());
+ printf("CT = %s\r\n", EncodeHex(ct.data(), ct.size()).c_str());
+ printf("Tag = %s\r\n\r\n", EncodeHex(tag.data(), tag.size()).c_str());
+
+ // Check if sample response file matches.
+ if (ctx->response_sample) {
+ ctx->response_sample->ReadNext();
+ std::string expected_count;
+ std::vector<uint8_t> expected_iv, expected_ct, expected_tag;
+ if (!ctx->response_sample->GetAttribute(&expected_count, "Count") ||
+ count != expected_count ||
+ !ctx->response_sample->GetBytes(&expected_iv, "IV") ||
+ !t->ExpectBytesEqual(expected_iv.data(), expected_iv.size(), iv.data(),
+ iv.size()) ||
+ !ctx->response_sample->GetBytes(&expected_ct, "CT") ||
+ !t->ExpectBytesEqual(expected_ct.data(), expected_ct.size(), ct.data(),
+ ct.size()) ||
+ !ctx->response_sample->GetBytes(&expected_tag, "Tag") ||
+ !t->ExpectBytesEqual(expected_tag.data(), expected_tag.size(),
+ tag.data(), tag.size())) {
+ t->PrintLine("result doesn't match");
+ return false;
+ }
+ }
+
+ return true;
+}
+
+static bool TestAEADDecrypt(FileTest *t, void *arg) {
+ TestCtx *ctx = reinterpret_cast<TestCtx *>(arg);
+
+ std::string key_len, iv_len, pt_len_str, aad_len_str, tag_len;
+ if (!t->GetInstruction(&key_len, "Keylen") ||
+ !t->GetInstruction(&iv_len, "IVlen") ||
+ !t->GetInstruction(&pt_len_str, "PTlen") ||
+ !t->GetInstruction(&aad_len_str, "AADlen") ||
+ !t->GetInstruction(&tag_len, "Taglen")) {
+ t->PrintLine("Invalid instruction block.");
+ return false;
+ }
+ size_t aad_len = strtoul(aad_len_str.c_str(), nullptr, 0) / 8;
+ size_t pt_len = strtoul(pt_len_str.c_str(), nullptr, 0) / 8;
+
+ std::string count;
+ std::vector<uint8_t> key, iv, ct, aad, tag, pt;
+ if (!t->GetAttribute(&count, "Count") ||
+ !t->GetBytes(&key, "Key") ||
+ !t->GetBytes(&aad, "AAD") ||
+ !t->GetBytes(&tag, "Tag") ||
+ !t->GetBytes(&iv, "IV") ||
+ !t->GetBytes(&ct, "CT") ||
+ key.size() * 8 != strtoul(key_len.c_str(), nullptr, 0) ||
+ iv.size() * 8 != strtoul(iv_len.c_str(), nullptr, 0) ||
+ ct.size() != pt_len ||
+ aad.size() != aad_len ||
+ tag.size() * 8 != strtoul(tag_len.c_str(), nullptr, 0)) {
+ t->PrintLine("Invalid test case");
+ return false;
+ }
+
+ printf("%s", t->CurrentTestToString().c_str());
+ bool aead_result =
+ AEADDecrypt(ctx->aead, &pt, &aad, pt_len, aad_len, key, ct, tag, iv);
+ if (aead_result) {
+ printf("PT = %s\r\n\r\n", EncodeHex(pt.data(), pt.size()).c_str());
+ } else {
+ printf("FAIL\r\n\r\n");
+ }
+
+ // Check if sample response file matches.
+ if (ctx->response_sample) {
+ ctx->response_sample->ReadNext();
+ std::string expected_count;
+ std::vector<uint8_t> expected_pt;
+ if (!ctx->response_sample->GetAttribute(&expected_count, "Count") ||
+ count != expected_count ||
+ (!aead_result && (ctx->response_sample->HasAttribute("PT") ||
+ !ctx->response_sample->HasAttribute("FAIL"))) ||
+ (aead_result &&
+ (ctx->response_sample->HasAttribute("FAIL") ||
+ !ctx->response_sample->GetBytes(&expected_pt, "PT") ||
+ !t->ExpectBytesEqual(expected_pt.data(), expected_pt.size(),
+ pt.data(), pt.size())))) {
+ t->PrintLine("result doesn't match");
+ return false;
+ }
+ }
+
+ return true;
+}
+
+static int usage(char *arg) {
+ fprintf(stderr,
+ "usage: %s (enc|dec) <cipher> <test file> [<sample response file>]\n",
+ arg);
+ return 1;
+}
+
+int main(int argc, char **argv) {
+ CRYPTO_library_init();
+
+ if (argc < 4 || argc > 5) {
+ return usage(argv[0]);
+ }
+
+ const std::string mode(argv[1]);
+ bool (*test_fn)(FileTest * t, void *arg);
+ if (mode == "enc") {
+ test_fn = &TestAEADEncrypt;
+ } else if (mode == "dec") {
+ test_fn = &TestAEADDecrypt;
+ } else {
+ return usage(argv[0]);
+ }
+
+ const EVP_AEAD *aead = GetAEAD(argv[2], mode == "enc");
+ if (aead == nullptr) {
+ fprintf(stderr, "invalid aead: %s\n", argv[2]);
+ return 1;
+ }
+
+ TestCtx ctx = {aead, nullptr};
+
+ if (argc == 5) {
+ ctx.response_sample.reset(new FileTest(argv[4]));
+ if (!ctx.response_sample->is_open()) {
+ return 1;
+ }
+ ctx.response_sample->SetIgnoreUnusedAttributes(true);
+ }
+
+ printf("# Generated by");
+ for (int i = 0; i < argc; i++) {
+ printf(" %s", argv[i]);
+ }
+ printf("\n\n");
+
+ return FileTestMainSilent(test_fn, &ctx, argv[3]);
+}
diff --git a/crypto/fipsoracle/cavp_aes_test.cc b/crypto/fipsoracle/cavp_aes_test.cc
new file mode 100644
index 0000000..83dc0fe
--- /dev/null
+++ b/crypto/fipsoracle/cavp_aes_test.cc
@@ -0,0 +1,135 @@
+/* Copyright (c) 2017, Google Inc.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
+
+// cavp_aes_test processes a NIST CAVP AES test vector request file and emits
+// the corresponding response. An optional sample vector file can be passed to
+// verify the result.
+
+#include <stdlib.h>
+
+#include <openssl/cipher.h>
+#include <openssl/crypto.h>
+#include <openssl/err.h>
+
+#include "../test/file_test.h"
+#include "cavp_test_util.h"
+
+
+struct TestCtx {
+ const EVP_CIPHER *cipher;
+ std::unique_ptr<FileTest> response_sample;
+ bool has_iv;
+};
+
+static bool TestCipher(FileTest *t, void *arg) {
+ TestCtx *ctx = reinterpret_cast<TestCtx *>(arg);
+
+ if (t->HasInstruction("ENCRYPT") == t->HasInstruction("DECRYPT")) {
+ t->PrintLine("Want either ENCRYPT or DECRYPT");
+ return false;
+ }
+ enum {
+ kEncrypt,
+ kDecrypt,
+ } operation = t->HasInstruction("ENCRYPT") ? kEncrypt : kDecrypt;
+
+ std::string count;
+ std::vector<uint8_t> key, iv, in, result;
+ if (!t->GetAttribute(&count, "COUNT") ||
+ !t->GetBytes(&key, "KEY") ||
+ (ctx->has_iv && !t->GetBytes(&iv, "IV"))) {
+ return false;
+ }
+
+ const EVP_CIPHER *cipher = ctx->cipher;
+ if (operation == kEncrypt) {
+ if (!t->GetBytes(&in, "PLAINTEXT") ||
+ !CipherOperation(cipher, &result, true /* encrypt */, key, iv, in)) {
+ return false;
+ }
+ printf("%sCIPHERTEXT = %s\r\n\r\n", t->CurrentTestToString().c_str(),
+ EncodeHex(result.data(), result.size()).c_str());
+ } else {
+ if (!t->GetBytes(&in, "CIPHERTEXT") ||
+ !CipherOperation(cipher, &result, false /* decrypt */, key, iv, in)) {
+ return false;
+ }
+ printf("%sPLAINTEXT = %s\r\n\r\n", t->CurrentTestToString().c_str(),
+ EncodeHex(result.data(), result.size()).c_str());
+ }
+
+ // Check if sample response file matches.
+ if (ctx->response_sample) {
+ if (ctx->response_sample->ReadNext() != FileTest::kReadSuccess) {
+ t->PrintLine("invalid sample file");
+ return false;
+ }
+ std::string expected_count;
+ std::vector<uint8_t> expected_result;
+ if (!ctx->response_sample->GetAttribute(&expected_count, "COUNT") ||
+ count != expected_count ||
+ (operation == kEncrypt &&
+ (!ctx->response_sample->GetBytes(&expected_result, "CIPHERTEXT") ||
+ !t->ExpectBytesEqual(expected_result.data(), expected_result.size(),
+ result.data(), result.size()))) ||
+ (operation == kDecrypt &&
+ (!ctx->response_sample->GetBytes(&expected_result, "PLAINTEXT") ||
+ !t->ExpectBytesEqual(expected_result.data(), expected_result.size(),
+ result.data(), result.size())))) {
+ t->PrintLine("result doesn't match");
+ return false;
+ }
+ }
+
+ return true;
+}
+
+int main(int argc, char **argv) {
+ CRYPTO_library_init();
+
+ if (argc < 3 || argc > 4) {
+ fprintf(stderr, "usage: %s <cipher> <test file> [<sample response file>]\n",
+ argv[0]);
+ return 1;
+ }
+
+ const EVP_CIPHER *cipher = GetCipher(argv[1]);
+ if (cipher == nullptr) {
+ fprintf(stderr, "invalid cipher: %s\n", argv[1]);
+ return 1;
+ }
+ const std::string cipher_name(argv[1]);
+ const bool has_iv =
+ (cipher_name != "aes-128-ecb" &&
+ cipher_name != "aes-192-ecb" &&
+ cipher_name != "aes-256-ecb");
+
+ TestCtx ctx = {cipher, nullptr, has_iv};
+
+ if (argc == 4) {
+ ctx.response_sample.reset(new FileTest(argv[3]));
+ if (!ctx.response_sample->is_open()) {
+ return 1;
+ }
+ ctx.response_sample->SetIgnoreUnusedAttributes(true);
+ }
+
+ printf("# Generated by");
+ for (int i = 0; i < argc; i++) {
+ printf(" %s", argv[i]);
+ }
+ printf("\r\n\r\n");
+
+ return FileTestMainSilent(TestCipher, &ctx, argv[2]);
+}
diff --git a/crypto/fipsoracle/cavp_test_util.cc b/crypto/fipsoracle/cavp_test_util.cc
new file mode 100644
index 0000000..0f5b196
--- /dev/null
+++ b/crypto/fipsoracle/cavp_test_util.cc
@@ -0,0 +1,156 @@
+/* Copyright (c) 2017, Google Inc.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
+
+#include "cavp_test_util.h"
+
+
+std::string EncodeHex(const uint8_t *in, size_t in_len) {
+ static const char kHexDigits[] = "0123456789abcdef";
+ std::string ret;
+ ret.reserve(in_len * 2);
+ for (size_t i = 0; i < in_len; i++) {
+ ret += kHexDigits[in[i] >> 4];
+ ret += kHexDigits[in[i] & 0xf];
+ }
+ return ret;
+}
+
+const EVP_CIPHER *GetCipher(const std::string &name) {
+ if (name == "des-cbc") {
+ return EVP_des_cbc();
+ } else if (name == "des-ecb") {
+ return EVP_des_ecb();
+ } else if (name == "des-ede") {
+ return EVP_des_ede();
+ } else if (name == "des-ede3") {
+ return EVP_des_ede3();
+ } else if (name == "des-ede-cbc") {
+ return EVP_des_ede_cbc();
+ } else if (name == "des-ede3-cbc") {
+ return EVP_des_ede3_cbc();
+ } else if (name == "rc4") {
+ return EVP_rc4();
+ } else if (name == "aes-128-ecb") {
+ return EVP_aes_128_ecb();
+ } else if (name == "aes-256-ecb") {
+ return EVP_aes_256_ecb();
+ } else if (name == "aes-128-cbc") {
+ return EVP_aes_128_cbc();
+ } else if (name == "aes-128-gcm") {
+ return EVP_aes_128_gcm();
+ } else if (name == "aes-128-ofb") {
+ return EVP_aes_128_ofb();
+ } else if (name == "aes-192-cbc") {
+ return EVP_aes_192_cbc();
+ } else if (name == "aes-192-ctr") {
+ return EVP_aes_192_ctr();
+ } else if (name == "aes-192-ecb") {
+ return EVP_aes_192_ecb();
+ } else if (name == "aes-256-cbc") {
+ return EVP_aes_256_cbc();
+ } else if (name == "aes-128-ctr") {
+ return EVP_aes_128_ctr();
+ } else if (name == "aes-256-ctr") {
+ return EVP_aes_256_ctr();
+ } else if (name == "aes-256-gcm") {
+ return EVP_aes_256_gcm();
+ } else if (name == "aes-256-ofb") {
+ return EVP_aes_256_ofb();
+ }
+ return nullptr;
+}
+
+bool CipherOperation(const EVP_CIPHER *cipher, std::vector<uint8_t> *out,
+ bool encrypt, const std::vector<uint8_t> &key,
+ const std::vector<uint8_t> &iv,
+ const std::vector<uint8_t> &in) {
+ bssl::ScopedEVP_CIPHER_CTX ctx;
+ if (!EVP_CipherInit_ex(ctx.get(), cipher, nullptr, nullptr, nullptr,
+ encrypt ? 1 : 0)) {
+ return false;
+ }
+ if (!iv.empty() && iv.size() != EVP_CIPHER_CTX_iv_length(ctx.get())) {
+ return false;
+ }
+
+ int result_len1 = 0, result_len2;
+ *out = std::vector<uint8_t>(in.size());
+ if (!EVP_CIPHER_CTX_set_key_length(ctx.get(), key.size()) ||
+ !EVP_CipherInit_ex(ctx.get(), nullptr, nullptr, key.data(), iv.data(),
+ -1) ||
+ !EVP_CIPHER_CTX_set_padding(ctx.get(), 0) ||
+ !EVP_CipherUpdate(ctx.get(), out->data(), &result_len1, in.data(),
+ in.size()) ||
+ !EVP_CipherFinal_ex(ctx.get(), out->data() + result_len1, &result_len2)) {
+ return false;
+ }
+ out->resize(result_len1 + result_len2);
+
+ return true;
+}
+
+bool AEADEncrypt(const EVP_AEAD *aead, std::vector<uint8_t> *ct,
+ std::vector<uint8_t> *tag, size_t tag_len,
+ const std::vector<uint8_t> &key,
+ const std::vector<uint8_t> &pt,
+ const std::vector<uint8_t> &aad, std::vector<uint8_t> *iv) {
+ bssl::ScopedEVP_AEAD_CTX ctx;
+ if (!EVP_AEAD_CTX_init_with_direction(ctx.get(), aead, key.data(), key.size(),
+ tag->size(), evp_aead_seal)) {
+ return false;
+ }
+
+ std::vector<uint8_t> out;
+ out.resize(pt.size() + EVP_AEAD_max_overhead(aead));
+ size_t out_len;
+ if (!EVP_AEAD_CTX_seal(ctx.get(), out.data(), &out_len, out.size(),
+ nullptr /* iv */, 0 /* iv_len */, pt.data(), pt.size(),
+ aad.data(), aad.size())) {
+ return false;
+ }
+
+ static const size_t iv_len = EVP_AEAD_nonce_length(aead);
+ iv->assign(out.begin(), out.begin() + iv_len);
+ ct->assign(out.begin() + iv_len, out.end() - tag_len);
+ tag->assign(out.end() - tag_len, out.end());
+
+ return true;
+}
+
+bool AEADDecrypt(const EVP_AEAD *aead, std::vector<uint8_t> *pt,
+ std::vector<uint8_t> *aad, size_t pt_len, size_t aad_len,
+ const std::vector<uint8_t> &key,
+ const std::vector<uint8_t> &ct,
+ const std::vector<uint8_t> &tag, std::vector<uint8_t> &iv) {
+ bssl::ScopedEVP_AEAD_CTX ctx;
+ if (!EVP_AEAD_CTX_init_with_direction(ctx.get(), aead, key.data(), key.size(),
+ tag.size(), evp_aead_open)) {
+ return false;
+ }
+ std::vector<uint8_t> in = iv;
+ in.reserve(in.size() + ct.size() + tag.size());
+ in.insert(in.end(), ct.begin(), ct.end());
+ in.insert(in.end(), tag.begin(), tag.end());
+
+ pt->resize(pt_len);
+ aad->resize(aad_len);
+ size_t out_pt_len;
+ if (!EVP_AEAD_CTX_open(ctx.get(), pt->data(), &out_pt_len, pt->size(),
+ nullptr /* iv */, 0 /* iv_len */, in.data(), in.size(),
+ aad->data(), aad->size()) ||
+ out_pt_len != pt_len) {
+ return false;
+ }
+ return true;
+}
diff --git a/crypto/fipsoracle/cavp_test_util.h b/crypto/fipsoracle/cavp_test_util.h
new file mode 100644
index 0000000..6b4966c
--- /dev/null
+++ b/crypto/fipsoracle/cavp_test_util.h
@@ -0,0 +1,48 @@
+/* Copyright (c) 2017, Google Inc.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
+
+#ifndef OPENSSL_HEADER_CRYPTO_FIPSMODULE_CAVP_TEST_UTIL_H
+#define OPENSSL_HEADER_CRYPTO_FIPSMODULE_CAVP_TEST_UTIL_H
+
+#include <stdlib.h>
+#include <string>
+#include <vector>
+
+#include <openssl/aead.h>
+#include <openssl/cipher.h>
+
+
+std::string EncodeHex(const uint8_t *in, size_t in_len);
+
+const EVP_CIPHER *GetCipher(const std::string &name);
+
+bool CipherOperation(const EVP_CIPHER *cipher, std::vector<uint8_t> *out,
+ bool encrypt, const std::vector<uint8_t> &key,
+ const std::vector<uint8_t> &iv,
+ const std::vector<uint8_t> &in);
+
+bool AEADEncrypt(const EVP_AEAD *aead, std::vector<uint8_t> *ct,
+ std::vector<uint8_t> *tag, size_t tag_len,
+ const std::vector<uint8_t> &key,
+ const std::vector<uint8_t> &pt,
+ const std::vector<uint8_t> &aad, std::vector<uint8_t> *iv);
+
+bool AEADDecrypt(const EVP_AEAD *aead, std::vector<uint8_t> *pt,
+ std::vector<uint8_t> *aad, size_t pt_len, size_t aad_len,
+ const std::vector<uint8_t> &key,
+ const std::vector<uint8_t> &ct,
+ const std::vector<uint8_t> &tag, std::vector<uint8_t> &iv);
+
+
+#endif // OPENSSL_HEADER_CRYPTO_FIPSMODULE_CAVP_TEST_UTIL_H