forked from hacl-star/hacl-star
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage-mozilla.sh
More file actions
executable file
·110 lines (96 loc) · 3.1 KB
/
package-mozilla.sh
File metadata and controls
executable file
·110 lines (96 loc) · 3.1 KB
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
#!/usr/bin/env bash
set -o pipefail
set -e
if [[ "${BASH_VERSINFO[0]}" -lt 4 ]]; then
echo "A bash version >= 4 required. Got: $BASH_VERSION" >&2
exit 1
fi
if [[ $(uname) == "Darwin" ]]; then
# You're already running with homebrew or macports to satisfy the
# bash>=4 requirement, so requiring GNU sed is entirely reasonable.
sed=gsed
else
sed=sed
fi
# If FOO appears in FILES, then FOO.h, FOO.c, internal/FOO.h, FOO.asm, FOO.S and
# FOO all get copied unconditionally to dist/mozilla (as long as they exist)
FILES=" \
Hacl_Bignum \
Hacl_Bignum25519_51 \
Hacl_Bignum_Base \
Hacl_Chacha20 \
Hacl_AEAD Chacha20Poly1305_Simd128 \
Hacl_AEAD_Chacha20Poly1305_Simd256 \
Hacl_AEAD_Chacha20Poly1305 \
Hacl_Chacha20_Vec128 \
Hacl_Chacha20_Vec256 \
Hacl_Curve25519_51 \
Hacl_Curve25519_64 \
Hacl_Hash_SHA1 \
Hacl_Hash_SHA2 \
Hacl_Hash_SHA3 \
Hacl_IntTypes_Intrinsics \
Hacl_IntTypes_Intrinsics_128 \
Hacl_Krmllib \
Hacl_Lib \
Hacl_MAC_Poly1305_Simd128 \
Hacl_MAC_Poly1305_Simd256 \
Hacl_MAC_Poly1305 \
Hacl_P256 \
Hacl_P256_PrecompTable \
Hacl_RSAPSS \
Hacl_SHA2_Types \
Hacl_Spec \
Hacl_Streaming_Types \
Lib_Memzero0 \
TestLib \
Vale \
curve25519-inline \
curve25519-x86_64-darwin \
curve25519-x86_64-linux \
curve25519-x86_64-mingw \
curve25519-x86_64-msvc \
libintvector \
lib_memzero0 \
lib_intrinsics \
configure \
Makefile \
Makefile.basic"
mkdir -p mozilla/internal
for f in $FILES; do
for ext in h c asm S; do
[ -f msvc-compatible/$f.$ext ] && cp msvc-compatible/$f.$ext mozilla/ || true
done
[ -f msvc-compatible/internal/$f.h ] && cp msvc-compatible/internal/$f.h mozilla/internal || true
# Makefile, etc.
[ -f msvc-compatible/$f ] && cp msvc-compatible/$f mozilla || true
done
# The P256 file contains variants of ECDSA that sign the message.
# We strip these functions.
# This regexp matches a separator (two new lines), followed by:
#
# <non-empty-line>*
# ... _p256_sha ... {
# <indented-line>*
# }
#
# The first non-empty lines are the comment block. The second ... may spill over
# the next following lines if the arguments are printed in one-per-line mode.
$sed -i -z 's/\n\n\/\*\*[^*]*\*\/\n\([^\n]\+\n\)*[^\n]*_p256_sha[^{]*{\n\?\( [^\n]*\n\)*}//g' mozilla/Hacl_P256.c
# Same thing with function prototypes
$sed -i -z 's/\n\n\/\*\*[^*]*\*\/\n\([^\n]\+\n\)*[^\n]*_p256_sha[^;]*;//g' mozilla/Hacl_P256.h
# Remove the SHA2 header from P256
$sed -i -z 's/\n#include "Hacl_Hash_SHA2.h"\n/\n/g' mozilla/Hacl_P256.h
# Remove the "should-hash" recommendation
$sed -i -z 's/\n\n\/\*\n As per[^/]*\*\///g' mozilla/Hacl_P256.h
# Remove the "should-hash" recommendation
$sed -i -z 's/\n\n\/\*\n As per[^/]*\*\///g' mozilla/Hacl_P256.c
# Add an include for "builtin.h" to Hacl_Bignum_Base.h
sed -i -z 's!\(#include.*types.h"\)!\1\n#include "krml/internal/builtin.h"!g' mozilla/internal/Hacl_Bignum_Base.h
cat <<EOF > mozilla/Makefile.include
USER_TARGET=libevercrypt.a
USER_CFLAGS=-Wno-unused
USER_C_FILES=Lib_Memzero0.c
ALL_C_FILES=$(ls mozilla/*.c | xargs basename -a | xargs echo)
ALL_H_FILES=$(ls mozilla/*.h | xargs basename -a | xargs echo)
EOF