1#!/bin/bash -eu 2# Copyright 2020 Google Inc. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16################################################################################ 17 18export LINK_FLAGS="" 19 20# Not using OpenSSL 21 export CXXFLAGS="$CXXFLAGS -DCRYPTOFUZZ_NO_OPENSSL" 22 23# Install Boost headers 24 cd $SRC/ 25 tar jxf boost_1_74_0.tar.bz2 26 cd boost_1_74_0/ 27 CFLAGS="" CXXFLAGS="" ./bootstrap.sh 28 CFLAGS="" CXXFLAGS="" ./b2 headers 29 cp -R boost/ /usr/include/ 30 31 32# Generate lookup tables. This only needs to be done once. 33 cd $SRC/cryptofuzz 34 python gen_repository.py 35 36if [[ $CFLAGS != *sanitize=memory* ]] 37then 38 # Compile libgmp 39 cd $SRC/ 40 lzip -d gmp-6.2.0.tar.lz 41 tar xf gmp-6.2.0.tar 42 43 cd gmp-6.2.0/ 44 autoreconf -ivf 45 if [[ $CFLAGS != *-m32* ]] 46 then 47 ./configure --enable-maintainer-mode 48 else 49 setarch i386 ./configure --enable-maintainer-mode 50 fi 51 make -j$(nproc) 52 make install 53 54 # Compile Nettle (with libgmp) 55 mkdir $SRC/nettle-with-libgmp-install/ 56 cp -R $SRC/nettle $SRC/nettle-with-libgmp/ 57 cd $SRC/nettle-with-libgmp/ 58 bash .bootstrap 59 if [[ $CFLAGS != *sanitize=memory* ]] 60 then 61 ./configure --disable-documentation --disable-openssl --prefix=`realpath ../nettle-with-libgmp-install` 62 else 63 ./configure --disable-documentation --disable-openssl --disable-assembler --prefix=`realpath ../nettle-with-libgmp-install` 64 fi 65 make -j$(nproc) 66 make install 67 68 if [[ $CFLAGS != *-m32* ]] 69 then 70 export LIBNETTLE_A_PATH=`realpath ../nettle-with-libgmp-install/lib/libnettle.a` 71 export LIBHOGWEED_A_PATH=`realpath ../nettle-with-libgmp-install/lib/libhogweed.a` 72 ls -l $LIBHOGWEED_A_PATH 73 else 74 export LIBNETTLE_A_PATH=`realpath ../nettle-with-libgmp-install/lib32/libnettle.a` 75 export LIBHOGWEED_A_PATH=`realpath ../nettle-with-libgmp-install/lib32/libhogweed.a` 76 fi 77 export NETTLE_INCLUDE_PATH=`realpath ../nettle-with-libgmp-install/include` 78 export CXXFLAGS="$CXXFLAGS -DCRYPTOFUZZ_NETTLE" 79 export LINK_FLAGS="$LINK_FLAGS /usr/local/lib/libgmp.a" 80 81 # Compile Cryptofuzz Nettle module 82 cd $SRC/cryptofuzz/modules/nettle 83 make -f Makefile-hogweed -B 84 85 ############################################################################## 86 # Compile Botan 87 cd $SRC/botan 88 if [[ $CFLAGS != *-m32* ]] 89 then 90 ./configure.py --cc-bin=$CXX --cc-abi-flags="$CXXFLAGS" --disable-shared --disable-modules=locking_allocator --build-targets=static --without-documentation 91 else 92 ./configure.py --cpu=x86_32 --cc-bin=$CXX --cc-abi-flags="$CXXFLAGS" --disable-shared --disable-modules=locking_allocator --build-targets=static --without-documentation 93 fi 94 make -j$(nproc) 95 96 export CXXFLAGS="$CXXFLAGS -DCRYPTOFUZZ_BOTAN" 97 export LIBBOTAN_A_PATH="$SRC/botan/libbotan-3.a" 98 export BOTAN_INCLUDE_PATH="$SRC/botan/build/include" 99 100 # Compile Cryptofuzz Botan module 101 cd $SRC/cryptofuzz/modules/botan 102 make -B 103 104 # Compile Cryptofuzz 105 cd $SRC/cryptofuzz 106 LIBFUZZER_LINK="$LIB_FUZZING_ENGINE" make -B -j$(nproc) >/dev/null 107 108 # Generate dictionary 109 ./generate_dict 110 111 # Copy fuzzer 112 cp $SRC/cryptofuzz/cryptofuzz $OUT/cryptofuzz-nettle-with-libgmp 113 # Copy dictionary 114 cp $SRC/cryptofuzz/cryptofuzz-dict.txt $OUT/cryptofuzz-nettle-with-libgmp.dict 115 # Copy seed corpus 116 cp $SRC/cryptofuzz-corpora/libressl_latest.zip $OUT/cryptofuzz-nettle-with-libgmp_seed_corpus.zip 117fi 118 119# Compile Nettle (with mini gmp) 120 mkdir $SRC/nettle-with-mini-gmp-install/ 121 cp -R $SRC/nettle $SRC/nettle-with-mini-gmp/ 122 cd $SRC/nettle-with-mini-gmp/ 123 bash .bootstrap 124 if [[ $CFLAGS != *sanitize=memory* ]] 125 then 126 ./configure --enable-mini-gmp --disable-documentation --disable-openssl --prefix=`realpath ../nettle-with-mini-gmp-install` 127 else 128 ./configure --enable-mini-gmp --disable-documentation --disable-openssl --disable-assembler --prefix=`realpath ../nettle-with-mini-gmp-install` 129 fi 130 make -j$(nproc) 131 make install 132 133 if [[ $CFLAGS != *-m32* ]] 134 then 135 export LIBNETTLE_A_PATH=`realpath ../nettle-with-mini-gmp-install/lib/libnettle.a` 136 export LIBHOGWEED_A_PATH=`realpath ../nettle-with-mini-gmp-install/lib/libhogweed.a` 137 ls -l $LIBHOGWEED_A_PATH 138 else 139 export LIBNETTLE_A_PATH=`realpath ../nettle-with-mini-gmp-install/lib32/libnettle.a` 140 export LIBHOGWEED_A_PATH=`realpath ../nettle-with-mini-gmp-install/lib32/libhogweed.a` 141 fi 142 export NETTLE_INCLUDE_PATH=`realpath ../nettle-with-mini-gmp-install/include` 143 export LINK_FLAGS="" 144 export CXXFLAGS="$CXXFLAGS -DCRYPTOFUZZ_NETTLE" 145 146 # Compile Cryptofuzz Nettle module 147 cd $SRC/cryptofuzz/modules/nettle 148 make -f Makefile-hogweed -B 149 150# Compile Cryptofuzz 151 cd $SRC/cryptofuzz 152 LIBFUZZER_LINK="$LIB_FUZZING_ENGINE" make -B -j$(nproc) >/dev/null 153 154 # Generate dictionary 155 ./generate_dict 156 157 # Copy fuzzer 158 cp $SRC/cryptofuzz/cryptofuzz $OUT/cryptofuzz-nettle-with-mini-gmp 159 # Copy dictionary 160 cp $SRC/cryptofuzz/cryptofuzz-dict.txt $OUT/cryptofuzz-nettle-with-mini-gmp.dict 161 # Copy seed corpus 162 cp $SRC/cryptofuzz-corpora/libressl_latest.zip $OUT/cryptofuzz-nettle-with-mini-gmp_seed_corpus.zip 163