@@ -36,66 +36,63 @@ MAKE="${MAKE:-make}"
3636GIT=" ${GIT:- git -c advice.detachedHead=false} "
3737TEST_DIR=" ${TEST_DIR:- XXX-fips-test} "
3838FLAVOR=" ${FLAVOR:- linux} "
39- KEEP=" ${KEEP:- no} "
39+ # KEEP="${KEEP:-no}"
40+ KEEP=" ${KEEP:- yes} "
41+ # FIPS_REPO="${FIPS_REPO:-git@github.com:wolfssl/fips.git}"
4042
4143while [ " $1 " ]; do
42- if [ " $1 " = ' new' ]; then DO_NEW_ACTION=' yes' ; else
43- if [ " $1 " = ' keep' ]; then KEEP=' yes' ; else FLAVOR=" $1 " ; fi ; fi
44+ if [ " $1 " = ' keep' ]; then KEEP=' yes' ; else FLAVOR=" $1 " ; fi
4445 shift
4546done
4647
47- FIPS_REPO=' git@github.com:wolfssl/fips.git'
48- CRYPT_INC_PATH=' wolfssl/wolfcrypt'
49- CRYPT_SRC_PATH=' wolfcrypt/src'
50-
5148case " $FLAVOR " in
52- linuxv2|fipsv2-OE-ready)
53- FIPS_OPTION=' v2'
54- FIPS_VERSION=' WCv4-stable'
55- CRYPT_VERSION=' WCv4-stable'
56- RNG_VERSION=' WCv4-rng-stable'
57- WC_MODS=(' aes' ' aes_asm' ' cmac' ' des3' ' dh' ' ecc' ' hmac' ' random' ' rsa' ' sha' ' sha256' ' sha3' ' sha512' )
58- FIPS_SRCS=(' fips.c' ' fips_test.c' ' wolfcrypt_first.c' ' wolfcrypt_last.c' )
59- FIPS_INCS=(' fips.h' )
60- ;;
61- netbsd-selftest)
62- # non-FIPS, CAVP only but pull in selftest
63- FIPS_OPTION=' cavp-selftest'
64- FIPS_VERSION=' v3.14.2b'
65- CRYPT_VERSION=' v3.14.2'
66- RNG_VERSION=' v3.14.2'
67- WC_MODS=(' aes' ' dh' ' dsa' ' ecc' ' hmac' ' random' ' rsa' ' sha' ' sha256' ' sha512' )
68- FIPS_SRCS=(' selftest.c' )
69- ;;
70- marvell-linux-selftest)
71- # non-FIPS, CAVP only but pull in selftest
72- FIPS_OPTION=' cavp-selftest-v2'
73- FIPS_VERSION=' v3.14.2b'
74- CRYPT_VERSION=' v4.1.0-stable'
75- RNG_VERSION=' v4.1.0-stable'
76- WC_MODS=(' aes' ' dh' ' dsa' ' ecc' ' hmac' ' random' ' rsa' ' sha' ' sha256' ' sha512' )
77- FIPS_SRCS=(' selftest.c' )
78- ;;
79- linuxv5)
80- FIPS_OPTION=' v5'
81- FIPS_VERSION=' WCv5.0-RC12'
82- CRYPT_VERSION=' WCv5.0-RC12'
83- RNG_VERSION=' WCv5.0-RC12'
84- WC_MODS=(' aes' ' aes_asm' ' cmac' ' dh' ' ecc' ' hmac' ' kdf' ' random' ' rsa' ' sha' ' sha256' ' sha256_asm' ' sha3' ' sha512' ' sha512_asm' )
85- FIPS_SRCS=(' fips.c' ' fips_test.c' ' wolfcrypt_first.c' ' wolfcrypt_last.c' )
86- FIPS_INCS=(' fips.h' )
87- COPY_DIRECT=(' wolfcrypt/src/aes_gcm_asm.S' )
88- ;;
49+ # linuxv2|fipsv2-OE-ready)
50+ # FIPS_OPTION='v2'
51+ # FIPS_VERSION='WCv4-stable'
52+ # CRYPT_VERSION='WCv4-stable'
53+ # RNG_VERSION='WCv4-rng-stable'
54+ # WC_MODS=('aes' 'aes_asm' 'cmac' 'des3' 'dh' 'ecc' 'hmac' 'random' 'rsa' 'sha' 'sha256' 'sha3' 'sha512')
55+ # FIPS_SRCS=('fips.c' 'fips_test.c' 'wolfcrypt_first.c' 'wolfcrypt_last.c')
56+ # FIPS_INCS=('fips.h')
57+ # ;;
58+ # netbsd-selftest)
59+ # # non-FIPS, CAVP only but pull in selftest
60+ # FIPS_OPTION='cavp-selftest'
61+ # FIPS_VERSION='v3.14.2b'
62+ # CRYPT_VERSION='v3.14.2'
63+ # RNG_VERSION='v3.14.2'
64+ # WC_MODS=('aes' 'dh' 'dsa' 'ecc' 'hmac' 'random' 'rsa' 'sha' 'sha256' 'sha512')
65+ # FIPS_SRCS=('selftest.c')
66+ # ;;
67+ # marvell-linux-selftest)
68+ # # non-FIPS, CAVP only but pull in selftest
69+ # FIPS_OPTION='cavp-selftest-v2'
70+ # FIPS_VERSION='v3.14.2b'
71+ # CRYPT_VERSION='v4.1.0-stable'
72+ # RNG_VERSION='v4.1.0-stable'
73+ # WC_MODS=('aes' 'dh' 'dsa' 'ecc' 'hmac' 'random' 'rsa' 'sha' 'sha256' 'sha512')
74+ # FIPS_SRCS=('selftest.c')
75+ # ;;
76+ # linuxv5)
77+ # FIPS_OPTION='v5'
78+ # FIPS_VERSION='WCv5.0-RC12'
79+ # CRYPT_VERSION='WCv5.0-RC12'
80+ # RNG_VERSION='WCv5.0-RC12'
81+ # WC_MODS=('aes' 'aes_asm' 'cmac' 'dh' 'ecc' 'hmac' 'kdf' 'random' 'rsa' 'sha' 'sha256' 'sha256_asm' 'sha3' 'sha512' 'sha512_asm')
82+ # FIPS_SRCS=('fips.c' 'fips_test.c' 'wolfcrypt_first.c' 'wolfcrypt_last.c')
83+ # FIPS_INCS=('fips.h')
84+ # COPY_DIRECT=('wolfcrypt/src/aes_gcm_asm.S')
85+ # ;;
8986linuxv5a)
9087 FIPS_OPTION=' v5'
91- FIPS_FILES=(
92- ' fips.c:WCv5.0-RC12 '
93- ' fips_test.c:WCv5.0-RC12 '
94- ' wolfcrypt_first.c:WCv5.0-RC12 '
95- ' wolfcrypt_last.c:WCv5.0-RC12 '
96- ' fips.h:WCv5.0-RC12 '
88+ FIPS_FILES=(' WCv5.0-RC12 '
89+ ' wolfcrypt/src/ fips.c'
90+ ' wolfcrypt/src/ fips_test.c'
91+ ' wolfcrypt/src/ wolfcrypt_first.c'
92+ ' wolfcrypt/src/ wolfcrypt_last.c'
93+ ' wolfssl/wolfcrypt/ fips.h'
9794 )
98- WC_C_FILES =(
95+ WOLFCRYPT_FILES =(
9996 ' wolfcrypt/src/aes.c:WCv5.0-RC12'
10097 ' wolfcrypt/src/aes_asm.c:WCv5.0-RC12'
10198 ' wolfcrypt/src/cmac.c:WCv5.0-RC12'
@@ -129,86 +126,74 @@ linuxv5a)
129126 ' wolfssl/wolfcrypt/sha512_asm.h:WCv5.0-RC12'
130127 )
131128 ;;
132- fips-ready)
133- FIPS_OPTION=' ready'
134- FIPS_VERSION=' master'
135- FIPS_SRCS=(' fips.c' ' fips_test.c' ' wolfcrypt_first.c' ' wolfcrypt_last.c' )
136- FIPS_INCS=(' fips.h' )
137- ;;
138- fips-dev)
139- FIPS_OPTION=' dev'
140- FIPS_VERSION=' master'
141- FIPS_SRCS=(' fips.c' ' fips_test.c' ' wolfcrypt_first.c' ' wolfcrypt_last.c' )
142- FIPS_INCS=(' fips.h' )
143- ;;
144- wolfrand)
145- FIPS_OPTION=' rand'
146- FIPS_VERSION=' WRv4-stable'
147- CRYPT_VERSION=' WCv4-stable'
148- RNG_VERSION=' WCv4-rng-stable'
149- WC_MODS=(' hmac' ' random' ' sha256' )
150- FIPS_SRCS=(' fips.c' ' fips_test.c' ' wolfcrypt_first.c' ' wolfcrypt_last.c' )
151- FIPS_INCS=(' fips.h' )
152- ;;
153- solaris)
154- FIPS_OPTION=' v2'
155- FIPS_VERSION=' WCv4-stable'
156- CRYPT_VERSION=' WCv4-stable'
157- RNG_VERSION=' WCv4-rng-stable'
158- WC_MODS=(' aes' ' aes_asm' ' cmac' ' des3' ' dh' ' ecc' ' hmac' ' random' ' rsa' ' sha' ' sha256' ' sha3' ' sha512' )
159- FIPS_SRCS=(' fips.c' ' fips_test.c' ' wolfcrypt_first.c' ' wolfcrypt_last.c' )
160- FIPS_INCS=(' fips.h' )
161- MAKE=' gmake'
162- ;;
129+ # fips-ready)
130+ # FIPS_OPTION='ready'
131+ # FIPS_VERSION='master'
132+ # FIPS_SRCS=('fips.c' 'fips_test.c' 'wolfcrypt_first.c' 'wolfcrypt_last.c')
133+ # FIPS_INCS=('fips.h')
134+ # ;;
135+ # fips-dev)
136+ # FIPS_OPTION='dev'
137+ # FIPS_VERSION='master'
138+ # FIPS_SRCS=('fips.c' 'fips_test.c' 'wolfcrypt_first.c' 'wolfcrypt_last.c')
139+ # FIPS_INCS=('fips.h')
140+ # ;;
141+ # wolfrand)
142+ # FIPS_OPTION='rand'
143+ # FIPS_VERSION='WRv4-stable'
144+ # CRYPT_VERSION='WCv4-stable'
145+ # RNG_VERSION='WCv4-rng-stable'
146+ # WC_MODS=('hmac' 'random' 'sha256')
147+ # FIPS_SRCS=('fips.c' 'fips_test.c' 'wolfcrypt_first.c' 'wolfcrypt_last.c')
148+ # FIPS_INCS=('fips.h')
149+ # ;;
150+ # solaris)
151+ # FIPS_OPTION='v2'
152+ # FIPS_VERSION='WCv4-stable'
153+ # CRYPT_VERSION='WCv4-stable'
154+ # RNG_VERSION='WCv4-rng-stable'
155+ # WC_MODS=('aes' 'aes_asm' 'cmac' 'des3' 'dh' 'ecc' 'hmac' 'random' 'rsa' 'sha' 'sha256' 'sha3' 'sha512')
156+ # FIPS_SRCS=('fips.c' 'fips_test.c' 'wolfcrypt_first.c' 'wolfcrypt_last.c')
157+ # FIPS_INCS=('fips.h')
158+ # MAKE='gmake'
159+ # ;;
163160* )
164161 Usage
165162 exit 1
166163esac
167164
168- function checkout_tag() {
169- if ! $GIT branch --list | grep " my$1 "
170- then
171- $GIT branch --no-track " my$1 " " $1 " || exit $?
172- fi
173- }
174-
165+ # checkout_files takes an array of pairs of file paths and git tags to checkout.
166+ # It will check to see if mytag exists and if not will make that tag a branch.
175167function checkout_files() {
176- local repo_path=" $1 "
177- shift
178- pushd $repo_path
179168 for file_entry in " $@ "
180169 do
181170 local name=${file_entry%%:* }
182171 local tag=${file_entry#*: }
183- checkout_tag " $tag " || exit $?
172+ if ! $GIT branch --list | grep " my$tag "
173+ then
174+ $GIT branch --no-track " my$tag " " $tag " || exit $?
175+ fi
184176 $GIT checkout " my$tag " -- " $name " || exit $?
185177 done
186- popd
187178}
188179
189- function copy_files() {
190- local repo_path=" $1 "
180+ # copy_fips_files clones the FIPS repository. It takes an array of file paths, where
181+ # it breaks apart into file name and path, then copies it from the file from the fips
182+ # directory to the path. The first item is the name of the tag.
183+ function copy_fips_files() {
184+ local tag=" $1 "
191185 shift
192- pushd $repo_path
193- for file_entry in " $@ "
186+ if ! $GIT clone --depth 1 -b " $tag " ' git@github.com:wolfssl/fips.git' fips
187+ then
188+ echo " fips-check: Couldn't check out $tag from FIPS repository."
189+ exit 1
190+ fi
191+ for file_path in " $@ "
194192 do
195- local name=${file_entry%%:* }
196- local tag=${file_entry#*: }
197- checkout_tag " $tag " || exit $?
198- $GIT checkout " my$tag " -- " $name " || exit $?
193+ cp fips/" $( basename " $file_path " ) " " $( dirname " $file_path " ) "
199194 done
200- popd
201195}
202196
203- if [ " $DO_NEW_ACTION " = ' yes' ]
204- then
205- checkout_files ' .' " ${WC_C_FILES[@]} "
206- checkout_files ' ./fips' " ${FIPS_FILES[@]} "
207- exit
208- fi
209- echo " Escaped!"
210- exit
211-
212197if ! $GIT clone . " $TEST_DIR " ; then
213198 echo " fips-check: Couldn't duplicate current working directory."
214199 exit 1
@@ -227,52 +212,27 @@ case "$FIPS_OPTION" in
227212 ;;
228213
229214cavp-selftest* |v2|rand|v5* )
230- checkout_files ' . ' " ${WC_C_FILES [@]} "
215+ checkout_files " ${WOLFCRYPT_FILES [@]} "
231216 ;;
232217
233218* )
234- echo " fips-check: Invalid FIPS option \" ${FIPS_OPTION} \" ."
219+ echo " fips-check: Invalid FIPS option ${FIPS_OPTION} ."
235220 exit 1
236221 ;;
237222esac
238223
239- # clone the FIPS repository
240- case " $FIPS_OPTION " in
241- * dev)
242- if ! $GIT clone --depth 1 " $FIPS_REPO " fips; then
243- echo " fips-check: Couldn't check out the FIPS repository for fips-dev."
244- exit 1
245- fi
246- ;;
247- * )
248- if ! $GIT clone --depth 1 -b " $FIPS_VERSION " " $FIPS_REPO " fips; then
249- echo " fips-check: Couldn't check out ${FIPS_VERSION} from repository ${FIPS_REPO} ."
250- exit 1
251- fi
252- ;;
253- esac
254-
255- for SRC in " ${FIPS_SRCS[@]} "
256- do
257- cp " fips/$SRC " " $CRYPT_SRC_PATH "
258- done
259-
260- for INC in " ${FIPS_INCS[@]} "
261- do
262- cp " fips/$INC " " $CRYPT_INC_PATH "
263- done
224+ copy_fips_files " ${FIPS_FILES[@]} "
264225
265226# When checking out cert 3389 ready code, NIST will no longer perform
266227# new certifications on 140-2 modules. If we were to use the latest files from
267228# master that would require re-cert due to changes in the module boundary.
268229# Since OE additions can still be processed for cert3389 we will call 140-2
269230# ready "fipsv2-OE-ready" indicating it is ready to use for an OE addition but
270231# would not be good for a new certification effort with the latest files.
271- if [ " $FLAVOR " = ' fipsv2-OE-ready' ]; then
272- OLD_VERSION=" return \" v4.0.0-alpha\" ;"
273- OE_READY_VERSION=" return \" fipsv2-OE-ready\" ;"
274- cp " ${CRYPT_SRC_PATH} /fips.c" " ${CRYPT_SRC_PATH} /fips.c.bak"
275- sed " s/^${OLD_VERSION} /${OE_READY_VERSION} /" " ${CRYPT_SRC_PATH} /fips.c.bak" > " ${CRYPT_SRC_PATH} /fips.c"
232+ if [ " $FLAVOR " = ' fipsv2-OE-ready' ] && [ -s wolfcrypt/src/fips.c ]
233+ then
234+ cp wolfcrypt/src/fips.c wolfcrypt/src/fips.c.bak
235+ sed " s/^v4.0.0-alpha/fipsv2-OE-ready/" wolfcrypt/src/fips.c.bak > wolfcrypt/src/fips.c
276236fi
277237
278238# run the make test
@@ -296,25 +256,25 @@ then
296256 exit 3
297257fi
298258
299- if [ -s " ${CRYPT_SRC_PATH} / fips_test.c" ]
259+ if [ -s wolfcrypt/src/ fips_test.c ]
300260then
301261 NEWHASH=$( ./wolfcrypt/test/testwolfcrypt | sed -n ' s/hash = \(.*\)/\1/p' )
302262 if [ -n " $NEWHASH " ]; then
303- cp " ${CRYPT_SRC_PATH} / fips_test.c" " ${CRYPT_SRC_PATH} / fips_test.c.bak"
304- sed " s/^\" .*\" ;/\" ${NEWHASH} \" ;/" " ${CRYPT_SRC_PATH} / fips_test.c.bak" > " ${CRYPT_SRC_PATH} / fips_test.c"
263+ cp wolfcrypt/src/ fips_test.c wolfcrypt/src/ fips_test.c.bak
264+ sed " s/^\" .*\" ;/\" ${NEWHASH} \" ;/" wolfcrypt/src/ fips_test.c.bak > wolfcrypt/src/ fips_test.c
305265 make clean
306266 fi
307267fi
308268
309269if ! $MAKE check
310270then
311- echo " fips-check: Test failed. Debris left for analysis."
271+ echo ' fips-check: Test failed. Debris left for analysis.'
312272 exit 3
313273fi
314274
315275# Clean up
316276popd || exit 2
317- if [ " $KEEP " = " no " ];
277+ if [ " $KEEP " = ' no ' ];
318278then
319279 rm -rf " $TEST_DIR "
320280fi
0 commit comments