From f72a0a659a2dd2256adbbc01bc6bae18ece6acf5 Mon Sep 17 00:00:00 2001 From: Guido Vranken Date: Mon, 5 Sep 2022 08:01:56 +0200 Subject: [PATCH] [libressl] Add libgmp, Botan (#8403) --- projects/libressl/Dockerfile | 4 +++- projects/libressl/build.sh | 41 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/projects/libressl/Dockerfile b/projects/libressl/Dockerfile index 685a333c9..2e0ecbf88 100644 --- a/projects/libressl/Dockerfile +++ b/projects/libressl/Dockerfile @@ -17,12 +17,14 @@ # Held back because of github.com/google/oss-fuzz/pull/8313 # Please fix failure and upgrade. FROM gcr.io/oss-fuzz-base/base-builder@sha256:111d6b9d3a52bd3392602c71dc8936c628607a7a9bc86d381db7586f9b1e840f -RUN apt-get update && apt-get install -y make cmake wget +RUN apt-get update && apt-get install -y make cmake wget autoconf automake libtool bison flex texinfo lzip RUN git clone --depth 1 https://github.com/libressl-portable/portable.git libressl RUN git clone --depth 1 https://github.com/libressl-portable/fuzz.git libressl.fuzzers RUN git clone --depth 1 https://github.com/guidovranken/cryptofuzz RUN git clone --depth 1 https://github.com/guidovranken/cryptofuzz-corpora RUN wget https://boostorg.jfrog.io/artifactory/main/release/1.74.0/source/boost_1_74_0.tar.bz2 +RUN git clone --depth 1 https://github.com/randombit/botan.git +RUN wget https://gmplib.org/download/gmp/gmp-6.2.1.tar.lz WORKDIR libressl RUN ./update.sh COPY build.sh *.options $SRC/ diff --git a/projects/libressl/build.sh b/projects/libressl/build.sh index 5c639e63f..93c18637e 100755 --- a/projects/libressl/build.sh +++ b/projects/libressl/build.sh @@ -74,11 +74,52 @@ if [[ $CFLAGS = *sanitize=memory* ]] then export CXXFLAGS="$CXXFLAGS -DMSAN" fi + +# Build Botan +cd $SRC/botan +if [[ $CFLAGS != *-m32* ]] +then + ./configure.py --cc-bin=$CXX --cc-abi-flags="$CXXFLAGS" --disable-shared --disable-modules=locking_allocator,x509,tls --build-targets=static --without-documentation +else + ./configure.py --cpu=x86_32 --cc-bin=$CXX --cc-abi-flags="$CXXFLAGS" --disable-shared --disable-modules=locking_allocator,x509,tls --build-targets=static --without-documentation +fi +make -j$(nproc) + +export CXXFLAGS="$CXXFLAGS -DCRYPTOFUZZ_BOTAN -DCRYPTOFUZZ_BOTAN_IS_ORACLE" +export LIBBOTAN_A_PATH="$SRC/botan/libbotan-3.a" +export BOTAN_INCLUDE_PATH="$SRC/botan/build/include" + +# Compile libgmp +cd $SRC/ +tar --lzip -xvf gmp-6.2.1.tar.lz +cd $SRC/gmp-6.2.1/ +autoreconf -ivf +if [[ $CFLAGS = *-m32* ]] +then + setarch i386 ./configure --enable-maintainer-mode --enable-assert +elif [[ $CFLAGS = *sanitize=memory* ]] +then + ./configure --enable-maintainer-mode --enable-assert --disable-assembly +else + ./configure --enable-maintainer-mode --enable-assert +fi +make -j$(nproc) +export CXXFLAGS="$CXXFLAGS -DCRYPTOFUZZ_LIBGMP" +export LIBGMP_INCLUDE_PATH=$(realpath .) +export LIBGMP_A_PATH=$(realpath .libs/libgmp.a) + +cd $SRC/cryptofuzz/ # Generate lookup tables python3 gen_repository.py # Compile Cryptofuzz LibreSSL module cd $SRC/cryptofuzz/modules/openssl OPENSSL_INCLUDE_PATH="$SRC/libressl/include" OPENSSL_LIBCRYPTO_A_PATH="$WORK/libressl/crypto/libcrypto.a" CXXFLAGS="$CXXFLAGS -DCRYPTOFUZZ_LIBRESSL" make +# Compile Cryptofuzz libgmp module +cd ../libgmp/ +make -B -j$(nproc) +# Compile Cryptofuzz Botan module +cd ../botan/ +make -B -f Makefile-oracle -j$(nproc) # Compile Cryptofuzz cd $SRC/cryptofuzz/ LIBFUZZER_LINK="$LIB_FUZZING_ENGINE" CXXFLAGS="$CXXFLAGS -DCRYPTOFUZZ_LIBRESSL -I $SRC/libressl/include" make -j$(nproc)