]> Git Repo - secp256k1.git/blame - configure
Break malleability by producing S <= order/2
[secp256k1.git] / configure
CommitLineData
f0c89aad
PW
1#!/bin/sh
2
3if test -f config.mk; then
4 exit 0
5fi
6
7if test -z "$CC"; then
8 CC=cc
9fi
10
11if test -z "$YASM"; then
12 YASM=yasm
13fi
14
15# test yasm
16$YASM -f elf64 -o /tmp/secp256k1-$$.o - <<EOF
17 BITS 64
18 GLOBAL testyasm
19 ALIGN 32
20testyasm:
21 xor r9,r9
22EOF
23if [ "$?" = 0 ]; then
24 $CC $CFLAGS -std=c99 -x c -c - -o /tmp/secp256k1-$$-2.o 2>/dev/null <<EOF
25void __attribute__ ((sysv_abi)) testyasm(void);
26int main() {
27 testyasm();
28 return 0;
29}
30EOF
31 $CC $CFLAGS -std=c99 /tmp/secp256k1-$$-2.o /tmp/secp256k1-$$.o -o /dev/null 2>/dev/null
32 if [ "$?" = 0 ]; then
33 HAVE_YASM=1
34 fi
35 rm -rf /tmp/secp256k1-$$-2.o /tmp/secp256k1-$$.o
36fi
37
38# test openssl
39HAVE_OPENSSL=0
40$CC $CFLAGS -std=c99 -x c - -o /dev/null -lcrypto 2>/dev/null <<EOF
41#include <openssl/bn.h>
42int main() {
43 BN_CTX *ctx = BN_CTX_new();
44 BN_CTX_free(ctx);
45 return 0;
46}
47EOF
48if [ "$?" = 0 ]; then
49 HAVE_OPENSSL=1
50fi
51
dd08f037
PW
52# test openssl/EC
53HAVE_OPENSSL_EC=0
54if [ "$HAVE_OPENSSL" = "1" ]; then
7b03d836 55$CC $CFLAGS -std=c99 -x c - -o /dev/null -lcrypto 2>/dev/null <<EOF
dd08f037
PW
56#include <openssl/ec.h>
57#include <openssl/ecdsa.h>
58#include <openssl/obj_mac.h>
59int main() {
60 EC_KEY *eckey = EC_KEY_new_by_curve_name(NID_secp256k1);
61 ECDSA_sign(0, NULL, 0, NULL, NULL, eckey);
62 ECDSA_verify(0, NULL, 0, NULL, 0, eckey);
63 EC_KEY_free(eckey);
64 return 0;
65}
66EOF
67if [ "$?" = 0 ]; then
68 HAVE_OPENSSL_EC=1
69fi
70fi
71
f0c89aad
PW
72# test gmp
73HAVE_GMP=0
74$CC $CFLAGS -std=c99 -x c - -o /dev/null -lgmp 2>/dev/null <<EOF
75#include <gmp.h>
76int main() {
77 mpz_t n;
78 mpz_init(n);
79 mpz_clear(n);
80 return 0;
81}
82EOF
83if [ "$?" = 0 ]; then
84 HAVE_GMP=1
85fi
86
87# test __int128
88HAVE_INT128=0
89$CC $CFLAGS -std=c99 -x c - -o /dev/null 2>/dev/null <<EOF
90#include <stdint.h>
91int main() {
92 __int128 x = 0;
93 return 0;
94}
95EOF
96if [ "$?" = 0 ]; then
97 HAVE_INT128=1
98fi
99
dd804ade
DH
100#default limb size
101HAVE_LIMB=52
102
f0c89aad
PW
103for arg in "$@"; do
104 case "$arg" in
105 --no-yasm)
106 HAVE_YASM=0
107 ;;
108 --no-gmp)
109 HAVE_GMP=0
110 ;;
111 --no-openssl)
112 HAVE_OPENSSL=0
dd804ade
DH
113 ;;
114 --use-5x64)
115 HAVE_LIMB=64
f0c89aad
PW
116 ;;
117 esac
118done
119
120LINK_OPENSSL=0
121LINK_GMP=0
122USE_ASM=0
123
124# select field implementation
125if [ "$HAVE_YASM" = "1" ]; then
dd804ade 126 CFLAGS_FIELD="-DUSE_FIELD_5X$HAVE_LIMB -DUSE_FIELD_5X${HAVE_LIMB}_ASM"
f0c89aad
PW
127 USE_ASM=1
128elif [ "$HAVE_INT128" = "1" ]; then
dd804ade 129 CFLAGS_FIELD="-DUSE_FIELD_5X$HAVE_LIMB -DUSE_FIELD_5X${HAVE_LIMB}_INT128"
f0c89aad
PW
130elif [ "$HAVE_GMP" = "1" ]; then
131 CFLAGS_FIELD="-DUSE_FIELD_GMP"
132 LINK_GMP=1
133else
134 CFLAGS_FIELD="-DUSE_FIELD_10X26"
135fi
136
137# select num implementation
138if [ "$HAVE_GMP" = "1" ]; then
139 CFLAGS_NUM="-DUSE_NUM_GMP -DUSE_FIELD_INV_NUM"
140 LINK_GMP=1
141elif [ "$HAVE_OPENSSL" = "1" ]; then
142 CFLAGS_NUM="-DUSE_NUM_OPENSSL -DUSE_FIELD_INV_BUILTIN"
143 LINK_OPENSSL=1
144else
145 echo "No usable num implementation found" >&2
146 exit 1
147fi
148
149CFLAGS_EXTRA="$CFLAGS_FIELD $CFLAGS_NUM"
150LDFLAGS_EXTRA=""
151if [ "$LINK_GMP" = "1" ]; then
152 LDFLAGS_EXTRA="-lgmp"
153fi
154if [ "$LINK_OPENSSL" = "1" ]; then
155 LDFLAGS_EXTRA="-lcrypto"
dd08f037
PW
156else
157 if [ "$HAVE_OPENSSL_EC" = "1" ]; then
158 LDFLAGS_TEST_EXTRA="-lcrypto"
159 fi
160fi
161
162CFLAGS_TEST_EXTRA=""
163if [ "$HAVE_OPENSSL_EC" = "1" ]; then
164 CFLAGS_TEST_EXTRA="-DENABLE_OPENSSL_TESTS"
f0c89aad
PW
165fi
166
167echo "CC=$CC" > config.mk
168echo "YASM=$YASM" >>config.mk
169echo "CFLAGS_EXTRA=$CFLAGS_EXTRA" >> config.mk
dd08f037 170echo "CFLAGS_TEST_EXTRA=$CFLAGS_TEST_EXTRA" >> config.mk
f0c89aad 171echo "LDFLAGS_EXTRA=$LDFLAGS_EXTRA" >> config.mk
dd08f037 172echo "LDFLAGS_TEST_EXTRA=$LDFLAGS_TEST_EXTRA" >> config.mk
f0c89aad 173echo "USE_ASM=$USE_ASM" >>config.mk
dd804ade 174echo "HAVE_LIMB=$HAVE_LIMB" >>config.mk
355b4192 175echo "OPTLEVEL=O2" >>config.mk
This page took 0.038542 seconds and 4 git commands to generate.