mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-10-24 04:09:07 +03:00
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.
75 lines
3.4 KiB
C
75 lines
3.4 KiB
C
/* test_ed25519.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_ED25519_H
|
|
#define WOLFCRYPT_TEST_ED25519_H
|
|
|
|
#include <tests/api/api_decl.h>
|
|
|
|
int test_wc_ed25519_make_key(void);
|
|
int test_wc_ed25519_init(void);
|
|
int test_wc_ed25519_init_id(void);
|
|
int test_wc_ed25519_sign_msg(void);
|
|
int test_wc_ed25519_sign_msg_pubonly_fails(void);
|
|
int test_wc_ed25519_import_public(void);
|
|
int test_wc_ed25519_import_private_key(void);
|
|
int test_wc_ed25519_export(void);
|
|
int test_wc_ed25519_size(void);
|
|
int test_wc_ed25519_exportKey(void);
|
|
int test_wc_Ed25519PublicKeyToDer(void);
|
|
int test_wc_Ed25519KeyToDer(void);
|
|
int test_wc_Ed25519PrivateKeyToDer(void);
|
|
int test_wc_Ed25519KeyToDer_oneasymkey_version(void);
|
|
int test_wc_Ed25519PrivateKeyDecode_ex(void);
|
|
int test_wc_ed25519_reject_small_order_keys(void);
|
|
int test_wc_ed25519_sign_verify_ctx_ph(void);
|
|
int test_wc_ed25519_verify_streaming(void);
|
|
int test_wc_ed25519_check_key_edgecases(void);
|
|
int test_wc_ed25519_import_variants(void);
|
|
int test_wc_ed25519_make_public_argchecks(void);
|
|
int test_wc_ed25519_make_public_dev_key(void);
|
|
|
|
#define TEST_ED25519_DECLS \
|
|
TEST_DECL_GROUP("ed25519", test_wc_ed25519_make_key), \
|
|
TEST_DECL_GROUP("ed25519", test_wc_ed25519_init), \
|
|
TEST_DECL_GROUP("ed25519", test_wc_ed25519_init_id), \
|
|
TEST_DECL_GROUP("ed25519", test_wc_ed25519_sign_msg), \
|
|
TEST_DECL_GROUP("ed25519", test_wc_ed25519_sign_msg_pubonly_fails), \
|
|
TEST_DECL_GROUP("ed25519", test_wc_ed25519_import_public), \
|
|
TEST_DECL_GROUP("ed25519", test_wc_ed25519_import_private_key), \
|
|
TEST_DECL_GROUP("ed25519", test_wc_ed25519_export), \
|
|
TEST_DECL_GROUP("ed25519", test_wc_ed25519_size), \
|
|
TEST_DECL_GROUP("ed25519", test_wc_ed25519_exportKey), \
|
|
TEST_DECL_GROUP("ed25519", test_wc_Ed25519PublicKeyToDer), \
|
|
TEST_DECL_GROUP("ed25519", test_wc_Ed25519KeyToDer), \
|
|
TEST_DECL_GROUP("ed25519", test_wc_Ed25519PrivateKeyToDer), \
|
|
TEST_DECL_GROUP("ed25519", test_wc_Ed25519KeyToDer_oneasymkey_version), \
|
|
TEST_DECL_GROUP("ed25519", test_wc_ed25519_reject_small_order_keys), \
|
|
TEST_DECL_GROUP("ed25519", test_wc_ed25519_sign_verify_ctx_ph), \
|
|
TEST_DECL_GROUP("ed25519", test_wc_ed25519_verify_streaming), \
|
|
TEST_DECL_GROUP("ed25519", test_wc_ed25519_check_key_edgecases), \
|
|
TEST_DECL_GROUP("ed25519", test_wc_ed25519_import_variants), \
|
|
TEST_DECL_GROUP("ed25519", test_wc_ed25519_make_public_argchecks), \
|
|
TEST_DECL_GROUP("ed25519", test_wc_ed25519_make_public_dev_key), \
|
|
TEST_DECL_GROUP("ed25519", test_wc_Ed25519PrivateKeyDecode_ex)
|
|
|
|
#endif /* WOLFCRYPT_TEST_ED25519_H */
|