New AES and GHASH implementations using POWER8 crypto opcodes.
[BearSSL] / mk / mkrules.sh
1 #! /bin/sh
2
3 # ========================================================================
4 #
5 # Copyright (c) 2017 Thomas Pornin <pornin@bolet.org>
6 #
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
14 #
15 # The above copyright notice and this permission notice shall be
16 # included in all copies or substantial portions of the Software.
17 #
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 # SOFTWARE.
26 #
27 # ========================================================================
28 #
29 # This script is used to generate the 'Rules.mk' file from the list
30 # of source file included below. If the list changes (e.g. to add a
31 # new source file), then add it here and rerun this script.
32 #
33 # ========================================================================
34
35 # Solaris compatibility: switch to a more POSIX-compliant /bin/sh.
36 if [ -z "$BR_SCRIPT_LOOP" ] ; then
37 BR_SCRIPT_LOOP=yes
38 export BR_SCRIPT_LOOP
39 if [ -x /usr/xpg6/bin/sh ] ; then
40 exec /usr/xpg6/bin/sh "$0" "$@"
41 fi
42 if [ -x /usr/xpg4/bin/sh ] ; then
43 exec /usr/xpg4/bin/sh "$0" "$@"
44 fi
45 fi
46
47 # Exit on first error.
48 set -e
49
50 # Source files. Please keep in alphabetical order.
51 coresrc=" \
52 src/codec/ccopy.c \
53 src/codec/dec16be.c \
54 src/codec/dec16le.c \
55 src/codec/dec32be.c \
56 src/codec/dec32le.c \
57 src/codec/dec64be.c \
58 src/codec/dec64le.c \
59 src/codec/enc16be.c \
60 src/codec/enc16le.c \
61 src/codec/enc32be.c \
62 src/codec/enc32le.c \
63 src/codec/enc64be.c \
64 src/codec/enc64le.c \
65 src/codec/pemdec.c \
66 src/ec/ec_all_m15.c \
67 src/ec/ec_all_m31.c \
68 src/ec/ec_c25519_i15.c \
69 src/ec/ec_c25519_i31.c \
70 src/ec/ec_c25519_m15.c \
71 src/ec/ec_c25519_m31.c \
72 src/ec/ec_curve25519.c \
73 src/ec/ec_default.c \
74 src/ec/ec_p256_m15.c \
75 src/ec/ec_p256_m31.c \
76 src/ec/ec_prime_i15.c \
77 src/ec/ec_prime_i31.c \
78 src/ec/ec_secp256r1.c \
79 src/ec/ec_secp384r1.c \
80 src/ec/ec_secp521r1.c \
81 src/ec/ecdsa_atr.c \
82 src/ec/ecdsa_default_sign_asn1.c \
83 src/ec/ecdsa_default_sign_raw.c \
84 src/ec/ecdsa_default_vrfy_asn1.c \
85 src/ec/ecdsa_default_vrfy_raw.c \
86 src/ec/ecdsa_i15_bits.c \
87 src/ec/ecdsa_i15_sign_asn1.c \
88 src/ec/ecdsa_i15_sign_raw.c \
89 src/ec/ecdsa_i15_vrfy_asn1.c \
90 src/ec/ecdsa_i15_vrfy_raw.c \
91 src/ec/ecdsa_i31_bits.c \
92 src/ec/ecdsa_i31_sign_asn1.c \
93 src/ec/ecdsa_i31_sign_raw.c \
94 src/ec/ecdsa_i31_vrfy_asn1.c \
95 src/ec/ecdsa_i31_vrfy_raw.c \
96 src/ec/ecdsa_rta.c \
97 src/hash/dig_oid.c \
98 src/hash/dig_size.c \
99 src/hash/ghash_ctmul.c \
100 src/hash/ghash_ctmul32.c \
101 src/hash/ghash_ctmul64.c \
102 src/hash/ghash_pclmul.c \
103 src/hash/ghash_pwr8.c \
104 src/hash/md5.c \
105 src/hash/md5sha1.c \
106 src/hash/multihash.c \
107 src/hash/sha1.c \
108 src/hash/sha2big.c \
109 src/hash/sha2small.c \
110 src/int/i15_add.c \
111 src/int/i15_bitlen.c \
112 src/int/i15_decmod.c \
113 src/int/i15_decode.c \
114 src/int/i15_decred.c \
115 src/int/i15_encode.c \
116 src/int/i15_fmont.c \
117 src/int/i15_iszero.c \
118 src/int/i15_modpow.c \
119 src/int/i15_modpow2.c \
120 src/int/i15_montmul.c \
121 src/int/i15_mulacc.c \
122 src/int/i15_muladd.c \
123 src/int/i15_ninv15.c \
124 src/int/i15_reduce.c \
125 src/int/i15_rshift.c \
126 src/int/i15_sub.c \
127 src/int/i15_tmont.c \
128 src/int/i31_add.c \
129 src/int/i31_bitlen.c \
130 src/int/i31_decmod.c \
131 src/int/i31_decode.c \
132 src/int/i31_decred.c \
133 src/int/i31_encode.c \
134 src/int/i31_fmont.c \
135 src/int/i31_iszero.c \
136 src/int/i31_modpow.c \
137 src/int/i31_montmul.c \
138 src/int/i31_mulacc.c \
139 src/int/i31_muladd.c \
140 src/int/i31_ninv31.c \
141 src/int/i31_reduce.c \
142 src/int/i31_rshift.c \
143 src/int/i31_sub.c \
144 src/int/i31_tmont.c \
145 src/int/i32_add.c \
146 src/int/i32_bitlen.c \
147 src/int/i32_decmod.c \
148 src/int/i32_decode.c \
149 src/int/i32_decred.c \
150 src/int/i32_div32.c \
151 src/int/i32_encode.c \
152 src/int/i32_fmont.c \
153 src/int/i32_iszero.c \
154 src/int/i32_modpow.c \
155 src/int/i32_montmul.c \
156 src/int/i32_mulacc.c \
157 src/int/i32_muladd.c \
158 src/int/i32_ninv32.c \
159 src/int/i32_reduce.c \
160 src/int/i32_sub.c \
161 src/int/i32_tmont.c \
162 src/mac/hmac.c \
163 src/mac/hmac_ct.c \
164 src/rand/hmac_drbg.c \
165 src/rsa/rsa_default_pkcs1_sign.c \
166 src/rsa/rsa_default_pkcs1_vrfy.c \
167 src/rsa/rsa_default_priv.c \
168 src/rsa/rsa_default_pub.c \
169 src/rsa/rsa_i15_pkcs1_sign.c \
170 src/rsa/rsa_i15_pkcs1_vrfy.c \
171 src/rsa/rsa_i15_priv.c \
172 src/rsa/rsa_i15_pub.c \
173 src/rsa/rsa_i31_pkcs1_sign.c \
174 src/rsa/rsa_i31_pkcs1_vrfy.c \
175 src/rsa/rsa_i31_priv.c \
176 src/rsa/rsa_i31_pub.c \
177 src/rsa/rsa_i32_pkcs1_sign.c \
178 src/rsa/rsa_i32_pkcs1_vrfy.c \
179 src/rsa/rsa_i32_priv.c \
180 src/rsa/rsa_i32_pub.c \
181 src/rsa/rsa_pkcs1_sig_pad.c \
182 src/rsa/rsa_pkcs1_sig_unpad.c \
183 src/rsa/rsa_ssl_decrypt.c \
184 src/ssl/prf.c \
185 src/ssl/prf_md5sha1.c \
186 src/ssl/prf_sha256.c \
187 src/ssl/prf_sha384.c \
188 src/ssl/ssl_ccert_single_ec.c \
189 src/ssl/ssl_ccert_single_rsa.c \
190 src/ssl/ssl_client.c \
191 src/ssl/ssl_client_default_rsapub.c \
192 src/ssl/ssl_client_full.c \
193 src/ssl/ssl_engine.c \
194 src/ssl/ssl_engine_default_aescbc.c \
195 src/ssl/ssl_engine_default_aesgcm.c \
196 src/ssl/ssl_engine_default_chapol.c \
197 src/ssl/ssl_engine_default_descbc.c \
198 src/ssl/ssl_engine_default_ec.c \
199 src/ssl/ssl_engine_default_ecdsa.c \
200 src/ssl/ssl_engine_default_rsavrfy.c \
201 src/ssl/ssl_hashes.c \
202 src/ssl/ssl_hs_client.c \
203 src/ssl/ssl_hs_server.c \
204 src/ssl/ssl_io.c \
205 src/ssl/ssl_lru.c \
206 src/ssl/ssl_rec_cbc.c \
207 src/ssl/ssl_rec_chapol.c \
208 src/ssl/ssl_rec_gcm.c \
209 src/ssl/ssl_scert_single_ec.c \
210 src/ssl/ssl_scert_single_rsa.c \
211 src/ssl/ssl_server.c \
212 src/ssl/ssl_server_full_ec.c \
213 src/ssl/ssl_server_full_rsa.c \
214 src/ssl/ssl_server_mine2c.c \
215 src/ssl/ssl_server_mine2g.c \
216 src/ssl/ssl_server_minf2c.c \
217 src/ssl/ssl_server_minf2g.c \
218 src/ssl/ssl_server_minr2g.c \
219 src/ssl/ssl_server_minu2g.c \
220 src/ssl/ssl_server_minv2g.c \
221 src/symcipher/aes_big_cbcdec.c \
222 src/symcipher/aes_big_cbcenc.c \
223 src/symcipher/aes_big_ctr.c \
224 src/symcipher/aes_big_dec.c \
225 src/symcipher/aes_big_enc.c \
226 src/symcipher/aes_common.c \
227 src/symcipher/aes_ct.c \
228 src/symcipher/aes_ct64.c \
229 src/symcipher/aes_ct64_cbcdec.c \
230 src/symcipher/aes_ct64_cbcenc.c \
231 src/symcipher/aes_ct64_ctr.c \
232 src/symcipher/aes_ct64_dec.c \
233 src/symcipher/aes_ct64_enc.c \
234 src/symcipher/aes_ct_cbcdec.c \
235 src/symcipher/aes_ct_cbcenc.c \
236 src/symcipher/aes_ct_ctr.c \
237 src/symcipher/aes_ct_dec.c \
238 src/symcipher/aes_ct_enc.c \
239 src/symcipher/aes_pwr8.c \
240 src/symcipher/aes_pwr8_cbcdec.c \
241 src/symcipher/aes_pwr8_cbcenc.c \
242 src/symcipher/aes_pwr8_ctr.c \
243 src/symcipher/aes_small_cbcdec.c \
244 src/symcipher/aes_small_cbcenc.c \
245 src/symcipher/aes_small_ctr.c \
246 src/symcipher/aes_small_dec.c \
247 src/symcipher/aes_small_enc.c \
248 src/symcipher/aes_x86ni.c \
249 src/symcipher/aes_x86ni_cbcdec.c \
250 src/symcipher/aes_x86ni_cbcenc.c \
251 src/symcipher/aes_x86ni_ctr.c \
252 src/symcipher/chacha20_ct.c \
253 src/symcipher/des_ct.c \
254 src/symcipher/des_ct_cbcdec.c \
255 src/symcipher/des_ct_cbcenc.c \
256 src/symcipher/des_support.c \
257 src/symcipher/des_tab.c \
258 src/symcipher/des_tab_cbcdec.c \
259 src/symcipher/des_tab_cbcenc.c \
260 src/symcipher/poly1305_ctmul.c \
261 src/symcipher/poly1305_ctmul32.c \
262 src/symcipher/poly1305_i15.c \
263 src/x509/skey_decoder.c \
264 src/x509/x509_decoder.c \
265 src/x509/x509_knownkey.c \
266 src/x509/x509_minimal.c \
267 src/x509/x509_minimal_full.c"
268
269 # Source files for the 'brssl' command-line tool.
270 toolssrc=" \
271 tools/brssl.c \
272 tools/certs.c \
273 tools/chain.c \
274 tools/client.c \
275 tools/errors.c \
276 tools/files.c \
277 tools/keys.c \
278 tools/names.c \
279 tools/server.c \
280 tools/skey.c \
281 tools/sslio.c \
282 tools/ta.c \
283 tools/vector.c \
284 tools/verify.c \
285 tools/xmem.c"
286
287 # Source files the the 'testcrypto' command-line tool.
288 testcryptosrc=" \
289 test/test_crypto.c"
290
291 # Source files the the 'testspeed' command-line tool.
292 testspeedsrc=" \
293 test/test_speed.c"
294
295 # Source files the the 'testx509' command-line tool.
296 testx509src=" \
297 test/test_x509.c"
298
299 # Public header files.
300 headerspub=" \
301 inc/bearssl.h \
302 inc/bearssl_block.h \
303 inc/bearssl_ec.h \
304 inc/bearssl_hash.h \
305 inc/bearssl_hmac.h \
306 inc/bearssl_pem.h \
307 inc/bearssl_prf.h \
308 inc/bearssl_rand.h \
309 inc/bearssl_rsa.h \
310 inc/bearssl_ssl.h \
311 inc/bearssl_x509.h"
312
313 # Private header files.
314 headerspriv=" \
315 src/config.h \
316 src/inner.h"
317
318 # Header files for the 'brssl' command-line tool.
319 headerstools=" \
320 tools/brssl.h"
321
322 # T0 compiler source code.
323 t0compsrc=" \
324 T0/BlobWriter.cs \
325 T0/CPU.cs \
326 T0/CodeElement.cs \
327 T0/CodeElementJump.cs \
328 T0/CodeElementUInt.cs \
329 T0/CodeElementUIntExpr.cs \
330 T0/CodeElementUIntInt.cs \
331 T0/CodeElementUIntUInt.cs \
332 T0/ConstData.cs \
333 T0/Opcode.cs \
334 T0/OpcodeCall.cs \
335 T0/OpcodeConst.cs \
336 T0/OpcodeGetLocal.cs \
337 T0/OpcodeJump.cs \
338 T0/OpcodeJumpIf.cs \
339 T0/OpcodeJumpIfNot.cs \
340 T0/OpcodeJumpUncond.cs \
341 T0/OpcodePutLocal.cs \
342 T0/OpcodeRet.cs \
343 T0/SType.cs \
344 T0/T0Comp.cs \
345 T0/TPointerBase.cs \
346 T0/TPointerBlob.cs \
347 T0/TPointerExpr.cs \
348 T0/TPointerNull.cs \
349 T0/TPointerXT.cs \
350 T0/TValue.cs \
351 T0/Word.cs \
352 T0/WordBuilder.cs \
353 T0/WordData.cs \
354 T0/WordInterpreted.cs \
355 T0/WordNative.cs"
356
357 t0compkern=" \
358 T0/kern.t0"
359
360 # Function to turn slashes into $P (macro for path separator).
361 escsep() {
362 printf '%s' "$1" | sed 's/\//$P/g'
363 }
364
365 # Create rules file.
366 rm -f Rules.mk
367 cat > Rules.mk <<EOF
368 # Automatically generated rules. Use 'mkrules.sh' to modify/regenerate.
369 EOF
370
371 (printf "\nOBJ ="
372 for f in $coresrc ; do
373 printf ' $(OBJDIR)$P%s' "$(basename "$f" .c)\$O"
374 done
375 printf "\nOBJBRSSL ="
376 for f in $toolssrc ; do
377 printf ' $(OBJDIR)$P%s' "$(basename "$f" .c)\$O"
378 done
379 printf "\nOBJTESTCRYPTO ="
380 for f in $testcryptosrc ; do
381 printf ' $(OBJDIR)$P%s' "$(basename "$f" .c)\$O"
382 done
383 printf "\nOBJTESTSPEED ="
384 for f in $testspeedsrc ; do
385 printf ' $(OBJDIR)$P%s' "$(basename "$f" .c)\$O"
386 done
387 printf "\nOBJTESTX509 ="
388 for f in $testx509src ; do
389 printf ' $(OBJDIR)$P%s' "$(basename "$f" .c)\$O"
390 done
391 printf "\nHEADERSPUB ="
392 for f in $headerspub ; do
393 printf " %s" "$(escsep "$f")"
394 done
395 printf "\nHEADERSPRIV = %s" '$(HEADERSPUB)'
396 for f in $headerspriv ; do
397 printf " %s" "$(escsep "$f")"
398 done
399 printf "\nHEADERSTOOLS = %s" '$(HEADERSPUB)'
400 for f in $headerstools ; do
401 printf " %s" "$(escsep "$f")"
402 done
403 printf "\nT0SRC ="
404 for f in $t0compsrc ; do
405 printf " %s" "$(escsep "$f")"
406 done
407 printf "\nT0KERN ="
408 for f in $t0kernsrc ; do
409 printf " %s" "$(escsep "$f")"
410 done
411 printf "\n") >> Rules.mk
412
413 cat >> Rules.mk <<EOF
414
415 all: \$(STATICLIB) \$(DLL) \$(TOOLS) \$(TESTS)
416
417 no:
418
419 lib: \$(BEARSSLLIB)
420
421 dll: \$(BEARSSLDLL)
422
423 tools: \$(BRSSL)
424
425 tests: \$(TESTCRYPTO) \$(TESTSPEED) \$(TESTX509)
426
427 T0: \$(T0COMP)
428 \$(RUNT0COMP) -o src\$Pcodec\$Ppemdec -r br_pem_decoder src\$Pcodec\$Ppemdec.t0
429 \$(RUNT0COMP) -o src\$Pssl\$Pssl_hs_client -r br_ssl_hs_client src\$Pssl\$Pssl_hs_common.t0 src\$Pssl\$Pssl_hs_client.t0
430 \$(RUNT0COMP) -o src\$Pssl\$Pssl_hs_server -r br_ssl_hs_server src\$Pssl\$Pssl_hs_common.t0 src\$Pssl\$Pssl_hs_server.t0
431 \$(RUNT0COMP) -o src\$Px509\$Pskey_decoder -r br_skey_decoder src\$Px509\$Pasn1.t0 src\$Px509\$Pskey_decoder.t0
432 \$(RUNT0COMP) -o src\$Px509\$Px509_decoder -r br_x509_decoder src\$Px509\$Pasn1.t0 src\$Px509\$Px509_decoder.t0
433 \$(RUNT0COMP) -o src\$Px509\$Px509_minimal -r br_x509_minimal src\$Px509\$Pasn1.t0 src\$Px509\$Px509_minimal.t0
434
435 \$(T0COMP): \$(T0SRC) \$(T0KERN)
436 \$(MKT0COMP)
437
438 clean:
439 -\$(RM) \$(OBJDIR)\$P*\$O
440 -\$(RM) \$(BEARSSLLIB) \$(BEARSSLDLL) \$(BRSSL) \$(TESTCRYPTO) \$(TESTSPEED) \$(TESTX509)
441
442 \$(OBJDIR):
443 -\$(MKDIR) \$(OBJDIR)
444
445 \$(BEARSSLLIB): \$(OBJDIR) \$(OBJ)
446 \$(AR) \$(ARFLAGS) \$(AROUT)\$(BEARSSLLIB) \$(OBJ)
447
448 \$(BEARSSLDLL): \$(OBJDIR) \$(OBJ)
449 \$(LDDLL) \$(LDDLLFLAGS) \$(LDDLLOUT)\$(BEARSSLDLL) \$(OBJ)
450
451 \$(BRSSL): \$(BEARSSLLIB) \$(OBJBRSSL)
452 \$(LD) \$(LDFLAGS) \$(LDOUT)\$(BRSSL) \$(OBJBRSSL) \$(BEARSSLLIB)
453
454 \$(TESTCRYPTO): \$(BEARSSLLIB) \$(OBJTESTCRYPTO)
455 \$(LD) \$(LDFLAGS) \$(LDOUT)\$(TESTCRYPTO) \$(OBJTESTCRYPTO) \$(BEARSSLLIB)
456
457 \$(TESTSPEED): \$(BEARSSLLIB) \$(OBJTESTSPEED)
458 \$(LD) \$(LDFLAGS) \$(LDOUT)\$(TESTSPEED) \$(OBJTESTSPEED) \$(BEARSSLLIB)
459
460 \$(TESTX509): \$(BEARSSLLIB) \$(OBJTESTX509)
461 \$(LD) \$(LDFLAGS) \$(LDOUT)\$(TESTX509) \$(OBJTESTX509) \$(BEARSSLLIB)
462 EOF
463
464 (for f in $coresrc ; do
465 b="$(basename "$f" .c)\$O"
466 g="$(escsep "$f")"
467 printf '\n$(OBJDIR)$P%s: %s $(HEADERSPRIV)\n\t$(CC) $(CFLAGS) $(INCFLAGS) $(CCOUT)$(OBJDIR)$P%s %s\n' "$b" "$g" "$b" "$g"
468 done
469
470 for f in $toolssrc ; do
471 b="$(basename "$f" .c)\$O"
472 g="$(escsep "$f")"
473 printf '\n$(OBJDIR)$P%s: %s $(HEADERSTOOLS)\n\t$(CC) $(CFLAGS) $(INCFLAGS) $(CCOUT)$(OBJDIR)$P%s %s\n' "$b" "$g" "$b" "$g"
474 done
475
476 for f in $testcryptosrc $testspeedsrc ; do
477 b="$(basename "$f" .c)\$O"
478 g="$(escsep "$f")"
479 printf '\n$(OBJDIR)$P%s: %s $(HEADERSPRIV)\n\t$(CC) $(CFLAGS) $(INCFLAGS) $(CCOUT)$(OBJDIR)$P%s %s\n' "$b" "$g" "$b" "$g"
480 done
481
482 for f in $testx509src ; do
483 b="$(basename "$f" .c)\$O"
484 g="$(escsep "$f")"
485 printf '\n$(OBJDIR)$P%s: %s $(HEADERSPRIV)\n\t$(CC) $(CFLAGS) $(INCFLAGS) -DSRCDIRNAME=".." $(CCOUT)$(OBJDIR)$P%s %s\n' "$b" "$g" "$b" "$g"
486 done) >> Rules.mk