1
0
mirror of https://github.com/wolfSSL/wolfssl.git synced 2026-10-24 04:09:07 +03:00
Files
wolfssl/tests/api/test_ed448.h
Tobias Frauenschläger 478847d81e Support device private keys by id or label for Ed25519 and Ed448
RSA, ECC and the PQC signature algorithms can reference a private key
held by a crypto callback device through an id or label
(WOLF_PRIVATE_KEY_ID), both in wolfCrypt and through
wolfSSL_CTX_use_PrivateKey_Id / _Label. Ed25519 and Ed448 already
dispatch sign and verify through crypto callbacks but had no way to
name such a key, so a TLS server with an Ed25519 or Ed448 certificate
could not use a device key: no key object could be created for it and
wolfSSL_CTX_check_private_key failed.

Add wc_ed25519_init_id, wc_ed25519_init_label, wc_ed448_init_id and
wc_ed448_init_label, with the id and label stored at the end of the key
structures and limited to 32 bytes, like ECC. Code outside ed25519.c and
ed448.c tests ED25519_MAX_ID_LEN and ED448_MAX_ID_LEN rather than
WOLF_PRIVATE_KEY_ID, because FIPS v6 builds use pinned ed25519.h and
ed448.h that have neither the fields nor the functions.

wc_ed25519_make_public and wc_ed448_make_public no longer reject a key
named by id or label before asking the device, so a device can derive
the public key of a key it holds. When the device declines, or the key
has no device, they still return ECC_PRIV_KEY_E rather than deriving
from an empty software key.

In the TLS layer, CreateDevPrivateKey and DecodePrivateKey_ex build
Ed25519 and Ed448 device keys for ed25519_sa_algo and ed448_sa_algo.
check_cert_key_dev imports the certificate's public key into the device
key and validates the pair through the Ed25519 or Ed448 check_key
callback. It calls the callback directly rather than wc_ed*_check_key,
whose software fallback would only validate the public key of a device
key, so a device that declines the check fails it. Builds without
Ed25519 or Ed448 key import cannot do that, so they keep failing the
check as before.

A device key named by id or label has no private key in software, so
the check_key callbacks previously reported checkPriv as 0 for it and
a device would only have validated the public key. checkPriv is now
also set when the key carries an id or label.

Tests cover the init argument checks, make_public on a device key, and a
TLS 1.3 test per curve where a callback device holds the server key: the
pair check succeeds for both id and label, fails against a certificate
for another key, with an id longer than the key can hold or when the
device declines the check, and the handshake is signed by the device
after one more pair check when the certificate public key is loaded into
the device key.
2026-10-12 21:36:01 -07:00

81 lines
3.6 KiB
C

/* test_ed448.h
*
* Copyright (C) 2006-2026 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#ifndef WOLFCRYPT_TEST_ED448_H
#define WOLFCRYPT_TEST_ED448_H
#include <tests/api/api_decl.h>
int test_wc_ed448_make_key(void);
int test_wc_ed448_make_public_stores_pub(void);
int test_wc_ed448_init(void);
int test_wc_ed448_init_id(void);
int test_wc_ed448_sign_msg(void);
int test_wc_ed448_verify_sig_S_range(void);
int test_wc_ed448_sign_msg_pubonly_fails(void);
int test_wc_ed448_import_public(void);
int test_wc_ed448_import_private_key(void);
int test_wc_ed448_export(void);
int test_wc_ed448_size(void);
int test_wc_ed448_exportKey(void);
int test_wc_Ed448PublicKeyToDer(void);
int test_wc_Ed448KeyToDer(void);
int test_wc_Ed448PrivateKeyToDer(void);
int test_wc_Ed448KeyToDer_oneasymkey_version(void);
int test_wc_Ed448PrivateKeyDecode_ex(void);
int test_wc_ed448_reject_small_order_keys(void);
int test_wc_ed448_reject_noncanonical_y(void);
int test_wc_Ed448DecisionCoverage(void);
int test_wc_Ed448FeatureCoverage(void);
int test_wc_ed448_import_private_only(void);
int test_wc_ed448_check_key_decisions(void);
int test_wc_ed448_cryptocb(void);
int test_wc_ed448_make_public_dev_key(void);
#define TEST_ED448_DECLS \
TEST_DECL_GROUP("ed448", test_wc_ed448_make_key), \
TEST_DECL_GROUP("ed448", test_wc_ed448_make_public_stores_pub), \
TEST_DECL_GROUP("ed448", test_wc_ed448_init), \
TEST_DECL_GROUP("ed448", test_wc_ed448_init_id), \
TEST_DECL_GROUP("ed448", test_wc_ed448_sign_msg), \
TEST_DECL_GROUP("ed448", test_wc_ed448_verify_sig_S_range), \
TEST_DECL_GROUP("ed448", test_wc_ed448_sign_msg_pubonly_fails), \
TEST_DECL_GROUP("ed448", test_wc_ed448_import_public), \
TEST_DECL_GROUP("ed448", test_wc_ed448_import_private_key), \
TEST_DECL_GROUP("ed448", test_wc_ed448_export), \
TEST_DECL_GROUP("ed448", test_wc_ed448_size), \
TEST_DECL_GROUP("ed448", test_wc_ed448_exportKey), \
TEST_DECL_GROUP("ed448", test_wc_Ed448PublicKeyToDer), \
TEST_DECL_GROUP("ed448", test_wc_Ed448KeyToDer), \
TEST_DECL_GROUP("ed448", test_wc_Ed448PrivateKeyToDer), \
TEST_DECL_GROUP("ed448", test_wc_Ed448KeyToDer_oneasymkey_version), \
TEST_DECL_GROUP("ed448", test_wc_ed448_reject_small_order_keys), \
TEST_DECL_GROUP("ed448", test_wc_ed448_reject_noncanonical_y), \
TEST_DECL_GROUP("ed448", test_wc_Ed448DecisionCoverage), \
TEST_DECL_GROUP("ed448", test_wc_Ed448FeatureCoverage), \
TEST_DECL_GROUP("ed448", test_wc_ed448_import_private_only), \
TEST_DECL_GROUP("ed448", test_wc_ed448_check_key_decisions), \
TEST_DECL_GROUP("ed448", test_wc_Ed448PrivateKeyDecode_ex), \
TEST_DECL_GROUP("ed448", test_wc_ed448_cryptocb), \
TEST_DECL_GROUP("ed448", test_wc_ed448_make_public_dev_key)
#endif /* WOLFCRYPT_TEST_ED448_H */