all.sh 182 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379
  1. #! /usr/bin/env bash
  2. # all.sh
  3. #
  4. # Copyright The Mbed TLS Contributors
  5. # SPDX-License-Identifier: Apache-2.0
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  8. # not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. ################################################################
  19. #### Documentation
  20. ################################################################
  21. # Purpose
  22. # -------
  23. #
  24. # To run all tests possible or available on the platform.
  25. #
  26. # Notes for users
  27. # ---------------
  28. #
  29. # Warning: the test is destructive. It includes various build modes and
  30. # configurations, and can and will arbitrarily change the current CMake
  31. # configuration. The following files must be committed into git:
  32. # * include/mbedtls/mbedtls_config.h
  33. # * Makefile, library/Makefile, programs/Makefile, tests/Makefile,
  34. # programs/fuzz/Makefile
  35. # After running this script, the CMake cache will be lost and CMake
  36. # will no longer be initialised.
  37. #
  38. # The script assumes the presence of a number of tools:
  39. # * Basic Unix tools (Windows users note: a Unix-style find must be before
  40. # the Windows find in the PATH)
  41. # * Perl
  42. # * GNU Make
  43. # * CMake
  44. # * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
  45. # * G++
  46. # * arm-gcc and mingw-gcc
  47. # * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
  48. # * OpenSSL and GnuTLS command line tools, recent enough for the
  49. # interoperability tests. If they don't support old features which we want
  50. # to test, then a legacy version of these tools must be present as well
  51. # (search for LEGACY below).
  52. # See the invocation of check_tools below for details.
  53. #
  54. # This script must be invoked from the toplevel directory of a git
  55. # working copy of Mbed TLS.
  56. #
  57. # The behavior on an error depends on whether --keep-going (alias -k)
  58. # is in effect.
  59. # * Without --keep-going: the script stops on the first error without
  60. # cleaning up. This lets you work in the configuration of the failing
  61. # component.
  62. # * With --keep-going: the script runs all requested components and
  63. # reports failures at the end. In particular the script always cleans
  64. # up on exit.
  65. #
  66. # Note that the output is not saved. You may want to run
  67. # script -c tests/scripts/all.sh
  68. # or
  69. # tests/scripts/all.sh >all.log 2>&1
  70. #
  71. # Notes for maintainers
  72. # ---------------------
  73. #
  74. # The bulk of the code is organized into functions that follow one of the
  75. # following naming conventions:
  76. # * pre_XXX: things to do before running the tests, in order.
  77. # * component_XXX: independent components. They can be run in any order.
  78. # * component_check_XXX: quick tests that aren't worth parallelizing.
  79. # * component_build_XXX: build things but don't run them.
  80. # * component_test_XXX: build and test.
  81. # * support_XXX: if support_XXX exists and returns false then
  82. # component_XXX is not run by default.
  83. # * post_XXX: things to do after running the tests.
  84. # * other: miscellaneous support functions.
  85. #
  86. # Each component must start by invoking `msg` with a short informative message.
  87. #
  88. # Warning: due to the way bash detects errors, the failure of a command
  89. # inside 'if' or '!' is not detected. Use the 'not' function instead of '!'.
  90. #
  91. # Each component is executed in a separate shell process. The component
  92. # fails if any command in it returns a non-zero status.
  93. #
  94. # The framework performs some cleanup tasks after each component. This
  95. # means that components can assume that the working directory is in a
  96. # cleaned-up state, and don't need to perform the cleanup themselves.
  97. # * Run `make clean`.
  98. # * Restore `include/mbedtls/mbedtls_config.h` from a backup made before running
  99. # the component.
  100. # * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
  101. # `tests/Makefile` and `programs/fuzz/Makefile` from git.
  102. # This cleans up after an in-tree use of CMake.
  103. #
  104. # The tests are roughly in order from fastest to slowest. This doesn't
  105. # have to be exact, but in general you should add slower tests towards
  106. # the end and fast checks near the beginning.
  107. ################################################################
  108. #### Initialization and command line parsing
  109. ################################################################
  110. # Abort on errors (even on the left-hand side of a pipe).
  111. # Treat uninitialised variables as errors.
  112. set -e -o pipefail -u
  113. # Enable ksh/bash extended file matching patterns
  114. shopt -s extglob
  115. pre_check_environment () {
  116. if [ -d library -a -d include -a -d tests ]; then :; else
  117. echo "Must be run from mbed TLS root" >&2
  118. exit 1
  119. fi
  120. }
  121. pre_initialize_variables () {
  122. CONFIG_H='include/mbedtls/mbedtls_config.h'
  123. CRYPTO_CONFIG_H='include/psa/crypto_config.h'
  124. CONFIG_TEST_DRIVER_H='tests/include/test/drivers/config_test_driver.h'
  125. # Files that are clobbered by some jobs will be backed up. Use a different
  126. # suffix from auxiliary scripts so that all.sh and auxiliary scripts can
  127. # independently decide when to remove the backup file.
  128. backup_suffix='.all.bak'
  129. # Files clobbered by config.py
  130. files_to_back_up="$CONFIG_H $CRYPTO_CONFIG_H $CONFIG_TEST_DRIVER_H"
  131. # Files clobbered by in-tree cmake
  132. files_to_back_up="$files_to_back_up Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile"
  133. append_outcome=0
  134. MEMORY=0
  135. FORCE=0
  136. QUIET=0
  137. KEEP_GOING=0
  138. # Seed value used with the --release-test option.
  139. #
  140. # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
  141. # both values are kept in sync. If you change the value here because it
  142. # breaks some tests, you'll definitely want to change it in
  143. # basic-build-test.sh as well.
  144. RELEASE_SEED=1
  145. : ${MBEDTLS_TEST_OUTCOME_FILE=}
  146. : ${MBEDTLS_TEST_PLATFORM="$(uname -s | tr -c \\n0-9A-Za-z _)-$(uname -m | tr -c \\n0-9A-Za-z _)"}
  147. export MBEDTLS_TEST_OUTCOME_FILE
  148. export MBEDTLS_TEST_PLATFORM
  149. # Default commands, can be overridden by the environment
  150. : ${OPENSSL:="openssl"}
  151. : ${OPENSSL_LEGACY:="$OPENSSL"}
  152. : ${OPENSSL_NEXT:="$OPENSSL"}
  153. : ${GNUTLS_CLI:="gnutls-cli"}
  154. : ${GNUTLS_SERV:="gnutls-serv"}
  155. : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
  156. : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
  157. : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
  158. : ${ARMC5_BIN_DIR:=/usr/bin}
  159. : ${ARMC6_BIN_DIR:=/usr/bin}
  160. : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
  161. : ${ARM_LINUX_GNUEABI_GCC_PREFIX:=arm-linux-gnueabi-}
  162. # if MAKEFLAGS is not set add the -j option to speed up invocations of make
  163. if [ -z "${MAKEFLAGS+set}" ]; then
  164. export MAKEFLAGS="-j$(all_sh_nproc)"
  165. fi
  166. # Include more verbose output for failing tests run by CMake or make
  167. export CTEST_OUTPUT_ON_FAILURE=1
  168. # CFLAGS and LDFLAGS for Asan builds that don't use CMake
  169. # default to -O2, use -Ox _after_ this if you want another level
  170. ASAN_CFLAGS='-O2 -Werror -fsanitize=address,undefined -fno-sanitize-recover=all'
  171. # Gather the list of available components. These are the functions
  172. # defined in this script whose name starts with "component_".
  173. # Parse the script with sed. This way we get the functions in the order
  174. # they are defined.
  175. ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
  176. # Exclude components that are not supported on this platform.
  177. SUPPORTED_COMPONENTS=
  178. for component in $ALL_COMPONENTS; do
  179. case $(type "support_$component" 2>&1) in
  180. *' function'*)
  181. if ! support_$component; then continue; fi;;
  182. esac
  183. SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
  184. done
  185. }
  186. # Test whether the component $1 is included in the command line patterns.
  187. is_component_included()
  188. {
  189. # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
  190. # only does word splitting.
  191. set -f
  192. for pattern in $COMMAND_LINE_COMPONENTS; do
  193. set +f
  194. case ${1#component_} in $pattern) return 0;; esac
  195. done
  196. set +f
  197. return 1
  198. }
  199. usage()
  200. {
  201. cat <<EOF
  202. Usage: $0 [OPTION]... [COMPONENT]...
  203. Run mbedtls release validation tests.
  204. By default, run all tests. With one or more COMPONENT, run only those.
  205. COMPONENT can be the name of a component or a shell wildcard pattern.
  206. Examples:
  207. $0 "check_*"
  208. Run all sanity checks.
  209. $0 --no-armcc --except test_memsan
  210. Run everything except builds that require armcc and MemSan.
  211. Special options:
  212. -h|--help Print this help and exit.
  213. --list-all-components List all available test components and exit.
  214. --list-components List components supported on this platform and exit.
  215. General options:
  216. -q|--quiet Only output component names, and errors if any.
  217. -f|--force Force the tests to overwrite any modified files.
  218. -k|--keep-going Run all tests and report errors at the end.
  219. -m|--memory Additional optional memory tests.
  220. --append-outcome Append to the outcome file (if used).
  221. --arm-none-eabi-gcc-prefix=<string>
  222. Prefix for a cross-compiler for arm-none-eabi
  223. (default: "${ARM_NONE_EABI_GCC_PREFIX}")
  224. --arm-linux-gnueabi-gcc-prefix=<string>
  225. Prefix for a cross-compiler for arm-linux-gnueabi
  226. (default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}")
  227. --armcc Run ARM Compiler builds (on by default).
  228. --restore First clean up the build tree, restoring backed up
  229. files. Do not run any components unless they are
  230. explicitly specified.
  231. --error-test Error test mode: run a failing function in addition
  232. to any specified component. May be repeated.
  233. --except Exclude the COMPONENTs listed on the command line,
  234. instead of running only those.
  235. --no-append-outcome Write a new outcome file and analyze it (default).
  236. --no-armcc Skip ARM Compiler builds.
  237. --no-force Refuse to overwrite modified files (default).
  238. --no-keep-going Stop at the first error (default).
  239. --no-memory No additional memory tests (default).
  240. --no-quiet Print full output from components.
  241. --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
  242. --outcome-file=<path> File where test outcomes are written (not done if
  243. empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
  244. --random-seed Use a random seed value for randomized tests (default).
  245. -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
  246. -s|--seed Integer seed value to use for this test run.
  247. Tool path options:
  248. --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
  249. --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
  250. --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
  251. --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
  252. --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
  253. --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
  254. --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
  255. --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests..
  256. --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
  257. EOF
  258. }
  259. # Cleanup before/after running a component.
  260. # Remove built files as well as the cmake cache/config.
  261. # Does not remove generated source files.
  262. cleanup()
  263. {
  264. command make clean
  265. # Remove CMake artefacts
  266. find . -name .git -prune -o \
  267. -iname CMakeFiles -exec rm -rf {} \+ -o \
  268. \( -iname cmake_install.cmake -o \
  269. -iname CTestTestfile.cmake -o \
  270. -iname CMakeCache.txt -o \
  271. -path './cmake/*.cmake' \) -exec rm -f {} \+
  272. # Recover files overwritten by in-tree CMake builds
  273. rm -f include/Makefile include/mbedtls/Makefile programs/!(fuzz)/Makefile
  274. # Remove any artifacts from the component_test_cmake_as_subdirectory test.
  275. rm -rf programs/test/cmake_subproject/build
  276. rm -f programs/test/cmake_subproject/Makefile
  277. rm -f programs/test/cmake_subproject/cmake_subproject
  278. # Remove any artifacts from the component_test_cmake_as_package test.
  279. rm -rf programs/test/cmake_package/build
  280. rm -f programs/test/cmake_package/Makefile
  281. rm -f programs/test/cmake_package/cmake_package
  282. # Remove any artifacts from the component_test_cmake_as_installed_package test.
  283. rm -rf programs/test/cmake_package_install/build
  284. rm -f programs/test/cmake_package_install/Makefile
  285. rm -f programs/test/cmake_package_install/cmake_package_install
  286. # Restore files that may have been clobbered by the job
  287. for x in $files_to_back_up; do
  288. if [[ -e "$x$backup_suffix" ]]; then
  289. cp -p "$x$backup_suffix" "$x"
  290. fi
  291. done
  292. }
  293. # Final cleanup when this script exits (except when exiting on a failure
  294. # in non-keep-going mode).
  295. final_cleanup () {
  296. cleanup
  297. for x in $files_to_back_up; do
  298. rm -f "$x$backup_suffix"
  299. done
  300. }
  301. # Executed on exit. May be redefined depending on command line options.
  302. final_report () {
  303. :
  304. }
  305. fatal_signal () {
  306. final_cleanup
  307. final_report $1
  308. trap - $1
  309. kill -$1 $$
  310. }
  311. trap 'fatal_signal HUP' HUP
  312. trap 'fatal_signal INT' INT
  313. trap 'fatal_signal TERM' TERM
  314. # Number of processors on this machine. Used as the default setting
  315. # for parallel make.
  316. all_sh_nproc ()
  317. {
  318. {
  319. nproc || # Linux
  320. sysctl -n hw.ncpuonline || # NetBSD, OpenBSD
  321. sysctl -n hw.ncpu || # FreeBSD
  322. echo 1
  323. } 2>/dev/null
  324. }
  325. msg()
  326. {
  327. if [ -n "${current_component:-}" ]; then
  328. current_section="${current_component#component_}: $1"
  329. else
  330. current_section="$1"
  331. fi
  332. if [ $QUIET -eq 1 ]; then
  333. return
  334. fi
  335. echo ""
  336. echo "******************************************************************"
  337. echo "* $current_section "
  338. printf "* "; date
  339. echo "******************************************************************"
  340. }
  341. armc6_build_test()
  342. {
  343. FLAGS="$1"
  344. msg "build: ARM Compiler 6 ($FLAGS)"
  345. ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
  346. WARNING_CFLAGS='-Werror -xc -std=c99' make lib
  347. msg "size: ARM Compiler 6 ($FLAGS)"
  348. "$ARMC6_FROMELF" -z library/*.o
  349. make clean
  350. }
  351. err_msg()
  352. {
  353. echo "$1" >&2
  354. }
  355. check_tools()
  356. {
  357. for TOOL in "$@"; do
  358. if ! `type "$TOOL" >/dev/null 2>&1`; then
  359. err_msg "$TOOL not found!"
  360. exit 1
  361. fi
  362. done
  363. }
  364. pre_parse_command_line () {
  365. COMMAND_LINE_COMPONENTS=
  366. all_except=0
  367. error_test=0
  368. restore_first=0
  369. no_armcc=
  370. # Note that legacy options are ignored instead of being omitted from this
  371. # list of options, so invocations that worked with previous version of
  372. # all.sh will still run and work properly.
  373. while [ $# -gt 0 ]; do
  374. case "$1" in
  375. --append-outcome) append_outcome=1;;
  376. --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
  377. --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
  378. --armcc) no_armcc=;;
  379. --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
  380. --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
  381. --error-test) error_test=$((error_test + 1));;
  382. --except) all_except=1;;
  383. --force|-f) FORCE=1;;
  384. --gnutls-cli) shift; GNUTLS_CLI="$1";;
  385. --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
  386. --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
  387. --gnutls-serv) shift; GNUTLS_SERV="$1";;
  388. --help|-h) usage; exit;;
  389. --keep-going|-k) KEEP_GOING=1;;
  390. --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
  391. --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
  392. --memory|-m) MEMORY=1;;
  393. --no-append-outcome) append_outcome=0;;
  394. --no-armcc) no_armcc=1;;
  395. --no-force) FORCE=0;;
  396. --no-keep-going) KEEP_GOING=0;;
  397. --no-memory) MEMORY=0;;
  398. --no-quiet) QUIET=0;;
  399. --openssl) shift; OPENSSL="$1";;
  400. --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
  401. --openssl-next) shift; OPENSSL_NEXT="$1";;
  402. --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
  403. --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
  404. --quiet|-q) QUIET=1;;
  405. --random-seed) unset SEED;;
  406. --release-test|-r) SEED=$RELEASE_SEED;;
  407. --restore) restore_first=1;;
  408. --seed|-s) shift; SEED="$1";;
  409. -*)
  410. echo >&2 "Unknown option: $1"
  411. echo >&2 "Run $0 --help for usage."
  412. exit 120
  413. ;;
  414. *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
  415. esac
  416. shift
  417. done
  418. # With no list of components, run everything.
  419. if [ -z "$COMMAND_LINE_COMPONENTS" ] && [ $restore_first -eq 0 ]; then
  420. all_except=1
  421. fi
  422. # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
  423. # Ignore it if components are listed explicitly on the command line.
  424. if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
  425. COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
  426. fi
  427. # Error out if an explicitly requested component doesn't exist.
  428. if [ $all_except -eq 0 ]; then
  429. unsupported=0
  430. # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
  431. # only does word splitting.
  432. set -f
  433. for component in $COMMAND_LINE_COMPONENTS; do
  434. set +f
  435. # If the requested name includes a wildcard character, don't
  436. # check it. Accept wildcard patterns that don't match anything.
  437. case $component in
  438. *[*?\[]*) continue;;
  439. esac
  440. case " $SUPPORTED_COMPONENTS " in
  441. *" $component "*) :;;
  442. *)
  443. echo >&2 "Component $component was explicitly requested, but is not known or not supported."
  444. unsupported=$((unsupported + 1));;
  445. esac
  446. done
  447. set +f
  448. if [ $unsupported -ne 0 ]; then
  449. exit 2
  450. fi
  451. fi
  452. # Build the list of components to run.
  453. RUN_COMPONENTS=
  454. for component in $SUPPORTED_COMPONENTS; do
  455. if is_component_included "$component"; [ $? -eq $all_except ]; then
  456. RUN_COMPONENTS="$RUN_COMPONENTS $component"
  457. fi
  458. done
  459. unset all_except
  460. unset no_armcc
  461. }
  462. pre_check_git () {
  463. if [ $FORCE -eq 1 ]; then
  464. rm -rf "$OUT_OF_SOURCE_DIR"
  465. git checkout-index -f -q $CONFIG_H
  466. cleanup
  467. else
  468. if [ -d "$OUT_OF_SOURCE_DIR" ]; then
  469. echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
  470. echo "You can either delete this directory manually, or force the test by rerunning"
  471. echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
  472. exit 1
  473. fi
  474. if ! git diff --quiet include/mbedtls/mbedtls_config.h; then
  475. err_msg "Warning - the configuration file 'include/mbedtls/mbedtls_config.h' has been edited. "
  476. echo "You can either delete or preserve your work, or force the test by rerunning the"
  477. echo "script as: $0 --force"
  478. exit 1
  479. fi
  480. fi
  481. }
  482. pre_restore_files () {
  483. # If the makefiles have been generated by a framework such as cmake,
  484. # restore them from git. If the makefiles look like modifications from
  485. # the ones checked into git, take care not to modify them. Whatever
  486. # this function leaves behind is what the script will restore before
  487. # each component.
  488. case "$(head -n1 Makefile)" in
  489. *[Gg]enerated*)
  490. git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
  491. git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
  492. ;;
  493. esac
  494. }
  495. pre_back_up () {
  496. for x in $files_to_back_up; do
  497. cp -p "$x" "$x$backup_suffix"
  498. done
  499. }
  500. pre_setup_keep_going () {
  501. failure_count=0 # Number of failed components
  502. last_failure_status=0 # Last failure status in this component
  503. # See err_trap
  504. previous_failure_status=0
  505. previous_failed_command=
  506. previous_failure_funcall_depth=0
  507. unset report_failed_command
  508. start_red=
  509. end_color=
  510. if [ -t 1 ]; then
  511. case "${TERM:-}" in
  512. *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
  513. start_red=$(printf '\033[31m')
  514. end_color=$(printf '\033[0m')
  515. ;;
  516. esac
  517. fi
  518. # Keep a summary of failures in a file. We'll print it out at the end.
  519. failure_summary_file=$PWD/all-sh-failures-$$.log
  520. : >"$failure_summary_file"
  521. # Whether it makes sense to keep a component going after the specified
  522. # command fails (test command) or not (configure or build).
  523. # This function normally receives the failing simple command
  524. # ($BASH_COMMAND) as an argument, but if $report_failed_command is set,
  525. # this is passed instead.
  526. # This doesn't have to be 100% accurate: all failures are recorded anyway.
  527. # False positives result in running things that can't be expected to
  528. # work. False negatives result in things not running after something else
  529. # failed even though they might have given useful feedback.
  530. can_keep_going_after_failure () {
  531. case "$1" in
  532. "msg "*) false;;
  533. "cd "*) false;;
  534. *make*[\ /]tests*) false;; # make tests, make CFLAGS=-I../tests, ...
  535. *test*) true;; # make test, tests/stuff, env V=v tests/stuff, ...
  536. *make*check*) true;;
  537. "grep "*) true;;
  538. "[ "*) true;;
  539. "! "*) true;;
  540. *) false;;
  541. esac
  542. }
  543. # This function runs if there is any error in a component.
  544. # It must either exit with a nonzero status, or set
  545. # last_failure_status to a nonzero value.
  546. err_trap () {
  547. # Save $? (status of the failing command). This must be the very
  548. # first thing, before $? is overridden.
  549. last_failure_status=$?
  550. failed_command=${report_failed_command-$BASH_COMMAND}
  551. if [[ $last_failure_status -eq $previous_failure_status &&
  552. "$failed_command" == "$previous_failed_command" &&
  553. ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
  554. then
  555. # The same command failed twice in a row, but this time one level
  556. # less deep in the function call stack. This happens when the last
  557. # command of a function returns a nonzero status, and the function
  558. # returns that same status. Ignore the second failure.
  559. previous_failure_funcall_depth=${#FUNCNAME[@]}
  560. return
  561. fi
  562. previous_failure_status=$last_failure_status
  563. previous_failed_command=$failed_command
  564. previous_failure_funcall_depth=${#FUNCNAME[@]}
  565. text="$current_section: $failed_command -> $last_failure_status"
  566. echo "${start_red}^^^^$text^^^^${end_color}" >&2
  567. echo "$text" >>"$failure_summary_file"
  568. # If the command is fatal (configure or build command), stop this
  569. # component. Otherwise (test command) keep the component running
  570. # (run more tests from the same build).
  571. if ! can_keep_going_after_failure "$failed_command"; then
  572. exit $last_failure_status
  573. fi
  574. }
  575. final_report () {
  576. if [ $failure_count -gt 0 ]; then
  577. echo
  578. echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  579. echo "${start_red}FAILED: $failure_count components${end_color}"
  580. cat "$failure_summary_file"
  581. echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  582. elif [ -z "${1-}" ]; then
  583. echo "SUCCESS :)"
  584. fi
  585. if [ -n "${1-}" ]; then
  586. echo "Killed by SIG$1."
  587. fi
  588. rm -f "$failure_summary_file"
  589. if [ $failure_count -gt 0 ]; then
  590. exit 1
  591. fi
  592. }
  593. }
  594. # record_status() and if_build_succeeded() are kept temporarily for backward
  595. # compatibility. Don't use them in new components.
  596. record_status () {
  597. "$@"
  598. }
  599. if_build_succeeded () {
  600. "$@"
  601. }
  602. # '! true' does not trigger the ERR trap. Arrange to trigger it, with
  603. # a reasonably informative error message (not just "$@").
  604. not () {
  605. if "$@"; then
  606. report_failed_command="! $*"
  607. false
  608. unset report_failed_command
  609. fi
  610. }
  611. pre_prepare_outcome_file () {
  612. case "$MBEDTLS_TEST_OUTCOME_FILE" in
  613. [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
  614. esac
  615. if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
  616. rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
  617. fi
  618. }
  619. pre_print_configuration () {
  620. if [ $QUIET -eq 1 ]; then
  621. return
  622. fi
  623. msg "info: $0 configuration"
  624. echo "MEMORY: $MEMORY"
  625. echo "FORCE: $FORCE"
  626. echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
  627. echo "SEED: ${SEED-"UNSET"}"
  628. echo
  629. echo "OPENSSL: $OPENSSL"
  630. echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
  631. echo "OPENSSL_NEXT: $OPENSSL_NEXT"
  632. echo "GNUTLS_CLI: $GNUTLS_CLI"
  633. echo "GNUTLS_SERV: $GNUTLS_SERV"
  634. echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
  635. echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
  636. echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
  637. echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
  638. }
  639. # Make sure the tools we need are available.
  640. pre_check_tools () {
  641. # Build the list of variables to pass to output_env.sh.
  642. set env
  643. case " $RUN_COMPONENTS " in
  644. # Require OpenSSL and GnuTLS if running any tests (as opposed to
  645. # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
  646. # is a good enough approximation in practice.
  647. *" test_"*)
  648. # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
  649. # and ssl-opt.sh, we just export the variables they require.
  650. export OPENSSL="$OPENSSL"
  651. export GNUTLS_CLI="$GNUTLS_CLI"
  652. export GNUTLS_SERV="$GNUTLS_SERV"
  653. # Avoid passing --seed flag in every call to ssl-opt.sh
  654. if [ -n "${SEED-}" ]; then
  655. export SEED
  656. fi
  657. set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
  658. set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
  659. set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
  660. set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
  661. check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
  662. "$GNUTLS_CLI" "$GNUTLS_SERV" \
  663. "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
  664. ;;
  665. esac
  666. case " $RUN_COMPONENTS " in
  667. *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
  668. esac
  669. case " $RUN_COMPONENTS " in
  670. *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
  671. esac
  672. case " $RUN_COMPONENTS " in
  673. *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
  674. esac
  675. case " $RUN_COMPONENTS " in
  676. *" test_zeroize "*) check_tools "gdb";;
  677. esac
  678. case " $RUN_COMPONENTS " in
  679. *_armcc*)
  680. ARMC5_CC="$ARMC5_BIN_DIR/armcc"
  681. ARMC5_AR="$ARMC5_BIN_DIR/armar"
  682. ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
  683. ARMC6_CC="$ARMC6_BIN_DIR/armclang"
  684. ARMC6_AR="$ARMC6_BIN_DIR/armar"
  685. ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
  686. check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
  687. "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
  688. esac
  689. # past this point, no call to check_tool, only printing output
  690. if [ $QUIET -eq 1 ]; then
  691. return
  692. fi
  693. msg "info: output_env.sh"
  694. case $RUN_COMPONENTS in
  695. *_armcc*)
  696. set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
  697. *) set "$@" RUN_ARMCC=0;;
  698. esac
  699. "$@" scripts/output_env.sh
  700. }
  701. pre_generate_files() {
  702. # since make doesn't have proper dependencies, remove any possibly outdate
  703. # file that might be around before generating fresh ones
  704. make neat
  705. if [ $QUIET -eq 1 ]; then
  706. make generated_files >/dev/null
  707. else
  708. make generated_files
  709. fi
  710. }
  711. ################################################################
  712. #### Basic checks
  713. ################################################################
  714. #
  715. # Test Suites to be executed
  716. #
  717. # The test ordering tries to optimize for the following criteria:
  718. # 1. Catch possible problems early, by running first tests that run quickly
  719. # and/or are more likely to fail than others (eg I use Clang most of the
  720. # time, so start with a GCC build).
  721. # 2. Minimize total running time, by avoiding useless rebuilds
  722. #
  723. # Indicative running times are given for reference.
  724. component_check_recursion () {
  725. msg "Check: recursion.pl" # < 1s
  726. tests/scripts/recursion.pl library/*.c
  727. }
  728. component_check_generated_files () {
  729. msg "Check: check-generated-files, files generated with make" # 2s
  730. make generated_files
  731. tests/scripts/check-generated-files.sh
  732. msg "Check: check-generated-files -u, files present" # 2s
  733. tests/scripts/check-generated-files.sh -u
  734. # Check that the generated files are considered up to date.
  735. tests/scripts/check-generated-files.sh
  736. msg "Check: check-generated-files -u, files absent" # 2s
  737. command make neat
  738. tests/scripts/check-generated-files.sh -u
  739. # Check that the generated files are considered up to date.
  740. tests/scripts/check-generated-files.sh
  741. # This component ends with the generated files present in the source tree.
  742. # This is necessary for subsequent components!
  743. }
  744. component_check_doxy_blocks () {
  745. msg "Check: doxygen markup outside doxygen blocks" # < 1s
  746. tests/scripts/check-doxy-blocks.pl
  747. }
  748. component_check_files () {
  749. msg "Check: file sanity checks (permissions, encodings)" # < 1s
  750. tests/scripts/check_files.py
  751. }
  752. component_check_changelog () {
  753. msg "Check: changelog entries" # < 1s
  754. rm -f ChangeLog.new
  755. scripts/assemble_changelog.py -o ChangeLog.new
  756. if [ -e ChangeLog.new ]; then
  757. # Show the diff for information. It isn't an error if the diff is
  758. # non-empty.
  759. diff -u ChangeLog ChangeLog.new || true
  760. rm ChangeLog.new
  761. fi
  762. }
  763. component_check_names () {
  764. msg "Check: declared and exported names (builds the library)" # < 3s
  765. tests/scripts/check_names.py -v
  766. }
  767. component_check_test_cases () {
  768. msg "Check: test case descriptions" # < 1s
  769. if [ $QUIET -eq 1 ]; then
  770. opt='--quiet'
  771. else
  772. opt=''
  773. fi
  774. tests/scripts/check_test_cases.py -q $opt
  775. unset opt
  776. }
  777. component_check_doxygen_warnings () {
  778. msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
  779. tests/scripts/doxygen.sh
  780. }
  781. ################################################################
  782. #### Build and test many configurations and targets
  783. ################################################################
  784. component_test_default_out_of_box () {
  785. msg "build: make, default config (out-of-box)" # ~1min
  786. make
  787. # Disable fancy stuff
  788. unset MBEDTLS_TEST_OUTCOME_FILE
  789. msg "test: main suites make, default config (out-of-box)" # ~10s
  790. make test
  791. msg "selftest: make, default config (out-of-box)" # ~10s
  792. programs/test/selftest
  793. }
  794. component_test_default_cmake_gcc_asan () {
  795. msg "build: cmake, gcc, ASan" # ~ 1 min 50s
  796. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  797. make
  798. msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
  799. make test
  800. msg "test: selftest (ASan build)" # ~ 10s
  801. programs/test/selftest
  802. msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
  803. tests/ssl-opt.sh
  804. msg "test: compat.sh (ASan build)" # ~ 6 min
  805. tests/compat.sh
  806. msg "test: context-info.sh (ASan build)" # ~ 15 sec
  807. tests/context-info.sh
  808. }
  809. component_test_full_cmake_gcc_asan () {
  810. msg "build: full config, cmake, gcc, ASan"
  811. scripts/config.py full
  812. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  813. make
  814. msg "test: main suites (inc. selftests) (full config, ASan build)"
  815. make test
  816. msg "test: selftest (ASan build)" # ~ 10s
  817. programs/test/selftest
  818. msg "test: ssl-opt.sh (full config, ASan build)"
  819. tests/ssl-opt.sh
  820. msg "test: compat.sh (full config, ASan build)"
  821. tests/compat.sh
  822. msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
  823. tests/context-info.sh
  824. msg "test: check direct ECP dependencies in TLS and X.509"
  825. docs/architecture/psa-migration/syms.sh full
  826. # TODO: replace "mbedtls_ecp_curve" with "mbedtls_ecp" also for
  827. # "full-tls-external" once Issue6839 is completed
  828. not grep mbedtls_ecp_curve full-tls-external
  829. not grep mbedtls_ecp full-x509-external
  830. rm full-tls-external \
  831. full-tls-modules \
  832. full-x509-external \
  833. full-x509-modules
  834. }
  835. component_test_psa_crypto_key_id_encodes_owner () {
  836. msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
  837. scripts/config.py full
  838. scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
  839. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  840. make
  841. msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
  842. make test
  843. }
  844. # check_renamed_symbols HEADER LIB
  845. # Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
  846. # name is LIB.
  847. check_renamed_symbols () {
  848. ! nm "$2" | sed 's/.* //' |
  849. grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
  850. }
  851. component_build_psa_crypto_spm () {
  852. msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
  853. scripts/config.py full
  854. scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
  855. scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
  856. scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
  857. # We can only compile, not link, since our test and sample programs
  858. # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
  859. # is active.
  860. make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
  861. # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
  862. # version is not present.
  863. echo "Checking for renamed symbols in the library"
  864. check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
  865. }
  866. component_test_psa_crypto_client () {
  867. msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
  868. scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
  869. scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
  870. scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
  871. scripts/config.py unset MBEDTLS_LMS_C
  872. scripts/config.py unset MBEDTLS_LMS_PRIVATE
  873. make
  874. msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
  875. make test
  876. }
  877. component_test_psa_crypto_rsa_no_genprime() {
  878. msg "build: default config minus MBEDTLS_GENPRIME"
  879. scripts/config.py unset MBEDTLS_GENPRIME
  880. make
  881. msg "test: default config minus MBEDTLS_GENPRIME"
  882. make test
  883. }
  884. component_test_ref_configs () {
  885. msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
  886. # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake
  887. # want to re-generate generated files that depend on it, quite correctly.
  888. # However this doesn't work as the generation script expects a specific
  889. # format for mbedtls_config.h, which the other files don't follow. Also,
  890. # cmake can't know this, but re-generation is actually not necessary as
  891. # the generated files only depend on the list of available options, not
  892. # whether they're on or off. So, disable cmake's (over-sensitive here)
  893. # dependency resolution for generated files and just rely on them being
  894. # present (thanks to pre_generate_files) by turning GEN_FILES off.
  895. CC=gcc cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan .
  896. tests/scripts/test-ref-configs.pl
  897. }
  898. component_test_no_renegotiation () {
  899. msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
  900. scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
  901. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  902. make
  903. msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
  904. make test
  905. msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
  906. tests/ssl-opt.sh
  907. }
  908. component_test_no_pem_no_fs () {
  909. msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
  910. scripts/config.py unset MBEDTLS_PEM_PARSE_C
  911. scripts/config.py unset MBEDTLS_FS_IO
  912. scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
  913. scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
  914. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  915. make
  916. msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
  917. make test
  918. msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
  919. tests/ssl-opt.sh
  920. }
  921. component_test_rsa_no_crt () {
  922. msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
  923. scripts/config.py set MBEDTLS_RSA_NO_CRT
  924. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  925. make
  926. msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
  927. make test
  928. msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
  929. tests/ssl-opt.sh -f RSA
  930. msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
  931. tests/compat.sh -t RSA
  932. msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
  933. tests/context-info.sh
  934. }
  935. component_test_no_ctr_drbg_classic () {
  936. msg "build: Full minus CTR_DRBG, classic crypto in TLS"
  937. scripts/config.py full
  938. scripts/config.py unset MBEDTLS_CTR_DRBG_C
  939. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  940. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  941. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  942. make
  943. msg "test: Full minus CTR_DRBG, classic crypto - main suites"
  944. make test
  945. # In this configuration, the TLS test programs use HMAC_DRBG.
  946. # The SSL tests are slow, so run a small subset, just enough to get
  947. # confidence that the SSL code copes with HMAC_DRBG.
  948. msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
  949. tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
  950. msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
  951. tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
  952. }
  953. component_test_no_ctr_drbg_use_psa () {
  954. msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
  955. scripts/config.py full
  956. scripts/config.py unset MBEDTLS_CTR_DRBG_C
  957. scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
  958. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  959. make
  960. msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
  961. make test
  962. # In this configuration, the TLS test programs use HMAC_DRBG.
  963. # The SSL tests are slow, so run a small subset, just enough to get
  964. # confidence that the SSL code copes with HMAC_DRBG.
  965. msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
  966. tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
  967. msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
  968. tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
  969. }
  970. component_test_no_hmac_drbg_classic () {
  971. msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
  972. scripts/config.py full
  973. scripts/config.py unset MBEDTLS_HMAC_DRBG_C
  974. scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
  975. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  976. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  977. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  978. make
  979. msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
  980. make test
  981. # Normally our ECDSA implementation uses deterministic ECDSA. But since
  982. # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
  983. # instead.
  984. # Test SSL with non-deterministic ECDSA. Only test features that
  985. # might be affected by how ECDSA signature is performed.
  986. msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
  987. tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
  988. # To save time, only test one protocol version, since this part of
  989. # the protocol is identical in (D)TLS up to 1.2.
  990. msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
  991. tests/compat.sh -m tls12 -t 'ECDSA'
  992. }
  993. component_test_no_hmac_drbg_use_psa () {
  994. msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
  995. scripts/config.py full
  996. scripts/config.py unset MBEDTLS_HMAC_DRBG_C
  997. scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
  998. scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
  999. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  1000. make
  1001. msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
  1002. make test
  1003. # Normally our ECDSA implementation uses deterministic ECDSA. But since
  1004. # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
  1005. # instead.
  1006. # Test SSL with non-deterministic ECDSA. Only test features that
  1007. # might be affected by how ECDSA signature is performed.
  1008. msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
  1009. tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
  1010. # To save time, only test one protocol version, since this part of
  1011. # the protocol is identical in (D)TLS up to 1.2.
  1012. msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
  1013. tests/compat.sh -m tls12 -t 'ECDSA'
  1014. }
  1015. component_test_psa_external_rng_no_drbg_classic () {
  1016. msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
  1017. scripts/config.py full
  1018. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1019. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  1020. scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
  1021. scripts/config.py unset MBEDTLS_ENTROPY_C
  1022. scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
  1023. scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
  1024. scripts/config.py unset MBEDTLS_CTR_DRBG_C
  1025. scripts/config.py unset MBEDTLS_HMAC_DRBG_C
  1026. scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
  1027. # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
  1028. # the SSL test programs don't have an RNG and can't work. Explicitly
  1029. # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
  1030. make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
  1031. msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
  1032. make test
  1033. msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
  1034. tests/ssl-opt.sh -f 'Default'
  1035. }
  1036. component_test_psa_external_rng_no_drbg_use_psa () {
  1037. msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
  1038. scripts/config.py full
  1039. scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
  1040. scripts/config.py unset MBEDTLS_ENTROPY_C
  1041. scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
  1042. scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
  1043. scripts/config.py unset MBEDTLS_CTR_DRBG_C
  1044. scripts/config.py unset MBEDTLS_HMAC_DRBG_C
  1045. scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
  1046. make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
  1047. msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
  1048. make test
  1049. msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
  1050. tests/ssl-opt.sh -f 'Default\|opaque'
  1051. }
  1052. component_test_crypto_full_md_light_only () {
  1053. msg "build: crypto_full with only the light subset of MD"
  1054. scripts/config.py crypto_full
  1055. # Disable MD
  1056. scripts/config.py unset MBEDTLS_MD_C
  1057. # Disable direct dependencies of MD
  1058. scripts/config.py unset MBEDTLS_HKDF_C
  1059. scripts/config.py unset MBEDTLS_HMAC_DRBG_C
  1060. scripts/config.py unset MBEDTLS_PKCS7_C
  1061. # Disable indirect dependencies of MD
  1062. scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # needs HMAC_DRBG
  1063. # Note: MD-light is auto-enabled in build_info.h by modules that need it,
  1064. # which we haven't disabled, so no need to explicitly enable it.
  1065. make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
  1066. # Make sure we don't have the HMAC functions, but the hashing functions
  1067. not grep mbedtls_md_hmac library/md.o
  1068. grep mbedtls_md library/md.o
  1069. msg "test: crypto_full with only the light subset of MD"
  1070. make test
  1071. }
  1072. component_test_full_no_cipher () {
  1073. msg "build: full minus CIPHER"
  1074. scripts/config.py full
  1075. scripts/config.py unset MBEDTLS_CIPHER_C
  1076. # Direct dependencies
  1077. scripts/config.py unset MBEDTLS_CCM_C
  1078. scripts/config.py unset MBEDTLS_CMAC_C
  1079. scripts/config.py unset MBEDTLS_GCM_C
  1080. scripts/config.py unset MBEDTLS_NIST_KW_C
  1081. scripts/config.py unset MBEDTLS_PKCS12_C
  1082. scripts/config.py unset MBEDTLS_PKCS5_C
  1083. scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
  1084. scripts/config.py unset MBEDTLS_SSL_TLS_C
  1085. scripts/config.py unset MBEDTLS_SSL_TICKET_C
  1086. # Indirect dependencies
  1087. scripts/config.py unset MBEDTLS_SSL_CLI_C
  1088. scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
  1089. scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
  1090. scripts/config.py unset MBEDTLS_SSL_DTLS_ANTI_REPLAY
  1091. scripts/config.py unset MBEDTLS_SSL_DTLS_CONNECTION_ID
  1092. scripts/config.py unset MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT
  1093. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  1094. scripts/config.py unset MBEDTLS_SSL_SRV_C
  1095. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1096. scripts/config.py unset MBEDTLS_LMS_C
  1097. scripts/config.py unset MBEDTLS_LMS_PRIVATE
  1098. make
  1099. msg "test: full minus CIPHER"
  1100. make test
  1101. }
  1102. component_test_crypto_full_no_cipher () {
  1103. msg "build: crypto_full minus CIPHER"
  1104. scripts/config.py crypto_full
  1105. scripts/config.py unset MBEDTLS_CIPHER_C
  1106. # Direct dependencies
  1107. scripts/config.py unset MBEDTLS_CCM_C
  1108. scripts/config.py unset MBEDTLS_CMAC_C
  1109. scripts/config.py unset MBEDTLS_GCM_C
  1110. scripts/config.py unset MBEDTLS_NIST_KW_C
  1111. scripts/config.py unset MBEDTLS_PKCS12_C
  1112. scripts/config.py unset MBEDTLS_PKCS5_C
  1113. scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
  1114. # Indirect dependencies
  1115. scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
  1116. scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
  1117. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1118. scripts/config.py unset MBEDTLS_LMS_C
  1119. scripts/config.py unset MBEDTLS_LMS_PRIVATE
  1120. make
  1121. msg "test: crypto_full minus CIPHER"
  1122. make test
  1123. }
  1124. component_test_full_no_bignum () {
  1125. msg "build: full minus bignum"
  1126. scripts/config.py full
  1127. scripts/config.py unset MBEDTLS_BIGNUM_C
  1128. # Direct dependencies of bignum
  1129. scripts/config.py unset MBEDTLS_ECP_C
  1130. scripts/config.py unset MBEDTLS_RSA_C
  1131. scripts/config.py unset MBEDTLS_DHM_C
  1132. # Direct dependencies of ECP
  1133. scripts/config.py unset MBEDTLS_ECDH_C
  1134. scripts/config.py unset MBEDTLS_ECDSA_C
  1135. scripts/config.py unset MBEDTLS_ECJPAKE_C
  1136. scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
  1137. # Indirect dependencies of ECP
  1138. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
  1139. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
  1140. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
  1141. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
  1142. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
  1143. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
  1144. scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
  1145. scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
  1146. # Direct dependencies of DHM
  1147. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
  1148. # Direct dependencies of RSA
  1149. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
  1150. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
  1151. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
  1152. scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
  1153. # PK and its dependencies
  1154. scripts/config.py unset MBEDTLS_PK_C
  1155. scripts/config.py unset MBEDTLS_PK_PARSE_C
  1156. scripts/config.py unset MBEDTLS_PK_WRITE_C
  1157. scripts/config.py unset MBEDTLS_X509_USE_C
  1158. scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
  1159. scripts/config.py unset MBEDTLS_X509_CRL_PARSE_C
  1160. scripts/config.py unset MBEDTLS_X509_CSR_PARSE_C
  1161. scripts/config.py unset MBEDTLS_X509_CREATE_C
  1162. scripts/config.py unset MBEDTLS_X509_CRT_WRITE_C
  1163. scripts/config.py unset MBEDTLS_X509_CSR_WRITE_C
  1164. scripts/config.py unset MBEDTLS_PKCS7_C
  1165. scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
  1166. scripts/config.py unset MBEDTLS_SSL_ASYNC_PRIVATE
  1167. scripts/config.py unset MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
  1168. make
  1169. msg "test: full minus bignum"
  1170. make test
  1171. }
  1172. component_test_tls1_2_default_stream_cipher_only () {
  1173. msg "build: default with only stream cipher"
  1174. # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C
  1175. scripts/config.py unset MBEDTLS_GCM_C
  1176. scripts/config.py unset MBEDTLS_CCM_C
  1177. scripts/config.py unset MBEDTLS_CHACHAPOLY_C
  1178. # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
  1179. scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
  1180. # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
  1181. scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
  1182. # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
  1183. scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
  1184. # Modules that depend on AEAD
  1185. scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
  1186. scripts/config.py unset MBEDTLS_SSL_TICKET_C
  1187. make
  1188. msg "test: default with only stream cipher"
  1189. make test
  1190. # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
  1191. }
  1192. component_test_tls1_2_default_stream_cipher_only_use_psa () {
  1193. msg "build: default with only stream cipher use psa"
  1194. scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
  1195. # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
  1196. scripts/config.py unset MBEDTLS_GCM_C
  1197. scripts/config.py unset MBEDTLS_CCM_C
  1198. scripts/config.py unset MBEDTLS_CHACHAPOLY_C
  1199. # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
  1200. scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
  1201. # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
  1202. scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
  1203. # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
  1204. scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
  1205. # Modules that depend on AEAD
  1206. scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
  1207. scripts/config.py unset MBEDTLS_SSL_TICKET_C
  1208. make
  1209. msg "test: default with only stream cipher use psa"
  1210. make test
  1211. # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
  1212. }
  1213. component_test_tls1_2_default_cbc_legacy_cipher_only () {
  1214. msg "build: default with only CBC-legacy cipher"
  1215. # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
  1216. scripts/config.py unset MBEDTLS_GCM_C
  1217. scripts/config.py unset MBEDTLS_CCM_C
  1218. scripts/config.py unset MBEDTLS_CHACHAPOLY_C
  1219. # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
  1220. scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
  1221. # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
  1222. scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
  1223. # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
  1224. scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
  1225. # Modules that depend on AEAD
  1226. scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
  1227. scripts/config.py unset MBEDTLS_SSL_TICKET_C
  1228. make
  1229. msg "test: default with only CBC-legacy cipher"
  1230. make test
  1231. msg "test: default with only CBC-legacy cipher - ssl-opt.sh (subset)"
  1232. tests/ssl-opt.sh -f "TLS 1.2"
  1233. }
  1234. component_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa () {
  1235. msg "build: default with only CBC-legacy cipher use psa"
  1236. scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
  1237. # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
  1238. scripts/config.py unset MBEDTLS_GCM_C
  1239. scripts/config.py unset MBEDTLS_CCM_C
  1240. scripts/config.py unset MBEDTLS_CHACHAPOLY_C
  1241. # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
  1242. scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
  1243. # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
  1244. scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
  1245. # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
  1246. scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
  1247. # Modules that depend on AEAD
  1248. scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
  1249. scripts/config.py unset MBEDTLS_SSL_TICKET_C
  1250. make
  1251. msg "test: default with only CBC-legacy cipher use psa"
  1252. make test
  1253. msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
  1254. tests/ssl-opt.sh -f "TLS 1.2"
  1255. }
  1256. component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
  1257. msg "build: default with only CBC-legacy and CBC-EtM ciphers"
  1258. # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
  1259. scripts/config.py unset MBEDTLS_GCM_C
  1260. scripts/config.py unset MBEDTLS_CCM_C
  1261. scripts/config.py unset MBEDTLS_CHACHAPOLY_C
  1262. # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
  1263. scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
  1264. # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
  1265. scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
  1266. # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
  1267. scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
  1268. # Modules that depend on AEAD
  1269. scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
  1270. scripts/config.py unset MBEDTLS_SSL_TICKET_C
  1271. make
  1272. msg "test: default with only CBC-legacy and CBC-EtM ciphers"
  1273. make test
  1274. msg "test: default with only CBC-legacy and CBC-EtM ciphers - ssl-opt.sh (subset)"
  1275. tests/ssl-opt.sh -f "TLS 1.2"
  1276. }
  1277. component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa () {
  1278. msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
  1279. scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
  1280. # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
  1281. scripts/config.py unset MBEDTLS_GCM_C
  1282. scripts/config.py unset MBEDTLS_CCM_C
  1283. scripts/config.py unset MBEDTLS_CHACHAPOLY_C
  1284. # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
  1285. scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
  1286. # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
  1287. scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
  1288. # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
  1289. scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
  1290. # Modules that depend on AEAD
  1291. scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
  1292. scripts/config.py unset MBEDTLS_SSL_TICKET_C
  1293. make
  1294. msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
  1295. make test
  1296. msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
  1297. tests/ssl-opt.sh -f "TLS 1.2"
  1298. }
  1299. # We're not aware of any other (open source) implementation of EC J-PAKE in TLS
  1300. # that we could use for interop testing. However, we now have sort of two
  1301. # implementations ourselves: one using PSA, the other not. At least test that
  1302. # these two interoperate with each other.
  1303. component_test_tls1_2_ecjpake_compatibility() {
  1304. msg "build: TLS1.2 server+client w/ EC-JPAKE w/o USE_PSA"
  1305. scripts/config.py set MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
  1306. make -C programs ssl/ssl_server2 ssl/ssl_client2
  1307. cp programs/ssl/ssl_server2 s2_no_use_psa
  1308. cp programs/ssl/ssl_client2 c2_no_use_psa
  1309. msg "build: TLS1.2 server+client w/ EC-JPAKE w/ USE_PSA"
  1310. scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
  1311. make clean
  1312. make -C programs ssl/ssl_server2 ssl/ssl_client2
  1313. make -C programs test/udp_proxy test/query_compile_time_config
  1314. msg "test: server w/o USE_PSA - client w/ USE_PSA, text password"
  1315. P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
  1316. msg "test: server w/o USE_PSA - client w/ USE_PSA, opaque password"
  1317. P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: opaque password client only, working, TLS"
  1318. msg "test: client w/o USE_PSA - server w/ USE_PSA, text password"
  1319. P_CLI=../c2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
  1320. msg "test: client w/o USE_PSA - server w/ USE_PSA, opaque password"
  1321. P_CLI=../c2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: opaque password server only, working, TLS"
  1322. rm s2_no_use_psa c2_no_use_psa
  1323. }
  1324. component_test_psa_external_rng_use_psa_crypto () {
  1325. msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
  1326. scripts/config.py full
  1327. scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
  1328. scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
  1329. scripts/config.py unset MBEDTLS_CTR_DRBG_C
  1330. make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
  1331. msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
  1332. make test
  1333. msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
  1334. tests/ssl-opt.sh -f 'Default\|opaque'
  1335. }
  1336. component_test_everest () {
  1337. msg "build: Everest ECDH context (ASan build)" # ~ 6 min
  1338. scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
  1339. CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
  1340. make
  1341. msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
  1342. make test
  1343. msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
  1344. tests/ssl-opt.sh -f ECDH
  1345. msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
  1346. # Exclude some symmetric ciphers that are redundant here to gain time.
  1347. tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
  1348. }
  1349. component_test_everest_curve25519_only () {
  1350. msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
  1351. scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
  1352. scripts/config.py unset MBEDTLS_ECDSA_C
  1353. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
  1354. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
  1355. scripts/config.py unset MBEDTLS_ECJPAKE_C
  1356. # Disable all curves
  1357. for c in $(sed -n 's/#define \(MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED\).*/\1/p' <"$CONFIG_H"); do
  1358. scripts/config.py unset "$c"
  1359. done
  1360. scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
  1361. make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
  1362. msg "test: Everest ECDH context, only Curve25519" # ~ 50s
  1363. make test
  1364. }
  1365. component_test_small_ssl_out_content_len () {
  1366. msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
  1367. scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
  1368. scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
  1369. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  1370. make
  1371. msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
  1372. tests/ssl-opt.sh -f "Max fragment\|Large packet"
  1373. }
  1374. component_test_small_ssl_in_content_len () {
  1375. msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
  1376. scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
  1377. scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
  1378. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  1379. make
  1380. msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
  1381. tests/ssl-opt.sh -f "Max fragment"
  1382. }
  1383. component_test_small_ssl_dtls_max_buffering () {
  1384. msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
  1385. scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
  1386. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  1387. make
  1388. msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
  1389. tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
  1390. }
  1391. component_test_small_mbedtls_ssl_dtls_max_buffering () {
  1392. msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
  1393. scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
  1394. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  1395. make
  1396. msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
  1397. tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
  1398. }
  1399. component_test_psa_collect_statuses () {
  1400. msg "build+test: psa_collect_statuses" # ~30s
  1401. scripts/config.py full
  1402. tests/scripts/psa_collect_statuses.py
  1403. # Check that psa_crypto_init() succeeded at least once
  1404. grep -q '^0:psa_crypto_init:' tests/statuses.log
  1405. rm -f tests/statuses.log
  1406. }
  1407. component_test_full_cmake_clang () {
  1408. msg "build: cmake, full config, clang" # ~ 50s
  1409. scripts/config.py full
  1410. CC=clang CXX=clang cmake -D CMAKE_BUILD_TYPE:String=Release -D ENABLE_TESTING=On -D TEST_CPP=1 .
  1411. make
  1412. msg "test: main suites (full config, clang)" # ~ 5s
  1413. make test
  1414. msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
  1415. programs/test/cpp_dummy_build
  1416. msg "test: psa_constant_names (full config, clang)" # ~ 1s
  1417. tests/scripts/test_psa_constant_names.py
  1418. msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
  1419. tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
  1420. msg "test: compat.sh NULL (full config)" # ~ 2 min
  1421. env OPENSSL="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '^$' -f 'NULL'
  1422. msg "test: compat.sh ARIA + ChachaPoly"
  1423. env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
  1424. }
  1425. skip_suites_without_constant_flow () {
  1426. # Skip the test suites that don't have any constant-flow annotations.
  1427. # This will need to be adjusted if we ever start declaring things as
  1428. # secret from macros or functions inside tests/include or tests/src.
  1429. SKIP_TEST_SUITES=$(
  1430. git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
  1431. sed 's/test_suite_//; s/\.function$//' |
  1432. tr '\n' ,)
  1433. export SKIP_TEST_SUITES
  1434. }
  1435. component_test_memsan_constant_flow () {
  1436. # This tests both (1) accesses to undefined memory, and (2) branches or
  1437. # memory access depending on secret values. To distinguish between those:
  1438. # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
  1439. # - or alternatively, change the build type to MemSanDbg, which enables
  1440. # origin tracking and nicer stack traces (which are useful for debugging
  1441. # anyway), and check if the origin was TEST_CF_SECRET() or something else.
  1442. msg "build: cmake MSan (clang), full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
  1443. scripts/config.py full
  1444. scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
  1445. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1446. scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
  1447. CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
  1448. make
  1449. msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO, Msan + constant flow)"
  1450. make test
  1451. }
  1452. component_test_memsan_constant_flow_psa () {
  1453. # This tests both (1) accesses to undefined memory, and (2) branches or
  1454. # memory access depending on secret values. To distinguish between those:
  1455. # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
  1456. # - or alternatively, change the build type to MemSanDbg, which enables
  1457. # origin tracking and nicer stack traces (which are useful for debugging
  1458. # anyway), and check if the origin was TEST_CF_SECRET() or something else.
  1459. msg "build: cmake MSan (clang), full config with constant flow testing"
  1460. scripts/config.py full
  1461. scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
  1462. scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
  1463. CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
  1464. make
  1465. msg "test: main suites (Msan + constant flow)"
  1466. make test
  1467. }
  1468. component_test_valgrind_constant_flow () {
  1469. # This tests both (1) everything that valgrind's memcheck usually checks
  1470. # (heap buffer overflows, use of uninitialized memory, use-after-free,
  1471. # etc.) and (2) branches or memory access depending on secret values,
  1472. # which will be reported as uninitialized memory. To distinguish between
  1473. # secret and actually uninitialized:
  1474. # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
  1475. # - or alternatively, build with debug info and manually run the offending
  1476. # test suite with valgrind --track-origins=yes, then check if the origin
  1477. # was TEST_CF_SECRET() or something else.
  1478. msg "build: cmake release GCC, full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
  1479. scripts/config.py full
  1480. scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
  1481. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1482. skip_suites_without_constant_flow
  1483. cmake -D CMAKE_BUILD_TYPE:String=Release .
  1484. make
  1485. # this only shows a summary of the results (how many of each type)
  1486. # details are left in Testing/<date>/DynamicAnalysis.xml
  1487. msg "test: some suites (full minus MBEDTLS_USE_PSA_CRYPTO, valgrind + constant flow)"
  1488. make memcheck
  1489. }
  1490. component_test_valgrind_constant_flow_psa () {
  1491. # This tests both (1) everything that valgrind's memcheck usually checks
  1492. # (heap buffer overflows, use of uninitialized memory, use-after-free,
  1493. # etc.) and (2) branches or memory access depending on secret values,
  1494. # which will be reported as uninitialized memory. To distinguish between
  1495. # secret and actually uninitialized:
  1496. # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
  1497. # - or alternatively, build with debug info and manually run the offending
  1498. # test suite with valgrind --track-origins=yes, then check if the origin
  1499. # was TEST_CF_SECRET() or something else.
  1500. msg "build: cmake release GCC, full config with constant flow testing"
  1501. scripts/config.py full
  1502. scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
  1503. skip_suites_without_constant_flow
  1504. cmake -D CMAKE_BUILD_TYPE:String=Release .
  1505. make
  1506. # this only shows a summary of the results (how many of each type)
  1507. # details are left in Testing/<date>/DynamicAnalysis.xml
  1508. msg "test: some suites (valgrind + constant flow)"
  1509. make memcheck
  1510. }
  1511. component_test_default_no_deprecated () {
  1512. # Test that removing the deprecated features from the default
  1513. # configuration leaves something consistent.
  1514. msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
  1515. scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
  1516. make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
  1517. msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
  1518. make test
  1519. }
  1520. component_test_full_no_deprecated () {
  1521. msg "build: make, full_no_deprecated config" # ~ 30s
  1522. scripts/config.py full_no_deprecated
  1523. make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
  1524. msg "test: make, full_no_deprecated config" # ~ 5s
  1525. make test
  1526. msg "test: ensure that X509 has no direct dependency on BIGNUM_C"
  1527. not grep mbedtls_mpi library/libmbedx509.a
  1528. }
  1529. component_test_full_no_deprecated_deprecated_warning () {
  1530. # Test that there is nothing deprecated in "full_no_deprecated".
  1531. # A deprecated feature would trigger a warning (made fatal) from
  1532. # MBEDTLS_DEPRECATED_WARNING.
  1533. msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
  1534. scripts/config.py full_no_deprecated
  1535. scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
  1536. scripts/config.py set MBEDTLS_DEPRECATED_WARNING
  1537. make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
  1538. msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
  1539. make test
  1540. }
  1541. component_test_full_deprecated_warning () {
  1542. # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
  1543. # with only certain whitelisted types of warnings.
  1544. msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
  1545. scripts/config.py full
  1546. scripts/config.py set MBEDTLS_DEPRECATED_WARNING
  1547. # Expect warnings from '#warning' directives in check_config.h.
  1548. make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
  1549. msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
  1550. # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
  1551. # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
  1552. # Expect warnings from '#warning' directives in check_config.h and
  1553. # from the use of deprecated functions in test suites.
  1554. make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=deprecated-declarations -Wno-error=cpp -DMBEDTLS_TEST_DEPRECATED' tests
  1555. msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
  1556. make test
  1557. }
  1558. # Check that the specified libraries exist and are empty.
  1559. are_empty_libraries () {
  1560. nm "$@" >/dev/null 2>/dev/null
  1561. ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
  1562. }
  1563. component_build_crypto_default () {
  1564. msg "build: make, crypto only"
  1565. scripts/config.py crypto
  1566. make CFLAGS='-O1 -Werror'
  1567. are_empty_libraries library/libmbedx509.* library/libmbedtls.*
  1568. }
  1569. component_build_crypto_full () {
  1570. msg "build: make, crypto only, full config"
  1571. scripts/config.py crypto_full
  1572. make CFLAGS='-O1 -Werror'
  1573. are_empty_libraries library/libmbedx509.* library/libmbedtls.*
  1574. }
  1575. component_test_crypto_for_psa_service () {
  1576. msg "build: make, config for PSA crypto service"
  1577. scripts/config.py crypto
  1578. scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
  1579. # Disable things that are not needed for just cryptography, to
  1580. # reach a configuration that would be typical for a PSA cryptography
  1581. # service providing all implemented PSA algorithms.
  1582. # System stuff
  1583. scripts/config.py unset MBEDTLS_ERROR_C
  1584. scripts/config.py unset MBEDTLS_TIMING_C
  1585. scripts/config.py unset MBEDTLS_VERSION_FEATURES
  1586. # Crypto stuff with no PSA interface
  1587. scripts/config.py unset MBEDTLS_BASE64_C
  1588. # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
  1589. scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
  1590. # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
  1591. scripts/config.py unset MBEDTLS_NIST_KW_C
  1592. scripts/config.py unset MBEDTLS_PEM_PARSE_C
  1593. scripts/config.py unset MBEDTLS_PEM_WRITE_C
  1594. scripts/config.py unset MBEDTLS_PKCS12_C
  1595. scripts/config.py unset MBEDTLS_PKCS5_C
  1596. # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
  1597. # in PSA code to work with RSA keys. We don't require users to set those:
  1598. # they will be reenabled in build_info.h.
  1599. scripts/config.py unset MBEDTLS_PK_C
  1600. scripts/config.py unset MBEDTLS_PK_PARSE_C
  1601. scripts/config.py unset MBEDTLS_PK_WRITE_C
  1602. make CFLAGS='-O1 -Werror' all test
  1603. are_empty_libraries library/libmbedx509.* library/libmbedtls.*
  1604. }
  1605. component_build_crypto_baremetal () {
  1606. msg "build: make, crypto only, baremetal config"
  1607. scripts/config.py crypto_baremetal
  1608. make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
  1609. are_empty_libraries library/libmbedx509.* library/libmbedtls.*
  1610. }
  1611. support_build_crypto_baremetal () {
  1612. support_build_baremetal "$@"
  1613. }
  1614. component_build_baremetal () {
  1615. msg "build: make, baremetal config"
  1616. scripts/config.py baremetal
  1617. make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
  1618. }
  1619. support_build_baremetal () {
  1620. # Older Glibc versions include time.h from other headers such as stdlib.h,
  1621. # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
  1622. # problem, Ubuntu 18.04 is ok.
  1623. ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
  1624. }
  1625. # depends.py family of tests
  1626. component_test_depends_py_cipher_id () {
  1627. msg "test/build: depends.py cipher_id (gcc)"
  1628. tests/scripts/depends.py cipher_id --unset-use-psa
  1629. }
  1630. component_test_depends_py_cipher_chaining () {
  1631. msg "test/build: depends.py cipher_chaining (gcc)"
  1632. tests/scripts/depends.py cipher_chaining --unset-use-psa
  1633. }
  1634. component_test_depends_py_cipher_padding () {
  1635. msg "test/build: depends.py cipher_padding (gcc)"
  1636. tests/scripts/depends.py cipher_padding --unset-use-psa
  1637. }
  1638. component_test_depends_py_curves () {
  1639. msg "test/build: depends.py curves (gcc)"
  1640. tests/scripts/depends.py curves --unset-use-psa
  1641. }
  1642. component_test_depends_py_hashes () {
  1643. msg "test/build: depends.py hashes (gcc)"
  1644. tests/scripts/depends.py hashes --unset-use-psa
  1645. }
  1646. component_test_depends_py_kex () {
  1647. msg "test/build: depends.py kex (gcc)"
  1648. tests/scripts/depends.py kex --unset-use-psa
  1649. }
  1650. component_test_depends_py_pkalgs () {
  1651. msg "test/build: depends.py pkalgs (gcc)"
  1652. tests/scripts/depends.py pkalgs --unset-use-psa
  1653. }
  1654. # PSA equivalents of the depends.py tests
  1655. component_test_depends_py_cipher_id_psa () {
  1656. msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
  1657. tests/scripts/depends.py cipher_id
  1658. }
  1659. component_test_depends_py_cipher_chaining_psa () {
  1660. msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
  1661. tests/scripts/depends.py cipher_chaining
  1662. }
  1663. component_test_depends_py_cipher_padding_psa () {
  1664. msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
  1665. tests/scripts/depends.py cipher_padding
  1666. }
  1667. component_test_depends_py_curves_psa () {
  1668. msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
  1669. tests/scripts/depends.py curves
  1670. }
  1671. component_test_depends_py_hashes_psa () {
  1672. msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
  1673. tests/scripts/depends.py hashes
  1674. }
  1675. component_test_depends_py_kex_psa () {
  1676. msg "test/build: depends.py kex (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
  1677. tests/scripts/depends.py kex
  1678. }
  1679. component_test_depends_py_pkalgs_psa () {
  1680. msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
  1681. tests/scripts/depends.py pkalgs
  1682. }
  1683. component_build_no_pk_rsa_alt_support () {
  1684. msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
  1685. scripts/config.py full
  1686. scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
  1687. scripts/config.py set MBEDTLS_RSA_C
  1688. scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
  1689. # Only compile - this is primarily to test for compile issues
  1690. make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
  1691. }
  1692. component_build_module_alt () {
  1693. msg "build: MBEDTLS_XXX_ALT" # ~30s
  1694. scripts/config.py full
  1695. # Disable options that are incompatible with some ALT implementations:
  1696. # aesni.c and padlock.c reference mbedtls_aes_context fields directly.
  1697. scripts/config.py unset MBEDTLS_AESNI_C
  1698. scripts/config.py unset MBEDTLS_PADLOCK_C
  1699. scripts/config.py unset MBEDTLS_AESCE_C
  1700. # MBEDTLS_ECP_RESTARTABLE is documented as incompatible.
  1701. scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
  1702. # You can only have one threading implementation: alt or pthread, not both.
  1703. scripts/config.py unset MBEDTLS_THREADING_PTHREAD
  1704. # The SpecifiedECDomain parsing code accesses mbedtls_ecp_group fields
  1705. # directly and assumes the implementation works with partial groups.
  1706. scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
  1707. # MBEDTLS_SHA256_*ALT can't be used with MBEDTLS_SHA256_USE_A64_CRYPTO_*
  1708. scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
  1709. scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
  1710. # MBEDTLS_SHA512_*ALT can't be used with MBEDTLS_SHA512_USE_A64_CRYPTO_*
  1711. scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
  1712. scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY
  1713. # Enable all MBEDTLS_XXX_ALT for whole modules. Do not enable
  1714. # MBEDTLS_XXX_YYY_ALT which are for single functions.
  1715. scripts/config.py set-all 'MBEDTLS_([A-Z0-9]*|NIST_KW)_ALT'
  1716. scripts/config.py unset MBEDTLS_DHM_ALT #incompatible with MBEDTLS_DEBUG_C
  1717. # We can only compile, not link, since we don't have any implementations
  1718. # suitable for testing with the dummy alt headers.
  1719. make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
  1720. }
  1721. component_build_dhm_alt () {
  1722. msg "build: MBEDTLS_DHM_ALT" # ~30s
  1723. scripts/config.py full
  1724. scripts/config.py set MBEDTLS_DHM_ALT
  1725. # debug.c currently references mbedtls_dhm_context fields directly.
  1726. scripts/config.py unset MBEDTLS_DEBUG_C
  1727. # We can only compile, not link, since we don't have any implementations
  1728. # suitable for testing with the dummy alt headers.
  1729. make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
  1730. }
  1731. component_test_no_use_psa_crypto_full_cmake_asan() {
  1732. # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
  1733. msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
  1734. scripts/config.py full
  1735. scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
  1736. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  1737. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  1738. scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
  1739. scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
  1740. scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
  1741. scripts/config.py unset MBEDTLS_LMS_C
  1742. scripts/config.py unset MBEDTLS_LMS_PRIVATE
  1743. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  1744. make
  1745. msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
  1746. make test
  1747. # Note: ssl-opt.sh has some test cases that depend on
  1748. # MBEDTLS_ECP_RESTARTABLE && !MBEDTLS_USE_PSA_CRYPTO
  1749. # This is the only component where those tests are not skipped.
  1750. msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
  1751. tests/ssl-opt.sh
  1752. msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
  1753. tests/compat.sh
  1754. msg "test: compat.sh NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
  1755. env OPENSSL="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -f 'NULL'
  1756. msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
  1757. env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
  1758. }
  1759. component_test_psa_crypto_config_accel_ecdsa () {
  1760. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
  1761. # Algorithms and key types to accelerate
  1762. loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA KEY_TYPE_ECC_KEY_PAIR KEY_TYPE_ECC_PUBLIC_KEY"
  1763. # Configure and build the test driver library
  1764. # -------------------------------------------
  1765. # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
  1766. # partial support for cipher operations in the driver test library.
  1767. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
  1768. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
  1769. loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
  1770. # These hashes are needed for some ECDSA signature tests.
  1771. loc_accel_flags="$loc_accel_flags -DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_ALG_SHA_224"
  1772. loc_accel_flags="$loc_accel_flags -DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_ALG_SHA_256"
  1773. loc_accel_flags="$loc_accel_flags -DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_ALG_SHA_384"
  1774. loc_accel_flags="$loc_accel_flags -DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_ALG_SHA_512"
  1775. make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
  1776. # Configure and build the main libraries
  1777. # --------------------------------------
  1778. # Start from default config (no USE_PSA) + driver support + TLS 1.3
  1779. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1780. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1781. scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3
  1782. # Disable the module that's accelerated
  1783. scripts/config.py unset MBEDTLS_ECDSA_C
  1784. # Disable things that depend on it
  1785. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
  1786. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
  1787. # Build the library
  1788. loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
  1789. make CFLAGS="$ASAN_CFLAGS -O -Werror -I../tests/include -I../tests -I../../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
  1790. # Make sure this was not re-enabled by accident (additive config)
  1791. not grep mbedtls_ecdsa_ library/ecdsa.o
  1792. # Run the tests
  1793. # -------------
  1794. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
  1795. make test
  1796. }
  1797. # Auxiliary function to build config for ECDSA with and without drivers
  1798. config_psa_crypto_config_ecdsa_use_psa () {
  1799. DRIVER_ONLY="$1"
  1800. # start with config full for maximum coverage (also enables USE_PSA)
  1801. scripts/config.py full
  1802. # enable support for drivers and configuring PSA-only algorithms
  1803. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1804. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1805. if [ "$DRIVER_ONLY" -eq 1 ]; then
  1806. # Disable the module that's accelerated
  1807. scripts/config.py unset MBEDTLS_ECDSA_C
  1808. fi
  1809. # Restartable feature is not yet supported by PSA. Once it will in
  1810. # the future, the following line could be removed (see issues
  1811. # 6061, 6332 and following ones)
  1812. scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
  1813. # Dynamic secure element support is a deprecated feature and needs to be disabled here.
  1814. # This is done to have the same form of psa_key_attributes_s for libdriver and library.
  1815. scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
  1816. }
  1817. # Keep in sync with component_test_psa_crypto_config_reference_ecdsa_use_psa
  1818. component_test_psa_crypto_config_accel_ecdsa_use_psa () {
  1819. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA + USE_PSA"
  1820. # Algorithms and key types to accelerate
  1821. loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA KEY_TYPE_ECC_KEY_PAIR KEY_TYPE_ECC_PUBLIC_KEY"
  1822. # Configure and build the test driver library
  1823. # -------------------------------------------
  1824. # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
  1825. # partial support for cipher operations in the driver test library.
  1826. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
  1827. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
  1828. loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
  1829. # SHA-1 and all variants of SHA-2 are needed for ECDSA and X.509 tests
  1830. loc_accel_flags="$loc_accel_flags -DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_ALG_SHA_1"
  1831. loc_accel_flags="$loc_accel_flags -DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_ALG_SHA_224"
  1832. loc_accel_flags="$loc_accel_flags -DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_ALG_SHA_256"
  1833. loc_accel_flags="$loc_accel_flags -DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_ALG_SHA_384"
  1834. loc_accel_flags="$loc_accel_flags -DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_ALG_SHA_512"
  1835. make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
  1836. # Configure and build the main libraries with drivers enabled
  1837. # -----------------------------------------------------------
  1838. # Use the same config as reference, only without built-in ECDSA
  1839. config_psa_crypto_config_ecdsa_use_psa 1
  1840. # Build the library
  1841. loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
  1842. make CFLAGS="$ASAN_CFLAGS -O -Werror -I../tests/include -I../tests -I../../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
  1843. # Make sure ECDSA was not re-enabled by accident (additive config)
  1844. not grep mbedtls_ecdsa_ library/ecdsa.o
  1845. # Run the tests
  1846. # -------------
  1847. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA + USE_PSA"
  1848. make test
  1849. msg "test: ssl-opt.sh"
  1850. tests/ssl-opt.sh
  1851. }
  1852. # Keep in sync with component_test_psa_crypto_config_accel_ecdsa_use_psa.
  1853. # Used by tests/scripts/analyze_outcomes.py for comparison purposes.
  1854. component_test_psa_crypto_config_reference_ecdsa_use_psa () {
  1855. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA + USE_PSA"
  1856. # To be aligned with the accel component that needs this
  1857. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
  1858. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
  1859. config_psa_crypto_config_ecdsa_use_psa 0
  1860. make
  1861. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA + USE_PSA"
  1862. make test
  1863. msg "test: ssl-opt.sh"
  1864. tests/ssl-opt.sh
  1865. }
  1866. component_test_psa_crypto_config_accel_ecdh () {
  1867. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
  1868. # Algorithms and key types to accelerate
  1869. loc_accel_list="ALG_ECDH KEY_TYPE_ECC_KEY_PAIR KEY_TYPE_ECC_PUBLIC_KEY"
  1870. # Configure and build the test driver library
  1871. # -------------------------------------------
  1872. # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
  1873. # partial support for cipher operations in the driver test library.
  1874. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
  1875. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
  1876. loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
  1877. make -C tests libtestdriver1.a CFLAGS=" $ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
  1878. # Configure and build the main libraries
  1879. # --------------------------------------
  1880. # Start from default config (no USE_PSA or TLS 1.3) + driver support
  1881. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1882. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1883. # Disable the module that's accelerated
  1884. scripts/config.py unset MBEDTLS_ECDH_C
  1885. # Disable things that depend on it
  1886. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
  1887. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
  1888. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
  1889. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
  1890. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
  1891. # Build the main library
  1892. loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
  1893. make CFLAGS="$ASAN_CFLAGS -O -Werror -I../tests/include -I../tests -I../../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
  1894. # Make sure this was not re-enabled by accident (additive config)
  1895. not grep mbedtls_ecdh_ library/ecdh.o
  1896. # Run the tests
  1897. # -------------
  1898. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
  1899. make test
  1900. }
  1901. # Auxiliary function to build config for ECDH with and without drivers.
  1902. #
  1903. # This is used by the two following components to ensure they always use the
  1904. # same config, except for the use of driver or built-in ECDH:
  1905. # - component_test_psa_crypto_config_accel_ecdh_use_psa;
  1906. # - component_test_psa_crypto_config_reference_ecdh_use_psa.
  1907. # This support comparing their test coverage with analyze_outcomes.py.
  1908. config_psa_crypto_config_ecdh_use_psa () {
  1909. DRIVER_ONLY="$1"
  1910. # start with config full for maximum coverage (also enables USE_PSA)
  1911. scripts/config.py full
  1912. # enable support for drivers and configuring PSA-only algorithms
  1913. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1914. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1915. if [ "$DRIVER_ONLY" -eq 1 ]; then
  1916. # Disable the module that's accelerated
  1917. scripts/config.py unset MBEDTLS_ECDH_C
  1918. fi
  1919. # Disable things that depend on it (regardless of driver or built-in)
  1920. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
  1921. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
  1922. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
  1923. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
  1924. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
  1925. scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
  1926. scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
  1927. # Note: the above two lines should be enough, but currently there's a bug
  1928. # that prevents tests from passing TLS 1.3 with only PSK (no ephemeral)
  1929. # when TLS 1.2 is also enabled, see #6848.
  1930. # So, as a temporary measure disable all of TLS 1.3.
  1931. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  1932. # Restartable feature is not yet supported by PSA. Once it will in
  1933. # the future, the following line could be removed (see issues
  1934. # 6061, 6332 and following ones)
  1935. scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
  1936. }
  1937. # Keep in sync with component_test_psa_crypto_config_reference_ecdh_use_psa
  1938. component_test_psa_crypto_config_accel_ecdh_use_psa () {
  1939. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH + USE_PSA"
  1940. # Algorithms and key types to accelerate
  1941. loc_accel_list="ALG_ECDH KEY_TYPE_ECC_KEY_PAIR KEY_TYPE_ECC_PUBLIC_KEY"
  1942. # Configure and build the test driver library
  1943. # -------------------------------------------
  1944. # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
  1945. # partial support for cipher operations in the driver test library.
  1946. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
  1947. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
  1948. loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
  1949. make -C tests libtestdriver1.a CFLAGS=" $ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
  1950. # Configure and build the main libraries
  1951. # --------------------------------------
  1952. # Use the same config as reference, only without built-in ECDH
  1953. config_psa_crypto_config_ecdh_use_psa 1
  1954. # Build the main library
  1955. loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
  1956. make CFLAGS="$ASAN_CFLAGS -O -Werror -I../tests/include -I../tests -I../../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
  1957. # Make sure this was not re-enabled by accident (additive config)
  1958. not grep mbedtls_ecdh_ library/ecdh.o
  1959. # Run the tests
  1960. # -------------
  1961. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH + USE_PSA"
  1962. make test
  1963. msg "test: ssl-opt.sh"
  1964. tests/ssl-opt.sh
  1965. }
  1966. # Keep in sync with component_test_psa_crypto_config_accel_ecdh_use_psa.
  1967. # Used by tests/scripts/analyze_outcomes.py for comparison purposes.
  1968. component_test_psa_crypto_config_reference_ecdh_use_psa () {
  1969. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with reference ECDH + USE_PSA"
  1970. # To be aligned with the accel component that needs this
  1971. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
  1972. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
  1973. config_psa_crypto_config_ecdh_use_psa 0
  1974. make
  1975. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with reference ECDH + USE_PSA"
  1976. make test
  1977. msg "test: ssl-opt.sh"
  1978. tests/ssl-opt.sh
  1979. }
  1980. # Auxiliary function to build config for EC JPAKE with and without drivers.
  1981. #
  1982. # This is used by the two following components to ensure they always use the
  1983. # same config, except for the use of driver or built-in ECJPAKE:
  1984. # - component_test_psa_crypto_config_accel_ecjpake_use_psa;
  1985. # - component_test_psa_crypto_config_reference_ecjpake_use_psa.
  1986. # This support comparing their test coverage with analyze_outcomes.py.
  1987. config_psa_crypto_config_ecjpake_use_psa () {
  1988. DRIVER_ONLY="$1"
  1989. # start with config full for maximum coverage (also enables USE_PSA)
  1990. scripts/config.py full
  1991. # enable support for drivers and configuring PSA-only algorithms
  1992. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  1993. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  1994. if [ "$DRIVER_ONLY" -eq 1 ]; then
  1995. # Disable the module that's accelerated
  1996. scripts/config.py unset MBEDTLS_ECJPAKE_C
  1997. fi
  1998. # Dynamic secure element support is a deprecated feature and needs to be disabled here.
  1999. # This is done to have the same form of psa_key_attributes_s for libdriver and library.
  2000. scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
  2001. }
  2002. # Keep in sync with component_test_psa_crypto_config_reference_ecjpake_use_psa
  2003. component_test_psa_crypto_config_accel_ecjpake_use_psa () {
  2004. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECJPAKE + USE_PSA"
  2005. # Algorithms and key types to accelerate
  2006. loc_accel_list="ALG_JPAKE KEY_TYPE_ECC_KEY_PAIR KEY_TYPE_ECC_PUBLIC_KEY"
  2007. # Configure and build the test driver library
  2008. # -------------------------------------------
  2009. # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
  2010. # partial support for cipher operations in the driver test library.
  2011. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
  2012. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
  2013. loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
  2014. make -C tests libtestdriver1.a CFLAGS=" $ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
  2015. # Configure and build the main libraries
  2016. # --------------------------------------
  2017. # Use the same config as reference, only without built-in JPAKE
  2018. config_psa_crypto_config_ecjpake_use_psa 1
  2019. # Build the main library
  2020. loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
  2021. make CFLAGS="$ASAN_CFLAGS -O -Werror -I../tests/include -I../tests -I../../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
  2022. # Make sure this was not re-enabled by accident (additive config)
  2023. not grep mbedtls_ecjpake_ library/ecjpake.o
  2024. # Run the tests
  2025. # -------------
  2026. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated JPAKE + USE_PSA"
  2027. make test
  2028. msg "test: ssl-opt.sh"
  2029. tests/ssl-opt.sh
  2030. }
  2031. # Keep in sync with component_test_psa_crypto_config_accel_ecjpake_use_psa.
  2032. # Used by tests/scripts/analyze_outcomes.py for comparison purposes.
  2033. component_test_psa_crypto_config_reference_ecjpake_use_psa () {
  2034. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with reference ECJPAKE + USE_PSA"
  2035. # To be aligned with the accel component that needs this
  2036. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
  2037. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
  2038. config_psa_crypto_config_ecjpake_use_psa 0
  2039. make
  2040. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with reference ECJPAKE + USE_PSA"
  2041. make test
  2042. msg "test: ssl-opt.sh"
  2043. tests/ssl-opt.sh
  2044. }
  2045. component_test_psa_crypto_config_accel_ecc () {
  2046. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECC"
  2047. # Algorithms and key types to accelerate
  2048. loc_accel_list="ALG_ECDH ALG_ECDSA ALG_DETERMINISTIC_ECDSA ALG_JPAKE KEY_TYPE_ECC_KEY_PAIR KEY_TYPE_ECC_PUBLIC_KEY"
  2049. # Configure and build the test driver library
  2050. # --------------------------------------------
  2051. # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
  2052. # partial support for cipher operations in the driver test library.
  2053. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
  2054. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
  2055. loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
  2056. # These hashes are needed for some ECDSA signature tests.
  2057. loc_accel_flags="$loc_accel_flags -DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_ALG_SHA_224"
  2058. loc_accel_flags="$loc_accel_flags -DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_ALG_SHA_256"
  2059. loc_accel_flags="$loc_accel_flags -DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_ALG_SHA_384"
  2060. loc_accel_flags="$loc_accel_flags -DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_ALG_SHA_512"
  2061. make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
  2062. # Configure and build the main libraries
  2063. # ---------------------------------------
  2064. # start with default + driver support
  2065. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2066. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2067. # disable modules for which we have drivers
  2068. scripts/config.py unset MBEDTLS_ECDSA_C
  2069. scripts/config.py unset MBEDTLS_ECDH_C
  2070. scripts/config.py unset MBEDTLS_ECJPAKE_C
  2071. # dependencies
  2072. #scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 # not in default anyway
  2073. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
  2074. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
  2075. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
  2076. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
  2077. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
  2078. # build and link with test drivers
  2079. loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
  2080. make CFLAGS="$ASAN_CFLAGS -I../tests/include -I../tests -I../../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
  2081. # make sure these were not auto-re-enabled by accident
  2082. not grep mbedtls_ecdh_ library/ecdh.o
  2083. not grep mbedtls_ecdsa_ library/ecdsa.o
  2084. not grep mbedtls_ecjpake_ library/ecjpake.o
  2085. # Run the tests
  2086. # -------------
  2087. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECC"
  2088. make test
  2089. }
  2090. component_test_psa_crypto_config_accel_rsa_signature () {
  2091. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
  2092. # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
  2093. # partial support for cipher operations in the driver test library.
  2094. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
  2095. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
  2096. # It seems it is not possible to remove only the support for RSA signature
  2097. # in the library. Thus we have to remove all RSA support (signature and
  2098. # encryption/decryption). AS there is no driver support for asymmetric
  2099. # encryption/decryption so far remove RSA encryption/decryption from the
  2100. # application algorithm list.
  2101. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
  2102. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
  2103. # Make sure both the library and the test library support the SHA hash
  2104. # algorithms and only those ones (SHA256 is included by default). That way:
  2105. # - the test library can compute the RSA signatures even in the case of a
  2106. # composite RSA signature algorithm based on a SHA hash (no other hash
  2107. # used in the unit tests).
  2108. # - the dependency of RSA signature tests on PSA_WANT_ALG_SHA_xyz is
  2109. # fulfilled as the hash SHA algorithm is supported by the library, and
  2110. # thus the tests are run, not skipped.
  2111. # - when testing a signature key with an algorithm wildcard built from
  2112. # PSA_ALG_ANY_HASH as algorithm to test with the key, the chosen hash
  2113. # algorithm based on the hashes supported by the library is also
  2114. # supported by the test library.
  2115. # Disabled unwanted hashes here, we'll enable hashes we want in loc_accel_flags.
  2116. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
  2117. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160_C
  2118. # We need PEM parsing in the test library as well to support the import
  2119. # of PEM encoded RSA keys.
  2120. scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_PEM_PARSE_C
  2121. scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_BASE64_C
  2122. loc_accel_list="ALG_RSA_PKCS1V15_SIGN ALG_RSA_PSS KEY_TYPE_RSA_KEY_PAIR KEY_TYPE_RSA_PUBLIC_KEY"
  2123. loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
  2124. # These hashes are needed for some RSA-PSS signature tests.
  2125. loc_accel_flags="$loc_accel_flags -DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_ALG_SHA_1"
  2126. loc_accel_flags="$loc_accel_flags -DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_ALG_SHA_224"
  2127. loc_accel_flags="$loc_accel_flags -DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_ALG_SHA_256"
  2128. loc_accel_flags="$loc_accel_flags -DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_ALG_SHA_384"
  2129. loc_accel_flags="$loc_accel_flags -DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_ALG_SHA_512"
  2130. make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
  2131. # Mbed TLS library build
  2132. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2133. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2134. # Remove RSA support and its dependencies
  2135. scripts/config.py unset MBEDTLS_PKCS1_V15
  2136. scripts/config.py unset MBEDTLS_PKCS1_V21
  2137. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
  2138. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
  2139. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
  2140. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
  2141. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
  2142. scripts/config.py unset MBEDTLS_RSA_C
  2143. scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
  2144. scripts/config.py unset MBEDTLS_MD5_C
  2145. scripts/config.py unset MBEDTLS_RIPEMD160_C
  2146. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
  2147. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
  2148. scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
  2149. loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
  2150. make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -I../../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
  2151. not grep mbedtls_rsa_rsassa_pkcs1_v15_sign library/rsa.o
  2152. not grep mbedtls_rsa_rsassa_pss_sign_ext library/rsa.o
  2153. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
  2154. make test
  2155. }
  2156. component_test_psa_crypto_config_accel_hash () {
  2157. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
  2158. # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
  2159. # partial support for cipher operations in the driver test library.
  2160. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
  2161. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
  2162. loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
  2163. loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
  2164. make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
  2165. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2166. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2167. scripts/config.py unset MBEDTLS_MD5_C
  2168. scripts/config.py unset MBEDTLS_RIPEMD160_C
  2169. scripts/config.py unset MBEDTLS_SHA1_C
  2170. # Don't unset MBEDTLS_SHA256_C as it is needed by PSA crypto core.
  2171. scripts/config.py unset MBEDTLS_SHA384_C
  2172. scripts/config.py unset MBEDTLS_SHA512_C
  2173. loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
  2174. make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -I../../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
  2175. not grep mbedtls_sha512_init library/sha512.o
  2176. not grep mbedtls_sha1_init library/sha1.o
  2177. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
  2178. make test
  2179. }
  2180. component_test_psa_crypto_config_accel_hash_keep_builtins () {
  2181. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
  2182. # This component ensures that all the test cases for
  2183. # md_psa_dynamic_dispatch with legacy+driver in test_suite_md are run.
  2184. # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
  2185. # partial support for cipher operations in the driver test library.
  2186. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
  2187. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
  2188. loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
  2189. loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
  2190. make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
  2191. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2192. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2193. loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
  2194. make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -I../../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
  2195. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
  2196. make test
  2197. }
  2198. # Auxiliary function to build config for hashes with and without drivers
  2199. config_psa_crypto_hash_use_psa () {
  2200. DRIVER_ONLY="$1"
  2201. # start with config full for maximum coverage (also enables USE_PSA)
  2202. scripts/config.py full
  2203. # enable support for drivers and configuring PSA-only algorithms
  2204. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2205. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2206. if [ "$DRIVER_ONLY" -eq 1 ]; then
  2207. # disable the built-in implementation of hashes
  2208. scripts/config.py unset MBEDTLS_MD5_C
  2209. scripts/config.py unset MBEDTLS_RIPEMD160_C
  2210. scripts/config.py unset MBEDTLS_SHA1_C
  2211. scripts/config.py unset MBEDTLS_SHA224_C
  2212. scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below
  2213. scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
  2214. scripts/config.py unset MBEDTLS_SHA384_C
  2215. scripts/config.py unset MBEDTLS_SHA512_C
  2216. scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
  2217. fi
  2218. # Use an external RNG as currently internal RNGs depend on entropy.c
  2219. # which in turn hard-depends on SHA256_C (or SHA512_C).
  2220. # See component_test_psa_external_rng_no_drbg_use_psa.
  2221. scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
  2222. scripts/config.py unset MBEDTLS_ENTROPY_C
  2223. scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED # depends on ENTROPY_C
  2224. scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT # depends on former
  2225. # Also unset MD_C and things that depend on it.
  2226. if [ "$DRIVER_ONLY" -eq 1 ]; then
  2227. scripts/config.py unset MBEDTLS_MD_C
  2228. fi
  2229. scripts/config.py unset MBEDTLS_HKDF_C # has independent PSA implementation
  2230. scripts/config.py unset MBEDTLS_HMAC_DRBG_C
  2231. scripts/config.py unset MBEDTLS_PKCS7_C
  2232. scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC
  2233. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
  2234. # Dynamic secure element support is a deprecated feature and needs to be disabled here.
  2235. # This is done to have the same form of psa_key_attributes_s for libdriver and library.
  2236. scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
  2237. }
  2238. # Note that component_test_psa_crypto_config_reference_hash_use_psa
  2239. # is related to this component and both components need to be kept in sync.
  2240. # For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
  2241. component_test_psa_crypto_config_accel_hash_use_psa () {
  2242. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash and USE_PSA"
  2243. # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
  2244. # partial support for cipher operations in the driver test library.
  2245. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
  2246. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
  2247. loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
  2248. loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
  2249. make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
  2250. config_psa_crypto_hash_use_psa 1
  2251. loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
  2252. make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -I../../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS" all
  2253. # There's a risk of something getting re-enabled via config_psa.h;
  2254. # make sure it did not happen. Note: it's OK for MD_LIGHT to be enabled,
  2255. # but not the full MD_C (for now), so check mbedtls_md_hmac for that.
  2256. not grep mbedtls_md_hmac library/md.o
  2257. not grep mbedtls_md5 library/md5.o
  2258. not grep mbedtls_sha1 library/sha1.o
  2259. not grep mbedtls_sha256 library/sha256.o
  2260. not grep mbedtls_sha512 library/sha512.o
  2261. not grep mbedtls_ripemd160 library/ripemd160.o
  2262. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash and USE_PSA"
  2263. make test
  2264. # This is mostly useful so that we can later compare outcome files with
  2265. # the reference config in analyze_outcomes.py, to check that the
  2266. # dependency declarations in ssl-opt.sh and in TLS code are correct.
  2267. msg "test: ssl-opt.sh, MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash and USE_PSA"
  2268. tests/ssl-opt.sh
  2269. # This is to make sure all ciphersuites are exercised, but we don't need
  2270. # interop testing (besides, we already got some from ssl-opt.sh).
  2271. msg "test: compat.sh, MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash and USE_PSA"
  2272. tests/compat.sh -p mbedTLS -V YES
  2273. }
  2274. # This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
  2275. # without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
  2276. # script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
  2277. # Both components need to be kept in sync.
  2278. component_test_psa_crypto_config_reference_hash_use_psa() {
  2279. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG without accelerated hash and USE_PSA"
  2280. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
  2281. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
  2282. config_psa_crypto_hash_use_psa 0
  2283. make
  2284. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG without accelerated hash and USE_PSA"
  2285. make test
  2286. msg "test: ssl-opt.sh, MBEDTLS_PSA_CRYPTO_CONFIG without accelerated hash and USE_PSA"
  2287. tests/ssl-opt.sh
  2288. }
  2289. component_test_psa_crypto_config_accel_cipher () {
  2290. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
  2291. loc_accel_list="ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB ALG_OFB ALG_XTS KEY_TYPE_DES"
  2292. loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
  2293. make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
  2294. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2295. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2296. # There is no intended accelerator support for ALG STREAM_CIPHER and
  2297. # ALG_ECB_NO_PADDING. Therefore, asking for them in the build implies the
  2298. # inclusion of the Mbed TLS cipher operations. As we want to test here with
  2299. # cipher operations solely supported by accelerators, disabled those
  2300. # PSA configuration options.
  2301. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
  2302. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
  2303. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_CMAC
  2304. scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
  2305. scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
  2306. scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
  2307. scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
  2308. scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
  2309. scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
  2310. scripts/config.py unset MBEDTLS_DES_C
  2311. loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
  2312. make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -I../../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
  2313. not grep mbedtls_des* library/des.o
  2314. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
  2315. make test
  2316. }
  2317. component_test_psa_crypto_config_accel_aead () {
  2318. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
  2319. # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
  2320. # partial support for cipher operations in the driver test library.
  2321. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
  2322. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
  2323. loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
  2324. loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
  2325. make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
  2326. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2327. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2328. scripts/config.py unset MBEDTLS_GCM_C
  2329. scripts/config.py unset MBEDTLS_CCM_C
  2330. scripts/config.py unset MBEDTLS_CHACHAPOLY_C
  2331. # Features that depend on AEAD
  2332. scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
  2333. scripts/config.py unset MBEDTLS_SSL_TICKET_C
  2334. loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
  2335. make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -I../../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
  2336. # There's a risk of something getting re-enabled via config_psa.h
  2337. # make sure it did not happen.
  2338. not grep mbedtls_ccm library/ccm.o
  2339. not grep mbedtls_gcm library/gcm.o
  2340. not grep mbedtls_chachapoly library/chachapoly.o
  2341. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
  2342. make test
  2343. }
  2344. component_test_psa_crypto_config_accel_pake() {
  2345. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated PAKE"
  2346. # Start with full
  2347. scripts/config.py full
  2348. # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
  2349. # partial support for cipher operations in the driver test library.
  2350. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
  2351. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
  2352. loc_accel_list="ALG_JPAKE"
  2353. loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
  2354. make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
  2355. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2356. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2357. # Make build-in fallback not available
  2358. scripts/config.py unset MBEDTLS_ECJPAKE_C
  2359. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
  2360. # Dynamic secure element support is a deprecated feature and needs to be disabled here.
  2361. # This is done to have the same form of psa_key_attributes_s for libdriver and library.
  2362. scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
  2363. loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
  2364. make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -I../../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
  2365. not grep mbedtls_ecjpake_init library/ecjpake.o
  2366. msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated PAKE"
  2367. make test
  2368. }
  2369. component_test_psa_crypto_config_no_driver() {
  2370. # full plus MBEDTLS_PSA_CRYPTO_CONFIG
  2371. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
  2372. scripts/config.py full
  2373. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2374. scripts/config.py unset MBEDTLS_PSA_CRYPTO_DRIVERS
  2375. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  2376. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  2377. make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
  2378. msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
  2379. make test
  2380. }
  2381. component_test_psa_crypto_config_chachapoly_disabled() {
  2382. # full minus MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305
  2383. msg "build: full minus MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305"
  2384. scripts/config.py full
  2385. scripts/config.py unset MBEDTLS_CHACHAPOLY_C
  2386. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_GCM
  2387. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_CHACHA20_POLY1305
  2388. make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
  2389. msg "test: full minus MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305"
  2390. make test
  2391. }
  2392. # This should be renamed to test and updated once the accelerator ECDH code is in place and ready to test.
  2393. component_build_psa_accel_alg_ecdh() {
  2394. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_ECDH
  2395. # without MBEDTLS_ECDH_C
  2396. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
  2397. scripts/config.py full
  2398. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2399. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2400. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  2401. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  2402. scripts/config.py unset MBEDTLS_ECDH_C
  2403. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
  2404. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
  2405. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
  2406. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
  2407. scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
  2408. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  2409. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  2410. }
  2411. # This should be renamed to test and updated once the accelerator ECC key pair code is in place and ready to test.
  2412. component_build_psa_accel_key_type_ecc_key_pair() {
  2413. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
  2414. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR"
  2415. scripts/config.py full
  2416. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2417. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2418. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  2419. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  2420. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_KEY_PAIR 1
  2421. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
  2422. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  2423. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  2424. }
  2425. # This should be renamed to test and updated once the accelerator ECC public key code is in place and ready to test.
  2426. component_build_psa_accel_key_type_ecc_public_key() {
  2427. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY
  2428. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY"
  2429. scripts/config.py full
  2430. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2431. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2432. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  2433. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  2434. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
  2435. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
  2436. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  2437. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  2438. }
  2439. # This should be renamed to test and updated once the accelerator HMAC code is in place and ready to test.
  2440. component_build_psa_accel_alg_hmac() {
  2441. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HMAC
  2442. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HMAC"
  2443. scripts/config.py full
  2444. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2445. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2446. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  2447. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  2448. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  2449. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  2450. }
  2451. # This should be renamed to test and updated once the accelerator HKDF code is in place and ready to test.
  2452. component_build_psa_accel_alg_hkdf() {
  2453. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HKDF
  2454. # without MBEDTLS_HKDF_C
  2455. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
  2456. scripts/config.py full
  2457. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2458. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2459. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  2460. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  2461. scripts/config.py unset MBEDTLS_HKDF_C
  2462. # Make sure to unset TLS1_3 since it requires HKDF_C and will not build properly without it.
  2463. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  2464. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  2465. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  2466. }
  2467. # This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
  2468. component_build_psa_accel_alg_md5() {
  2469. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD5 without other hashes
  2470. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD5 - other hashes"
  2471. scripts/config.py full
  2472. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2473. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2474. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  2475. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  2476. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
  2477. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
  2478. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
  2479. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
  2480. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
  2481. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
  2482. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
  2483. scripts/config.py unset MBEDTLS_LMS_C
  2484. scripts/config.py unset MBEDTLS_LMS_PRIVATE
  2485. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  2486. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  2487. }
  2488. # This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
  2489. component_build_psa_accel_alg_ripemd160() {
  2490. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RIPEMD160 without other hashes
  2491. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RIPEMD160 - other hashes"
  2492. scripts/config.py full
  2493. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2494. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2495. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  2496. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  2497. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
  2498. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
  2499. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
  2500. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
  2501. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
  2502. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
  2503. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
  2504. scripts/config.py unset MBEDTLS_LMS_C
  2505. scripts/config.py unset MBEDTLS_LMS_PRIVATE
  2506. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  2507. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  2508. }
  2509. # This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
  2510. component_build_psa_accel_alg_sha1() {
  2511. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_1 without other hashes
  2512. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_1 - other hashes"
  2513. scripts/config.py full
  2514. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2515. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2516. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  2517. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  2518. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
  2519. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
  2520. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
  2521. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
  2522. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
  2523. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
  2524. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
  2525. scripts/config.py unset MBEDTLS_LMS_C
  2526. scripts/config.py unset MBEDTLS_LMS_PRIVATE
  2527. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  2528. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  2529. }
  2530. # This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
  2531. component_build_psa_accel_alg_sha224() {
  2532. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_224 without other hashes
  2533. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_224 - other hashes"
  2534. scripts/config.py full
  2535. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2536. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2537. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  2538. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  2539. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
  2540. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
  2541. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
  2542. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
  2543. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
  2544. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
  2545. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  2546. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  2547. }
  2548. # This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
  2549. component_build_psa_accel_alg_sha256() {
  2550. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_256 without other hashes
  2551. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_256 - other hashes"
  2552. scripts/config.py full
  2553. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2554. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2555. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  2556. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  2557. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
  2558. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
  2559. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
  2560. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
  2561. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
  2562. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
  2563. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  2564. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  2565. }
  2566. # This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
  2567. component_build_psa_accel_alg_sha384() {
  2568. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_384 without other hashes
  2569. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_384 - other hashes"
  2570. scripts/config.py full
  2571. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2572. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2573. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  2574. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  2575. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
  2576. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
  2577. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
  2578. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
  2579. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
  2580. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
  2581. scripts/config.py unset MBEDTLS_LMS_C
  2582. scripts/config.py unset MBEDTLS_LMS_PRIVATE
  2583. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  2584. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  2585. }
  2586. # This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
  2587. component_build_psa_accel_alg_sha512() {
  2588. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_512 without other hashes
  2589. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_512 - other hashes"
  2590. scripts/config.py full
  2591. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2592. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2593. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  2594. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  2595. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
  2596. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
  2597. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
  2598. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
  2599. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
  2600. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
  2601. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
  2602. scripts/config.py unset MBEDTLS_LMS_C
  2603. scripts/config.py unset MBEDTLS_LMS_PRIVATE
  2604. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  2605. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  2606. }
  2607. # This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
  2608. component_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
  2609. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
  2610. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PKCS1V15_CRYPT + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
  2611. scripts/config.py full
  2612. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2613. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2614. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  2615. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  2616. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
  2617. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
  2618. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
  2619. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
  2620. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  2621. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  2622. }
  2623. # This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
  2624. component_build_psa_accel_alg_rsa_pkcs1v15_sign() {
  2625. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_SIGN and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
  2626. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PKCS1V15_SIGN + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
  2627. scripts/config.py full
  2628. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2629. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2630. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  2631. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  2632. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
  2633. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
  2634. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
  2635. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
  2636. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  2637. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  2638. }
  2639. # This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
  2640. component_build_psa_accel_alg_rsa_oaep() {
  2641. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_OAEP and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
  2642. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_OAEP + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
  2643. scripts/config.py full
  2644. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2645. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2646. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  2647. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  2648. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_OAEP 1
  2649. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
  2650. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
  2651. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
  2652. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  2653. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  2654. }
  2655. # This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
  2656. component_build_psa_accel_alg_rsa_pss() {
  2657. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PSS and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
  2658. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PSS + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
  2659. scripts/config.py full
  2660. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2661. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2662. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  2663. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  2664. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
  2665. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
  2666. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
  2667. scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
  2668. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  2669. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  2670. }
  2671. # This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
  2672. component_build_psa_accel_key_type_rsa_key_pair() {
  2673. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_KEY_PAIR and PSA_WANT_ALG_RSA_PSS
  2674. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR + PSA_WANT_ALG_RSA_PSS"
  2675. scripts/config.py full
  2676. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2677. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2678. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  2679. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  2680. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
  2681. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1
  2682. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  2683. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  2684. }
  2685. # This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
  2686. component_build_psa_accel_key_type_rsa_public_key() {
  2687. # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY and PSA_WANT_ALG_RSA_PSS
  2688. msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + PSA_WANT_ALG_RSA_PSS"
  2689. scripts/config.py full
  2690. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  2691. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2692. scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
  2693. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
  2694. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
  2695. scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
  2696. # Need to define the correct symbol and include the test driver header path in order to build with the test driver
  2697. make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
  2698. }
  2699. component_test_no_platform () {
  2700. # Full configuration build, without platform support, file IO and net sockets.
  2701. # This should catch missing mbedtls_printf definitions, and by disabling file
  2702. # IO, it should catch missing '#include <stdio.h>'
  2703. msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
  2704. scripts/config.py full
  2705. scripts/config.py unset MBEDTLS_PLATFORM_C
  2706. scripts/config.py unset MBEDTLS_NET_C
  2707. scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
  2708. scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
  2709. scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
  2710. scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
  2711. scripts/config.py unset MBEDTLS_PLATFORM_VSNPRINTF_ALT
  2712. scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
  2713. scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
  2714. scripts/config.py unset MBEDTLS_PLATFORM_SETBUF_ALT
  2715. scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
  2716. scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
  2717. scripts/config.py unset MBEDTLS_FS_IO
  2718. scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
  2719. scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
  2720. scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
  2721. # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
  2722. # to re-enable platform integration features otherwise disabled in C99 builds
  2723. make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
  2724. make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
  2725. }
  2726. component_build_no_std_function () {
  2727. # catch compile bugs in _uninit functions
  2728. msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
  2729. scripts/config.py full
  2730. scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
  2731. scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
  2732. scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
  2733. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
  2734. make
  2735. }
  2736. component_build_no_ssl_srv () {
  2737. msg "build: full config except SSL server, make, gcc" # ~ 30s
  2738. scripts/config.py full
  2739. scripts/config.py unset MBEDTLS_SSL_SRV_C
  2740. make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
  2741. }
  2742. component_build_no_ssl_cli () {
  2743. msg "build: full config except SSL client, make, gcc" # ~ 30s
  2744. scripts/config.py full
  2745. scripts/config.py unset MBEDTLS_SSL_CLI_C
  2746. make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
  2747. }
  2748. component_build_no_sockets () {
  2749. # Note, C99 compliance can also be tested with the sockets support disabled,
  2750. # as that requires a POSIX platform (which isn't the same as C99).
  2751. msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
  2752. scripts/config.py full
  2753. scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
  2754. scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
  2755. make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
  2756. }
  2757. component_test_memory_buffer_allocator_backtrace () {
  2758. msg "build: default config with memory buffer allocator and backtrace enabled"
  2759. scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
  2760. scripts/config.py set MBEDTLS_PLATFORM_MEMORY
  2761. scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
  2762. scripts/config.py set MBEDTLS_MEMORY_DEBUG
  2763. CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
  2764. make
  2765. msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
  2766. make test
  2767. }
  2768. component_test_memory_buffer_allocator () {
  2769. msg "build: default config with memory buffer allocator"
  2770. scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
  2771. scripts/config.py set MBEDTLS_PLATFORM_MEMORY
  2772. CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
  2773. make
  2774. msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
  2775. make test
  2776. msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
  2777. # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
  2778. tests/ssl-opt.sh -e '^DTLS proxy'
  2779. }
  2780. component_test_no_max_fragment_length () {
  2781. # Run max fragment length tests with MFL disabled
  2782. msg "build: default config except MFL extension (ASan build)" # ~ 30s
  2783. scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
  2784. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  2785. make
  2786. msg "test: ssl-opt.sh, MFL-related tests"
  2787. tests/ssl-opt.sh -f "Max fragment length"
  2788. }
  2789. component_test_asan_remove_peer_certificate () {
  2790. msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
  2791. scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
  2792. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  2793. make
  2794. msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
  2795. make test
  2796. msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
  2797. tests/ssl-opt.sh
  2798. msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
  2799. tests/compat.sh
  2800. msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
  2801. tests/context-info.sh
  2802. }
  2803. component_test_no_max_fragment_length_small_ssl_out_content_len () {
  2804. msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
  2805. scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
  2806. scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
  2807. scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
  2808. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  2809. make
  2810. msg "test: MFL tests (disabled MFL extension case) & large packet tests"
  2811. tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
  2812. msg "test: context-info.sh (disabled MFL extension case)"
  2813. tests/context-info.sh
  2814. }
  2815. component_test_variable_ssl_in_out_buffer_len () {
  2816. msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
  2817. scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
  2818. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  2819. make
  2820. msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
  2821. make test
  2822. msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
  2823. tests/ssl-opt.sh
  2824. msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
  2825. tests/compat.sh
  2826. }
  2827. component_test_dtls_cid_legacy () {
  2828. msg "build: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled (ASan build)"
  2829. scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 1
  2830. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  2831. make
  2832. msg "test: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy)"
  2833. make test
  2834. msg "test: ssl-opt.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
  2835. tests/ssl-opt.sh
  2836. msg "test: compat.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
  2837. tests/compat.sh
  2838. }
  2839. component_test_ssl_alloc_buffer_and_mfl () {
  2840. msg "build: default config with memory buffer allocator and MFL extension"
  2841. scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
  2842. scripts/config.py set MBEDTLS_PLATFORM_MEMORY
  2843. scripts/config.py set MBEDTLS_MEMORY_DEBUG
  2844. scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
  2845. scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
  2846. CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
  2847. make
  2848. msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
  2849. make test
  2850. msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
  2851. tests/ssl-opt.sh -f "Handshake memory usage"
  2852. }
  2853. component_test_when_no_ciphersuites_have_mac () {
  2854. msg "build: when no ciphersuites have MAC"
  2855. scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
  2856. scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
  2857. scripts/config.py unset MBEDTLS_CMAC_C
  2858. make
  2859. msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
  2860. make test
  2861. msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
  2862. tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
  2863. }
  2864. component_test_no_date_time () {
  2865. msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
  2866. scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
  2867. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
  2868. make
  2869. msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
  2870. make test
  2871. }
  2872. component_test_platform_calloc_macro () {
  2873. msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
  2874. scripts/config.py set MBEDTLS_PLATFORM_MEMORY
  2875. scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
  2876. scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
  2877. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  2878. make
  2879. msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
  2880. make test
  2881. }
  2882. component_test_malloc_0_null () {
  2883. msg "build: malloc(0) returns NULL (ASan+UBSan build)"
  2884. scripts/config.py full
  2885. make CC=gcc CFLAGS="'-DMBEDTLS_CONFIG_FILE=\"$PWD/tests/configs/config-wrapper-malloc-0-null.h\"' $ASAN_CFLAGS -O" LDFLAGS="$ASAN_CFLAGS"
  2886. msg "test: malloc(0) returns NULL (ASan+UBSan build)"
  2887. make test
  2888. msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
  2889. # Just the calloc selftest. "make test" ran the others as part of the
  2890. # test suites.
  2891. programs/test/selftest calloc
  2892. msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
  2893. # Run a subset of the tests. The choice is a balance between coverage
  2894. # and time (including time indirectly wasted due to flaky tests).
  2895. # The current choice is to skip tests whose description includes
  2896. # "proxy", which is an approximation of skipping tests that use the
  2897. # UDP proxy, which tend to be slower and flakier.
  2898. tests/ssl-opt.sh -e 'proxy'
  2899. }
  2900. component_test_aes_fewer_tables () {
  2901. msg "build: default config with AES_FEWER_TABLES enabled"
  2902. scripts/config.py set MBEDTLS_AES_FEWER_TABLES
  2903. make CC=gcc CFLAGS='-Werror -Wall -Wextra'
  2904. msg "test: AES_FEWER_TABLES"
  2905. make test
  2906. }
  2907. component_test_aes_rom_tables () {
  2908. msg "build: default config with AES_ROM_TABLES enabled"
  2909. scripts/config.py set MBEDTLS_AES_ROM_TABLES
  2910. make CC=gcc CFLAGS='-Werror -Wall -Wextra'
  2911. msg "test: AES_ROM_TABLES"
  2912. make test
  2913. }
  2914. component_test_aes_fewer_tables_and_rom_tables () {
  2915. msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
  2916. scripts/config.py set MBEDTLS_AES_FEWER_TABLES
  2917. scripts/config.py set MBEDTLS_AES_ROM_TABLES
  2918. make CC=gcc CFLAGS='-Werror -Wall -Wextra'
  2919. msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
  2920. make test
  2921. }
  2922. component_test_ctr_drbg_aes_256_sha_256 () {
  2923. msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
  2924. scripts/config.py full
  2925. scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
  2926. scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
  2927. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  2928. make
  2929. msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
  2930. make test
  2931. }
  2932. component_test_ctr_drbg_aes_128_sha_512 () {
  2933. msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
  2934. scripts/config.py full
  2935. scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
  2936. scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
  2937. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  2938. make
  2939. msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
  2940. make test
  2941. }
  2942. component_test_ctr_drbg_aes_128_sha_256 () {
  2943. msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
  2944. scripts/config.py full
  2945. scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
  2946. scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
  2947. scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
  2948. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  2949. make
  2950. msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
  2951. make test
  2952. }
  2953. component_test_se_default () {
  2954. msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
  2955. scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
  2956. make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
  2957. msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
  2958. make test
  2959. }
  2960. component_test_psa_crypto_drivers () {
  2961. msg "build: MBEDTLS_PSA_CRYPTO_DRIVERS w/ driver hooks"
  2962. scripts/config.py full
  2963. scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
  2964. scripts/config.py set MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
  2965. loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
  2966. loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
  2967. loc_cflags="${loc_cflags} -I../tests/include -O2"
  2968. make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
  2969. msg "test: full + MBEDTLS_PSA_CRYPTO_DRIVERS"
  2970. make test
  2971. }
  2972. component_test_make_shared () {
  2973. msg "build/test: make shared" # ~ 40s
  2974. make SHARED=1 all check
  2975. ldd programs/util/strerror | grep libmbedcrypto
  2976. programs/test/dlopen_demo.sh
  2977. }
  2978. component_test_cmake_shared () {
  2979. msg "build/test: cmake shared" # ~ 2min
  2980. cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
  2981. make
  2982. ldd programs/util/strerror | grep libmbedcrypto
  2983. make test
  2984. programs/test/dlopen_demo.sh
  2985. }
  2986. test_build_opt () {
  2987. info=$1 cc=$2; shift 2
  2988. for opt in "$@"; do
  2989. msg "build/test: $cc $opt, $info" # ~ 30s
  2990. make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
  2991. # We're confident enough in compilers to not run _all_ the tests,
  2992. # but at least run the unit tests. In particular, runs with
  2993. # optimizations use inline assembly whereas runs with -O0
  2994. # skip inline assembly.
  2995. make test # ~30s
  2996. make clean
  2997. done
  2998. }
  2999. component_test_clang_opt () {
  3000. scripts/config.py full
  3001. test_build_opt 'full config' clang -O0 -Os -O2
  3002. }
  3003. component_test_gcc_opt () {
  3004. scripts/config.py full
  3005. test_build_opt 'full config' gcc -O0 -Os -O2
  3006. }
  3007. component_build_mbedtls_config_file () {
  3008. msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
  3009. scripts/config.py -w full_config.h full
  3010. echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
  3011. make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
  3012. # Make sure this feature is enabled. We'll disable it in the next phase.
  3013. programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
  3014. make clean
  3015. msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
  3016. # In the user config, disable one feature (for simplicity, pick a feature
  3017. # that nothing else depends on).
  3018. echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
  3019. make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
  3020. not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
  3021. rm -f user_config.h full_config.h
  3022. }
  3023. component_build_psa_config_file () {
  3024. msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
  3025. scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
  3026. cp "$CRYPTO_CONFIG_H" psa_test_config.h
  3027. echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
  3028. make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
  3029. # Make sure this feature is enabled. We'll disable it in the next phase.
  3030. programs/test/query_compile_time_config MBEDTLS_CMAC_C
  3031. make clean
  3032. msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
  3033. # In the user config, disable one feature, which will reflect on the
  3034. # mbedtls configuration so we can query it with query_compile_time_config.
  3035. echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
  3036. scripts/config.py unset MBEDTLS_CMAC_C
  3037. make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
  3038. not programs/test/query_compile_time_config MBEDTLS_CMAC_C
  3039. rm -f psa_test_config.h psa_user_config.h
  3040. }
  3041. component_build_psa_alt_headers () {
  3042. msg "build: make with PSA alt headers" # ~20s
  3043. # Generate alternative versions of the substitutable headers with the
  3044. # same content except different include guards.
  3045. make -C tests include/alt-extra/psa/crypto_platform_alt.h include/alt-extra/psa/crypto_struct_alt.h
  3046. # Build the library and some programs.
  3047. # Don't build the fuzzers to avoid having to go through hoops to set
  3048. # a correct include path for programs/fuzz/Makefile.
  3049. make CFLAGS="-I ../tests/include/alt-extra -DMBEDTLS_PSA_CRYPTO_PLATFORM_FILE='\"psa/crypto_platform_alt.h\"' -DMBEDTLS_PSA_CRYPTO_STRUCT_FILE='\"psa/crypto_struct_alt.h\"'" lib
  3050. make -C programs -o fuzz CFLAGS="-I ../tests/include/alt-extra -DMBEDTLS_PSA_CRYPTO_PLATFORM_FILE='\"psa/crypto_platform_alt.h\"' -DMBEDTLS_PSA_CRYPTO_STRUCT_FILE='\"psa/crypto_struct_alt.h\"'"
  3051. # Check that we're getting the alternative include guards and not the
  3052. # original include guards.
  3053. programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
  3054. programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
  3055. programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
  3056. programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
  3057. }
  3058. component_test_m32_o0 () {
  3059. # Build without optimization, so as to use portable C code (in a 32-bit
  3060. # build) and not the i386-specific inline assembly.
  3061. msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
  3062. scripts/config.py full
  3063. make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
  3064. msg "test: i386, make, gcc -O0 (ASan build)"
  3065. make test
  3066. }
  3067. support_test_m32_o0 () {
  3068. case $(uname -m) in
  3069. amd64|x86_64) true;;
  3070. *) false;;
  3071. esac
  3072. }
  3073. component_test_m32_o2 () {
  3074. # Build with optimization, to use the i386 specific inline assembly
  3075. # and go faster for tests.
  3076. msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
  3077. scripts/config.py full
  3078. make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
  3079. msg "test: i386, make, gcc -O2 (ASan build)"
  3080. make test
  3081. msg "test ssl-opt.sh, i386, make, gcc-O2"
  3082. tests/ssl-opt.sh
  3083. }
  3084. support_test_m32_o2 () {
  3085. support_test_m32_o0 "$@"
  3086. }
  3087. component_test_m32_everest () {
  3088. msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
  3089. scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
  3090. make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
  3091. msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
  3092. make test
  3093. msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
  3094. tests/ssl-opt.sh -f ECDH
  3095. msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
  3096. # Exclude some symmetric ciphers that are redundant here to gain time.
  3097. tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
  3098. }
  3099. support_test_m32_everest () {
  3100. support_test_m32_o0 "$@"
  3101. }
  3102. component_test_mx32 () {
  3103. msg "build: 64-bit ILP32, make, gcc" # ~ 30s
  3104. scripts/config.py full
  3105. make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
  3106. msg "test: 64-bit ILP32, make, gcc"
  3107. make test
  3108. }
  3109. support_test_mx32 () {
  3110. case $(uname -m) in
  3111. amd64|x86_64) true;;
  3112. *) false;;
  3113. esac
  3114. }
  3115. component_test_min_mpi_window_size () {
  3116. msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
  3117. scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
  3118. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  3119. make
  3120. msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
  3121. make test
  3122. }
  3123. component_test_have_int32 () {
  3124. msg "build: gcc, force 32-bit bignum limbs"
  3125. scripts/config.py unset MBEDTLS_HAVE_ASM
  3126. scripts/config.py unset MBEDTLS_AESNI_C
  3127. scripts/config.py unset MBEDTLS_PADLOCK_C
  3128. scripts/config.py unset MBEDTLS_AESCE_C
  3129. make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
  3130. msg "test: gcc, force 32-bit bignum limbs"
  3131. make test
  3132. }
  3133. component_test_have_int64 () {
  3134. msg "build: gcc, force 64-bit bignum limbs"
  3135. scripts/config.py unset MBEDTLS_HAVE_ASM
  3136. scripts/config.py unset MBEDTLS_AESNI_C
  3137. scripts/config.py unset MBEDTLS_PADLOCK_C
  3138. scripts/config.py unset MBEDTLS_AESCE_C
  3139. make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
  3140. msg "test: gcc, force 64-bit bignum limbs"
  3141. make test
  3142. }
  3143. component_test_no_udbl_division () {
  3144. msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
  3145. scripts/config.py full
  3146. scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
  3147. make CFLAGS='-Werror -O1'
  3148. msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
  3149. make test
  3150. }
  3151. component_test_no_64bit_multiplication () {
  3152. msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
  3153. scripts/config.py full
  3154. scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
  3155. make CFLAGS='-Werror -O1'
  3156. msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
  3157. make test
  3158. }
  3159. component_test_no_strings () {
  3160. msg "build: no strings" # ~10s
  3161. scripts/config.py full
  3162. # Disable options that activate a large amount of string constants.
  3163. scripts/config.py unset MBEDTLS_DEBUG_C
  3164. scripts/config.py unset MBEDTLS_ERROR_C
  3165. scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
  3166. scripts/config.py unset MBEDTLS_VERSION_FEATURES
  3167. make CFLAGS='-Werror -Os'
  3168. msg "test: no strings" # ~ 10s
  3169. make test
  3170. }
  3171. component_test_no_x509_info () {
  3172. msg "build: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
  3173. scripts/config.pl full
  3174. scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
  3175. scripts/config.pl set MBEDTLS_X509_REMOVE_INFO
  3176. make CFLAGS='-Werror -O2'
  3177. msg "test: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
  3178. make test
  3179. msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_INFO" # ~ 1 min
  3180. tests/ssl-opt.sh
  3181. }
  3182. component_build_arm_none_eabi_gcc () {
  3183. msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
  3184. scripts/config.py baremetal
  3185. make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -Wall -Wextra -O1' lib
  3186. msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
  3187. ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
  3188. }
  3189. component_build_arm_linux_gnueabi_gcc_arm5vte () {
  3190. msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
  3191. scripts/config.py baremetal
  3192. # Build for a target platform that's close to what Debian uses
  3193. # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
  3194. # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
  3195. # Build everything including programs, see for example
  3196. # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
  3197. make CC="${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc" AR="${ARM_LINUX_GNUEABI_GCC_PREFIX}ar" CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te'
  3198. msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
  3199. ${ARM_LINUX_GNUEABI_GCC_PREFIX}size library/*.o
  3200. }
  3201. support_build_arm_linux_gnueabi_gcc_arm5vte () {
  3202. type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
  3203. }
  3204. component_build_arm_none_eabi_gcc_arm5vte () {
  3205. msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
  3206. scripts/config.py baremetal
  3207. # This is an imperfect substitute for
  3208. # component_build_arm_linux_gnueabi_gcc_arm5vte
  3209. # in case the gcc-arm-linux-gnueabi toolchain is not available
  3210. make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" CFLAGS='-std=c99 -Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
  3211. msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
  3212. ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
  3213. }
  3214. component_build_arm_none_eabi_gcc_m0plus () {
  3215. msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
  3216. scripts/config.py baremetal_size
  3217. make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -Wall -Wextra -mthumb -mcpu=cortex-m0plus -Os' lib
  3218. msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
  3219. ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
  3220. }
  3221. component_build_arm_none_eabi_gcc_no_udbl_division () {
  3222. msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
  3223. scripts/config.py baremetal
  3224. scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
  3225. make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -Wall -Wextra' lib
  3226. echo "Checking that software 64-bit division is not required"
  3227. not grep __aeabi_uldiv library/*.o
  3228. }
  3229. component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
  3230. msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
  3231. scripts/config.py baremetal
  3232. scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
  3233. make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -O1 -march=armv6-m -mthumb' lib
  3234. echo "Checking that software 64-bit multiplication is not required"
  3235. not grep __aeabi_lmul library/*.o
  3236. }
  3237. component_build_armcc () {
  3238. msg "build: ARM Compiler 5"
  3239. scripts/config.py baremetal
  3240. # armc[56] don't support SHA-512 intrinsics
  3241. scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
  3242. # Stop armclang warning about feature detection for A64_CRYPTO.
  3243. # With this enabled, the library does build correctly under armclang,
  3244. # but in baremetal builds (as tested here), feature detection is
  3245. # unavailable, and the user is notified via a #warning. So enabling
  3246. # this feature would prevent us from building with -Werror on
  3247. # armclang. Tracked in #7198.
  3248. scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
  3249. scripts/config.py set MBEDTLS_HAVE_ASM
  3250. make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
  3251. msg "size: ARM Compiler 5"
  3252. "$ARMC5_FROMELF" -z library/*.o
  3253. make clean
  3254. # Compile with -O1 since some Arm inline assembly is disabled for -O0.
  3255. # ARM Compiler 6 - Target ARMv7-A
  3256. armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-a"
  3257. # ARM Compiler 6 - Target ARMv7-M
  3258. armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m"
  3259. # ARM Compiler 6 - Target ARMv7-M+DSP
  3260. armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m+dsp"
  3261. # ARM Compiler 6 - Target ARMv8-A - AArch32
  3262. armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8.2-a"
  3263. # ARM Compiler 6 - Target ARMv8-M
  3264. armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8-m.main"
  3265. # ARM Compiler 6 - Target ARMv8.2-A - AArch64
  3266. armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto"
  3267. }
  3268. support_build_armcc () {
  3269. armc5_cc="$ARMC5_BIN_DIR/armcc"
  3270. armc6_cc="$ARMC6_BIN_DIR/armclang"
  3271. (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
  3272. }
  3273. component_test_tls13_only () {
  3274. msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3, without MBEDTLS_SSL_PROTO_TLS1_2"
  3275. scripts/config.py set MBEDTLS_SSL_EARLY_DATA
  3276. make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
  3277. msg "test: TLS 1.3 only, all key exchange modes enabled"
  3278. make test
  3279. msg "ssl-opt.sh: TLS 1.3 only, all key exchange modes enabled"
  3280. tests/ssl-opt.sh
  3281. }
  3282. component_test_tls13_only_psk () {
  3283. msg "build: TLS 1.3 only from default, only PSK key exchange mode"
  3284. scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
  3285. scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
  3286. scripts/config.py unset MBEDTLS_ECDH_C
  3287. scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
  3288. scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
  3289. scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
  3290. scripts/config.py unset MBEDTLS_ECDSA_C
  3291. scripts/config.py unset MBEDTLS_PKCS1_V21
  3292. scripts/config.py unset MBEDTLS_PKCS7_C
  3293. scripts/config.py set MBEDTLS_SSL_EARLY_DATA
  3294. make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
  3295. msg "test_suite_ssl: TLS 1.3 only, only PSK key exchange mode enabled"
  3296. cd tests; ./test_suite_ssl; cd ..
  3297. msg "ssl-opt.sh: TLS 1.3 only, only PSK key exchange mode enabled"
  3298. tests/ssl-opt.sh
  3299. }
  3300. component_test_tls13_only_ephemeral () {
  3301. msg "build: TLS 1.3 only from default, only ephemeral key exchange mode"
  3302. scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
  3303. scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
  3304. scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
  3305. make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
  3306. msg "test_suite_ssl: TLS 1.3 only, only ephemeral key exchange mode"
  3307. cd tests; ./test_suite_ssl; cd ..
  3308. msg "ssl-opt.sh: TLS 1.3 only, only ephemeral key exchange mode"
  3309. tests/ssl-opt.sh
  3310. }
  3311. component_test_tls13_only_psk_ephemeral () {
  3312. msg "build: TLS 1.3 only from default, only PSK ephemeral key exchange mode"
  3313. scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
  3314. scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
  3315. scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
  3316. scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
  3317. scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
  3318. scripts/config.py unset MBEDTLS_ECDSA_C
  3319. scripts/config.py unset MBEDTLS_PKCS1_V21
  3320. scripts/config.py unset MBEDTLS_PKCS7_C
  3321. scripts/config.py set MBEDTLS_SSL_EARLY_DATA
  3322. make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
  3323. msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral key exchange mode"
  3324. cd tests; ./test_suite_ssl; cd ..
  3325. msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral key exchange mode"
  3326. tests/ssl-opt.sh
  3327. }
  3328. component_test_tls13_only_psk_all () {
  3329. msg "build: TLS 1.3 only from default, without ephemeral key exchange mode"
  3330. scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
  3331. scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
  3332. scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
  3333. scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
  3334. scripts/config.py unset MBEDTLS_ECDSA_C
  3335. scripts/config.py unset MBEDTLS_PKCS1_V21
  3336. scripts/config.py unset MBEDTLS_PKCS7_C
  3337. scripts/config.py set MBEDTLS_SSL_EARLY_DATA
  3338. make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
  3339. msg "test_suite_ssl: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
  3340. cd tests; ./test_suite_ssl; cd ..
  3341. msg "ssl-opt.sh: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
  3342. tests/ssl-opt.sh
  3343. }
  3344. component_test_tls13_only_ephemeral_all () {
  3345. msg "build: TLS 1.3 only from default, without PSK key exchange mode"
  3346. scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
  3347. scripts/config.py set MBEDTLS_SSL_EARLY_DATA
  3348. make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
  3349. msg "test_suite_ssl: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
  3350. cd tests; ./test_suite_ssl; cd ..
  3351. msg "ssl-opt.sh: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
  3352. tests/ssl-opt.sh
  3353. }
  3354. component_test_tls13 () {
  3355. msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
  3356. scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3
  3357. scripts/config.py set MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
  3358. scripts/config.py set MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 1
  3359. scripts/config.py set MBEDTLS_SSL_EARLY_DATA
  3360. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  3361. make
  3362. msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
  3363. make test
  3364. msg "ssl-opt.sh (TLS 1.3)"
  3365. tests/ssl-opt.sh
  3366. }
  3367. component_test_tls13_no_compatibility_mode () {
  3368. msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
  3369. scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3
  3370. scripts/config.py unset MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
  3371. scripts/config.py set MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 1
  3372. scripts/config.py set MBEDTLS_SSL_EARLY_DATA
  3373. CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
  3374. make
  3375. msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
  3376. make test
  3377. msg "ssl-opt.sh (TLS 1.3 no compatibility mode)"
  3378. tests/ssl-opt.sh
  3379. }
  3380. component_test_tls13_only_record_size_limit () {
  3381. msg "build: TLS 1.3 only from default, record size limit extension enabled"
  3382. scripts/config.py set MBEDTLS_SSL_RECORD_SIZE_LIMIT
  3383. make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
  3384. msg "test_suite_ssl: TLS 1.3 only, record size limit extension enabled"
  3385. cd tests; ./test_suite_ssl; cd ..
  3386. msg "ssl-opt.sh: (TLS 1.3 only, record size limit extension tests only)"
  3387. # Both the server and the client will currently abort the handshake when they encounter the
  3388. # record size limit extension. There is no way to prevent gnutls-cli from sending the extension
  3389. # which makes all G_NEXT_CLI + P_SRV tests fail. Thus, run only the tests for the this extension.
  3390. tests/ssl-opt.sh -f "Record Size Limit"
  3391. }
  3392. component_build_mingw () {
  3393. msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
  3394. make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs
  3395. # note Make tests only builds the tests, but doesn't run them
  3396. make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
  3397. make WINDOWS_BUILD=1 clean
  3398. msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
  3399. make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 lib programs
  3400. make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 tests
  3401. make WINDOWS_BUILD=1 clean
  3402. }
  3403. support_build_mingw() {
  3404. case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in
  3405. [0-5]*|"") false;;
  3406. *) true;;
  3407. esac
  3408. }
  3409. component_test_memsan () {
  3410. msg "build: MSan (clang)" # ~ 1 min 20s
  3411. scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
  3412. CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
  3413. make
  3414. msg "test: main suites (MSan)" # ~ 10s
  3415. make test
  3416. msg "test: ssl-opt.sh (MSan)" # ~ 1 min
  3417. tests/ssl-opt.sh
  3418. # Optional part(s)
  3419. if [ "$MEMORY" -gt 0 ]; then
  3420. msg "test: compat.sh (MSan)" # ~ 6 min 20s
  3421. tests/compat.sh
  3422. fi
  3423. }
  3424. component_test_valgrind () {
  3425. msg "build: Release (clang)"
  3426. # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
  3427. CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
  3428. make
  3429. msg "test: main suites, Valgrind (default config)"
  3430. make memcheck
  3431. # Optional parts (slow; currently broken on OS X because programs don't
  3432. # seem to receive signals under valgrind on OS X).
  3433. # These optional parts don't run on the CI.
  3434. if [ "$MEMORY" -gt 0 ]; then
  3435. msg "test: ssl-opt.sh --memcheck (default config)"
  3436. tests/ssl-opt.sh --memcheck
  3437. fi
  3438. if [ "$MEMORY" -gt 1 ]; then
  3439. msg "test: compat.sh --memcheck (default config)"
  3440. tests/compat.sh --memcheck
  3441. fi
  3442. if [ "$MEMORY" -gt 0 ]; then
  3443. msg "test: context-info.sh --memcheck (default config)"
  3444. tests/context-info.sh --memcheck
  3445. fi
  3446. }
  3447. component_test_valgrind_psa () {
  3448. msg "build: Release, full (clang)"
  3449. # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
  3450. scripts/config.py full
  3451. CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
  3452. make
  3453. msg "test: main suites, Valgrind (full config)"
  3454. make memcheck
  3455. }
  3456. support_test_cmake_out_of_source () {
  3457. distrib_id=""
  3458. distrib_ver=""
  3459. distrib_ver_minor=""
  3460. distrib_ver_major=""
  3461. # Attempt to parse lsb-release to find out distribution and version. If not
  3462. # found this should fail safe (test is supported).
  3463. if [[ -f /etc/lsb-release ]]; then
  3464. while read -r lsb_line; do
  3465. case "$lsb_line" in
  3466. "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
  3467. "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
  3468. esac
  3469. done < /etc/lsb-release
  3470. distrib_ver_major="${distrib_ver%%.*}"
  3471. distrib_ver="${distrib_ver#*.}"
  3472. distrib_ver_minor="${distrib_ver%%.*}"
  3473. fi
  3474. # Running the out of source CMake test on Ubuntu 16.04 using more than one
  3475. # processor (as the CI does) can create a race condition whereby the build
  3476. # fails to see a generated file, despite that file actually having been
  3477. # generated. This problem appears to go away with 18.04 or newer, so make
  3478. # the out of source tests unsupported on Ubuntu 16.04.
  3479. [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
  3480. }
  3481. component_test_cmake_out_of_source () {
  3482. msg "build: cmake 'out-of-source' build"
  3483. MBEDTLS_ROOT_DIR="$PWD"
  3484. mkdir "$OUT_OF_SOURCE_DIR"
  3485. cd "$OUT_OF_SOURCE_DIR"
  3486. cmake -D CMAKE_BUILD_TYPE:String=Check "$MBEDTLS_ROOT_DIR"
  3487. make
  3488. msg "test: cmake 'out-of-source' build"
  3489. make test
  3490. # Check that ssl-opt.sh can find the test programs.
  3491. # Also ensure that there are no error messages such as
  3492. # "No such file or directory", which would indicate that some required
  3493. # file is missing (ssl-opt.sh tolerates the absence of some files so
  3494. # may exit with status 0 but emit errors).
  3495. ./tests/ssl-opt.sh -f 'Default' >ssl-opt.out 2>ssl-opt.err
  3496. grep PASS ssl-opt.out
  3497. cat ssl-opt.err >&2
  3498. # If ssl-opt.err is non-empty, record an error and keep going.
  3499. [ ! -s ssl-opt.err ]
  3500. rm ssl-opt.out ssl-opt.err
  3501. cd "$MBEDTLS_ROOT_DIR"
  3502. rm -rf "$OUT_OF_SOURCE_DIR"
  3503. }
  3504. component_test_cmake_as_subdirectory () {
  3505. msg "build: cmake 'as-subdirectory' build"
  3506. cd programs/test/cmake_subproject
  3507. cmake .
  3508. make
  3509. ./cmake_subproject
  3510. }
  3511. support_test_cmake_as_subdirectory () {
  3512. support_test_cmake_out_of_source
  3513. }
  3514. component_test_cmake_as_package () {
  3515. msg "build: cmake 'as-package' build"
  3516. cd programs/test/cmake_package
  3517. cmake .
  3518. make
  3519. ./cmake_package
  3520. }
  3521. support_test_cmake_as_package () {
  3522. support_test_cmake_out_of_source
  3523. }
  3524. component_test_cmake_as_package_install () {
  3525. msg "build: cmake 'as-installed-package' build"
  3526. cd programs/test/cmake_package_install
  3527. cmake .
  3528. make
  3529. ./cmake_package_install
  3530. }
  3531. support_test_cmake_as_package_install () {
  3532. support_test_cmake_out_of_source
  3533. }
  3534. component_test_zeroize () {
  3535. # Test that the function mbedtls_platform_zeroize() is not optimized away by
  3536. # different combinations of compilers and optimization flags by using an
  3537. # auxiliary GDB script. Unfortunately, GDB does not return error values to the
  3538. # system in all cases that the script fails, so we must manually search the
  3539. # output to check whether the pass string is present and no failure strings
  3540. # were printed.
  3541. # Don't try to disable ASLR. We don't care about ASLR here. We do care
  3542. # about a spurious message if Gdb tries and fails, so suppress that.
  3543. gdb_disable_aslr=
  3544. if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
  3545. gdb_disable_aslr='set disable-randomization off'
  3546. fi
  3547. for optimization_flag in -O2 -O3 -Ofast -Os; do
  3548. for compiler in clang gcc; do
  3549. msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
  3550. make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
  3551. gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
  3552. grep "The buffer was correctly zeroized" test_zeroize.log
  3553. not grep -i "error" test_zeroize.log
  3554. rm -f test_zeroize.log
  3555. make clean
  3556. done
  3557. done
  3558. }
  3559. component_test_psa_compliance () {
  3560. msg "build: make, default config (out-of-box), libmbedcrypto.a only"
  3561. make -C library libmbedcrypto.a
  3562. msg "unit test: test_psa_compliance.py"
  3563. ./tests/scripts/test_psa_compliance.py
  3564. }
  3565. support_test_psa_compliance () {
  3566. # psa-compliance-tests only supports CMake >= 3.10.0
  3567. ver="$(cmake --version)"
  3568. ver="${ver#cmake version }"
  3569. ver_major="${ver%%.*}"
  3570. ver="${ver#*.}"
  3571. ver_minor="${ver%%.*}"
  3572. [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
  3573. }
  3574. component_check_code_style () {
  3575. msg "Check C code style"
  3576. ./scripts/code_style.py
  3577. }
  3578. support_check_code_style() {
  3579. case $(uncrustify --version) in
  3580. *0.75.1*) true;;
  3581. *) false;;
  3582. esac
  3583. }
  3584. component_check_python_files () {
  3585. msg "Lint: Python scripts"
  3586. tests/scripts/check-python-files.sh
  3587. }
  3588. component_check_test_helpers () {
  3589. msg "unit test: generate_test_code.py"
  3590. # unittest writes out mundane stuff like number or tests run on stderr.
  3591. # Our convention is to reserve stderr for actual errors, and write
  3592. # harmless info on stdout so it can be suppress with --quiet.
  3593. ./tests/scripts/test_generate_test_code.py 2>&1
  3594. msg "unit test: translate_ciphers.py"
  3595. python3 -m unittest tests/scripts/translate_ciphers.py 2>&1
  3596. }
  3597. ################################################################
  3598. #### Termination
  3599. ################################################################
  3600. post_report () {
  3601. msg "Done, cleaning up"
  3602. final_cleanup
  3603. final_report
  3604. }
  3605. ################################################################
  3606. #### Run all the things
  3607. ################################################################
  3608. # Function invoked by --error-test to test error reporting.
  3609. pseudo_component_error_test () {
  3610. msg "Testing error reporting $error_test_i"
  3611. if [ $KEEP_GOING -ne 0 ]; then
  3612. echo "Expect three failing commands."
  3613. fi
  3614. # If the component doesn't run in a subshell, changing error_test_i to an
  3615. # invalid integer will cause an error in the loop that runs this function.
  3616. error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell
  3617. # Expected error: 'grep non_existent /dev/null -> 1'
  3618. grep non_existent /dev/null
  3619. # Expected error: '! grep -q . tests/scripts/all.sh -> 1'
  3620. not grep -q . "$0"
  3621. # Expected error: 'make unknown_target -> 2'
  3622. make unknown_target
  3623. false "this should not be executed"
  3624. }
  3625. # Run one component and clean up afterwards.
  3626. run_component () {
  3627. current_component="$1"
  3628. export MBEDTLS_TEST_CONFIGURATION="$current_component"
  3629. # Unconditionally create a seedfile that's sufficiently long.
  3630. # Do this before each component, because a previous component may
  3631. # have messed it up or shortened it.
  3632. local dd_cmd
  3633. dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
  3634. case $OSTYPE in
  3635. linux*|freebsd*|openbsd*) dd_cmd+=(status=none)
  3636. esac
  3637. "${dd_cmd[@]}"
  3638. # Run the component in a subshell, with error trapping and output
  3639. # redirection set up based on the relevant options.
  3640. if [ $KEEP_GOING -eq 1 ]; then
  3641. # We want to keep running if the subshell fails, so 'set -e' must
  3642. # be off when the subshell runs.
  3643. set +e
  3644. fi
  3645. (
  3646. if [ $QUIET -eq 1 ]; then
  3647. # msg() will be silenced, so just print the component name here.
  3648. echo "${current_component#component_}"
  3649. exec >/dev/null
  3650. fi
  3651. if [ $KEEP_GOING -eq 1 ]; then
  3652. # Keep "set -e" off, and run an ERR trap instead to record failures.
  3653. set -E
  3654. trap err_trap ERR
  3655. fi
  3656. # The next line is what runs the component
  3657. "$@"
  3658. if [ $KEEP_GOING -eq 1 ]; then
  3659. trap - ERR
  3660. exit $last_failure_status
  3661. fi
  3662. )
  3663. component_status=$?
  3664. if [ $KEEP_GOING -eq 1 ]; then
  3665. set -e
  3666. if [ $component_status -ne 0 ]; then
  3667. failure_count=$((failure_count + 1))
  3668. fi
  3669. fi
  3670. # Restore the build tree to a clean state.
  3671. cleanup
  3672. unset current_component
  3673. }
  3674. # Preliminary setup
  3675. pre_check_environment
  3676. pre_initialize_variables
  3677. pre_parse_command_line "$@"
  3678. pre_check_git
  3679. pre_restore_files
  3680. pre_back_up
  3681. build_status=0
  3682. if [ $KEEP_GOING -eq 1 ]; then
  3683. pre_setup_keep_going
  3684. fi
  3685. pre_prepare_outcome_file
  3686. pre_print_configuration
  3687. pre_check_tools
  3688. cleanup
  3689. pre_generate_files
  3690. # Run the requested tests.
  3691. for ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do
  3692. run_component pseudo_component_error_test
  3693. done
  3694. unset error_test_i
  3695. for component in $RUN_COMPONENTS; do
  3696. run_component "component_$component"
  3697. done
  3698. # We're done.
  3699. post_report