Files
wolfssl/tests/api/test_wolfmath.h
T
Daniele Lacamera 8efb4ddf19 tests: add sp_int.c (sp-math module) MC/DC DecisionCoverage + white-box
tests/api/test_wolfmath.c gains six DecisionCoverage test functions
covering sp_int.c's mp_*/sp_* API: the allocation family (sp_init_size,
sp_grow, sp_copy, sp_exch), the shift family (sp_set_bit, sp_2expt,
sp_lshd, sp_rshb), the single-digit and multi-precision arithmetic
families (sp_add_d/sp_sub_d/sp_mul_d/sp_div_d/sp_mod_d/sp_div_2/
sp_div_2_mod_ct/sp_add/sp_sub/sp_addmod_ct/sp_submod_ct/sp_div,
including their WOLFSSL_SP_INT_NEGATIVE sign-path counterparts), the
conversion family (sp_div_2d/sp_mod_2d/sp_mul_2d/sp_sqrmod/
sp_mont_red_ex/sp_to_unsigned_bin_len(_ct)/sp_tohex/sp_read_radix), and
the sp_invmod/sp_exptmod_ex/sp_gcd/sp_prime_is_prime(_ex) top-level
argument and degenerate-input checks. Each exercises an internal
size/capacity guard or argument check via a deliberately undersized
destination (sp_init_size with a small size) or an out-of-range
argument - legitimate, public ways to reach decisions valid-sized RSA/
ECC/DH usage never trips.

tests/unit-mcdc/test_sp_int_whitebox.c is a new white-box supplement
(compiles sp_int.c in directly) closing the sp_count_bits/sp_cnt_lsb
non-normalized-digit trim loops: no public caller can produce that
state since every public mutator normalizes via sp_clamp before
returning.

Part of the ISO 26262 per-module MC/DC campaign's sp-math module
(wolfcrypt/src/sp_int.c, Phase 1): 412/547 (75.32%) MC/DC across 6
build-variant axes (WOLFSSL_SP_MATH_ALL vs bare WOLFSSL_SP_MATH,
WOLFSSL_SP_SMALL, WOLFSSL_SP_INT_NEGATIVE, WOLFSSL_SP_DIV_WORD_HALF,
WOLFSSL_SMALL_STACK) + the white-box, up from a 318/547 baseline. The
remaining gaps are deep invmod/exptmod/prime/gcd internal state-machine
internals, the SP-accelerated-backend-entangled RSA/DH key-size
dispatch, and other structural residuals; campaign-side files (config,
module registry, baseline) live in the separate testing repo.
2026-07-13 11:19:23 +02:00

55 lines
2.2 KiB
C

/* test_wolfmath.h
*
* Copyright (C) 2006-2026 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#ifndef WOLFCRYPT_TEST_WOLFMATH_H
#define WOLFCRYPT_TEST_WOLFMATH_H
#include <tests/api/api_decl.h>
int test_mp_get_digit_count(void);
int test_mp_get_digit(void);
int test_mp_get_rand_digit(void);
int test_mp_cond_copy(void);
int test_mp_rand(void);
int test_wc_export_int(void);
int test_wc_SpIntSizeDecisionCoverage(void);
int test_wc_SpIntShiftDecisionCoverage(void);
int test_wc_SpIntDigitArithDecisionCoverage(void);
int test_wc_SpIntArithDecisionCoverage(void);
int test_wc_SpIntConvDecisionCoverage(void);
int test_wc_SpIntExptGcdDecisionCoverage(void);
#define TEST_WOLFMATH_DECLS \
TEST_DECL_GROUP("wolfmath", test_mp_get_digit_count), \
TEST_DECL_GROUP("wolfmath", test_mp_get_digit), \
TEST_DECL_GROUP("wolfmath", test_mp_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), \
TEST_DECL_GROUP("wolfmath", test_wc_SpIntSizeDecisionCoverage), \
TEST_DECL_GROUP("wolfmath", test_wc_SpIntShiftDecisionCoverage), \
TEST_DECL_GROUP("wolfmath", test_wc_SpIntDigitArithDecisionCoverage),\
TEST_DECL_GROUP("wolfmath", test_wc_SpIntArithDecisionCoverage), \
TEST_DECL_GROUP("wolfmath", test_wc_SpIntConvDecisionCoverage), \
TEST_DECL_GROUP("wolfmath", test_wc_SpIntExptGcdDecisionCoverage)
#endif /* WOLFCRYPT_TEST_WOLFMATH_H */