• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 Relic
30cd $SRC/relic/
31mkdir build/
32cd build/
33if [[ $CFLAGS = *-m32* ]]
34then
35    export RELIC_ARCH="X86"
36else
37    export RELIC_ARCH="X64"
38fi
39cmake .. -DCOMP="$CFLAGS" -DQUIET=on -DRAND=CALL -DSHLIB=off -DSTBIN=off -DTESTS=0 -DBENCH=0 -DALLOC=DYNAMIC -DARCH=$RELIC_ARCH
40make -j$(nproc)
41cd ../..
42export RELIC_PATH=$(realpath relic)
43export CXXFLAGS="$CXXFLAGS -DCRYPTOFUZZ_RELIC"
44
45# Build Botan
46cd $SRC/botan
47if [[ $CFLAGS != *-m32* ]]
48then
49    ./configure.py --cc-bin=$CXX --cc-abi-flags="$CXXFLAGS" --disable-shared --disable-modules=locking_allocator --build-targets=static --without-documentation
50else
51    ./configure.py --cpu=x86_32 --cc-bin=$CXX --cc-abi-flags="$CXXFLAGS" --disable-shared --disable-modules=locking_allocator --build-targets=static --without-documentation
52fi
53make -j$(nproc)
54
55export CXXFLAGS="$CXXFLAGS -DCRYPTOFUZZ_BOTAN -DCRYPTOFUZZ_BOTAN_IS_ORACLE"
56export LIBBOTAN_A_PATH="$SRC/botan/libbotan-3.a"
57export BOTAN_INCLUDE_PATH="$SRC/botan/build/include"
58
59# Build Cryptofuzz
60cd $SRC/cryptofuzz
61python gen_repository.py
62rm extra_options.h
63echo -n '"' >>extra_options.h
64echo -n '--force-module=relic ' >>extra_options.h
65echo -n '--operations=BignumCalc,ECC_PrivateToPublic,ECC_ValidatePubkey,ECDSA_Sign,ECDSA_Verify,Digest,HMAC,KDF_X963,SymmetricEncrypt,SymmetricDecrypt,ECC_Point_Add,ECC_Point_Mul ' >>extra_options.h
66echo -n '--curves=secp256k1,secp256r1 ' >>extra_options.h
67echo -n '--digests=NULL,SHA224,SHA256,SHA384,SHA512,BLAKE2S160,BLAKE2S256 ' >>extra_options.h
68echo -n '--ciphers=AES_128_CBC,AES_192_CBC,AES_256_CBC ' >>extra_options.h
69echo -n '--calcops=Abs,Add,Bit,ClearBit,Cmp,CmpAbs,Div,ExpMod,GCD,InvMod,IsEven,IsOdd,IsZero,Jacobi,LCM,LShift1,Mod,Mul,Neg,NumBits,RShift,SetBit,Sqr,Sqrt,Sub ' >>extra_options.h
70echo -n '"' >>extra_options.h
71cd modules/relic/
72make -B -j$(nproc)
73cd ../botan/
74make -B -j$(nproc)
75cd ../../
76make -B -j$(nproc)
77
78cp cryptofuzz $OUT/cryptofuzz-relic
79