Skip to content

Conversation

@gojimmypi
Copy link
Contributor

Description

Updates gencertbuf.pl to generate #define sizeof_... instead of static const int sizeof_...

For example:

#define sizeof_client_key_der_1024 (sizeof(client_key_der_1024))

Instead of

static const int sizeof_client_key_der_1024 = sizeof(client_key_der_1024);

Since C89/C90 (which Watcom generally defaults to), sizeof must be a compile-time constant expression when used in a static initializer.

Otherwise Watcom will fail to compile:

@echo off

set WATCOM=C:\watcom
set PATH=%WATCOM%\binnt;%WATCOM%\binw;%PATH%
set INCLUDE=%WATCOM%\h;%WATCOM%\h\nt
set EDPATH=%WATCOM%\eddat
set WIPFC=%WATCOM%\wipfc
set LIB=%WATCOM%\lib386;%WATCOM%\lib386\nt

echo ""
echo "Config #2a"
rmdir /s /q .\build-watcom
cmake -B build-watcom -G "Watcom WMake" ^
  -DWOLFSSL_DEBUG_CERTS=YES ^
  -DCMAKE_SYSTEM_NAME=Windows ^
  -DCMAKE_SYSTEM_PROCESSOR=x86 ^
  -DCMAKE_VERBOSE_MAKEFILE=TRUE ^
  -DWOLFSSL_ASM=NO ^
  -DWOLFSSL_EXAMPLES=YES ^
  -DWOLFSSL_CRYPT_TESTS=NO ^
  -DWOLFSSL_SINGLE_THREADED=YES ^
  -DBUILD_SHARED_LIBS=NO ^
  -DCMAKE_POLICY_DEFAULT_CMP0136=NEW ^
  -DCMAKE_WATCOM_RUNTIME_LIBRARY=SingleThreaded
if errorlevel 1 (
    echo "Config 2a failed!"
    exit /b
)
cmake --build build-watcom || (echo "Build 2a failed!" && exit /b)

Fails with this error:

wcc386 C:\workspace\wolfssl-pr-cert\tests\api\test_pkcs12.c  -d+ -DECC_SHAMIR -DECC_TIMING_RESISTANT -DGCM_TABLE_4BIT -DHAVE_AESGCM -DHAVE_CHACHA -DHAVE_CONFIG_H -DHAVE_DH_DEFAULT_PARAMS -DHAVE_ECC -DHAVE_ENCRYPT_THEN_MAC -DHAVE_EXTENDED_MASTER -DHAVE_FFDHE_2048 -DHAVE_HASHDRBG -DHAVE_HKDF -DHAVE_ONE_TIME_AUTH -DHAVE_POLY1305 -DHAVE_SNI -DHAVE_SUPPORTED_CURVES -DHAVE_THREAD_LS -DHAVE_TLS_EXTENSIONS -DNO_CHACHA_ASM -DNO_DES3 -DNO_DES3_TLS_SUITES -DNO_DSA -DNO_MD4 -DNO_MD5 -DNO_OLD_TLS -DNO_PSK -DNO_RC4 -DSINGLE_THREADED -DTFM_ECC256 -DTFM_NO_ASM -DTFM_TIMING_RESISTANT -DWC_NO_ASYNC_THREADING -DWC_RSA_BLINDING -DWC_RSA_PSS -DWOLFSSL_HAVE_MIN -DWOLFSSL_HAVE_MAX -DNO_WRITEV -DWOLFSSL_IGNORE_FILE_WARN -DWOLFSSL_NO_ASM -DWOLFSSL_NO_SHAKE128 -DWOLFSSL_NO_SHAKE256 -DWOLFSSL_PSS_LONG_SALT -DWOLFSSL_SHA384 -DWOLFSSL_SHA512 -DWOLFSSL_SYS_CA_CERTS -DWOLFSSL_TLS13 -DWOLFSSL_USE_ALIGN -I"C:\workspace\wolfssl-pr-cert\build-watcom" -I"C:\workspace\wolfssl-pr-cert" -I"C:\watcom\h" -I"C:\watcom\h\nt" -w3 -bt=nt -dWIN32 -wx -wcd=202 -d2 -DNO_MAIN_DRIVER -foCMakeFiles\unit_test.dir\tests\api\test_pkcs12.c.obj
Open Watcom C x86 32-bit Optimizing Compiler
Version 2.0 beta Jul 11 2025 02:49:30 (32-bit)
Copyright (c) 2002-2025 The Open Watcom Contributors. All Rights Reserved.
Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See https://github.com/open-watcom/open-watcom-v2#readme for details.
C:\workspace\wolfssl-pr-cert\tests\api\test_pkcs12.c(109): Error! E1054: Expression must be constant
C:\workspace\wolfssl-pr-cert\tests\api\test_pkcs12.c: 197 lines, included 252837, 0 warnings, 1 errors
Error: Unable to invoke "C:\watcom\binnt\wcc386.exe"

Due to this initialization syntax:

    WC_DerCertList inCa = {
        (byte*)ca_cert_der_2048, sizeof_ca_cert_der_2048, NULL
    };

Fixes zd# n/a

Testing

How did you test?

Considered some sort of GitHub workflow, but it would been to be a source-code-scanning exercise, not a Watcom-compiling check.

Manually tested with Watcom.

Also basic test with:

./gencertbuf.pl
./autogen.sh
./configure --enable-all
make distclean
make
make test

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@gojimmypi gojimmypi force-pushed the pr-cert-test-sizeof branch from b91c46e to f279f9c Compare August 13, 2025 18:59
@gojimmypi gojimmypi requested a review from wolfSSL-Bot August 13, 2025 19:40
@douzzer douzzer merged commit 22b221a into wolfSSL:master Aug 13, 2025
324 of 327 checks passed
@gojimmypi gojimmypi deleted the pr-cert-test-sizeof branch August 13, 2025 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants