fips-check.sh 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  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. FLAVOR="${FLAVOR:-linux}"
  16. KEEP="${KEEP:-no}"
  17. MAKECHECK=${MAKECHECK:-yes}
  18. DOCONFIGURE=${DOCONFIGURE:-yes}
  19. DOAUTOGEN=${DOAUTOGEN:-yes}
  20. FIPS_REPO="${FIPS_REPO:-git@github.com:wolfssl/fips.git}"
  21. WOLFSSL_REPO="${WOLFSSL_REPO:-origin}"
  22. Usage() {
  23. cat <<usageText
  24. Usage: $0 [flavor] [keep]
  25. Flavor is one of:
  26. linuxv2 (FIPSv2, use for Win10)
  27. fipsv2-OE-ready (ready FIPSv2)
  28. solaris
  29. netbsd-selftest
  30. marvell-linux-selftest
  31. linuxv5 (current FIPS 140-3)
  32. fips-ready (ready FIPS 140-3)
  33. fips-dev (dev FIPS 140-3)
  34. wolfrand
  35. wolfentropy
  36. v6.0.0
  37. Keep (default off) retains the temp dir $TEST_DIR for inspection.
  38. Example:
  39. $0 windows keep
  40. usageText
  41. }
  42. while [ "$1" ]; do
  43. if [ "$1" = 'keep' ]; then KEEP='yes';
  44. elif [ "$1" = 'nomakecheck' ]; then MAKECHECK='no';
  45. elif [ "$1" = 'nodoconfigure' ]; then DOCONFIGURE='no';
  46. elif [ "$1" = 'noautogen' ]; then DOCONFIGURE='no'; DOAUTOGEN='no';
  47. else FLAVOR="$1"; fi
  48. shift
  49. done
  50. case "$FLAVOR" in
  51. linuxv2|fipsv2-OE-ready|solaris)
  52. FIPS_OPTION='v2'
  53. FIPS_FILES=(
  54. 'wolfcrypt/src/fips.c:WCv4-stable'
  55. 'wolfcrypt/src/fips_test.c:WCv4-stable'
  56. 'wolfcrypt/src/wolfcrypt_first.c:WCv4-stable'
  57. 'wolfcrypt/src/wolfcrypt_last.c:WCv4-stable'
  58. 'wolfssl/wolfcrypt/fips.h:WCv4-stable'
  59. )
  60. WOLFCRYPT_FILES=(
  61. 'wolfcrypt/src/aes.c:WCv4-stable'
  62. 'wolfcrypt/src/aes_asm.asm:WCv4-stable'
  63. 'wolfcrypt/src/aes_asm.S:WCv4-stable'
  64. 'wolfcrypt/src/cmac.c:WCv4-stable'
  65. 'wolfcrypt/src/des3.c:WCv4-stable'
  66. 'wolfcrypt/src/dh.c:WCv4-stable'
  67. 'wolfcrypt/src/ecc.c:WCv4-stable'
  68. 'wolfcrypt/src/hmac.c:WCv4-stable'
  69. 'wolfcrypt/src/random.c:WCv4-rng-stable'
  70. 'wolfcrypt/src/rsa.c:WCv4-stable'
  71. 'wolfcrypt/src/sha.c:WCv4-stable'
  72. 'wolfcrypt/src/sha256.c:WCv4-stable'
  73. 'wolfcrypt/src/sha3.c:WCv4-stable'
  74. 'wolfcrypt/src/sha512.c:WCv4-stable'
  75. 'wolfssl/wolfcrypt/aes.h:WCv4-stable'
  76. 'wolfssl/wolfcrypt/cmac.h:WCv4-stable'
  77. 'wolfssl/wolfcrypt/des3.h:WCv4-stable'
  78. 'wolfssl/wolfcrypt/dh.h:WCv4-stable'
  79. 'wolfssl/wolfcrypt/ecc.h:WCv4-stable'
  80. 'wolfssl/wolfcrypt/hmac.h:WCv4-stable'
  81. 'wolfssl/wolfcrypt/random.h:WCv4-rng-stable'
  82. 'wolfssl/wolfcrypt/rsa.h:WCv4-stable'
  83. 'wolfssl/wolfcrypt/sha.h:WCv4-stable'
  84. 'wolfssl/wolfcrypt/sha256.h:WCv4-stable'
  85. 'wolfssl/wolfcrypt/sha3.h:WCv4-stable'
  86. 'wolfssl/wolfcrypt/sha512.h:WCv4-stable'
  87. )
  88. if [ "$FLAVOR" = 'solaris' ]; then MAKE='gmake'; fi
  89. ;;
  90. netbsd-selftest)
  91. # non-FIPS, CAVP only but pull in selftest
  92. FIPS_OPTION='cavp-selftest'
  93. FIPS_FILES=('wolfcrypt/src/selftest.c:v3.14.2b')
  94. WOLFCRYPT_FILES=(
  95. 'wolfcrypt/src/aes.c:v3.14.2'
  96. 'wolfcrypt/src/dh.c:v3.14.2'
  97. 'wolfcrypt/src/dsa.c:v3.14.2'
  98. 'wolfcrypt/src/ecc.c:v3.14.2'
  99. 'wolfcrypt/src/hmac.c:v3.14.2'
  100. 'wolfcrypt/src/random.c:v3.14.2'
  101. 'wolfcrypt/src/rsa.c:v3.14.2'
  102. 'wolfcrypt/src/sha.c:v3.14.2'
  103. 'wolfcrypt/src/sha256.c:v3.14.2'
  104. 'wolfcrypt/src/sha512.c:v3.14.2'
  105. 'wolfssl/wolfcrypt/aes.h:v3.14.2'
  106. 'wolfssl/wolfcrypt/dh.h:v3.14.2'
  107. 'wolfssl/wolfcrypt/dsa.h:v3.14.2'
  108. 'wolfssl/wolfcrypt/ecc.h:v3.14.2'
  109. 'wolfssl/wolfcrypt/hmac.h:v3.14.2'
  110. 'wolfssl/wolfcrypt/random.h:v3.14.2'
  111. 'wolfssl/wolfcrypt/rsa.h:v3.14.2'
  112. 'wolfssl/wolfcrypt/sha.h:v3.14.2'
  113. 'wolfssl/wolfcrypt/sha256.h:v3.14.2'
  114. 'wolfssl/wolfcrypt/sha512.h:v3.14.2'
  115. )
  116. ;;
  117. marvell-linux-selftest)
  118. # non-FIPS, CAVP only but pull in selftest
  119. FIPS_OPTION='cavp-selftest-v2'
  120. FIPS_FILES=('wolfcrypt/src/selftest.c:v3.14.2b')
  121. WOLFCRYPT_FILES=(
  122. 'wolfcrypt/src/aes.c:v4.1.0-stable'
  123. 'wolfcrypt/src/dh.c:v4.1.0-stable'
  124. 'wolfcrypt/src/dsa.c:v4.1.0-stable'
  125. 'wolfcrypt/src/ecc.c:v4.1.0-stable'
  126. 'wolfcrypt/src/hmac.c:v4.1.0-stable'
  127. 'wolfcrypt/src/random.c:v4.1.0-stable'
  128. 'wolfcrypt/src/rsa.c:v4.1.0-stable'
  129. 'wolfcrypt/src/sha.c:v4.1.0-stable'
  130. 'wolfcrypt/src/sha256.c:v4.1.0-stable'
  131. 'wolfcrypt/src/sha512.c:v4.1.0-stable'
  132. 'wolfssl/wolfcrypt/aes.h:v4.1.0-stable'
  133. 'wolfssl/wolfcrypt/dh.h:v4.1.0-stable'
  134. 'wolfssl/wolfcrypt/dsa.h:v4.1.0-stable'
  135. 'wolfssl/wolfcrypt/ecc.h:v4.1.0-stable'
  136. 'wolfssl/wolfcrypt/hmac.h:v4.1.0-stable'
  137. 'wolfssl/wolfcrypt/random.h:v4.1.0-stable'
  138. 'wolfssl/wolfcrypt/rsa.h:v4.1.0-stable'
  139. 'wolfssl/wolfcrypt/sha.h:v4.1.0-stable'
  140. 'wolfssl/wolfcrypt/sha256.h:v4.1.0-stable'
  141. 'wolfssl/wolfcrypt/sha512.h:v4.1.0-stable'
  142. )
  143. ;;
  144. linuxv5-RC12)
  145. FIPS_OPTION='v5-RC12'
  146. FIPS_FILES=(
  147. 'wolfcrypt/src/fips.c:WCv5.2.0.1-RC01'
  148. 'wolfcrypt/src/fips_test.c:WCv5.0-RC12'
  149. 'wolfcrypt/src/wolfcrypt_first.c:WCv5.0-RC12'
  150. 'wolfcrypt/src/wolfcrypt_last.c:WCv5.0-RC12'
  151. 'wolfssl/wolfcrypt/fips.h:WCv5.0-RC12'
  152. )
  153. WOLFCRYPT_FILES=(
  154. 'wolfcrypt/src/aes.c:WCv5.0-RC12'
  155. 'wolfcrypt/src/aes_asm.asm:WCv5.0-RC12'
  156. 'wolfcrypt/src/aes_asm.S:WCv5.0-RC12'
  157. 'wolfcrypt/src/aes_gcm_asm.S:WCv5.0-RC12'
  158. 'wolfcrypt/src/cmac.c:WCv5.0-RC12'
  159. 'wolfcrypt/src/dh.c:WCv5.0-RC12'
  160. 'wolfcrypt/src/ecc.c:WCv5.0-RC12'
  161. 'wolfcrypt/src/hmac.c:WCv5.0-RC12'
  162. 'wolfcrypt/src/kdf.c:WCv5.0-RC12'
  163. 'wolfcrypt/src/random.c:WCv5.0-RC12'
  164. 'wolfcrypt/src/rsa.c:WCv5.0-RC12'
  165. 'wolfcrypt/src/sha.c:WCv5.0-RC12'
  166. 'wolfcrypt/src/sha256.c:WCv5.0-RC12'
  167. 'wolfcrypt/src/sha256_asm.S:WCv5.0-RC12'
  168. 'wolfcrypt/src/sha3.c:WCv5.0-RC12'
  169. 'wolfcrypt/src/sha512.c:WCv5.0-RC12'
  170. 'wolfcrypt/src/sha512_asm.S:WCv5.0-RC12'
  171. 'wolfssl/wolfcrypt/aes.h:WCv5.0-RC12'
  172. 'wolfssl/wolfcrypt/cmac.h:WCv5.0-RC12'
  173. 'wolfssl/wolfcrypt/dh.h:WCv5.0-RC12'
  174. 'wolfssl/wolfcrypt/ecc.h:WCv5.0-RC12'
  175. 'wolfssl/wolfcrypt/fips_test.h:WCv5.0-RC12'
  176. 'wolfssl/wolfcrypt/hmac.h:WCv5.0-RC12'
  177. 'wolfssl/wolfcrypt/kdf.h:WCv5.0-RC12'
  178. 'wolfssl/wolfcrypt/random.h:WCv5.0-RC12'
  179. 'wolfssl/wolfcrypt/rsa.h:WCv5.0-RC12'
  180. 'wolfssl/wolfcrypt/sha.h:WCv5.0-RC12'
  181. 'wolfssl/wolfcrypt/sha256.h:WCv5.0-RC12'
  182. 'wolfssl/wolfcrypt/sha3.h:WCv5.0-RC12'
  183. 'wolfssl/wolfcrypt/sha512.h:WCv5.0-RC12'
  184. )
  185. ;;
  186. linuxv5|linuxv5.2.1)
  187. FIPS_OPTION='v5'
  188. FIPS_FILES=(
  189. 'wolfcrypt/src/fips.c:v5.2.1-stable'
  190. 'wolfcrypt/src/fips_test.c:v5.2.1-stable'
  191. 'wolfcrypt/src/wolfcrypt_first.c:v5.2.1-stable'
  192. 'wolfcrypt/src/wolfcrypt_last.c:v5.2.1-stable'
  193. 'wolfssl/wolfcrypt/fips.h:v5.2.1-stable-OS_Seed-HdrOnly'
  194. )
  195. WOLFCRYPT_FILES=(
  196. 'wolfcrypt/src/aes.c:v5.2.1-stable'
  197. 'wolfcrypt/src/aes_asm.asm:v5.2.1-stable'
  198. 'wolfcrypt/src/aes_asm.S:v5.2.1-stable'
  199. 'wolfcrypt/src/aes_gcm_asm.S:v5.2.1-stable'
  200. 'wolfcrypt/src/cmac.c:v5.2.1-stable'
  201. 'wolfcrypt/src/dh.c:v5.2.1-stable'
  202. 'wolfcrypt/src/ecc.c:v5.2.1-stable'
  203. 'wolfcrypt/src/hmac.c:v5.2.1-stable'
  204. 'wolfcrypt/src/kdf.c:v5.2.1-stable'
  205. 'wolfcrypt/src/random.c:v5.2.1-stable'
  206. 'wolfcrypt/src/rsa.c:v5.2.1-stable'
  207. 'wolfcrypt/src/sha.c:v5.2.1-stable'
  208. 'wolfcrypt/src/sha256.c:v5.2.1-stable'
  209. 'wolfcrypt/src/sha256_asm.S:v5.2.1-stable'
  210. 'wolfcrypt/src/sha3.c:v5.2.1-stable'
  211. 'wolfcrypt/src/sha512.c:v5.2.1-stable'
  212. 'wolfcrypt/src/sha512_asm.S:v5.2.1-stable'
  213. 'wolfssl/wolfcrypt/aes.h:v5.2.1-stable'
  214. 'wolfssl/wolfcrypt/cmac.h:v5.2.1-stable'
  215. 'wolfssl/wolfcrypt/dh.h:v5.2.1-stable'
  216. 'wolfssl/wolfcrypt/ecc.h:v5.2.1-stable'
  217. 'wolfssl/wolfcrypt/fips_test.h:v5.2.1-stable'
  218. 'wolfssl/wolfcrypt/hmac.h:v5.2.1-stable'
  219. 'wolfssl/wolfcrypt/kdf.h:v5.2.1-stable'
  220. 'wolfssl/wolfcrypt/random.h:v5.2.1-stable-OS_Seed-HdrOnly'
  221. 'wolfssl/wolfcrypt/rsa.h:v5.2.1-stable'
  222. 'wolfssl/wolfcrypt/sha.h:v5.2.1-stable'
  223. 'wolfssl/wolfcrypt/sha256.h:v5.2.1-stable'
  224. 'wolfssl/wolfcrypt/sha3.h:v5.2.1-stable'
  225. 'wolfssl/wolfcrypt/sha512.h:v5.2.1-stable'
  226. )
  227. ;;
  228. v6.0.0)
  229. WOLF_REPO_TAG='WCv6.0.0-RC1'
  230. FIPS_REPO_TAG='WCv6.0.0-RC1'
  231. ASM_PICKUPS_TAG='WCv6.0.0-RC2'
  232. FIPS_OPTION='v6'
  233. FIPS_FILES=(
  234. "wolfcrypt/src/fips.c:${FIPS_REPO_TAG}"
  235. "wolfcrypt/src/fips_test.c:${FIPS_REPO_TAG}"
  236. "wolfcrypt/src/wolfcrypt_first.c:${FIPS_REPO_TAG}"
  237. "wolfcrypt/src/wolfcrypt_last.c:${FIPS_REPO_TAG}"
  238. "wolfssl/wolfcrypt/fips.h:${FIPS_REPO_TAG}"
  239. )
  240. WOLFCRYPT_FILES=(
  241. "wolfcrypt/src/aes_asm.asm:${WOLF_REPO_TAG}"
  242. "wolfcrypt/src/aes_asm.S:${WOLF_REPO_TAG}"
  243. "wolfcrypt/src/aes_gcm_asm.S:${WOLF_REPO_TAG}"
  244. "wolfcrypt/src/aes_gcm_x86_asm.S:${WOLF_REPO_TAG}"
  245. "wolfcrypt/src/aes_xts_asm.S:${WOLF_REPO_TAG}"
  246. "wolfcrypt/src/aes.c:${WOLF_REPO_TAG}"
  247. "wolfcrypt/src/port/arm/armv8-32-aes-asm_c.c:${ASM_PICKUPS_TAG}"
  248. "wolfcrypt/src/port/arm/armv8-32-aes-asm.S:${WOLF_REPO_TAG}"
  249. "wolfcrypt/src/port/arm/armv8-32-curve25519_c.c:${ASM_PICKUPS_TAG}"
  250. "wolfcrypt/src/port/arm/armv8-32-curve25519.S:${WOLF_REPO_TAG}"
  251. "wolfcrypt/src/port/arm/armv8-32-sha256-asm_c.c:${ASM_PICKUPS_TAG}"
  252. "wolfcrypt/src/port/arm/armv8-32-sha256-asm.S:${WOLF_REPO_TAG}"
  253. "wolfcrypt/src/port/arm/armv8-32-sha512-asm_c.c:${ASM_PICKUPS_TAG}"
  254. "wolfcrypt/src/port/arm/armv8-32-sha512-asm.S:${WOLF_REPO_TAG}"
  255. "wolfcrypt/src/port/arm/armv8-aes.c:${ASM_PICKUPS_TAG}"
  256. "wolfcrypt/src/port/arm/armv8-curve25519_c.c:${ASM_PICKUPS_TAG}"
  257. "wolfcrypt/src/port/arm/armv8-curve25519.S:${WOLF_REPO_TAG}"
  258. "wolfcrypt/src/port/arm/armv8-sha256.c:${WOLF_REPO_TAG}"
  259. "wolfcrypt/src/port/arm/armv8-sha3-asm_c.c:${ASM_PICKUPS_TAG}"
  260. "wolfcrypt/src/port/arm/armv8-sha3-asm.S:${ASM_PICKUPS_TAG}"
  261. "wolfcrypt/src/port/arm/armv8-sha512-asm_c.c:${ASM_PICKUPS_TAG}"
  262. "wolfcrypt/src/port/arm/armv8-sha512-asm.S:${WOLF_REPO_TAG}"
  263. "wolfcrypt/src/port/arm/armv8-sha512.c:${WOLF_REPO_TAG}"
  264. "wolfcrypt/src/cmac.c:${WOLF_REPO_TAG}"
  265. "wolfcrypt/src/curve25519.c:${WOLF_REPO_TAG}"
  266. "wolfcrypt/src/curve448.c:${WOLF_REPO_TAG}"
  267. "wolfcrypt/src/dh.c:${WOLF_REPO_TAG}"
  268. "wolfcrypt/src/ecc.c:${WOLF_REPO_TAG}"
  269. "wolfcrypt/src/ed25519.c:${WOLF_REPO_TAG}"
  270. "wolfcrypt/src/ed448.c:${WOLF_REPO_TAG}"
  271. "wolfcrypt/src/hmac.c:${WOLF_REPO_TAG}"
  272. "wolfcrypt/src/kdf.c:${WOLF_REPO_TAG}"
  273. "wolfcrypt/src/pwdbased.c:${WOLF_REPO_TAG}"
  274. "wolfcrypt/src/random.c:${WOLF_REPO_TAG}"
  275. "wolfcrypt/src/rsa.c:${WOLF_REPO_TAG}"
  276. "wolfcrypt/src/sha.c:${WOLF_REPO_TAG}"
  277. "wolfcrypt/src/sha256_asm.S:${WOLF_REPO_TAG}"
  278. "wolfcrypt/src/sha256.c:${WOLF_REPO_TAG}"
  279. "wolfcrypt/src/sha3.c:${WOLF_REPO_TAG}"
  280. "wolfcrypt/src/sha3_asm.S:${WOLF_REPO_TAG}"
  281. "wolfcrypt/src/sha512_asm.S:${WOLF_REPO_TAG}"
  282. "wolfcrypt/src/sha512.c:${WOLF_REPO_TAG}"
  283. "wolfcrypt/src/sp_arm32.c:${ASM_PICKUPS_TAG}"
  284. "wolfcrypt/src/sp_arm64.c:${ASM_PICKUPS_TAG}"
  285. "wolfcrypt/src/sp_armthumb.c:${ASM_PICKUPS_TAG}"
  286. "wolfcrypt/src/sp_c32.c:${ASM_PICKUPS_TAG}"
  287. "wolfcrypt/src/sp_c64.c:${ASM_PICKUPS_TAG}"
  288. "wolfcrypt/src/sp_cortexm.c:${ASM_PICKUPS_TAG}"
  289. "wolfcrypt/src/sp_x86_64_asm.asm:${WOLF_REPO_TAG}"
  290. "wolfcrypt/src/sp_x86_64_asm.S:${WOLF_REPO_TAG}"
  291. "wolfcrypt/src/sp_x86_64.c:${ASM_PICKUPS_TAG}"
  292. "wolfcrypt/src/port/arm/thumb2-aes-asm_c.c:${WOLF_REPO_TAG}"
  293. "wolfcrypt/src/port/arm/thumb2-aes-asm.S:${WOLF_REPO_TAG}"
  294. "wolfcrypt/src/port/arm/thumb2-curve25519_c.c:${WOLF_REPO_TAG}"
  295. "wolfcrypt/src/port/arm/thumb2-curve25519.S:${WOLF_REPO_TAG}"
  296. "wolfcrypt/src/port/arm/thumb2-sha256-asm_c.c:${WOLF_REPO_TAG}"
  297. "wolfcrypt/src/port/arm/thumb2-sha256-asm.S:${WOLF_REPO_TAG}"
  298. "wolfcrypt/src/port/arm/thumb2-sha512-asm_c.c:${WOLF_REPO_TAG}"
  299. "wolfcrypt/src/port/arm/thumb2-sha512-asm.S:${WOLF_REPO_TAG}"
  300. "wolfssl/wolfcrypt/aes.h:${WOLF_REPO_TAG}"
  301. "wolfssl/wolfcrypt/cmac.h:${WOLF_REPO_TAG}"
  302. "wolfssl/wolfcrypt/curve25519.h:${WOLF_REPO_TAG}"
  303. "wolfssl/wolfcrypt/curve448.h:${WOLF_REPO_TAG}"
  304. "wolfssl/wolfcrypt/dh.h:${WOLF_REPO_TAG}"
  305. "wolfssl/wolfcrypt/ecc.h:${WOLF_REPO_TAG}"
  306. "wolfssl/wolfcrypt/ed25519.h:${WOLF_REPO_TAG}"
  307. "wolfssl/wolfcrypt/ed448.h:${WOLF_REPO_TAG}"
  308. "wolfssl/wolfcrypt/fips_test.h:${WOLF_REPO_TAG}"
  309. "wolfssl/wolfcrypt/hmac.h:${WOLF_REPO_TAG}"
  310. "wolfssl/wolfcrypt/kdf.h:${WOLF_REPO_TAG}"
  311. "wolfssl/wolfcrypt/pwdbased.h:${WOLF_REPO_TAG}"
  312. "wolfssl/wolfcrypt/random.h:${WOLF_REPO_TAG}"
  313. "wolfssl/wolfcrypt/rsa.h:${WOLF_REPO_TAG}"
  314. "wolfssl/wolfcrypt/sha.h:${WOLF_REPO_TAG}"
  315. "wolfssl/wolfcrypt/sha256.h:${WOLF_REPO_TAG}"
  316. "wolfssl/wolfcrypt/sha3.h:${WOLF_REPO_TAG}"
  317. "wolfssl/wolfcrypt/sha512.h:${WOLF_REPO_TAG}"
  318. )
  319. ;;
  320. fips-ready|fips-dev)
  321. if [ "$FLAVOR" = 'fips-dev' ]; then
  322. FIPS_OPTION='dev'
  323. else
  324. FIPS_OPTION='ready'
  325. fi
  326. FIPS_FILES=(
  327. 'wolfcrypt/src/fips.c:master'
  328. 'wolfcrypt/src/fips_test.c:master'
  329. 'wolfcrypt/src/wolfcrypt_first.c:master'
  330. 'wolfcrypt/src/wolfcrypt_last.c:master'
  331. 'wolfssl/wolfcrypt/fips.h:master'
  332. )
  333. WOLFCRYPT_FILES=()
  334. ;;
  335. wolfrand)
  336. FIPS_OPTION='rand'
  337. FIPS_FILES=(
  338. 'wolfcrypt/src/fips.c:WRv4-stable'
  339. 'wolfcrypt/src/fips_test.c:WRv4-stable'
  340. 'wolfcrypt/src/wolfcrypt_first.c:WRv4-stable'
  341. 'wolfcrypt/src/wolfcrypt_last.c:WRv4-stable'
  342. 'wolfssl/wolfcrypt/fips.h:WRv4-stable'
  343. )
  344. WOLFCRYPT_FILES=(
  345. 'wolfcrypt/src/hmac.c:WCv4-stable'
  346. 'wolfcrypt/src/random.c:WCv4-rng-stable'
  347. 'wolfcrypt/src/sha256.c:WCv4-stable'
  348. 'wolfssl/wolfcrypt/hmac.h:WCv4-stable'
  349. 'wolfssl/wolfcrypt/random.h:WCv4-rng-stable'
  350. 'wolfssl/wolfcrypt/sha256.h:WCv4-stable'
  351. )
  352. ;;
  353. wolfentropy)
  354. FIPS_OPTION='v6'
  355. FIPS_FILES=(
  356. 'wolfcrypt/src/fips.c:wolfEntropy1'
  357. 'wolfcrypt/src/fips_test.c:wolfEntropy1'
  358. 'wolfcrypt/src/wolfcrypt_first.c:wolfEntropy1'
  359. 'wolfcrypt/src/wolfcrypt_last.c:wolfEntropy1'
  360. 'wolfssl/wolfcrypt/fips.h:wolfEntropy1'
  361. )
  362. WOLFCRYPT_FILES=(
  363. 'wolfcrypt/src/aes.c:wolfEntropy1'
  364. 'wolfcrypt/src/aes_asm.asm:wolfEntropy1'
  365. 'wolfcrypt/src/aes_asm.S:wolfEntropy1'
  366. 'wolfcrypt/src/aes_gcm_asm.S:wolfEntropy1'
  367. 'wolfcrypt/src/ecc.c:wolfEntropy1'
  368. 'wolfcrypt/src/hmac.c:wolfEntropy1'
  369. 'wolfcrypt/src/kdf.c:wolfEntropy1'
  370. 'wolfcrypt/src/random.c:wolfEntropy1'
  371. 'wolfcrypt/src/sha256.c:wolfEntropy1'
  372. 'wolfcrypt/src/sha256_asm.S:wolfEntropy1'
  373. 'wolfcrypt/src/sha3.c:wolfEntropy1'
  374. 'wolfcrypt/src/sha512.c:wolfEntropy1'
  375. 'wolfcrypt/src/sha512_asm.S:wolfEntropy1'
  376. 'wolfssl/wolfcrypt/aes.h:wolfEntropy1'
  377. 'wolfssl/wolfcrypt/ecc.h:wolfEntropy1'
  378. 'wolfssl/wolfcrypt/fips_test.h:wolfEntropy1'
  379. 'wolfssl/wolfcrypt/hmac.h:wolfEntropy1'
  380. 'wolfssl/wolfcrypt/kdf.h:wolfEntropy1'
  381. 'wolfssl/wolfcrypt/random.h:wolfEntropy1'
  382. 'wolfssl/wolfcrypt/sha256.h:wolfEntropy1'
  383. 'wolfssl/wolfcrypt/sha3.h:wolfEntropy1'
  384. 'wolfssl/wolfcrypt/sha512.h:wolfEntropy1'
  385. )
  386. ;;
  387. *)
  388. Usage
  389. exit 1
  390. esac
  391. # checkout_files takes an array of pairs of file paths and git tags to
  392. # checkout. It will check to see if mytag exists and if not will make that
  393. # tag a branch.
  394. function checkout_files() {
  395. local name
  396. local tag
  397. for file_entry in "$@"; do
  398. name=${file_entry%%:*}
  399. tag=${file_entry#*:}
  400. if ! $GIT rev-parse -q --verify "my$tag" >/dev/null
  401. then
  402. $GIT branch --no-track "my$tag" "$tag" || exit $?
  403. fi
  404. $GIT checkout "my$tag" -- "$name" || exit $?
  405. done
  406. }
  407. # copy_fips_files takes an array of pairs of file paths and git tags to
  408. # checkout. It will check to see if mytag exists and if now will make that
  409. # tag a branch. It breaks the filepath apart into file name and path, then
  410. # copies it from the file from the fips directory to the path.
  411. function copy_fips_files() {
  412. local name
  413. local bname
  414. local dname
  415. local tag
  416. for file_entry in "$@"; do
  417. name=${file_entry%%:*}
  418. tag=${file_entry#*:}
  419. bname=$(basename "$name")
  420. dname=$(dirname "$name")
  421. if ! $GIT rev-parse -q --verify "my$tag" >/dev/null; then
  422. $GIT branch --no-track "my$tag" "$tag" || exit $?
  423. fi
  424. $GIT checkout "my$tag" -- "$bname" || exit $?
  425. cp "$bname" "../$dname"
  426. done
  427. }
  428. declare -A FIPS_TAGS_NEEDED WOLFCRYPT_TAGS_NEEDED
  429. for file_entry in "${WOLFCRYPT_FILES[@]}"; do
  430. WOLFCRYPT_TAGS_NEEDED["${file_entry#*:}"]=1
  431. done
  432. for file_entry in "${FIPS_FILES[@]}"; do
  433. FIPS_TAGS_NEEDED["${file_entry#*:}"]=1
  434. done
  435. echo "wolfCrypt tag$( [[ ${#WOLFCRYPT_TAGS_NEEDED[@]} != "1" ]] && echo -n 's'):"
  436. for tag in "${!WOLFCRYPT_TAGS_NEEDED[@]}"; do
  437. if $GIT describe --exact-match --long "$tag" 2>/dev/null; then
  438. continue
  439. fi
  440. if ! $GIT fetch --depth 1 "$WOLFSSL_REPO" tag "$tag"; then
  441. echo "Can't fetch wolfCrypt tag: $tag"
  442. exit 1
  443. fi
  444. done
  445. if ! $GIT clone . "$TEST_DIR"; then
  446. echo "fips-check: Couldn't duplicate current working directory."
  447. exit 1
  448. fi
  449. pushd "$TEST_DIR" 1>/dev/null || exit 2
  450. if ! $GIT clone "$FIPS_REPO" fips; then
  451. echo "fips-check: Couldn't check out FIPS repository."
  452. exit 1
  453. fi
  454. pushd fips 1>/dev/null || exit 2
  455. echo "FIPS tag$( [[ ${#FIPS_TAGS_NEEDED[@]} != "1" ]] && echo -n 's'):"
  456. for tag in "${!FIPS_TAGS_NEEDED[@]}"; do
  457. if $GIT describe "$tag" 2>/dev/null; then
  458. continue
  459. fi
  460. if ! $GIT fetch --depth 1 "$FIPS_REPO" tag "$tag"; then
  461. echo "Can't fetch FIPS tag: $tag"
  462. exit 1
  463. fi
  464. done
  465. popd 1>/dev/null || exit 2
  466. checkout_files "${WOLFCRYPT_FILES[@]}" || exit 3
  467. pushd fips 1>/dev/null || exit 2
  468. copy_fips_files "${FIPS_FILES[@]}" || exit 3
  469. popd 1>/dev/null || exit 2
  470. # When checking out cert 3389 ready code, NIST will no longer perform
  471. # new certifications on 140-2 modules. If we were to use the latest files from
  472. # master that would require re-cert due to changes in the module boundary.
  473. # Since OE additions can still be processed for cert3389 we will call 140-2
  474. # ready "fipsv2-OE-ready" indicating it is ready to use for an OE addition but
  475. # would not be good for a new certification effort with the latest files.
  476. if [ "$FLAVOR" = 'fipsv2-OE-ready' ] && [ -s wolfcrypt/src/fips.c ]; then
  477. cp wolfcrypt/src/fips.c wolfcrypt/src/fips.c.bak
  478. sed "s/v4.0.0-alpha/fipsv2-OE-ready/" wolfcrypt/src/fips.c.bak >wolfcrypt/src/fips.c
  479. fi
  480. # run the make test
  481. if [ "$DOAUTOGEN" = "yes" ]; then
  482. ./autogen.sh
  483. fi
  484. if [ "$DOCONFIGURE" = "yes" ]; then
  485. case "$FIPS_OPTION" in
  486. cavp-selftest)
  487. ./configure --enable-selftest
  488. ;;
  489. cavp-selftest-v2)
  490. ./configure --enable-selftest=v2
  491. ;;
  492. *)
  493. ./configure --enable-fips=$FIPS_OPTION
  494. ;;
  495. esac
  496. if ! $MAKE; then
  497. echo 'fips-check: Make failed. Debris left for analysis.'
  498. exit 3
  499. fi
  500. if [ -s wolfcrypt/src/fips_test.c ]; then
  501. NEWHASH=$(./wolfcrypt/test/testwolfcrypt | sed -n 's/hash = \(.*\)/\1/p')
  502. if [ -n "$NEWHASH" ]; then
  503. cp wolfcrypt/src/fips_test.c wolfcrypt/src/fips_test.c.bak
  504. sed "s/^\".*\";/\"${NEWHASH}\";/" wolfcrypt/src/fips_test.c.bak >wolfcrypt/src/fips_test.c
  505. make clean
  506. fi
  507. fi
  508. if [ "$MAKECHECK" = "yes" ]; then
  509. if ! $MAKE check; then
  510. echo 'fips-check: Test failed. Debris left for analysis.'
  511. exit 3
  512. fi
  513. fi
  514. fi
  515. # Clean up
  516. popd 1>/dev/null || exit 2
  517. if [ "$KEEP" = 'no' ]; then
  518. rm -rf "$TEST_DIR"
  519. fi