forked from wolfSSL/wolfssl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fips-check.sh
executable file
·408 lines (387 loc) · 13.1 KB
/
fips-check.sh
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
#!/usr/bin/env bash
# fips-check.sh
# This script checks the current revision of the code against the
# previous release of the FIPS code. While wolfSSL and wolfCrypt
# may be advancing, they must work correctly with the last tested
# copy of our FIPS approved code.
#
# This should check out all the approved flavors. The command line
# option selects the flavor. The keep option keeps the output
# directory.
# These variables may be overridden on the command line.
MAKE="${MAKE:-make}"
GIT="${GIT:-git -c advice.detachedHead=false}"
TEST_DIR="${TEST_DIR:-XXX-fips-test}"
FLAVOR="${FLAVOR:-linux}"
KEEP="${KEEP:-no}"
MAKECHECK=${MAKECHECK:-yes}
FIPS_REPO="${FIPS_REPO:[email protected]:wolfssl/fips.git}"
Usage() {
cat <<usageText
Usage: $0 [flavor] [keep]
Flavor is one of:
linuxv2 (FIPSv2, use for Win10)
fipsv2-OE-ready (ready FIPSv2)
solaris
netbsd-selftest
marvell-linux-selftest
linuxv5 (current FIPS 140-3)
fips-ready (ready FIPS 140-3)
fips-dev (dev FIPS 140-3)
wolfrand
wolfentropy
Keep (default off) retains the temp dir $TEST_DIR for inspection.
Example:
$0 windows keep
usageText
}
while [ "$1" ]; do
if [ "$1" = 'keep' ]; then KEEP='yes';
elif [ "$1" = 'nomakecheck' ]; then MAKECHECK='no';
else FLAVOR="$1"; fi
shift
done
case "$FLAVOR" in
linuxv2|fipsv2-OE-ready|solaris)
FIPS_OPTION='v2'
FIPS_FILES=(
'wolfcrypt/src/fips.c:WCv4-stable'
'wolfcrypt/src/fips_test.c:WCv4-stable'
'wolfcrypt/src/wolfcrypt_first.c:WCv4-stable'
'wolfcrypt/src/wolfcrypt_last.c:WCv4-stable'
'wolfssl/wolfcrypt/fips.h:WCv4-stable'
)
WOLFCRYPT_FILES=(
'wolfcrypt/src/aes.c:WCv4-stable'
'wolfcrypt/src/aes_asm.asm:WCv4-stable'
'wolfcrypt/src/aes_asm.S:WCv4-stable'
'wolfcrypt/src/cmac.c:WCv4-stable'
'wolfcrypt/src/des3.c:WCv4-stable'
'wolfcrypt/src/dh.c:WCv4-stable'
'wolfcrypt/src/ecc.c:WCv4-stable'
'wolfcrypt/src/hmac.c:WCv4-stable'
'wolfcrypt/src/random.c:WCv4-rng-stable'
'wolfcrypt/src/rsa.c:WCv4-stable'
'wolfcrypt/src/sha.c:WCv4-stable'
'wolfcrypt/src/sha256.c:WCv4-stable'
'wolfcrypt/src/sha3.c:WCv4-stable'
'wolfcrypt/src/sha512.c:WCv4-stable'
'wolfssl/wolfcrypt/aes.h:WCv4-stable'
'wolfssl/wolfcrypt/cmac.h:WCv4-stable'
'wolfssl/wolfcrypt/des3.h:WCv4-stable'
'wolfssl/wolfcrypt/dh.h:WCv4-stable'
'wolfssl/wolfcrypt/ecc.h:WCv4-stable'
'wolfssl/wolfcrypt/hmac.h:WCv4-stable'
'wolfssl/wolfcrypt/random.h:WCv4-rng-stable'
'wolfssl/wolfcrypt/rsa.h:WCv4-stable'
'wolfssl/wolfcrypt/sha.h:WCv4-stable'
'wolfssl/wolfcrypt/sha256.h:WCv4-stable'
'wolfssl/wolfcrypt/sha3.h:WCv4-stable'
'wolfssl/wolfcrypt/sha512.h:WCv4-stable'
)
if [ "$FLAVOR" = 'solaris' ]; then MAKE='gmake'; fi
;;
netbsd-selftest)
# non-FIPS, CAVP only but pull in selftest
FIPS_OPTION='cavp-selftest'
FIPS_FILES=('wolfcrypt/src/selftest.c:v3.14.2b')
WOLFCRYPT_FILES=(
'wolfcrypt/src/aes.c:v3.14.2'
'wolfcrypt/src/dh.c:v3.14.2'
'wolfcrypt/src/dsa.c:v3.14.2'
'wolfcrypt/src/ecc.c:v3.14.2'
'wolfcrypt/src/hmac.c:v3.14.2'
'wolfcrypt/src/random.c:v3.14.2'
'wolfcrypt/src/rsa.c:v3.14.2'
'wolfcrypt/src/sha.c:v3.14.2'
'wolfcrypt/src/sha256.c:v3.14.2'
'wolfcrypt/src/sha512.c:v3.14.2'
'wolfssl/wolfcrypt/aes.h:v3.14.2'
'wolfssl/wolfcrypt/dh.h:v3.14.2'
'wolfssl/wolfcrypt/dsa.h:v3.14.2'
'wolfssl/wolfcrypt/ecc.h:v3.14.2'
'wolfssl/wolfcrypt/hmac.h:v3.14.2'
'wolfssl/wolfcrypt/random.h:v3.14.2'
'wolfssl/wolfcrypt/rsa.h:v3.14.2'
'wolfssl/wolfcrypt/sha.h:v3.14.2'
'wolfssl/wolfcrypt/sha256.h:v3.14.2'
'wolfssl/wolfcrypt/sha512.h:v3.14.2'
)
;;
marvell-linux-selftest)
# non-FIPS, CAVP only but pull in selftest
FIPS_OPTION='cavp-selftest-v2'
FIPS_FILES=('wolfcrypt/src/selftest.c:v3.14.2b')
WOLFCRYPT_FILES=(
'wolfcrypt/src/aes.c:v4.1.0-stable'
'wolfcrypt/src/dh.c:v4.1.0-stable'
'wolfcrypt/src/dsa.c:v4.1.0-stable'
'wolfcrypt/src/ecc.c:v4.1.0-stable'
'wolfcrypt/src/hmac.c:v4.1.0-stable'
'wolfcrypt/src/random.c:v4.1.0-stable'
'wolfcrypt/src/rsa.c:v4.1.0-stable'
'wolfcrypt/src/sha.c:v4.1.0-stable'
'wolfcrypt/src/sha256.c:v4.1.0-stable'
'wolfcrypt/src/sha512.c:v4.1.0-stable'
'wolfssl/wolfcrypt/aes.h:v4.1.0-stable'
'wolfssl/wolfcrypt/dh.h:v4.1.0-stable'
'wolfssl/wolfcrypt/dsa.h:v4.1.0-stable'
'wolfssl/wolfcrypt/ecc.h:v4.1.0-stable'
'wolfssl/wolfcrypt/hmac.h:v4.1.0-stable'
'wolfssl/wolfcrypt/random.h:v4.1.0-stable'
'wolfssl/wolfcrypt/rsa.h:v4.1.0-stable'
'wolfssl/wolfcrypt/sha.h:v4.1.0-stable'
'wolfssl/wolfcrypt/sha256.h:v4.1.0-stable'
'wolfssl/wolfcrypt/sha512.h:v4.1.0-stable'
)
;;
linuxv5)
FIPS_OPTION='v5'
FIPS_FILES=(
'wolfcrypt/src/fips.c:WCv5.2.0.1-RC01'
'wolfcrypt/src/fips_test.c:WCv5.0-RC12'
'wolfcrypt/src/wolfcrypt_first.c:WCv5.0-RC12'
'wolfcrypt/src/wolfcrypt_last.c:WCv5.0-RC12'
'wolfssl/wolfcrypt/fips.h:WCv5.0-RC12'
)
WOLFCRYPT_FILES=(
'wolfcrypt/src/aes.c:WCv5.0-RC12'
'wolfcrypt/src/aes_asm.asm:WCv5.0-RC12'
'wolfcrypt/src/aes_asm.S:WCv5.0-RC12'
'wolfcrypt/src/aes_gcm_asm.S:WCv5.0-RC12'
'wolfcrypt/src/cmac.c:WCv5.0-RC12'
'wolfcrypt/src/dh.c:WCv5.0-RC12'
'wolfcrypt/src/ecc.c:WCv5.0-RC12'
'wolfcrypt/src/hmac.c:WCv5.0-RC12'
'wolfcrypt/src/kdf.c:WCv5.0-RC12'
'wolfcrypt/src/random.c:WCv5.0-RC12'
'wolfcrypt/src/rsa.c:WCv5.0-RC12'
'wolfcrypt/src/sha.c:WCv5.0-RC12'
'wolfcrypt/src/sha256.c:WCv5.0-RC12'
'wolfcrypt/src/sha256_asm.S:WCv5.0-RC12'
'wolfcrypt/src/sha3.c:WCv5.0-RC12'
'wolfcrypt/src/sha512.c:WCv5.0-RC12'
'wolfcrypt/src/sha512_asm.S:WCv5.0-RC12'
'wolfssl/wolfcrypt/aes.h:WCv5.0-RC12'
'wolfssl/wolfcrypt/cmac.h:WCv5.0-RC12'
'wolfssl/wolfcrypt/dh.h:WCv5.0-RC12'
'wolfssl/wolfcrypt/ecc.h:WCv5.0-RC12'
'wolfssl/wolfcrypt/fips_test.h:WCv5.0-RC12'
'wolfssl/wolfcrypt/hmac.h:WCv5.0-RC12'
'wolfssl/wolfcrypt/kdf.h:WCv5.0-RC12'
'wolfssl/wolfcrypt/random.h:WCv5.0-RC12'
'wolfssl/wolfcrypt/rsa.h:WCv5.0-RC12'
'wolfssl/wolfcrypt/sha.h:WCv5.0-RC12'
'wolfssl/wolfcrypt/sha256.h:WCv5.0-RC12'
'wolfssl/wolfcrypt/sha3.h:WCv5.0-RC12'
'wolfssl/wolfcrypt/sha512.h:WCv5.0-RC12'
)
;;
linuxv5.2.1)
FIPS_OPTION='v5'
FIPS_FILES=(
'wolfcrypt/src/fips.c:v5.2.1-stable'
'wolfcrypt/src/fips_test.c:v5.2.1-stable'
'wolfcrypt/src/wolfcrypt_first.c:v5.2.1-stable'
'wolfcrypt/src/wolfcrypt_last.c:v5.2.1-stable'
'wolfssl/wolfcrypt/fips.h:v5.2.1-stable'
)
WOLFCRYPT_FILES=(
'wolfcrypt/src/aes.c:v5.2.1-stable'
'wolfcrypt/src/aes_asm.asm:v5.2.1-stable'
'wolfcrypt/src/aes_asm.S:v5.2.1-stable'
'wolfcrypt/src/aes_gcm_asm.S:v5.2.1-stable'
'wolfcrypt/src/cmac.c:v5.2.1-stable'
'wolfcrypt/src/dh.c:v5.2.1-stable'
'wolfcrypt/src/ecc.c:v5.2.1-stable'
'wolfcrypt/src/hmac.c:v5.2.1-stable'
'wolfcrypt/src/kdf.c:v5.2.1-stable'
'wolfcrypt/src/random.c:v5.2.1-stable'
'wolfcrypt/src/rsa.c:v5.2.1-stable'
'wolfcrypt/src/sha.c:v5.2.1-stable'
'wolfcrypt/src/sha256.c:v5.2.1-stable'
'wolfcrypt/src/sha256_asm.S:v5.2.1-stable'
'wolfcrypt/src/sha3.c:v5.2.1-stable'
'wolfcrypt/src/sha512.c:v5.2.1-stable'
'wolfcrypt/src/sha512_asm.S:v5.2.1-stable'
'wolfssl/wolfcrypt/aes.h:v5.2.1-stable'
'wolfssl/wolfcrypt/cmac.h:v5.2.1-stable'
'wolfssl/wolfcrypt/dh.h:v5.2.1-stable'
'wolfssl/wolfcrypt/ecc.h:v5.2.1-stable'
'wolfssl/wolfcrypt/fips_test.h:v5.2.1-stable'
'wolfssl/wolfcrypt/hmac.h:v5.2.1-stable'
'wolfssl/wolfcrypt/kdf.h:v5.2.1-stable'
'wolfssl/wolfcrypt/random.h:v5.2.1-stable'
'wolfssl/wolfcrypt/rsa.h:v5.2.1-stable'
'wolfssl/wolfcrypt/sha.h:v5.2.1-stable'
'wolfssl/wolfcrypt/sha256.h:v5.2.1-stable'
'wolfssl/wolfcrypt/sha3.h:v5.2.1-stable'
'wolfssl/wolfcrypt/sha512.h:v5.2.1-stable'
)
;;
fips-ready|fips-dev)
FIPS_OPTION='ready'
FIPS_FILES=(
'wolfcrypt/src/fips.c:master'
'wolfcrypt/src/fips_test.c:master'
'wolfcrypt/src/wolfcrypt_first.c:master'
'wolfcrypt/src/wolfcrypt_last.c:master'
'wolfssl/wolfcrypt/fips.h:master'
)
WOLFCRYPT_FILES=()
if [ "$FLAVOR" = 'fips-dev' ]; then FIPS_OPTION='dev'; fi
;;
wolfrand)
FIPS_OPTION='rand'
FIPS_FILES=(
'wolfcrypt/src/fips.c:WRv4-stable'
'wolfcrypt/src/fips_test.c:WRv4-stable'
'wolfcrypt/src/wolfcrypt_first.c:WRv4-stable'
'wolfcrypt/src/wolfcrypt_last.c:WRv4-stable'
'wolfssl/wolfcrypt/fips.h:WRv4-stable'
)
WOLFCRYPT_FILES=(
'wolfcrypt/src/hmac.c:WCv4-stable'
'wolfcrypt/src/random.c:WCv4-rng-stable'
'wolfcrypt/src/sha256.c:WCv4-stable'
'wolfssl/wolfcrypt/hmac.h:WCv4-stable'
'wolfssl/wolfcrypt/random.h:WCv4-rng-stable'
'wolfssl/wolfcrypt/sha256.h:WCv4-stable'
)
;;
wolfentropy)
FIPS_OPTION='v6'
FIPS_FILES=(
'wolfcrypt/src/fips.c:wolfEntropy1'
'wolfcrypt/src/fips_test.c:wolfEntropy1'
'wolfcrypt/src/wolfcrypt_first.c:wolfEntropy1'
'wolfcrypt/src/wolfcrypt_last.c:wolfEntropy1'
'wolfssl/wolfcrypt/fips.h:wolfEntropy1'
)
WOLFCRYPT_FILES=(
'wolfcrypt/src/aes.c:wolfEntropy1'
'wolfcrypt/src/aes_asm.asm:wolfEntropy1'
'wolfcrypt/src/aes_asm.S:wolfEntropy1'
'wolfcrypt/src/aes_gcm_asm.S:wolfEntropy1'
'wolfcrypt/src/ecc.c:wolfEntropy1'
'wolfcrypt/src/hmac.c:wolfEntropy1'
'wolfcrypt/src/kdf.c:wolfEntropy1'
'wolfcrypt/src/random.c:wolfEntropy1'
'wolfcrypt/src/sha256.c:wolfEntropy1'
'wolfcrypt/src/sha256_asm.S:wolfEntropy1'
'wolfcrypt/src/sha3.c:wolfEntropy1'
'wolfcrypt/src/sha512.c:wolfEntropy1'
'wolfcrypt/src/sha512_asm.S:wolfEntropy1'
'wolfssl/wolfcrypt/aes.h:wolfEntropy1'
'wolfssl/wolfcrypt/ecc.h:wolfEntropy1'
'wolfssl/wolfcrypt/fips_test.h:wolfEntropy1'
'wolfssl/wolfcrypt/hmac.h:wolfEntropy1'
'wolfssl/wolfcrypt/kdf.h:wolfEntropy1'
'wolfssl/wolfcrypt/random.h:wolfEntropy1'
'wolfssl/wolfcrypt/sha256.h:wolfEntropy1'
'wolfssl/wolfcrypt/sha3.h:wolfEntropy1'
'wolfssl/wolfcrypt/sha512.h:wolfEntropy1'
)
;;
*)
Usage
exit 1
esac
# checkout_files takes an array of pairs of file paths and git tags to
# checkout. It will check to see if mytag exists and if not will make that
# tag a branch.
function checkout_files() {
local name
local tag
for file_entry in "$@"; do
name=${file_entry%%:*}
tag=${file_entry#*:}
if ! $GIT rev-parse -q --verify "my$tag" >/dev/null
then
$GIT branch --no-track "my$tag" "$tag" || exit $?
fi
$GIT checkout "my$tag" -- "$name" || exit $?
done
}
# copy_fips_files takes an array of pairs of file paths and git tags to
# checkout. It will check to see if mytag exists and if now will make that
# tag a branch. It breaks the filepath apart into file name and path, then
# copies it from the file from the fips directory to the path.
function copy_fips_files() {
local name
local bname
local dname
local tag
for file_entry in "$@"; do
name=${file_entry%%:*}
tag=${file_entry#*:}
bname=$(basename "$name")
dname=$(dirname "$name")
if ! $GIT rev-parse -q --verify "my$tag" >/dev/null; then
$GIT branch --no-track "my$tag" "$tag" || exit $?
fi
$GIT checkout "my$tag" -- "$bname" || exit $?
cp "$bname" "../$dname"
done
}
# Check to make sure this is not a shallow repo
$GIT fetch --unshallow 2>/dev/null
if ! $GIT clone . "$TEST_DIR"; then
echo "fips-check: Couldn't duplicate current working directory."
exit 1
fi
pushd "$TEST_DIR" || exit 2
if ! $GIT clone "$FIPS_REPO" fips; then
echo "fips-check: Couldn't check out FIPS repository."
exit 1
fi
checkout_files "${WOLFCRYPT_FILES[@]}" || exit 3
pushd fips || exit 2
copy_fips_files "${FIPS_FILES[@]}" || exit 3
popd || exit 2
# When checking out cert 3389 ready code, NIST will no longer perform
# new certifications on 140-2 modules. If we were to use the latest files from
# master that would require re-cert due to changes in the module boundary.
# Since OE additions can still be processed for cert3389 we will call 140-2
# ready "fipsv2-OE-ready" indicating it is ready to use for an OE addition but
# would not be good for a new certification effort with the latest files.
if [ "$FLAVOR" = 'fipsv2-OE-ready' ] && [ -s wolfcrypt/src/fips.c ]; then
cp wolfcrypt/src/fips.c wolfcrypt/src/fips.c.bak
sed "s/v4.0.0-alpha/fipsv2-OE-ready/" wolfcrypt/src/fips.c.bak >wolfcrypt/src/fips.c
fi
# run the make test
./autogen.sh
case "$FIPS_OPTION" in
cavp-selftest)
./configure --enable-selftest
;;
cavp-selftest-v2)
./configure --enable-selftest=v2
;;
*)
./configure --enable-fips=$FIPS_OPTION
;;
esac
if ! $MAKE; then
echo 'fips-check: Make failed. Debris left for analysis.'
exit 3
fi
if [ -s wolfcrypt/src/fips_test.c ]; then
NEWHASH=$(./wolfcrypt/test/testwolfcrypt | sed -n 's/hash = \(.*\)/\1/p')
if [ -n "$NEWHASH" ]; then
cp wolfcrypt/src/fips_test.c wolfcrypt/src/fips_test.c.bak
sed "s/^\".*\";/\"${NEWHASH}\";/" wolfcrypt/src/fips_test.c.bak >wolfcrypt/src/fips_test.c
make clean
fi
fi
if [ "$MAKECHECK" = "yes" ]; then
if ! $MAKE check; then
echo 'fips-check: Test failed. Debris left for analysis.'
exit 3
fi
fi
# Clean up
popd || exit 2
if [ "$KEEP" = 'no' ]; then
rm -rf "$TEST_DIR"
fi