/*
* Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
typedef struct {
const char *curvename;
/* seed */
const unsigned char *ikm;
size_t ikmlen;
/* expected public key */
const unsigned char *pub;
size_t publen;
/* expected private key */
const unsigned char *priv;
size_t privlen;
} TEST_DERIVEKEY_DATA;
typedef struct {
const char *curve;
/* The seed for the senders ephemeral key */
const unsigned char *ikmE;
size_t ikmElen;
/* Recipient key */
const unsigned char *rpub;
size_t rpublen;
const unsigned char *rpriv;
size_t rprivlen;
/* The senders generated ephemeral public key */
const unsigned char *expected_enc;
size_t expected_enclen;
/* The generated shared secret */
const unsigned char *expected_secret;
size_t expected_secretlen;
/* Senders Auth key */
const unsigned char *spub;
size_t spublen;
const unsigned char *spriv;
size_t sprivlen;
} TEST_ENCAPDATA;
static const char *dhkem_supported_curves[] = {
"P-256",
"P-384",
"P-521",
#ifndef OPENSSL_NO_ECX
"X25519",
"X448",
#endif
};
/* TEST vectors extracted from RFC 9180 */
/* Base test values */
#ifndef OPENSSL_NO_ECX
static const unsigned char x25519_ikme[] = {
0x72, 0x68, 0x60, 0x0d, 0x40, 0x3f, 0xce, 0x43,
0x15, 0x61, 0xae, 0xf5, 0x83, 0xee, 0x16, 0x13,
0x52, 0x7c, 0xff, 0x65, 0x5c, 0x13, 0x43, 0xf2,
0x98, 0x12, 0xe6, 0x67, 0x06, 0xdf, 0x32, 0x34
};
static const unsigned char x25519_ikme_priv[] = {
0x52, 0xc4, 0xa7, 0x58, 0xa8, 0x02, 0xcd, 0x8b,
0x93, 0x6e, 0xce, 0xea, 0x31, 0x44, 0x32, 0x79,
0x8d, 0x5b, 0xaf, 0x2d, 0x7e, 0x92, 0x35, 0xdc,
0x08, 0x4a, 0xb1, 0xb9, 0xcf, 0xa2, 0xf7, 0x36
};
static const unsigned char x25519_ikme_pub[] = {
0x37, 0xfd, 0xa3, 0x56, 0x7b, 0xdb, 0xd6, 0x28,
0xe8, 0x86, 0x68, 0xc3, 0xc8, 0xd7, 0xe9, 0x7d,
0x1d, 0x12, 0x53, 0xb6, 0xd4, 0xea, 0x6d, 0x44,
0xc1, 0x50, 0xf7, 0x41, 0xf1, 0xbf, 0x44, 0x31
};
static const unsigned char x25519_rpub[] = {
0x39, 0x48, 0xcf, 0xe0, 0xad, 0x1d, 0xdb, 0x69,
0x5d, 0x78, 0x0e, 0x59, 0x07, 0x71, 0x95, 0xda,
0x6c, 0x56, 0x50, 0x6b, 0x02, 0x73, 0x29, 0x79,
0x4a, 0xb0, 0x2b, 0xca, 0x80, 0x81, 0x5c, 0x4d
};
static const unsigned char x25519_rpriv[] = {
0x46, 0x12, 0xc5, 0x50, 0x26, 0x3f, 0xc8, 0xad,
0x58, 0x37, 0x5d, 0xf3, 0xf5, 0x57, 0xaa, 0xc5,
0x31, 0xd2, 0x68, 0x50, 0x90, 0x3e, 0x55, 0xa9,
0xf2, 0x3f, 0x21, 0xd8, 0x53, 0x4e, 0x8a, 0xc8
};
static const unsigned char x25519_expected_enc[] = {
0x37, 0xfd, 0xa3, 0x56, 0x7b, 0xdb, 0xd6, 0x28,
0xe8, 0x86, 0x68, 0xc3, 0xc8, 0xd7, 0xe9, 0x7d,
0x1d, 0x12, 0x53, 0xb6, 0xd4, 0xea, 0x6d, 0x44,
0xc1, 0x50, 0xf7, 0x41, 0xf1, 0xbf, 0x44, 0x31
};
static const unsigned char x25519_expected_secret[] = {
0xfe, 0x0e, 0x18, 0xc9, 0xf0, 0x24, 0xce, 0x43,
0x79, 0x9a, 0xe3, 0x93, 0xc7, 0xe8, 0xfe, 0x8f,
0xce, 0x9d