#include <cstdint>
#include <vector>
#include <string.h>
#include <gtest/gtest.h>
#include <openssl/base.h>
#include <openssl/bytestring.h>
#include <openssl/mem.h>
#include <openssl/mlkem.h>
#include "../keccak/internal.h"
#include "../test/file_test.h"
#include "../test/test_util.h"
#include "./internal.h"
namespace {
template <typename T>
std::vector<uint8_t> Marshal(int (*marshal_func)(CBB *, const T *),
const T *t) { … }
template <typename PUBLIC_KEY, size_t PUBLIC_KEY_BYTES, typename PRIVATE_KEY,
size_t PRIVATE_KEY_BYTES,
void (*GENERATE)(uint8_t *, uint8_t *, PRIVATE_KEY *),
int (*FROM_SEED)(PRIVATE_KEY *, const uint8_t *, size_t),
void PUBLIC_FROM_PRIVATE(PUBLIC_KEY *, const PRIVATE_KEY *),
int (*PARSE_PUBLIC)(PUBLIC_KEY *, CBS *),
int (*MARSHAL_PUBLIC)(CBB *, const PUBLIC_KEY *),
int (*PARSE_PRIVATE)(PRIVATE_KEY *, CBS *),
int (*MARSHAL_PRIVATE)(CBB *, const PRIVATE_KEY *),
size_t CIPHERTEXT_BYTES,
void (*ENCAP)(uint8_t *, uint8_t *, const PUBLIC_KEY *),
int (*DECAP)(uint8_t *, const uint8_t *, size_t, const PRIVATE_KEY *)>
void BasicTest() { … }
TEST(MLKEMTest, Basic768) { … }
TEST(MLKEMTest, Basic1024) { … }
template <typename PUBLIC_KEY, size_t PUBLIC_KEY_BYTES, typename PRIVATE_KEY,
int (*MARSHAL_PRIVATE)(CBB *, const PRIVATE_KEY *),
void (*GENERATE)(uint8_t *, PRIVATE_KEY *, const uint8_t *)>
void MLKEMKeyGenFileTest(FileTest *t) { … }
TEST(MLKEMTest, KeyGen768TestVectors) { … }
TEST(MLKEMTest, KeyGen1024TestVectors) { … }
template <typename PUBLIC_KEY, size_t PUBLIC_KEY_BYTES, typename PRIVATE_KEY,
int (*MARSHAL_PRIVATE)(CBB *, const PRIVATE_KEY *),
void (*GENERATE)(uint8_t *, PRIVATE_KEY *, const uint8_t *)>
void MLKEMNistKeyGenFileTest(FileTest *t) { … }
TEST(MLKEMTest, NISTKeyGen768TestVectors) { … }
TEST(MLKEMTest, NISTKeyGen1024TestVectors) { … }
template <typename PUBLIC_KEY, size_t PUBLIC_KEY_BYTES,
int (*PARSE_PUBLIC)(PUBLIC_KEY *, CBS *), size_t CIPHERTEXT_BYTES,
void (*ENCAP)(uint8_t *, uint8_t *, const PUBLIC_KEY *,
const uint8_t *)>
void MLKEMEncapFileTest(FileTest *t) { … }
TEST(MLKEMTest, Encap768TestVectors) { … }
TEST(MLKEMTest, Encap1024TestVectors) { … }
template <typename PRIVATE_KEY, size_t PRIVATE_KEY_BYTES,
int (*PARSE_PRIVATE)(PRIVATE_KEY *, CBS *), size_t CIPHERTEXT_BYTES,
int (*DECAP)(uint8_t *, const uint8_t *, size_t, const PRIVATE_KEY *)>
void MLKEMDecapFileTest(FileTest *t) { … }
TEST(MLKEMTest, Decap768TestVectors) { … }
TEST(MLKEMTest, Decap1024TestVectors) { … }
template <typename PRIVATE_KEY, int (*PARSE_PRIVATE)(PRIVATE_KEY *, CBS *),
int (*DECAP)(uint8_t *, const uint8_t *, size_t, const PRIVATE_KEY *)>
void MLKEMNistDecapFileTest(FileTest *t) { … }
TEST(MLKEMTest, NistDecap768TestVectors) { … }
TEST(MLKEMTest, NistDecap1024TestVectors) { … }
template <
typename PUBLIC_KEY, size_t PUBLIC_KEY_BYTES, typename PRIVATE_KEY,
size_t PRIVATE_KEY_BYTES,
void (*GENERATE)(uint8_t *, PRIVATE_KEY *, const uint8_t *),
void (*TO_PUBLIC)(PUBLIC_KEY *, const PRIVATE_KEY *),
int (*MARSHAL_PRIVATE)(CBB *, const PRIVATE_KEY *), size_t CIPHERTEXT_BYTES,
void (*ENCAP)(uint8_t *, uint8_t *, const PUBLIC_KEY *, const uint8_t *),
int (*DECAP)(uint8_t *, const uint8_t *, size_t, const PRIVATE_KEY *)>
void IteratedTest(uint8_t out[32]) { … }
TEST(MLKEMTest, Iterate768) { … }
TEST(MLKEMTest, Iterate1024) { … }
}