mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-10-24 04:09:07 +03:00
Two check-source-text / clang-tidy fixes on the MC/DC test files: * Wrap error-code comparison operands in WC_NO_ERR_TRACE() (check-source-text check I). Code comparisons (blake2b/blake2s/hpke white-boxes and the logging global-queue pull check) are wrapped; the pseudo-code in doc comments and the WB_CHECK message strings (mcdc_fault_alloc.h, dsa/mlkem fault white-boxes, logging white-box) are reworded so an error code is no longer adjacent to == / != . * Uppercase the integer-literal suffixes in test_sakke.c (384u -> 384U, etc.) for clang-tidy readability-uppercase-literal-suffix. No behavioral change.
87 lines
3.6 KiB
C
87 lines
3.6 KiB
C
/* test_blake2b_whitebox.c
|
|
*
|
|
* 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
|
|
*/
|
|
|
|
/*
|
|
* MC/DC white-box supplement for wolfcrypt/src/blake2b.c.
|
|
*
|
|
* The internal blake2b_init() (blake2b.c:125) and blake2b_init_key()
|
|
* (blake2b.c:142/144) argument guards -- "!outlen || outlen > BLAKE2B_OUTBYTES"
|
|
* and "!key || !keylen || keylen > BLAKE2B_KEYBYTES" -- are unreachable through
|
|
* the public wc_InitBlake2b* wrappers, which fully validate digestSz (word32)
|
|
* before narrowing it to a byte and calling these functions. blake2b_init* are
|
|
* also non-WOLFSSL_API (declared in blake2-int.h without export), so they must
|
|
* NOT be called from tests/api (they would fail to link against the shared
|
|
* library). This white-box #includes blake2b.c directly so the internal guards
|
|
* are reachable, and drives both short-circuit halves of every operand.
|
|
*
|
|
* Crash-safety: every call here either returns BAD_FUNC_ARG before touching
|
|
* state, or is a valid init of a stack blake2b_state, so no cleanup is needed.
|
|
*/
|
|
|
|
#include <wolfcrypt/src/blake2b.c>
|
|
|
|
#include <stdio.h>
|
|
|
|
static int wb_fail = 0;
|
|
#define WB_NOTE(msg) do { printf(" [wb] %s\n", (msg)); } while (0)
|
|
|
|
int main(void)
|
|
{
|
|
printf("blake2b.c white-box supplement\n");
|
|
#ifdef HAVE_BLAKE2B
|
|
blake2b_state bs;
|
|
byte key[BLAKE2B_KEYBYTES];
|
|
|
|
XMEMSET(&bs, 0, sizeof(bs));
|
|
XMEMSET(key, 0, sizeof(key));
|
|
|
|
/* blake2b_init(): !outlen || outlen > BLAKE2B_OUTBYTES */
|
|
if (blake2b_init(&bs, 0) != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) wb_fail = 1;
|
|
if (blake2b_init(&bs, BLAKE2B_OUTBYTES + 1) != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) wb_fail = 1;
|
|
if (blake2b_init(&bs, BLAKE2B_OUTBYTES) != 0) wb_fail = 1;
|
|
|
|
/* blake2b_init_key(): outlen bound, key/keylen held valid to isolate it. */
|
|
if (blake2b_init_key(&bs, 0, key, BLAKE2B_KEYBYTES) != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
|
|
wb_fail = 1;
|
|
if (blake2b_init_key(&bs, BLAKE2B_OUTBYTES + 1, key, BLAKE2B_KEYBYTES)
|
|
!= WC_NO_ERR_TRACE(BAD_FUNC_ARG)) wb_fail = 1;
|
|
|
|
/* blake2b_init_key(): !key || !keylen || keylen > BLAKE2B_KEYBYTES,
|
|
* outlen held valid to isolate this decision. */
|
|
if (blake2b_init_key(&bs, BLAKE2B_OUTBYTES, NULL, BLAKE2B_KEYBYTES)
|
|
!= WC_NO_ERR_TRACE(BAD_FUNC_ARG)) wb_fail = 1;
|
|
if (blake2b_init_key(&bs, BLAKE2B_OUTBYTES, key, 0) != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
|
|
wb_fail = 1;
|
|
if (blake2b_init_key(&bs, BLAKE2B_OUTBYTES, key, BLAKE2B_KEYBYTES + 1)
|
|
!= WC_NO_ERR_TRACE(BAD_FUNC_ARG)) wb_fail = 1;
|
|
/* Baseline: both decisions false on both lines. */
|
|
if (blake2b_init_key(&bs, BLAKE2B_OUTBYTES, key, BLAKE2B_KEYBYTES) != 0)
|
|
wb_fail = 1;
|
|
|
|
WB_NOTE("blake2b_init / blake2b_init_key outlen+key+keylen guards exercised");
|
|
printf("done (%s)\n", wb_fail ? "with skips" : "ok");
|
|
#else
|
|
printf(" HAVE_BLAKE2B not defined; nothing to exercise\n");
|
|
#endif
|
|
(void)wb_fail;
|
|
return 0;
|
|
}
|