1#!/bin/bash -eu 2# Copyright 2021 Google LLC 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 CXXFLAGS="$CXXFLAGS -DCRYPTOFUZZ_NO_OPENSSL" 19export LIBFUZZER_LINK="$LIB_FUZZING_ENGINE" 20 21# Install Boost headers 22cd $SRC/ 23tar jxf boost_1_74_0.tar.bz2 24cd boost_1_74_0/ 25CFLAGS="" CXXFLAGS="" ./bootstrap.sh 26CFLAGS="" CXXFLAGS="" ./b2 headers 27cp -R boost/ /usr/include/ 28 29# Build libecc 30cd $SRC/libecc 31git checkout cryptofuzz 32export CFLAGS="$CFLAGS -DUSE_CRYPTOFUZZ" 33make -j$(nproc) build/libsign.a 34export LIBECC_PATH=$(realpath .) 35export CXXFLAGS="$CXXFLAGS -DCRYPTOFUZZ_LIBECC" 36 37# Build Botan 38cd $SRC/botan 39if [[ $CFLAGS != *-m32* ]] 40then 41 ./configure.py --cc-bin=$CXX --cc-abi-flags="$CXXFLAGS" --disable-shared --disable-modules=locking_allocator,x509,tls --build-targets=static --without-documentation 42else 43 ./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 44fi 45make -j$(nproc) 46 47export CXXFLAGS="$CXXFLAGS -DCRYPTOFUZZ_BOTAN -DCRYPTOFUZZ_BOTAN_IS_ORACLE" 48export LIBBOTAN_A_PATH="$SRC/botan/libbotan-3.a" 49export BOTAN_INCLUDE_PATH="$SRC/botan/build/include" 50 51# Build Cryptofuzz 52cd $SRC/cryptofuzz 53python gen_repository.py 54rm extra_options.h 55echo -n '"' >>extra_options.h 56echo -n '--force-module=libecc ' >>extra_options.h 57echo -n '--operations=Digest,ECC_PrivateToPublic,ECDSA_Sign,ECDSA_Verify,ECGDSA_Sign,ECGDSA_Verify,ECRDSA_Sign,ECRDSA_Verify,ECC_Point_Add,ECC_Point_Mul,BignumCalc ' >>extra_options.h 58echo -n '--curves=brainpool224r1,brainpool256r1,brainpool384r1,brainpool512r1,secp192r1,secp224r1,secp256r1,secp384r1,secp521r1,secp256k1 ' >>extra_options.h 59echo -n '--digests=NULL,SHA224,SHA256,SHA3-224,SHA3-256,SHA3-384,SHA3-512,SHA384,SHA512,SHA512-224,SHA512-256,SM3,SHAKE256_114,STREEBOG-256,STREEBOG-512 ' >>extra_options.h 60echo -n '--calcops=Add,AddMod,And,Bit,GCD,InvMod,IsOdd,IsOne,IsZero,LShift1,Mod,Mul,MulMod,NumBits,Or,RShift,Sqr,Sub,SubMod,Xor ' >>extra_options.h 61echo -n '"' >>extra_options.h 62cd modules/libecc/ 63make -B -j$(nproc) 64cd ../botan/ 65make -B -j$(nproc) 66cd ../../ 67make -B -j$(nproc) 68 69cp cryptofuzz $OUT/cryptofuzz-libecc 70