mirror of https://github.com/wolfSSL/wolfssl.git
Split out tests: random, wolfmath, public key
Improved testing of random APIs. wolfmath tests moved out. Public key algorithm testing moved out: RSA, DSA, DH, ECC, SM2, Curve25519, Ed25519, Curve448, Ed448, ML-DSA. Signature API tests moved out. Fix for OCSP testing to ensure RSA is available. Added group names to API test cases. Can select groups to run with --group <name>. --groups lists all known group names. Added option to stop API testing on first failure: --stopOnFail.pull/8560/head
parent
bc7fbee539
commit
663ca29a5d
|
@ -2536,7 +2536,20 @@ if(WOLFSSL_EXAMPLES)
|
|||
tests/api/test_ascon.c
|
||||
tests/api/test_sm4.c
|
||||
tests/api/test_wc_encrypt.c
|
||||
tests/api/test_random.c
|
||||
tests/api/test_wolfmath.c
|
||||
tests/api/test_rsa.c
|
||||
tests/api/test_dsa.c
|
||||
tests/api/test_dh.c
|
||||
tests/api/test_ecc.c
|
||||
tests/api/test_sm2.c
|
||||
tests/api/test_curve25519.c
|
||||
tests/api/test_ed25519.c
|
||||
tests/api/test_curve448.c
|
||||
tests/api/test_ed448.c
|
||||
tests/api/test_mlkem.c
|
||||
tests/api/test_mldsa.c
|
||||
tests/api/test_signature.c
|
||||
tests/api/test_dtls.c
|
||||
tests/api/test_ocsp.c
|
||||
tests/api/test_evp.c
|
||||
|
|
23549
tests/api.c
23549
tests/api.c
File diff suppressed because it is too large
Load Diff
161
tests/api/api.h
161
tests/api/api.h
|
@ -23,6 +23,16 @@
|
|||
#define WOLFCRYPT_TEST_API_H
|
||||
|
||||
|
||||
/* force enable test buffers */
|
||||
#ifndef USE_CERT_BUFFERS_2048
|
||||
#define USE_CERT_BUFFERS_2048
|
||||
#endif
|
||||
#ifndef USE_CERT_BUFFERS_256
|
||||
#define USE_CERT_BUFFERS_256
|
||||
#endif
|
||||
#include <wolfssl/certs_test.h>
|
||||
|
||||
|
||||
#ifndef HEAP_HINT
|
||||
#define HEAP_HINT NULL
|
||||
#endif
|
||||
|
@ -32,6 +42,126 @@
|
|||
#define TEST_STRING_SZ 25
|
||||
|
||||
|
||||
#ifndef ONEK_BUF
|
||||
#define ONEK_BUF 1024
|
||||
#endif
|
||||
#ifndef TWOK_BUF
|
||||
#define TWOK_BUF 2048
|
||||
#endif
|
||||
#ifndef FOURK_BUF
|
||||
#define FOURK_BUF 4096
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef NO_RSA
|
||||
#define GEN_BUF 294
|
||||
|
||||
#if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
|
||||
(!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
|
||||
(defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
|
||||
#define TEST_RSA_BITS 1024
|
||||
#else
|
||||
#define TEST_RSA_BITS 2048
|
||||
#endif
|
||||
#define TEST_RSA_BYTES (TEST_RSA_BITS/8)
|
||||
#endif /* !NO_RSA */
|
||||
|
||||
#if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
|
||||
/* In FIPS builds, wc_MakeRsaKey() will return an error if it cannot find
|
||||
* a probable prime in 5*(modLen/2) attempts. In non-FIPS builds, it keeps
|
||||
* trying until it gets a probable prime. */
|
||||
#ifdef HAVE_FIPS
|
||||
extern int MakeRsaKeyRetry(RsaKey* key, int size, long e, WC_RNG* rng);
|
||||
#define MAKE_RSA_KEY(a, b, c, d) MakeRsaKeyRetry(a, b, c, d)
|
||||
#else
|
||||
#define MAKE_RSA_KEY(a, b, c, d) wc_MakeRsaKey(a, b, c, d)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef NO_DSA
|
||||
#ifndef DSA_SIG_SIZE
|
||||
#define DSA_SIG_SIZE 40
|
||||
#endif
|
||||
#ifndef MAX_DSA_PARAM_SIZE
|
||||
#define MAX_DSA_PARAM_SIZE 256
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ECC
|
||||
#ifndef ECC_ASN963_MAX_BUF_SZ
|
||||
#define ECC_ASN963_MAX_BUF_SZ 133
|
||||
#endif
|
||||
#ifndef ECC_PRIV_KEY_BUF
|
||||
#define ECC_PRIV_KEY_BUF 66 /* For non user defined curves. */
|
||||
#endif
|
||||
/* ecc key sizes: 14, 16, 20, 24, 28, 30, 32, 40, 48, 64 */
|
||||
/* logic to choose right key ECC size */
|
||||
#if (defined(HAVE_ECC112) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 112
|
||||
#define KEY14 14
|
||||
#else
|
||||
#define KEY14 32
|
||||
#endif
|
||||
#if (defined(HAVE_ECC128) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 128
|
||||
#define KEY16 16
|
||||
#else
|
||||
#define KEY16 32
|
||||
#endif
|
||||
#if (defined(HAVE_ECC160) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 160
|
||||
#define KEY20 20
|
||||
#else
|
||||
#define KEY20 32
|
||||
#endif
|
||||
#if (defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 192
|
||||
#define KEY24 24
|
||||
#else
|
||||
#define KEY24 32
|
||||
#endif
|
||||
#if defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)
|
||||
#define KEY28 28
|
||||
#else
|
||||
#define KEY28 32
|
||||
#endif
|
||||
#if defined(HAVE_ECC239) || defined(HAVE_ALL_CURVES)
|
||||
#define KEY30 30
|
||||
#else
|
||||
#define KEY30 32
|
||||
#endif
|
||||
#define KEY32 32
|
||||
#if defined(HAVE_ECC320) || defined(HAVE_ALL_CURVES)
|
||||
#define KEY40 40
|
||||
#else
|
||||
#define KEY40 32
|
||||
#endif
|
||||
#if defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)
|
||||
#define KEY48 48
|
||||
#else
|
||||
#define KEY48 32
|
||||
#endif
|
||||
#if defined(HAVE_ECC512) || defined(HAVE_ALL_CURVES)
|
||||
#define KEY64 64
|
||||
#else
|
||||
#define KEY64 32
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_COMP_KEY)
|
||||
#if !defined(NOCOMP)
|
||||
#define NOCOMP 0
|
||||
#endif
|
||||
#else
|
||||
#if !defined(COMP)
|
||||
#define COMP 1
|
||||
#endif
|
||||
#endif
|
||||
#if !defined(DER_SZ)
|
||||
#define DER_SZ(ks) ((ks) * 2 + 1)
|
||||
#endif
|
||||
#endif /* HAVE_ECC */
|
||||
#ifndef WOLFSSL_HAVE_ECC_KEY_GET_PRIV
|
||||
/* FIPS build has replaced ecc.h. */
|
||||
#define wc_ecc_key_get_priv(key) (&((key)->k))
|
||||
#define WOLFSSL_HAVE_ECC_KEY_GET_PRIV
|
||||
#endif
|
||||
|
||||
/* Returns the result based on whether check is true.
|
||||
*
|
||||
* @param [in] check Condition for success.
|
||||
|
@ -53,6 +183,37 @@
|
|||
((check) ? TEST_SUCCESS : TEST_FAIL)
|
||||
#endif /* DEBUG_WOLFSSL_VERBOSE */
|
||||
|
||||
#define PRINT_DATA(name, data, len) \
|
||||
do { \
|
||||
int ii; \
|
||||
fprintf(stderr, "%s\n", name); \
|
||||
for (ii = 0; ii < (int)(len); ii++) { \
|
||||
if ((ii % 8) == 0) \
|
||||
fprintf(stderr, " "); \
|
||||
fprintf(stderr, "0x%02x,", (data)[ii]); \
|
||||
if ((ii % 8) == 7) \
|
||||
fprintf(stderr, "\n"); \
|
||||
else \
|
||||
fprintf(stderr, " "); \
|
||||
} \
|
||||
fprintf(stderr, "\n"); \
|
||||
} while (0)
|
||||
|
||||
#define PRINT_DATA_STR(name, data, len) \
|
||||
do { \
|
||||
int ii; \
|
||||
fprintf(stderr, "%s\n", name); \
|
||||
for (ii = 0; ii < (int)(len); ii++) { \
|
||||
if ((ii % 8) == 0) \
|
||||
fprintf(stderr, " \""); \
|
||||
fprintf(stderr, "\\x%02x", (data)[ii]); \
|
||||
if ((ii % 8) == 7) \
|
||||
fprintf(stderr, "\"\n"); \
|
||||
} \
|
||||
if ((ii % 8) != 0) \
|
||||
fprintf(stderr, "\""); \
|
||||
fprintf(stderr, "\n"); \
|
||||
} while (0)
|
||||
|
||||
typedef struct testVector {
|
||||
const char* input;
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/* api_decl.h
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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_API_DECL_H
|
||||
#define WOLFCRYPT_TEST_API_DECL_H
|
||||
|
||||
typedef int (*TEST_FUNC)(void);
|
||||
typedef struct {
|
||||
const char *group;
|
||||
const char *name;
|
||||
TEST_FUNC func;
|
||||
byte run:1;
|
||||
byte fail:1;
|
||||
} TEST_CASE;
|
||||
|
||||
#define TEST_DECL(func) { NULL, #func, func, 0, 0 }
|
||||
#define TEST_DECL_GROUP(group, func) { group, #func, func, 0, 0 }
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_API_DECL_H */
|
||||
|
|
@ -30,8 +30,23 @@ tests_unit_test_SOURCES += tests/api/test_aes.c
|
|||
tests_unit_test_SOURCES += tests/api/test_ascon.c
|
||||
tests_unit_test_SOURCES += tests/api/test_sm4.c
|
||||
tests_unit_test_SOURCES += tests/api/test_wc_encrypt.c
|
||||
# Signature Algorithm
|
||||
# Random
|
||||
tests_unit_test_SOURCES += tests/api/test_random.c
|
||||
# MP
|
||||
tests_unit_test_SOURCES += tests/api/test_wolfmath.c
|
||||
# Public Key Algorithm
|
||||
tests_unit_test_SOURCES += tests/api/test_rsa.c
|
||||
tests_unit_test_SOURCES += tests/api/test_dsa.c
|
||||
tests_unit_test_SOURCES += tests/api/test_dh.c
|
||||
tests_unit_test_SOURCES += tests/api/test_ecc.c
|
||||
tests_unit_test_SOURCES += tests/api/test_sm2.c
|
||||
tests_unit_test_SOURCES += tests/api/test_curve25519.c
|
||||
tests_unit_test_SOURCES += tests/api/test_ed25519.c
|
||||
tests_unit_test_SOURCES += tests/api/test_curve448.c
|
||||
tests_unit_test_SOURCES += tests/api/test_ed448.c
|
||||
tests_unit_test_SOURCES += tests/api/test_mlkem.c
|
||||
tests_unit_test_SOURCES += tests/api/test_mldsa.c
|
||||
tests_unit_test_SOURCES += tests/api/test_signature.c
|
||||
# TLS Protocol
|
||||
tests_unit_test_SOURCES += tests/api/test_dtls.c
|
||||
# TLS Feature
|
||||
|
@ -40,6 +55,7 @@ tests_unit_test_SOURCES += tests/api/test_evp.c
|
|||
endif
|
||||
|
||||
EXTRA_DIST += tests/api/api.h
|
||||
EXTRA_DIST += tests/api/api_decl.h
|
||||
EXTRA_DIST += tests/api/test_md2.h
|
||||
EXTRA_DIST += tests/api/test_md4.h
|
||||
EXTRA_DIST += tests/api/test_md5.h
|
||||
|
@ -66,7 +82,20 @@ EXTRA_DIST += tests/api/test_ascon.h
|
|||
EXTRA_DIST += tests/api/test_sm4.h
|
||||
EXTRA_DIST += tests/api/test_ascon_kats.h
|
||||
EXTRA_DIST += tests/api/test_wc_encrypt.h
|
||||
EXTRA_DIST += tests/api/test_random.h
|
||||
EXTRA_DIST += tests/api/test_wolfmath.h
|
||||
EXTRA_DIST += tests/api/test_rsa.h
|
||||
EXTRA_DIST += tests/api/test_dsa.h
|
||||
EXTRA_DIST += tests/api/test_dh.h
|
||||
EXTRA_DIST += tests/api/test_ecc.h
|
||||
EXTRA_DIST += tests/api/test_sm2.h
|
||||
EXTRA_DIST += tests/api/test_curve25519.h
|
||||
EXTRA_DIST += tests/api/test_ed25519.h
|
||||
EXTRA_DIST += tests/api/test_curve448.h
|
||||
EXTRA_DIST += tests/api/test_ed448.h
|
||||
EXTRA_DIST += tests/api/test_mlkem.h
|
||||
EXTRA_DIST += tests/api/test_mldsa.h
|
||||
EXTRA_DIST += tests/api/test_signature.h
|
||||
EXTRA_DIST += tests/api/test_dtls.h
|
||||
EXTRA_DIST += tests/api/test_ocsp.h
|
||||
EXTRA_DIST += tests/api/test_ocsp_test_blobs.h
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef WOLFCRYPT_TEST_AES_H
|
||||
#define WOLFCRYPT_TEST_AES_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_AesSetKey(void);
|
||||
int test_wc_AesSetIV(void);
|
||||
int test_wc_AesCbcEncryptDecrypt(void);
|
||||
|
@ -30,8 +32,6 @@ int test_wc_AesGcmSetKey(void);
|
|||
int test_wc_AesGcmEncryptDecrypt(void);
|
||||
int test_wc_AesGcmMixedEncDecLongIV(void);
|
||||
int test_wc_AesGcmStream(void);
|
||||
int test_wc_GmacSetKey(void);
|
||||
int test_wc_GmacUpdate(void);
|
||||
int test_wc_AesCcmSetKey(void);
|
||||
int test_wc_AesCcmEncryptDecrypt(void);
|
||||
#if defined(WOLFSSL_AES_EAX) && \
|
||||
|
@ -41,4 +41,31 @@ int test_wc_AesEaxEncryptAuth(void);
|
|||
int test_wc_AesEaxDecryptAuth(void);
|
||||
#endif /* WOLFSSL_AES_EAX */
|
||||
|
||||
int test_wc_GmacSetKey(void);
|
||||
int test_wc_GmacUpdate(void);
|
||||
|
||||
#define TEST_AES_DECLS \
|
||||
TEST_DECL_GROUP("aes", test_wc_AesSetKey), \
|
||||
TEST_DECL_GROUP("aes", test_wc_AesSetIV), \
|
||||
TEST_DECL_GROUP("aes", test_wc_AesCbcEncryptDecrypt), \
|
||||
TEST_DECL_GROUP("aes", test_wc_AesCtrEncryptDecrypt), \
|
||||
TEST_DECL_GROUP("aes", test_wc_AesGcmSetKey), \
|
||||
TEST_DECL_GROUP("aes", test_wc_AesGcmEncryptDecrypt), \
|
||||
TEST_DECL_GROUP("aes", test_wc_AesGcmMixedEncDecLongIV), \
|
||||
TEST_DECL_GROUP("aes", test_wc_AesGcmStream), \
|
||||
TEST_DECL_GROUP("aes", test_wc_AesCcmSetKey), \
|
||||
TEST_DECL_GROUP("aes", test_wc_AesCcmEncryptDecrypt)
|
||||
|
||||
#if defined(WOLFSSL_AES_EAX) && \
|
||||
(!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
|
||||
#define TEST_AES_EAX_DECLS \
|
||||
TEST_DECL_GROUP("aes-eax", test_wc_AesEaxVectors), \
|
||||
TEST_DECL_GROUP("aes-eax", test_wc_AesEaxEncryptAuth), \
|
||||
TEST_DECL_GROUP("aes-eax", test_wc_AesEaxDecryptAuth)
|
||||
#endif /* WOLFSSL_AES_EAX */
|
||||
|
||||
#define TEST_GMAC_DECLS \
|
||||
TEST_DECL_GROUP("gmac", test_wc_GmacSetKey), \
|
||||
TEST_DECL_GROUP("gmac", test_wc_GmacUpdate)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_AES_H */
|
||||
|
|
|
@ -22,7 +22,13 @@
|
|||
#ifndef WOLFCRYPT_TEST_ARC4_H
|
||||
#define WOLFCRYPT_TEST_ARC4_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_Arc4SetKey(void);
|
||||
int test_wc_Arc4Process(void);
|
||||
|
||||
#define TEST_ARC4_DECLS \
|
||||
TEST_DECL_GROUP("arc4", test_wc_Arc4SetKey), \
|
||||
TEST_DECL_GROUP("arc4", test_wc_Arc4Process)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_ARC4_H */
|
||||
|
|
|
@ -22,7 +22,13 @@
|
|||
#ifndef TESTS_API_TEST_ASCON_H
|
||||
#define TESTS_API_TEST_ASCON_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_ascon_hash256(void);
|
||||
int test_ascon_aead128(void);
|
||||
|
||||
#define TEST_ASCON_DECLS \
|
||||
TEST_DECL_GROUP("ascon", test_ascon_hash256), \
|
||||
TEST_DECL_GROUP("ascon", test_ascon_aead128)
|
||||
|
||||
#endif /* TESTS_API_TEST_ASCON_H */
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef WOLFCRYPT_TEST_BLAKE2_H
|
||||
#define WOLFCRYPT_TEST_BLAKE2_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_InitBlake2b(void);
|
||||
int test_wc_InitBlake2b_WithKey(void);
|
||||
int test_wc_Blake2bUpdate(void);
|
||||
|
@ -36,4 +38,20 @@ int test_wc_Blake2sFinal(void);
|
|||
int test_wc_Blake2s_KATs(void);
|
||||
int test_wc_Blake2s_other(void);
|
||||
|
||||
#define TEST_BLAKE2B_DECLS \
|
||||
TEST_DECL_GROUP("blake2b", test_wc_InitBlake2b), \
|
||||
TEST_DECL_GROUP("blake2b", test_wc_InitBlake2b_WithKey), \
|
||||
TEST_DECL_GROUP("blake2b", test_wc_Blake2bUpdate), \
|
||||
TEST_DECL_GROUP("blake2b", test_wc_Blake2bFinal), \
|
||||
TEST_DECL_GROUP("blake2b", test_wc_Blake2b_KATs), \
|
||||
TEST_DECL_GROUP("blake2b", test_wc_Blake2b_other)
|
||||
|
||||
#define TEST_BLAKE2S_DECLS \
|
||||
TEST_DECL_GROUP("blake2s", test_wc_InitBlake2s), \
|
||||
TEST_DECL_GROUP("blake2s", test_wc_InitBlake2s_WithKey), \
|
||||
TEST_DECL_GROUP("blake2s", test_wc_Blake2sUpdate), \
|
||||
TEST_DECL_GROUP("blake2s", test_wc_Blake2sFinal), \
|
||||
TEST_DECL_GROUP("blake2s", test_wc_Blake2s_KATs), \
|
||||
TEST_DECL_GROUP("blake2s", test_wc_Blake2s_other)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_BLAKE2_H */
|
||||
|
|
|
@ -22,9 +22,17 @@
|
|||
#ifndef WOLFCRYPT_TEST_CAMELLIA_H
|
||||
#define WOLFCRYPT_TEST_CAMELLIA_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_CamelliaSetKey(void);
|
||||
int test_wc_CamelliaSetIV(void);
|
||||
int test_wc_CamelliaEncryptDecryptDirect(void);
|
||||
int test_wc_CamelliaCbcEncryptDecrypt(void);
|
||||
|
||||
#define TEST_CAMELLIA_DECLS \
|
||||
TEST_DECL_GROUP("camellia", test_wc_CamelliaSetKey), \
|
||||
TEST_DECL_GROUP("camellia", test_wc_CamelliaSetIV), \
|
||||
TEST_DECL_GROUP("camellia", test_wc_CamelliaEncryptDecryptDirect), \
|
||||
TEST_DECL_GROUP("camellia", test_wc_CamelliaCbcEncryptDecrypt)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_CAMELLIA_H */
|
||||
|
|
|
@ -22,7 +22,13 @@
|
|||
#ifndef WOLFCRYPT_TEST_CHACHA_H
|
||||
#define WOLFCRYPT_TEST_CHACHA_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_Chacha_SetKey(void);
|
||||
int test_wc_Chacha_Process(void);
|
||||
|
||||
#define TEST_CHACHA_DECLS \
|
||||
TEST_DECL_GROUP("chacha", test_wc_Chacha_SetKey), \
|
||||
TEST_DECL_GROUP("chacha", test_wc_Chacha_Process)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_CHACHA_H */
|
||||
|
|
|
@ -22,6 +22,11 @@
|
|||
#ifndef WOLFCRYPT_TEST_CHACHA20_POLY1305_H
|
||||
#define WOLFCRYPT_TEST_CHACHA20_POLY1305_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_ChaCha20Poly1305_aead(void);
|
||||
|
||||
#define TEST_CHACHA20_POLY1305_DECLS \
|
||||
TEST_DECL_GROUP("chacha20-poly1305", test_wc_ChaCha20Poly1305_aead)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_CHACHA20_POLY1305_H */
|
||||
|
|
|
@ -22,9 +22,17 @@
|
|||
#ifndef WOLFCRYPT_TEST_CMAC_H
|
||||
#define WOLFCRYPT_TEST_CMAC_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_InitCmac(void);
|
||||
int test_wc_CmacUpdate(void);
|
||||
int test_wc_CmacFinal(void);
|
||||
int test_wc_AesCmacGenerate(void);
|
||||
|
||||
#define TEST_CMAC_DECLS \
|
||||
TEST_DECL_GROUP("cmac", test_wc_InitCmac), \
|
||||
TEST_DECL_GROUP("cmac", test_wc_CmacUpdate), \
|
||||
TEST_DECL_GROUP("cmac", test_wc_CmacFinal), \
|
||||
TEST_DECL_GROUP("cmac", test_wc_AesCmacGenerate)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_CMAC_H */
|
||||
|
|
|
@ -0,0 +1,557 @@
|
|||
/* test_curve25519.c
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H)
|
||||
#include <wolfssl/options.h>
|
||||
#endif
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
|
||||
#ifdef NO_INLINE
|
||||
#include <wolfssl/wolfcrypt/misc.h>
|
||||
#else
|
||||
#define WOLFSSL_MISC_INCLUDED
|
||||
#include <wolfcrypt/src/misc.c>
|
||||
#endif
|
||||
|
||||
#include <wolfssl/wolfcrypt/curve25519.h>
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
#include <tests/unit.h>
|
||||
#include <tests/api/api.h>
|
||||
#include <tests/api/test_curve25519.h>
|
||||
|
||||
|
||||
/*
|
||||
* Testing wc_curve25519_init and wc_curve25519_free.
|
||||
*/
|
||||
int test_wc_curve25519_init(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_CURVE25519)
|
||||
curve25519_key key;
|
||||
|
||||
ExpectIntEQ(wc_curve25519_init(&key), 0);
|
||||
/* Test bad args for wc_curve25519_init */
|
||||
ExpectIntEQ(wc_curve25519_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
/* Test good args for wc_curve_25519_free */
|
||||
wc_curve25519_free(&key);
|
||||
/* Test bad args for wc_curve25519 free. */
|
||||
wc_curve25519_free(NULL);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_curve25519_init and wc_curve_25519_free */
|
||||
/*
|
||||
* Testing test_wc_curve25519_size.
|
||||
*/
|
||||
int test_wc_curve25519_size(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_CURVE25519)
|
||||
curve25519_key key;
|
||||
|
||||
ExpectIntEQ(wc_curve25519_init(&key), 0);
|
||||
|
||||
/* Test good args for wc_curve25519_size */
|
||||
ExpectIntEQ(wc_curve25519_size(&key), CURVE25519_KEYSIZE);
|
||||
/* Test bad args for wc_curve25519_size */
|
||||
ExpectIntEQ(wc_curve25519_size(NULL), 0);
|
||||
|
||||
wc_curve25519_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_curve25519_size */
|
||||
|
||||
/*
|
||||
* Testing test_wc_curve25519_export_key_raw().
|
||||
*/
|
||||
int test_wc_curve25519_export_key_raw(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_CURVE25519) && defined(HAVE_CURVE25519_KEY_EXPORT)
|
||||
curve25519_key key;
|
||||
WC_RNG rng;
|
||||
byte privateKey[CURVE25519_KEYSIZE];
|
||||
byte publicKey[CURVE25519_KEYSIZE];
|
||||
word32 prvkSz;
|
||||
word32 pubkSz;
|
||||
byte prik[CURVE25519_KEYSIZE];
|
||||
byte pubk[CURVE25519_KEYSIZE];
|
||||
word32 prksz;
|
||||
word32 pbksz;
|
||||
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_curve25519_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
|
||||
|
||||
/* bad-argument-test cases - target function should return BAD_FUNC_ARG */
|
||||
prvkSz = CURVE25519_KEYSIZE;
|
||||
pubkSz = CURVE25519_KEYSIZE;
|
||||
ExpectIntEQ(wc_curve25519_export_key_raw(NULL, privateKey, &prvkSz,
|
||||
publicKey, &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
prvkSz = CURVE25519_KEYSIZE;
|
||||
pubkSz = CURVE25519_KEYSIZE;
|
||||
ExpectIntEQ(wc_curve25519_export_key_raw(&key, NULL, &prvkSz, publicKey,
|
||||
&pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
prvkSz = CURVE25519_KEYSIZE;
|
||||
pubkSz = CURVE25519_KEYSIZE;
|
||||
ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, NULL,
|
||||
publicKey, &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
/* prvkSz = CURVE25519_KEYSIZE; */
|
||||
pubkSz = CURVE25519_KEYSIZE;
|
||||
ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, &prvkSz,
|
||||
NULL, &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
prvkSz = CURVE25519_KEYSIZE;
|
||||
pubkSz = CURVE25519_KEYSIZE;
|
||||
ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, &prvkSz,
|
||||
publicKey, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
/* cross-testing */
|
||||
prksz = CURVE25519_KEYSIZE;
|
||||
ExpectIntEQ(wc_curve25519_export_private_raw(&key, prik, &prksz), 0);
|
||||
pbksz = CURVE25519_KEYSIZE;
|
||||
ExpectIntEQ(wc_curve25519_export_public(&key, pubk, &pbksz), 0);
|
||||
prvkSz = CURVE25519_KEYSIZE;
|
||||
/* pubkSz = CURVE25519_KEYSIZE; */
|
||||
ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, &prvkSz,
|
||||
publicKey, &pubkSz), 0);
|
||||
ExpectIntEQ(prksz, CURVE25519_KEYSIZE);
|
||||
ExpectIntEQ(pbksz, CURVE25519_KEYSIZE);
|
||||
ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
|
||||
ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
|
||||
ExpectIntEQ(XMEMCMP(privateKey, prik, CURVE25519_KEYSIZE), 0);
|
||||
ExpectIntEQ(XMEMCMP(publicKey, pubk, CURVE25519_KEYSIZE), 0);
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_curve25519_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* end of test_wc_curve25519_export_key_raw */
|
||||
|
||||
/*
|
||||
* Testing test_wc_curve25519_export_key_raw_ex().
|
||||
*/
|
||||
int test_wc_curve25519_export_key_raw_ex(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_CURVE25519) && defined(HAVE_CURVE25519_KEY_EXPORT)
|
||||
curve25519_key key;
|
||||
WC_RNG rng;
|
||||
byte privateKey[CURVE25519_KEYSIZE];
|
||||
byte publicKey[CURVE25519_KEYSIZE];
|
||||
word32 prvkSz;
|
||||
word32 pubkSz;
|
||||
byte prik[CURVE25519_KEYSIZE];
|
||||
byte pubk[CURVE25519_KEYSIZE];
|
||||
word32 prksz;
|
||||
word32 pbksz;
|
||||
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_curve25519_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
|
||||
|
||||
/* bad-argument-test cases - target function should return BAD_FUNC_ARG */
|
||||
prvkSz = CURVE25519_KEYSIZE;
|
||||
pubkSz = CURVE25519_KEYSIZE;
|
||||
ExpectIntEQ(wc_curve25519_export_key_raw_ex(NULL, privateKey,
|
||||
&prvkSz, publicKey, &pubkSz, EC25519_LITTLE_ENDIAN),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
prvkSz = CURVE25519_KEYSIZE;
|
||||
pubkSz = CURVE25519_KEYSIZE;
|
||||
ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, NULL,
|
||||
&prvkSz, publicKey, &pubkSz, EC25519_LITTLE_ENDIAN),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
prvkSz = CURVE25519_KEYSIZE;
|
||||
pubkSz = CURVE25519_KEYSIZE;
|
||||
ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
|
||||
NULL, publicKey, &pubkSz, EC25519_LITTLE_ENDIAN),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
/* prvkSz = CURVE25519_KEYSIZE; */
|
||||
pubkSz = CURVE25519_KEYSIZE;
|
||||
ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
|
||||
&prvkSz, NULL, &pubkSz, EC25519_LITTLE_ENDIAN),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
prvkSz = CURVE25519_KEYSIZE;
|
||||
pubkSz = CURVE25519_KEYSIZE;
|
||||
ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
|
||||
&prvkSz, publicKey, NULL, EC25519_LITTLE_ENDIAN),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
prvkSz = CURVE25519_KEYSIZE;
|
||||
/* pubkSz = CURVE25519_KEYSIZE; */
|
||||
ExpectIntEQ(wc_curve25519_export_key_raw_ex(NULL, privateKey,
|
||||
&prvkSz, publicKey, &pubkSz, EC25519_BIG_ENDIAN),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
prvkSz = CURVE25519_KEYSIZE;
|
||||
pubkSz = CURVE25519_KEYSIZE;
|
||||
ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, NULL,
|
||||
&prvkSz, publicKey, &pubkSz, EC25519_BIG_ENDIAN),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
prvkSz = CURVE25519_KEYSIZE;
|
||||
pubkSz = CURVE25519_KEYSIZE;
|
||||
ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
|
||||
NULL, publicKey, &pubkSz, EC25519_BIG_ENDIAN),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
/* prvkSz = CURVE25519_KEYSIZE; */
|
||||
pubkSz = CURVE25519_KEYSIZE;
|
||||
ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
|
||||
&prvkSz, NULL, &pubkSz, EC25519_BIG_ENDIAN),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
prvkSz = CURVE25519_KEYSIZE;
|
||||
pubkSz = CURVE25519_KEYSIZE;
|
||||
ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
|
||||
&prvkSz, publicKey, NULL, EC25519_BIG_ENDIAN),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
/* illegal value for endian */
|
||||
prvkSz = CURVE25519_KEYSIZE;
|
||||
/* pubkSz = CURVE25519_KEYSIZE; */
|
||||
ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey, &prvkSz,
|
||||
publicKey, NULL, EC25519_BIG_ENDIAN + 10),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
/* cross-testing */
|
||||
prksz = CURVE25519_KEYSIZE;
|
||||
ExpectIntEQ(wc_curve25519_export_private_raw( &key, prik, &prksz), 0);
|
||||
pbksz = CURVE25519_KEYSIZE;
|
||||
ExpectIntEQ(wc_curve25519_export_public( &key, pubk, &pbksz), 0);
|
||||
prvkSz = CURVE25519_KEYSIZE;
|
||||
/* pubkSz = CURVE25519_KEYSIZE; */
|
||||
ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey, &prvkSz,
|
||||
publicKey, &pubkSz, EC25519_BIG_ENDIAN), 0);
|
||||
ExpectIntEQ(prksz, CURVE25519_KEYSIZE);
|
||||
ExpectIntEQ(pbksz, CURVE25519_KEYSIZE);
|
||||
ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
|
||||
ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
|
||||
ExpectIntEQ(XMEMCMP(privateKey, prik, CURVE25519_KEYSIZE), 0);
|
||||
ExpectIntEQ(XMEMCMP(publicKey, pubk, CURVE25519_KEYSIZE), 0);
|
||||
ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey, &prvkSz,
|
||||
publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), 0);
|
||||
ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
|
||||
ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
|
||||
|
||||
/* try once with another endian */
|
||||
prvkSz = CURVE25519_KEYSIZE;
|
||||
pubkSz = CURVE25519_KEYSIZE;
|
||||
ExpectIntEQ(wc_curve25519_export_key_raw_ex( &key, privateKey, &prvkSz,
|
||||
publicKey, &pubkSz, EC25519_BIG_ENDIAN), 0);
|
||||
ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
|
||||
ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_curve25519_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* end of test_wc_curve25519_export_key_raw_ex */
|
||||
|
||||
/*
|
||||
* Testing wc_curve25519_make_key
|
||||
*/
|
||||
int test_wc_curve25519_make_key(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_CURVE25519)
|
||||
curve25519_key key;
|
||||
WC_RNG rng;
|
||||
int keysize = 0;
|
||||
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_curve25519_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
|
||||
ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
|
||||
ExpectIntEQ(keysize = wc_curve25519_size(&key), CURVE25519_KEYSIZE);
|
||||
ExpectIntEQ(wc_curve25519_make_key(&rng, keysize, &key), 0);
|
||||
/* test bad cases */
|
||||
ExpectIntEQ(wc_curve25519_make_key(NULL, 0, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve25519_make_key(&rng, keysize, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve25519_make_key(NULL, keysize, &key),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve25519_make_key(&rng, 0, &key),
|
||||
WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_curve25519_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_curve25519_make_key */
|
||||
|
||||
/*
|
||||
* Testing wc_curve25519_shared_secret_ex
|
||||
*/
|
||||
int test_wc_curve25519_shared_secret_ex(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_CURVE25519)
|
||||
curve25519_key private_key;
|
||||
curve25519_key public_key;
|
||||
WC_RNG rng;
|
||||
byte out[CURVE25519_KEYSIZE];
|
||||
word32 outLen = sizeof(out);
|
||||
int endian = EC25519_BIG_ENDIAN;
|
||||
|
||||
ExpectIntEQ(wc_curve25519_init(&private_key), 0);
|
||||
#ifdef WOLFSSL_CURVE25519_BLINDING
|
||||
ExpectIntEQ(wc_curve25519_set_rng(&private_key, &rng), 0);
|
||||
#endif
|
||||
ExpectIntEQ(wc_curve25519_init(&public_key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
|
||||
ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &private_key),
|
||||
0);
|
||||
ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &public_key),
|
||||
0);
|
||||
|
||||
ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
|
||||
&outLen, endian), 0);
|
||||
|
||||
/* test bad cases */
|
||||
ExpectIntEQ(wc_curve25519_shared_secret_ex(NULL, NULL, NULL, 0, endian),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve25519_shared_secret_ex(NULL, &public_key, out, &outLen,
|
||||
endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, NULL, out, &outLen,
|
||||
endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, NULL,
|
||||
&outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
|
||||
NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
/* curve25519.c is checking for public_key size less than or equal to 0x7f,
|
||||
* increasing to 0x8f checks for error being returned */
|
||||
public_key.p.point[CURVE25519_KEYSIZE-1] = 0x8F;
|
||||
ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
|
||||
&outLen, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
|
||||
|
||||
outLen = outLen - 2;
|
||||
ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
|
||||
&outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_curve25519_free(&private_key);
|
||||
wc_curve25519_free(&public_key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_curve25519_shared_secret_ex */
|
||||
|
||||
/*
|
||||
* Testing wc_curve25519_make_pub
|
||||
*/
|
||||
int test_wc_curve25519_make_pub(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#ifdef HAVE_CURVE25519
|
||||
curve25519_key key;
|
||||
WC_RNG rng;
|
||||
byte out[CURVE25519_KEYSIZE];
|
||||
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_curve25519_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
|
||||
|
||||
ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(out), out,
|
||||
(int)sizeof(key.k), key.k), 0);
|
||||
/* test bad cases */
|
||||
ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(key.k) - 1, key.k,
|
||||
(int)sizeof out, out), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
|
||||
ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k),
|
||||
NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
|
||||
ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out - 1, out,
|
||||
(int)sizeof(key.k), key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
|
||||
ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, NULL,
|
||||
(int)sizeof(key.k), key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
|
||||
/* verify clamping test */
|
||||
key.k[0] |= ~248;
|
||||
ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k),
|
||||
key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
|
||||
key.k[0] &= 248;
|
||||
/* repeat the expected-to-succeed test. */
|
||||
ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k),
|
||||
key.k), 0);
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_curve25519_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_curve25519_make_pub */
|
||||
|
||||
/*
|
||||
* Testing test_wc_curve25519_export_public_ex
|
||||
*/
|
||||
int test_wc_curve25519_export_public_ex(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_CURVE25519)
|
||||
curve25519_key key;
|
||||
WC_RNG rng;
|
||||
byte out[CURVE25519_KEYSIZE];
|
||||
word32 outLen = sizeof(out);
|
||||
int endian = EC25519_BIG_ENDIAN;
|
||||
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_curve25519_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
|
||||
|
||||
ExpectIntEQ(wc_curve25519_export_public(&key, out, &outLen), 0);
|
||||
ExpectIntEQ(wc_curve25519_export_public_ex(&key, out, &outLen, endian), 0);
|
||||
/* test bad cases */
|
||||
ExpectIntEQ(wc_curve25519_export_public_ex(NULL, NULL, NULL, endian),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve25519_export_public_ex(NULL, out, &outLen, endian),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve25519_export_public_ex(&key, NULL, &outLen, endian),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve25519_export_public_ex(&key, out, NULL, endian),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
outLen = outLen - 2;
|
||||
ExpectIntEQ(wc_curve25519_export_public_ex(&key, out, &outLen, endian),
|
||||
WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_curve25519_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_curve25519_export_public_ex */
|
||||
|
||||
/*
|
||||
* Testing test_wc_curve25519_export_private_raw_ex
|
||||
*/
|
||||
int test_wc_curve25519_export_private_raw_ex(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_CURVE25519)
|
||||
curve25519_key key;
|
||||
byte out[CURVE25519_KEYSIZE];
|
||||
word32 outLen = sizeof(out);
|
||||
int endian = EC25519_BIG_ENDIAN;
|
||||
|
||||
ExpectIntEQ(wc_curve25519_init(&key), 0);
|
||||
|
||||
ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, &outLen, endian),
|
||||
0);
|
||||
/* test bad cases */
|
||||
ExpectIntEQ(wc_curve25519_export_private_raw_ex(NULL, NULL, NULL, endian),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve25519_export_private_raw_ex(NULL, out, &outLen, endian),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, NULL, &outLen,
|
||||
endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, NULL, endian),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, &outLen,
|
||||
EC25519_LITTLE_ENDIAN), 0);
|
||||
outLen = outLen - 2;
|
||||
ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, &outLen, endian),
|
||||
WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
|
||||
|
||||
wc_curve25519_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_curve25519_export_private_raw_ex */
|
||||
|
||||
/*
|
||||
* Testing test_wc_curve25519_import_private_raw_ex
|
||||
*/
|
||||
int test_wc_curve25519_import_private_raw_ex(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_CURVE25519)
|
||||
curve25519_key key;
|
||||
WC_RNG rng;
|
||||
byte priv[CURVE25519_KEYSIZE];
|
||||
byte pub[CURVE25519_KEYSIZE];
|
||||
word32 privSz = sizeof(priv);
|
||||
word32 pubSz = sizeof(pub);
|
||||
int endian = EC25519_BIG_ENDIAN;
|
||||
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_curve25519_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
|
||||
|
||||
ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, priv, &privSz,
|
||||
endian), 0);
|
||||
ExpectIntEQ(wc_curve25519_export_public(&key, pub, &pubSz), 0);
|
||||
ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, pubSz,
|
||||
&key, endian), 0);
|
||||
/* test bad cases */
|
||||
ExpectIntEQ(wc_curve25519_import_private_raw_ex(NULL, 0, NULL, 0, NULL,
|
||||
endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve25519_import_private_raw_ex(NULL, privSz, pub, pubSz,
|
||||
&key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, NULL, pubSz,
|
||||
&key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, pubSz,
|
||||
NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, 0, pub, pubSz,
|
||||
&key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
|
||||
ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, 0,
|
||||
&key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
|
||||
ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, pubSz,
|
||||
&key, EC25519_LITTLE_ENDIAN), 0);
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_curve25519_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_curve25519_import_private_raw_ex */
|
||||
|
||||
/*
|
||||
* Testing test_wc_curve25519_import_private
|
||||
*/
|
||||
int test_wc_curve25519_import_private(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_CURVE25519)
|
||||
curve25519_key key;
|
||||
WC_RNG rng;
|
||||
byte priv[CURVE25519_KEYSIZE];
|
||||
word32 privSz = sizeof(priv);
|
||||
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_curve25519_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
|
||||
|
||||
ExpectIntEQ(wc_curve25519_export_private_raw(&key, priv, &privSz), 0);
|
||||
ExpectIntEQ(wc_curve25519_import_private(priv, privSz, &key), 0);
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_curve25519_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_curve25519_import */
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/* test_curve25519.h
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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_CURVE25519_H
|
||||
#define WOLFCRYPT_TEST_CURVE25519_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_curve25519_init(void);
|
||||
int test_wc_curve25519_size(void);
|
||||
int test_wc_curve25519_export_key_raw(void);
|
||||
int test_wc_curve25519_export_key_raw_ex(void);
|
||||
int test_wc_curve25519_make_key(void);
|
||||
int test_wc_curve25519_shared_secret_ex(void);
|
||||
int test_wc_curve25519_make_pub(void);
|
||||
int test_wc_curve25519_export_public_ex(void);
|
||||
int test_wc_curve25519_export_private_raw_ex(void);
|
||||
int test_wc_curve25519_import_private_raw_ex(void);
|
||||
int test_wc_curve25519_import_private(void);
|
||||
|
||||
#define TEST_CURVE25519_DECLS \
|
||||
TEST_DECL_GROUP("curve25519", test_wc_curve25519_init), \
|
||||
TEST_DECL_GROUP("curve25519", test_wc_curve25519_size), \
|
||||
TEST_DECL_GROUP("curve25519", test_wc_curve25519_export_key_raw), \
|
||||
TEST_DECL_GROUP("curve25519", test_wc_curve25519_export_key_raw_ex), \
|
||||
TEST_DECL_GROUP("curve25519", test_wc_curve25519_make_key), \
|
||||
TEST_DECL_GROUP("curve25519", test_wc_curve25519_shared_secret_ex), \
|
||||
TEST_DECL_GROUP("curve25519", test_wc_curve25519_make_pub), \
|
||||
TEST_DECL_GROUP("curve25519", test_wc_curve25519_export_public_ex), \
|
||||
TEST_DECL_GROUP("curve25519", test_wc_curve25519_export_private_raw_ex), \
|
||||
TEST_DECL_GROUP("curve25519", test_wc_curve25519_import_private_raw_ex), \
|
||||
TEST_DECL_GROUP("curve25519", test_wc_curve25519_import_private)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_CURVE25519_H */
|
|
@ -0,0 +1,407 @@
|
|||
/* test_curve448.c
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H)
|
||||
#include <wolfssl/options.h>
|
||||
#endif
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
|
||||
#ifdef NO_INLINE
|
||||
#include <wolfssl/wolfcrypt/misc.h>
|
||||
#else
|
||||
#define WOLFSSL_MISC_INCLUDED
|
||||
#include <wolfcrypt/src/misc.c>
|
||||
#endif
|
||||
|
||||
#include <wolfssl/wolfcrypt/curve448.h>
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
#include <tests/unit.h>
|
||||
#include <tests/api/api.h>
|
||||
#include <tests/api/test_curve448.h>
|
||||
|
||||
/*
|
||||
* Testing wc_curve448_make_key
|
||||
*/
|
||||
int test_wc_curve448_make_key(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_CURVE448)
|
||||
curve448_key key;
|
||||
WC_RNG rng;
|
||||
int keysize = 0;
|
||||
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_curve448_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
|
||||
ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
|
||||
ExpectIntEQ(keysize = wc_curve448_size(&key), CURVE448_KEY_SIZE);
|
||||
ExpectIntEQ(wc_curve448_make_key(&rng, keysize, &key), 0);
|
||||
|
||||
/* test bad cases */
|
||||
ExpectIntEQ(wc_curve448_make_key(NULL, 0, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve448_make_key(&rng, keysize, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve448_make_key(NULL, keysize, &key),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve448_make_key(&rng, 0, &key),
|
||||
WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_curve448_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_curve448_make_key */
|
||||
|
||||
/*
|
||||
* Testing test_wc_curve448_shared_secret_ex
|
||||
*/
|
||||
int test_wc_curve448_shared_secret_ex(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_CURVE448)
|
||||
curve448_key private_key;
|
||||
curve448_key public_key;
|
||||
WC_RNG rng;
|
||||
byte out[CURVE448_KEY_SIZE];
|
||||
word32 outLen = sizeof(out);
|
||||
int endian = EC448_BIG_ENDIAN;
|
||||
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_curve448_init(&private_key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &private_key), 0);
|
||||
|
||||
ExpectIntEQ(wc_curve448_init(&public_key), 0);
|
||||
ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &public_key), 0);
|
||||
ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, out,
|
||||
&outLen, endian), 0);
|
||||
|
||||
/* test bad cases */
|
||||
ExpectIntEQ(wc_curve448_shared_secret_ex(NULL, NULL, NULL, 0, endian),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve448_shared_secret_ex(NULL, &public_key, out, &outLen,
|
||||
endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, NULL, out, &outLen,
|
||||
endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, NULL,
|
||||
&outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, out,
|
||||
NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
outLen = outLen - 2;
|
||||
ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, out,
|
||||
&outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_curve448_free(&private_key);
|
||||
wc_curve448_free(&public_key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_curve448_shared_secret_ex */
|
||||
|
||||
/*
|
||||
* Testing test_wc_curve448_export_public_ex
|
||||
*/
|
||||
int test_wc_curve448_export_public_ex(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_CURVE448)
|
||||
WC_RNG rng;
|
||||
curve448_key key;
|
||||
byte out[CURVE448_KEY_SIZE];
|
||||
word32 outLen = sizeof(out);
|
||||
int endian = EC448_BIG_ENDIAN;
|
||||
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_curve448_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
|
||||
|
||||
ExpectIntEQ(wc_curve448_export_public(&key, out, &outLen), 0);
|
||||
ExpectIntEQ(wc_curve448_export_public_ex(&key, out, &outLen, endian), 0);
|
||||
/* test bad cases */
|
||||
ExpectIntEQ(wc_curve448_export_public_ex(NULL, NULL, NULL, endian),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve448_export_public_ex(NULL, out, &outLen, endian),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve448_export_public_ex(&key, NULL, &outLen, endian),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve448_export_public_ex(&key, out, NULL, endian),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
outLen = outLen - 2;
|
||||
ExpectIntEQ(wc_curve448_export_public_ex(&key, out, &outLen, endian),
|
||||
WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_curve448_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_curve448_export_public_ex */
|
||||
|
||||
/*
|
||||
* Testing test_wc_curve448_export_private_raw_ex
|
||||
*/
|
||||
int test_wc_curve448_export_private_raw_ex(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_CURVE448)
|
||||
curve448_key key;
|
||||
byte out[CURVE448_KEY_SIZE];
|
||||
word32 outLen = sizeof(out);
|
||||
int endian = EC448_BIG_ENDIAN;
|
||||
|
||||
ExpectIntEQ(wc_curve448_init(&key), 0);
|
||||
ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, &outLen, endian),
|
||||
0);
|
||||
/* test bad cases */
|
||||
ExpectIntEQ(wc_curve448_export_private_raw_ex(NULL, NULL, NULL, endian),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve448_export_private_raw_ex(NULL, out, &outLen, endian),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, NULL, &outLen, endian),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, NULL, endian),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, &outLen,
|
||||
EC448_LITTLE_ENDIAN), 0);
|
||||
outLen = outLen - 2;
|
||||
ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, &outLen, endian),
|
||||
WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
|
||||
|
||||
wc_curve448_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_curve448_export_private_raw_ex */
|
||||
|
||||
/*
|
||||
* Testing test_curve448_export_key_raw
|
||||
*/
|
||||
int test_wc_curve448_export_key_raw(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_CURVE448)
|
||||
curve448_key key;
|
||||
WC_RNG rng;
|
||||
byte priv[CURVE448_KEY_SIZE];
|
||||
byte pub[CURVE448_KEY_SIZE];
|
||||
word32 privSz = sizeof(priv);
|
||||
word32 pubSz = sizeof(pub);
|
||||
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_curve448_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
|
||||
|
||||
ExpectIntEQ(wc_curve448_export_private_raw(&key, priv, &privSz), 0);
|
||||
ExpectIntEQ(wc_curve448_export_public(&key, pub, &pubSz), 0);
|
||||
ExpectIntEQ(wc_curve448_export_key_raw(&key, priv, &privSz, pub, &pubSz),
|
||||
0);
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_curve448_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_curve448_import_private_raw_ex */
|
||||
|
||||
/*
|
||||
* Testing test_wc_curve448_import_private_raw_ex
|
||||
*/
|
||||
int test_wc_curve448_import_private_raw_ex(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_CURVE448)
|
||||
curve448_key key;
|
||||
WC_RNG rng;
|
||||
byte priv[CURVE448_KEY_SIZE];
|
||||
byte pub[CURVE448_KEY_SIZE];
|
||||
word32 privSz = sizeof(priv);
|
||||
word32 pubSz = sizeof(pub);
|
||||
int endian = EC448_BIG_ENDIAN;
|
||||
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_curve448_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
|
||||
|
||||
ExpectIntEQ(wc_curve448_export_private_raw(&key, priv, &privSz), 0);
|
||||
ExpectIntEQ(wc_curve448_export_public(&key, pub, &pubSz), 0);
|
||||
ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
|
||||
&key, endian), 0);
|
||||
/* test bad cases */
|
||||
ExpectIntEQ(wc_curve448_import_private_raw_ex(NULL, 0, NULL, 0, NULL, 0),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve448_import_private_raw_ex(NULL, privSz, pub, pubSz,
|
||||
&key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, NULL, pubSz,
|
||||
&key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
|
||||
NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, 0, pub, pubSz,
|
||||
&key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
|
||||
ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, 0,
|
||||
&key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
|
||||
ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
|
||||
&key, EC448_LITTLE_ENDIAN), 0);
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_curve448_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_curve448_import_private_raw_ex */
|
||||
|
||||
/*
|
||||
* Testing test_wc_curve448_import_private
|
||||
*/
|
||||
int test_wc_curve448_import_private(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_CURVE448)
|
||||
curve448_key key;
|
||||
WC_RNG rng;
|
||||
byte priv[CURVE448_KEY_SIZE];
|
||||
word32 privSz = sizeof(priv);
|
||||
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_curve448_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
|
||||
|
||||
ExpectIntEQ(wc_curve448_export_private_raw(&key, priv, &privSz), 0);
|
||||
ExpectIntEQ(wc_curve448_import_private(priv, privSz, &key), 0);
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_curve448_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_curve448_import */
|
||||
|
||||
/*
|
||||
* Testing wc_curve448_init and wc_curve448_free.
|
||||
*/
|
||||
int test_wc_curve448_init(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_CURVE448)
|
||||
curve448_key key;
|
||||
|
||||
/* Test bad args for wc_curve448_init */
|
||||
ExpectIntEQ(wc_curve448_init(&key), 0);
|
||||
/* Test bad args for wc_curve448_init */
|
||||
ExpectIntEQ(wc_curve448_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
/* Test good args for wc_curve_448_free */
|
||||
wc_curve448_free(&key);
|
||||
/* Test bad args for wc_curve448_free */
|
||||
wc_curve448_free(NULL);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_curve448_init and wc_curve_448_free */
|
||||
|
||||
/*
|
||||
* Testing test_wc_curve448_size.
|
||||
*/
|
||||
int test_wc_curve448_size(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_CURVE448)
|
||||
curve448_key key;
|
||||
|
||||
ExpectIntEQ(wc_curve448_init(&key), 0);
|
||||
|
||||
/* Test good args for wc_curve448_size */
|
||||
ExpectIntEQ(wc_curve448_size(&key), CURVE448_KEY_SIZE);
|
||||
/* Test bad args for wc_curve448_size */
|
||||
ExpectIntEQ(wc_curve448_size(NULL), 0);
|
||||
|
||||
wc_curve448_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_curve448_size */
|
||||
|
||||
/*
|
||||
* Testing wc_Curve448PrivateKeyToDer
|
||||
*/
|
||||
int test_wc_Curve448PrivateKeyToDer(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_CURVE448) && defined(HAVE_CURVE448_KEY_EXPORT) && \
|
||||
(defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
|
||||
byte output[ONEK_BUF];
|
||||
curve448_key curve448PrivKey;
|
||||
WC_RNG rng;
|
||||
word32 inLen;
|
||||
|
||||
XMEMSET(&curve448PrivKey, 0, sizeof(curve448PrivKey));
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_curve448_init(&curve448PrivKey), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &curve448PrivKey),
|
||||
0);
|
||||
inLen = (word32)sizeof(output);
|
||||
|
||||
/* Bad Cases */
|
||||
ExpectIntEQ(wc_Curve448PrivateKeyToDer(NULL, NULL, 0),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_Curve448PrivateKeyToDer(NULL, output, inLen),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_Curve448PrivateKeyToDer(&curve448PrivKey, output, 0),
|
||||
WC_NO_ERR_TRACE(BUFFER_E));
|
||||
/* Good cases */
|
||||
/* length only */
|
||||
ExpectIntGT(wc_Curve448PrivateKeyToDer(&curve448PrivKey, NULL, 0), 0);
|
||||
ExpectIntGT(wc_Curve448PrivateKeyToDer(&curve448PrivKey, output, inLen), 0);
|
||||
|
||||
/* Bad Cases */
|
||||
ExpectIntEQ(wc_Curve448PublicKeyToDer(NULL, NULL, 0, 0),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_Curve448PublicKeyToDer(NULL, output, inLen, 0),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, 0, 0),
|
||||
WC_NO_ERR_TRACE(BUFFER_E));
|
||||
ExpectIntEQ(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, 0, 1),
|
||||
WC_NO_ERR_TRACE(BUFFER_E));
|
||||
/* Good cases */
|
||||
/* length only */
|
||||
ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, NULL, 0, 0), 0);
|
||||
ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, NULL, 0, 1), 0);
|
||||
ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, inLen, 0),
|
||||
0);
|
||||
ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, inLen, 1),
|
||||
0);
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_curve448_free(&curve448PrivKey);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* End wc_Curve448PrivateKeyToDer*/
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
/* test_curve448.h
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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_CURVE448_H
|
||||
#define WOLFCRYPT_TEST_CURVE448_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_curve448_make_key(void);
|
||||
int test_wc_curve448_shared_secret_ex(void);
|
||||
int test_wc_curve448_export_public_ex(void);
|
||||
int test_wc_curve448_export_private_raw_ex(void);
|
||||
int test_wc_curve448_export_key_raw(void);
|
||||
int test_wc_curve448_import_private_raw_ex(void);
|
||||
int test_wc_curve448_import_private(void);
|
||||
int test_wc_curve448_init(void);
|
||||
int test_wc_curve448_size(void);
|
||||
int test_wc_Curve448PrivateKeyToDer(void);
|
||||
|
||||
#define TEST_CURVE448_DECLS \
|
||||
TEST_DECL_GROUP("curve448", test_wc_curve448_make_key), \
|
||||
TEST_DECL_GROUP("curve448", test_wc_curve448_shared_secret_ex), \
|
||||
TEST_DECL_GROUP("curve448", test_wc_curve448_export_public_ex), \
|
||||
TEST_DECL_GROUP("curve448", test_wc_curve448_export_private_raw_ex), \
|
||||
TEST_DECL_GROUP("curve448", test_wc_curve448_export_key_raw), \
|
||||
TEST_DECL_GROUP("curve448", test_wc_curve448_import_private_raw_ex), \
|
||||
TEST_DECL_GROUP("curve448", test_wc_curve448_import_private), \
|
||||
TEST_DECL_GROUP("curve448", test_wc_curve448_init), \
|
||||
TEST_DECL_GROUP("curve448", test_wc_curve448_size), \
|
||||
TEST_DECL_GROUP("curve448", test_wc_Curve448PrivateKeyToDer)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_CURVE448_H */
|
|
@ -22,9 +22,17 @@
|
|||
#ifndef WOLFCRYPT_TEST_DES3_H
|
||||
#define WOLFCRYPT_TEST_DES3_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_Des3_SetIV(void);
|
||||
int test_wc_Des3_SetKey(void);
|
||||
int test_wc_Des3_CbcEncryptDecrypt(void);
|
||||
int test_wc_Des3_EcbEncrypt(void);
|
||||
|
||||
#define TEST_DES3_DECLS \
|
||||
TEST_DECL_GROUP("des3", test_wc_Des3_SetIV), \
|
||||
TEST_DECL_GROUP("des3", test_wc_Des3_SetKey), \
|
||||
TEST_DECL_GROUP("des3", test_wc_Des3_CbcEncryptDecrypt), \
|
||||
TEST_DECL_GROUP("des3", test_wc_Des3_CbcEncryptDecrypt)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_DES3_H */
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
/* test_dh.c
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H)
|
||||
#include <wolfssl/options.h>
|
||||
#endif
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
|
||||
#ifdef NO_INLINE
|
||||
#include <wolfssl/wolfcrypt/misc.h>
|
||||
#else
|
||||
#define WOLFSSL_MISC_INCLUDED
|
||||
#include <wolfcrypt/src/misc.c>
|
||||
#endif
|
||||
|
||||
#include <wolfssl/wolfcrypt/dh.h>
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
#include <tests/unit.h>
|
||||
#include <tests/api/api.h>
|
||||
#include <tests/api/test_dh.h>
|
||||
|
||||
/*
|
||||
* Testing wc_DhPublicKeyDecode
|
||||
*/
|
||||
int test_wc_DhPublicKeyDecode(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#ifndef NO_DH
|
||||
#if defined(WOLFSSL_DH_EXTRA) && defined(USE_CERT_BUFFERS_2048)
|
||||
DhKey key;
|
||||
word32 inOutIdx;
|
||||
|
||||
XMEMSET(&key, 0, sizeof(DhKey));
|
||||
|
||||
ExpectIntEQ(wc_InitDhKey(&key), 0);
|
||||
|
||||
ExpectIntEQ(wc_DhPublicKeyDecode(NULL,NULL,NULL,0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,NULL,NULL,0),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,NULL,NULL,0),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
inOutIdx = 0;
|
||||
ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,NULL, 0),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
inOutIdx = 0;
|
||||
ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,&key, 0),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
inOutIdx = 0;
|
||||
ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,&key,
|
||||
sizeof_dh_pub_key_der_2048), 0);
|
||||
ExpectIntNE(key.p.used, 0);
|
||||
ExpectIntNE(key.g.used, 0);
|
||||
ExpectIntEQ(key.q.used, 0);
|
||||
ExpectIntNE(key.pub.used, 0);
|
||||
ExpectIntEQ(key.priv.used, 0);
|
||||
|
||||
DoExpectIntEQ(wc_FreeDhKey(&key), 0);
|
||||
#endif
|
||||
#endif /* !NO_DH */
|
||||
return EXPECT_RESULT();
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
/* test_dh.h
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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_DH_H
|
||||
#define WOLFCRYPT_TEST_DH_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_DhPublicKeyDecode(void);
|
||||
|
||||
#define TEST_DH_DECLS \
|
||||
TEST_DECL_GROUP("dh", test_wc_DhPublicKeyDecode)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_DH_H */
|
|
@ -19,22 +19,6 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||
*/
|
||||
|
||||
#define PRINT_DATA(name, data, len) \
|
||||
do { \
|
||||
int ii; \
|
||||
fprintf(stderr, "%s\n", name); \
|
||||
for (ii = 0; ii < (int)(len); ii++) { \
|
||||
if ((ii % 8) == 0) \
|
||||
fprintf(stderr, " \""); \
|
||||
fprintf(stderr, "\\x%02x", (data)[ii]); \
|
||||
if ((ii % 8) == 7) \
|
||||
fprintf(stderr, "\"\n"); \
|
||||
} \
|
||||
if ((ii % 8) != 0) \
|
||||
fprintf(stderr, "\""); \
|
||||
fprintf(stderr, "\n"); \
|
||||
} while (0)
|
||||
|
||||
|
||||
#define DIGEST_INIT_TEST(type, name) \
|
||||
do { \
|
||||
|
|
|
@ -0,0 +1,587 @@
|
|||
/* test_dsa.c
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H)
|
||||
#include <wolfssl/options.h>
|
||||
#endif
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
|
||||
#ifdef NO_INLINE
|
||||
#include <wolfssl/wolfcrypt/misc.h>
|
||||
#else
|
||||
#define WOLFSSL_MISC_INCLUDED
|
||||
#include <wolfcrypt/src/misc.c>
|
||||
#endif
|
||||
|
||||
#include <wolfssl/wolfcrypt/dsa.h>
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
#include <tests/unit.h>
|
||||
#include <tests/api/api.h>
|
||||
#include <tests/api/test_dsa.h>
|
||||
|
||||
/*
|
||||
* Testing wc_InitDsaKey()
|
||||
*/
|
||||
int test_wc_InitDsaKey(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#ifndef NO_DSA
|
||||
DsaKey key;
|
||||
|
||||
XMEMSET(&key, 0, sizeof(DsaKey));
|
||||
|
||||
ExpectIntEQ(wc_InitDsaKey(&key), 0);
|
||||
|
||||
/* Pass in bad args. */
|
||||
ExpectIntEQ(wc_InitDsaKey(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
wc_FreeDsaKey(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
|
||||
} /* END test_wc_InitDsaKey */
|
||||
|
||||
/*
|
||||
* Testing wc_DsaSign() and wc_DsaVerify()
|
||||
*/
|
||||
int test_wc_DsaSignVerify(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if !defined(NO_DSA)
|
||||
DsaKey key;
|
||||
WC_RNG rng;
|
||||
wc_Sha sha;
|
||||
byte signature[DSA_SIG_SIZE];
|
||||
byte hash[WC_SHA_DIGEST_SIZE];
|
||||
word32 idx = 0;
|
||||
word32 bytes;
|
||||
int answer = 0;
|
||||
#ifdef USE_CERT_BUFFERS_1024
|
||||
byte tmp[ONEK_BUF];
|
||||
|
||||
XMEMSET(tmp, 0, sizeof(tmp));
|
||||
XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
|
||||
bytes = sizeof_dsa_key_der_1024;
|
||||
#elif defined(USE_CERT_BUFFERS_2048)
|
||||
byte tmp[TWOK_BUF];
|
||||
|
||||
XMEMSET(tmp, 0, sizeof(tmp));
|
||||
XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
|
||||
bytes = sizeof_dsa_key_der_2048;
|
||||
#else
|
||||
byte tmp[TWOK_BUF];
|
||||
XFILE fp = XBADFILE;
|
||||
|
||||
XMEMSET(tmp, 0, sizeof(tmp));
|
||||
ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
|
||||
ExpectTrue((bytes = (word32)XFREAD(tmp, 1, sizeof(tmp), fp)) > 0);
|
||||
if (fp != XBADFILE)
|
||||
XFCLOSE(fp);
|
||||
#endif /* END USE_CERT_BUFFERS_1024 */
|
||||
|
||||
ExpectIntEQ(wc_InitSha(&sha), 0);
|
||||
ExpectIntEQ(wc_ShaUpdate(&sha, tmp, bytes), 0);
|
||||
ExpectIntEQ(wc_ShaFinal(&sha, hash), 0);
|
||||
ExpectIntEQ(wc_InitDsaKey(&key), 0);
|
||||
ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
|
||||
/* Sign. */
|
||||
ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), 0);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_DsaSign(NULL, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_DsaSign(hash, NULL, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_DsaSign(hash, signature, NULL, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_DsaSign(hash, signature, &key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
/* Verify. */
|
||||
ExpectIntEQ(wc_DsaVerify(hash, signature, &key, &answer), 0);
|
||||
ExpectIntEQ(answer, 1);
|
||||
/* Pass in bad args. */
|
||||
ExpectIntEQ(wc_DsaVerify(NULL, signature, &key, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_DsaVerify(hash, NULL, &key, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_DsaVerify(hash, signature, NULL, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_DsaVerify(hash, signature, &key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
#if !defined(HAVE_FIPS) && defined(WOLFSSL_PUBLIC_MP)
|
||||
/* hard set q to 0 and test fail case */
|
||||
mp_free(&key.q);
|
||||
mp_init(&key.q);
|
||||
ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
mp_set(&key.q, 1);
|
||||
ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
#endif
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng),0);
|
||||
wc_FreeDsaKey(&key);
|
||||
wc_ShaFree(&sha);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_DsaSign */
|
||||
|
||||
/*
|
||||
* Testing wc_DsaPrivateKeyDecode() and wc_DsaPublicKeyDecode()
|
||||
*/
|
||||
int test_wc_DsaPublicPrivateKeyDecode(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if !defined(NO_DSA)
|
||||
DsaKey key;
|
||||
word32 bytes = 0;
|
||||
word32 idx = 0;
|
||||
int ret = 0;
|
||||
#ifdef USE_CERT_BUFFERS_1024
|
||||
byte tmp[ONEK_BUF];
|
||||
|
||||
XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
|
||||
bytes = sizeof_dsa_key_der_1024;
|
||||
#elif defined(USE_CERT_BUFFERS_2048)
|
||||
byte tmp[TWOK_BUF];
|
||||
|
||||
XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
|
||||
bytes = sizeof_dsa_key_der_2048;
|
||||
#else
|
||||
byte tmp[TWOK_BUF];
|
||||
XFILE fp = XBADFILE;
|
||||
|
||||
XMEMSET(tmp, 0, sizeof(tmp));
|
||||
ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
|
||||
ExpectTrue((bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp)) > 0);
|
||||
if (fp != XBADFILE)
|
||||
XFCLOSE(fp);
|
||||
#endif /* END USE_CERT_BUFFERS_1024 */
|
||||
|
||||
ExpectIntEQ(wc_InitDsaKey(&key), 0);
|
||||
ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_DsaPrivateKeyDecode(NULL, &idx, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, NULL, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, NULL, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntLT(ret = wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
|
||||
ExpectTrue((ret == WC_NO_ERR_TRACE(ASN_PARSE_E)) || (ret == WC_NO_ERR_TRACE(BUFFER_E)));
|
||||
wc_FreeDsaKey(&key);
|
||||
|
||||
ExpectIntEQ(wc_InitDsaKey(&key), 0);
|
||||
idx = 0; /* Reset */
|
||||
ExpectIntEQ(wc_DsaPublicKeyDecode(tmp, &idx, &key, bytes), 0);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_DsaPublicKeyDecode(NULL, &idx, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_DsaPublicKeyDecode(tmp, NULL, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_DsaPublicKeyDecode(tmp, &idx, NULL, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntLT(ret = wc_DsaPublicKeyDecode(tmp, &idx, &key, bytes), 0);
|
||||
ExpectTrue((ret == WC_NO_ERR_TRACE(ASN_PARSE_E)) || (ret == WC_NO_ERR_TRACE(BUFFER_E)));
|
||||
wc_FreeDsaKey(&key);
|
||||
#endif /* !NO_DSA */
|
||||
return EXPECT_RESULT();
|
||||
|
||||
} /* END test_wc_DsaPublicPrivateKeyDecode */
|
||||
|
||||
/*
|
||||
* Testing wc_MakeDsaKey() and wc_MakeDsaParameters()
|
||||
*/
|
||||
int test_wc_MakeDsaKey(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
|
||||
DsaKey genKey;
|
||||
WC_RNG rng;
|
||||
|
||||
XMEMSET(&genKey, 0, sizeof(genKey));
|
||||
XMEMSET(&rng, 0, sizeof(rng));
|
||||
|
||||
ExpectIntEQ(wc_InitDsaKey(&genKey), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
|
||||
ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF, &genKey), 0);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_MakeDsaParameters(NULL, ONEK_BUF, &genKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF + 1, &genKey),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
ExpectIntEQ(wc_MakeDsaKey(&rng, &genKey), 0);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_MakeDsaKey(NULL, &genKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_MakeDsaKey(&rng, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_FreeDsaKey(&genKey);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_MakeDsaKey */
|
||||
|
||||
/*
|
||||
* Testing wc_DsaKeyToDer()
|
||||
*/
|
||||
int test_wc_DsaKeyToDer(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
|
||||
DsaKey key;
|
||||
word32 bytes;
|
||||
word32 idx = 0;
|
||||
#ifdef USE_CERT_BUFFERS_1024
|
||||
byte tmp[ONEK_BUF];
|
||||
byte der[ONEK_BUF];
|
||||
|
||||
XMEMSET(tmp, 0, sizeof(tmp));
|
||||
XMEMSET(der, 0, sizeof(der));
|
||||
XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
|
||||
bytes = sizeof_dsa_key_der_1024;
|
||||
#elif defined(USE_CERT_BUFFERS_2048)
|
||||
byte tmp[TWOK_BUF];
|
||||
byte der[TWOK_BUF];
|
||||
|
||||
XMEMSET(tmp, 0, sizeof(tmp));
|
||||
XMEMSET(der, 0, sizeof(der));
|
||||
XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
|
||||
bytes = sizeof_dsa_key_der_2048;
|
||||
#else
|
||||
byte tmp[TWOK_BUF];
|
||||
byte der[TWOK_BUF];
|
||||
XFILE fp = XBADFILE;
|
||||
|
||||
XMEMSET(tmp, 0, sizeof(tmp));
|
||||
XMEMSET(der, 0, sizeof(der));
|
||||
ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
|
||||
ExpectTrue((bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp)) > 0);
|
||||
if (fp != XBADFILE)
|
||||
XFCLOSE(fp);
|
||||
#endif /* END USE_CERT_BUFFERS_1024 */
|
||||
|
||||
XMEMSET(&key, 0, sizeof(DsaKey));
|
||||
|
||||
ExpectIntEQ(wc_InitDsaKey(&key), 0);
|
||||
ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
|
||||
ExpectIntGE(wc_DsaKeyToDer(&key, der, bytes), 0);
|
||||
ExpectIntEQ(XMEMCMP(der, tmp, bytes), 0);
|
||||
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_DsaKeyToDer(NULL, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_DsaKeyToDer(&key, NULL, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
wc_FreeDsaKey(&key);
|
||||
#endif /* !NO_DSA && WOLFSSL_KEY_GEN */
|
||||
return EXPECT_RESULT();
|
||||
|
||||
} /* END test_wc_DsaKeyToDer */
|
||||
|
||||
/*
|
||||
* Testing wc_DsaKeyToPublicDer()
|
||||
* (indirectly testing setDsaPublicKey())
|
||||
*/
|
||||
int test_wc_DsaKeyToPublicDer(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#ifndef HAVE_SELFTEST
|
||||
#if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
|
||||
DsaKey key;
|
||||
WC_RNG rng;
|
||||
byte* der = NULL;
|
||||
word32 sz = 0;
|
||||
word32 idx = 0;
|
||||
|
||||
XMEMSET(&key, 0, sizeof(DsaKey));
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectNotNull(der = (byte*)XMALLOC(ONEK_BUF, NULL,
|
||||
DYNAMIC_TYPE_TMP_BUFFER));
|
||||
ExpectIntEQ(wc_InitDsaKey(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF, &key), 0);
|
||||
ExpectIntEQ(wc_MakeDsaKey(&rng, &key), 0);
|
||||
|
||||
ExpectIntGE(sz = (word32)wc_DsaKeyToPublicDer(&key, der, ONEK_BUF), 0);
|
||||
wc_FreeDsaKey(&key);
|
||||
|
||||
idx = 0;
|
||||
ExpectIntEQ(wc_DsaPublicKeyDecode(der, &idx, &key, sz), 0);
|
||||
|
||||
/* Test without the SubjectPublicKeyInfo header */
|
||||
ExpectIntGE(sz = (word32)wc_SetDsaPublicKey(der, &key, ONEK_BUF, 0), 0);
|
||||
wc_FreeDsaKey(&key);
|
||||
idx = 0;
|
||||
ExpectIntEQ(wc_DsaPublicKeyDecode(der, &idx, &key, sz), 0);
|
||||
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_DsaKeyToPublicDer(NULL, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_DsaKeyToPublicDer(&key, NULL, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_FreeDsaKey(&key);
|
||||
XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif /* !NO_DSA && WOLFSSL_KEY_GEN */
|
||||
#endif /* !HAVE_SELFTEST */
|
||||
return EXPECT_RESULT();
|
||||
|
||||
} /* END test_wc_DsaKeyToPublicDer */
|
||||
|
||||
/*
|
||||
* Testing wc_DsaImportParamsRaw()
|
||||
*/
|
||||
int test_wc_DsaImportParamsRaw(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if !defined(NO_DSA)
|
||||
DsaKey key;
|
||||
/* [mod = L=1024, N=160], from CAVP KeyPair */
|
||||
const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
|
||||
"4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
|
||||
"5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
|
||||
"52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
|
||||
"47123188f8dc551054ee162b634d60f097f719076640e209"
|
||||
"80a0093113a8bd73";
|
||||
const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
|
||||
const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
|
||||
"138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
|
||||
"b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
|
||||
"07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
|
||||
"61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
|
||||
"76341a7e7d9";
|
||||
/* invalid p and q parameters */
|
||||
const char* invalidP = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d";
|
||||
const char* invalidQ = "96c5390a";
|
||||
|
||||
XMEMSET(&key, 0, sizeof(DsaKey));
|
||||
|
||||
ExpectIntEQ(wc_InitDsaKey(&key), 0);
|
||||
ExpectIntEQ(wc_DsaImportParamsRaw(&key, p, q, g), 0);
|
||||
|
||||
/* test bad args */
|
||||
/* null key struct */
|
||||
ExpectIntEQ(wc_DsaImportParamsRaw(NULL, p, q, g), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
/* null param pointers */
|
||||
ExpectIntEQ(wc_DsaImportParamsRaw(&key, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
/* illegal p length */
|
||||
ExpectIntEQ(wc_DsaImportParamsRaw(&key, invalidP, q, g), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
/* illegal q length */
|
||||
ExpectIntEQ(wc_DsaImportParamsRaw(&key, p, invalidQ, g), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
wc_FreeDsaKey(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
|
||||
} /* END test_wc_DsaImportParamsRaw */
|
||||
|
||||
/*
|
||||
* Testing wc_DsaImportParamsRawCheck()
|
||||
*/
|
||||
int test_wc_DsaImportParamsRawCheck(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if !defined(NO_DSA) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
|
||||
DsaKey key;
|
||||
int trusted = 0;
|
||||
/* [mod = L=1024, N=160], from CAVP KeyPair */
|
||||
const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
|
||||
"4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
|
||||
"5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
|
||||
"52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
|
||||
"47123188f8dc551054ee162b634d60f097f719076640e209"
|
||||
"80a0093113a8bd73";
|
||||
const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
|
||||
const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
|
||||
"138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
|
||||
"b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
|
||||
"07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
|
||||
"61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
|
||||
"76341a7e7d9";
|
||||
/* invalid p and q parameters */
|
||||
const char* invalidP = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d";
|
||||
const char* invalidQ = "96c5390a";
|
||||
|
||||
ExpectIntEQ(wc_InitDsaKey(&key), 0);
|
||||
ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, p, q, g, trusted, NULL), 0);
|
||||
|
||||
/* test bad args */
|
||||
/* null key struct */
|
||||
ExpectIntEQ(wc_DsaImportParamsRawCheck(NULL, p, q, g, trusted, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
/* null param pointers */
|
||||
ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, NULL, NULL, NULL, trusted,
|
||||
NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
/* illegal p length */
|
||||
ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, invalidP, q, g, trusted, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
/* illegal q length */
|
||||
ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, p, invalidQ, g, trusted, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
wc_FreeDsaKey(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_DsaImportParamsRawCheck */
|
||||
|
||||
/*
|
||||
* Testing wc_DsaExportParamsRaw()
|
||||
*/
|
||||
int test_wc_DsaExportParamsRaw(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if !defined(NO_DSA)
|
||||
DsaKey key;
|
||||
/* [mod = L=1024, N=160], from CAVP KeyPair */
|
||||
const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
|
||||
"4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
|
||||
"5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
|
||||
"52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
|
||||
"47123188f8dc551054ee162b634d60f097f719076640e209"
|
||||
"80a0093113a8bd73";
|
||||
const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
|
||||
const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
|
||||
"138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
|
||||
"b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
|
||||
"07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
|
||||
"61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
|
||||
"76341a7e7d9";
|
||||
const char* pCompare = "\xd3\x83\x11\xe2\xcd\x38\x8c\x3e\xd6\x98\xe8\x2f"
|
||||
"\xdf\x88\xeb\x92\xb5\xa9\xa4\x83\xdc\x88\x00\x5d"
|
||||
"\x4b\x72\x5e\xf3\x41\xea\xbb\x47\xcf\x8a\x7a\x8a"
|
||||
"\x41\xe7\x92\xa1\x56\xb7\xce\x97\x20\x6c\x4f\x9c"
|
||||
"\x5c\xe6\xfc\x5a\xe7\x91\x21\x02\xb6\xb5\x02\xe5"
|
||||
"\x90\x50\xb5\xb2\x1c\xe2\x63\xdd\xdb\x20\x44\xb6"
|
||||
"\x52\x23\x6f\x4d\x42\xab\x4b\x5d\x6a\xa7\x31\x89"
|
||||
"\xce\xf1\xac\xe7\x78\xd7\x84\x5a\x5c\x1c\x1c\x71"
|
||||
"\x47\x12\x31\x88\xf8\xdc\x55\x10\x54\xee\x16\x2b"
|
||||
"\x63\x4d\x60\xf0\x97\xf7\x19\x07\x66\x40\xe2\x09"
|
||||
"\x80\xa0\x09\x31\x13\xa8\xbd\x73";
|
||||
const char* qCompare = "\x96\xc5\x39\x0a\x8b\x61\x2c\x0e\x42\x2b\xb2\xb0"
|
||||
"\xea\x19\x4a\x3e\xc9\x35\xa2\x81";
|
||||
const char* gCompare = "\x06\xb7\x86\x1a\xbb\xd3\x5c\xc8\x9e\x79\xc5\x2f"
|
||||
"\x68\xd2\x08\x75\x38\x9b\x12\x73\x61\xca\x66\x82"
|
||||
"\x21\x38\xce\x49\x91\xd2\xb8\x62\x25\x9d\x6b\x45"
|
||||
"\x48\xa6\x49\x5b\x19\x5a\xa0\xe0\xb6\x13\x7c\xa3"
|
||||
"\x7e\xb2\x3b\x94\x07\x4d\x3c\x3d\x30\x00\x42\xbd"
|
||||
"\xf1\x57\x62\x81\x2b\x63\x33\xef\x7b\x07\xce\xba"
|
||||
"\x78\x60\x76\x10\xfc\xc9\xee\x68\x49\x1d\xbc\x1e"
|
||||
"\x34\xcd\x12\x61\x54\x74\xe5\x2b\x18\xbc\x93\x4f"
|
||||
"\xb0\x0c\x61\xd3\x9e\x7d\xa8\x90\x22\x91\xc4\x43"
|
||||
"\x4a\x4e\x22\x24\xc3\xf4\xfd\x9f\x93\xcd\x6f\x4f"
|
||||
"\x17\xfc\x07\x63\x41\xa7\xe7\xd9";
|
||||
byte pOut[MAX_DSA_PARAM_SIZE];
|
||||
byte qOut[MAX_DSA_PARAM_SIZE];
|
||||
byte gOut[MAX_DSA_PARAM_SIZE];
|
||||
word32 pOutSz;
|
||||
word32 qOutSz;
|
||||
word32 gOutSz;
|
||||
|
||||
XMEMSET(&key, 0, sizeof(DsaKey));
|
||||
|
||||
ExpectIntEQ(wc_InitDsaKey(&key), 0);
|
||||
/* first test using imported raw parameters, for expected */
|
||||
ExpectIntEQ(wc_DsaImportParamsRaw(&key, p, q, g), 0);
|
||||
pOutSz = sizeof(pOut);
|
||||
qOutSz = sizeof(qOut);
|
||||
gOutSz = sizeof(gOut);
|
||||
ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
|
||||
&gOutSz), 0);
|
||||
/* validate exported parameters are correct */
|
||||
ExpectIntEQ(XMEMCMP(pOut, pCompare, pOutSz), 0);
|
||||
ExpectIntEQ(XMEMCMP(qOut, qCompare, qOutSz), 0);
|
||||
ExpectIntEQ(XMEMCMP(gOut, gCompare, gOutSz), 0);
|
||||
|
||||
/* test bad args */
|
||||
/* null key struct */
|
||||
ExpectIntEQ(wc_DsaExportParamsRaw(NULL, pOut, &pOutSz, qOut, &qOutSz, gOut,
|
||||
&gOutSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
/* null output pointers */
|
||||
ExpectIntEQ(wc_DsaExportParamsRaw(&key, NULL, &pOutSz, NULL, &qOutSz, NULL,
|
||||
&gOutSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
|
||||
/* null output size pointers */
|
||||
ExpectIntEQ( wc_DsaExportParamsRaw(&key, pOut, NULL, qOut, NULL, gOut,
|
||||
NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
/* p output buffer size too small */
|
||||
pOutSz = 1;
|
||||
ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
|
||||
&gOutSz), WC_NO_ERR_TRACE(BUFFER_E));
|
||||
pOutSz = sizeof(pOut);
|
||||
/* q output buffer size too small */
|
||||
qOutSz = 1;
|
||||
ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
|
||||
&gOutSz), WC_NO_ERR_TRACE(BUFFER_E));
|
||||
qOutSz = sizeof(qOut);
|
||||
/* g output buffer size too small */
|
||||
gOutSz = 1;
|
||||
ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
|
||||
&gOutSz), WC_NO_ERR_TRACE(BUFFER_E));
|
||||
|
||||
wc_FreeDsaKey(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_DsaExportParamsRaw */
|
||||
|
||||
/*
|
||||
* Testing wc_DsaExportKeyRaw()
|
||||
*/
|
||||
int test_wc_DsaExportKeyRaw(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
|
||||
DsaKey key;
|
||||
WC_RNG rng;
|
||||
byte xOut[MAX_DSA_PARAM_SIZE];
|
||||
byte yOut[MAX_DSA_PARAM_SIZE];
|
||||
word32 xOutSz, yOutSz;
|
||||
|
||||
XMEMSET(&key, 0, sizeof(key));
|
||||
XMEMSET(&rng, 0, sizeof(rng));
|
||||
|
||||
ExpectIntEQ(wc_InitDsaKey(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_MakeDsaParameters(&rng, 1024, &key), 0);
|
||||
ExpectIntEQ(wc_MakeDsaKey(&rng, &key), 0);
|
||||
|
||||
/* try successful export */
|
||||
xOutSz = sizeof(xOut);
|
||||
yOutSz = sizeof(yOut);
|
||||
ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz), 0);
|
||||
|
||||
/* test bad args */
|
||||
/* null key struct */
|
||||
ExpectIntEQ(wc_DsaExportKeyRaw(NULL, xOut, &xOutSz, yOut, &yOutSz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
/* null output pointers */
|
||||
ExpectIntEQ(wc_DsaExportKeyRaw(&key, NULL, &xOutSz, NULL, &yOutSz),
|
||||
WC_NO_ERR_TRACE(LENGTH_ONLY_E));
|
||||
/* null output size pointers */
|
||||
ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, NULL, yOut, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
/* x output buffer size too small */
|
||||
xOutSz = 1;
|
||||
ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz),
|
||||
WC_NO_ERR_TRACE(BUFFER_E));
|
||||
xOutSz = sizeof(xOut);
|
||||
/* y output buffer size too small */
|
||||
yOutSz = 1;
|
||||
ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz),
|
||||
WC_NO_ERR_TRACE(BUFFER_E));
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_FreeDsaKey(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_DsaExportParamsRaw */
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
/* test_dsa.h
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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_DSA_H
|
||||
#define WOLFCRYPT_TEST_DSA_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_InitDsaKey(void);
|
||||
int test_wc_DsaSignVerify(void);
|
||||
int test_wc_DsaPublicPrivateKeyDecode(void);
|
||||
int test_wc_MakeDsaKey(void);
|
||||
int test_wc_DsaKeyToDer(void);
|
||||
int test_wc_DsaKeyToPublicDer(void);
|
||||
int test_wc_DsaImportParamsRaw(void);
|
||||
int test_wc_DsaImportParamsRawCheck(void);
|
||||
int test_wc_DsaExportParamsRaw(void);
|
||||
int test_wc_DsaExportKeyRaw(void);
|
||||
|
||||
#define TEST_DSA_DECLS \
|
||||
TEST_DECL_GROUP("dsa", test_wc_InitDsaKey), \
|
||||
TEST_DECL_GROUP("dsa", test_wc_DsaSignVerify), \
|
||||
TEST_DECL_GROUP("dsa", test_wc_DsaPublicPrivateKeyDecode), \
|
||||
TEST_DECL_GROUP("dsa", test_wc_MakeDsaKey), \
|
||||
TEST_DECL_GROUP("dsa", test_wc_DsaKeyToDer), \
|
||||
TEST_DECL_GROUP("dsa", test_wc_DsaKeyToPublicDer), \
|
||||
TEST_DECL_GROUP("dsa", test_wc_DsaImportParamsRaw), \
|
||||
TEST_DECL_GROUP("dsa", test_wc_DsaImportParamsRawCheck), \
|
||||
TEST_DECL_GROUP("dsa", test_wc_DsaExportParamsRaw), \
|
||||
TEST_DECL_GROUP("dsa", test_wc_DsaExportKeyRaw)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_DSA_H */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,100 @@
|
|||
/* test_ecc.h
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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_ECC_H
|
||||
#define WOLFCRYPT_TEST_ECC_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_ecc_get_curve_size_from_name(void);
|
||||
int test_wc_ecc_get_curve_id_from_name(void);
|
||||
int test_wc_ecc_get_curve_id_from_params(void);
|
||||
int test_wc_ecc_get_curve_id_from_dp_params(void);
|
||||
int test_wc_ecc_make_key(void);
|
||||
int test_wc_ecc_init(void);
|
||||
int test_wc_ecc_check_key(void);
|
||||
int test_wc_ecc_get_generator(void);
|
||||
int test_wc_ecc_size(void);
|
||||
int test_wc_ecc_params(void);
|
||||
int test_wc_ecc_signVerify_hash(void);
|
||||
int test_wc_ecc_shared_secret(void);
|
||||
int test_wc_ecc_export_x963(void);
|
||||
int test_wc_ecc_export_x963_ex(void);
|
||||
int test_wc_ecc_import_x963(void);
|
||||
int test_wc_ecc_import_private_key(void);
|
||||
int test_wc_ecc_export_private_only(void);
|
||||
int test_wc_ecc_rs_to_sig(void);
|
||||
int test_wc_ecc_import_raw(void);
|
||||
int test_wc_ecc_import_unsigned(void);
|
||||
int test_wc_ecc_sig_size(void);
|
||||
int test_wc_ecc_ctx_new(void);
|
||||
int test_wc_ecc_ctx_reset(void);
|
||||
int test_wc_ecc_ctx_set_peer_salt(void);
|
||||
int test_wc_ecc_ctx_set_info(void);
|
||||
int test_wc_ecc_encryptDecrypt(void);
|
||||
int test_wc_ecc_del_point(void);
|
||||
int test_wc_ecc_pointFns(void);
|
||||
int test_wc_ecc_shared_secret_ssh(void);
|
||||
int test_wc_ecc_verify_hash_ex(void);
|
||||
int test_wc_ecc_mulmod(void);
|
||||
int test_wc_ecc_is_valid_idx(void);
|
||||
int test_wc_ecc_get_curve_id_from_oid(void);
|
||||
int test_wc_ecc_sig_size_calc(void);
|
||||
int test_wc_EccPrivateKeyToDer(void);
|
||||
|
||||
#define TEST_ECC_DECLS \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_get_curve_size_from_name), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_get_curve_id_from_name), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_get_curve_id_from_params), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_get_curve_id_from_dp_params), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_make_key), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_init), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_check_key), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_get_generator), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_size), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_params), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_signVerify_hash), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_shared_secret), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_export_x963), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_export_x963_ex), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_import_x963), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_import_private_key), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_export_private_only), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_rs_to_sig), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_import_raw), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_import_unsigned), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_sig_size), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_ctx_new), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_ctx_reset), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_ctx_set_peer_salt), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_ctx_set_info), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_encryptDecrypt), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_del_point), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_pointFns), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_shared_secret_ssh), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_verify_hash_ex), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_mulmod), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_is_valid_idx), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_get_curve_id_from_oid), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_ecc_sig_size_calc), \
|
||||
TEST_DECL_GROUP("ecc", test_wc_EccPrivateKeyToDer)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_ECC_H */
|
|
@ -0,0 +1,605 @@
|
|||
/* test_ed25519.c
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H)
|
||||
#include <wolfssl/options.h>
|
||||
#endif
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
|
||||
#ifdef NO_INLINE
|
||||
#include <wolfssl/wolfcrypt/misc.h>
|
||||
#else
|
||||
#define WOLFSSL_MISC_INCLUDED
|
||||
#include <wolfcrypt/src/misc.c>
|
||||
#endif
|
||||
|
||||
#include <wolfssl/wolfcrypt/ed25519.h>
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
#include <tests/unit.h>
|
||||
#include <tests/api/api.h>
|
||||
#include <tests/api/test_ed25519.h>
|
||||
|
||||
/*
|
||||
* Testing wc_ed25519_make_key().
|
||||
*/
|
||||
int test_wc_ed25519_make_key(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED25519) && defined(HAVE_ED25519_MAKE_KEY)
|
||||
ed25519_key key;
|
||||
WC_RNG rng;
|
||||
unsigned char pubkey[ED25519_PUB_KEY_SIZE+1];
|
||||
int pubkey_sz = ED25519_PUB_KEY_SIZE;
|
||||
|
||||
XMEMSET(&key, 0, sizeof(ed25519_key));
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_ed25519_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
|
||||
ExpectIntEQ(wc_ed25519_make_public(&key, pubkey, (word32)pubkey_sz),
|
||||
WC_NO_ERR_TRACE(ECC_PRIV_KEY_E));
|
||||
ExpectIntEQ(wc_ed25519_make_public(&key, pubkey+1, (word32)pubkey_sz),
|
||||
WC_NO_ERR_TRACE(ECC_PRIV_KEY_E));
|
||||
ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
|
||||
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed25519_make_key(NULL, ED25519_KEY_SIZE, &key),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE - 1, &key),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE + 1, &key),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_ed25519_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_ed25519_make_key */
|
||||
|
||||
/*
|
||||
* Testing wc_ed25519_init()
|
||||
*/
|
||||
int test_wc_ed25519_init(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED25519)
|
||||
ed25519_key key;
|
||||
|
||||
XMEMSET(&key, 0, sizeof(ed25519_key));
|
||||
|
||||
ExpectIntEQ(wc_ed25519_init(&key), 0);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed25519_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
wc_ed25519_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_ed25519_init */
|
||||
|
||||
/*
|
||||
* Test wc_ed25519_sign_msg() and wc_ed25519_verify_msg()
|
||||
*/
|
||||
int test_wc_ed25519_sign_msg(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED25519) && defined(HAVE_ED25519_SIGN)
|
||||
WC_RNG rng;
|
||||
ed25519_key key;
|
||||
byte msg[] = "Everybody gets Friday off.\n";
|
||||
byte sig[ED25519_SIG_SIZE+1];
|
||||
word32 msglen = sizeof(msg);
|
||||
word32 siglen = ED25519_SIG_SIZE;
|
||||
word32 badSigLen = ED25519_SIG_SIZE - 1;
|
||||
#ifdef HAVE_ED25519_VERIFY
|
||||
int verify_ok = 0; /*1 = Verify success.*/
|
||||
#endif
|
||||
|
||||
/* Initialize stack variables. */
|
||||
XMEMSET(&key, 0, sizeof(ed25519_key));
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
XMEMSET(sig, 0, sizeof(sig));
|
||||
|
||||
/* Initialize key. */
|
||||
ExpectIntEQ(wc_ed25519_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
|
||||
|
||||
ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, &siglen, &key), 0);
|
||||
ExpectIntEQ(siglen, ED25519_SIG_SIZE);
|
||||
ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig+1, &siglen, &key), 0);
|
||||
ExpectIntEQ(siglen, ED25519_SIG_SIZE);
|
||||
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed25519_sign_msg(NULL, msglen, sig, &siglen, &key),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, NULL, &siglen, &key),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, NULL, &key),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, &siglen, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, &badSigLen, &key),
|
||||
WC_NO_ERR_TRACE(BUFFER_E));
|
||||
ExpectIntEQ(badSigLen, ED25519_SIG_SIZE);
|
||||
badSigLen--;
|
||||
|
||||
#ifdef HAVE_ED25519_VERIFY
|
||||
ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, msg, msglen, &verify_ok,
|
||||
&key), 0);
|
||||
ExpectIntEQ(verify_ok, 1);
|
||||
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen - 1, msg, msglen,
|
||||
&verify_ok, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen + 1, msg, msglen,
|
||||
&verify_ok, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_verify_msg(NULL, siglen, msg, msglen, &verify_ok,
|
||||
&key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, NULL, msglen, &verify_ok,
|
||||
&key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, msg, msglen, NULL, &key),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, msg, msglen, &verify_ok,
|
||||
NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_verify_msg(sig+1, badSigLen, msg, msglen, &verify_ok,
|
||||
&key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
#endif /* Verify. */
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_ed25519_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
|
||||
} /* END test_wc_ed25519_sign_msg */
|
||||
|
||||
/*
|
||||
* Testing wc_ed25519_import_public()
|
||||
*/
|
||||
int test_wc_ed25519_import_public(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
|
||||
ed25519_key pubKey;
|
||||
WC_RNG rng;
|
||||
const byte in[] = "Ed25519PublicKeyUnitTest......\n";
|
||||
word32 inlen = sizeof(in);
|
||||
|
||||
XMEMSET(&pubKey, 0, sizeof(ed25519_key));
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_ed25519_init(&pubKey), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
#ifdef HAVE_ED25519_MAKE_KEY
|
||||
ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &pubKey), 0);
|
||||
#endif
|
||||
|
||||
ExpectIntEQ(wc_ed25519_import_public_ex(in, inlen, &pubKey, 1), 0);
|
||||
ExpectIntEQ(XMEMCMP(in, pubKey.p, inlen), 0);
|
||||
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed25519_import_public(NULL, inlen, &pubKey),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_import_public(in, inlen, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_import_public(in, inlen - 1, &pubKey),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_ed25519_free(&pubKey);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END wc_ed25519_import_public */
|
||||
|
||||
/*
|
||||
* Testing wc_ed25519_import_private_key()
|
||||
*/
|
||||
int test_wc_ed25519_import_private_key(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
|
||||
ed25519_key key;
|
||||
WC_RNG rng;
|
||||
const byte privKey[] = "Ed25519PrivateKeyUnitTest.....\n";
|
||||
const byte pubKey[] = "Ed25519PublicKeyUnitTest......\n";
|
||||
word32 privKeySz = sizeof(privKey);
|
||||
word32 pubKeySz = sizeof(pubKey);
|
||||
#ifdef HAVE_ED25519_KEY_EXPORT
|
||||
byte bothKeys[sizeof(privKey) + sizeof(pubKey)];
|
||||
word32 bothKeysSz = sizeof(bothKeys);
|
||||
#endif
|
||||
|
||||
XMEMSET(&key, 0, sizeof(ed25519_key));
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_ed25519_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
#ifdef HAVE_ED25519_MAKE_KEY
|
||||
ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
|
||||
#endif
|
||||
|
||||
ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, privKeySz, pubKey,
|
||||
pubKeySz, &key, 1), 0);
|
||||
ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
|
||||
ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
|
||||
|
||||
#ifdef HAVE_ED25519_KEY_EXPORT
|
||||
PRIVATE_KEY_UNLOCK();
|
||||
ExpectIntEQ(wc_ed25519_export_private(&key, bothKeys, &bothKeysSz), 0);
|
||||
PRIVATE_KEY_LOCK();
|
||||
ExpectIntEQ(wc_ed25519_import_private_key_ex(bothKeys, bothKeysSz, NULL, 0,
|
||||
&key, 1), 0);
|
||||
ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
|
||||
ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
|
||||
#endif
|
||||
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed25519_import_private_key(NULL, privKeySz, pubKey, pubKeySz,
|
||||
&key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, NULL,
|
||||
pubKeySz, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, pubKey,
|
||||
pubKeySz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz - 1, pubKey,
|
||||
pubKeySz, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, pubKey,
|
||||
pubKeySz - 1, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, NULL, 0,
|
||||
&key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_ed25519_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_ed25519_import_private_key */
|
||||
|
||||
/*
|
||||
* Testing wc_ed25519_export_public() and wc_ed25519_export_private_only()
|
||||
*/
|
||||
int test_wc_ed25519_export(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
|
||||
ed25519_key key;
|
||||
WC_RNG rng;
|
||||
byte priv[ED25519_PRV_KEY_SIZE];
|
||||
byte pub[ED25519_PUB_KEY_SIZE];
|
||||
word32 privSz = sizeof(priv);
|
||||
word32 pubSz = sizeof(pub);
|
||||
#ifndef HAVE_ED25519_MAKE_KEY
|
||||
const byte privKey[] = {
|
||||
0xf8, 0x55, 0xb7, 0xb6, 0x49, 0x3f, 0x99, 0x9c,
|
||||
0x88, 0xe3, 0xc5, 0x42, 0x6a, 0xa4, 0x47, 0x4a,
|
||||
0xe4, 0x95, 0xda, 0xdb, 0xbf, 0xf8, 0xa7, 0x42,
|
||||
0x9d, 0x0e, 0xe7, 0xd0, 0x57, 0x8f, 0x16, 0x69
|
||||
};
|
||||
const byte pubKey[] = {
|
||||
0x42, 0x3b, 0x7a, 0xf9, 0x82, 0xcf, 0xf9, 0xdf,
|
||||
0x19, 0xdd, 0xf3, 0xf0, 0x32, 0x29, 0x6d, 0xfa,
|
||||
0xfd, 0x76, 0x4f, 0x68, 0xc2, 0xc2, 0xe0, 0x6c,
|
||||
0x47, 0xae, 0xc2, 0x55, 0x68, 0xac, 0x0d, 0x4d
|
||||
};
|
||||
#endif
|
||||
|
||||
XMEMSET(&key, 0, sizeof(ed25519_key));
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_ed25519_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
#ifdef HAVE_ED25519_MAKE_KEY
|
||||
ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
|
||||
#else
|
||||
ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, sizeof(privKey),
|
||||
pubKey, sizeof(pubKey), &key, 1), 0);
|
||||
#endif
|
||||
|
||||
PRIVATE_KEY_UNLOCK();
|
||||
ExpectIntEQ(wc_ed25519_export_public(&key, pub, &pubSz), 0);
|
||||
ExpectIntEQ(pubSz, ED25519_KEY_SIZE);
|
||||
ExpectIntEQ(XMEMCMP(key.p, pub, pubSz), 0);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed25519_export_public(NULL, pub, &pubSz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_export_public(&key, NULL, &pubSz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_export_public(&key, pub, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
ExpectIntEQ(wc_ed25519_export_private_only(&key, priv, &privSz), 0);
|
||||
ExpectIntEQ(privSz, ED25519_KEY_SIZE);
|
||||
ExpectIntEQ(XMEMCMP(key.k, priv, privSz), 0);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed25519_export_private_only(NULL, priv, &privSz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_export_private_only(&key, NULL, &privSz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_export_private_only(&key, priv, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
PRIVATE_KEY_LOCK();
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_ed25519_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_ed25519_export */
|
||||
|
||||
/*
|
||||
* Testing wc_ed25519_size()
|
||||
*/
|
||||
int test_wc_ed25519_size(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED25519)
|
||||
ed25519_key key;
|
||||
WC_RNG rng;
|
||||
#ifndef HAVE_ED25519_MAKE_KEY
|
||||
const byte privKey[] = {
|
||||
0xf8, 0x55, 0xb7, 0xb6, 0x49, 0x3f, 0x99, 0x9c,
|
||||
0x88, 0xe3, 0xc5, 0x42, 0x6a, 0xa4, 0x47, 0x4a,
|
||||
0xe4, 0x95, 0xda, 0xdb, 0xbf, 0xf8, 0xa7, 0x42,
|
||||
0x9d, 0x0e, 0xe7, 0xd0, 0x57, 0x8f, 0x16, 0x69
|
||||
};
|
||||
const byte pubKey[] = {
|
||||
0x42, 0x3b, 0x7a, 0xf9, 0x82, 0xcf, 0xf9, 0xdf,
|
||||
0x19, 0xdd, 0xf3, 0xf0, 0x32, 0x29, 0x6d, 0xfa,
|
||||
0xfd, 0x76, 0x4f, 0x68, 0xc2, 0xc2, 0xe0, 0x6c,
|
||||
0x47, 0xae, 0xc2, 0x55, 0x68, 0xac, 0x0d, 0x4d
|
||||
};
|
||||
#endif
|
||||
|
||||
XMEMSET(&key, 0, sizeof(ed25519_key));
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_ed25519_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
#ifdef HAVE_ED25519_MAKE_KEY
|
||||
ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
|
||||
#else
|
||||
ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, sizeof(privKey),
|
||||
pubKey, sizeof(pubKey), &key, 1), 0);
|
||||
#endif
|
||||
|
||||
ExpectIntEQ(wc_ed25519_size(&key), ED25519_KEY_SIZE);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed25519_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
ExpectIntEQ(wc_ed25519_sig_size(&key), ED25519_SIG_SIZE);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed25519_sig_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
ExpectIntEQ(wc_ed25519_pub_size(&key), ED25519_PUB_KEY_SIZE);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed25519_pub_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
ExpectIntEQ(wc_ed25519_priv_size(&key), ED25519_PRV_KEY_SIZE);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed25519_priv_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_ed25519_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_ed25519_size */
|
||||
|
||||
/*
|
||||
* Testing wc_ed25519_export_private() and wc_ed25519_export_key()
|
||||
*/
|
||||
int test_wc_ed25519_exportKey(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
|
||||
WC_RNG rng;
|
||||
ed25519_key key;
|
||||
byte priv[ED25519_PRV_KEY_SIZE];
|
||||
byte pub[ED25519_PUB_KEY_SIZE];
|
||||
byte privOnly[ED25519_PRV_KEY_SIZE];
|
||||
word32 privSz = sizeof(priv);
|
||||
word32 pubSz = sizeof(pub);
|
||||
word32 privOnlySz = sizeof(privOnly);
|
||||
#ifndef HAVE_ED25519_MAKE_KEY
|
||||
const byte privKey[] = {
|
||||
0xf8, 0x55, 0xb7, 0xb6, 0x49, 0x3f, 0x99, 0x9c,
|
||||
0x88, 0xe3, 0xc5, 0x42, 0x6a, 0xa4, 0x47, 0x4a,
|
||||
0xe4, 0x95, 0xda, 0xdb, 0xbf, 0xf8, 0xa7, 0x42,
|
||||
0x9d, 0x0e, 0xe7, 0xd0, 0x57, 0x8f, 0x16, 0x69
|
||||
};
|
||||
const byte pubKey[] = {
|
||||
0x42, 0x3b, 0x7a, 0xf9, 0x82, 0xcf, 0xf9, 0xdf,
|
||||
0x19, 0xdd, 0xf3, 0xf0, 0x32, 0x29, 0x6d, 0xfa,
|
||||
0xfd, 0x76, 0x4f, 0x68, 0xc2, 0xc2, 0xe0, 0x6c,
|
||||
0x47, 0xae, 0xc2, 0x55, 0x68, 0xac, 0x0d, 0x4d
|
||||
};
|
||||
#endif
|
||||
|
||||
XMEMSET(&key, 0, sizeof(ed25519_key));
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_ed25519_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
#ifdef HAVE_ED25519_MAKE_KEY
|
||||
ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
|
||||
#else
|
||||
ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, sizeof(privKey),
|
||||
pubKey, sizeof(pubKey), &key, 1), 0);
|
||||
#endif
|
||||
|
||||
PRIVATE_KEY_UNLOCK();
|
||||
ExpectIntEQ(wc_ed25519_export_private(&key, privOnly, &privOnlySz), 0);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed25519_export_private(NULL, privOnly, &privOnlySz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_export_private(&key, NULL, &privOnlySz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_export_private(&key, privOnly, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
ExpectIntEQ(wc_ed25519_export_key(&key, priv, &privSz, pub, &pubSz), 0);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed25519_export_key(NULL, priv, &privSz, pub, &pubSz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_export_key(&key, NULL, &privSz, pub, &pubSz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_export_key(&key, priv, NULL, pub, &pubSz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_export_key(&key, priv, &privSz, NULL, &pubSz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_export_key(&key, priv, &privSz, pub, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
PRIVATE_KEY_LOCK();
|
||||
|
||||
/* Cross check output. */
|
||||
ExpectIntEQ(XMEMCMP(priv, privOnly, privSz), 0);
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_ed25519_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_ed25519_exportKey */
|
||||
|
||||
/*
|
||||
* Testing wc_Ed25519PublicKeyToDer
|
||||
*/
|
||||
int test_wc_Ed25519PublicKeyToDer(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
|
||||
(defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
|
||||
ed25519_key key;
|
||||
byte derBuf[1024];
|
||||
|
||||
XMEMSET(&key, 0, sizeof(ed25519_key));
|
||||
|
||||
/* Test bad args */
|
||||
ExpectIntEQ(wc_Ed25519PublicKeyToDer(NULL, NULL, 0, 0),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed25519_init(&key), 0);
|
||||
ExpectIntEQ(wc_Ed25519PublicKeyToDer(&key, derBuf, 0, 0),
|
||||
WC_NO_ERR_TRACE(BUFFER_E));
|
||||
wc_ed25519_free(&key);
|
||||
|
||||
/* Test good args */
|
||||
if (EXPECT_SUCCESS()) {
|
||||
WC_RNG rng;
|
||||
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_ed25519_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
|
||||
/* length only */
|
||||
ExpectIntGT(wc_Ed25519PublicKeyToDer(&key, NULL, 0, 0), 0);
|
||||
ExpectIntGT(wc_Ed25519PublicKeyToDer(&key, NULL, 0, 1), 0);
|
||||
ExpectIntGT(wc_Ed25519PublicKeyToDer(&key, derBuf,
|
||||
(word32)sizeof(derBuf), 1), 0);
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_ed25519_free(&key);
|
||||
}
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END testing wc_Ed25519PublicKeyToDer */
|
||||
|
||||
/*
|
||||
* Testing wc_Ed25519KeyToDer
|
||||
*/
|
||||
int test_wc_Ed25519KeyToDer(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
|
||||
(defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
|
||||
byte output[ONEK_BUF];
|
||||
ed25519_key ed25519Key;
|
||||
WC_RNG rng;
|
||||
word32 inLen;
|
||||
|
||||
XMEMSET(&ed25519Key, 0, sizeof(ed25519_key));
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_ed25519_init(&ed25519Key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519Key), 0);
|
||||
inLen = (word32)sizeof(output);
|
||||
|
||||
/* Bad Cases */
|
||||
ExpectIntEQ(wc_Ed25519KeyToDer(NULL, NULL, 0),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_Ed25519KeyToDer(NULL, output, inLen),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_Ed25519KeyToDer(&ed25519Key, output, 0),
|
||||
WC_NO_ERR_TRACE(BUFFER_E));
|
||||
/* Good Cases */
|
||||
/* length only */
|
||||
ExpectIntGT(wc_Ed25519KeyToDer(&ed25519Key, NULL, 0), 0);
|
||||
ExpectIntGT(wc_Ed25519KeyToDer(&ed25519Key, NULL, inLen), 0);
|
||||
ExpectIntGT(wc_Ed25519KeyToDer(&ed25519Key, output, inLen), 0);
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_ed25519_free(&ed25519Key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* End test_wc_Ed25519KeyToDer*/
|
||||
|
||||
/*
|
||||
* Testing wc_Ed25519PrivateKeyToDer
|
||||
*/
|
||||
int test_wc_Ed25519PrivateKeyToDer(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
|
||||
(defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
|
||||
byte output[ONEK_BUF];
|
||||
ed25519_key ed25519PrivKey;
|
||||
WC_RNG rng;
|
||||
word32 inLen;
|
||||
|
||||
XMEMSET(&ed25519PrivKey, 0, sizeof(ed25519_key));
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_ed25519_init(&ed25519PrivKey), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519PrivKey),
|
||||
0);
|
||||
inLen = (word32)sizeof(output);
|
||||
|
||||
/* Bad Cases */
|
||||
ExpectIntEQ(wc_Ed25519PrivateKeyToDer(NULL, NULL, 0),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_Ed25519PrivateKeyToDer(NULL, output, inLen),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_Ed25519PrivateKeyToDer(&ed25519PrivKey, output, 0),
|
||||
WC_NO_ERR_TRACE(BUFFER_E));
|
||||
/* Good Cases */
|
||||
/* length only */
|
||||
ExpectIntGT(wc_Ed25519PrivateKeyToDer(&ed25519PrivKey, NULL, 0), 0);
|
||||
ExpectIntGT(wc_Ed25519PrivateKeyToDer(&ed25519PrivKey, output, inLen), 0);
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_ed25519_free(&ed25519PrivKey);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* End test_wc_Ed25519PrivateKeyToDer*/
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/* test_ed25519.h
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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_sign_msg(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);
|
||||
|
||||
#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_sign_msg), \
|
||||
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)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_ED25519_H */
|
|
@ -0,0 +1,539 @@
|
|||
/* test_ed448.c
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H)
|
||||
#include <wolfssl/options.h>
|
||||
#endif
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
|
||||
#ifdef NO_INLINE
|
||||
#include <wolfssl/wolfcrypt/misc.h>
|
||||
#else
|
||||
#define WOLFSSL_MISC_INCLUDED
|
||||
#include <wolfcrypt/src/misc.c>
|
||||
#endif
|
||||
|
||||
#include <wolfssl/wolfcrypt/ed448.h>
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
#include <tests/unit.h>
|
||||
#include <tests/api/api.h>
|
||||
#include <tests/api/test_ed448.h>
|
||||
|
||||
|
||||
/*
|
||||
* Testing wc_ed448_make_key().
|
||||
*/
|
||||
int test_wc_ed448_make_key(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED448)
|
||||
ed448_key key;
|
||||
WC_RNG rng;
|
||||
unsigned char pubkey[ED448_PUB_KEY_SIZE];
|
||||
|
||||
XMEMSET(&key, 0, sizeof(ed448_key));
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_ed448_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
|
||||
ExpectIntEQ(wc_ed448_make_public(&key, pubkey, sizeof(pubkey)),
|
||||
WC_NO_ERR_TRACE(ECC_PRIV_KEY_E));
|
||||
ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed448_make_key(NULL, ED448_KEY_SIZE, &key),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE - 1, &key),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE + 1, &key),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_ed448_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_ed448_make_key */
|
||||
|
||||
|
||||
/*
|
||||
* Testing wc_ed448_init()
|
||||
*/
|
||||
int test_wc_ed448_init(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED448)
|
||||
ed448_key key;
|
||||
|
||||
XMEMSET(&key, 0, sizeof(ed448_key));
|
||||
|
||||
ExpectIntEQ(wc_ed448_init(&key), 0);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed448_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
wc_ed448_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_ed448_init */
|
||||
|
||||
/*
|
||||
* Test wc_ed448_sign_msg() and wc_ed448_verify_msg()
|
||||
*/
|
||||
int test_wc_ed448_sign_msg(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED448) && defined(HAVE_ED448_SIGN)
|
||||
ed448_key key;
|
||||
WC_RNG rng;
|
||||
byte msg[] = "Everybody gets Friday off.\n";
|
||||
byte sig[ED448_SIG_SIZE];
|
||||
word32 msglen = sizeof(msg);
|
||||
word32 siglen = sizeof(sig);
|
||||
word32 badSigLen = sizeof(sig) - 1;
|
||||
#ifdef HAVE_ED448_VERIFY
|
||||
int verify_ok = 0; /*1 = Verify success.*/
|
||||
#endif
|
||||
|
||||
/* Initialize stack variables. */
|
||||
XMEMSET(&key, 0, sizeof(ed448_key));
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
XMEMSET(sig, 0, siglen);
|
||||
|
||||
/* Initialize key. */
|
||||
ExpectIntEQ(wc_ed448_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
|
||||
|
||||
ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, &siglen, &key, NULL, 0), 0);
|
||||
ExpectIntEQ(siglen, ED448_SIG_SIZE);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed448_sign_msg(NULL, msglen, sig, &siglen, &key, NULL, 0),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, NULL, &siglen, &key, NULL, 0),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, NULL, &key, NULL, 0),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, &siglen, NULL, NULL, 0),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, &badSigLen, &key, NULL, 0),
|
||||
WC_NO_ERR_TRACE(BUFFER_E));
|
||||
ExpectIntEQ(badSigLen, ED448_SIG_SIZE);
|
||||
badSigLen--;
|
||||
|
||||
#ifdef HAVE_ED448_VERIFY
|
||||
ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, msg, msglen, &verify_ok, &key,
|
||||
NULL, 0), 0);
|
||||
ExpectIntEQ(verify_ok, 1);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed448_verify_msg(sig, siglen - 1, msg, msglen, &verify_ok,
|
||||
&key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_verify_msg(sig, siglen + 1, msg, msglen, &verify_ok,
|
||||
&key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_verify_msg(NULL, siglen, msg, msglen, &verify_ok,
|
||||
&key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, NULL, msglen, &verify_ok,
|
||||
&key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, msg, msglen, NULL,
|
||||
&key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, msg, msglen, &verify_ok,
|
||||
NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_verify_msg(sig, badSigLen, msg, msglen, &verify_ok,
|
||||
&key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
#endif /* Verify. */
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_ed448_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_ed448_sign_msg */
|
||||
|
||||
/*
|
||||
* Testing wc_ed448_import_public()
|
||||
*/
|
||||
int test_wc_ed448_import_public(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
|
||||
ed448_key pubKey;
|
||||
WC_RNG rng;
|
||||
const byte in[] =
|
||||
"Ed448PublicKeyUnitTest.................................\n";
|
||||
word32 inlen = sizeof(in);
|
||||
|
||||
XMEMSET(&pubKey, 0, sizeof(ed448_key));
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_ed448_init(&pubKey), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &pubKey), 0);
|
||||
|
||||
ExpectIntEQ(wc_ed448_import_public_ex(in, inlen, &pubKey, 1), 0);
|
||||
ExpectIntEQ(XMEMCMP(in, pubKey.p, inlen), 0);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed448_import_public(NULL, inlen, &pubKey),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_import_public(in, inlen, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_import_public(in, inlen - 1, &pubKey),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_ed448_free(&pubKey);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END wc_ed448_import_public */
|
||||
|
||||
/*
|
||||
* Testing wc_ed448_import_private_key()
|
||||
*/
|
||||
int test_wc_ed448_import_private_key(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
|
||||
ed448_key key;
|
||||
WC_RNG rng;
|
||||
const byte privKey[] =
|
||||
"Ed448PrivateKeyUnitTest................................\n";
|
||||
const byte pubKey[] =
|
||||
"Ed448PublicKeyUnitTest.................................\n";
|
||||
word32 privKeySz = sizeof(privKey);
|
||||
word32 pubKeySz = sizeof(pubKey);
|
||||
#ifdef HAVE_ED448_KEY_EXPORT
|
||||
byte bothKeys[sizeof(privKey) + sizeof(pubKey)];
|
||||
word32 bothKeysSz = sizeof(bothKeys);
|
||||
#endif
|
||||
|
||||
XMEMSET(&key, 0, sizeof(ed448_key));
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_ed448_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
|
||||
|
||||
ExpectIntEQ(wc_ed448_import_private_key_ex(privKey, privKeySz, pubKey,
|
||||
pubKeySz, &key, 1), 0);
|
||||
ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
|
||||
ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
|
||||
|
||||
#ifdef HAVE_ED448_KEY_EXPORT
|
||||
PRIVATE_KEY_UNLOCK();
|
||||
ExpectIntEQ(wc_ed448_export_private(&key, bothKeys, &bothKeysSz), 0);
|
||||
PRIVATE_KEY_LOCK();
|
||||
ExpectIntEQ(wc_ed448_import_private_key_ex(bothKeys, bothKeysSz, NULL, 0,
|
||||
&key, 1), 0);
|
||||
ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
|
||||
ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
|
||||
#endif
|
||||
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed448_import_private_key(NULL, privKeySz, pubKey, pubKeySz,
|
||||
&key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, NULL, pubKeySz,
|
||||
&key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, pubKey,
|
||||
pubKeySz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz - 1, pubKey,
|
||||
pubKeySz, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, pubKey,
|
||||
pubKeySz - 1, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, NULL, 0, &key),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_ed448_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_ed448_import_private_key */
|
||||
|
||||
/*
|
||||
* Testing wc_ed448_export_public() and wc_ed448_export_private_only()
|
||||
*/
|
||||
int test_wc_ed448_export(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
|
||||
ed448_key key;
|
||||
WC_RNG rng;
|
||||
byte priv[ED448_PRV_KEY_SIZE];
|
||||
byte pub[ED448_PUB_KEY_SIZE];
|
||||
word32 privSz = sizeof(priv);
|
||||
word32 pubSz = sizeof(pub);
|
||||
|
||||
XMEMSET(&key, 0, sizeof(ed448_key));
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_ed448_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
|
||||
|
||||
ExpectIntEQ(wc_ed448_export_public(&key, pub, &pubSz), 0);
|
||||
ExpectIntEQ(pubSz, ED448_KEY_SIZE);
|
||||
ExpectIntEQ(XMEMCMP(key.p, pub, pubSz), 0);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed448_export_public(NULL, pub, &pubSz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_export_public(&key, NULL, &pubSz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_export_public(&key, pub, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
PRIVATE_KEY_UNLOCK();
|
||||
ExpectIntEQ(wc_ed448_export_private_only(&key, priv, &privSz), 0);
|
||||
ExpectIntEQ(privSz, ED448_KEY_SIZE);
|
||||
ExpectIntEQ(XMEMCMP(key.k, priv, privSz), 0);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed448_export_private_only(NULL, priv, &privSz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_export_private_only(&key, NULL, &privSz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_export_private_only(&key, priv, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
PRIVATE_KEY_LOCK();
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_ed448_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_ed448_export */
|
||||
|
||||
/*
|
||||
* Testing wc_ed448_size()
|
||||
*/
|
||||
int test_wc_ed448_size(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED448)
|
||||
ed448_key key;
|
||||
WC_RNG rng;
|
||||
|
||||
XMEMSET(&key, 0, sizeof(ed448_key));
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_ed448_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
|
||||
|
||||
ExpectIntEQ(wc_ed448_size(&key), ED448_KEY_SIZE);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed448_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
ExpectIntEQ(wc_ed448_sig_size(&key), ED448_SIG_SIZE);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed448_sig_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
ExpectIntEQ(wc_ed448_pub_size(&key), ED448_PUB_KEY_SIZE);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed448_pub_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
ExpectIntEQ(wc_ed448_priv_size(&key), ED448_PRV_KEY_SIZE);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed448_priv_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_ed448_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_ed448_size */
|
||||
|
||||
/*
|
||||
* Testing wc_ed448_export_private() and wc_ed448_export_key()
|
||||
*/
|
||||
int test_wc_ed448_exportKey(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
|
||||
ed448_key key;
|
||||
WC_RNG rng;
|
||||
byte priv[ED448_PRV_KEY_SIZE];
|
||||
byte pub[ED448_PUB_KEY_SIZE];
|
||||
byte privOnly[ED448_PRV_KEY_SIZE];
|
||||
word32 privSz = sizeof(priv);
|
||||
word32 pubSz = sizeof(pub);
|
||||
word32 privOnlySz = sizeof(privOnly);
|
||||
|
||||
XMEMSET(&key, 0, sizeof(ed448_key));
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_ed448_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
|
||||
|
||||
PRIVATE_KEY_UNLOCK();
|
||||
ExpectIntEQ(wc_ed448_export_private(&key, privOnly, &privOnlySz), 0);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed448_export_private(NULL, privOnly, &privOnlySz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_export_private(&key, NULL, &privOnlySz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_export_private(&key, privOnly, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
ExpectIntEQ(wc_ed448_export_key(&key, priv, &privSz, pub, &pubSz), 0);
|
||||
/* Test bad args. */
|
||||
ExpectIntEQ(wc_ed448_export_key(NULL, priv, &privSz, pub, &pubSz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_export_key(&key, NULL, &privSz, pub, &pubSz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_export_key(&key, priv, NULL, pub, &pubSz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_export_key(&key, priv, &privSz, NULL, &pubSz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ed448_export_key(&key, priv, &privSz, pub, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
PRIVATE_KEY_LOCK();
|
||||
|
||||
/* Cross check output. */
|
||||
ExpectIntEQ(XMEMCMP(priv, privOnly, privSz), 0);
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_ed448_free(&key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_ed448_exportKey */
|
||||
|
||||
/*
|
||||
* Testing wc_Ed448PublicKeyToDer
|
||||
*/
|
||||
int test_wc_Ed448PublicKeyToDer(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
|
||||
(defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
|
||||
ed448_key key;
|
||||
byte derBuf[1024];
|
||||
|
||||
XMEMSET(&key, 0, sizeof(ed448_key));
|
||||
|
||||
/* Test bad args */
|
||||
ExpectIntEQ(wc_Ed448PublicKeyToDer(NULL, NULL, 0, 0),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
ExpectIntEQ(wc_ed448_init(&key), 0);
|
||||
ExpectIntEQ(wc_Ed448PublicKeyToDer(&key, derBuf, 0, 0),
|
||||
WC_NO_ERR_TRACE(BUFFER_E));
|
||||
wc_ed448_free(&key);
|
||||
|
||||
/* Test good args */
|
||||
if (EXPECT_SUCCESS()) {
|
||||
WC_RNG rng;
|
||||
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_ed448_init(&key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
|
||||
/* length only */
|
||||
ExpectIntGT(wc_Ed448PublicKeyToDer(&key, NULL, 0, 0), 0);
|
||||
ExpectIntGT(wc_Ed448PublicKeyToDer(&key, NULL, 0, 1), 0);
|
||||
ExpectIntGT(wc_Ed448PublicKeyToDer(&key, derBuf,
|
||||
(word32)sizeof(derBuf), 1), 0);
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_ed448_free(&key);
|
||||
}
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* END testing wc_Ed448PublicKeyToDer */
|
||||
|
||||
/*
|
||||
* Testing wc_Ed448KeyToDer
|
||||
*/
|
||||
int test_wc_Ed448KeyToDer(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
|
||||
(defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
|
||||
byte output[ONEK_BUF];
|
||||
ed448_key ed448Key;
|
||||
WC_RNG rng;
|
||||
word32 inLen;
|
||||
|
||||
XMEMSET(&ed448Key, 0, sizeof(ed448_key));
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_ed448_init(&ed448Key), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448Key), 0);
|
||||
inLen = (word32)sizeof(output);
|
||||
|
||||
/* Bad Cases */
|
||||
ExpectIntEQ(wc_Ed448KeyToDer(NULL, NULL, 0),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_Ed448KeyToDer(NULL, output, inLen),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_Ed448KeyToDer(&ed448Key, output, 0),
|
||||
WC_NO_ERR_TRACE(BUFFER_E));
|
||||
/* Good Cases */
|
||||
/* length only */
|
||||
ExpectIntGT(wc_Ed448KeyToDer(&ed448Key, NULL, 0), 0);
|
||||
ExpectIntGT(wc_Ed448KeyToDer(&ed448Key, output, inLen), 0);
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_ed448_free(&ed448Key);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* End test_wc_Ed448KeyToDer */
|
||||
|
||||
/*
|
||||
* Testing wc_Ed448PrivateKeyToDer
|
||||
*/
|
||||
int test_wc_Ed448PrivateKeyToDer(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
|
||||
(defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
|
||||
byte output[ONEK_BUF];
|
||||
ed448_key ed448PrivKey;
|
||||
WC_RNG rng;
|
||||
word32 inLen;
|
||||
|
||||
XMEMSET(&ed448PrivKey, 0, sizeof(ed448_key));
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_ed448_init(&ed448PrivKey), 0);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448PrivKey),
|
||||
0);
|
||||
inLen = (word32)sizeof(output);
|
||||
|
||||
/* Bad Cases */
|
||||
ExpectIntEQ(wc_Ed448PrivateKeyToDer(NULL, NULL, 0),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_Ed448PrivateKeyToDer(NULL, output, inLen),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_Ed448PrivateKeyToDer(&ed448PrivKey, output, 0),
|
||||
WC_NO_ERR_TRACE(BUFFER_E));
|
||||
/* Good cases */
|
||||
/* length only */
|
||||
ExpectIntGT(wc_Ed448PrivateKeyToDer(&ed448PrivKey, NULL, 0), 0);
|
||||
ExpectIntGT(wc_Ed448PrivateKeyToDer(&ed448PrivKey, output, inLen), 0);
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
wc_ed448_free(&ed448PrivKey);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* End test_wc_Ed448PrivateKeyToDer */
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/* test_ed448.h
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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_init(void);
|
||||
int test_wc_ed448_sign_msg(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);
|
||||
|
||||
#define TEST_ED448_DECLS \
|
||||
TEST_DECL_GROUP("ed448", test_wc_ed448_make_key), \
|
||||
TEST_DECL_GROUP("ed448", test_wc_ed448_init), \
|
||||
TEST_DECL_GROUP("ed448", test_wc_ed448_sign_msg), \
|
||||
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)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_ED448_H */
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef WOLFCRYPT_TEST_HASH_H
|
||||
#define WOLFCRYPT_TEST_HASH_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_HashInit(void);
|
||||
int test_wc_HashUpdate(void);
|
||||
int test_wc_HashFinal(void);
|
||||
|
@ -35,4 +37,18 @@ int test_wc_Hash_Algs(void);
|
|||
int test_wc_HashGetOID(void);
|
||||
int test_wc_OidGetHash(void);
|
||||
|
||||
#define TEST_HASH_DECLS \
|
||||
TEST_DECL_GROUP("hash", test_wc_HashInit), \
|
||||
TEST_DECL_GROUP("hash", test_wc_HashUpdate), \
|
||||
TEST_DECL_GROUP("hash", test_wc_HashFinal), \
|
||||
TEST_DECL_GROUP("hash", test_wc_HashNewDelete), \
|
||||
TEST_DECL_GROUP("hash", test_wc_HashGetDigestSize), \
|
||||
TEST_DECL_GROUP("hash", test_wc_HashGetBlockSize), \
|
||||
TEST_DECL_GROUP("hash", test_wc_Hash), \
|
||||
TEST_DECL_GROUP("hash", test_wc_HashSetFlags), \
|
||||
TEST_DECL_GROUP("hash", test_wc_HashGetFlags), \
|
||||
TEST_DECL_GROUP("hash", test_wc_Hash_Algs), \
|
||||
TEST_DECL_GROUP("hash", test_wc_HashGetOID), \
|
||||
TEST_DECL_GROUP("hash", test_wc_OidGetHash)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_HASH_H */
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef WOLFCRYPT_TEST_HMAC_H
|
||||
#define WOLFCRYPT_TEST_HMAC_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_Md5HmacSetKey(void);
|
||||
int test_wc_Md5HmacUpdate(void);
|
||||
int test_wc_Md5HmacFinal(void);
|
||||
|
@ -38,4 +40,21 @@ int test_wc_Sha384HmacSetKey(void);
|
|||
int test_wc_Sha384HmacUpdate(void);
|
||||
int test_wc_Sha384HmacFinal(void);
|
||||
|
||||
#define TEST_HMAC_DECLS \
|
||||
TEST_DECL_GROUP("hmac", test_wc_Md5HmacSetKey), \
|
||||
TEST_DECL_GROUP("hmac", test_wc_Md5HmacUpdate), \
|
||||
TEST_DECL_GROUP("hmac", test_wc_Md5HmacFinal), \
|
||||
TEST_DECL_GROUP("hmac", test_wc_ShaHmacSetKey), \
|
||||
TEST_DECL_GROUP("hmac", test_wc_ShaHmacUpdate), \
|
||||
TEST_DECL_GROUP("hmac", test_wc_ShaHmacFinal), \
|
||||
TEST_DECL_GROUP("hmac", test_wc_Sha224HmacSetKey), \
|
||||
TEST_DECL_GROUP("hmac", test_wc_Sha224HmacUpdate), \
|
||||
TEST_DECL_GROUP("hmac", test_wc_Sha224HmacFinal), \
|
||||
TEST_DECL_GROUP("hmac", test_wc_Sha256HmacSetKey), \
|
||||
TEST_DECL_GROUP("hmac", test_wc_Sha256HmacUpdate), \
|
||||
TEST_DECL_GROUP("hmac", test_wc_Sha256HmacFinal), \
|
||||
TEST_DECL_GROUP("hmac", test_wc_Sha384HmacSetKey), \
|
||||
TEST_DECL_GROUP("hmac", test_wc_Sha384HmacUpdate), \
|
||||
TEST_DECL_GROUP("hmac", test_wc_Sha384HmacFinal)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_HMAC_H */
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef WOLFCRYPT_TEST_MD2_H
|
||||
#define WOLFCRYPT_TEST_MD2_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_InitMd2(void);
|
||||
int test_wc_Md2Update(void);
|
||||
int test_wc_Md2Final(void);
|
||||
|
@ -29,4 +31,12 @@ int test_wc_Md2_KATs(void);
|
|||
int test_wc_Md2_other(void);
|
||||
int test_wc_Md2Hash(void);
|
||||
|
||||
#define TEST_MD2_DECLS \
|
||||
TEST_DECL_GROUP("md2", test_wc_InitMd2), \
|
||||
TEST_DECL_GROUP("md2", test_wc_Md2Update), \
|
||||
TEST_DECL_GROUP("md2", test_wc_Md2Final), \
|
||||
TEST_DECL_GROUP("md2", test_wc_Md2_KATs), \
|
||||
TEST_DECL_GROUP("md2", test_wc_Md2_other), \
|
||||
TEST_DECL_GROUP("md2", test_wc_Md2Hash)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_MD2_H */
|
||||
|
|
|
@ -22,10 +22,19 @@
|
|||
#ifndef WOLFCRYPT_TEST_MD4_H
|
||||
#define WOLFCRYPT_TEST_MD4_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_InitMd4(void);
|
||||
int test_wc_Md4Update(void);
|
||||
int test_wc_Md4Final(void);
|
||||
int test_wc_Md4_KATs(void);
|
||||
int test_wc_Md4_other(void);
|
||||
|
||||
#define TEST_MD4_DECLS \
|
||||
TEST_DECL_GROUP("md4", test_wc_InitMd4), \
|
||||
TEST_DECL_GROUP("md4", test_wc_Md4Update), \
|
||||
TEST_DECL_GROUP("md4", test_wc_Md4Final), \
|
||||
TEST_DECL_GROUP("md4", test_wc_Md4_KATs), \
|
||||
TEST_DECL_GROUP("md4", test_wc_Md4_other)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_MD4_H */
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef WOLFCRYPT_TEST_MD5_H
|
||||
#define WOLFCRYPT_TEST_MD5_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_InitMd5(void);
|
||||
int test_wc_Md5Update(void);
|
||||
int test_wc_Md5Final(void);
|
||||
|
@ -32,4 +34,15 @@ int test_wc_Md5GetHash(void);
|
|||
int test_wc_Md5Transform(void);
|
||||
int test_wc_Md5_Flags(void);
|
||||
|
||||
#define TEST_MD5_DECLS \
|
||||
TEST_DECL_GROUP("md5", test_wc_InitMd5), \
|
||||
TEST_DECL_GROUP("md5", test_wc_Md5Update), \
|
||||
TEST_DECL_GROUP("md5", test_wc_Md5Final), \
|
||||
TEST_DECL_GROUP("md5", test_wc_Md5_KATs), \
|
||||
TEST_DECL_GROUP("md5", test_wc_Md5_other), \
|
||||
TEST_DECL_GROUP("md5", test_wc_Md5Copy), \
|
||||
TEST_DECL_GROUP("md5", test_wc_Md5GetHash), \
|
||||
TEST_DECL_GROUP("md5", test_wc_Md5Transform), \
|
||||
TEST_DECL_GROUP("md5", test_wc_Md5_Flags)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_MD5_H */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,52 @@
|
|||
/* test_mldsa.h
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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_MLDSA_H
|
||||
#define WOLFCRYPT_TEST_MLDSA_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_dilithium(void);
|
||||
int test_wc_dilithium_make_key(void);
|
||||
int test_wc_dilithium_sign(void);
|
||||
int test_wc_dilithium_verify(void);
|
||||
int test_wc_dilithium_sign_vfy(void);
|
||||
int test_wc_dilithium_check_key(void);
|
||||
int test_wc_dilithium_public_der_decode(void);
|
||||
int test_wc_dilithium_der(void);
|
||||
int test_wc_dilithium_make_key_from_seed(void);
|
||||
int test_wc_dilithium_sig_kats(void);
|
||||
int test_wc_dilithium_verify_kats(void);
|
||||
|
||||
#define TEST_MLDSA_DECLS \
|
||||
TEST_DECL_GROUP("mldsa", test_wc_dilithium), \
|
||||
TEST_DECL_GROUP("mldsa", test_wc_dilithium_make_key), \
|
||||
TEST_DECL_GROUP("mldsa", test_wc_dilithium_sign), \
|
||||
TEST_DECL_GROUP("mldsa", test_wc_dilithium_verify), \
|
||||
TEST_DECL_GROUP("mldsa", test_wc_dilithium_sign_vfy), \
|
||||
TEST_DECL_GROUP("mldsa", test_wc_dilithium_check_key), \
|
||||
TEST_DECL_GROUP("mldsa", test_wc_dilithium_public_der_decode), \
|
||||
TEST_DECL_GROUP("mldsa", test_wc_dilithium_der), \
|
||||
TEST_DECL_GROUP("mldsa", test_wc_dilithium_make_key_from_seed), \
|
||||
TEST_DECL_GROUP("mldsa", test_wc_dilithium_sig_kats), \
|
||||
TEST_DECL_GROUP("mldsa", test_wc_dilithium_verify_kats)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_MLDSA_H */
|
|
@ -22,8 +22,15 @@
|
|||
#ifndef WOLFCRYPT_TEST_MLKEM_H
|
||||
#define WOLFCRYPT_TEST_MLKEM_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_mlkem_make_key_kats(void);
|
||||
int test_wc_mlkem_encapsulate_kats(void);
|
||||
int test_wc_mlkem_decapsulate_kats(void);
|
||||
|
||||
#define TEST_MLKEM_DECLS \
|
||||
TEST_DECL_GROUP("mlkem", test_wc_mlkem_make_key_kats), \
|
||||
TEST_DECL_GROUP("mlkem", test_wc_mlkem_encapsulate_kats), \
|
||||
TEST_DECL_GROUP("mlkem", test_wc_mlkem_decapsulate_kats)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_MLKEM_H */
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include <wolfssl/ocsp.h>
|
||||
#include <wolfssl/ssl.h>
|
||||
|
||||
#if defined(HAVE_OCSP) && !defined(NO_SHA)
|
||||
#if defined(HAVE_OCSP) && !defined(NO_SHA) && !defined(NO_RSA)
|
||||
struct ocsp_cb_ctx {
|
||||
byte* response;
|
||||
int responseSz;
|
||||
|
@ -155,7 +155,6 @@ int test_ocsp_response_parsing(void)
|
|||
conf.targetCertSz = sizeof(intermediate1_ca_cert_pem);
|
||||
ExpectIntEQ(test_ocsp_response_with_cm(&conf, WOLFSSL_SUCCESS),
|
||||
TEST_SUCCESS);
|
||||
|
||||
return EXPECT_SUCCESS();
|
||||
}
|
||||
#else /* HAVE_OCSP && !NO_SHA */
|
||||
|
@ -165,7 +164,8 @@ int test_ocsp_response_parsing(void)
|
|||
}
|
||||
#endif /* HAVE_OCSP && !NO_SHA */
|
||||
|
||||
#if defined(HAVE_OCSP) && (defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA))
|
||||
#if defined(HAVE_OCSP) && (defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA)) && \
|
||||
!defined(NO_RSA)
|
||||
static int test_ocsp_create_x509store(WOLFSSL_X509_STORE** store,
|
||||
unsigned char* ca, int caSz)
|
||||
{
|
||||
|
@ -349,7 +349,6 @@ int test_ocsp_basic_verify(void)
|
|||
wc_FreeDecodedCert(&cert);
|
||||
wolfSSL_sk_X509_pop_free(certs, wolfSSL_X509_free);
|
||||
wolfSSL_X509_STORE_free(store);
|
||||
|
||||
return EXPECT_RESULT();
|
||||
}
|
||||
#else
|
||||
|
@ -594,7 +593,7 @@ int test_ocsp_status_callback(void)
|
|||
&& defined(OPENSSL_ALL) */
|
||||
|
||||
#if !defined(NO_SHA) && defined(OPENSSL_ALL) && defined(HAVE_OCSP) && \
|
||||
!defined(WOLFSSL_SM3) && !defined(WOLFSSL_SM2)
|
||||
!defined(WOLFSSL_SM3) && !defined(WOLFSSL_SM2) && !defined(NO_RSA)
|
||||
int test_ocsp_certid_enc_dec(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
|
@ -651,7 +650,6 @@ int test_ocsp_certid_enc_dec(void)
|
|||
wolfSSL_OCSP_CERTID_free(certIdDec);
|
||||
wolfSSL_X509_free(subject);
|
||||
wolfSSL_X509_free(issuer);
|
||||
|
||||
return EXPECT_SUCCESS();
|
||||
}
|
||||
#else /* !NO_SHA && OPENSSL_ALL && HAVE_OCSP && !WOLFSSL_SM3 && !WOLFSSL_SM2 */
|
||||
|
|
|
@ -22,6 +22,11 @@
|
|||
#ifndef WOLFCRYPT_TEST_POLY1305_H
|
||||
#define WOLFCRYPT_TEST_POLY1305_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_Poly1305SetKey(void);
|
||||
|
||||
#define TEST_POLY1305_DECLS \
|
||||
TEST_DECL_GROUP("poly1305", test_wc_Poly1305SetKey)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_POLY1305_H */
|
||||
|
|
|
@ -0,0 +1,535 @@
|
|||
/* test_random.c
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H)
|
||||
#include <wolfssl/options.h>
|
||||
#endif
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
|
||||
#ifdef NO_INLINE
|
||||
#include <wolfssl/wolfcrypt/misc.h>
|
||||
#else
|
||||
#define WOLFSSL_MISC_INCLUDED
|
||||
#include <wolfcrypt/src/misc.c>
|
||||
#endif
|
||||
|
||||
#include <wolfssl/wolfcrypt/random.h>
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
#include <tests/unit.h>
|
||||
#include <tests/api/api.h>
|
||||
#include <tests/api/test_random.h>
|
||||
|
||||
|
||||
int test_wc_InitRng(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#ifndef WC_NO_RNG
|
||||
WC_RNG rng[1];
|
||||
|
||||
(void)rng;
|
||||
|
||||
/* Bad parameter. */
|
||||
ExpectIntEQ(wc_InitRng(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_InitRng_ex(NULL, HEAP_HINT, INVALID_DEVID),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_FreeRng(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
#ifdef HAVE_HASHDRBG
|
||||
/* Good parameter. */
|
||||
ExpectIntEQ(wc_InitRng(rng), 0);
|
||||
ExpectIntEQ(wc_FreeRng(rng), 0);
|
||||
ExpectIntEQ(wc_InitRng_ex(rng, HEAP_HINT, INVALID_DEVID), 0);
|
||||
ExpectIntEQ(wc_FreeRng(rng), 0);
|
||||
#endif
|
||||
#elif !defined(HAVE_FIPS) || \
|
||||
(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
|
||||
WC_RNG rng[1];
|
||||
|
||||
(void)rng;
|
||||
|
||||
ExpectIntEQ(wc_InitRng(NULL), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
|
||||
ExpectIntEQ(wc_InitRng_ex(NULL, HEAP_HINT, INVALID_DEVID),
|
||||
WC_NO_ERR_TRACE(NOT_COMPILED_IN));
|
||||
ExpectIntEQ(wc_FreeRng(NULL), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
|
||||
|
||||
ExpectIntEQ(wc_InitRng(rng), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
|
||||
ExpectIntEQ(wc_InitRng_ex(rng, HEAP_HINT, INVALID_DEVID),
|
||||
WC_NO_ERR_TRACE(NOT_COMPILED_IN));
|
||||
ExpectIntEQ(wc_FreeRng(rng), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
}
|
||||
|
||||
|
||||
int test_wc_RNG_GenerateBlock_Reseed(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_HASHDRBG) && defined(TEST_RESEED_INTERVAL)
|
||||
int i;
|
||||
WC_RNG rng;
|
||||
byte key[32];
|
||||
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
for (i = 0; i < WC_RESEED_INTERVAL + 10; i++) {
|
||||
ExpectIntEQ(wc_RNG_GenerateBlock(&rng, key, sizeof(key)), 0);
|
||||
}
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
}
|
||||
|
||||
int test_wc_RNG_GenerateBlock(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#ifdef HAVE_HASHDRBG
|
||||
int i;
|
||||
WC_RNG rng;
|
||||
byte key[32];
|
||||
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
|
||||
/* Bad parameters. */
|
||||
ExpectIntEQ(wc_RNG_GenerateBlock(NULL, NULL, sizeof(key)),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_RNG_GenerateBlock(&rng, NULL, sizeof(key)),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_RNG_GenerateBlock(NULL, key , sizeof(key)),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
for (i = 0; i <= (int)sizeof(key); i++) {
|
||||
ExpectIntEQ(wc_RNG_GenerateBlock(&rng, key + i, sizeof(key) - i), 0);
|
||||
}
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
}
|
||||
|
||||
int test_wc_RNG_GenerateByte(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#ifdef HAVE_HASHDRBG
|
||||
int i;
|
||||
WC_RNG rng;
|
||||
byte output[10];
|
||||
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
|
||||
/* Bad parameters. */
|
||||
ExpectIntEQ(wc_RNG_GenerateByte(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_RNG_GenerateByte(&rng, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_RNG_GenerateByte(NULL, output),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
for (i = 0; i < (int)sizeof(output); i++) {
|
||||
ExpectIntEQ(wc_RNG_GenerateByte(&rng, output + i), 0);
|
||||
}
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
}
|
||||
|
||||
int test_wc_InitRngNonce(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \
|
||||
(!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
|
||||
HAVE_FIPS_VERSION >= 2))
|
||||
WC_RNG rng;
|
||||
byte nonce[] = "\x0D\x74\xDB\x42\xA9\x10\x77\xDE"
|
||||
"\x45\xAC\x13\x7A\xE1\x48\xAF\x16";
|
||||
word32 nonceSz = sizeof(nonce);
|
||||
|
||||
/* Bad parameters. */
|
||||
ExpectIntEQ(wc_InitRngNonce(NULL, NULL , nonceSz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_InitRngNonce(&rng, NULL , nonceSz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_InitRngNonce(NULL, nonce, nonceSz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
/* Good parameters. */
|
||||
ExpectIntEQ(wc_InitRngNonce(&rng, nonce, nonceSz), 0);
|
||||
ExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
ExpectIntEQ(wc_InitRngNonce(&rng, NULL, 0), 0);
|
||||
ExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
ExpectIntEQ(wc_InitRngNonce(&rng, nonce, 0), 0);
|
||||
ExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
}
|
||||
|
||||
int test_wc_InitRngNonce_ex(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \
|
||||
(!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
|
||||
HAVE_FIPS_VERSION >= 2))
|
||||
WC_RNG rng;
|
||||
byte nonce[] = "\x0D\x74\xDB\x42\xA9\x10\x77\xDE"
|
||||
"\x45\xAC\x13\x7A\xE1\x48\xAF\x16";
|
||||
word32 nonceSz = sizeof(nonce);
|
||||
|
||||
/* Bad parameters. */
|
||||
ExpectIntEQ(wc_InitRngNonce_ex(NULL, NULL , nonceSz, HEAP_HINT, testDevId),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_InitRngNonce_ex(&rng, NULL , nonceSz, HEAP_HINT, testDevId),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_InitRngNonce_ex(NULL, nonce, nonceSz, HEAP_HINT, testDevId),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
ExpectIntEQ(wc_InitRngNonce_ex(&rng, nonce, nonceSz, HEAP_HINT, testDevId),
|
||||
0);
|
||||
ExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
ExpectIntEQ(wc_InitRngNonce_ex(&rng, NULL, 0, HEAP_HINT, testDevId), 0);
|
||||
ExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
ExpectIntEQ(wc_InitRngNonce_ex(&rng, nonce, 0, HEAP_HINT, testDevId), 0);
|
||||
ExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
}
|
||||
|
||||
int test_wc_GenerateSeed(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if !defined(WC_NO_RNG) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
|
||||
OS_Seed seed[1];
|
||||
byte output[16];
|
||||
|
||||
XMEMSET(seed, 0, sizeof(OS_Seed));
|
||||
|
||||
/* Different configurations have different paths and different errors or
|
||||
* no error at all. */
|
||||
#ifdef TEST_WC_GENERATE_SEED_PARAMS
|
||||
/* Bad parameters. */
|
||||
ExpectIntEQ(wc_GenerateSeed(NULL, NULL , 16),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntLT(wc_GenerateSeed(seed, NULL , 16), 0);
|
||||
ExpectIntEQ(wc_GenerateSeed(NULL, output, 16),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
#endif
|
||||
|
||||
/* Good parameters. */
|
||||
ExpectIntEQ(wc_GenerateSeed(seed, output, 16), 0);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
}
|
||||
|
||||
int test_wc_rng_new(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if !defined(WC_NO_RNG) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
|
||||
!defined(WOLFSSL_NO_MALLOC)
|
||||
WC_RNG* rng = NULL;
|
||||
unsigned char nonce[16];
|
||||
word32 nonceSz = (word32)sizeof(nonce);
|
||||
|
||||
XMEMSET(nonce, 0xa5, nonceSz);
|
||||
|
||||
/* Bad parameters. */
|
||||
ExpectNull(wc_rng_new(NULL, nonceSz, HEAP_HINT));
|
||||
ExpectIntEQ(wc_rng_new_ex(&rng, NULL, nonceSz, HEAP_HINT, INVALID_DEVID),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectNull(rng);
|
||||
|
||||
/* Good parameters. */
|
||||
ExpectNotNull(rng = wc_rng_new(nonce, nonceSz, HEAP_HINT));
|
||||
#ifdef HAVE_HASHDRBG
|
||||
/* Ensure random object is usable. */
|
||||
ExpectIntEQ(wc_RNG_GenerateBlock(rng, nonce, nonceSz), 0);
|
||||
#endif
|
||||
wc_rng_free(rng);
|
||||
rng = NULL;
|
||||
ExpectNotNull(rng = wc_rng_new(nonce, 0, HEAP_HINT));
|
||||
#ifdef HAVE_HASHDRBG
|
||||
/* Ensure random object is usable. */
|
||||
ExpectIntEQ(wc_RNG_GenerateBlock(rng, nonce, nonceSz), 0);
|
||||
#endif
|
||||
wc_rng_free(rng);
|
||||
rng = NULL;
|
||||
|
||||
ExpectIntEQ(wc_rng_new_ex(&rng, nonce, nonceSz, HEAP_HINT, INVALID_DEVID),
|
||||
0);
|
||||
ExpectNotNull(rng);
|
||||
#ifdef HAVE_HASHDRBG
|
||||
/* Ensure random object is usable. */
|
||||
ExpectIntEQ(wc_RNG_GenerateBlock(rng, nonce, nonceSz), 0);
|
||||
#endif
|
||||
wc_rng_free(rng);
|
||||
rng = NULL;
|
||||
ExpectIntEQ(wc_rng_new_ex(&rng, nonce, 0, HEAP_HINT, INVALID_DEVID), 0);
|
||||
ExpectNotNull(rng);
|
||||
#ifdef HAVE_HASHDRBG
|
||||
/* Ensure random object is usable. */
|
||||
ExpectIntEQ(wc_RNG_GenerateBlock(rng, nonce, nonceSz), 0);
|
||||
#endif
|
||||
wc_rng_free(rng);
|
||||
|
||||
wc_rng_free(NULL);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
}
|
||||
|
||||
int test_wc_RNG_DRBG_Reseed(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_HASHDRBG) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
|
||||
WC_RNG rng[1];
|
||||
byte entropy[16];
|
||||
word32 entropySz = sizeof(entropy);
|
||||
|
||||
XMEMSET(entropy, 0xa5, entropySz);
|
||||
|
||||
ExpectIntEQ(wc_InitRng(rng), 0);
|
||||
|
||||
/* Bad Parameters. */
|
||||
ExpectIntEQ(wc_RNG_DRBG_Reseed(NULL, NULL, entropySz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_RNG_DRBG_Reseed(rng, NULL, entropySz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_RNG_DRBG_Reseed(NULL, entropy, entropySz),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
/* Good Parameters. */
|
||||
ExpectIntEQ(wc_RNG_DRBG_Reseed(rng, entropy, entropySz), 0);
|
||||
ExpectIntEQ(wc_RNG_GenerateBlock(rng, entropy, entropySz), 0);
|
||||
ExpectIntEQ(wc_RNG_DRBG_Reseed(rng, entropy, 0), 0);
|
||||
ExpectIntEQ(wc_RNG_GenerateBlock(rng, entropy, entropySz), 0);
|
||||
|
||||
ExpectIntEQ(wc_FreeRng(rng), 0);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
}
|
||||
|
||||
int test_wc_RNG_TestSeed(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_HASHDRBG) && \
|
||||
!(defined(HAVE_FIPS) || defined(HAVE_SELFTEST)) || \
|
||||
(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
|
||||
byte seed[16];
|
||||
byte i;
|
||||
|
||||
#ifdef TEST_WC_RNG_TESTSEED_BAD_PARAMS
|
||||
/* Doesn't handle NULL. */
|
||||
ExpectIntEQ(wc_RNG_TestSeed(NULL, sizeof(seed)),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
/* Doesn't handle seed being less than SEED_BLOCK_SZ which is not public
|
||||
* and is different for different configurations. */
|
||||
for (i = 0; i < 4; i++) {
|
||||
ExpectIntEQ(wc_RNG_TestSeed(seed, i),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Bad seed as it repeats. */
|
||||
XMEMSET(seed, 0xa5, sizeof(seed));
|
||||
/* Return value is DRBG_CONT_FAILURE which is not public. */
|
||||
ExpectIntGT(wc_RNG_TestSeed(seed, sizeof(seed)), 0);
|
||||
|
||||
/* Good seed. */
|
||||
for (i = 0; i < (byte)sizeof(seed); i++)
|
||||
seed[i] = i;
|
||||
ExpectIntEQ(wc_RNG_TestSeed(seed, sizeof(seed)), 0);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
}
|
||||
|
||||
int test_wc_RNG_HealthTest(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(HAVE_HASHDRBG)
|
||||
static const byte test1Seed[] = {
|
||||
0xa6, 0x5a, 0xd0, 0xf3, 0x45, 0xdb, 0x4e, 0x0e,
|
||||
0xff, 0xe8, 0x75, 0xc3, 0xa2, 0xe7, 0x1f, 0x42,
|
||||
0xc7, 0x12, 0x9d, 0x62, 0x0f, 0xf5, 0xc1, 0x19,
|
||||
0xa9, 0xef, 0x55, 0xf0, 0x51, 0x85, 0xe0, 0xfb,
|
||||
0x85, 0x81, 0xf9, 0x31, 0x75, 0x17, 0x27, 0x6e,
|
||||
0x06, 0xe9, 0x60, 0x7d, 0xdb, 0xcb, 0xcc, 0x2e
|
||||
};
|
||||
static const byte test1Output[] = {
|
||||
0xd3, 0xe1, 0x60, 0xc3, 0x5b, 0x99, 0xf3, 0x40,
|
||||
0xb2, 0x62, 0x82, 0x64, 0xd1, 0x75, 0x10, 0x60,
|
||||
0xe0, 0x04, 0x5d, 0xa3, 0x83, 0xff, 0x57, 0xa5,
|
||||
0x7d, 0x73, 0xa6, 0x73, 0xd2, 0xb8, 0xd8, 0x0d,
|
||||
0xaa, 0xf6, 0xa6, 0xc3, 0x5a, 0x91, 0xbb, 0x45,
|
||||
0x79, 0xd7, 0x3f, 0xd0, 0xc8, 0xfe, 0xd1, 0x11,
|
||||
0xb0, 0x39, 0x13, 0x06, 0x82, 0x8a, 0xdf, 0xed,
|
||||
0x52, 0x8f, 0x01, 0x81, 0x21, 0xb3, 0xfe, 0xbd,
|
||||
0xc3, 0x43, 0xe7, 0x97, 0xb8, 0x7d, 0xbb, 0x63,
|
||||
0xdb, 0x13, 0x33, 0xde, 0xd9, 0xd1, 0xec, 0xe1,
|
||||
0x77, 0xcf, 0xa6, 0xb7, 0x1f, 0xe8, 0xab, 0x1d,
|
||||
0xa4, 0x66, 0x24, 0xed, 0x64, 0x15, 0xe5, 0x1c,
|
||||
0xcd, 0xe2, 0xc7, 0xca, 0x86, 0xe2, 0x83, 0x99,
|
||||
0x0e, 0xea, 0xeb, 0x91, 0x12, 0x04, 0x15, 0x52,
|
||||
0x8b, 0x22, 0x95, 0x91, 0x02, 0x81, 0xb0, 0x2d,
|
||||
0xd4, 0x31, 0xf4, 0xc9, 0xf7, 0x04, 0x27, 0xdf
|
||||
};
|
||||
static const byte test2SeedA[] = {
|
||||
0x63, 0x36, 0x33, 0x77, 0xe4, 0x1e, 0x86, 0x46,
|
||||
0x8d, 0xeb, 0x0a, 0xb4, 0xa8, 0xed, 0x68, 0x3f,
|
||||
0x6a, 0x13, 0x4e, 0x47, 0xe0, 0x14, 0xc7, 0x00,
|
||||
0x45, 0x4e, 0x81, 0xe9, 0x53, 0x58, 0xa5, 0x69,
|
||||
0x80, 0x8a, 0xa3, 0x8f, 0x2a, 0x72, 0xa6, 0x23,
|
||||
0x59, 0x91, 0x5a, 0x9f, 0x8a, 0x04, 0xca, 0x68
|
||||
};
|
||||
static const byte test2SeedB[] = {
|
||||
0xe6, 0x2b, 0x8a, 0x8e, 0xe8, 0xf1, 0x41, 0xb6,
|
||||
0x98, 0x05, 0x66, 0xe3, 0xbf, 0xe3, 0xc0, 0x49,
|
||||
0x03, 0xda, 0xd4, 0xac, 0x2c, 0xdf, 0x9f, 0x22,
|
||||
0x80, 0x01, 0x0a, 0x67, 0x39, 0xbc, 0x83, 0xd3
|
||||
};
|
||||
static const byte test2Output[] = {
|
||||
0x04, 0xee, 0xc6, 0x3b, 0xb2, 0x31, 0xdf, 0x2c,
|
||||
0x63, 0x0a, 0x1a, 0xfb, 0xe7, 0x24, 0x94, 0x9d,
|
||||
0x00, 0x5a, 0x58, 0x78, 0x51, 0xe1, 0xaa, 0x79,
|
||||
0x5e, 0x47, 0x73, 0x47, 0xc8, 0xb0, 0x56, 0x62,
|
||||
0x1c, 0x18, 0xbd, 0xdc, 0xdd, 0x8d, 0x99, 0xfc,
|
||||
0x5f, 0xc2, 0xb9, 0x20, 0x53, 0xd8, 0xcf, 0xac,
|
||||
0xfb, 0x0b, 0xb8, 0x83, 0x12, 0x05, 0xfa, 0xd1,
|
||||
0xdd, 0xd6, 0xc0, 0x71, 0x31, 0x8a, 0x60, 0x18,
|
||||
0xf0, 0x3b, 0x73, 0xf5, 0xed, 0xe4, 0xd4, 0xd0,
|
||||
0x71, 0xf9, 0xde, 0x03, 0xfd, 0x7a, 0xea, 0x10,
|
||||
0x5d, 0x92, 0x99, 0xb8, 0xaf, 0x99, 0xaa, 0x07,
|
||||
0x5b, 0xdb, 0x4d, 0xb9, 0xaa, 0x28, 0xc1, 0x8d,
|
||||
0x17, 0x4b, 0x56, 0xee, 0x2a, 0x01, 0x4d, 0x09,
|
||||
0x88, 0x96, 0xff, 0x22, 0x82, 0xc9, 0x55, 0xa8,
|
||||
0x19, 0x69, 0xe0, 0x69, 0xfa, 0x8c, 0xe0, 0x07,
|
||||
0xa1, 0x80, 0x18, 0x3a, 0x07, 0xdf, 0xae, 0x17
|
||||
};
|
||||
#if !(defined(HAVE_FIPS) || defined(HAVE_SELFTEST)) || \
|
||||
(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
|
||||
static const byte testEx1Nonce[] = {
|
||||
0x89, 0xc9, 0x49, 0xe9, 0xc8, 0x04, 0xaf, 0x01,
|
||||
0x4d, 0x56, 0x04, 0xb3, 0x94, 0x59, 0xf2, 0xc8
|
||||
};
|
||||
static const byte testEx1Output[] = {
|
||||
0x2d, 0xa7, 0x72, 0x76, 0xe2, 0xab, 0xf5, 0x79,
|
||||
0x08, 0x4f, 0x1a, 0xf3, 0x53, 0xb4, 0xec, 0x58,
|
||||
0x07, 0x09, 0x1f, 0x61, 0xa4, 0x3c, 0x65, 0x38,
|
||||
0xd3, 0x43, 0x66, 0x29, 0x10, 0x81, 0x33, 0xa6,
|
||||
0xb8, 0x71, 0x8d, 0xc0, 0x27, 0x80, 0xfe, 0x11,
|
||||
0x85, 0xc6, 0xe6, 0x40, 0x69, 0x23, 0x39, 0x74,
|
||||
0x4a, 0xc9, 0xdc, 0x68, 0x6f, 0x47, 0x5c, 0x5c,
|
||||
0x56, 0xc8, 0x00, 0x78, 0xcf, 0x12, 0x7a, 0x67,
|
||||
0x27, 0x1b, 0xe7, 0x14, 0xdf, 0x9d, 0x22, 0xb5,
|
||||
0x5a, 0x8a, 0x2f, 0xdd, 0x7b, 0x6f, 0xb7, 0xf4,
|
||||
0xe3, 0x58, 0x8e, 0x6c, 0x79, 0x09, 0xf1, 0xe3,
|
||||
0x15, 0x1d, 0x9f, 0x1f, 0x69, 0x23, 0x70, 0x2f,
|
||||
0xd0, 0xee, 0x4e, 0xdd, 0x02, 0x56, 0xeb, 0x3f,
|
||||
0x25, 0xcc, 0x63, 0x06, 0x70, 0x97, 0x07, 0x76,
|
||||
0xb3, 0xe1, 0x39, 0xbd, 0xd3, 0xc2, 0x12, 0xeb,
|
||||
0x42, 0x77, 0xe8, 0xc5, 0xd0, 0xde, 0xf1, 0x4f
|
||||
};
|
||||
static const byte testEx2Nonce[] = {
|
||||
0xeb, 0xb7, 0x73, 0xf9, 0x93, 0x27, 0x8e, 0xff,
|
||||
0xf0, 0x51, 0x77, 0x8b, 0x65, 0xdb, 0x13, 0x57
|
||||
};
|
||||
static const byte testEx2Output[] = {
|
||||
0x40, 0xb2, 0xeb, 0x2b, 0x10, 0x53, 0x30, 0x8f,
|
||||
0xe4, 0xa0, 0x47, 0xe0, 0x24, 0x22, 0xe7, 0x03,
|
||||
0x03, 0x90, 0x91, 0x7b, 0xa5, 0xa8, 0xa2, 0xfd,
|
||||
0xba, 0x3b, 0xc9, 0x8e, 0xfb, 0x39, 0xef, 0xd9,
|
||||
0xae, 0x62, 0xb7, 0x0b, 0x21, 0xe6, 0x93, 0x22,
|
||||
0xeb, 0x3d, 0x3b, 0x00, 0x59, 0xaa, 0xc0, 0x27,
|
||||
0x0c, 0xde, 0xb4, 0xbd, 0x5c, 0x73, 0xa6, 0x51,
|
||||
0xf5, 0x55, 0x2c, 0xf4, 0xb8, 0xc8, 0x46, 0x04,
|
||||
0x03, 0x63, 0xa7, 0x9f, 0x81, 0xd1, 0x34, 0x1c,
|
||||
0x93, 0x86, 0x43, 0x09, 0x4c, 0x0e, 0x0a, 0x7d,
|
||||
0x54, 0x63, 0xc4, 0x72, 0xbe, 0xe3, 0x30, 0x39,
|
||||
0x3b, 0x1b, 0x8d, 0xbe, 0x55, 0x9a, 0x46, 0x11,
|
||||
0x75, 0x22, 0x00, 0xcc, 0x5a, 0xa6, 0xbb, 0x8c,
|
||||
0xd1, 0x70, 0xba, 0xbc, 0x3c, 0xf5, 0xcf, 0x81,
|
||||
0xa5, 0x17, 0x5a, 0x34, 0x0c, 0x29, 0xca, 0xcf,
|
||||
0x2b, 0x27, 0x38, 0x42, 0x21, 0x32, 0x9b, 0xc0
|
||||
};
|
||||
#endif
|
||||
byte output[WC_SHA256_DIGEST_SIZE * 4];
|
||||
|
||||
/* Bad parameters. */
|
||||
ExpectIntEQ(wc_RNG_HealthTest(0, NULL , 0 , NULL, 0,
|
||||
NULL , 0 ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_RNG_HealthTest(0, test1Seed, sizeof(test1Seed), NULL, 0,
|
||||
NULL , 0 ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_RNG_HealthTest(0, NULL , 0 , NULL, 0,
|
||||
output, sizeof(output)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_RNG_HealthTest(0, test1Seed, sizeof(test1Seed), NULL, 0,
|
||||
output, 0 ), WC_NO_ERR_TRACE(-1));
|
||||
|
||||
/* Good parameters. */
|
||||
ExpectIntEQ(wc_RNG_HealthTest(0, test1Seed, sizeof(test1Seed), NULL, 0,
|
||||
output, sizeof(output)), 0);
|
||||
ExpectBufEQ(test1Output, output, sizeof(output));
|
||||
|
||||
ExpectIntEQ(wc_RNG_HealthTest(1, test2SeedA, sizeof(test2SeedA), test2SeedB,
|
||||
sizeof(test2SeedB), output, sizeof(output)), 0);
|
||||
ExpectBufEQ(test2Output, output, sizeof(output));
|
||||
|
||||
#if !(defined(HAVE_FIPS) || defined(HAVE_SELFTEST)) || \
|
||||
(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
|
||||
/* Bad parameters. */
|
||||
ExpectIntEQ(wc_RNG_HealthTest_ex(0, NULL, 0, NULL , 0 ,
|
||||
NULL, 0, NULL , 0 , HEAP_HINT, INVALID_DEVID),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_RNG_HealthTest_ex(0, NULL, 0, test1Seed, sizeof(test1Seed),
|
||||
NULL, 0, NULL , 0 , HEAP_HINT,
|
||||
INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_RNG_HealthTest_ex(0, NULL, 0, NULL , 0 ,
|
||||
NULL, 0, output, sizeof(output), HEAP_HINT, INVALID_DEVID),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_RNG_HealthTest_ex(0, NULL, 0, test1Seed, sizeof(test1Seed),
|
||||
NULL, 0, output, 0 , HEAP_HINT, INVALID_DEVID),
|
||||
WC_NO_ERR_TRACE(-1));
|
||||
|
||||
/* Good parameters. */
|
||||
ExpectIntEQ(wc_RNG_HealthTest_ex(0, NULL, 0, test1Seed, sizeof(test1Seed),
|
||||
NULL, 0, output, sizeof(output), HEAP_HINT, INVALID_DEVID), 0);
|
||||
ExpectBufEQ(test1Output, output, sizeof(output));
|
||||
/* with nonce */
|
||||
ExpectIntEQ(wc_RNG_HealthTest_ex(0, testEx1Nonce, sizeof(testEx1Nonce),
|
||||
test1Seed, sizeof(test1Seed), NULL, 0, output, sizeof(output),
|
||||
HEAP_HINT, INVALID_DEVID), 0);
|
||||
ExpectBufEQ(testEx1Output, output, sizeof(output));
|
||||
|
||||
ExpectIntEQ(wc_RNG_HealthTest_ex(1, NULL, 0, test2SeedA, sizeof(test2SeedA),
|
||||
test2SeedB, sizeof(test2SeedB), output, sizeof(output), HEAP_HINT,
|
||||
INVALID_DEVID), 0);
|
||||
ExpectBufEQ(test2Output, output, sizeof(output));
|
||||
/* with nonce */
|
||||
ExpectIntEQ(wc_RNG_HealthTest_ex(1, testEx2Nonce, sizeof(testEx2Nonce),
|
||||
test2SeedA, sizeof(test2SeedA), test2SeedB, sizeof(test2SeedB), output,
|
||||
sizeof(output), HEAP_HINT, INVALID_DEVID), 0);
|
||||
ExpectBufEQ(testEx2Output, output, sizeof(output));
|
||||
#endif
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/* test_random.h
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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_RANDOM_H
|
||||
#define WOLFCRYPT_TEST_RANDOM_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_InitRng(void);
|
||||
int test_wc_RNG_GenerateBlock_Reseed(void);
|
||||
int test_wc_RNG_GenerateBlock(void);
|
||||
int test_wc_RNG_GenerateByte(void);
|
||||
int test_wc_InitRngNonce(void);
|
||||
int test_wc_InitRngNonce_ex(void);
|
||||
int test_wc_GenerateSeed(void);
|
||||
int test_wc_rng_new(void);
|
||||
int test_wc_RNG_DRBG_Reseed(void);
|
||||
int test_wc_RNG_TestSeed(void);
|
||||
int test_wc_RNG_HealthTest(void);
|
||||
|
||||
#define TEST_RANDOM_DECLS \
|
||||
TEST_DECL_GROUP("random", test_wc_InitRng), \
|
||||
TEST_DECL_GROUP("random", test_wc_RNG_GenerateBlock_Reseed), \
|
||||
TEST_DECL_GROUP("random", test_wc_RNG_GenerateBlock), \
|
||||
TEST_DECL_GROUP("random", test_wc_RNG_GenerateByte), \
|
||||
TEST_DECL_GROUP("random", test_wc_InitRngNonce), \
|
||||
TEST_DECL_GROUP("random", test_wc_InitRngNonce_ex), \
|
||||
TEST_DECL_GROUP("random", test_wc_GenerateSeed), \
|
||||
TEST_DECL_GROUP("random", test_wc_rng_new), \
|
||||
TEST_DECL_GROUP("random", test_wc_RNG_DRBG_Reseed), \
|
||||
TEST_DECL_GROUP("random", test_wc_RNG_TestSeed), \
|
||||
TEST_DECL_GROUP("random", test_wc_RNG_HealthTest)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_RANDOM_H */
|
|
@ -22,9 +22,17 @@
|
|||
#ifndef WOLFCRYPT_TEST_RC2_H
|
||||
#define WOLFCRYPT_TEST_RC2_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_Rc2SetKey(void);
|
||||
int test_wc_Rc2SetIV(void);
|
||||
int test_wc_Rc2EcbEncryptDecrypt(void);
|
||||
int test_wc_Rc2CbcEncryptDecrypt(void);
|
||||
|
||||
#define TEST_RC2_DECLS \
|
||||
TEST_DECL_GROUP("rc2", test_wc_Rc2SetKey), \
|
||||
TEST_DECL_GROUP("rc2", test_wc_Rc2SetIV), \
|
||||
TEST_DECL_GROUP("rc2", test_wc_Rc2EcbEncryptDecrypt), \
|
||||
TEST_DECL_GROUP("rc2", test_wc_Rc2CbcEncryptDecrypt)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_RC2_H */
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* 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
|
||||
|
@ -22,10 +23,19 @@
|
|||
#ifndef WOLFCRYPT_TEST_RIPEMD_H
|
||||
#define WOLFCRYPT_TEST_RIPEMD_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_InitRipeMd(void);
|
||||
int test_wc_RipeMdUpdate(void);
|
||||
int test_wc_RipeMdFinal(void);
|
||||
int test_wc_RipeMd_KATs(void);
|
||||
int test_wc_RipeMd_other(void);
|
||||
|
||||
#define TEST_RIPEMD_DECLS \
|
||||
TEST_DECL_GROUP("ripemd", test_wc_InitRipeMd), \
|
||||
TEST_DECL_GROUP("ripemd", test_wc_RipeMdUpdate), \
|
||||
TEST_DECL_GROUP("ripemd", test_wc_RipeMdFinal), \
|
||||
TEST_DECL_GROUP("ripemd", test_wc_RipeMd_KATs), \
|
||||
TEST_DECL_GROUP("ripemd", test_wc_RipeMd_other)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_RIPEMD_H */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,66 @@
|
|||
/* test_rsa.h
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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_RSA_H
|
||||
#define WOLFCRYPT_TEST_RSA_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_InitRsaKey(void);
|
||||
int test_wc_RsaPrivateKeyDecode(void);
|
||||
int test_wc_RsaPublicKeyDecode(void);
|
||||
int test_wc_RsaPublicKeyDecodeRaw(void);
|
||||
int test_wc_RsaPrivateKeyDecodeRaw(void);
|
||||
int test_wc_MakeRsaKey(void);
|
||||
int test_wc_CheckProbablePrime(void);
|
||||
int test_wc_RsaPSS_Verify(void);
|
||||
int test_wc_RsaPSS_VerifyCheck(void);
|
||||
int test_wc_RsaPSS_VerifyCheckInline(void);
|
||||
int test_wc_RsaKeyToDer(void);
|
||||
int test_wc_RsaKeyToPublicDer(void);
|
||||
int test_wc_RsaPublicEncryptDecrypt(void);
|
||||
int test_wc_RsaPublicEncryptDecrypt_ex(void);
|
||||
int test_wc_RsaEncryptSize(void);
|
||||
int test_wc_RsaSSL_SignVerify(void);
|
||||
int test_wc_RsaFlattenPublicKey(void);
|
||||
int test_wc_RsaDecrypt_BoundsCheck(void);
|
||||
|
||||
#define TEST_RSA_DECLS \
|
||||
TEST_DECL_GROUP("rsa", test_wc_InitRsaKey), \
|
||||
TEST_DECL_GROUP("rsa", test_wc_RsaPrivateKeyDecode), \
|
||||
TEST_DECL_GROUP("rsa", test_wc_RsaPublicKeyDecode), \
|
||||
TEST_DECL_GROUP("rsa", test_wc_RsaPublicKeyDecodeRaw), \
|
||||
TEST_DECL_GROUP("rsa", test_wc_RsaPrivateKeyDecodeRaw), \
|
||||
TEST_DECL_GROUP("rsa", test_wc_MakeRsaKey), \
|
||||
TEST_DECL_GROUP("rsa", test_wc_CheckProbablePrime), \
|
||||
TEST_DECL_GROUP("rsa", test_wc_RsaPSS_Verify), \
|
||||
TEST_DECL_GROUP("rsa", test_wc_RsaPSS_VerifyCheck), \
|
||||
TEST_DECL_GROUP("rsa", test_wc_RsaPSS_VerifyCheckInline), \
|
||||
TEST_DECL_GROUP("rsa", test_wc_RsaKeyToDer), \
|
||||
TEST_DECL_GROUP("rsa", test_wc_RsaKeyToPublicDer), \
|
||||
TEST_DECL_GROUP("rsa", test_wc_RsaPublicEncryptDecrypt), \
|
||||
TEST_DECL_GROUP("rsa", test_wc_RsaPublicEncryptDecrypt_ex), \
|
||||
TEST_DECL_GROUP("rsa", test_wc_RsaEncryptSize), \
|
||||
TEST_DECL_GROUP("rsa", test_wc_RsaSSL_SignVerify), \
|
||||
TEST_DECL_GROUP("rsa", test_wc_RsaFlattenPublicKey), \
|
||||
TEST_DECL_GROUP("rsa", test_wc_RsaDecrypt_BoundsCheck)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_RSA_H */
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef WOLFCRYPT_TEST_SHA_H
|
||||
#define WOLFCRYPT_TEST_SHA_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_InitSha(void);
|
||||
int test_wc_ShaUpdate(void);
|
||||
int test_wc_ShaFinal(void);
|
||||
|
@ -33,4 +35,16 @@ int test_wc_ShaGetHash(void);
|
|||
int test_wc_ShaTransform(void);
|
||||
int test_wc_Sha_Flags(void);
|
||||
|
||||
#define TEST_SHA_DECLS \
|
||||
TEST_DECL_GROUP("sha", test_wc_InitSha), \
|
||||
TEST_DECL_GROUP("sha", test_wc_ShaUpdate), \
|
||||
TEST_DECL_GROUP("sha", test_wc_ShaFinal), \
|
||||
TEST_DECL_GROUP("sha", test_wc_ShaFinalRaw), \
|
||||
TEST_DECL_GROUP("sha", test_wc_Sha_KATs), \
|
||||
TEST_DECL_GROUP("sha", test_wc_Sha_other), \
|
||||
TEST_DECL_GROUP("sha", test_wc_ShaCopy), \
|
||||
TEST_DECL_GROUP("sha", test_wc_ShaGetHash), \
|
||||
TEST_DECL_GROUP("sha", test_wc_ShaTransform), \
|
||||
TEST_DECL_GROUP("sha", test_wc_Sha_Flags)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_SHA_H */
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef WOLFCRYPT_TEST_SHA256_H
|
||||
#define WOLFCRYPT_TEST_SHA256_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_InitSha256(void);
|
||||
int test_wc_Sha256Update(void);
|
||||
int test_wc_Sha256Final(void);
|
||||
|
@ -42,4 +44,26 @@ int test_wc_Sha224Copy(void);
|
|||
int test_wc_Sha224GetHash(void);
|
||||
int test_wc_Sha224_Flags(void);
|
||||
|
||||
#define TEST_SHA256_DECLS \
|
||||
TEST_DECL_GROUP("sha256", test_wc_InitSha256), \
|
||||
TEST_DECL_GROUP("sha256", test_wc_Sha256Update), \
|
||||
TEST_DECL_GROUP("sha256", test_wc_Sha256Final), \
|
||||
TEST_DECL_GROUP("sha256", test_wc_Sha256FinalRaw), \
|
||||
TEST_DECL_GROUP("sha256", test_wc_Sha256_KATs), \
|
||||
TEST_DECL_GROUP("sha256", test_wc_Sha256_other), \
|
||||
TEST_DECL_GROUP("sha256", test_wc_Sha256Copy), \
|
||||
TEST_DECL_GROUP("sha256", test_wc_Sha256GetHash), \
|
||||
TEST_DECL_GROUP("sha256", test_wc_Sha256Transform), \
|
||||
TEST_DECL_GROUP("sha256", test_wc_Sha256_Flags)
|
||||
|
||||
#define TEST_SHA224_DECLS \
|
||||
TEST_DECL_GROUP("sha224", test_wc_InitSha224), \
|
||||
TEST_DECL_GROUP("sha224", test_wc_Sha224Update), \
|
||||
TEST_DECL_GROUP("sha224", test_wc_Sha224Final), \
|
||||
TEST_DECL_GROUP("sha224", test_wc_Sha224_KATs), \
|
||||
TEST_DECL_GROUP("sha224", test_wc_Sha224_other), \
|
||||
TEST_DECL_GROUP("sha224", test_wc_Sha224Copy), \
|
||||
TEST_DECL_GROUP("sha224", test_wc_Sha224GetHash), \
|
||||
TEST_DECL_GROUP("sha224", test_wc_Sha224_Flags)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_SHA256_H */
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef WOLFCRYPT_TEST_SHA3_H
|
||||
#define WOLFCRYPT_TEST_SHA3_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_InitSha3(void);
|
||||
int test_wc_Sha3_Update(void);
|
||||
int test_wc_Sha3_Final(void);
|
||||
|
@ -56,4 +58,41 @@ int test_wc_Shake256_Absorb(void);
|
|||
int test_wc_Shake256_SqueezeBlocks(void);
|
||||
int test_wc_Shake256_XOF(void);
|
||||
|
||||
#define TEST_SHA3_DECLS \
|
||||
TEST_DECL_GROUP("sha3", test_wc_InitSha3), \
|
||||
TEST_DECL_GROUP("sha3", test_wc_Sha3_Update), \
|
||||
TEST_DECL_GROUP("sha3", test_wc_Sha3_Final), \
|
||||
TEST_DECL_GROUP("sha3", test_wc_Sha3_224_KATs), \
|
||||
TEST_DECL_GROUP("sha3", test_wc_Sha3_256_KATs), \
|
||||
TEST_DECL_GROUP("sha3", test_wc_Sha3_384_KATs), \
|
||||
TEST_DECL_GROUP("sha3", test_wc_Sha3_512_KATs), \
|
||||
TEST_DECL_GROUP("sha3", test_wc_Sha3_other), \
|
||||
TEST_DECL_GROUP("sha3", test_wc_Sha3_Copy), \
|
||||
TEST_DECL_GROUP("sha3", test_wc_Sha3_GetHash), \
|
||||
TEST_DECL_GROUP("sha3", test_wc_Sha3_Flags)
|
||||
|
||||
#define TEST_SHAKE128_DECLS \
|
||||
TEST_DECL_GROUP("shake128", test_wc_InitShake128), \
|
||||
TEST_DECL_GROUP("shake128", test_wc_Shake128_Update), \
|
||||
TEST_DECL_GROUP("shake128", test_wc_Shake128_Final), \
|
||||
TEST_DECL_GROUP("shake128", test_wc_Shake128_KATs), \
|
||||
TEST_DECL_GROUP("shake128", test_wc_Shake128_other), \
|
||||
TEST_DECL_GROUP("shake128", test_wc_Shake128_Copy), \
|
||||
TEST_DECL_GROUP("shake128", test_wc_Shake128Hash), \
|
||||
TEST_DECL_GROUP("shake128", test_wc_Shake128_Absorb), \
|
||||
TEST_DECL_GROUP("shake128", test_wc_Shake128_SqueezeBlocks), \
|
||||
TEST_DECL_GROUP("shake128", test_wc_Shake128_XOF)
|
||||
|
||||
#define TEST_SHAKE256_DECLS \
|
||||
TEST_DECL_GROUP("shake256", test_wc_InitShake256), \
|
||||
TEST_DECL_GROUP("shake256", test_wc_Shake256_Update), \
|
||||
TEST_DECL_GROUP("shake256", test_wc_Shake256_Final), \
|
||||
TEST_DECL_GROUP("shake256", test_wc_Shake256_KATs), \
|
||||
TEST_DECL_GROUP("shake256", test_wc_Shake256_other), \
|
||||
TEST_DECL_GROUP("shake256", test_wc_Shake256_Copy), \
|
||||
TEST_DECL_GROUP("shake256", test_wc_Shake256Hash), \
|
||||
TEST_DECL_GROUP("shake256", test_wc_Shake256_Absorb), \
|
||||
TEST_DECL_GROUP("shake256", test_wc_Shake256_SqueezeBlocks), \
|
||||
TEST_DECL_GROUP("shake256", test_wc_Shake256_XOF)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_SHA3_H */
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef WOLFCRYPT_TEST_SHA512_H
|
||||
#define WOLFCRYPT_TEST_SHA512_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_InitSha512(void);
|
||||
int test_wc_Sha512Update(void);
|
||||
int test_wc_Sha512Final(void);
|
||||
|
@ -65,4 +67,51 @@ int test_wc_Sha384Copy(void);
|
|||
int test_wc_Sha384GetHash(void);
|
||||
int test_wc_Sha384_Flags(void);
|
||||
|
||||
#define TEST_SHA512_DECLS \
|
||||
TEST_DECL_GROUP("sha512", test_wc_InitSha512), \
|
||||
TEST_DECL_GROUP("sha512", test_wc_Sha512Update), \
|
||||
TEST_DECL_GROUP("sha512", test_wc_Sha512Final), \
|
||||
TEST_DECL_GROUP("sha512", test_wc_Sha512FinalRaw), \
|
||||
TEST_DECL_GROUP("sha512", test_wc_Sha512_KATs), \
|
||||
TEST_DECL_GROUP("sha512", test_wc_Sha512_other), \
|
||||
TEST_DECL_GROUP("sha512", test_wc_Sha512Copy), \
|
||||
TEST_DECL_GROUP("sha512", test_wc_Sha512GetHash), \
|
||||
TEST_DECL_GROUP("sha512", test_wc_Sha512Transform), \
|
||||
TEST_DECL_GROUP("sha512", test_wc_Sha512_Flags)
|
||||
|
||||
#define TEST_SHA512_224_DECLS \
|
||||
TEST_DECL_GROUP("sha512_224", test_wc_InitSha512_224), \
|
||||
TEST_DECL_GROUP("sha512_224", test_wc_Sha512_224Update), \
|
||||
TEST_DECL_GROUP("sha512_224", test_wc_Sha512_224Final), \
|
||||
TEST_DECL_GROUP("sha512_224", test_wc_Sha512_224FinalRaw), \
|
||||
TEST_DECL_GROUP("sha512_224", test_wc_Sha512_224_KATs), \
|
||||
TEST_DECL_GROUP("sha512_224", test_wc_Sha512_224_other), \
|
||||
TEST_DECL_GROUP("sha512_224", test_wc_Sha512_224Copy), \
|
||||
TEST_DECL_GROUP("sha512_224", test_wc_Sha512_224GetHash), \
|
||||
TEST_DECL_GROUP("sha512_224", test_wc_Sha512_224Transform), \
|
||||
TEST_DECL_GROUP("sha512_224", test_wc_Sha512_224_Flags)
|
||||
|
||||
#define TEST_SHA512_256_DECLS \
|
||||
TEST_DECL_GROUP("sha512_256", test_wc_InitSha512_256), \
|
||||
TEST_DECL_GROUP("sha512_256", test_wc_Sha512_256Update), \
|
||||
TEST_DECL_GROUP("sha512_256", test_wc_Sha512_256Final), \
|
||||
TEST_DECL_GROUP("sha512_256", test_wc_Sha512_256FinalRaw), \
|
||||
TEST_DECL_GROUP("sha512_256", test_wc_Sha512_256_KATs), \
|
||||
TEST_DECL_GROUP("sha512_256", test_wc_Sha512_256_other), \
|
||||
TEST_DECL_GROUP("sha512_256", test_wc_Sha512_256Copy), \
|
||||
TEST_DECL_GROUP("sha512_256", test_wc_Sha512_256GetHash), \
|
||||
TEST_DECL_GROUP("sha512_256", test_wc_Sha512_256Transform), \
|
||||
TEST_DECL_GROUP("sha512_256", test_wc_Sha512_256_Flags)
|
||||
|
||||
#define TEST_SHA384_DECLS \
|
||||
TEST_DECL_GROUP("sha384", test_wc_InitSha384), \
|
||||
TEST_DECL_GROUP("sha384", test_wc_Sha384Update), \
|
||||
TEST_DECL_GROUP("sha384", test_wc_Sha384Final), \
|
||||
TEST_DECL_GROUP("sha384", test_wc_Sha384FinalRaw), \
|
||||
TEST_DECL_GROUP("sha384", test_wc_Sha384_KATs), \
|
||||
TEST_DECL_GROUP("sha384", test_wc_Sha384_other), \
|
||||
TEST_DECL_GROUP("sha384", test_wc_Sha384Copy), \
|
||||
TEST_DECL_GROUP("sha384", test_wc_Sha384GetHash), \
|
||||
TEST_DECL_GROUP("sha384", test_wc_Sha384_Flags)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_SHA512_H */
|
||||
|
|
|
@ -0,0 +1,157 @@
|
|||
/* test_signature.c
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H)
|
||||
#include <wolfssl/options.h>
|
||||
#endif
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
|
||||
#ifdef NO_INLINE
|
||||
#include <wolfssl/wolfcrypt/misc.h>
|
||||
#else
|
||||
#define WOLFSSL_MISC_INCLUDED
|
||||
#include <wolfcrypt/src/misc.c>
|
||||
#endif
|
||||
|
||||
#include <wolfssl/wolfcrypt/signature.h>
|
||||
#include <wolfssl/wolfcrypt/rsa.h>
|
||||
#include <wolfssl/wolfcrypt/ecc.h>
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
#include <tests/unit.h>
|
||||
#include <tests/api/api.h>
|
||||
#include <tests/api/test_signature.h>
|
||||
|
||||
/* Testing wc_SignatureGetSize() for signature type ECC */
|
||||
int test_wc_SignatureGetSize_ecc(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if !defined(NO_SIG_WRAPPER) && defined(HAVE_ECC) && !defined(NO_ECC256)
|
||||
enum wc_SignatureType sig_type;
|
||||
word32 key_len;
|
||||
ecc_key ecc;
|
||||
const char* qx =
|
||||
"fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0";
|
||||
const char* qy =
|
||||
"d4ccd6dae698208aa8c3a6f39e45510d03be09b2f124bfc067856c324f9b4d09";
|
||||
const char* d =
|
||||
"be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25";
|
||||
|
||||
XMEMSET(&ecc, 0, sizeof(ecc_key));
|
||||
|
||||
ExpectIntEQ(wc_ecc_init(&ecc), 0);
|
||||
ExpectIntEQ(wc_ecc_import_raw(&ecc, qx, qy, d, "SECP256R1"), 0);
|
||||
/* Input for signature type ECC */
|
||||
sig_type = WC_SIGNATURE_TYPE_ECC;
|
||||
key_len = sizeof(ecc_key);
|
||||
ExpectIntGT(wc_SignatureGetSize(sig_type, &ecc, key_len), 0);
|
||||
|
||||
/* Test bad args */
|
||||
/* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
|
||||
sig_type = (enum wc_SignatureType) 100;
|
||||
/* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
|
||||
ExpectIntEQ(wc_SignatureGetSize(sig_type, &ecc, key_len),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
sig_type = WC_SIGNATURE_TYPE_ECC;
|
||||
ExpectIntEQ(wc_SignatureGetSize(sig_type, NULL, key_len), 0);
|
||||
key_len = (word32)0;
|
||||
ExpectIntEQ(wc_SignatureGetSize(sig_type, &ecc, key_len),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
DoExpectIntEQ(wc_ecc_free(&ecc), 0);
|
||||
#endif /* !NO_SIG_WRAPPER && HAVE_ECC && !NO_ECC256 */
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_SignatureGetSize_ecc() */
|
||||
|
||||
/* Testing wc_SignatureGetSize() for signature type rsa */
|
||||
int test_wc_SignatureGetSize_rsa(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if !defined(NO_SIG_WRAPPER) && !defined(NO_RSA)
|
||||
enum wc_SignatureType sig_type;
|
||||
word32 key_len;
|
||||
word32 idx = 0;
|
||||
RsaKey rsa_key;
|
||||
byte* tmp = NULL;
|
||||
size_t bytes;
|
||||
|
||||
XMEMSET(&rsa_key, 0, sizeof(RsaKey));
|
||||
|
||||
#ifdef USE_CERT_BUFFERS_1024
|
||||
bytes = (size_t)sizeof_client_key_der_1024;
|
||||
if (bytes < (size_t)sizeof_client_key_der_1024)
|
||||
bytes = (size_t)sizeof_client_cert_der_1024;
|
||||
#elif defined(USE_CERT_BUFFERS_2048)
|
||||
bytes = (size_t)sizeof_client_key_der_2048;
|
||||
if (bytes < (size_t)sizeof_client_cert_der_2048)
|
||||
bytes = (size_t)sizeof_client_cert_der_2048;
|
||||
#else
|
||||
bytes = FOURK_BUF;
|
||||
#endif
|
||||
|
||||
ExpectNotNull(tmp = (byte*)XMALLOC(bytes, HEAP_HINT,
|
||||
DYNAMIC_TYPE_TMP_BUFFER));
|
||||
if (tmp != NULL) {
|
||||
#ifdef USE_CERT_BUFFERS_1024
|
||||
XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
|
||||
#elif defined(USE_CERT_BUFFERS_2048)
|
||||
XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
|
||||
#elif !defined(NO_FILESYSTEM)
|
||||
XFILE file = XBADFILE;
|
||||
ExpectTrue((file = XFOPEN(clientKey, "rb")) != XBADFILE);
|
||||
ExpectIntGT(bytes = (size_t)XFREAD(tmp, 1, FOURK_BUF, file), 0);
|
||||
if (file != XBADFILE) {
|
||||
XFCLOSE(file);
|
||||
}
|
||||
#else
|
||||
ExpectFail();
|
||||
#endif
|
||||
}
|
||||
|
||||
ExpectIntEQ(wc_InitRsaKey_ex(&rsa_key, HEAP_HINT, testDevId), 0);
|
||||
ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, &idx, &rsa_key, (word32)bytes), 0);
|
||||
/* Input for signature type RSA */
|
||||
sig_type = WC_SIGNATURE_TYPE_RSA;
|
||||
key_len = sizeof(RsaKey);
|
||||
ExpectIntGT(wc_SignatureGetSize(sig_type, &rsa_key, key_len), 0);
|
||||
|
||||
/* Test bad args */
|
||||
/* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
|
||||
sig_type = (enum wc_SignatureType)100;
|
||||
/* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
|
||||
ExpectIntEQ(wc_SignatureGetSize(sig_type, &rsa_key, key_len),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
sig_type = WC_SIGNATURE_TYPE_RSA;
|
||||
ExpectIntEQ(wc_SignatureGetSize(sig_type, NULL, key_len),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
key_len = (word32)0;
|
||||
ExpectIntEQ(wc_SignatureGetSize(sig_type, &rsa_key, key_len),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
DoExpectIntEQ(wc_FreeRsaKey(&rsa_key), 0);
|
||||
XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif /* !NO_SIG_WRAPPER && !NO_RSA */
|
||||
return EXPECT_RESULT();
|
||||
} /* END test_wc_SignatureGetSize_rsa(void) */
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/* test_signature.h
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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_SIGNATURE_H
|
||||
#define WOLFCRYPT_TEST_SIGNATURE_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_SignatureGetSize_ecc(void);
|
||||
int test_wc_SignatureGetSize_rsa(void);
|
||||
|
||||
#define TEST_SIGNATURE_DECLS \
|
||||
TEST_DECL_GROUP("signature", test_wc_SignatureGetSize_ecc), \
|
||||
TEST_DECL_GROUP("signature", test_wc_SignatureGetSize_ecc)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_SIGNATURE_H */
|
|
@ -0,0 +1,657 @@
|
|||
/* test_sm2.c
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H)
|
||||
#include <wolfssl/options.h>
|
||||
#endif
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
|
||||
#ifdef NO_INLINE
|
||||
#include <wolfssl/wolfcrypt/misc.h>
|
||||
#else
|
||||
#define WOLFSSL_MISC_INCLUDED
|
||||
#include <wolfcrypt/src/misc.c>
|
||||
#endif
|
||||
|
||||
#include <wolfssl/wolfcrypt/sm2.h>
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
#include <tests/unit.h>
|
||||
#include <tests/api/api.h>
|
||||
#include <tests/api/test_sm2.h>
|
||||
|
||||
/*
|
||||
* Testing wc_ecc_sm2_make_key()
|
||||
*/
|
||||
int test_wc_ecc_sm2_make_key(void)
|
||||
{
|
||||
int res = TEST_SKIPPED;
|
||||
#if defined(HAVE_ECC) && defined(WOLFSSL_SM2)
|
||||
EXPECT_DECLS;
|
||||
WC_RNG rng[1];
|
||||
ecc_key key[1];
|
||||
|
||||
XMEMSET(rng, 0, sizeof(*rng));
|
||||
XMEMSET(key, 0, sizeof(*key));
|
||||
|
||||
ExpectIntEQ(wc_InitRng(rng), 0);
|
||||
ExpectIntEQ(wc_ecc_init(key), 0);
|
||||
|
||||
/* Test invalid parameters. */
|
||||
ExpectIntEQ(wc_ecc_sm2_make_key(NULL, NULL, WC_ECC_FLAG_NONE),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_make_key(rng, NULL, WC_ECC_FLAG_NONE),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_make_key(NULL, key, WC_ECC_FLAG_NONE),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
/* Test valid parameters. */
|
||||
ExpectIntEQ(wc_ecc_sm2_make_key(rng, key, WC_ECC_FLAG_NONE), 0);
|
||||
ExpectIntEQ(key->dp->id, ECC_SM2P256V1);
|
||||
|
||||
wc_ecc_free(key);
|
||||
wc_FreeRng(rng);
|
||||
#ifdef FP_ECC
|
||||
wc_ecc_fp_free();
|
||||
#endif
|
||||
|
||||
res = EXPECT_RESULT();
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
* Testing wc_ecc_sm2_shared_secret()
|
||||
*/
|
||||
int test_wc_ecc_sm2_shared_secret(void)
|
||||
{
|
||||
int res = TEST_SKIPPED;
|
||||
#if defined(HAVE_ECC) && defined(WOLFSSL_SM2)
|
||||
EXPECT_DECLS;
|
||||
WC_RNG rng[1];
|
||||
ecc_key keyA[1];
|
||||
ecc_key keyB[1];
|
||||
byte outA[32];
|
||||
byte outB[32];
|
||||
word32 outALen = 32;
|
||||
word32 outBLen = 32;
|
||||
|
||||
XMEMSET(rng, 0, sizeof(*rng));
|
||||
XMEMSET(keyA, 0, sizeof(*keyA));
|
||||
XMEMSET(keyB, 0, sizeof(*keyB));
|
||||
|
||||
ExpectIntEQ(wc_InitRng(rng), 0);
|
||||
ExpectIntEQ(wc_ecc_init(keyA), 0);
|
||||
ExpectIntEQ(wc_ecc_init(keyB), 0);
|
||||
ExpectIntEQ(wc_ecc_sm2_make_key(rng, keyA, WC_ECC_FLAG_NONE), 0);
|
||||
ExpectIntEQ(wc_ecc_sm2_make_key(rng, keyB, WC_ECC_FLAG_NONE), 0);
|
||||
|
||||
#ifdef ECC_TIMING_RESISTANT
|
||||
ExpectIntEQ(wc_ecc_set_rng(keyA, rng), 0);
|
||||
ExpectIntEQ(wc_ecc_set_rng(keyB, rng), 0);
|
||||
#endif
|
||||
|
||||
/* Test invalid parameters. */
|
||||
ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, NULL, NULL, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, NULL, NULL, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, keyB, NULL, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, NULL, outA, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, NULL, NULL, &outALen),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, keyB, outA, &outALen),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, NULL, outA, &outALen),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, keyB, NULL, &outALen),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, keyB, outA, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
/* Test valid parameters. */
|
||||
ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, keyB, outA, &outALen), 0);
|
||||
ExpectIntLE(outALen, 32);
|
||||
ExpectIntEQ(wc_ecc_sm2_shared_secret(keyB, keyA, outB, &outBLen), 0);
|
||||
ExpectIntLE(outBLen, 32);
|
||||
ExpectIntEQ(outALen, outBLen);
|
||||
ExpectBufEQ(outA, outB, outALen);
|
||||
|
||||
wc_ecc_free(keyB);
|
||||
wc_ecc_free(keyA);
|
||||
wc_FreeRng(rng);
|
||||
#ifdef FP_ECC
|
||||
wc_ecc_fp_free();
|
||||
#endif
|
||||
|
||||
res = EXPECT_RESULT();
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
* Testing wc_ecc_sm2_create_digest()
|
||||
*/
|
||||
int test_wc_ecc_sm2_create_digest(void)
|
||||
{
|
||||
int res = TEST_SKIPPED;
|
||||
#if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && !defined(NO_HASH_WRAPPER) && \
|
||||
(defined(WOLFSSL_SM3) || !defined(NO_SHA256))
|
||||
EXPECT_DECLS;
|
||||
ecc_key key[1];
|
||||
enum wc_HashType hashType;
|
||||
unsigned char pub[] = {
|
||||
0x04,
|
||||
0x63, 0x7F, 0x1B, 0x13, 0x50, 0x36, 0xC9, 0x33,
|
||||
0xDC, 0x3F, 0x7A, 0x8E, 0xBB, 0x1B, 0x7B, 0x2F,
|
||||
0xD1, 0xDF, 0xBD, 0x26, 0x8D, 0x4F, 0x89, 0x4B,
|
||||
0x5A, 0xD4, 0x7D, 0xBD, 0xBE, 0xCD, 0x55, 0x8F,
|
||||
0xE8, 0x81, 0x01, 0xD0, 0x80, 0x48, 0xE3, 0x6C,
|
||||
0xCB, 0xF6, 0x1C, 0xA3, 0x8D, 0xDF, 0x7A, 0xBA,
|
||||
0x54, 0x2B, 0x44, 0x86, 0xE9, 0x9E, 0x49, 0xF3,
|
||||
0xA7, 0x47, 0x0A, 0x85, 0x7A, 0x09, 0x64, 0x33
|
||||
};
|
||||
unsigned char id[] = {
|
||||
0x01, 0x02, 0x03,
|
||||
};
|
||||
unsigned char msg[] = {
|
||||
0x01, 0x02, 0x03,
|
||||
};
|
||||
unsigned char hash[32];
|
||||
#ifdef WOLFSSL_SM3
|
||||
unsigned char expHash[32] = {
|
||||
0xc1, 0xdd, 0x92, 0xc5, 0x60, 0xd3, 0x94, 0x28,
|
||||
0xeb, 0x0f, 0x57, 0x79, 0x3f, 0xc9, 0x96, 0xc5,
|
||||
0xfa, 0xf5, 0x90, 0xb2, 0x64, 0x2f, 0xaf, 0x9c,
|
||||
0xc8, 0x57, 0x21, 0x6a, 0x52, 0x7e, 0xf1, 0x95
|
||||
};
|
||||
#else
|
||||
unsigned char expHash[32] = {
|
||||
0xea, 0x41, 0x55, 0x21, 0x61, 0x00, 0x5c, 0x9a,
|
||||
0x57, 0x35, 0x6b, 0x49, 0xca, 0x8f, 0x65, 0xc2,
|
||||
0x0e, 0x29, 0x0c, 0xa0, 0x1d, 0xa7, 0xc4, 0xed,
|
||||
0xdd, 0x51, 0x12, 0xf6, 0xe7, 0x55, 0xc5, 0xf4
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SM3
|
||||
hashType = WC_HASH_TYPE_SM3;
|
||||
#else
|
||||
hashType = WC_HASH_TYPE_SHA256;
|
||||
#endif
|
||||
|
||||
XMEMSET(key, 0, sizeof(*key));
|
||||
|
||||
ExpectIntEQ(wc_ecc_init(key), 0);
|
||||
|
||||
/* Test with no curve set. */
|
||||
ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
|
||||
hashType, hash, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
ExpectIntEQ(wc_ecc_import_x963_ex(pub, sizeof(pub), key, ECC_SM2P256V1), 0);
|
||||
|
||||
/* Test invalid parameters. */
|
||||
ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), NULL, sizeof(msg),
|
||||
hashType, NULL, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), NULL, sizeof(msg),
|
||||
hashType, NULL, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), msg, sizeof(msg),
|
||||
hashType, NULL, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), NULL, sizeof(msg),
|
||||
hashType, hash, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), NULL, sizeof(msg),
|
||||
hashType, NULL, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), msg, sizeof(msg),
|
||||
hashType, hash, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), NULL, sizeof(msg),
|
||||
hashType, hash, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
|
||||
hashType, NULL, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
|
||||
hashType, hash, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
/* Bad hash type. */
|
||||
/* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
|
||||
ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
|
||||
-1, hash, 0, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
/* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
|
||||
/* Bad hash size. */
|
||||
ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
|
||||
hashType, hash, 0, key), WC_NO_ERR_TRACE(BUFFER_E));
|
||||
|
||||
/* Test valid parameters. */
|
||||
ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
|
||||
hashType, hash, sizeof(hash), key), 0);
|
||||
ExpectBufEQ(hash, expHash, sizeof(expHash));
|
||||
|
||||
wc_ecc_free(key);
|
||||
|
||||
res = EXPECT_RESULT();
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
* Testing wc_ecc_sm2_verify_hash_ex()
|
||||
*/
|
||||
int test_wc_ecc_sm2_verify_hash_ex(void)
|
||||
{
|
||||
int res = TEST_SKIPPED;
|
||||
#if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_VERIFY) && \
|
||||
defined(WOLFSSL_PUBLIC_MP)
|
||||
EXPECT_DECLS;
|
||||
ecc_key key[1];
|
||||
mp_int r[1];
|
||||
mp_int s[1];
|
||||
int verified;
|
||||
unsigned char pub[] = {
|
||||
0x04,
|
||||
0x63, 0x7F, 0x1B, 0x13, 0x50, 0x36, 0xC9, 0x33,
|
||||
0xDC, 0x3F, 0x7A, 0x8E, 0xBB, 0x1B, 0x7B, 0x2F,
|
||||
0xD1, 0xDF, 0xBD, 0x26, 0x8D, 0x4F, 0x89, 0x4B,
|
||||
0x5A, 0xD4, 0x7D, 0xBD, 0xBE, 0xCD, 0x55, 0x8F,
|
||||
0xE8, 0x81, 0x01, 0xD0, 0x80, 0x48, 0xE3, 0x6C,
|
||||
0xCB, 0xF6, 0x1C, 0xA3, 0x8D, 0xDF, 0x7A, 0xBA,
|
||||
0x54, 0x2B, 0x44, 0x86, 0xE9, 0x9E, 0x49, 0xF3,
|
||||
0xA7, 0x47, 0x0A, 0x85, 0x7A, 0x09, 0x64, 0x33
|
||||
};
|
||||
unsigned char hash[] = {
|
||||
0x3B, 0xFA, 0x5F, 0xFB, 0xC4, 0x27, 0x8C, 0x9D,
|
||||
0x02, 0x3A, 0x19, 0xCB, 0x1E, 0xAA, 0xD2, 0xF1,
|
||||
0x50, 0x69, 0x5B, 0x20
|
||||
};
|
||||
unsigned char rData[] = {
|
||||
0xD2, 0xFC, 0xA3, 0x88, 0xE3, 0xDF, 0xA3, 0x00,
|
||||
0x73, 0x9B, 0x3C, 0x2A, 0x0D, 0xAD, 0x44, 0xA2,
|
||||
0xFC, 0x62, 0xD5, 0x6B, 0x84, 0x54, 0xD8, 0x40,
|
||||
0x22, 0x62, 0x3D, 0x5C, 0xA6, 0x61, 0x9B, 0xE7,
|
||||
};
|
||||
unsigned char sData[] = {
|
||||
0x1D,
|
||||
0xB5, 0xB5, 0xD9, 0xD8, 0xF1, 0x20, 0xDD, 0x97,
|
||||
0x92, 0xBF, 0x7E, 0x9B, 0x3F, 0xE6, 0x3C, 0x4B,
|
||||
0x03, 0xD8, 0x80, 0xBD, 0xB7, 0x27, 0x7E, 0x6A,
|
||||
0x84, 0x23, 0xDE, 0x61, 0x7C, 0x8D, 0xDC
|
||||
};
|
||||
unsigned char rBadData[] = {
|
||||
0xD2, 0xFC, 0xA3, 0x88, 0xE3, 0xDF, 0xA3, 0x00,
|
||||
0x73, 0x9B, 0x3C, 0x2A, 0x0D, 0xAD, 0x44, 0xA2,
|
||||
0xFC, 0x62, 0xD5, 0x6B, 0x84, 0x54, 0xD8, 0x40,
|
||||
0x22, 0x62, 0x3D, 0x5C, 0xA6, 0x61, 0x9B, 0xE8,
|
||||
};
|
||||
|
||||
XMEMSET(key, 0, sizeof(*key));
|
||||
XMEMSET(r, 0, sizeof(*r));
|
||||
XMEMSET(s, 0, sizeof(*s));
|
||||
|
||||
ExpectIntEQ(mp_init(r), 0);
|
||||
ExpectIntEQ(mp_init(s), 0);
|
||||
ExpectIntEQ(mp_read_unsigned_bin(r, rData, sizeof(rData)), 0);
|
||||
ExpectIntEQ(mp_read_unsigned_bin(s, sData, sizeof(sData)), 0);
|
||||
|
||||
ExpectIntEQ(wc_ecc_init(key), 0);
|
||||
|
||||
/* Test with no curve set. */
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
|
||||
&verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
ExpectIntEQ(wc_ecc_import_x963_ex(pub, sizeof(pub), key, ECC_SM2P256V1), 0);
|
||||
|
||||
/* Test invalid parameters. */
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, NULL, sizeof(hash),
|
||||
NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, NULL, NULL, sizeof(hash),
|
||||
NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, s, NULL, sizeof(hash),
|
||||
NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, hash, sizeof(hash),
|
||||
NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, NULL, sizeof(hash),
|
||||
&verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, NULL, sizeof(hash),
|
||||
NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, s, hash, sizeof(hash),
|
||||
&verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, NULL, hash, sizeof(hash),
|
||||
&verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, NULL, sizeof(hash),
|
||||
&verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
|
||||
NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
|
||||
&verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
/* Make key not on the SM2 curve. */
|
||||
ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
|
||||
&verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
|
||||
|
||||
/* Test valid parameters. */
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
|
||||
&verified, key), 0);
|
||||
ExpectIntEQ(verified, 1);
|
||||
|
||||
ExpectIntEQ(mp_read_unsigned_bin(r, rBadData, sizeof(rBadData)), 0);
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
|
||||
&verified, key), 0);
|
||||
ExpectIntEQ(verified, 0);
|
||||
|
||||
mp_free(s);
|
||||
mp_free(r);
|
||||
wc_ecc_free(key);
|
||||
#ifdef FP_ECC
|
||||
wc_ecc_fp_free();
|
||||
#endif
|
||||
|
||||
res = EXPECT_RESULT();
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
* Testing wc_ecc_sm2_verify_hash()
|
||||
*/
|
||||
int test_wc_ecc_sm2_verify_hash(void)
|
||||
{
|
||||
int res = TEST_SKIPPED;
|
||||
#if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_VERIFY)
|
||||
EXPECT_DECLS;
|
||||
ecc_key key[1];
|
||||
int verified;
|
||||
unsigned char pub[] = {
|
||||
0x04,
|
||||
0x63, 0x7F, 0x1B, 0x13, 0x50, 0x36, 0xC9, 0x33,
|
||||
0xDC, 0x3F, 0x7A, 0x8E, 0xBB, 0x1B, 0x7B, 0x2F,
|
||||
0xD1, 0xDF, 0xBD, 0x26, 0x8D, 0x4F, 0x89, 0x4B,
|
||||
0x5A, 0xD4, 0x7D, 0xBD, 0xBE, 0xCD, 0x55, 0x8F,
|
||||
0xE8, 0x81, 0x01, 0xD0, 0x80, 0x48, 0xE3, 0x6C,
|
||||
0xCB, 0xF6, 0x1C, 0xA3, 0x8D, 0xDF, 0x7A, 0xBA,
|
||||
0x54, 0x2B, 0x44, 0x86, 0xE9, 0x9E, 0x49, 0xF3,
|
||||
0xA7, 0x47, 0x0A, 0x85, 0x7A, 0x09, 0x64, 0x33
|
||||
};
|
||||
unsigned char hash[] = {
|
||||
0x3B, 0xFA, 0x5F, 0xFB, 0xC4, 0x27, 0x8C, 0x9D,
|
||||
0x02, 0x3A, 0x19, 0xCB, 0x1E, 0xAA, 0xD2, 0xF1,
|
||||
0x50, 0x69, 0x5B, 0x20
|
||||
};
|
||||
unsigned char sig[] = {
|
||||
0x30, 0x45, 0x02, 0x21, 0x00, 0xD2, 0xFC, 0xA3,
|
||||
0x88, 0xE3, 0xDF, 0xA3, 0x00, 0x73, 0x9B, 0x3C,
|
||||
0x2A, 0x0D, 0xAD, 0x44, 0xA2, 0xFC, 0x62, 0xD5,
|
||||
0x6B, 0x84, 0x54, 0xD8, 0x40, 0x22, 0x62, 0x3D,
|
||||
0x5C, 0xA6, 0x61, 0x9B, 0xE7, 0x02, 0x20, 0x1D,
|
||||
0xB5, 0xB5, 0xD9, 0xD8, 0xF1, 0x20, 0xDD, 0x97,
|
||||
0x92, 0xBF, 0x7E, 0x9B, 0x3F, 0xE6, 0x3C, 0x4B,
|
||||
0x03, 0xD8, 0x80, 0xBD, 0xB7, 0x27, 0x7E, 0x6A,
|
||||
0x84, 0x23, 0xDE, 0x61, 0x7C, 0x8D, 0xDC
|
||||
};
|
||||
unsigned char sigBad[] = {
|
||||
0x30, 0x45, 0x02, 0x21, 0x00, 0xD2, 0xFC, 0xA3,
|
||||
0x88, 0xE3, 0xDF, 0xA3, 0x00, 0x73, 0x9B, 0x3C,
|
||||
0x2A, 0x0D, 0xAD, 0x44, 0xA2, 0xFC, 0x62, 0xD5,
|
||||
0x6B, 0x84, 0x54, 0xD8, 0x40, 0x22, 0x62, 0x3D,
|
||||
0x5C, 0xA6, 0x61, 0x9B, 0xE7, 0x02, 0x20, 0x1D,
|
||||
0xB5, 0xB5, 0xD9, 0xD8, 0xF1, 0x20, 0xDD, 0x97,
|
||||
0x92, 0xBF, 0x7E, 0x9B, 0x3F, 0xE6, 0x3C, 0x4B,
|
||||
0x03, 0xD8, 0x80, 0xBD, 0xB7, 0x27, 0x7E, 0x6A,
|
||||
0x84, 0x23, 0xDE, 0x61, 0x7C, 0x8D, 0xDD
|
||||
};
|
||||
|
||||
|
||||
XMEMSET(key, 0, sizeof(*key));
|
||||
ExpectIntEQ(wc_ecc_init(key), 0);
|
||||
|
||||
/* Test with no curve set. */
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
|
||||
&verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
ExpectIntEQ(wc_ecc_import_x963_ex(pub, sizeof(pub), key, ECC_SM2P256V1), 0);
|
||||
|
||||
/* Test invalid parameters. */
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), NULL, sizeof(hash),
|
||||
NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), NULL, sizeof(hash),
|
||||
NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), hash, sizeof(hash),
|
||||
NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), NULL, sizeof(hash),
|
||||
&verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), NULL, sizeof(hash),
|
||||
NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), hash, sizeof(hash),
|
||||
&verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), NULL, sizeof(hash),
|
||||
&verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
|
||||
NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
|
||||
&verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
/* Make key not on the SM2 curve. */
|
||||
ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
|
||||
&verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
|
||||
|
||||
/* Test valid parameters. */
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
|
||||
&verified, key), 0);
|
||||
ExpectIntEQ(verified, 1);
|
||||
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash(sigBad, sizeof(sigBad), hash,
|
||||
sizeof(hash), &verified, key), 0);
|
||||
ExpectIntEQ(verified, 0);
|
||||
|
||||
wc_ecc_free(key);
|
||||
#ifdef FP_ECC
|
||||
wc_ecc_fp_free();
|
||||
#endif
|
||||
|
||||
res = EXPECT_RESULT();
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
* Testing wc_ecc_sm2_sign_hash_ex()
|
||||
*/
|
||||
int test_wc_ecc_sm2_sign_hash_ex(void)
|
||||
{
|
||||
int res = TEST_SKIPPED;
|
||||
#if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_SIGN) && \
|
||||
defined(WOLFSSL_PUBLIC_MP)
|
||||
EXPECT_DECLS;
|
||||
WC_RNG rng[1];
|
||||
ecc_key key[1];
|
||||
mp_int r[1];
|
||||
mp_int s[1];
|
||||
unsigned char hash[32];
|
||||
#ifdef HAVE_ECC_VERIFY
|
||||
int verified;
|
||||
#endif
|
||||
|
||||
XMEMSET(rng, 0, sizeof(*rng));
|
||||
XMEMSET(key, 0, sizeof(*key));
|
||||
XMEMSET(r, 0, sizeof(*r));
|
||||
XMEMSET(s, 0, sizeof(*s));
|
||||
|
||||
ExpectIntEQ(wc_InitRng(rng), 0);
|
||||
ExpectIntEQ(mp_init(r), 0);
|
||||
ExpectIntEQ(mp_init(s), 0);
|
||||
ExpectIntEQ(wc_RNG_GenerateBlock(rng, hash, sizeof(hash)), 0);
|
||||
|
||||
ExpectIntEQ(wc_ecc_init(key), 0);
|
||||
|
||||
/* Test with no curve set. */
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, s),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
ExpectIntEQ(wc_ecc_sm2_make_key(rng, key, WC_ECC_FLAG_NONE), 0);
|
||||
|
||||
/* Test invalid parameters. */
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, NULL, NULL,
|
||||
NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), NULL, NULL, NULL,
|
||||
NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), rng, NULL, NULL,
|
||||
NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, key, NULL,
|
||||
NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, NULL, r,
|
||||
NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, NULL, NULL,
|
||||
s), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), rng, key, r, s),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), NULL, key, r, s),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, NULL, r, s),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, NULL, s),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, NULL),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
/* Make key not on the SM2 curve. */
|
||||
ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, s),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
|
||||
|
||||
#ifdef WOLFSSL_SP_MATH_ALL
|
||||
{
|
||||
mp_int smallR[1];
|
||||
sp_init_size(smallR, 1);
|
||||
/* Force failure in _ecc_sm2_calc_r_s by r being too small. */
|
||||
ExpectIntLT(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key,
|
||||
smallR, s), 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Test valid parameters. */
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, s),
|
||||
0);
|
||||
#ifdef HAVE_ECC_VERIFY
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash), &verified,
|
||||
key), 0);
|
||||
ExpectIntEQ(verified, 1);
|
||||
#endif
|
||||
|
||||
mp_free(s);
|
||||
mp_free(r);
|
||||
wc_ecc_free(key);
|
||||
wc_FreeRng(rng);
|
||||
#ifdef FP_ECC
|
||||
wc_ecc_fp_free();
|
||||
#endif
|
||||
|
||||
res = EXPECT_RESULT();
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
* Testing wc_ecc_sm2_sign_hash()
|
||||
*/
|
||||
int test_wc_ecc_sm2_sign_hash(void)
|
||||
{
|
||||
int res = TEST_SKIPPED;
|
||||
#if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_SIGN)
|
||||
EXPECT_DECLS;
|
||||
WC_RNG rng[1];
|
||||
ecc_key key[1];
|
||||
unsigned char hash[32];
|
||||
unsigned char sig[72];
|
||||
word32 sigSz = sizeof(sig);
|
||||
#ifdef HAVE_ECC_VERIFY
|
||||
int verified;
|
||||
#endif
|
||||
|
||||
XMEMSET(rng, 0, sizeof(*rng));
|
||||
XMEMSET(key, 0, sizeof(*key));
|
||||
|
||||
ExpectIntEQ(wc_InitRng(rng), 0);
|
||||
ExpectIntEQ(wc_RNG_GenerateBlock(rng, hash, sizeof(hash)), 0);
|
||||
|
||||
ExpectIntEQ(wc_ecc_init(key), 0);
|
||||
|
||||
/* Test with no curve set. */
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
ExpectIntEQ(wc_ecc_sm2_make_key(rng, key, WC_ECC_FLAG_NONE), 0);
|
||||
|
||||
/* Test invalid parameters. */
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, NULL, NULL,
|
||||
NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), NULL, NULL, NULL,
|
||||
NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), sig, NULL, NULL,
|
||||
NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, &sigSz, NULL,
|
||||
NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, NULL, rng,
|
||||
NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, NULL, NULL,
|
||||
key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), sig, &sigSz, rng,
|
||||
key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), NULL, &sigSz, rng,
|
||||
key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, NULL, rng,
|
||||
key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, NULL,
|
||||
key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng,
|
||||
NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
/* Make key not on the SM2 curve. */
|
||||
ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
|
||||
|
||||
/* Test valid parameters. */
|
||||
ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key),
|
||||
0);
|
||||
#ifdef HAVE_ECC_VERIFY
|
||||
ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sigSz, hash, sizeof(hash),
|
||||
&verified, key), 0);
|
||||
ExpectIntEQ(verified, 1);
|
||||
#endif
|
||||
|
||||
wc_ecc_free(key);
|
||||
wc_FreeRng(rng);
|
||||
#ifdef FP_ECC
|
||||
wc_ecc_fp_free();
|
||||
#endif
|
||||
|
||||
res = EXPECT_RESULT();
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
/* test_sm2.h
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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_SM2_H
|
||||
#define WOLFCRYPT_TEST_SM2_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_ecc_sm2_make_key(void);
|
||||
int test_wc_ecc_sm2_shared_secret(void);
|
||||
int test_wc_ecc_sm2_create_digest(void);
|
||||
int test_wc_ecc_sm2_verify_hash_ex(void);
|
||||
int test_wc_ecc_sm2_verify_hash(void);
|
||||
int test_wc_ecc_sm2_sign_hash_ex(void);
|
||||
int test_wc_ecc_sm2_sign_hash(void);
|
||||
|
||||
#define TEST_SM2_DECLS \
|
||||
TEST_DECL_GROUP("sm2", test_wc_ecc_sm2_make_key), \
|
||||
TEST_DECL_GROUP("sm2", test_wc_ecc_sm2_shared_secret), \
|
||||
TEST_DECL_GROUP("sm2", test_wc_ecc_sm2_create_digest), \
|
||||
TEST_DECL_GROUP("sm2", test_wc_ecc_sm2_verify_hash_ex), \
|
||||
TEST_DECL_GROUP("sm2", test_wc_ecc_sm2_verify_hash), \
|
||||
TEST_DECL_GROUP("sm2", test_wc_ecc_sm2_sign_hash_ex), \
|
||||
TEST_DECL_GROUP("sm2", test_wc_ecc_sm2_sign_hash)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_SM2_H */
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef WOLFCRYPT_TEST_SM3_H
|
||||
#define WOLFCRYPT_TEST_SM3_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_InitSm3(void);
|
||||
int test_wc_Sm3Update(void);
|
||||
int test_wc_Sm3Final(void);
|
||||
|
@ -32,4 +34,15 @@ int test_wc_Sm3Copy(void);
|
|||
int test_wc_Sm3GetHash(void);
|
||||
int test_wc_Sm3_Flags(void);
|
||||
|
||||
#define TEST_SM3_DECLS \
|
||||
TEST_DECL_GROUP("sm3", test_wc_InitSm3), \
|
||||
TEST_DECL_GROUP("sm3", test_wc_Sm3Update), \
|
||||
TEST_DECL_GROUP("sm3", test_wc_Sm3Final), \
|
||||
TEST_DECL_GROUP("sm3", test_wc_Sm3FinalRaw), \
|
||||
TEST_DECL_GROUP("sm3", test_wc_Sm3_KATs), \
|
||||
TEST_DECL_GROUP("sm3", test_wc_Sm3_other), \
|
||||
TEST_DECL_GROUP("sm3", test_wc_Sm3Copy), \
|
||||
TEST_DECL_GROUP("sm3", test_wc_Sm3GetHash), \
|
||||
TEST_DECL_GROUP("sm3", test_wc_Sm3_Flags)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_SM3_H */
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef WOLFCRYPT_TEST_SM4_H
|
||||
#define WOLFCRYPT_TEST_SM4_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_Sm4(void);
|
||||
int test_wc_Sm4Ecb(void);
|
||||
int test_wc_Sm4Cbc(void);
|
||||
|
@ -29,4 +31,12 @@ int test_wc_Sm4Ctr(void);
|
|||
int test_wc_Sm4Gcm(void);
|
||||
int test_wc_Sm4Ccm(void);
|
||||
|
||||
#define TEST_SM4_DECLS \
|
||||
TEST_DECL_GROUP("sm4", test_wc_Sm4), \
|
||||
TEST_DECL_GROUP("sm4", test_wc_Sm4Ecb), \
|
||||
TEST_DECL_GROUP("sm4", test_wc_Sm4Cbc), \
|
||||
TEST_DECL_GROUP("sm4", test_wc_Sm4Ctr), \
|
||||
TEST_DECL_GROUP("sm4", test_wc_Sm4Gcm), \
|
||||
TEST_DECL_GROUP("sm4", test_wc_Sm4Ccm)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_SM4_H */
|
||||
|
|
|
@ -22,6 +22,11 @@
|
|||
#ifndef WOLFCRYPT_TEST_WC_ENCRYPT_H
|
||||
#define WOLFCRYPT_TEST_WC_ENCRYPT_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_wc_Des3_CbcEncryptDecryptWithKey(void);
|
||||
|
||||
#define TEST_WC_ENCRYPT_DECLS \
|
||||
TEST_DECL_GROUP("wc_encrypt", test_wc_Des3_CbcEncryptDecryptWithKey)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_WC_ENCRYPT_H */
|
||||
|
|
|
@ -0,0 +1,204 @@
|
|||
/* test_wolfmath.c
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H)
|
||||
#include <wolfssl/options.h>
|
||||
#endif
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
|
||||
#ifdef NO_INLINE
|
||||
#include <wolfssl/wolfcrypt/misc.h>
|
||||
#else
|
||||
#define WOLFSSL_MISC_INCLUDED
|
||||
#include <wolfcrypt/src/misc.c>
|
||||
#endif
|
||||
|
||||
#include <wolfssl/wolfcrypt/wolfmath.h>
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
#include <tests/unit.h>
|
||||
#include <tests/api/api.h>
|
||||
#include <tests/api/test_wolfmath.h>
|
||||
|
||||
/*
|
||||
* Testing get_digit_count
|
||||
*/
|
||||
int test_get_digit_count(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if !defined(WOLFSSL_SP_MATH) && defined(WOLFSSL_PUBLIC_MP)
|
||||
mp_int a;
|
||||
|
||||
XMEMSET(&a, 0, sizeof(mp_int));
|
||||
|
||||
ExpectIntEQ(mp_init(&a), 0);
|
||||
|
||||
ExpectIntEQ(get_digit_count(NULL), 0);
|
||||
ExpectIntEQ(get_digit_count(&a), 0);
|
||||
|
||||
mp_clear(&a);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* End test_get_digit_count */
|
||||
|
||||
/*
|
||||
* Testing get_digit
|
||||
*/
|
||||
int test_get_digit(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(WOLFSSL_PUBLIC_MP)
|
||||
mp_int a;
|
||||
int n = 0;
|
||||
|
||||
XMEMSET(&a, 0, sizeof(mp_int));
|
||||
|
||||
ExpectIntEQ(mp_init(&a), MP_OKAY);
|
||||
ExpectIntEQ(get_digit(NULL, n), 0);
|
||||
ExpectIntEQ(get_digit(&a, n), 0);
|
||||
|
||||
mp_clear(&a);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* End test_get_digit */
|
||||
|
||||
/*
|
||||
* Testing get_rand_digit
|
||||
*/
|
||||
int test_get_rand_digit(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if !defined(WC_NO_RNG) && defined(WOLFSSL_PUBLIC_MP)
|
||||
WC_RNG rng;
|
||||
mp_digit d;
|
||||
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
|
||||
ExpectIntEQ(get_rand_digit(&rng, &d), 0);
|
||||
ExpectIntEQ(get_rand_digit(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(get_rand_digit(NULL, &d), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(get_rand_digit(&rng, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* End test_get_rand_digit */
|
||||
|
||||
/*
|
||||
* Testing mp_cond_copy
|
||||
*/
|
||||
int test_mp_cond_copy(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if (defined(HAVE_ECC) || defined(WOLFSSL_MP_COND_COPY)) && \
|
||||
defined(WOLFSSL_PUBLIC_MP)
|
||||
mp_int a;
|
||||
mp_int b;
|
||||
int copy = 0;
|
||||
|
||||
XMEMSET(&a, 0, sizeof(mp_int));
|
||||
XMEMSET(&b, 0, sizeof(mp_int));
|
||||
|
||||
ExpectIntEQ(mp_init(&a), MP_OKAY);
|
||||
ExpectIntEQ(mp_init(&b), MP_OKAY);
|
||||
|
||||
ExpectIntEQ(mp_cond_copy(NULL, copy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(mp_cond_copy(NULL, copy, &b), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(mp_cond_copy(&a, copy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(mp_cond_copy(&a, copy, &b), 0);
|
||||
|
||||
mp_clear(&a);
|
||||
mp_clear(&b);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* End test_mp_cond_copy */
|
||||
|
||||
/*
|
||||
* Testing mp_rand
|
||||
*/
|
||||
int test_mp_rand(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if defined(WC_RSA_BLINDING) && defined(WOLFSSL_PUBLIC_MP)
|
||||
mp_int a;
|
||||
WC_RNG rng;
|
||||
int digits = 1;
|
||||
|
||||
XMEMSET(&a, 0, sizeof(mp_int));
|
||||
XMEMSET(&rng, 0, sizeof(WC_RNG));
|
||||
|
||||
ExpectIntEQ(mp_init(&a), MP_OKAY);
|
||||
ExpectIntEQ(wc_InitRng(&rng), 0);
|
||||
|
||||
ExpectIntEQ(mp_rand(&a, digits, NULL), WC_NO_ERR_TRACE(MISSING_RNG_E));
|
||||
ExpectIntEQ(mp_rand(NULL, digits, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(mp_rand(&a, 0, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
ExpectIntEQ(mp_rand(&a, digits, &rng), 0);
|
||||
|
||||
mp_clear(&a);
|
||||
DoExpectIntEQ(wc_FreeRng(&rng), 0);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* End test_mp_rand */
|
||||
|
||||
/*
|
||||
* Testing wc_export_int
|
||||
*/
|
||||
int test_wc_export_int(void)
|
||||
{
|
||||
EXPECT_DECLS;
|
||||
#if (defined(HAVE_ECC) || defined(WOLFSSL_EXPORT_INT)) && \
|
||||
defined(WOLFSSL_PUBLIC_MP)
|
||||
mp_int mp;
|
||||
byte buf[32];
|
||||
word32 keySz = (word32)sizeof(buf);
|
||||
word32 len = (word32)sizeof(buf);
|
||||
|
||||
XMEMSET(&mp, 0, sizeof(mp_int));
|
||||
|
||||
ExpectIntEQ(mp_init(&mp), MP_OKAY);
|
||||
ExpectIntEQ(mp_set(&mp, 1234), 0);
|
||||
|
||||
ExpectIntEQ(wc_export_int(NULL, buf, &len, keySz, WC_TYPE_UNSIGNED_BIN),
|
||||
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
|
||||
len = sizeof(buf)-1;
|
||||
ExpectIntEQ(wc_export_int(&mp, buf, &len, keySz, WC_TYPE_UNSIGNED_BIN),
|
||||
WC_NO_ERR_TRACE(BUFFER_E));
|
||||
len = sizeof(buf);
|
||||
ExpectIntEQ(wc_export_int(&mp, buf, &len, keySz, WC_TYPE_UNSIGNED_BIN), 0);
|
||||
len = 4; /* test input too small */
|
||||
ExpectIntEQ(wc_export_int(&mp, buf, &len, 0, WC_TYPE_HEX_STR),
|
||||
WC_NO_ERR_TRACE(BUFFER_E));
|
||||
len = sizeof(buf);
|
||||
ExpectIntEQ(wc_export_int(&mp, buf, &len, 0, WC_TYPE_HEX_STR), 0);
|
||||
/* hex version of 1234 is 04D2 and should be 4 digits + 1 null */
|
||||
ExpectIntEQ(len, 5);
|
||||
|
||||
mp_clear(&mp);
|
||||
#endif
|
||||
return EXPECT_RESULT();
|
||||
} /* End test_wc_export_int */
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/* test_wolfmath.h
|
||||
*
|
||||
* Copyright (C) 2006-2025 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 2 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_WOLFMATH_H
|
||||
#define WOLFCRYPT_TEST_WOLFMATH_H
|
||||
|
||||
#include <tests/api/api_decl.h>
|
||||
|
||||
int test_get_digit_count(void);
|
||||
int test_get_digit(void);
|
||||
int test_get_rand_digit(void);
|
||||
int test_mp_cond_copy(void);
|
||||
int test_mp_rand(void);
|
||||
int test_wc_export_int(void);
|
||||
|
||||
#define TEST_WOLFMATH_DECLS \
|
||||
TEST_DECL_GROUP("wolfmath", test_get_digit_count), \
|
||||
TEST_DECL_GROUP("wolfmath", test_get_digit), \
|
||||
TEST_DECL_GROUP("wolfmath", test_get_rand_digit), \
|
||||
TEST_DECL_GROUP("wolfmath", test_mp_cond_copy), \
|
||||
TEST_DECL_GROUP("wolfmath", test_mp_rand), \
|
||||
TEST_DECL_GROUP("wolfmath", test_wc_export_int)
|
||||
|
||||
#endif /* WOLFCRYPT_TEST_WOLFMATH_H */
|
42
tests/unit.c
42
tests/unit.c
|
@ -52,14 +52,19 @@ int main(int argc, char** argv)
|
|||
static void UnitTest_Usage(void)
|
||||
{
|
||||
printf("Usage: ./tests/unit.test <options>\n");
|
||||
printf(" -?, --help Display this usage information.\n");
|
||||
printf(" --list List the API tests.\n");
|
||||
printf(" --api Only perform API tests.\n");
|
||||
printf(" -<number> Run the API test identified by number.\n");
|
||||
printf(" Can be specified multiple times.\n");
|
||||
printf(" -<string> Run the API test identified by name.\n");
|
||||
printf(" Can be specified multiple times.\n");
|
||||
printf(" <filename> Name of cipher suite testing file.\n");
|
||||
printf(" -?, --help Display this usage information.\n");
|
||||
printf(" --list List the API tests.\n");
|
||||
printf(" --api Only perform API tests.\n");
|
||||
printf(" --no-api Do not perform API tests.\n");
|
||||
printf(" --stopOnFail Stops API testing on first failure.\n");
|
||||
printf(" --groups List known group names.\n");
|
||||
printf(" --group <string> Functions in this group are tested.\n");
|
||||
printf(" -<number> Run the API test identified by number.\n");
|
||||
printf(" Can be specified multiple times.\n");
|
||||
printf(" -<string> Run the API test identified by name.\n");
|
||||
printf(" Can be specified multiple times.\n");
|
||||
printf(" -~<string> Functions with this substring are tested.\n");
|
||||
printf(" <filename> Name of cipher suite testing file.\n");
|
||||
}
|
||||
|
||||
int unit_test(int argc, char** argv)
|
||||
|
@ -196,6 +201,27 @@ int unit_test(int argc, char** argv)
|
|||
else if (XSTRCMP(argv[1], "--no-api") == 0) {
|
||||
apiTesting = 0;
|
||||
}
|
||||
else if (XSTRCMP(argv[1], "--stopOnFail") == 0) {
|
||||
ApiTest_StopOnFail();
|
||||
}
|
||||
else if (XSTRCMP(argv[1], "--groups") == 0) {
|
||||
ApiTest_PrintGroups();
|
||||
goto exit;
|
||||
}
|
||||
else if (XSTRCMP(argv[1], "--group") == 0) {
|
||||
if (argc == 1) {
|
||||
fprintf(stderr, "No group name supplied\n");
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
ret = ApiTest_RunGroup(argv[2]);
|
||||
if (ret != 0) {
|
||||
goto exit;
|
||||
}
|
||||
allTesting = 0;
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
else if (argv[1][0] == '-' && argv[1][1] >= '0' && argv[1][1] <= '9') {
|
||||
ret = ApiTest_RunIdx(atoi(argv[1] + 1));
|
||||
if (ret != 0) {
|
||||
|
|
|
@ -414,7 +414,10 @@ int test_wolfSSL_client_server_nofail_memio(test_ssl_cbf* client_cb,
|
|||
test_ssl_cbf* server_cb, test_cbType client_on_handshake);
|
||||
#endif /* HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
|
||||
|
||||
void ApiTest_StopOnFail(void);
|
||||
void ApiTest_PrintTestCases(void);
|
||||
void ApiTest_PrintGroups(void);
|
||||
int ApiTest_RunGroup(char* name);
|
||||
int ApiTest_RunIdx(int idx);
|
||||
int ApiTest_RunPartName(char* name);
|
||||
int ApiTest_RunName(char* name);
|
||||
|
|
|
@ -38764,9 +38764,11 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed448_test(void)
|
|||
(void)keySz;
|
||||
(void)sigSz;
|
||||
|
||||
#if defined(HAVE_ED448_KEY_IMPORT)
|
||||
ret = ed448_test_check_key();
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
#endif
|
||||
#ifdef WOLFSSL_TEST_CERT
|
||||
ret = ed448_test_cert();
|
||||
if (ret < 0)
|
||||
|
|
Loading…
Reference in New Issue