configuration.xml 111 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <SPC5-Config version="1.0.0">
  3. <application name="Crypto Test Suite" version="1.0.0" standalone="true" locked="false">
  4. <description>Test Specification for Hal Crypto </description>
  5. <component id="org.chibios.spc5.components.portable.generic_startup">
  6. <component id="org.chibios.spc5.components.portable.chibios_unitary_tests_engine" />
  7. </component>
  8. <instances>
  9. <instance locked="false" id="org.chibios.spc5.components.portable.generic_startup" />
  10. <instance locked="false" id="org.chibios.spc5.components.portable.chibios_unitary_tests_engine">
  11. <description>
  12. <brief>
  13. <value>Chibios Hal Crypto Test Suite.</value>
  14. </brief>
  15. <copyright>
  16. <value><![CDATA[/*
  17. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  18. Licensed under the Apache License, Version 2.0 (the "License");
  19. you may not use this file except in compliance with the License.
  20. You may obtain a copy of the License at
  21. http://www.apache.org/licenses/LICENSE-2.0
  22. Unless required by applicable law or agreed to in writing, software
  23. distributed under the License is distributed on an "AS IS" BASIS,
  24. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. See the License for the specific language governing permissions and
  26. limitations under the License.
  27. */]]></value>
  28. </copyright>
  29. <introduction>
  30. <value>Test suite for ChibiOS Crypto Hal. The purpose of this suite is to perform unit tests on the Hal Crypto and to converge to 100% code coverage through successive improvements.</value>
  31. </introduction>
  32. </description>
  33. <global_data_and_code>
  34. <code_prefix>
  35. <value>cry_</value>
  36. </code_prefix>
  37. <global_definitions>
  38. <value><![CDATA[
  39. extern void cryptoTest_setStream(BaseSequentialStream * s);
  40. extern void cryptoTest_printArray32(bool isLE,const uint32_t *a,size_t len);
  41. #ifdef LOG_CRYPTO_DATA
  42. #define SHOW_ENCRYPDATA(w) cryptoTest_printArray32(true,msg_encrypted,w)
  43. #define SHOW_DECRYPDATA(w) cryptoTest_printArray32(true,msg_decrypted,w)
  44. #define SHOW_DATA(d,w) cryptoTest_printArray32(true,d,w)
  45. #else
  46. #define SHOW_ENCRYPDATA(w)
  47. #define SHOW_DECRYPDATA(w)
  48. #define SHOW_DATA(d,w)
  49. #endif
  50. #define TEST_DATA_BYTE_LEN 640
  51. #define TEST_DATA_WORD_LEN (TEST_DATA_BYTE_LEN / 4)
  52. #define TEST_MSG_DATA_BYTE_LEN 640
  53. #define TEST_MSG_DATA_WORD_LEN (TEST_MSG_DATA_BYTE_LEN / 4)
  54. #define SHA_LEN_0 3
  55. #define SHA_LEN_1 56
  56. #define SHA_LEN_2 64
  57. #define SHA_LEN_3 128
  58. #define TEST_GCM_KEY1_LEN 32
  59. #define TEST_P_LEN 60
  60. #define TEST_A_LEN 20
  61. #define TEST_IV1_LEN 12
  62. #define TEST_CL_LEN 60
  63. #define TEST_TL_LEN 16
  64. extern const char test_plain_data[TEST_DATA_BYTE_LEN];
  65. extern uint32_t msg_clear[TEST_MSG_DATA_WORD_LEN];
  66. extern uint32_t msg_encrypted[TEST_MSG_DATA_WORD_LEN];
  67. extern uint32_t msg_decrypted[TEST_MSG_DATA_WORD_LEN];
  68. extern const uint32_t test_keys[8];
  69. extern const uint32_t test_vectors[4];
  70. extern const uint8_t sha_msg0[SHA_LEN_0];
  71. extern const uint8_t sha_msg1[SHA_LEN_1];
  72. extern const uint8_t sha_msg2[SHA_LEN_2];
  73. extern const uint8_t sha_msg3[SHA_LEN_3];
  74. ]]></value>
  75. </global_definitions>
  76. <global_code>
  77. <value><![CDATA[
  78. #if CRYPTO_LOG_LEVEL == 1
  79. #include "chprintf.h"
  80. #endif
  81. const uint32_t test_keys[8]=
  82. {
  83. 0x01234567, //KEY 1 low part
  84. 0x89ABCDEF, //KEY 1 hi part
  85. 0x76543210, //KEY 2 low part
  86. 0xFEDCBA98, //KEY 2 hi part
  87. 0x55AA55AA,
  88. 0xAA55AA55,
  89. 0x0000FFFF,
  90. 0xFFFF0000
  91. };
  92. const uint32_t test_vectors[4]=
  93. {
  94. 0x11223344, //VECTOR 1 low part
  95. 0x55667788, //VECTOR 1 hi part
  96. 0x11112222,
  97. 0x33334444
  98. };
  99. const char test_plain_data[TEST_DATA_BYTE_LEN] ="\
  100. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesen\
  101. t et pellentesque risus. Sed id gravida elit. Proin eget accumsa\
  102. n mi. Aliquam vitae dui porta, euismod velit viverra, elementum \
  103. lacus. Nunc turpis orci, venenatis vel vulputate nec, luctus sit\
  104. amet urna. Ut et nunc purus. Aliquam erat volutpat. Vestibulum n\
  105. ulla dolor, cursus vitae cursus eget, dapibus eget sapien. Integ\
  106. er justo eros, commodo ut massa eu, bibendum elementum tellus. N\
  107. am quis dolor in libero placerat congue. Sed sodales urna sceler\
  108. isque dui faucibus, vitae malesuada dui fermentum. Proin ultrici\
  109. es sit amet justo at ornare. Suspendisse efficitur purus nullam.";
  110. const uint8_t sha_msg0[SHA_LEN_0] = "abc";
  111. const uint8_t sha_msg1[SHA_LEN_1] = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  112. const uint8_t sha_msg2[SHA_LEN_2] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
  113. const uint8_t sha_msg3[SHA_LEN_3] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
  114. ALIGNED_VAR(4) uint32_t msg_clear[TEST_MSG_DATA_WORD_LEN];
  115. ALIGNED_VAR(4) uint32_t msg_encrypted[TEST_MSG_DATA_WORD_LEN];
  116. ALIGNED_VAR(4) uint32_t msg_decrypted[TEST_MSG_DATA_WORD_LEN];
  117. BaseSequentialStream * ts;
  118. #if CRYPTO_LOG_LEVEL == 1
  119. static uint32_t toBigEndian(uint32_t v)
  120. {
  121. return (v & 0x000000ff) << 24u |
  122. ( (v & 0x0000ff00) << 8u ) |
  123. ( (v & 0x00ff0000) >> 8u ) |
  124. ( (v & 0xff000000) >> 24u );
  125. }
  126. #endif
  127. void cryptoTest_setStream(BaseSequentialStream * s)
  128. {
  129. ts = s;
  130. }
  131. void cryptoTest_printArray(const uint8_t *a,size_t len)
  132. {
  133. #if CRYPTO_LOG_LEVEL == 1
  134. for(size_t i=0;i<len;i++)
  135. {
  136. chprintf(ts,"%02X",a[i]);
  137. }
  138. chprintf(ts,"\r\n");
  139. #else
  140. (void)a;
  141. (void)len;
  142. #endif
  143. }
  144. void cryptoTest_printArray32(bool isLE,const uint32_t *a,size_t len)
  145. {
  146. #if CRYPTO_LOG_LEVEL == 1
  147. uint32_t data;
  148. for(size_t i=0;i<len;i++)
  149. {
  150. if (isLE)
  151. data = toBigEndian(a[i]);
  152. else
  153. data = a[i];
  154. chprintf(ts,"%08X ",data);
  155. }
  156. chprintf(ts,"\r\n");
  157. #else
  158. (void)isLE;
  159. (void)a;
  160. (void)len;
  161. #endif
  162. }
  163. ]]></value>
  164. </global_code>
  165. </global_data_and_code>
  166. <sequences>
  167. <sequence>
  168. <type index="0">
  169. <value>Internal Tests</value>
  170. </type>
  171. <brief>
  172. <value>AES ECB</value>
  173. </brief>
  174. <description>
  175. <value>AES ECB</value>
  176. </description>
  177. <condition>
  178. <value />
  179. </condition>
  180. <shared_code>
  181. <value><![CDATA[
  182. #include <string.h>
  183. #include "ref_aes.h"
  184. static const CRYConfig config_Polling = {
  185. TRANSFER_POLLING,
  186. AES_CFBS_128 //cfbs
  187. };
  188. static const CRYConfig config_DMA = {
  189. TRANSFER_DMA,
  190. AES_CFBS_128 //cfbs
  191. };
  192. ]]></value>
  193. </shared_code>
  194. <cases>
  195. <case>
  196. <brief>
  197. <value>AES ECB Polling</value>
  198. </brief>
  199. <description>
  200. <value>testing AES ECB with various Keys</value>
  201. </description>
  202. <condition>
  203. <value />
  204. </condition>
  205. <various_code>
  206. <setup_code>
  207. <value><![CDATA[
  208. memcpy((char*) msg_clear, test_plain_data, TEST_DATA_BYTE_LEN);
  209. memset(msg_encrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  210. memset(msg_decrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  211. cryStart(&CRYD1, &config_Polling);
  212. ]]></value>
  213. </setup_code>
  214. <teardown_code>
  215. <value><![CDATA[cryStop(&CRYD1);]]></value>
  216. </teardown_code>
  217. <local_variables>
  218. <value><![CDATA[
  219. cryerror_t ret;
  220. ]]></value>
  221. </local_variables>
  222. </various_code>
  223. <steps>
  224. <step>
  225. <description>
  226. <value>loading the key with 16 byte size</value>
  227. </description>
  228. <tags>
  229. <value />
  230. </tags>
  231. <code>
  232. <value><![CDATA[
  233. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,16, (uint8_t *) test_keys);
  234. test_assert(ret == CRY_NOERROR, "failed load transient key");
  235. ]]></value>
  236. </code>
  237. </step>
  238. <step>
  239. <description>
  240. <value>Encrypt</value>
  241. </description>
  242. <tags>
  243. <value />
  244. </tags>
  245. <code>
  246. <value><![CDATA[
  247. ret = cryEncryptAES_ECB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted);
  248. test_assert(ret == CRY_NOERROR, "encrypt failed");
  249. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  250. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  251. test_assert(msg_encrypted[i] == ((uint32_t*) refAES_ECB_128)[i], "encrypt mismatch");
  252. }
  253. ]]></value>
  254. </code>
  255. </step>
  256. <step>
  257. <description>
  258. <value>Decrypt</value>
  259. </description>
  260. <tags>
  261. <value />
  262. </tags>
  263. <code>
  264. <value><![CDATA[
  265. ret = cryDecryptAES_ECB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted);
  266. test_assert(ret == CRY_NOERROR, "decrypt failed");
  267. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  268. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  269. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  270. }
  271. ]]></value>
  272. </code>
  273. </step>
  274. <step>
  275. <description>
  276. <value>loading the key with 24 byte size</value>
  277. </description>
  278. <tags>
  279. <value />
  280. </tags>
  281. <code>
  282. <value><![CDATA[
  283. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,24, (uint8_t *) test_keys);
  284. test_assert(ret == CRY_NOERROR, "failed load transient key");
  285. ]]></value>
  286. </code>
  287. </step>
  288. <step>
  289. <description>
  290. <value>Encrypt</value>
  291. </description>
  292. <tags>
  293. <value />
  294. </tags>
  295. <code>
  296. <value><![CDATA[
  297. ret = cryEncryptAES_ECB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted);
  298. test_assert(ret == CRY_NOERROR, "encrypt failed");
  299. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  300. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  301. test_assert(msg_encrypted[i] == ((uint32_t*) refAES_ECB_192)[i], "encrypt mismatch");
  302. }
  303. ]]></value>
  304. </code>
  305. </step>
  306. <step>
  307. <description>
  308. <value>Decrypt</value>
  309. </description>
  310. <tags>
  311. <value />
  312. </tags>
  313. <code>
  314. <value><![CDATA[
  315. ret = cryDecryptAES_ECB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted);
  316. test_assert(ret == CRY_NOERROR, "decrypt failed");
  317. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  318. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  319. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  320. }
  321. ]]></value>
  322. </code>
  323. </step>
  324. <step>
  325. <description>
  326. <value>loading the key with 32 byte size</value>
  327. </description>
  328. <tags>
  329. <value />
  330. </tags>
  331. <code>
  332. <value><![CDATA[
  333. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,32, (uint8_t *) test_keys);
  334. test_assert(ret == CRY_NOERROR, "failed load transient key");
  335. ]]></value>
  336. </code>
  337. </step>
  338. <step>
  339. <description>
  340. <value>Encrypt</value>
  341. </description>
  342. <tags>
  343. <value />
  344. </tags>
  345. <code>
  346. <value><![CDATA[
  347. ret = cryEncryptAES_ECB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted);
  348. test_assert(ret == CRY_NOERROR, "encrypt failed");
  349. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  350. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  351. test_assert(msg_encrypted[i] == ((uint32_t*) refAES_ECB_256)[i], "encrypt mismatch");
  352. }
  353. ]]></value>
  354. </code>
  355. </step>
  356. <step>
  357. <description>
  358. <value>Decrypt</value>
  359. </description>
  360. <tags>
  361. <value />
  362. </tags>
  363. <code>
  364. <value><![CDATA[
  365. ret = cryDecryptAES_ECB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted);
  366. test_assert(ret == CRY_NOERROR, "decrypt failed");
  367. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  368. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  369. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  370. }
  371. ]]></value>
  372. </code>
  373. </step>
  374. </steps>
  375. </case>
  376. <case>
  377. <brief>
  378. <value>AES ECB DMA</value>
  379. </brief>
  380. <description>
  381. <value>testing AES ECB with various Keys</value>
  382. </description>
  383. <condition>
  384. <value />
  385. </condition>
  386. <various_code>
  387. <setup_code>
  388. <value><![CDATA[
  389. memcpy((char*) msg_clear, test_plain_data, TEST_DATA_BYTE_LEN);
  390. memset(msg_encrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  391. memset(msg_decrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  392. cryStart(&CRYD1, &config_DMA);
  393. ]]></value>
  394. </setup_code>
  395. <teardown_code>
  396. <value><![CDATA[cryStop(&CRYD1);]]></value>
  397. </teardown_code>
  398. <local_variables>
  399. <value><![CDATA[
  400. cryerror_t ret;
  401. ]]></value>
  402. </local_variables>
  403. </various_code>
  404. <steps>
  405. <step>
  406. <description>
  407. <value>loading the key with 16 byte size</value>
  408. </description>
  409. <tags>
  410. <value />
  411. </tags>
  412. <code>
  413. <value><![CDATA[
  414. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,16, (uint8_t *) test_keys);
  415. test_assert(ret == CRY_NOERROR, "failed load transient key");
  416. ]]></value>
  417. </code>
  418. </step>
  419. <step>
  420. <description>
  421. <value>Encrypt</value>
  422. </description>
  423. <tags>
  424. <value />
  425. </tags>
  426. <code>
  427. <value><![CDATA[
  428. ret = cryEncryptAES_ECB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted);
  429. test_assert(ret == CRY_NOERROR, "encrypt failed");
  430. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  431. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  432. test_assert(msg_encrypted[i] == ((uint32_t*) refAES_ECB_128)[i], "encrypt mismatch");
  433. }
  434. ]]></value>
  435. </code>
  436. </step>
  437. <step>
  438. <description>
  439. <value>Decrypt</value>
  440. </description>
  441. <tags>
  442. <value />
  443. </tags>
  444. <code>
  445. <value><![CDATA[
  446. ret = cryDecryptAES_ECB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted);
  447. test_assert(ret == CRY_NOERROR, "decrypt failed");
  448. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  449. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  450. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  451. }
  452. ]]></value>
  453. </code>
  454. </step>
  455. <step>
  456. <description>
  457. <value>loading the key with 24 byte size</value>
  458. </description>
  459. <tags>
  460. <value />
  461. </tags>
  462. <code>
  463. <value><![CDATA[
  464. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,24, (uint8_t *) test_keys);
  465. test_assert(ret == CRY_NOERROR, "failed load transient key");
  466. ]]></value>
  467. </code>
  468. </step>
  469. <step>
  470. <description>
  471. <value>Encrypt</value>
  472. </description>
  473. <tags>
  474. <value />
  475. </tags>
  476. <code>
  477. <value><![CDATA[
  478. ret = cryEncryptAES_ECB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted);
  479. test_assert(ret == CRY_NOERROR, "encrypt failed");
  480. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  481. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  482. test_assert(msg_encrypted[i] == ((uint32_t*) refAES_ECB_192)[i], "encrypt mismatch");
  483. }
  484. ]]></value>
  485. </code>
  486. </step>
  487. <step>
  488. <description>
  489. <value>Decrypt</value>
  490. </description>
  491. <tags>
  492. <value />
  493. </tags>
  494. <code>
  495. <value><![CDATA[
  496. ret = cryDecryptAES_ECB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted);
  497. test_assert(ret == CRY_NOERROR, "decrypt failed");
  498. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  499. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  500. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  501. }
  502. ]]></value>
  503. </code>
  504. </step>
  505. <step>
  506. <description>
  507. <value>loading the key with 32 byte size</value>
  508. </description>
  509. <tags>
  510. <value />
  511. </tags>
  512. <code>
  513. <value><![CDATA[
  514. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,32, (uint8_t *) test_keys);
  515. test_assert(ret == CRY_NOERROR, "failed load transient key");
  516. ]]></value>
  517. </code>
  518. </step>
  519. <step>
  520. <description>
  521. <value>Encrypt</value>
  522. </description>
  523. <tags>
  524. <value />
  525. </tags>
  526. <code>
  527. <value><![CDATA[
  528. ret = cryEncryptAES_ECB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted);
  529. test_assert(ret == CRY_NOERROR, "encrypt failed");
  530. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  531. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  532. test_assert(msg_encrypted[i] == ((uint32_t*) refAES_ECB_256)[i], "encrypt mismatch");
  533. }
  534. ]]></value>
  535. </code>
  536. </step>
  537. <step>
  538. <description>
  539. <value>Decrypt</value>
  540. </description>
  541. <tags>
  542. <value />
  543. </tags>
  544. <code>
  545. <value><![CDATA[
  546. ret = cryDecryptAES_ECB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted);
  547. test_assert(ret == CRY_NOERROR, "decrypt failed");
  548. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  549. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  550. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  551. }
  552. ]]></value>
  553. </code>
  554. </step>
  555. </steps>
  556. </case>
  557. </cases>
  558. </sequence>
  559. <sequence>
  560. <type index="0">
  561. <value>Internal Tests</value>
  562. </type>
  563. <brief>
  564. <value>AES CFB</value>
  565. </brief>
  566. <description>
  567. <value>AES CFB</value>
  568. </description>
  569. <condition>
  570. <value />
  571. </condition>
  572. <shared_code>
  573. <value><![CDATA[
  574. #include <string.h>
  575. #include "ref_aes.h"
  576. static const CRYConfig config_Polling = {
  577. TRANSFER_POLLING,
  578. AES_CFBS_128 //cfbs
  579. };
  580. static const CRYConfig config_DMA = {
  581. TRANSFER_DMA,
  582. AES_CFBS_128 //cfbs
  583. };
  584. ]]></value>
  585. </shared_code>
  586. <cases>
  587. <case>
  588. <brief>
  589. <value>AES CFB Polling</value>
  590. </brief>
  591. <description>
  592. <value>testing AES CFB with various Keys</value>
  593. </description>
  594. <condition>
  595. <value />
  596. </condition>
  597. <various_code>
  598. <setup_code>
  599. <value><![CDATA[
  600. memcpy((char*) msg_clear, test_plain_data, TEST_DATA_BYTE_LEN);
  601. memset(msg_encrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  602. memset(msg_decrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  603. cryStart(&CRYD1, &config_Polling);
  604. ]]></value>
  605. </setup_code>
  606. <teardown_code>
  607. <value><![CDATA[cryStop(&CRYD1);]]></value>
  608. </teardown_code>
  609. <local_variables>
  610. <value><![CDATA[
  611. cryerror_t ret;
  612. ]]></value>
  613. </local_variables>
  614. </various_code>
  615. <steps>
  616. <step>
  617. <description>
  618. <value>loading the key with 16 byte size</value>
  619. </description>
  620. <tags>
  621. <value />
  622. </tags>
  623. <code>
  624. <value><![CDATA[
  625. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,16, (uint8_t *) test_keys);
  626. test_assert(ret == CRY_NOERROR, "failed load transient key");
  627. ]]></value>
  628. </code>
  629. </step>
  630. <step>
  631. <description>
  632. <value>Encrypt</value>
  633. </description>
  634. <tags>
  635. <value />
  636. </tags>
  637. <code>
  638. <value><![CDATA[
  639. ret = cryEncryptAES_CFB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted,(uint8_t*)test_vectors);
  640. test_assert(ret == CRY_NOERROR, "encrypt failed");
  641. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  642. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  643. test_assert(msg_encrypted[i] == ((uint32_t*) refAES_CFB_128)[i], "encrypt mismatch");
  644. }
  645. ]]></value>
  646. </code>
  647. </step>
  648. <step>
  649. <description>
  650. <value>Decrypt</value>
  651. </description>
  652. <tags>
  653. <value />
  654. </tags>
  655. <code>
  656. <value><![CDATA[
  657. ret = cryDecryptAES_CFB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted,(uint8_t*)test_vectors);
  658. test_assert(ret == CRY_NOERROR, "decrypt failed");
  659. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  660. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  661. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  662. }
  663. ]]></value>
  664. </code>
  665. </step>
  666. <step>
  667. <description>
  668. <value>loading the key with 24 byte size</value>
  669. </description>
  670. <tags>
  671. <value />
  672. </tags>
  673. <code>
  674. <value><![CDATA[
  675. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,24, (uint8_t *) test_keys);
  676. test_assert(ret == CRY_NOERROR, "failed load transient key");
  677. ]]></value>
  678. </code>
  679. </step>
  680. <step>
  681. <description>
  682. <value>Encrypt</value>
  683. </description>
  684. <tags>
  685. <value />
  686. </tags>
  687. <code>
  688. <value><![CDATA[
  689. ret = cryEncryptAES_CFB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted,(uint8_t*)test_vectors);
  690. test_assert(ret == CRY_NOERROR, "encrypt failed");
  691. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  692. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  693. test_assert(msg_encrypted[i] == ((uint32_t*) refAES_CFB_192)[i], "encrypt mismatch");
  694. }
  695. ]]></value>
  696. </code>
  697. </step>
  698. <step>
  699. <description>
  700. <value>Decrypt</value>
  701. </description>
  702. <tags>
  703. <value />
  704. </tags>
  705. <code>
  706. <value><![CDATA[
  707. ret = cryDecryptAES_CFB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted,(uint8_t*)test_vectors);
  708. test_assert(ret == CRY_NOERROR, "decrypt failed");
  709. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  710. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  711. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  712. }
  713. ]]></value>
  714. </code>
  715. </step>
  716. <step>
  717. <description>
  718. <value>loading the key with 32 byte size</value>
  719. </description>
  720. <tags>
  721. <value />
  722. </tags>
  723. <code>
  724. <value><![CDATA[
  725. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,32, (uint8_t *) test_keys);
  726. test_assert(ret == CRY_NOERROR, "failed load transient key");
  727. ]]></value>
  728. </code>
  729. </step>
  730. <step>
  731. <description>
  732. <value>Encrypt</value>
  733. </description>
  734. <tags>
  735. <value />
  736. </tags>
  737. <code>
  738. <value><![CDATA[
  739. ret = cryEncryptAES_CFB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted,(uint8_t*)test_vectors);
  740. test_assert(ret == CRY_NOERROR, "encrypt failed");
  741. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  742. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  743. test_assert(msg_encrypted[i] == ((uint32_t*) refAES_CFB_256)[i], "encrypt mismatch");
  744. }
  745. ]]></value>
  746. </code>
  747. </step>
  748. <step>
  749. <description>
  750. <value>Decrypt</value>
  751. </description>
  752. <tags>
  753. <value />
  754. </tags>
  755. <code>
  756. <value><![CDATA[
  757. ret = cryDecryptAES_CFB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted,(uint8_t*)test_vectors);
  758. test_assert(ret == CRY_NOERROR, "decrypt failed");
  759. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  760. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  761. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  762. }
  763. ]]></value>
  764. </code>
  765. </step>
  766. </steps>
  767. </case>
  768. <case>
  769. <brief>
  770. <value>AES CFB DMA</value>
  771. </brief>
  772. <description>
  773. <value>testing AES CFB with various Keys</value>
  774. </description>
  775. <condition>
  776. <value />
  777. </condition>
  778. <various_code>
  779. <setup_code>
  780. <value><![CDATA[
  781. memcpy((char*) msg_clear, test_plain_data, TEST_DATA_BYTE_LEN);
  782. memset(msg_encrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  783. memset(msg_decrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  784. cryStart(&CRYD1, &config_DMA);
  785. ]]></value>
  786. </setup_code>
  787. <teardown_code>
  788. <value><![CDATA[cryStop(&CRYD1);]]></value>
  789. </teardown_code>
  790. <local_variables>
  791. <value><![CDATA[
  792. cryerror_t ret;
  793. ]]></value>
  794. </local_variables>
  795. </various_code>
  796. <steps>
  797. <step>
  798. <description>
  799. <value>loading the key with 16 byte size</value>
  800. </description>
  801. <tags>
  802. <value />
  803. </tags>
  804. <code>
  805. <value><![CDATA[
  806. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,16, (uint8_t *) test_keys);
  807. test_assert(ret == CRY_NOERROR, "failed load transient key");
  808. ]]></value>
  809. </code>
  810. </step>
  811. <step>
  812. <description>
  813. <value>Encrypt</value>
  814. </description>
  815. <tags>
  816. <value />
  817. </tags>
  818. <code>
  819. <value><![CDATA[
  820. ret = cryEncryptAES_CFB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted,(uint8_t*)test_vectors);
  821. test_assert(ret == CRY_NOERROR, "encrypt failed");
  822. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  823. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  824. test_assert(msg_encrypted[i] == ((uint32_t*) refAES_CFB_128)[i], "encrypt mismatch");
  825. }
  826. ]]></value>
  827. </code>
  828. </step>
  829. <step>
  830. <description>
  831. <value>Decrypt</value>
  832. </description>
  833. <tags>
  834. <value />
  835. </tags>
  836. <code>
  837. <value><![CDATA[
  838. ret = cryDecryptAES_CFB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted,(uint8_t*)test_vectors);
  839. test_assert(ret == CRY_NOERROR, "decrypt failed");
  840. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  841. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  842. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  843. }
  844. ]]></value>
  845. </code>
  846. </step>
  847. <step>
  848. <description>
  849. <value>loading the key with 24 byte size</value>
  850. </description>
  851. <tags>
  852. <value />
  853. </tags>
  854. <code>
  855. <value><![CDATA[
  856. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,24, (uint8_t *) test_keys);
  857. test_assert(ret == CRY_NOERROR, "failed load transient key");
  858. ]]></value>
  859. </code>
  860. </step>
  861. <step>
  862. <description>
  863. <value>Encrypt</value>
  864. </description>
  865. <tags>
  866. <value />
  867. </tags>
  868. <code>
  869. <value><![CDATA[
  870. ret = cryEncryptAES_CFB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted,(uint8_t*)test_vectors);
  871. test_assert(ret == CRY_NOERROR, "encrypt failed");
  872. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  873. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  874. test_assert(msg_encrypted[i] == ((uint32_t*) refAES_CFB_192)[i], "encrypt mismatch");
  875. }
  876. ]]></value>
  877. </code>
  878. </step>
  879. <step>
  880. <description>
  881. <value>Decrypt</value>
  882. </description>
  883. <tags>
  884. <value />
  885. </tags>
  886. <code>
  887. <value><![CDATA[
  888. ret = cryDecryptAES_CFB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted,(uint8_t*)test_vectors);
  889. test_assert(ret == CRY_NOERROR, "decrypt failed");
  890. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  891. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  892. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  893. }
  894. ]]></value>
  895. </code>
  896. </step>
  897. <step>
  898. <description>
  899. <value>loading the key with 32 byte size</value>
  900. </description>
  901. <tags>
  902. <value />
  903. </tags>
  904. <code>
  905. <value><![CDATA[
  906. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,32, (uint8_t *) test_keys);
  907. test_assert(ret == CRY_NOERROR, "failed load transient key");
  908. ]]></value>
  909. </code>
  910. </step>
  911. <step>
  912. <description>
  913. <value>Encrypt</value>
  914. </description>
  915. <tags>
  916. <value />
  917. </tags>
  918. <code>
  919. <value><![CDATA[
  920. ret = cryEncryptAES_CFB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted,(uint8_t*)test_vectors);
  921. test_assert(ret == CRY_NOERROR, "encrypt failed");
  922. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  923. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  924. test_assert(msg_encrypted[i] == ((uint32_t*) refAES_CFB_256)[i], "encrypt mismatch");
  925. }
  926. ]]></value>
  927. </code>
  928. </step>
  929. <step>
  930. <description>
  931. <value>Decrypt</value>
  932. </description>
  933. <tags>
  934. <value />
  935. </tags>
  936. <code>
  937. <value><![CDATA[
  938. ret = cryDecryptAES_CFB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted,(uint8_t*)test_vectors);
  939. test_assert(ret == CRY_NOERROR, "decrypt failed");
  940. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  941. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  942. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  943. }
  944. ]]></value>
  945. </code>
  946. </step>
  947. </steps>
  948. </case>
  949. </cases>
  950. </sequence>
  951. <sequence>
  952. <type index="0">
  953. <value>Internal Tests</value>
  954. </type>
  955. <brief>
  956. <value>AES CBC</value>
  957. </brief>
  958. <description>
  959. <value>AES CBC</value>
  960. </description>
  961. <condition>
  962. <value />
  963. </condition>
  964. <shared_code>
  965. <value><![CDATA[
  966. #include <string.h>
  967. #include "ref_aes.h"
  968. static const CRYConfig config_Polling = {
  969. TRANSFER_POLLING,
  970. AES_CFBS_128 //cfbs
  971. };
  972. static const CRYConfig config_DMA = {
  973. TRANSFER_DMA,
  974. AES_CFBS_128 //cfbs
  975. };
  976. ]]></value>
  977. </shared_code>
  978. <cases>
  979. <case>
  980. <brief>
  981. <value>AES CBC Polling</value>
  982. </brief>
  983. <description>
  984. <value>testing AES CBC with various Keys</value>
  985. </description>
  986. <condition>
  987. <value />
  988. </condition>
  989. <various_code>
  990. <setup_code>
  991. <value><![CDATA[
  992. memcpy((char*) msg_clear, test_plain_data, TEST_DATA_BYTE_LEN);
  993. memset(msg_encrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  994. memset(msg_decrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  995. cryStart(&CRYD1, &config_Polling);
  996. ]]></value>
  997. </setup_code>
  998. <teardown_code>
  999. <value><![CDATA[cryStop(&CRYD1);]]></value>
  1000. </teardown_code>
  1001. <local_variables>
  1002. <value><![CDATA[
  1003. cryerror_t ret;
  1004. ]]></value>
  1005. </local_variables>
  1006. </various_code>
  1007. <steps>
  1008. <step>
  1009. <description>
  1010. <value>loading the key with 16 byte size</value>
  1011. </description>
  1012. <tags>
  1013. <value />
  1014. </tags>
  1015. <code>
  1016. <value><![CDATA[
  1017. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,16, (uint8_t *) test_keys);
  1018. test_assert(ret == CRY_NOERROR, "failed load transient key");
  1019. ]]></value>
  1020. </code>
  1021. </step>
  1022. <step>
  1023. <description>
  1024. <value>Encrypt</value>
  1025. </description>
  1026. <tags>
  1027. <value />
  1028. </tags>
  1029. <code>
  1030. <value><![CDATA[
  1031. ret = cryEncryptAES_CBC(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted,(uint8_t*)test_vectors);
  1032. test_assert(ret == CRY_NOERROR, "encrypt failed");
  1033. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  1034. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1035. test_assert(msg_encrypted[i] == ((uint32_t*) refAES_CBC_128)[i], "encrypt mismatch");
  1036. }
  1037. ]]></value>
  1038. </code>
  1039. </step>
  1040. <step>
  1041. <description>
  1042. <value>Decrypt</value>
  1043. </description>
  1044. <tags>
  1045. <value />
  1046. </tags>
  1047. <code>
  1048. <value><![CDATA[
  1049. ret = cryDecryptAES_CBC(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted,(uint8_t*)test_vectors);
  1050. test_assert(ret == CRY_NOERROR, "decrypt failed");
  1051. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  1052. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1053. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  1054. }
  1055. ]]></value>
  1056. </code>
  1057. </step>
  1058. <step>
  1059. <description>
  1060. <value>loading the key with 24 byte size</value>
  1061. </description>
  1062. <tags>
  1063. <value />
  1064. </tags>
  1065. <code>
  1066. <value><![CDATA[
  1067. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,24, (uint8_t *) test_keys);
  1068. test_assert(ret == CRY_NOERROR, "failed load transient key");
  1069. ]]></value>
  1070. </code>
  1071. </step>
  1072. <step>
  1073. <description>
  1074. <value>Encrypt</value>
  1075. </description>
  1076. <tags>
  1077. <value />
  1078. </tags>
  1079. <code>
  1080. <value><![CDATA[
  1081. ret = cryEncryptAES_CBC(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted,(uint8_t*)test_vectors);
  1082. test_assert(ret == CRY_NOERROR, "encrypt failed");
  1083. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  1084. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1085. test_assert(msg_encrypted[i] == ((uint32_t*) refAES_CBC_192)[i], "encrypt mismatch");
  1086. }
  1087. ]]></value>
  1088. </code>
  1089. </step>
  1090. <step>
  1091. <description>
  1092. <value>Decrypt</value>
  1093. </description>
  1094. <tags>
  1095. <value />
  1096. </tags>
  1097. <code>
  1098. <value><![CDATA[
  1099. ret = cryDecryptAES_CBC(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted,(uint8_t*)test_vectors);
  1100. test_assert(ret == CRY_NOERROR, "decrypt failed");
  1101. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  1102. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1103. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  1104. }
  1105. ]]></value>
  1106. </code>
  1107. </step>
  1108. <step>
  1109. <description>
  1110. <value>loading the key with 32 byte size</value>
  1111. </description>
  1112. <tags>
  1113. <value />
  1114. </tags>
  1115. <code>
  1116. <value><![CDATA[
  1117. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,32, (uint8_t *) test_keys);
  1118. test_assert(ret == CRY_NOERROR, "failed load transient key");
  1119. ]]></value>
  1120. </code>
  1121. </step>
  1122. <step>
  1123. <description>
  1124. <value>Encrypt</value>
  1125. </description>
  1126. <tags>
  1127. <value />
  1128. </tags>
  1129. <code>
  1130. <value><![CDATA[
  1131. ret = cryEncryptAES_CBC(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted,(uint8_t*)test_vectors);
  1132. test_assert(ret == CRY_NOERROR, "encrypt failed");
  1133. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  1134. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1135. test_assert(msg_encrypted[i] == ((uint32_t*) refAES_CBC_256)[i], "encrypt mismatch");
  1136. }
  1137. ]]></value>
  1138. </code>
  1139. </step>
  1140. <step>
  1141. <description>
  1142. <value>Decrypt</value>
  1143. </description>
  1144. <tags>
  1145. <value />
  1146. </tags>
  1147. <code>
  1148. <value><![CDATA[
  1149. ret = cryDecryptAES_CBC(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted,(uint8_t*)test_vectors);
  1150. test_assert(ret == CRY_NOERROR, "decrypt failed");
  1151. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  1152. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1153. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  1154. }
  1155. ]]></value>
  1156. </code>
  1157. </step>
  1158. </steps>
  1159. </case>
  1160. <case>
  1161. <brief>
  1162. <value>AES CBC DMA</value>
  1163. </brief>
  1164. <description>
  1165. <value>testing AES CBC with various Keys</value>
  1166. </description>
  1167. <condition>
  1168. <value />
  1169. </condition>
  1170. <various_code>
  1171. <setup_code>
  1172. <value><![CDATA[
  1173. memcpy((char*) msg_clear, test_plain_data, TEST_DATA_BYTE_LEN);
  1174. memset(msg_encrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  1175. memset(msg_decrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  1176. cryStart(&CRYD1, &config_DMA);
  1177. ]]></value>
  1178. </setup_code>
  1179. <teardown_code>
  1180. <value><![CDATA[cryStop(&CRYD1);]]></value>
  1181. </teardown_code>
  1182. <local_variables>
  1183. <value><![CDATA[
  1184. cryerror_t ret;
  1185. ]]></value>
  1186. </local_variables>
  1187. </various_code>
  1188. <steps>
  1189. <step>
  1190. <description>
  1191. <value>loading the key with 16 byte size</value>
  1192. </description>
  1193. <tags>
  1194. <value />
  1195. </tags>
  1196. <code>
  1197. <value><![CDATA[
  1198. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,16, (uint8_t *) test_keys);
  1199. test_assert(ret == CRY_NOERROR, "failed load transient key");
  1200. ]]></value>
  1201. </code>
  1202. </step>
  1203. <step>
  1204. <description>
  1205. <value>Encrypt</value>
  1206. </description>
  1207. <tags>
  1208. <value />
  1209. </tags>
  1210. <code>
  1211. <value><![CDATA[
  1212. ret = cryEncryptAES_CBC(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted,(uint8_t*)test_vectors);
  1213. test_assert(ret == CRY_NOERROR, "encrypt failed");
  1214. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  1215. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1216. test_assert(msg_encrypted[i] == ((uint32_t*) refAES_CBC_128)[i], "encrypt mismatch");
  1217. }
  1218. ]]></value>
  1219. </code>
  1220. </step>
  1221. <step>
  1222. <description>
  1223. <value>Decrypt</value>
  1224. </description>
  1225. <tags>
  1226. <value />
  1227. </tags>
  1228. <code>
  1229. <value><![CDATA[
  1230. ret = cryDecryptAES_CBC(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted,(uint8_t*)test_vectors);
  1231. test_assert(ret == CRY_NOERROR, "decrypt failed");
  1232. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  1233. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1234. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  1235. }
  1236. ]]></value>
  1237. </code>
  1238. </step>
  1239. <step>
  1240. <description>
  1241. <value>loading the key with 24 byte size</value>
  1242. </description>
  1243. <tags>
  1244. <value />
  1245. </tags>
  1246. <code>
  1247. <value><![CDATA[
  1248. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,24, (uint8_t *) test_keys);
  1249. test_assert(ret == CRY_NOERROR, "failed load transient key");
  1250. ]]></value>
  1251. </code>
  1252. </step>
  1253. <step>
  1254. <description>
  1255. <value>Encrypt</value>
  1256. </description>
  1257. <tags>
  1258. <value />
  1259. </tags>
  1260. <code>
  1261. <value><![CDATA[
  1262. ret = cryEncryptAES_CBC(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted,(uint8_t*)test_vectors);
  1263. test_assert(ret == CRY_NOERROR, "encrypt failed");
  1264. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  1265. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1266. test_assert(msg_encrypted[i] == ((uint32_t*) refAES_CBC_192)[i], "encrypt mismatch");
  1267. }
  1268. ]]></value>
  1269. </code>
  1270. </step>
  1271. <step>
  1272. <description>
  1273. <value>Decrypt</value>
  1274. </description>
  1275. <tags>
  1276. <value />
  1277. </tags>
  1278. <code>
  1279. <value><![CDATA[
  1280. ret = cryDecryptAES_CBC(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted,(uint8_t*)test_vectors);
  1281. test_assert(ret == CRY_NOERROR, "decrypt failed");
  1282. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  1283. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1284. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  1285. }
  1286. ]]></value>
  1287. </code>
  1288. </step>
  1289. <step>
  1290. <description>
  1291. <value>loading the key with 32 byte size</value>
  1292. </description>
  1293. <tags>
  1294. <value />
  1295. </tags>
  1296. <code>
  1297. <value><![CDATA[
  1298. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,32, (uint8_t *) test_keys);
  1299. test_assert(ret == CRY_NOERROR, "failed load transient key");
  1300. ]]></value>
  1301. </code>
  1302. </step>
  1303. <step>
  1304. <description>
  1305. <value>Encrypt</value>
  1306. </description>
  1307. <tags>
  1308. <value />
  1309. </tags>
  1310. <code>
  1311. <value><![CDATA[
  1312. ret = cryEncryptAES_CBC(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted,(uint8_t*)test_vectors);
  1313. test_assert(ret == CRY_NOERROR, "encrypt failed");
  1314. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  1315. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1316. test_assert(msg_encrypted[i] == ((uint32_t*) refAES_CBC_256)[i], "encrypt mismatch");
  1317. }
  1318. ]]></value>
  1319. </code>
  1320. </step>
  1321. <step>
  1322. <description>
  1323. <value>Decrypt</value>
  1324. </description>
  1325. <tags>
  1326. <value />
  1327. </tags>
  1328. <code>
  1329. <value><![CDATA[
  1330. ret = cryDecryptAES_CBC(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted,(uint8_t*)test_vectors);
  1331. test_assert(ret == CRY_NOERROR, "decrypt failed");
  1332. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  1333. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1334. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  1335. }
  1336. ]]></value>
  1337. </code>
  1338. </step>
  1339. </steps>
  1340. </case>
  1341. </cases>
  1342. </sequence>
  1343. <sequence>
  1344. <type index="0">
  1345. <value>Internal Tests</value>
  1346. </type>
  1347. <brief>
  1348. <value>(T)DES</value>
  1349. </brief>
  1350. <description>
  1351. <value>(T)DES testing</value>
  1352. </description>
  1353. <condition>
  1354. <value />
  1355. </condition>
  1356. <shared_code>
  1357. <value><![CDATA[
  1358. #include <string.h>
  1359. #include "ref_des.h"
  1360. static const CRYConfig configDES_Polling=
  1361. {
  1362. TRANSFER_POLLING,
  1363. 0
  1364. };
  1365. static const CRYConfig configDES_DMA=
  1366. {
  1367. TRANSFER_DMA,
  1368. 0
  1369. };
  1370. ]]></value>
  1371. </shared_code>
  1372. <cases>
  1373. <case>
  1374. <brief>
  1375. <value>DES Polling</value>
  1376. </brief>
  1377. <description>
  1378. <value>testing DES in polled mode</value>
  1379. </description>
  1380. <condition>
  1381. <value />
  1382. </condition>
  1383. <various_code>
  1384. <setup_code>
  1385. <value><![CDATA[
  1386. memcpy((char*) msg_clear, test_plain_data, TEST_DATA_BYTE_LEN);
  1387. memset(msg_encrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  1388. memset(msg_decrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  1389. cryStart(&CRYD1, &configDES_Polling);
  1390. ]]></value>
  1391. </setup_code>
  1392. <teardown_code>
  1393. <value><![CDATA[cryStop(&CRYD1);]]></value>
  1394. </teardown_code>
  1395. <local_variables>
  1396. <value><![CDATA[
  1397. cryerror_t ret;
  1398. ]]></value>
  1399. </local_variables>
  1400. </various_code>
  1401. <steps>
  1402. <step>
  1403. <description>
  1404. <value>loading the key with 8 byte size</value>
  1405. </description>
  1406. <tags>
  1407. <value />
  1408. </tags>
  1409. <code>
  1410. <value><![CDATA[
  1411. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_des,8, (uint8_t *) test_keys);
  1412. test_assert(ret == CRY_NOERROR, "failed load transient key");
  1413. ]]></value>
  1414. </code>
  1415. </step>
  1416. <step>
  1417. <description>
  1418. <value>Encrypt</value>
  1419. </description>
  1420. <tags>
  1421. <value />
  1422. </tags>
  1423. <code>
  1424. <value><![CDATA[
  1425. ret = cryEncryptDES(&CRYD1, 0, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted);
  1426. test_assert(ret == CRY_NOERROR, "encrypt failed");
  1427. SHOW_ENCRYPDATA(2);
  1428. for (int i = 0; i < 2; i++) {
  1429. test_assert(msg_encrypted[i] == ((uint32_t*) refDES_ECB_8)[i], "encrypt mismatch");
  1430. }
  1431. ]]></value>
  1432. </code>
  1433. </step>
  1434. <step>
  1435. <description>
  1436. <value>Decrypt</value>
  1437. </description>
  1438. <tags>
  1439. <value />
  1440. </tags>
  1441. <code>
  1442. <value><![CDATA[
  1443. ret = cryDecryptDES(&CRYD1, 0, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted);
  1444. test_assert(ret == CRY_NOERROR, "decrypt failed");
  1445. SHOW_DECRYPDATA(2);
  1446. for (int i = 0; i < 2; i++) {
  1447. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  1448. }
  1449. ]]></value>
  1450. </code>
  1451. </step>
  1452. </steps>
  1453. </case>
  1454. <case>
  1455. <brief>
  1456. <value>TDES CBC Polling</value>
  1457. </brief>
  1458. <description>
  1459. <value>testing TDES CBC in polled mode</value>
  1460. </description>
  1461. <condition>
  1462. <value />
  1463. </condition>
  1464. <various_code>
  1465. <setup_code>
  1466. <value><![CDATA[
  1467. memcpy((char*) msg_clear, test_plain_data, TEST_DATA_BYTE_LEN);
  1468. memset(msg_encrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  1469. memset(msg_decrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  1470. cryStart(&CRYD1, &configDES_Polling);
  1471. ]]></value>
  1472. </setup_code>
  1473. <teardown_code>
  1474. <value><![CDATA[cryStop(&CRYD1);]]></value>
  1475. </teardown_code>
  1476. <local_variables>
  1477. <value><![CDATA[
  1478. cryerror_t ret;
  1479. ]]></value>
  1480. </local_variables>
  1481. </various_code>
  1482. <steps>
  1483. <step>
  1484. <description>
  1485. <value>loading the key with 16 byte size</value>
  1486. </description>
  1487. <tags>
  1488. <value />
  1489. </tags>
  1490. <code>
  1491. <value><![CDATA[
  1492. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_des,16, (uint8_t *) test_keys);
  1493. test_assert(ret == CRY_NOERROR, "failed load transient key");
  1494. ]]></value>
  1495. </code>
  1496. </step>
  1497. <step>
  1498. <description>
  1499. <value>Encrypt</value>
  1500. </description>
  1501. <tags>
  1502. <value />
  1503. </tags>
  1504. <code>
  1505. <value><![CDATA[
  1506. ret = cryEncryptDES_CBC(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted,(uint8_t*)test_vectors);
  1507. test_assert(ret == CRY_NOERROR, "encrypt failed");
  1508. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  1509. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1510. test_assert(msg_encrypted[i] == ((uint32_t*) refTDES_CBC_16)[i], "encrypt mismatch");
  1511. }
  1512. ]]></value>
  1513. </code>
  1514. </step>
  1515. <step>
  1516. <description>
  1517. <value>Decrypt</value>
  1518. </description>
  1519. <tags>
  1520. <value />
  1521. </tags>
  1522. <code>
  1523. <value><![CDATA[
  1524. ret = cryDecryptDES_CBC(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted,(uint8_t*)test_vectors);
  1525. test_assert(ret == CRY_NOERROR, "decrypt failed");
  1526. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  1527. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1528. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  1529. }
  1530. ]]></value>
  1531. </code>
  1532. </step>
  1533. <step>
  1534. <description>
  1535. <value>loading the key with 24 byte size</value>
  1536. </description>
  1537. <tags>
  1538. <value />
  1539. </tags>
  1540. <code>
  1541. <value><![CDATA[
  1542. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_des,24, (uint8_t *) test_keys);
  1543. test_assert(ret == CRY_NOERROR, "failed load transient key");
  1544. ]]></value>
  1545. </code>
  1546. </step>
  1547. <step>
  1548. <description>
  1549. <value>Encrypt</value>
  1550. </description>
  1551. <tags>
  1552. <value />
  1553. </tags>
  1554. <code>
  1555. <value><![CDATA[
  1556. ret = cryEncryptDES_CBC(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted,(uint8_t*)test_vectors);
  1557. test_assert(ret == CRY_NOERROR, "encrypt failed");
  1558. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  1559. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1560. test_assert(msg_encrypted[i] == ((uint32_t*) refTDES_CBC_24)[i], "encrypt mismatch");
  1561. }
  1562. ]]></value>
  1563. </code>
  1564. </step>
  1565. <step>
  1566. <description>
  1567. <value>Decrypt</value>
  1568. </description>
  1569. <tags>
  1570. <value />
  1571. </tags>
  1572. <code>
  1573. <value><![CDATA[
  1574. ret = cryDecryptDES_CBC(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted,(uint8_t*)test_vectors);
  1575. test_assert(ret == CRY_NOERROR, "decrypt failed");
  1576. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  1577. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1578. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  1579. }
  1580. ]]></value>
  1581. </code>
  1582. </step>
  1583. </steps>
  1584. </case>
  1585. <case>
  1586. <brief>
  1587. <value>TDES ECB Polling</value>
  1588. </brief>
  1589. <description>
  1590. <value>testing TDES ECB in polling mode</value>
  1591. </description>
  1592. <condition>
  1593. <value />
  1594. </condition>
  1595. <various_code>
  1596. <setup_code>
  1597. <value><![CDATA[
  1598. memcpy((char*) msg_clear, test_plain_data, TEST_DATA_BYTE_LEN);
  1599. memset(msg_encrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  1600. memset(msg_decrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  1601. cryStart(&CRYD1, &configDES_Polling);
  1602. ]]></value>
  1603. </setup_code>
  1604. <teardown_code>
  1605. <value><![CDATA[cryStop(&CRYD1);]]></value>
  1606. </teardown_code>
  1607. <local_variables>
  1608. <value><![CDATA[
  1609. cryerror_t ret;
  1610. ]]></value>
  1611. </local_variables>
  1612. </various_code>
  1613. <steps>
  1614. <step>
  1615. <description>
  1616. <value>loading the key with 16 byte size</value>
  1617. </description>
  1618. <tags>
  1619. <value />
  1620. </tags>
  1621. <code>
  1622. <value><![CDATA[
  1623. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_des,16, (uint8_t *) test_keys);
  1624. test_assert(ret == CRY_NOERROR, "failed load transient key");
  1625. ]]></value>
  1626. </code>
  1627. </step>
  1628. <step>
  1629. <description>
  1630. <value>Encrypt</value>
  1631. </description>
  1632. <tags>
  1633. <value />
  1634. </tags>
  1635. <code>
  1636. <value><![CDATA[
  1637. ret = cryEncryptDES_ECB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted);
  1638. test_assert(ret == CRY_NOERROR, "encrypt failed");
  1639. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  1640. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1641. test_assert(msg_encrypted[i] == ((uint32_t*) refTDES_ECB_16)[i], "encrypt mismatch");
  1642. }
  1643. ]]></value>
  1644. </code>
  1645. </step>
  1646. <step>
  1647. <description>
  1648. <value>Decrypt</value>
  1649. </description>
  1650. <tags>
  1651. <value />
  1652. </tags>
  1653. <code>
  1654. <value><![CDATA[
  1655. ret = cryDecryptDES_ECB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted);
  1656. test_assert(ret == CRY_NOERROR, "decrypt failed");
  1657. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  1658. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1659. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  1660. }
  1661. ]]></value>
  1662. </code>
  1663. </step>
  1664. <step>
  1665. <description>
  1666. <value>loading the key with 24 byte size</value>
  1667. </description>
  1668. <tags>
  1669. <value />
  1670. </tags>
  1671. <code>
  1672. <value><![CDATA[
  1673. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_des,24, (uint8_t *) test_keys);
  1674. test_assert(ret == CRY_NOERROR, "failed load transient key");
  1675. ]]></value>
  1676. </code>
  1677. </step>
  1678. <step>
  1679. <description>
  1680. <value>Encrypt</value>
  1681. </description>
  1682. <tags>
  1683. <value />
  1684. </tags>
  1685. <code>
  1686. <value><![CDATA[
  1687. ret = cryEncryptDES_ECB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted);
  1688. test_assert(ret == CRY_NOERROR, "encrypt failed");
  1689. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  1690. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1691. test_assert(msg_encrypted[i] == ((uint32_t*) refTDES_ECB_24)[i], "encrypt mismatch");
  1692. }
  1693. ]]></value>
  1694. </code>
  1695. </step>
  1696. <step>
  1697. <description>
  1698. <value>Decrypt</value>
  1699. </description>
  1700. <tags>
  1701. <value />
  1702. </tags>
  1703. <code>
  1704. <value><![CDATA[
  1705. ret = cryDecryptDES_ECB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted);
  1706. test_assert(ret == CRY_NOERROR, "decrypt failed");
  1707. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  1708. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1709. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  1710. }
  1711. ]]></value>
  1712. </code>
  1713. </step>
  1714. </steps>
  1715. </case>
  1716. <case>
  1717. <brief>
  1718. <value>TDES CBC DMA</value>
  1719. </brief>
  1720. <description>
  1721. <value>testing TDES CBC in polled mode</value>
  1722. </description>
  1723. <condition>
  1724. <value />
  1725. </condition>
  1726. <various_code>
  1727. <setup_code>
  1728. <value><![CDATA[
  1729. memcpy((char*) msg_clear, test_plain_data, TEST_DATA_BYTE_LEN);
  1730. memset(msg_encrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  1731. memset(msg_decrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  1732. cryStart(&CRYD1, &configDES_DMA);
  1733. ]]></value>
  1734. </setup_code>
  1735. <teardown_code>
  1736. <value><![CDATA[cryStop(&CRYD1);]]></value>
  1737. </teardown_code>
  1738. <local_variables>
  1739. <value><![CDATA[
  1740. cryerror_t ret;
  1741. ]]></value>
  1742. </local_variables>
  1743. </various_code>
  1744. <steps>
  1745. <step>
  1746. <description>
  1747. <value>loading the key with 16 byte size</value>
  1748. </description>
  1749. <tags>
  1750. <value />
  1751. </tags>
  1752. <code>
  1753. <value><![CDATA[
  1754. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_des,16, (uint8_t *) test_keys);
  1755. test_assert(ret == CRY_NOERROR, "failed load transient key");
  1756. ]]></value>
  1757. </code>
  1758. </step>
  1759. <step>
  1760. <description>
  1761. <value>Encrypt</value>
  1762. </description>
  1763. <tags>
  1764. <value />
  1765. </tags>
  1766. <code>
  1767. <value><![CDATA[
  1768. ret = cryEncryptDES_CBC(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted,(uint8_t*)test_vectors);
  1769. test_assert(ret == CRY_NOERROR, "encrypt failed");
  1770. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  1771. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1772. test_assert(msg_encrypted[i] == ((uint32_t*) refTDES_CBC_16)[i], "encrypt mismatch");
  1773. }
  1774. ]]></value>
  1775. </code>
  1776. </step>
  1777. <step>
  1778. <description>
  1779. <value>Decrypt</value>
  1780. </description>
  1781. <tags>
  1782. <value />
  1783. </tags>
  1784. <code>
  1785. <value><![CDATA[
  1786. ret = cryDecryptDES_CBC(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted,(uint8_t*)test_vectors);
  1787. test_assert(ret == CRY_NOERROR, "decrypt failed");
  1788. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  1789. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1790. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  1791. }
  1792. ]]></value>
  1793. </code>
  1794. </step>
  1795. <step>
  1796. <description>
  1797. <value>loading the key with 24 byte size</value>
  1798. </description>
  1799. <tags>
  1800. <value />
  1801. </tags>
  1802. <code>
  1803. <value><![CDATA[
  1804. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_des,24, (uint8_t *) test_keys);
  1805. test_assert(ret == CRY_NOERROR, "failed load transient key");
  1806. ]]></value>
  1807. </code>
  1808. </step>
  1809. <step>
  1810. <description>
  1811. <value>Encrypt</value>
  1812. </description>
  1813. <tags>
  1814. <value />
  1815. </tags>
  1816. <code>
  1817. <value><![CDATA[
  1818. ret = cryEncryptDES_CBC(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted,(uint8_t*)test_vectors);
  1819. test_assert(ret == CRY_NOERROR, "encrypt failed");
  1820. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  1821. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1822. test_assert(msg_encrypted[i] == ((uint32_t*) refTDES_CBC_24)[i], "encrypt mismatch");
  1823. }
  1824. ]]></value>
  1825. </code>
  1826. </step>
  1827. <step>
  1828. <description>
  1829. <value>Decrypt</value>
  1830. </description>
  1831. <tags>
  1832. <value />
  1833. </tags>
  1834. <code>
  1835. <value><![CDATA[
  1836. ret = cryDecryptDES_CBC(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted,(uint8_t*)test_vectors);
  1837. test_assert(ret == CRY_NOERROR, "decrypt failed");
  1838. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  1839. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1840. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  1841. }
  1842. ]]></value>
  1843. </code>
  1844. </step>
  1845. </steps>
  1846. </case>
  1847. <case>
  1848. <brief>
  1849. <value>TDES ECB DMA</value>
  1850. </brief>
  1851. <description>
  1852. <value>testing TDES ECB in DMA mode</value>
  1853. </description>
  1854. <condition>
  1855. <value />
  1856. </condition>
  1857. <various_code>
  1858. <setup_code>
  1859. <value><![CDATA[
  1860. memcpy((char*) msg_clear, test_plain_data, TEST_DATA_BYTE_LEN);
  1861. memset(msg_encrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  1862. memset(msg_decrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
  1863. cryStart(&CRYD1, &configDES_DMA);
  1864. ]]></value>
  1865. </setup_code>
  1866. <teardown_code>
  1867. <value><![CDATA[cryStop(&CRYD1);]]></value>
  1868. </teardown_code>
  1869. <local_variables>
  1870. <value><![CDATA[
  1871. cryerror_t ret;
  1872. ]]></value>
  1873. </local_variables>
  1874. </various_code>
  1875. <steps>
  1876. <step>
  1877. <description>
  1878. <value>loading the key with 16 byte size</value>
  1879. </description>
  1880. <tags>
  1881. <value />
  1882. </tags>
  1883. <code>
  1884. <value><![CDATA[
  1885. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_des,16, (uint8_t *) test_keys);
  1886. test_assert(ret == CRY_NOERROR, "failed load transient key");
  1887. ]]></value>
  1888. </code>
  1889. </step>
  1890. <step>
  1891. <description>
  1892. <value>Encrypt</value>
  1893. </description>
  1894. <tags>
  1895. <value />
  1896. </tags>
  1897. <code>
  1898. <value><![CDATA[
  1899. ret = cryEncryptDES_ECB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted);
  1900. test_assert(ret == CRY_NOERROR, "encrypt failed");
  1901. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  1902. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1903. test_assert(msg_encrypted[i] == ((uint32_t*) refTDES_ECB_16)[i], "encrypt mismatch");
  1904. }
  1905. ]]></value>
  1906. </code>
  1907. </step>
  1908. <step>
  1909. <description>
  1910. <value>Decrypt</value>
  1911. </description>
  1912. <tags>
  1913. <value />
  1914. </tags>
  1915. <code>
  1916. <value><![CDATA[
  1917. ret = cryDecryptDES_ECB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted);
  1918. test_assert(ret == CRY_NOERROR, "decrypt failed");
  1919. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  1920. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1921. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  1922. }
  1923. ]]></value>
  1924. </code>
  1925. </step>
  1926. <step>
  1927. <description>
  1928. <value>loading the key with 24 byte size</value>
  1929. </description>
  1930. <tags>
  1931. <value />
  1932. </tags>
  1933. <code>
  1934. <value><![CDATA[
  1935. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_des,24, (uint8_t *) test_keys);
  1936. test_assert(ret == CRY_NOERROR, "failed load transient key");
  1937. ]]></value>
  1938. </code>
  1939. </step>
  1940. <step>
  1941. <description>
  1942. <value>Encrypt</value>
  1943. </description>
  1944. <tags>
  1945. <value />
  1946. </tags>
  1947. <code>
  1948. <value><![CDATA[
  1949. ret = cryEncryptDES_ECB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_clear, (uint8_t*) msg_encrypted);
  1950. test_assert(ret == CRY_NOERROR, "encrypt failed");
  1951. SHOW_ENCRYPDATA(TEST_DATA_WORD_LEN);
  1952. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1953. test_assert(msg_encrypted[i] == ((uint32_t*) refTDES_ECB_24)[i], "encrypt mismatch");
  1954. }
  1955. ]]></value>
  1956. </code>
  1957. </step>
  1958. <step>
  1959. <description>
  1960. <value>Decrypt</value>
  1961. </description>
  1962. <tags>
  1963. <value />
  1964. </tags>
  1965. <code>
  1966. <value><![CDATA[
  1967. ret = cryDecryptDES_ECB(&CRYD1, 0,TEST_DATA_BYTE_LEN, (uint8_t*) msg_encrypted, (uint8_t*) msg_decrypted);
  1968. test_assert(ret == CRY_NOERROR, "decrypt failed");
  1969. SHOW_DECRYPDATA(TEST_DATA_WORD_LEN);
  1970. for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
  1971. test_assert(msg_decrypted[i] == msg_clear[i], "decrypt mismatch");
  1972. }
  1973. ]]></value>
  1974. </code>
  1975. </step>
  1976. </steps>
  1977. </case>
  1978. </cases>
  1979. </sequence>
  1980. <sequence>
  1981. <type index="0">
  1982. <value>Internal Tests</value>
  1983. </type>
  1984. <brief>
  1985. <value>TRNG</value>
  1986. </brief>
  1987. <description>
  1988. <value>TRNG testing</value>
  1989. </description>
  1990. <condition>
  1991. <value />
  1992. </condition>
  1993. <shared_code>
  1994. <value><![CDATA[
  1995. #include <string.h>
  1996. static const CRYConfig configTRNG_Polling=
  1997. {
  1998. TRANSFER_POLLING,
  1999. 0
  2000. };
  2001. ]]></value>
  2002. </shared_code>
  2003. <cases>
  2004. <case>
  2005. <brief>
  2006. <value>TRNG Polling</value>
  2007. </brief>
  2008. <description>
  2009. <value>testing TRNG in polled mode</value>
  2010. </description>
  2011. <condition>
  2012. <value />
  2013. </condition>
  2014. <various_code>
  2015. <setup_code>
  2016. <value><![CDATA[
  2017. cryStart(&CRYD1, &configTRNG_Polling);
  2018. ]]></value>
  2019. </setup_code>
  2020. <teardown_code>
  2021. <value><![CDATA[cryStop(&CRYD1);]]></value>
  2022. </teardown_code>
  2023. <local_variables>
  2024. <value><![CDATA[
  2025. cryerror_t ret;
  2026. ]]></value>
  2027. </local_variables>
  2028. </various_code>
  2029. <steps>
  2030. <step>
  2031. <description>
  2032. <value>Random generation and test</value>
  2033. </description>
  2034. <tags>
  2035. <value />
  2036. </tags>
  2037. <code>
  2038. <value><![CDATA[
  2039. uint32_t random[4];
  2040. int i;
  2041. ret = cryTRNG(&CRYD1,(uint8_t*)&random);
  2042. test_assert(ret == CRY_NOERROR , "failed random");
  2043. SHOW_DATA(&random[0],4);
  2044. for (i=0;i<4;i++) {
  2045. test_assert(random[i] != 0 , "failed random generation (zero)");
  2046. }
  2047. for (i=1;i<4;i++)
  2048. {
  2049. test_assert(random[i-1] != random[i] , "failed random generation");
  2050. }
  2051. ]]></value>
  2052. </code>
  2053. </step>
  2054. </steps>
  2055. </case>
  2056. </cases>
  2057. </sequence>
  2058. <sequence>
  2059. <type index="0">
  2060. <value>Internal Tests</value>
  2061. </type>
  2062. <brief>
  2063. <value>SHA</value>
  2064. </brief>
  2065. <description>
  2066. <value>SHA testing</value>
  2067. </description>
  2068. <condition>
  2069. <value />
  2070. </condition>
  2071. <shared_code>
  2072. <value><![CDATA[
  2073. #include <string.h>
  2074. #include "ref_sha.h"
  2075. /* Buffer size for each SHA transfer, size should be multiple of block size
  2076. (block size: 64 for SHA_1/SHA_256/SHA_224, 128 for SHA_384/SHA_512) */
  2077. #define MAX_SHA_BLOCK_SIZE TEST_MSG_DATA_BYTE_LEN
  2078. #define MAX_SHA_BLOCK_SIZE_INWORD (MAX_SHA_BLOCK_SIZE/4)
  2079. #define shabuffer msg_decrypted
  2080. #define MAX_DIGEST_SIZE_INBYTE TEST_MSG_DATA_BYTE_LEN
  2081. #define MAX_DIGEST_SIZE_INWORD (MAX_DIGEST_SIZE_INBYTE/4)
  2082. #define digest msg_encrypted
  2083. static const CRYConfig configSHA_Polling=
  2084. {
  2085. TRANSFER_POLLING,
  2086. 0
  2087. };
  2088. static cryerror_t crySHA1(CRYDriver *cryp, size_t size,const uint8_t *in, uint8_t *out) {
  2089. cryerror_t ret;
  2090. SHA1Context shactxp;
  2091. shactxp.sha.sha_buffer = (uint8_t*)&shabuffer[0];
  2092. shactxp.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE;
  2093. ret = crySHA1Init(cryp,&shactxp);
  2094. ret = crySHA1Update(cryp,&shactxp,size,in);
  2095. ret = crySHA1Final(cryp,&shactxp,out);
  2096. return ret;
  2097. }
  2098. static cryerror_t crySHA256(CRYDriver *cryp, size_t size,const uint8_t *in, uint8_t *out) {
  2099. cryerror_t ret;
  2100. SHA256Context shactxp;
  2101. shactxp.sha.sha_buffer = (uint8_t*)&shabuffer[0];
  2102. shactxp.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE;
  2103. ret = crySHA256Init(cryp,&shactxp);
  2104. ret = crySHA256Update(cryp,&shactxp,size,in);
  2105. ret = crySHA256Final(cryp,&shactxp,out);
  2106. return ret;
  2107. }
  2108. static cryerror_t crySHA512(CRYDriver *cryp, size_t size,const uint8_t *in, uint8_t *out) {
  2109. cryerror_t ret;
  2110. SHA512Context shactxp;
  2111. shactxp.sha.sha_buffer = (uint8_t*)&shabuffer[0];
  2112. shactxp.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE;
  2113. ret = crySHA512Init(cryp,&shactxp);
  2114. ret = crySHA512Update(cryp,&shactxp,size,in);
  2115. ret = crySHA512Final(cryp,&shactxp,out);
  2116. return ret;
  2117. }
  2118. ]]></value>
  2119. </shared_code>
  2120. <cases>
  2121. <case>
  2122. <brief>
  2123. <value>SHA1 Polling</value>
  2124. </brief>
  2125. <description>
  2126. <value>testing SHA1 in polled mode</value>
  2127. </description>
  2128. <condition>
  2129. <value />
  2130. </condition>
  2131. <various_code>
  2132. <setup_code>
  2133. <value><![CDATA[
  2134. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2135. memset(digest, 0, MAX_DIGEST_SIZE_INWORD);
  2136. memcpy((char*) msg_clear, sha_msg0, SHA_LEN_0);
  2137. cryStart(&CRYD1, &configSHA_Polling);
  2138. ]]></value>
  2139. </setup_code>
  2140. <teardown_code>
  2141. <value><![CDATA[cryStop(&CRYD1);]]></value>
  2142. </teardown_code>
  2143. <local_variables>
  2144. <value><![CDATA[
  2145. cryerror_t ret;
  2146. uint32_t *ref;
  2147. ]]></value>
  2148. </local_variables>
  2149. </various_code>
  2150. <steps>
  2151. <step>
  2152. <description>
  2153. <value>Digest</value>
  2154. </description>
  2155. <tags>
  2156. <value />
  2157. </tags>
  2158. <code>
  2159. <value><![CDATA[
  2160. //---- Empty Block Test
  2161. ret = crySHA1(&CRYD1,0,(uint8_t*)msg_clear,(uint8_t*)digest);
  2162. test_assert(ret == CRY_NOERROR, "sha1 failed");
  2163. SHOW_DATA(digest,5);
  2164. ref = (uint32_t*)refSHA_SHA1_EMPTY;
  2165. for (int i = 0; i < 5; i++) {
  2166. test_assert(digest[i] == ref[i], "sha1 digest mismatch");
  2167. }
  2168. //---- One Block Test
  2169. ret = crySHA1(&CRYD1,SHA_LEN_0,(uint8_t*)msg_clear,(uint8_t*)digest);
  2170. test_assert(ret == CRY_NOERROR, "sha1 failed");
  2171. SHOW_DATA(digest,5);
  2172. ref = (uint32_t*)refSHA_SHA1_3;
  2173. for (int i = 0; i < 5; i++) {
  2174. test_assert(digest[i] == ref[i], "sha1 digest mismatch");
  2175. }
  2176. //---- Multi Block Test 56 Byte
  2177. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2178. memcpy((char*) msg_clear, sha_msg1, SHA_LEN_1);
  2179. ret = crySHA1(&CRYD1,SHA_LEN_1,(uint8_t*)msg_clear,(uint8_t*)digest);
  2180. test_assert(ret == CRY_NOERROR, "sha1 failed");
  2181. SHOW_DATA(digest,5);
  2182. ref = (uint32_t*)refSHA_SHA1_56;
  2183. for (int i = 0; i < 5; i++) {
  2184. test_assert(digest[i] == ref[i], "sha1 digest mismatch");
  2185. }
  2186. //---- Multi Block Test 64 Byte
  2187. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2188. memcpy((char*) msg_clear, sha_msg2, SHA_LEN_2);
  2189. ret = crySHA1(&CRYD1,SHA_LEN_2,(uint8_t*)msg_clear,(uint8_t*)digest);
  2190. test_assert(ret == CRY_NOERROR, "sha1 failed");
  2191. SHOW_DATA(digest,5);
  2192. ref = (uint32_t*)refSHA_SHA1_64;
  2193. for (int i = 0; i < 5; i++) {
  2194. test_assert(digest[i] == ref[i], "sha1 digest mismatch");
  2195. }
  2196. //---- Multi Block Test 128 Byte
  2197. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2198. memcpy((char*) msg_clear, sha_msg3, SHA_LEN_3);
  2199. ret = crySHA1(&CRYD1,SHA_LEN_3,(uint8_t*)msg_clear,(uint8_t*)digest);
  2200. test_assert(ret == CRY_NOERROR, "sha1 failed");
  2201. SHOW_DATA(digest,5);
  2202. ref = (uint32_t*)refSHA_SHA1_128;
  2203. for (int i = 0; i < 5; i++) {
  2204. test_assert(digest[i] == ref[i], "sha1 digest mismatch");
  2205. }
  2206. ]]></value>
  2207. </code>
  2208. </step>
  2209. </steps>
  2210. </case>
  2211. <case>
  2212. <brief>
  2213. <value>SHA256 Polling</value>
  2214. </brief>
  2215. <description>
  2216. <value>testing SHA256 in polled mode</value>
  2217. </description>
  2218. <condition>
  2219. <value />
  2220. </condition>
  2221. <various_code>
  2222. <setup_code>
  2223. <value><![CDATA[
  2224. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2225. memset(digest, 0, MAX_DIGEST_SIZE_INWORD);
  2226. memcpy((char*) msg_clear, sha_msg0, SHA_LEN_0);
  2227. cryStart(&CRYD1, &configSHA_Polling);
  2228. ]]></value>
  2229. </setup_code>
  2230. <teardown_code>
  2231. <value><![CDATA[cryStop(&CRYD1);]]></value>
  2232. </teardown_code>
  2233. <local_variables>
  2234. <value><![CDATA[
  2235. cryerror_t ret;
  2236. uint32_t *ref;
  2237. ]]></value>
  2238. </local_variables>
  2239. </various_code>
  2240. <steps>
  2241. <step>
  2242. <description>
  2243. <value>Digest</value>
  2244. </description>
  2245. <tags>
  2246. <value />
  2247. </tags>
  2248. <code>
  2249. <value><![CDATA[
  2250. //---- One Block Test
  2251. ret = crySHA256(&CRYD1,SHA_LEN_0,(uint8_t*)msg_clear,(uint8_t*)digest);
  2252. test_assert(ret == CRY_NOERROR, "sha256 failed");
  2253. SHOW_DATA(digest,8);
  2254. ref = (uint32_t*)refSHA_SHA256_3;
  2255. for (int i = 0; i < 8; i++) {
  2256. test_assert(digest[i] == ref[i], "sha256 digest mismatch");
  2257. }
  2258. //---- Multi Block Test 56 Byte
  2259. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2260. memcpy((char*) msg_clear, sha_msg1, SHA_LEN_1);
  2261. ret = crySHA256(&CRYD1,SHA_LEN_1,(uint8_t*)msg_clear,(uint8_t*)digest);
  2262. test_assert(ret == CRY_NOERROR, "sha256 56 byte failed");
  2263. SHOW_DATA(digest,8);
  2264. ref = (uint32_t*)refSHA_SHA256_56;
  2265. for (int i = 0; i < 8; i++) {
  2266. test_assert(digest[i] == ref[i], "sha256 56 byte digest mismatch");
  2267. }
  2268. //---- Multi Block Test 64 Byte
  2269. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2270. memcpy((char*) msg_clear, sha_msg2, SHA_LEN_2);
  2271. ret = crySHA256(&CRYD1,SHA_LEN_2,(uint8_t*)msg_clear,(uint8_t*)digest);
  2272. test_assert(ret == CRY_NOERROR, "sha256 64 byte failed");
  2273. SHOW_DATA(digest,8);
  2274. ref = (uint32_t*)refSHA_SHA256_64;
  2275. for (int i = 0; i < 8; i++) {
  2276. test_assert(digest[i] == ref[i], "sha256 64 byte digest mismatch");
  2277. }
  2278. //---- Multi Block Test 128 Byte
  2279. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2280. memcpy((char*) msg_clear, sha_msg3, SHA_LEN_3);
  2281. ret = crySHA256(&CRYD1,SHA_LEN_3,(uint8_t*)msg_clear,(uint8_t*)digest);
  2282. test_assert(ret == CRY_NOERROR, "sha256 128 byte failed");
  2283. SHOW_DATA(digest,8);
  2284. ref = (uint32_t*)refSHA_SHA256_128;
  2285. for (int i = 0; i < 8; i++) {
  2286. test_assert(digest[i] == ref[i], "sha256 128 byte digest mismatch");
  2287. }
  2288. ]]></value>
  2289. </code>
  2290. </step>
  2291. </steps>
  2292. </case>
  2293. <case>
  2294. <brief>
  2295. <value>SHA512 Polling</value>
  2296. </brief>
  2297. <description>
  2298. <value>testing SHA512 in polled mode</value>
  2299. </description>
  2300. <condition>
  2301. <value />
  2302. </condition>
  2303. <various_code>
  2304. <setup_code>
  2305. <value><![CDATA[
  2306. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2307. memset(digest, 0, MAX_DIGEST_SIZE_INWORD);
  2308. memcpy((char*) msg_clear, sha_msg0, SHA_LEN_0);
  2309. cryStart(&CRYD1, &configSHA_Polling);
  2310. ]]></value>
  2311. </setup_code>
  2312. <teardown_code>
  2313. <value><![CDATA[cryStop(&CRYD1);]]></value>
  2314. </teardown_code>
  2315. <local_variables>
  2316. <value><![CDATA[
  2317. cryerror_t ret;
  2318. uint32_t *ref;
  2319. ]]></value>
  2320. </local_variables>
  2321. </various_code>
  2322. <steps>
  2323. <step>
  2324. <description>
  2325. <value>Digest</value>
  2326. </description>
  2327. <tags>
  2328. <value />
  2329. </tags>
  2330. <code>
  2331. <value><![CDATA[
  2332. //---- One Block Test
  2333. ret = crySHA512(&CRYD1,SHA_LEN_0,(uint8_t*)msg_clear,(uint8_t*)digest);
  2334. test_assert(ret == CRY_NOERROR, "sha512 failed");
  2335. SHOW_DATA(digest,16);
  2336. ref = (uint32_t*)refSHA_SHA512_3;
  2337. for (int i = 0; i < 16; i++) {
  2338. test_assert(digest[i] == ref[i], "sha512 digest mismatch");
  2339. }
  2340. //---- Multi Block Test 56 Byte
  2341. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2342. memcpy((char*) msg_clear, sha_msg1, SHA_LEN_1);
  2343. ret = crySHA512(&CRYD1,SHA_LEN_1,(uint8_t*)msg_clear,(uint8_t*)digest);
  2344. test_assert(ret == CRY_NOERROR, "sha512 56 byte failed");
  2345. SHOW_DATA(digest,16);
  2346. ref = (uint32_t*)refSHA_SHA512_56;
  2347. for (int i = 0; i < 16; i++) {
  2348. test_assert(digest[i] == ref[i], "sha512 56 byte digest mismatch");
  2349. }
  2350. //---- Multi Block Test 64 Byte
  2351. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2352. memcpy((char*) msg_clear, sha_msg2, SHA_LEN_2);
  2353. ret = crySHA512(&CRYD1,SHA_LEN_2,(uint8_t*)msg_clear,(uint8_t*)digest);
  2354. test_assert(ret == CRY_NOERROR, "sha512 64 byte failed");
  2355. SHOW_DATA(digest,16);
  2356. ref = (uint32_t*)refSHA_SHA512_64;
  2357. for (int i = 0; i < 16; i++) {
  2358. test_assert(digest[i] == ref[i], "sha512 64 byte digest mismatch");
  2359. }
  2360. //---- Multi Block Test 128 Byte
  2361. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2362. memcpy((char*) msg_clear, sha_msg3, SHA_LEN_3);
  2363. ret = crySHA512(&CRYD1,SHA_LEN_3,(uint8_t*)msg_clear,(uint8_t*)digest);
  2364. test_assert(ret == CRY_NOERROR, "sha512 128 byte failed");
  2365. SHOW_DATA(digest,16);
  2366. ref = (uint32_t*)refSHA_SHA512_128;
  2367. for (int i = 0; i < 16; i++) {
  2368. test_assert(digest[i] == ref[i], "sha512 128 byte digest mismatch");
  2369. }
  2370. ]]></value>
  2371. </code>
  2372. </step>
  2373. </steps>
  2374. </case>
  2375. </cases>
  2376. </sequence>
  2377. <sequence>
  2378. <type index="0">
  2379. <value>Internal Tests</value>
  2380. </type>
  2381. <brief>
  2382. <value>SHA</value>
  2383. </brief>
  2384. <description>
  2385. <value>SHA testing</value>
  2386. </description>
  2387. <condition>
  2388. <value />
  2389. </condition>
  2390. <shared_code>
  2391. <value><![CDATA[
  2392. #include <string.h>
  2393. #include "ref_sha.h"
  2394. /* Buffer size for each SHA transfer, size should be multiple of block size
  2395. (block size: 64 for SHA_1/SHA_256/SHA_224, 128 for SHA_384/SHA_512) */
  2396. #define MAX_SHA_BLOCK_SIZE TEST_MSG_DATA_BYTE_LEN
  2397. #define MAX_SHA_BLOCK_SIZE_INWORD (MAX_SHA_BLOCK_SIZE/4)
  2398. #define shabuffer msg_decrypted
  2399. #define MAX_DIGEST_SIZE_INBYTE TEST_MSG_DATA_BYTE_LEN
  2400. #define MAX_DIGEST_SIZE_INWORD (MAX_DIGEST_SIZE_INBYTE/4)
  2401. #define digest msg_encrypted
  2402. static const CRYConfig configSHA_DMA=
  2403. {
  2404. TRANSFER_DMA,
  2405. 0
  2406. };
  2407. static cryerror_t crySHA1(CRYDriver *cryp, size_t size,const uint8_t *in, uint8_t *out) {
  2408. cryerror_t ret;
  2409. SHA1Context shactxp;
  2410. shactxp.sha.sha_buffer = (uint8_t*)&shabuffer[0];
  2411. shactxp.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE;
  2412. ret = crySHA1Init(cryp,&shactxp);
  2413. ret = crySHA1Update(cryp,&shactxp,size,in);
  2414. ret = crySHA1Final(cryp,&shactxp,out);
  2415. return ret;
  2416. }
  2417. static cryerror_t crySHA256(CRYDriver *cryp, size_t size,const uint8_t *in, uint8_t *out) {
  2418. cryerror_t ret;
  2419. SHA256Context shactxp;
  2420. shactxp.sha.sha_buffer = (uint8_t*)&shabuffer[0];
  2421. shactxp.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE;
  2422. ret = crySHA256Init(cryp,&shactxp);
  2423. ret = crySHA256Update(cryp,&shactxp,size,in);
  2424. ret = crySHA256Final(cryp,&shactxp,out);
  2425. return ret;
  2426. }
  2427. static cryerror_t crySHA512(CRYDriver *cryp, size_t size,const uint8_t *in, uint8_t *out) {
  2428. cryerror_t ret;
  2429. SHA512Context shactxp;
  2430. shactxp.sha.sha_buffer = (uint8_t*)&shabuffer[0];
  2431. shactxp.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE;
  2432. ret = crySHA512Init(cryp,&shactxp);
  2433. ret = crySHA512Update(cryp,&shactxp,size,in);
  2434. ret = crySHA512Final(cryp,&shactxp,out);
  2435. return ret;
  2436. }
  2437. ]]></value>
  2438. </shared_code>
  2439. <cases>
  2440. <case>
  2441. <brief>
  2442. <value>SHA1 DMA</value>
  2443. </brief>
  2444. <description>
  2445. <value>testing SHA1 in DMA mode</value>
  2446. </description>
  2447. <condition>
  2448. <value />
  2449. </condition>
  2450. <various_code>
  2451. <setup_code>
  2452. <value><![CDATA[
  2453. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2454. memset(digest, 0, MAX_DIGEST_SIZE_INWORD);
  2455. memcpy((char*) msg_clear, sha_msg0, SHA_LEN_0);
  2456. cryStart(&CRYD1, &configSHA_DMA);
  2457. ]]></value>
  2458. </setup_code>
  2459. <teardown_code>
  2460. <value><![CDATA[cryStop(&CRYD1);]]></value>
  2461. </teardown_code>
  2462. <local_variables>
  2463. <value><![CDATA[
  2464. cryerror_t ret;
  2465. uint32_t *ref;
  2466. ]]></value>
  2467. </local_variables>
  2468. </various_code>
  2469. <steps>
  2470. <step>
  2471. <description>
  2472. <value>Digest</value>
  2473. </description>
  2474. <tags>
  2475. <value />
  2476. </tags>
  2477. <code>
  2478. <value><![CDATA[
  2479. //---- Empty Block Test
  2480. ret = crySHA1(&CRYD1,0,(uint8_t*)msg_clear,(uint8_t*)digest);
  2481. test_assert(ret == CRY_NOERROR, "sha1 failed");
  2482. SHOW_DATA(digest,5);
  2483. ref = (uint32_t*)refSHA_SHA1_EMPTY;
  2484. for (int i = 0; i < 5; i++) {
  2485. test_assert(digest[i] == ref[i], "sha1 digest mismatch");
  2486. }
  2487. //---- One Block Test
  2488. ret = crySHA1(&CRYD1,SHA_LEN_0,(uint8_t*)msg_clear,(uint8_t*)digest);
  2489. test_assert(ret == CRY_NOERROR, "sha1 failed");
  2490. SHOW_DATA(digest,5);
  2491. ref = (uint32_t*)refSHA_SHA1_3;
  2492. for (int i = 0; i < 5; i++) {
  2493. test_assert(digest[i] == ref[i], "sha1 digest mismatch");
  2494. }
  2495. //---- Multi Block Test 56 Byte
  2496. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2497. memcpy((char*) msg_clear, sha_msg1, SHA_LEN_1);
  2498. ret = crySHA1(&CRYD1,SHA_LEN_1,(uint8_t*)msg_clear,(uint8_t*)digest);
  2499. test_assert(ret == CRY_NOERROR, "sha1 failed");
  2500. SHOW_DATA(digest,5);
  2501. ref = (uint32_t*)refSHA_SHA1_56;
  2502. for (int i = 0; i < 5; i++) {
  2503. test_assert(digest[i] == ref[i], "sha1 digest mismatch");
  2504. }
  2505. //---- Multi Block Test 64 Byte
  2506. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2507. memcpy((char*) msg_clear, sha_msg2, SHA_LEN_2);
  2508. ret = crySHA1(&CRYD1,SHA_LEN_2,(uint8_t*)msg_clear,(uint8_t*)digest);
  2509. test_assert(ret == CRY_NOERROR, "sha1 failed");
  2510. SHOW_DATA(digest,5);
  2511. ref = (uint32_t*)refSHA_SHA1_64;
  2512. for (int i = 0; i < 5; i++) {
  2513. test_assert(digest[i] == ref[i], "sha1 digest mismatch");
  2514. }
  2515. //---- Multi Block Test 128 Byte
  2516. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2517. memcpy((char*) msg_clear, sha_msg3, SHA_LEN_3);
  2518. ret = crySHA1(&CRYD1,SHA_LEN_3,(uint8_t*)msg_clear,(uint8_t*)digest);
  2519. test_assert(ret == CRY_NOERROR, "sha1 failed");
  2520. SHOW_DATA(digest,5);
  2521. ref = (uint32_t*)refSHA_SHA1_128;
  2522. for (int i = 0; i < 5; i++) {
  2523. test_assert(digest[i] == ref[i], "sha1 digest mismatch");
  2524. }
  2525. ]]></value>
  2526. </code>
  2527. </step>
  2528. </steps>
  2529. </case>
  2530. <case>
  2531. <brief>
  2532. <value>SHA256 DMA</value>
  2533. </brief>
  2534. <description>
  2535. <value>testing SHA256 in DMA mode</value>
  2536. </description>
  2537. <condition>
  2538. <value />
  2539. </condition>
  2540. <various_code>
  2541. <setup_code>
  2542. <value><![CDATA[
  2543. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2544. memset(digest, 0, MAX_DIGEST_SIZE_INWORD);
  2545. memcpy((char*) msg_clear, sha_msg0, SHA_LEN_0);
  2546. cryStart(&CRYD1, &configSHA_DMA);
  2547. ]]></value>
  2548. </setup_code>
  2549. <teardown_code>
  2550. <value><![CDATA[cryStop(&CRYD1);]]></value>
  2551. </teardown_code>
  2552. <local_variables>
  2553. <value><![CDATA[
  2554. cryerror_t ret;
  2555. uint32_t *ref;
  2556. ]]></value>
  2557. </local_variables>
  2558. </various_code>
  2559. <steps>
  2560. <step>
  2561. <description>
  2562. <value>Digest</value>
  2563. </description>
  2564. <tags>
  2565. <value />
  2566. </tags>
  2567. <code>
  2568. <value><![CDATA[
  2569. //---- One Block Test
  2570. ret = crySHA256(&CRYD1,SHA_LEN_0,(uint8_t*)msg_clear,(uint8_t*)digest);
  2571. test_assert(ret == CRY_NOERROR, "sha256 failed");
  2572. SHOW_DATA(digest,8);
  2573. ref = (uint32_t*)refSHA_SHA256_3;
  2574. for (int i = 0; i < 8; i++) {
  2575. test_assert(digest[i] == ref[i], "sha256 digest mismatch");
  2576. }
  2577. //---- Multi Block Test 56 Byte
  2578. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2579. memcpy((char*) msg_clear, sha_msg1, SHA_LEN_1);
  2580. ret = crySHA256(&CRYD1,SHA_LEN_1,(uint8_t*)msg_clear,(uint8_t*)digest);
  2581. test_assert(ret == CRY_NOERROR, "sha256 56 byte failed");
  2582. SHOW_DATA(digest,8);
  2583. ref = (uint32_t*)refSHA_SHA256_56;
  2584. for (int i = 0; i < 8; i++) {
  2585. test_assert(digest[i] == ref[i], "sha256 56 byte digest mismatch");
  2586. }
  2587. //---- Multi Block Test 64 Byte
  2588. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2589. memcpy((char*) msg_clear, sha_msg2, SHA_LEN_2);
  2590. ret = crySHA256(&CRYD1,SHA_LEN_2,(uint8_t*)msg_clear,(uint8_t*)digest);
  2591. test_assert(ret == CRY_NOERROR, "sha256 64 byte failed");
  2592. SHOW_DATA(digest,8);
  2593. ref = (uint32_t*)refSHA_SHA256_64;
  2594. for (int i = 0; i < 8; i++) {
  2595. test_assert(digest[i] == ref[i], "sha256 64 byte digest mismatch");
  2596. }
  2597. //---- Multi Block Test 128 Byte
  2598. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2599. memcpy((char*) msg_clear, sha_msg3, SHA_LEN_3);
  2600. ret = crySHA256(&CRYD1,SHA_LEN_3,(uint8_t*)msg_clear,(uint8_t*)digest);
  2601. test_assert(ret == CRY_NOERROR, "sha256 128 byte failed");
  2602. SHOW_DATA(digest,8);
  2603. ref = (uint32_t*)refSHA_SHA256_128;
  2604. for (int i = 0; i < 8; i++) {
  2605. test_assert(digest[i] == ref[i], "sha256 128 byte digest mismatch");
  2606. }
  2607. ]]></value>
  2608. </code>
  2609. </step>
  2610. </steps>
  2611. </case>
  2612. <case>
  2613. <brief>
  2614. <value>SHA512 DMA</value>
  2615. </brief>
  2616. <description>
  2617. <value>testing SHA512 in DMA mode</value>
  2618. </description>
  2619. <condition>
  2620. <value />
  2621. </condition>
  2622. <various_code>
  2623. <setup_code>
  2624. <value><![CDATA[
  2625. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2626. memset(digest, 0, MAX_DIGEST_SIZE_INWORD);
  2627. memcpy((char*) msg_clear, sha_msg0, SHA_LEN_0);
  2628. cryStart(&CRYD1, &configSHA_DMA);
  2629. ]]></value>
  2630. </setup_code>
  2631. <teardown_code>
  2632. <value><![CDATA[cryStop(&CRYD1);]]></value>
  2633. </teardown_code>
  2634. <local_variables>
  2635. <value><![CDATA[
  2636. cryerror_t ret;
  2637. uint32_t *ref;
  2638. ]]></value>
  2639. </local_variables>
  2640. </various_code>
  2641. <steps>
  2642. <step>
  2643. <description>
  2644. <value>Digest</value>
  2645. </description>
  2646. <tags>
  2647. <value />
  2648. </tags>
  2649. <code>
  2650. <value><![CDATA[
  2651. //---- One Block Test
  2652. ret = crySHA512(&CRYD1,SHA_LEN_0,(uint8_t*)msg_clear,(uint8_t*)digest);
  2653. test_assert(ret == CRY_NOERROR, "sha512 failed");
  2654. SHOW_DATA(digest,16);
  2655. ref = (uint32_t*)refSHA_SHA512_3;
  2656. for (int i = 0; i < 16; i++) {
  2657. test_assert(digest[i] == ref[i], "sha512 digest mismatch");
  2658. }
  2659. //---- Multi Block Test 56 Byte
  2660. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2661. memcpy((char*) msg_clear, sha_msg1, SHA_LEN_1);
  2662. ret = crySHA512(&CRYD1,SHA_LEN_1,(uint8_t*)msg_clear,(uint8_t*)digest);
  2663. test_assert(ret == CRY_NOERROR, "sha512 56 byte failed");
  2664. SHOW_DATA(digest,16);
  2665. ref = (uint32_t*)refSHA_SHA512_56;
  2666. for (int i = 0; i < 16; i++) {
  2667. test_assert(digest[i] == ref[i], "sha512 56 byte digest mismatch");
  2668. }
  2669. //---- Multi Block Test 64 Byte
  2670. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2671. memcpy((char*) msg_clear, sha_msg2, SHA_LEN_2);
  2672. ret = crySHA512(&CRYD1,SHA_LEN_2,(uint8_t*)msg_clear,(uint8_t*)digest);
  2673. test_assert(ret == CRY_NOERROR, "sha512 64 byte failed");
  2674. SHOW_DATA(digest,16);
  2675. ref = (uint32_t*)refSHA_SHA512_64;
  2676. for (int i = 0; i < 16; i++) {
  2677. test_assert(digest[i] == ref[i], "sha512 64 byte digest mismatch");
  2678. }
  2679. //---- Multi Block Test 128 Byte
  2680. memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
  2681. memcpy((char*) msg_clear, sha_msg3, SHA_LEN_3);
  2682. ret = crySHA512(&CRYD1,SHA_LEN_3,(uint8_t*)msg_clear,(uint8_t*)digest);
  2683. test_assert(ret == CRY_NOERROR, "sha512 128 byte failed");
  2684. SHOW_DATA(digest,16);
  2685. ref = (uint32_t*)refSHA_SHA512_128;
  2686. for (int i = 0; i < 16; i++) {
  2687. test_assert(digest[i] == ref[i], "sha512 128 byte digest mismatch");
  2688. }
  2689. ]]></value>
  2690. </code>
  2691. </step>
  2692. </steps>
  2693. </case>
  2694. </cases>
  2695. </sequence>
  2696. <sequence>
  2697. <type index="0">
  2698. <value>Internal Tests</value>
  2699. </type>
  2700. <brief>
  2701. <value>GCM</value>
  2702. </brief>
  2703. <description>
  2704. <value>GCM testing</value>
  2705. </description>
  2706. <condition>
  2707. <value />
  2708. </condition>
  2709. <shared_code>
  2710. <value><![CDATA[
  2711. #include <string.h>
  2712. #include "ref_gcm.h"
  2713. #define plaintext msg_clear
  2714. #define cypher msg_encrypted
  2715. #define authtag msg_decrypted
  2716. static const CRYConfig config_Polling=
  2717. {
  2718. TRANSFER_POLLING,
  2719. 0
  2720. };
  2721. static const CRYConfig config_DMA=
  2722. {
  2723. TRANSFER_DMA,
  2724. 0
  2725. };
  2726. struct test_el_t
  2727. {
  2728. uint32_t size;
  2729. const uint8_t * data;
  2730. };
  2731. struct test_gcm_t
  2732. {
  2733. struct test_el_t key;
  2734. struct test_el_t p;
  2735. struct test_el_t iv;
  2736. struct test_el_t aad;
  2737. struct test_el_t c;
  2738. struct test_el_t t;
  2739. };
  2740. #define TEST_GCM_LEN 3
  2741. const struct test_gcm_t test_gcm_k[TEST_GCM_LEN]={
  2742. { {K3_LEN,K3},{P3_LEN,P3},{IV3_LEN,IV3},{AAD3_LEN,A3},{C3_LEN,C3},{T3_LEN,T3} },
  2743. { {K4_LEN,K4},{P4_LEN,P4},{IV4_LEN,IV4},{AAD4_LEN,A4},{C4_LEN,C4},{T4_LEN,T4} },
  2744. { {K5_LEN,K5},{P5_LEN,P5},{IV5_LEN,IV5},{AAD5_LEN,A5},{C5_LEN,C5},{T5_LEN,T5} }
  2745. };
  2746. ]]></value>
  2747. </shared_code>
  2748. <cases>
  2749. <case>
  2750. <brief>
  2751. <value>GCM Polling</value>
  2752. </brief>
  2753. <description>
  2754. <value>testing GCM in polled mode</value>
  2755. </description>
  2756. <condition>
  2757. <value />
  2758. </condition>
  2759. <various_code>
  2760. <setup_code>
  2761. <value><![CDATA[
  2762. memset(cypher, 0xff, TEST_MSG_DATA_BYTE_LEN);
  2763. memset(authtag, 0xff, TEST_MSG_DATA_BYTE_LEN);
  2764. cryStart(&CRYD1, &config_Polling);
  2765. ]]></value>
  2766. </setup_code>
  2767. <teardown_code>
  2768. <value><![CDATA[cryStop(&CRYD1);]]></value>
  2769. </teardown_code>
  2770. <local_variables>
  2771. <value><![CDATA[
  2772. cryerror_t ret;
  2773. uint32_t *ref;
  2774. uint8_t i,len1,len2;
  2775. ]]></value>
  2776. </local_variables>
  2777. </various_code>
  2778. <steps>
  2779. <step>
  2780. <description>
  2781. <value>loading the key, encrypt and decrypt</value>
  2782. </description>
  2783. <tags>
  2784. <value />
  2785. </tags>
  2786. <code>
  2787. <value><![CDATA[
  2788. for (i = 0;i<TEST_GCM_LEN;i++) {
  2789. test_print("gcm test : ");
  2790. test_printn(i);
  2791. test_println("");
  2792. /* loading the key .*/
  2793. {
  2794. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,test_gcm_k[i].key.size, (uint8_t *) test_gcm_k[i].key.data);
  2795. test_assert(ret == CRY_NOERROR, "failed load transient key");
  2796. }
  2797. /* Encrypt.*/
  2798. {
  2799. ret = cryEncryptAES_GCM(&CRYD1,
  2800. 0,
  2801. test_gcm_k[i].p.size,
  2802. test_gcm_k[i].p.data,
  2803. (uint8_t*)cypher,
  2804. test_gcm_k[i].iv.data,
  2805. test_gcm_k[i].aad.size,
  2806. test_gcm_k[i].aad.data,
  2807. (uint8_t*)authtag);
  2808. test_assert(ret == CRY_NOERROR, "failed encryption");
  2809. len1 = test_gcm_k[i].c.size/4;
  2810. len2 = test_gcm_k[i].t.size/4;
  2811. SHOW_DATA(cypher,len1);
  2812. SHOW_DATA(authtag,len2);
  2813. ref = (uint32_t*)test_gcm_k[i].c.data;
  2814. for (uint8_t i = 0; i < len1; i++) {
  2815. test_assert(ref[i] == cypher[i], "c mismatch");
  2816. }
  2817. ref = (uint32_t*)test_gcm_k[i].t.data;
  2818. for (uint8_t i = 0; i < len2; i++) {
  2819. test_assert(ref[i] == authtag[i], "t mismatch");
  2820. }
  2821. }
  2822. /* Decrypt.*/
  2823. {
  2824. memset(plaintext, 0, test_gcm_k[i].p.size);
  2825. ret = cryDecryptAES_GCM(&CRYD1,
  2826. 0,
  2827. test_gcm_k[i].c.size,
  2828. (uint8_t*)cypher,
  2829. (uint8_t*)plaintext,
  2830. test_gcm_k[i].iv.data,
  2831. test_gcm_k[i].aad.size,
  2832. test_gcm_k[i].aad.data,
  2833. (uint8_t*)authtag);
  2834. test_assert(ret == CRY_NOERROR, "failed decryption");
  2835. len1 = test_gcm_k[i].p.size/4;
  2836. SHOW_DATA(plaintext,len1);
  2837. ref = (uint32_t*)test_gcm_k[i].p.data;
  2838. for (uint8_t i = 0; i < len1; i++) {
  2839. test_assert(ref[i] == plaintext[i], "decrypt plain mismatch");
  2840. }
  2841. }
  2842. }
  2843. ]]></value>
  2844. </code>
  2845. </step>
  2846. </steps>
  2847. </case>
  2848. <case>
  2849. <brief>
  2850. <value>GCM DMA</value>
  2851. </brief>
  2852. <description>
  2853. <value>testing GCM in DMA mode</value>
  2854. </description>
  2855. <condition>
  2856. <value />
  2857. </condition>
  2858. <various_code>
  2859. <setup_code>
  2860. <value><![CDATA[
  2861. memset(cypher, 0xff, TEST_MSG_DATA_BYTE_LEN);
  2862. memset(authtag, 0xff, TEST_MSG_DATA_BYTE_LEN);
  2863. cryStart(&CRYD1, &config_DMA);
  2864. ]]></value>
  2865. </setup_code>
  2866. <teardown_code>
  2867. <value><![CDATA[cryStop(&CRYD1);]]></value>
  2868. </teardown_code>
  2869. <local_variables>
  2870. <value><![CDATA[
  2871. cryerror_t ret;
  2872. uint32_t *ref;
  2873. uint8_t i,len1,len2;
  2874. ]]></value>
  2875. </local_variables>
  2876. </various_code>
  2877. <steps>
  2878. <step>
  2879. <description>
  2880. <value>loading the key, encrypt and decrypt</value>
  2881. </description>
  2882. <tags>
  2883. <value />
  2884. </tags>
  2885. <code>
  2886. <value><![CDATA[
  2887. for (i = 0;i<TEST_GCM_LEN;i++) {
  2888. test_print("gcm test : ");
  2889. test_printn(i);
  2890. test_println("");
  2891. /* loading the key .*/
  2892. {
  2893. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,test_gcm_k[i].key.size, (uint8_t *) test_gcm_k[i].key.data);
  2894. test_assert(ret == CRY_NOERROR, "failed load transient key");
  2895. }
  2896. /* Encrypt.*/
  2897. {
  2898. ret = cryEncryptAES_GCM(&CRYD1,
  2899. 0,
  2900. test_gcm_k[i].p.size,
  2901. test_gcm_k[i].p.data,
  2902. (uint8_t*)cypher,
  2903. test_gcm_k[i].iv.data,
  2904. test_gcm_k[i].aad.size,
  2905. test_gcm_k[i].aad.data,
  2906. (uint8_t*)authtag);
  2907. test_assert(ret == CRY_NOERROR, "failed encryption");
  2908. len1 = test_gcm_k[i].c.size/4;
  2909. len2 = test_gcm_k[i].t.size/4;
  2910. SHOW_DATA(cypher,len1);
  2911. SHOW_DATA(authtag,len2);
  2912. ref = (uint32_t*)test_gcm_k[i].c.data;
  2913. for (uint8_t i = 0; i < len1; i++) {
  2914. test_assert(ref[i] == cypher[i], "c mismatch");
  2915. }
  2916. ref = (uint32_t*)test_gcm_k[i].t.data;
  2917. for (uint8_t i = 0; i < len2; i++) {
  2918. test_assert(ref[i] == authtag[i], "t mismatch");
  2919. }
  2920. }
  2921. /* Decrypt.*/
  2922. {
  2923. memset(plaintext, 0, test_gcm_k[i].p.size);
  2924. ret = cryDecryptAES_GCM(&CRYD1,
  2925. 0,
  2926. test_gcm_k[i].c.size,
  2927. (uint8_t*)cypher,
  2928. (uint8_t*)plaintext,
  2929. test_gcm_k[i].iv.data,
  2930. test_gcm_k[i].aad.size,
  2931. test_gcm_k[i].aad.data,
  2932. (uint8_t*)authtag);
  2933. test_assert(ret == CRY_NOERROR, "failed decryption");
  2934. len1 = test_gcm_k[i].p.size/4;
  2935. SHOW_DATA(plaintext,len1);
  2936. ref = (uint32_t*)test_gcm_k[i].p.data;
  2937. for (uint8_t i = 0; i < len1; i++) {
  2938. test_assert(ref[i] == plaintext[i], "decrypt plain mismatch");
  2939. }
  2940. }
  2941. }
  2942. ]]></value>
  2943. </code>
  2944. </step>
  2945. </steps>
  2946. </case>
  2947. </cases>
  2948. </sequence>
  2949. <sequence>
  2950. <type index="0">
  2951. <value>Internal Tests</value>
  2952. </type>
  2953. <brief>
  2954. <value>HMAC</value>
  2955. </brief>
  2956. <description>
  2957. <value>HMAC testing</value>
  2958. </description>
  2959. <condition>
  2960. <value />
  2961. </condition>
  2962. <shared_code>
  2963. <value><![CDATA[
  2964. #include <string.h>
  2965. #include "ref_hmac.h"
  2966. #define plaintext msg_clear
  2967. #define HMACOUT msg_encrypted
  2968. #define shabuffer msg_decrypted
  2969. #define MAX_SHA_BLOCK_SIZE TEST_MSG_DATA_BYTE_LEN
  2970. #define MAX_SHA_BLOCK_SIZE_INWORD (MAX_SHA_BLOCK_SIZE/4)
  2971. static const CRYConfig config_Polling=
  2972. {
  2973. TRANSFER_POLLING,
  2974. 0
  2975. };
  2976. static const CRYConfig config_DMA=
  2977. {
  2978. TRANSFER_DMA,
  2979. 0
  2980. };
  2981. static const int hmackeys_size[]=
  2982. {
  2983. 20,
  2984. 4,
  2985. 20
  2986. };
  2987. static const uint8_t hmackey_1[]=
  2988. {
  2989. 0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,
  2990. 0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,
  2991. };
  2992. // "Hi There",
  2993. static const uint8_t hmacmsg1[8]= "Hi There";
  2994. static const size_t hmacmsg_size[]=
  2995. {
  2996. 8,
  2997. };
  2998. static void cryHMAC256(CRYDriver *cryp) {
  2999. cryerror_t ret;
  3000. HMACSHA256Context hmacshactxp;
  3001. uint8_t *keyp;
  3002. hmacshactxp.shacontext.sha.sha_buffer = (uint8_t*)&shabuffer[0];
  3003. hmacshactxp.shacontext.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE;
  3004. keyp =(uint8_t *)hmackey_1;
  3005. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_hmac,hmackeys_size[0], keyp);
  3006. test_assert(ret == CRY_NOERROR, "failed load transient key");
  3007. ret = cryHMACSHA256Init(cryp,&hmacshactxp);
  3008. test_assert(ret == CRY_NOERROR, "failed init HMACSHA256");
  3009. ret = cryHMACSHA256Update(cryp,&hmacshactxp,hmacmsg_size[0],(const uint8_t *)&hmacmsg1);
  3010. test_assert(ret == CRY_NOERROR, "failed update HMACSHA256");
  3011. ret = cryHMACSHA256Final(cryp,&hmacshactxp,(uint8_t *)HMACOUT);
  3012. test_assert(ret == CRY_NOERROR, "failed final HMACSHA256");
  3013. SHOW_DATA(HMACOUT,8);
  3014. }
  3015. static void cryHMAC512(CRYDriver *cryp) {
  3016. cryerror_t ret;
  3017. HMACSHA512Context hmacshactxp;
  3018. uint8_t *keyp;
  3019. hmacshactxp.shacontext.sha.sha_buffer = (uint8_t*)&shabuffer[0];
  3020. hmacshactxp.shacontext.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE;
  3021. keyp =(uint8_t *)hmackey_1;
  3022. ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_hmac,hmackeys_size[0], keyp);
  3023. test_assert(ret == CRY_NOERROR, "failed load transient key");
  3024. ret = cryHMACSHA512Init(cryp,&hmacshactxp);
  3025. test_assert(ret == CRY_NOERROR, "failed init HMACSHA512");
  3026. ret = cryHMACSHA512Update(cryp,&hmacshactxp,hmacmsg_size[0],(const uint8_t *)&hmacmsg1);
  3027. test_assert(ret == CRY_NOERROR, "failed update HMACSHA512");
  3028. ret = cryHMACSHA512Final(cryp,&hmacshactxp,(uint8_t *)HMACOUT);
  3029. test_assert(ret == CRY_NOERROR, "failed final HMACSHA512");
  3030. SHOW_DATA(HMACOUT,16);
  3031. }
  3032. ]]></value>
  3033. </shared_code>
  3034. <cases>
  3035. <case>
  3036. <brief>
  3037. <value>HMAC Polling</value>
  3038. </brief>
  3039. <description>
  3040. <value>testing HMAC in polled mode</value>
  3041. </description>
  3042. <condition>
  3043. <value />
  3044. </condition>
  3045. <various_code>
  3046. <setup_code>
  3047. <value><![CDATA[
  3048. memset(HMACOUT, 0xff, TEST_MSG_DATA_BYTE_LEN);
  3049. cryStart(&CRYD1, &config_Polling);
  3050. ]]></value>
  3051. </setup_code>
  3052. <teardown_code>
  3053. <value><![CDATA[cryStop(&CRYD1);]]></value>
  3054. </teardown_code>
  3055. <local_variables>
  3056. <value><![CDATA[
  3057. ]]></value>
  3058. </local_variables>
  3059. </various_code>
  3060. <steps>
  3061. <step>
  3062. <description>
  3063. <value>hmac 256</value>
  3064. </description>
  3065. <tags>
  3066. <value />
  3067. </tags>
  3068. <code>
  3069. <value><![CDATA[
  3070. cryHMAC256(&CRYD1);
  3071. for (int i = 0; i < 8; i++) {
  3072. test_assert(HMACOUT[i] == ((uint32_t*) refHMAC_HMAC256_1)[i], "hmac mismatch");
  3073. }
  3074. ]]></value>
  3075. </code>
  3076. </step>
  3077. <step>
  3078. <description>
  3079. <value>hmac 512</value>
  3080. </description>
  3081. <tags>
  3082. <value />
  3083. </tags>
  3084. <code>
  3085. <value><![CDATA[
  3086. cryHMAC512(&CRYD1);
  3087. for (int i = 0; i < 16; i++) {
  3088. test_assert(HMACOUT[i] == ((uint32_t*) refHMAC_HMAC512_1)[i], "hmac mismatch");
  3089. }
  3090. ]]></value>
  3091. </code>
  3092. </step>
  3093. </steps>
  3094. </case>
  3095. <case>
  3096. <brief>
  3097. <value>HMAC DMA</value>
  3098. </brief>
  3099. <description>
  3100. <value>testing HMAC in DMA mode</value>
  3101. </description>
  3102. <condition>
  3103. <value />
  3104. </condition>
  3105. <various_code>
  3106. <setup_code>
  3107. <value><![CDATA[
  3108. memset(HMACOUT, 0xff, TEST_MSG_DATA_BYTE_LEN);
  3109. cryStart(&CRYD1, &config_DMA);
  3110. ]]></value>
  3111. </setup_code>
  3112. <teardown_code>
  3113. <value><![CDATA[cryStop(&CRYD1);]]></value>
  3114. </teardown_code>
  3115. <local_variables>
  3116. <value><![CDATA[
  3117. ]]></value>
  3118. </local_variables>
  3119. </various_code>
  3120. <steps>
  3121. <step>
  3122. <description>
  3123. <value>hmac 256</value>
  3124. </description>
  3125. <tags>
  3126. <value />
  3127. </tags>
  3128. <code>
  3129. <value><![CDATA[
  3130. cryHMAC256(&CRYD1);
  3131. for (int i = 0; i < 8; i++) {
  3132. test_assert(HMACOUT[i] == ((uint32_t*) refHMAC_HMAC256_1)[i], "hmac mismatch");
  3133. }
  3134. ]]></value>
  3135. </code>
  3136. </step>
  3137. <step>
  3138. <description>
  3139. <value>hmac 512</value>
  3140. </description>
  3141. <tags>
  3142. <value />
  3143. </tags>
  3144. <code>
  3145. <value><![CDATA[
  3146. cryHMAC512(&CRYD1);
  3147. for (int i = 0; i < 16; i++) {
  3148. test_assert(HMACOUT[i] == ((uint32_t*) refHMAC_HMAC512_1)[i], "hmac mismatch");
  3149. }
  3150. ]]></value>
  3151. </code>
  3152. </step>
  3153. </steps>
  3154. </case>
  3155. </cases>
  3156. </sequence>
  3157. </sequences>
  3158. </instance>
  3159. </instances>
  3160. <exportedFeatures />
  3161. </application>
  3162. </SPC5-Config>