aboutsummaryrefslogtreecommitdiff
path: root/projects/ecc-diff-fuzzer/build.sh
blob: d05c14ae9b86bb3fccbc0dd23a3f64e22d996937 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash -eu
# Copyright 2018 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################

# build projects
#nettle
(
cd nettle
tar -xvf ../gmp-6.1.2.tar.bz2
cd gmp-6.1.2
#do not use assembly instructions as we do not know if they will be available on the machine who will run the fuzzer
#we could do instead --enable-fat
./configure --disable-shared --disable-assembly
make -j$(nproc)
make install
cd ..
autoreconf
./configure --disable-shared --disable-openssl
make -j$(nproc)
make install
)

#cryptopp
(
cd cryptopp
make -j$(nproc)
make install
)

#gcrypt
(
cd libgpg-error
./autogen.sh
if [ "$ARCHITECTURE" = 'i386' ]; then
    ./configure -host=i386 --disable-doc --enable-static --disable-shared
else
    ./configure --disable-doc --enable-static --disable-shared
fi
make -j$(nproc)
make install
cd ../gcrypt
./autogen.sh
if [ "$ARCHITECTURE" = 'i386' ]; then
    ./configure -host=i386 --enable-static --disable-shared --disable-doc --enable-maintainer-mode
else
    ./configure --enable-static --disable-shared --disable-doc --enable-maintainer-mode
fi
make -j$(nproc)
make install
)

#mbedtls
(
cd mbedtls
cmake . -DENABLE_PROGRAMS=0 -DENABLE_TESTING=0
make -j$(nproc) all
make install
)

#openssl
(
cd openssl
#option to not have the same exported function poly1305_blocks as in gcrypt
if [ "$ARCHITECTURE" = 'i386' ]; then
    setarch i386 ./config no-poly1305 no-shared no-threads -m32
else
    ./config no-poly1305 no-shared no-threads
fi
make build_generated libcrypto.a
make install
)

#libecc
(
cd libecc
#required by libecc
(export CFLAGS="$CFLAGS -fPIC"; make; cp build/*.a /usr/local/lib; cp -r src/* /usr/local/include/)
)

#botan
(
cd botan
if [ "$ARCHITECTURE" = 'i386' ]; then
    ./configure.py --cc-bin=$CXX --cc-abi-flags="$CXXFLAGS" \
               --disable-shared --disable-modules=locking_allocator --disable-shared-library \
               --without-os-features=getrandom,getentropy --cpu x86_32
else
    ./configure.py --cc-bin=$CXX --cc-abi-flags="$CXXFLAGS" \
               --disable-shared --disable-modules=locking_allocator --disable-shared-library \
               --without-os-features=getrandom,getentropy
fi
make -j$(nproc)
make install
)

#quickjs
(
cd quickjs
if [ "$ARCHITECTURE" = 'i386' ]; then
    make qjsc
    cp qjsc /usr/local/bin/
    make clean
    # Makefile should not override CFLAGS
    sed -i -e 's/CFLAGS=/CFLAGS+=/' Makefile
    CFLAGS="-m32" make libquickjs.a
else
    make && make install
fi
cp quickjs*.h /usr/local/include/
cp libquickjs.a /usr/local/lib/
)

export CARGO_BUILD_TARGET="x86_64-unknown-linux-gnu"
#build fuzz target
cd ecfuzzer
if [ "$ARCHITECTURE" = 'i386' ]; then
    export GOARCH=386
#needed explicitly because of cross compilation cf https://golang.org/cmd/cgo/
    export CGO_ENABLED=1
    export CARGO_BUILD_TARGET=i686-unknown-linux-gnu
fi
zip -r fuzz_ec_seed_corpus.zip corpus/
cp fuzz_ec_seed_corpus.zip $OUT/
cp fuzz_ec.dict $OUT/
cp fuzz_ec.dict $OUT/fuzz_ec_noblocker.dict

mkdir build
cd build
#no afl with long javascript initialization
if [ "$FUZZING_ENGINE" != 'afl' ]; then
    cmake ..
    make -j$(nproc)
    cp ecfuzzer $OUT/fuzz_ec
    rm -Rf *
fi

#another target without javascript
cmake -DDISABLE_JS=ON ..
make -j$(nproc)
cp ecfuzzer $OUT/fuzz_ec_noblocker