1
0

fips-check.sh 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. #!/usr/bin/env bash
  2. # fips-check.sh
  3. # This script checks the current revision of the code against the
  4. # previous release of the FIPS code. While wolfSSL and wolfCrypt
  5. # may be advancing, they must work correctly with the last tested
  6. # copy of our FIPS approved code.
  7. #
  8. # This should check out all the approved flavors. The command line
  9. # option selects the flavor. The keep option keeps the output
  10. # directory.
  11. # These variables may be overridden on the command line.
  12. MAKE="${MAKE:-make}"
  13. GIT="${GIT:-git -c advice.detachedHead=false}"
  14. TEST_DIR="${TEST_DIR:-XXX-fips-test}"
  15. case "$TEST_DIR" in
  16. /*) ;;
  17. *) TEST_DIR="${PWD}/${TEST_DIR}"
  18. ;;
  19. esac
  20. FLAVOR="${FLAVOR:-linux}"
  21. KEEP="${KEEP:-no}"
  22. MAKECHECK=${MAKECHECK:-yes}
  23. DOCONFIGURE=${DOCONFIGURE:-yes}
  24. DOAUTOGEN=${DOAUTOGEN:-yes}
  25. FIPS_REPO="${FIPS_REPO:-git@github.com:wolfssl/fips.git}"
  26. WOLFSSL_REPO="${WOLFSSL_REPO:-git@github.com:wolfssl/wolfssl.git}"
  27. Usage() {
  28. cat <<usageText
  29. Usage: $0 [flavor] [keep]
  30. Flavor is one of:
  31. linuxv2 (FIPSv2, use for Win10)
  32. fipsv2-OE-ready (ready FIPSv2)
  33. solaris
  34. netbsd-selftest
  35. marvell-linux-selftest
  36. linuxv5 (current FIPS 140-3)
  37. fips-ready (ready FIPS 140-3)
  38. fips-dev (dev FIPS 140-3)
  39. wolfrand
  40. wolfentropy
  41. v6.0.0
  42. Keep (default off) retains the temp dir $TEST_DIR for inspection.
  43. Example:
  44. $0 windows keep
  45. usageText
  46. }
  47. while [ "$1" ]; do
  48. if [ "$1" = 'keep' ]; then KEEP='yes';
  49. elif [ "$1" = 'nomakecheck' ]; then MAKECHECK='no';
  50. elif [ "$1" = 'nodoconfigure' ]; then DOCONFIGURE='no';
  51. elif [ "$1" = 'noautogen' ]; then DOCONFIGURE='no'; DOAUTOGEN='no';
  52. else FLAVOR="$1"; fi
  53. shift
  54. done
  55. case "$FLAVOR" in
  56. linuxv2|fipsv2-OE-ready|solaris)
  57. FIPS_OPTION='v2'
  58. FIPS_FILES=(
  59. 'wolfcrypt/src/fips.c:WCv4-stable'
  60. 'wolfcrypt/src/fips_test.c:WCv4-stable'
  61. 'wolfcrypt/src/wolfcrypt_first.c:WCv4-stable'
  62. 'wolfcrypt/src/wolfcrypt_last.c:WCv4-stable'
  63. 'wolfssl/wolfcrypt/fips.h:WCv4-stable'
  64. )
  65. WOLFCRYPT_FILES=(
  66. 'wolfcrypt/src/aes.c:WCv4-stable'
  67. 'wolfcrypt/src/aes_asm.asm:WCv4-stable'
  68. 'wolfcrypt/src/aes_asm.S:WCv4-stable'
  69. 'wolfcrypt/src/cmac.c:WCv4-stable'
  70. 'wolfcrypt/src/des3.c:WCv4-stable'
  71. 'wolfcrypt/src/dh.c:WCv4-stable'
  72. 'wolfcrypt/src/ecc.c:WCv4-stable'
  73. 'wolfcrypt/src/hmac.c:WCv4-stable'
  74. 'wolfcrypt/src/random.c:WCv4-rng-stable'
  75. 'wolfcrypt/src/rsa.c:WCv4-stable'
  76. 'wolfcrypt/src/sha.c:WCv4-stable'
  77. 'wolfcrypt/src/sha256.c:WCv4-stable'
  78. 'wolfcrypt/src/sha3.c:WCv4-stable'
  79. 'wolfcrypt/src/sha512.c:WCv4-stable'
  80. 'wolfssl/wolfcrypt/aes.h:WCv4-stable'
  81. 'wolfssl/wolfcrypt/cmac.h:WCv4-stable'
  82. 'wolfssl/wolfcrypt/des3.h:WCv4-stable'
  83. 'wolfssl/wolfcrypt/dh.h:WCv4-stable'
  84. 'wolfssl/wolfcrypt/ecc.h:WCv4-stable'
  85. 'wolfssl/wolfcrypt/hmac.h:WCv4-stable'
  86. 'wolfssl/wolfcrypt/random.h:WCv4-rng-stable'
  87. 'wolfssl/wolfcrypt/rsa.h:WCv4-stable'
  88. 'wolfssl/wolfcrypt/sha.h:WCv4-stable'
  89. 'wolfssl/wolfcrypt/sha256.h:WCv4-stable'
  90. 'wolfssl/wolfcrypt/sha3.h:WCv4-stable'
  91. 'wolfssl/wolfcrypt/sha512.h:WCv4-stable'
  92. )
  93. if [ "$FLAVOR" = 'solaris' ]; then MAKE='gmake'; fi
  94. ;;
  95. netbsd-selftest)
  96. # non-FIPS, CAVP only but pull in selftest
  97. FIPS_OPTION='cavp-selftest'
  98. FIPS_FILES=('wolfcrypt/src/selftest.c:v3.14.2b')
  99. WOLFCRYPT_FILES=(
  100. 'wolfcrypt/src/aes.c:v3.14.2'
  101. 'wolfcrypt/src/dh.c:v3.14.2'
  102. 'wolfcrypt/src/dsa.c:v3.14.2'
  103. 'wolfcrypt/src/ecc.c:v3.14.2'
  104. 'wolfcrypt/src/hmac.c:v3.14.2'
  105. 'wolfcrypt/src/random.c:v3.14.2'
  106. 'wolfcrypt/src/rsa.c:v3.14.2'
  107. 'wolfcrypt/src/sha.c:v3.14.2'
  108. 'wolfcrypt/src/sha256.c:v3.14.2'
  109. 'wolfcrypt/src/sha512.c:v3.14.2'
  110. 'wolfssl/wolfcrypt/aes.h:v3.14.2'
  111. 'wolfssl/wolfcrypt/dh.h:v3.14.2'
  112. 'wolfssl/wolfcrypt/dsa.h:v3.14.2'
  113. 'wolfssl/wolfcrypt/ecc.h:v3.14.2'
  114. 'wolfssl/wolfcrypt/hmac.h:v3.14.2'
  115. 'wolfssl/wolfcrypt/random.h:v3.14.2'
  116. 'wolfssl/wolfcrypt/rsa.h:v3.14.2'
  117. 'wolfssl/wolfcrypt/sha.h:v3.14.2'
  118. 'wolfssl/wolfcrypt/sha256.h:v3.14.2'
  119. 'wolfssl/wolfcrypt/sha512.h:v3.14.2'
  120. )
  121. ;;
  122. marvell-linux-selftest)
  123. # non-FIPS, CAVP only but pull in selftest
  124. FIPS_OPTION='cavp-selftest-v2'
  125. FIPS_FILES=('wolfcrypt/src/selftest.c:v3.14.2b')
  126. WOLFCRYPT_FILES=(
  127. 'wolfcrypt/src/aes.c:v4.1.0-stable'
  128. 'wolfcrypt/src/dh.c:v4.1.0-stable'
  129. 'wolfcrypt/src/dsa.c:v4.1.0-stable'
  130. 'wolfcrypt/src/ecc.c:v4.1.0-stable'
  131. 'wolfcrypt/src/hmac.c:v4.1.0-stable'
  132. 'wolfcrypt/src/random.c:v4.1.0-stable'
  133. 'wolfcrypt/src/rsa.c:v4.1.0-stable'
  134. 'wolfcrypt/src/sha.c:v4.1.0-stable'
  135. 'wolfcrypt/src/sha256.c:v4.1.0-stable'
  136. 'wolfcrypt/src/sha512.c:v4.1.0-stable'
  137. 'wolfssl/wolfcrypt/aes.h:v4.1.0-stable'
  138. 'wolfssl/wolfcrypt/dh.h:v4.1.0-stable'
  139. 'wolfssl/wolfcrypt/dsa.h:v4.1.0-stable'
  140. 'wolfssl/wolfcrypt/ecc.h:v4.1.0-stable'
  141. 'wolfssl/wolfcrypt/hmac.h:v4.1.0-stable'
  142. 'wolfssl/wolfcrypt/random.h:v4.1.0-stable'
  143. 'wolfssl/wolfcrypt/rsa.h:v4.1.0-stable'
  144. 'wolfssl/wolfcrypt/sha.h:v4.1.0-stable'
  145. 'wolfssl/wolfcrypt/sha256.h:v4.1.0-stable'
  146. 'wolfssl/wolfcrypt/sha512.h:v4.1.0-stable'
  147. )
  148. ;;
  149. linuxv5-RC12)
  150. FIPS_OPTION='v5-RC12'
  151. FIPS_FILES=(
  152. 'wolfcrypt/src/fips.c:WCv5.2.0.1-RC01'
  153. 'wolfcrypt/src/fips_test.c:WCv5.0-RC12'
  154. 'wolfcrypt/src/wolfcrypt_first.c:WCv5.0-RC12'
  155. 'wolfcrypt/src/wolfcrypt_last.c:WCv5.0-RC12'
  156. 'wolfssl/wolfcrypt/fips.h:WCv5.0-RC12'
  157. )
  158. WOLFCRYPT_FILES=(
  159. 'wolfcrypt/src/aes.c:WCv5.0-RC12'
  160. 'wolfcrypt/src/aes_asm.asm:WCv5.0-RC12'
  161. 'wolfcrypt/src/aes_asm.S:WCv5.0-RC12'
  162. 'wolfcrypt/src/aes_gcm_asm.S:WCv5.0-RC12'
  163. 'wolfcrypt/src/cmac.c:WCv5.0-RC12'
  164. 'wolfcrypt/src/dh.c:WCv5.0-RC12'
  165. 'wolfcrypt/src/ecc.c:WCv5.0-RC12'
  166. 'wolfcrypt/src/hmac.c:WCv5.0-RC12'
  167. 'wolfcrypt/src/kdf.c:WCv5.0-RC12'
  168. 'wolfcrypt/src/random.c:WCv5.0-RC12'
  169. 'wolfcrypt/src/rsa.c:WCv5.0-RC12'
  170. 'wolfcrypt/src/sha.c:WCv5.0-RC12'
  171. 'wolfcrypt/src/sha256.c:WCv5.0-RC12'
  172. 'wolfcrypt/src/sha256_asm.S:WCv5.0-RC12'
  173. 'wolfcrypt/src/sha3.c:WCv5.0-RC12'
  174. 'wolfcrypt/src/sha512.c:WCv5.0-RC12'
  175. 'wolfcrypt/src/sha512_asm.S:WCv5.0-RC12'
  176. 'wolfssl/wolfcrypt/aes.h:WCv5.0-RC12'
  177. 'wolfssl/wolfcrypt/cmac.h:WCv5.0-RC12'
  178. 'wolfssl/wolfcrypt/dh.h:WCv5.0-RC12'
  179. 'wolfssl/wolfcrypt/ecc.h:WCv5.0-RC12'
  180. 'wolfssl/wolfcrypt/fips_test.h:WCv5.0-RC12'
  181. 'wolfssl/wolfcrypt/hmac.h:WCv5.0-RC12'
  182. 'wolfssl/wolfcrypt/kdf.h:WCv5.0-RC12'
  183. 'wolfssl/wolfcrypt/random.h:WCv5.0-RC12'
  184. 'wolfssl/wolfcrypt/rsa.h:WCv5.0-RC12'
  185. 'wolfssl/wolfcrypt/sha.h:WCv5.0-RC12'
  186. 'wolfssl/wolfcrypt/sha256.h:WCv5.0-RC12'
  187. 'wolfssl/wolfcrypt/sha3.h:WCv5.0-RC12'
  188. 'wolfssl/wolfcrypt/sha512.h:WCv5.0-RC12'
  189. )
  190. ;;
  191. linuxv5|linuxv5.2.1)
  192. FIPS_OPTION='v5'
  193. FIPS_FILES=(
  194. 'wolfcrypt/src/fips.c:v5.2.1-stable'
  195. 'wolfcrypt/src/fips_test.c:v5.2.1-stable'
  196. 'wolfcrypt/src/wolfcrypt_first.c:v5.2.1-stable'
  197. 'wolfcrypt/src/wolfcrypt_last.c:v5.2.1-stable'
  198. 'wolfssl/wolfcrypt/fips.h:v5.2.1-stable-OS_Seed-HdrOnly'
  199. )
  200. WOLFCRYPT_FILES=(
  201. 'wolfcrypt/src/aes.c:v5.2.1-stable'
  202. 'wolfcrypt/src/aes_asm.asm:v5.2.1-stable'
  203. 'wolfcrypt/src/aes_asm.S:v5.2.1-stable'
  204. 'wolfcrypt/src/aes_gcm_asm.S:v5.2.1-stable'
  205. 'wolfcrypt/src/cmac.c:v5.2.1-stable'
  206. 'wolfcrypt/src/dh.c:v5.2.1-stable'
  207. 'wolfcrypt/src/ecc.c:v5.2.1-stable'
  208. 'wolfcrypt/src/hmac.c:v5.2.1-stable'
  209. 'wolfcrypt/src/kdf.c:v5.2.1-stable'
  210. 'wolfcrypt/src/random.c:v5.2.1-stable'
  211. 'wolfcrypt/src/rsa.c:v5.2.1-stable'
  212. 'wolfcrypt/src/sha.c:v5.2.1-stable'
  213. 'wolfcrypt/src/sha256.c:v5.2.1-stable'
  214. 'wolfcrypt/src/sha256_asm.S:v5.2.1-stable'
  215. 'wolfcrypt/src/sha3.c:v5.2.1-stable'
  216. 'wolfcrypt/src/sha512.c:v5.2.1-stable'
  217. 'wolfcrypt/src/sha512_asm.S:v5.2.1-stable'
  218. 'wolfssl/wolfcrypt/aes.h:v5.2.1-stable'
  219. 'wolfssl/wolfcrypt/cmac.h:v5.2.1-stable'
  220. 'wolfssl/wolfcrypt/dh.h:v5.2.1-stable'
  221. 'wolfssl/wolfcrypt/ecc.h:v5.2.1-stable'
  222. 'wolfssl/wolfcrypt/fips_test.h:v5.2.1-stable'
  223. 'wolfssl/wolfcrypt/hmac.h:v5.2.1-stable'
  224. 'wolfssl/wolfcrypt/kdf.h:v5.2.1-stable'
  225. 'wolfssl/wolfcrypt/random.h:v5.2.1-stable-OS_Seed-HdrOnly'
  226. 'wolfssl/wolfcrypt/rsa.h:v5.2.1-stable'
  227. 'wolfssl/wolfcrypt/sha.h:v5.2.1-stable'
  228. 'wolfssl/wolfcrypt/sha256.h:v5.2.1-stable'
  229. 'wolfssl/wolfcrypt/sha3.h:v5.2.1-stable'
  230. 'wolfssl/wolfcrypt/sha512.h:v5.2.1-stable'
  231. )
  232. ;;
  233. v6.0.0)
  234. WOLF_REPO_TAG='WCv6.0.0-RC1'
  235. FIPS_REPO_TAG='WCv6.0.0-RC1'
  236. ASM_PICKUPS_TAG='WCv6.0.0-RC2'
  237. FIPS_OPTION='v6'
  238. FIPS_FILES=(
  239. "wolfcrypt/src/fips.c:${FIPS_REPO_TAG}"
  240. "wolfcrypt/src/fips_test.c:${FIPS_REPO_TAG}"
  241. "wolfcrypt/src/wolfcrypt_first.c:${FIPS_REPO_TAG}"
  242. "wolfcrypt/src/wolfcrypt_last.c:${FIPS_REPO_TAG}"
  243. "wolfssl/wolfcrypt/fips.h:${FIPS_REPO_TAG}"
  244. )
  245. WOLFCRYPT_FILES=(
  246. "wolfcrypt/src/aes_asm.asm:${WOLF_REPO_TAG}"
  247. "wolfcrypt/src/aes_asm.S:${WOLF_REPO_TAG}"
  248. "wolfcrypt/src/aes_gcm_asm.S:${WOLF_REPO_TAG}"
  249. "wolfcrypt/src/aes_gcm_x86_asm.S:${WOLF_REPO_TAG}"
  250. "wolfcrypt/src/aes_xts_asm.S:${WOLF_REPO_TAG}"
  251. "wolfcrypt/src/aes.c:${WOLF_REPO_TAG}"
  252. "wolfcrypt/src/port/arm/armv8-32-aes-asm_c.c:${ASM_PICKUPS_TAG}"
  253. "wolfcrypt/src/port/arm/armv8-32-aes-asm.S:${WOLF_REPO_TAG}"
  254. "wolfcrypt/src/port/arm/armv8-32-curve25519_c.c:${ASM_PICKUPS_TAG}"
  255. "wolfcrypt/src/port/arm/armv8-32-curve25519.S:${WOLF_REPO_TAG}"
  256. "wolfcrypt/src/port/arm/armv8-32-sha256-asm_c.c:${ASM_PICKUPS_TAG}"
  257. "wolfcrypt/src/port/arm/armv8-32-sha256-asm.S:${WOLF_REPO_TAG}"
  258. "wolfcrypt/src/port/arm/armv8-32-sha512-asm_c.c:${ASM_PICKUPS_TAG}"
  259. "wolfcrypt/src/port/arm/armv8-32-sha512-asm.S:${WOLF_REPO_TAG}"
  260. "wolfcrypt/src/port/arm/armv8-aes.c:${ASM_PICKUPS_TAG}"
  261. "wolfcrypt/src/port/arm/armv8-curve25519_c.c:${ASM_PICKUPS_TAG}"
  262. "wolfcrypt/src/port/arm/armv8-curve25519.S:${WOLF_REPO_TAG}"
  263. "wolfcrypt/src/port/arm/armv8-sha256.c:${WOLF_REPO_TAG}"
  264. "wolfcrypt/src/port/arm/armv8-sha3-asm_c.c:${ASM_PICKUPS_TAG}"
  265. "wolfcrypt/src/port/arm/armv8-sha3-asm.S:${ASM_PICKUPS_TAG}"
  266. "wolfcrypt/src/port/arm/armv8-sha512-asm_c.c:${ASM_PICKUPS_TAG}"
  267. "wolfcrypt/src/port/arm/armv8-sha512-asm.S:${WOLF_REPO_TAG}"
  268. "wolfcrypt/src/port/arm/armv8-sha512.c:${WOLF_REPO_TAG}"
  269. "wolfcrypt/src/cmac.c:${WOLF_REPO_TAG}"
  270. "wolfcrypt/src/curve25519.c:${WOLF_REPO_TAG}"
  271. "wolfcrypt/src/curve448.c:${WOLF_REPO_TAG}"
  272. "wolfcrypt/src/dh.c:${WOLF_REPO_TAG}"
  273. "wolfcrypt/src/ecc.c:${WOLF_REPO_TAG}"
  274. "wolfcrypt/src/ed25519.c:${WOLF_REPO_TAG}"
  275. "wolfcrypt/src/ed448.c:${WOLF_REPO_TAG}"
  276. "wolfcrypt/src/hmac.c:${WOLF_REPO_TAG}"
  277. "wolfcrypt/src/kdf.c:${WOLF_REPO_TAG}"
  278. "wolfcrypt/src/pwdbased.c:${WOLF_REPO_TAG}"
  279. "wolfcrypt/src/random.c:${WOLF_REPO_TAG}"
  280. "wolfcrypt/src/rsa.c:${WOLF_REPO_TAG}"
  281. "wolfcrypt/src/sha.c:${WOLF_REPO_TAG}"
  282. "wolfcrypt/src/sha256_asm.S:${WOLF_REPO_TAG}"
  283. "wolfcrypt/src/sha256.c:${WOLF_REPO_TAG}"
  284. "wolfcrypt/src/sha3.c:${WOLF_REPO_TAG}"
  285. "wolfcrypt/src/sha3_asm.S:${WOLF_REPO_TAG}"
  286. "wolfcrypt/src/sha512_asm.S:${WOLF_REPO_TAG}"
  287. "wolfcrypt/src/sha512.c:${WOLF_REPO_TAG}"
  288. "wolfcrypt/src/sp_arm32.c:${ASM_PICKUPS_TAG}"
  289. "wolfcrypt/src/sp_arm64.c:${ASM_PICKUPS_TAG}"
  290. "wolfcrypt/src/sp_armthumb.c:${ASM_PICKUPS_TAG}"
  291. "wolfcrypt/src/sp_c32.c:${ASM_PICKUPS_TAG}"
  292. "wolfcrypt/src/sp_c64.c:${ASM_PICKUPS_TAG}"
  293. "wolfcrypt/src/sp_cortexm.c:${ASM_PICKUPS_TAG}"
  294. "wolfcrypt/src/sp_x86_64_asm.asm:${WOLF_REPO_TAG}"
  295. "wolfcrypt/src/sp_x86_64_asm.S:${WOLF_REPO_TAG}"
  296. "wolfcrypt/src/sp_x86_64.c:${ASM_PICKUPS_TAG}"
  297. "wolfcrypt/src/port/arm/thumb2-aes-asm_c.c:${WOLF_REPO_TAG}"
  298. "wolfcrypt/src/port/arm/thumb2-aes-asm.S:${WOLF_REPO_TAG}"
  299. "wolfcrypt/src/port/arm/thumb2-curve25519_c.c:${WOLF_REPO_TAG}"
  300. "wolfcrypt/src/port/arm/thumb2-curve25519.S:${WOLF_REPO_TAG}"
  301. "wolfcrypt/src/port/arm/thumb2-sha256-asm_c.c:${WOLF_REPO_TAG}"
  302. "wolfcrypt/src/port/arm/thumb2-sha256-asm.S:${WOLF_REPO_TAG}"
  303. "wolfcrypt/src/port/arm/thumb2-sha512-asm_c.c:${WOLF_REPO_TAG}"
  304. "wolfcrypt/src/port/arm/thumb2-sha512-asm.S:${WOLF_REPO_TAG}"
  305. "wolfssl/wolfcrypt/aes.h:${WOLF_REPO_TAG}"
  306. "wolfssl/wolfcrypt/cmac.h:${WOLF_REPO_TAG}"
  307. "wolfssl/wolfcrypt/curve25519.h:${WOLF_REPO_TAG}"
  308. "wolfssl/wolfcrypt/curve448.h:${WOLF_REPO_TAG}"
  309. "wolfssl/wolfcrypt/dh.h:${WOLF_REPO_TAG}"
  310. "wolfssl/wolfcrypt/ecc.h:${WOLF_REPO_TAG}"
  311. "wolfssl/wolfcrypt/ed25519.h:${WOLF_REPO_TAG}"
  312. "wolfssl/wolfcrypt/ed448.h:${WOLF_REPO_TAG}"
  313. "wolfssl/wolfcrypt/fips_test.h:${WOLF_REPO_TAG}"
  314. "wolfssl/wolfcrypt/hmac.h:${WOLF_REPO_TAG}"
  315. "wolfssl/wolfcrypt/kdf.h:${WOLF_REPO_TAG}"
  316. "wolfssl/wolfcrypt/pwdbased.h:${WOLF_REPO_TAG}"
  317. "wolfssl/wolfcrypt/random.h:${WOLF_REPO_TAG}"
  318. "wolfssl/wolfcrypt/rsa.h:${WOLF_REPO_TAG}"
  319. "wolfssl/wolfcrypt/sha.h:${WOLF_REPO_TAG}"
  320. "wolfssl/wolfcrypt/sha256.h:${WOLF_REPO_TAG}"
  321. "wolfssl/wolfcrypt/sha3.h:${WOLF_REPO_TAG}"
  322. "wolfssl/wolfcrypt/sha512.h:${WOLF_REPO_TAG}"
  323. )
  324. ;;
  325. fips-ready|fips-dev)
  326. if [ "$FLAVOR" = 'fips-dev' ]; then
  327. FIPS_OPTION='dev'
  328. else
  329. FIPS_OPTION='ready'
  330. fi
  331. FIPS_FILES=(
  332. 'wolfcrypt/src/fips.c:master'
  333. 'wolfcrypt/src/fips_test.c:master'
  334. 'wolfcrypt/src/wolfcrypt_first.c:master'
  335. 'wolfcrypt/src/wolfcrypt_last.c:master'
  336. 'wolfssl/wolfcrypt/fips.h:master'
  337. )
  338. WOLFCRYPT_FILES=()
  339. ;;
  340. wolfrand)
  341. FIPS_OPTION='rand'
  342. FIPS_FILES=(
  343. 'wolfcrypt/src/fips.c:WRv4-stable'
  344. 'wolfcrypt/src/fips_test.c:WRv4-stable'
  345. 'wolfcrypt/src/wolfcrypt_first.c:WRv4-stable'
  346. 'wolfcrypt/src/wolfcrypt_last.c:WRv4-stable'
  347. 'wolfssl/wolfcrypt/fips.h:WRv4-stable'
  348. )
  349. WOLFCRYPT_FILES=(
  350. 'wolfcrypt/src/hmac.c:WCv4-stable'
  351. 'wolfcrypt/src/random.c:WCv4-rng-stable'
  352. 'wolfcrypt/src/sha256.c:WCv4-stable'
  353. 'wolfssl/wolfcrypt/hmac.h:WCv4-stable'
  354. 'wolfssl/wolfcrypt/random.h:WCv4-rng-stable'
  355. 'wolfssl/wolfcrypt/sha256.h:WCv4-stable'
  356. )
  357. ;;
  358. wolfentropy)
  359. FIPS_OPTION='v6'
  360. FIPS_FILES=(
  361. 'wolfcrypt/src/fips.c:wolfEntropy1'
  362. 'wolfcrypt/src/fips_test.c:wolfEntropy1'
  363. 'wolfcrypt/src/wolfcrypt_first.c:wolfEntropy1'
  364. 'wolfcrypt/src/wolfcrypt_last.c:wolfEntropy1'
  365. 'wolfssl/wolfcrypt/fips.h:wolfEntropy1'
  366. )
  367. WOLFCRYPT_FILES=(
  368. 'wolfcrypt/src/aes.c:wolfEntropy1'
  369. 'wolfcrypt/src/aes_asm.asm:wolfEntropy1'
  370. 'wolfcrypt/src/aes_asm.S:wolfEntropy1'
  371. 'wolfcrypt/src/aes_gcm_asm.S:wolfEntropy1'
  372. 'wolfcrypt/src/ecc.c:wolfEntropy1'
  373. 'wolfcrypt/src/hmac.c:wolfEntropy1'
  374. 'wolfcrypt/src/kdf.c:wolfEntropy1'
  375. 'wolfcrypt/src/random.c:wolfEntropy1'
  376. 'wolfcrypt/src/sha256.c:wolfEntropy1'
  377. 'wolfcrypt/src/sha256_asm.S:wolfEntropy1'
  378. 'wolfcrypt/src/sha3.c:wolfEntropy1'
  379. 'wolfcrypt/src/sha512.c:wolfEntropy1'
  380. 'wolfcrypt/src/sha512_asm.S:wolfEntropy1'
  381. 'wolfssl/wolfcrypt/aes.h:wolfEntropy1'
  382. 'wolfssl/wolfcrypt/ecc.h:wolfEntropy1'
  383. 'wolfssl/wolfcrypt/fips_test.h:wolfEntropy1'
  384. 'wolfssl/wolfcrypt/hmac.h:wolfEntropy1'
  385. 'wolfssl/wolfcrypt/kdf.h:wolfEntropy1'
  386. 'wolfssl/wolfcrypt/random.h:wolfEntropy1'
  387. 'wolfssl/wolfcrypt/sha256.h:wolfEntropy1'
  388. 'wolfssl/wolfcrypt/sha3.h:wolfEntropy1'
  389. 'wolfssl/wolfcrypt/sha512.h:wolfEntropy1'
  390. )
  391. ;;
  392. *)
  393. Usage
  394. exit 1
  395. esac
  396. # checkout_files takes an array of pairs of file paths and git tags to
  397. # checkout. It will check to see if mytag exists and if not will make that
  398. # tag a branch.
  399. function checkout_files() {
  400. local name
  401. local tag
  402. for file_entry in "$@"; do
  403. name=${file_entry%%:*}
  404. tag=${file_entry#*:}
  405. if ! $GIT rev-parse -q --verify "my$tag" >/dev/null
  406. then
  407. $GIT branch --no-track "my$tag" "$tag" || exit $?
  408. fi
  409. $GIT checkout "my$tag" -- "$name" || exit $?
  410. done
  411. }
  412. # copy_fips_files takes an array of pairs of file paths and git tags to
  413. # checkout. It will check to see if mytag exists and if now will make that
  414. # tag a branch. It breaks the filepath apart into file name and path, then
  415. # copies it from the file from the fips directory to the path.
  416. function copy_fips_files() {
  417. local name
  418. local bname
  419. local dname
  420. local tag
  421. for file_entry in "$@"; do
  422. name=${file_entry%%:*}
  423. tag=${file_entry#*:}
  424. bname=$(basename "$name")
  425. dname=$(dirname "$name")
  426. if ! $GIT rev-parse -q --verify "my$tag" >/dev/null; then
  427. $GIT branch --no-track "my$tag" "$tag" || exit $?
  428. fi
  429. $GIT checkout "my$tag" -- "$bname" || exit $?
  430. cp "$bname" "../$dname"
  431. done
  432. }
  433. # Note, it would be cleaner to compute the tag lists using associative arrays,
  434. # but those were introduced in bash-4. It's more important to maintain backward
  435. # compatibility here.
  436. declare -a WOLFCRYPT_TAGS_NEEDED_UNSORTED WOLFCRYPT_TAGS_NEEDED
  437. if [ ${#WOLFCRYPT_FILES[@]} -gt 0 ]; then
  438. for file_entry in "${WOLFCRYPT_FILES[@]}"; do
  439. WOLFCRYPT_TAGS_NEEDED_UNSORTED+=("${file_entry#*:}")
  440. done
  441. while IFS= read -r tag; do WOLFCRYPT_TAGS_NEEDED+=("$tag"); done < <(IFS=$'\n'; sort -u <<< "${WOLFCRYPT_TAGS_NEEDED_UNSORTED[*]}")
  442. if [ "${#WOLFCRYPT_TAGS_NEEDED[@]}" = "0" ]; then
  443. echo "Error -- missing wolfCrypt tags." 1>&2
  444. exit 1
  445. fi
  446. fi
  447. declare -a FIPS_TAGS_NEEDED_UNSORTED FIPS_TAGS_NEEDED
  448. for file_entry in "${FIPS_FILES[@]}"; do
  449. FIPS_TAGS_NEEDED_UNSORTED+=("${file_entry#*:}")
  450. done
  451. while IFS= read -r tag; do FIPS_TAGS_NEEDED+=("$tag"); done < <(IFS=$'\n'; sort -u <<< "${FIPS_TAGS_NEEDED_UNSORTED[*]}")
  452. if [ "${#FIPS_TAGS_NEEDED[@]}" = "0" ]; then
  453. echo "Error -- missing FIPS tags." 1>&2
  454. exit 1
  455. fi
  456. if [ ${#WOLFCRYPT_TAGS_NEEDED[@]} -gt 0 ]; then
  457. echo "wolfCrypt tag$( [[ ${#WOLFCRYPT_TAGS_NEEDED[@]} != "1" ]] && echo -n 's'):"
  458. # Only use shallow fetch if the repo already has shallow branches, to avoid
  459. # tainting full repos with shallow objects.
  460. if [ -f .git/shallow ]; then
  461. shallow_args=(--depth 1)
  462. else
  463. shallow_args=()
  464. fi
  465. for tag in "${WOLFCRYPT_TAGS_NEEDED[@]}"; do
  466. if $GIT describe --long --exact-match "$tag" 2>/dev/null; then
  467. continue
  468. fi
  469. if ! $GIT fetch "${shallow_args[@]}" "$WOLFSSL_REPO" tag "$tag"; then
  470. echo "Can't fetch wolfCrypt tag: $tag" 1>&2
  471. exit 1
  472. fi
  473. # Make sure the tag is associated:
  474. $GIT tag "$tag" FETCH_HEAD >/dev/null 2>&1
  475. done
  476. fi
  477. if ! $GIT clone --shared . "$TEST_DIR"; then
  478. echo "fips-check: Couldn't clone current working directory." 1>&2
  479. exit 1
  480. fi
  481. # If there is a FIPS repo under the parent directory, leverage that:
  482. if [ -d ../fips/.git ]; then
  483. pushd ../fips 1>/dev/null || exit 2
  484. # Only use shallow fetch if the repo already has shallow branches, to avoid
  485. # tainting full repos with shallow objects.
  486. if [ -f .git/shallow ]; then
  487. shallow_args=(--depth 1)
  488. else
  489. shallow_args=()
  490. fi
  491. echo "FIPS tag$( [[ ${#FIPS_TAGS_NEEDED[@]} != "1" ]] && echo -n 's'):"
  492. for tag in "${FIPS_TAGS_NEEDED[@]}"; do
  493. if [ "$tag" = "master" ]; then
  494. # master is handled specially below.
  495. continue
  496. fi
  497. if $GIT describe --long --exact-match "$tag" 2>/dev/null; then
  498. continue
  499. fi
  500. if ! $GIT fetch "${shallow_args[@]}" "$FIPS_REPO" tag "$tag"; then
  501. echo "Can't fetch FIPS tag: $tag" 1>&2
  502. exit 1
  503. fi
  504. # Make sure the tag is associated:
  505. $GIT tag "$tag" FETCH_HEAD >/dev/null 2>&1
  506. done
  507. # The current tooling for the FIPS tests is in the master branch and must be
  508. # checked out here.
  509. if ! $GIT clone --shared --branch master . "${TEST_DIR}/fips"; then
  510. echo "fips-check: Couldn't clone current working directory." 1>&2
  511. exit 1
  512. fi
  513. popd 1>/dev/null || exit 2
  514. # Make sure master is up-to-date:
  515. pushd "${TEST_DIR}/fips" 1>/dev/null || exit 2
  516. if ! $GIT pull "$FIPS_REPO" master; then
  517. echo "Can't refresh master FIPS tag" 1>&2
  518. exit 1
  519. fi
  520. popd 1>/dev/null || exit 2
  521. fi
  522. pushd "$TEST_DIR" 1>/dev/null || exit 2
  523. if [ ! -d fips ]; then
  524. # The current tooling for the FIPS tests is in the master branch and must be
  525. # checked out here.
  526. if ! $GIT clone --depth 1 --branch master "$FIPS_REPO" fips; then
  527. echo "fips-check: Couldn't check out FIPS repository."
  528. exit 1
  529. fi
  530. pushd fips 1>/dev/null || exit 2
  531. echo "FIPS tag$( [[ ${#FIPS_TAGS_NEEDED[@]} != "1" ]] && echo -n 's'):"
  532. for tag in "${FIPS_TAGS_NEEDED[@]}"; do
  533. if [ "$tag" = "master" ]; then
  534. # master was just cloned fresh from $FIPS_REPO above.
  535. continue
  536. fi
  537. if $GIT describe --long --exact-match "$tag" 2>/dev/null; then
  538. continue
  539. fi
  540. # The FIPS repo here is an ephemeral clone, so we can safely use shallow
  541. # fetch unconditionally.
  542. if ! $GIT fetch --depth 1 "$FIPS_REPO" tag "$tag"; then
  543. echo "Can't fetch FIPS tag: $tag" 1>&2
  544. exit 1
  545. fi
  546. # Make sure the tag is associated:
  547. $GIT tag "$tag" FETCH_HEAD >/dev/null 2>&1
  548. done
  549. popd 1>/dev/null || exit 2
  550. fi
  551. checkout_files "${WOLFCRYPT_FILES[@]}" || exit 3
  552. pushd fips 1>/dev/null || exit 2
  553. copy_fips_files "${FIPS_FILES[@]}" || exit 3
  554. popd 1>/dev/null || exit 2
  555. # When checking out cert 3389 ready code, NIST will no longer perform
  556. # new certifications on 140-2 modules. If we were to use the latest files from
  557. # master that would require re-cert due to changes in the module boundary.
  558. # Since OE additions can still be processed for cert3389 we will call 140-2
  559. # ready "fipsv2-OE-ready" indicating it is ready to use for an OE addition but
  560. # would not be good for a new certification effort with the latest files.
  561. if [ "$FLAVOR" = 'fipsv2-OE-ready' ] && [ -s wolfcrypt/src/fips.c ]; then
  562. cp wolfcrypt/src/fips.c wolfcrypt/src/fips.c.bak
  563. sed "s/v4.0.0-alpha/fipsv2-OE-ready/" wolfcrypt/src/fips.c.bak >wolfcrypt/src/fips.c
  564. fi
  565. # run the make test
  566. if [ "$DOAUTOGEN" = "yes" ]; then
  567. ./autogen.sh
  568. fi
  569. if [ "$DOCONFIGURE" = "yes" ]; then
  570. case "$FIPS_OPTION" in
  571. cavp-selftest)
  572. ./configure --enable-selftest
  573. ;;
  574. cavp-selftest-v2)
  575. ./configure --enable-selftest=v2
  576. ;;
  577. *)
  578. ./configure --enable-fips=$FIPS_OPTION
  579. ;;
  580. esac
  581. if ! $MAKE; then
  582. echo 'fips-check: Make failed. Debris left for analysis.'
  583. exit 3
  584. fi
  585. if [ -s wolfcrypt/src/fips_test.c ]; then
  586. NEWHASH=$(./wolfcrypt/test/testwolfcrypt | sed -n 's/hash = \(.*\)/\1/p')
  587. if [ -n "$NEWHASH" ]; then
  588. cp wolfcrypt/src/fips_test.c wolfcrypt/src/fips_test.c.bak
  589. sed "s/^\".*\";/\"${NEWHASH}\";/" wolfcrypt/src/fips_test.c.bak >wolfcrypt/src/fips_test.c
  590. make clean
  591. fi
  592. fi
  593. if [ "$MAKECHECK" = "yes" ]; then
  594. if ! $MAKE check; then
  595. echo 'fips-check: Test failed. Debris left for analysis.'
  596. exit 3
  597. fi
  598. fi
  599. fi
  600. # Clean up
  601. popd 1>/dev/null || exit 2
  602. if [ "$KEEP" = 'no' ]; then
  603. rm -rf "$TEST_DIR"
  604. fi