The above script for CentOS 7 worked like a charm, and acted as a great starter for getting everything done for Windows. Thanks!
But if you, like us, needed the CST compiled for Windows (poor soul!), I've managed to get it compiled and running with an HSM backend.
Note that NXP support has informed us that the Dockerfile included in the 3.3.1 release can be used to cross-compile for Windows and has all the dependencies, so that may be easier than the path we took below before receiving that information.
The first important note is that libfrontend.a is no longer included as a binary file in the 3.3.1 release, so you must compile that too. Another note is that you MUST use MinGW32, not MinGW64. Some code changes are necessary to get the CST to use the HSM backend (instead of "engine" backend), and to correctly detect MinGW as the environment at compile time. Finally, the instructions aren't complete in the documentation for building on Windows (at least not anymore), and a few symlink hacks have to be put in place in the MinGW environment to get everything to build.
In practice, I had to compile OpenSSL from source (instead of installing from pacman) to get everything done.
1) Install MSYS2 -- it's the simplest way to get MinGW running on Windows, as far as I can tell: https://www.msys2.org/
2) Open MinGW32 from the Start menu
3) Run the following to install all the dependencies (note that there's almost certainly some extra stuff here you don't need, but anyway):
pacman -S mingw-w64-i686-gcc make vim mingw-w64-i686-gcc-libs bison bisonc++ btyacc flex mingw-w64-i686-binutils mingw-w64-i686-libconfig mingw-w64-i686-dlfcn git binutils mingw-w64-i686-toolchain --noconfirm
4) Run the following to set up some symlink hacks to convince compilation to complete:
ln -s /usr/bin/btyacc.exe /usr/bin/byacc.exe
ln -s /usr/bin/ar /usr/bin/i686-w64-mingw32-ar
ln -s /usr/bin/ranlib.exe /usr/bin/i686-w64-mingw32-ranlib
5) Make the following code changes (again, not sure what is wholly necessary, but these are the modifications we made before running (7)):
a) Fix the defined reference for MinGW:
file "cst-3.3.1/code/back_end-hsm/src/e_hsm.c: "
line 117: swap out "if defined(WIN32)" for "if defined(__CYGWIN32__)"
b) Remove code that ends up being duplicated by other files when using a different backend:
file "cst-3.3.1/code/cst/code/back_end/src/adapt_layer_openssl.c":
line 82 - 167: delete
line 266 - 358: delete
line 399 - 503: delete
line 818 - 876: delete
c) Fix an include:
file: cst-3.3.1/code/cst/code/front_end/src/cst.c
line 64: add an include:
#include <adapt_layer.h>
6) Make sure the script in (7) and the cst-3.3.1 folder (containing the contents of the 3.3.1 release archive) are in your current directory
7) Run the following to pull down the right OpenSSL source and compile the CST:
#!/bin/bash
set -e
VERSION_CST=3.3.1
VERSION_OPENSSL=1_0_2
OSTYPE=mingw32
OSTYPE_OPENSSL=mingw
if [[ -z ${CI_PROJECT_DIR} ]]; then
export CI_PROJECT_DIR=${HOME}
cp -r cst-${VERSION_CST} ${CI_PROJECT_DIR}
fi
OPENSSL_PATH=${CI_PROJECT_DIR}/openssl
SSL_PATH=${CI_PROJECT_DIR}/ssl
CST_PATH=${CI_PROJECT_DIR}/cst-${VERSION_CST}/code
CST_HSM_PATH=${CST_PATH}/back_end-hsm/src
git clone https://github.com/openssl/openssl.git ${OPENSSL_PATH} || true
cd ${OPENSSL_PATH}
git checkout OpenSSL_${VERSION_OPENSSL}
echo "Running ./Configure ${OSTYPE_OPENSSL} --prefix=${SSL_PATH}"
./Configure ${OSTYPE_OPENSSL} --prefix=${SSL_PATH}
make
make install
cd -
sed -i 's/no-idea/no-idea --prefix=$(CI_PROJECT_DIR)/' ${CST_PATH}/cst/Makefile
sed -i '/make && \\/a\ make install && \\' ${CST_PATH}/cst/Makefile
cd ${CST_PATH}/cst/code
sed -i '/OBJECTS += \\/a\ ssl_wrapper.o \\' ${CST_PATH}/cst/code/front_end/src/objects.mk
sed -i '/OBJECTS_FRONTEND += \\/a\ ssl_wrapper.o \\' ${CST_PATH}/cst/code/front_end/src/objects.mk
sed -i '/OBJECTS += \\/a\ pkey.o \\' ${CST_PATH}/cst/code/front_end/src/objects.mk
sed -i '/OBJECTS_FRONTEND += \\/a\ pkey.o \\' ${CST_PATH}/cst/code/front_end/src/objects.mk
sed -i '/OBJECTS += \\/a\ adapt_layer_openssl.o \\' ${CST_PATH}/cst/code/front_end/src/objects.mk
sed -i '/OBJECTS_FRONTEND += \\/a\ adapt_layer_openssl.o \\' ${CST_PATH}/cst/code/front_end/src/objects.mk
sed -i -e 's/err_msg/err_msg_local/g' ${CST_PATH}/cst/code/front_end/src/acst.c
cd -
cd ${CST_PATH}/cst/code/obj.mingw32
cp ${CI_PROJECT_DIR}/openssl/ms/* ${CI_PROJECT_DIR}/openssl/include/openssl
make libfrontend.a OSTYPE=${OSTYPE} _OPENSSL_PATH=${CI_PROJECT_DIR}/openssl
cp ${CST_PATH}/cst/code/obj.${OSTYPE}/libfrontend.a ${CST_HSM_PATH}
cd -
cd ${CST_HSM_PATH}
make OPENSSL_PATH=${SSL_PATH}
make all OSTYPE=${OSTYPE} OPENSSL_PATH=${CI_PROJECT_DIR}/ssl
cd -
You should now have cst.exe in the path "cst-3.3.1/code/back_end-hsm/src/cst"
Good luck!