• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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        export NETTLE_LIBDIR=`realpath ../nettle-with-libgmp-install`/lib
60        if [[ $CFLAGS != *sanitize=memory* ]]
61        then
62            ./configure --disable-documentation --disable-openssl --prefix=`realpath ../nettle-with-libgmp-install` --libdir="$NETTLE_LIBDIR"
63        else
64            ./configure --disable-documentation --disable-openssl --disable-assembler --prefix=`realpath ../nettle-with-libgmp-install` --libdir="$NETTLE_LIBDIR"
65        fi
66        make -j$(nproc)
67        make install
68
69        export LIBNETTLE_A_PATH=$NETTLE_LIBDIR/libnettle.a
70        export LIBHOGWEED_A_PATH=$NETTLE_LIBDIR/libhogweed.a
71        export NETTLE_INCLUDE_PATH=`realpath ../nettle-with-libgmp-install/include`
72        export CXXFLAGS="$CXXFLAGS -DCRYPTOFUZZ_NETTLE"
73        export LINK_FLAGS="$LINK_FLAGS /usr/local/lib/libgmp.a"
74
75        # Compile Cryptofuzz Nettle module
76        cd $SRC/cryptofuzz/modules/nettle
77        make -f Makefile-hogweed -B
78
79    ##############################################################################
80    # Compile Botan
81        cd $SRC/botan
82        if [[ $CFLAGS != *-m32* ]]
83        then
84            ./configure.py --cc-bin=$CXX --cc-abi-flags="$CXXFLAGS" --disable-shared --disable-modules=locking_allocator --build-targets=static --without-documentation
85        else
86            ./configure.py --cpu=x86_32 --cc-bin=$CXX --cc-abi-flags="$CXXFLAGS" --disable-shared --disable-modules=locking_allocator --build-targets=static --without-documentation
87        fi
88        make -j$(nproc)
89
90        export CXXFLAGS="$CXXFLAGS -DCRYPTOFUZZ_BOTAN"
91        export LIBBOTAN_A_PATH="$SRC/botan/libbotan-3.a"
92        export BOTAN_INCLUDE_PATH="$SRC/botan/build/include"
93
94        # Compile Cryptofuzz Botan module
95        cd $SRC/cryptofuzz/modules/botan
96        make -B
97
98    # Compile Cryptofuzz
99        cd $SRC/cryptofuzz
100        LIBFUZZER_LINK="$LIB_FUZZING_ENGINE" make -B -j$(nproc) >/dev/null
101
102        # Generate dictionary
103        ./generate_dict
104
105        # Copy fuzzer
106        cp $SRC/cryptofuzz/cryptofuzz $OUT/cryptofuzz-nettle-with-libgmp
107        # Copy dictionary
108        cp $SRC/cryptofuzz/cryptofuzz-dict.txt $OUT/cryptofuzz-nettle-with-libgmp.dict
109        # Copy seed corpus
110        cp $SRC/cryptofuzz-corpora/libressl_latest.zip $OUT/cryptofuzz-nettle-with-libgmp_seed_corpus.zip
111fi
112
113# Compile Nettle (with mini gmp)
114    mkdir $SRC/nettle-with-mini-gmp-install/
115    cp -R $SRC/nettle $SRC/nettle-with-mini-gmp/
116    cd $SRC/nettle-with-mini-gmp/
117    bash .bootstrap
118    export NETTLE_LIBDIR=`realpath ../nettle-with-mini-gmp-install`/lib
119    if [[ $CFLAGS != *sanitize=memory* ]]
120    then
121        ./configure --enable-mini-gmp --disable-documentation --disable-openssl --prefix=`realpath ../nettle-with-mini-gmp-install` --libdir="$NETTLE_LIBDIR"
122    else
123        ./configure --enable-mini-gmp --disable-documentation --disable-openssl --disable-assembler --prefix=`realpath ../nettle-with-mini-gmp-install` --libdir="$NETTLE_LIBDIR"
124    fi
125    make -j$(nproc)
126    make install
127
128    export LIBNETTLE_A_PATH=$NETTLE_LIBDIR/libnettle.a
129    export LIBHOGWEED_A_PATH=$NETTLE_LIBDIR/libhogweed.a
130    export NETTLE_INCLUDE_PATH=`realpath ../nettle-with-mini-gmp-install/include`
131    export LINK_FLAGS=""
132    export CXXFLAGS="$CXXFLAGS -DCRYPTOFUZZ_NETTLE"
133
134    # Compile Cryptofuzz Nettle module
135    cd $SRC/cryptofuzz/modules/nettle
136    make -f Makefile-hogweed -B
137
138# Compile Cryptofuzz
139    cd $SRC/cryptofuzz
140    LIBFUZZER_LINK="$LIB_FUZZING_ENGINE" make -B -j$(nproc) >/dev/null
141
142    # Generate dictionary
143    ./generate_dict
144
145    # Copy fuzzer
146    cp $SRC/cryptofuzz/cryptofuzz $OUT/cryptofuzz-nettle-with-mini-gmp
147    # Copy dictionary
148    cp $SRC/cryptofuzz/cryptofuzz-dict.txt $OUT/cryptofuzz-nettle-with-mini-gmp.dict
149    # Copy seed corpus
150    cp $SRC/cryptofuzz-corpora/libressl_latest.zip $OUT/cryptofuzz-nettle-with-mini-gmp_seed_corpus.zip
151