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 18# Not using OpenSSL 19 export CXXFLAGS="$CXXFLAGS -DCRYPTOFUZZ_NO_OPENSSL" 20 21# Install Boost headers 22 cd $SRC/ 23 tar jxf boost_1_74_0.tar.bz2 24 cd boost_1_74_0/ 25 CFLAGS="" CXXFLAGS="" ./bootstrap.sh 26 CFLAGS="" CXXFLAGS="" ./b2 headers 27 cp -R boost/ /usr/include/ 28 29# Generate lookup tables. This only needs to be done once. 30 cd $SRC/cryptofuzz 31 python gen_repository.py 32 33# Only test primitives which BearSSL supports 34 rm extra_options.h 35 echo -n '"' >>extra_options.h 36 echo -n '--force-module=BearSSL ' >>extra_options.h 37 echo -n '--digests=MD5,SHA1,SHA224,SHA256,SHA384,SHA512,MD5_SHA1,SHAKE128,SHAKE256 ' >>extra_options.h 38 echo -n '--ciphers=AES_128_GCM,AES_192_GCM,AES_256_GCM,AES_128_CCM,AES_192_CCM,AES_256_CCM,CHACHA20,CHACHA20_POLY1305 ' >>extra_options.h 39 echo -n '--operations=Digest,HMAC,SymmetricEncrypt,SymmetricDecrypt,KDF_HKDF,KDF_TLS1_PRF,ECC_GenerateKeyPair,ECC_PrivateToPublic,ECDSA_Verify,ECDSA_Sign' >>extra_options.h 40 echo -n '"' >>extra_options.h 41 42# Compile BearSSL 43 cd $SRC/BearSSL/ 44 sed -i '/^CC = /d' conf/Unix.mk 45 sed -i '/^CFLAGS = /d' conf/Unix.mk 46 make -j$(nproc) lib 47 48 export BEARSSL_INCLUDE_PATH=$(realpath inc/) 49 export LIBBEARSSL_A_PATH=$(realpath ./build/libbearssl.a) 50 export CXXFLAGS="$CXXFLAGS -DCRYPTOFUZZ_BEARSSL" 51 52 # Compile Cryptofuzz BearSSL module 53 cd $SRC/cryptofuzz/modules/bearssl 54 make -B 55 56# Compile Botan 57 cd $SRC/botan 58 if [[ $CFLAGS != *-m32* ]] 59 then 60 ./configure.py --cc-bin=$CXX --cc-abi-flags="$CXXFLAGS" --disable-shared --disable-modules=locking_allocator --build-targets=static --without-documentation 61 else 62 ./configure.py --cpu=x86_32 --cc-bin=$CXX --cc-abi-flags="$CXXFLAGS" --disable-shared --disable-modules=locking_allocator --build-targets=static --without-documentation 63 fi 64 make -j$(nproc) 65 66 export CXXFLAGS="$CXXFLAGS -DCRYPTOFUZZ_BOTAN" 67 export LIBBOTAN_A_PATH="$SRC/botan/libbotan-3.a" 68 export BOTAN_INCLUDE_PATH="$SRC/botan/build/include" 69 70 # Compile Cryptofuzz Botan module 71 cd $SRC/cryptofuzz/modules/botan 72 make -B 73 74# Compile Cryptofuzz 75 cd $SRC/cryptofuzz 76 LIBFUZZER_LINK="$LIB_FUZZING_ENGINE" make -B -j$(nproc) >/dev/null 77 78 # Generate dictionary 79 ./generate_dict 80 81 # Copy fuzzer 82 cp $SRC/cryptofuzz/cryptofuzz $OUT/cryptofuzz-bearssl 83 # Copy dictionary 84 cp $SRC/cryptofuzz/cryptofuzz-dict.txt $OUT/cryptofuzz-bearssl.dict 85