fsl_caam.h 129 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043
  1. /*
  2. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2021 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_CAAM_H_
  9. #define _FSL_CAAM_H_
  10. #include "fsl_common.h"
  11. /*!
  12. * @addtogroup caam_driver
  13. * @{
  14. */
  15. /*! @brief CAAM status return codes. */
  16. enum
  17. {
  18. kStatus_CAAM_Again = MAKE_STATUS(kStatusGroup_CAAM, 0), /*!< Non-blocking function shall be called again. */
  19. kStatus_CAAM_DataOverflow = MAKE_STATUS(kStatusGroup_CAAM, 1), /*!< Input data too big. */
  20. };
  21. /*******************************************************************************
  22. * Definitions
  23. *******************************************************************************/
  24. /*! @name Driver version */
  25. /*@{*/
  26. /*! @brief CAAM driver version. Version 2.1.5.
  27. *
  28. * Current version: 2.1.4
  29. *
  30. * Change log:
  31. * - Version 2.0.0
  32. * - Initial version
  33. * - Version 2.0.1
  34. * - Add Job Ring 2 and 3.
  35. * - Version 2.0.2
  36. * - Add Data and Instruction Synchronization Barrier in caam_input_ring_set_jobs_added()
  37. * to make sure that the descriptor will be loaded into CAAM correctly.
  38. * - Version 2.0.3
  39. * - Use MACRO instead of numbers in descriptor.
  40. * - Correct descriptor size mask.
  41. * - Version 2.1.0
  42. * - Add return codes check and handling.
  43. * - Version 2.1.1
  44. * - Add DCACHE support.
  45. * - Version 2.1.2
  46. * - Add data offset feature to provide support for mirrored (high-speed) memory.
  47. * - Version 2.1.3
  48. * - Fix MISRA-2012 issues.
  49. * - Version 2.1.4
  50. * - Fix MISRA-2012 issues.
  51. * - Version 2.1.5
  52. * - Support EXTENDED data size for all AES, HASH and RNG operations.
  53. * - Support multiple De-Initialization/Initialization of CAAM driver within one POR event.
  54. */
  55. #define FSL_CAAM_DRIVER_VERSION (MAKE_VERSION(2, 1, 5))
  56. /*@}*/
  57. /*! @brief CAAM callback function. */
  58. typedef struct _caam_job_callback
  59. {
  60. void (*JobCompleted)(void *userData); /*!< CAAM Job complete callback */
  61. } caam_job_callback_t;
  62. /*! @brief CAAM job ring selection. */
  63. typedef enum _caam_job_ring_t
  64. {
  65. kCAAM_JobRing0 = 0u, /*!< CAAM Job ring 0 */
  66. kCAAM_JobRing1 = 1u, /*!< CAAM Job ring 1 */
  67. kCAAM_JobRing2 = 2u, /*!< CAAM Job ring 2 */
  68. kCAAM_JobRing3 = 3u, /*!< CAAM Job ring 3 */
  69. } caam_job_ring_t;
  70. /*! @brief CAAM handle
  71. * Specifies jobRing and optionally the user callback function.
  72. * The user callback functions is invoked only if jobRing interrupt has been enabled by the user.
  73. * By default the jobRing interrupt is disabled (default job complete test is polling CAAM output ring).
  74. */
  75. typedef struct _caam_handle_t
  76. {
  77. caam_job_ring_t jobRing;
  78. /* Callback functions */
  79. caam_job_callback_t callback; /*!< Callback function */
  80. void *userData; /*!< Parameter for CAAM job complete callback */
  81. } caam_handle_t;
  82. /*! @brief CAAM driver wait mechanism
  83. */
  84. typedef enum _caam_wait_mode
  85. {
  86. kCAAM_Blocking = 0u, /*!< CAAM_Wait blocking mode */
  87. kCAAM_Nonblocking = 1u, /*!< CAAM Wait non-blocking mode */
  88. } caam_wait_mode_t;
  89. /*! @brief Memory buffer to hold CAAM descriptor for AESA ECB job */
  90. typedef uint32_t caam_desc_aes_ecb_t[64];
  91. /*! @brief Memory buffer to hold CAAM descriptor for AESA CBC job */
  92. typedef uint32_t caam_desc_aes_cbc_t[64];
  93. /*! @brief Memory buffer to hold CAAM descriptor for AESA CTR job */
  94. typedef uint32_t caam_desc_aes_ctr_t[64];
  95. /*! @brief Memory buffer to hold CAAM descriptor for AESA CCM job */
  96. typedef uint32_t caam_desc_aes_ccm_t[64];
  97. /*! @brief Memory buffer to hold CAAM descriptor for AESA GCM job */
  98. typedef uint32_t caam_desc_aes_gcm_t[64];
  99. /*! @brief Memory buffer to hold CAAM descriptor for MDHA job or AESA CMAC job */
  100. typedef uint32_t caam_desc_hash_t[64];
  101. /*! @brief Memory buffer to hold CAAM descriptor for RNG jobs */
  102. typedef uint32_t caam_desc_rng_t[64];
  103. /*! @brief Memory buffer to hold CAAM descriptor for DESA jobs */
  104. typedef uint32_t caam_desc_cipher_des_t[64];
  105. /*! @brief Memory buffer to hold CAAM descriptor for PKHA jobs */
  106. typedef uint32_t caam_desc_pkha_t[64];
  107. /*! @brief Memory buffer to hold CAAM descriptor for PKHA ECC jobs */
  108. typedef uint32_t caam_desc_pkha_ecc_t[64];
  109. typedef struct _caam_job_ring_interface
  110. {
  111. uint32_t inputJobRing[4];
  112. uint32_t outputJobRing[8];
  113. } caam_job_ring_interface_t;
  114. /*! @brief CAAM RNG sample mode. Used by caam_config_t. */
  115. typedef enum _caam_rng_sample_mode
  116. {
  117. kCAAM_RNG_SampleModeVonNeumann = 0U, /*!< Use von Neumann data in both Entropy shifter and Statistical Checker. */
  118. kCAAM_RNG_SampleModeRaw = 1U, /*!< Use raw data into both Entropy shifter and Statistical Checker. */
  119. kCAAM_RNG_SampleModeVonNeumannRaw =
  120. 2U /*!< Use von Neumann data in Entropy shifter. Use raw data into Statistical Checker. */
  121. } caam_rng_sample_mode_t;
  122. /*! @brief CAAM RNG ring oscillator divide. Used by caam_config_t. */
  123. typedef enum _caam_rng_ring_osc_div
  124. {
  125. kCAAM_RNG_RingOscDiv0 = 0U, /*!< Ring oscillator with no divide */
  126. kCAAM_RNG_RingOscDiv2 = 1U, /*!< Ring oscillator divided-by-2. */
  127. kCAAM_RNG_RingOscDiv4 = 2U, /*!< Ring oscillator divided-by-4. */
  128. kCAAM_RNG_RingOscDiv8 = 3U /*!< Ring oscillator divided-by-8. */
  129. } caam_rng_ring_osc_div_t;
  130. /*! @brief CAAM Private Blob. Used by caam_config_t. */
  131. typedef enum _caam_priblob
  132. {
  133. kCAAM_PrivSecureBootBlobs = 0U, /*!< Private secure boot software blobs. */
  134. kCAAM_PrivProvisioningBlobsType1 = 1U, /*!< Private Provisioning Type 1 blobs. */
  135. kCAAM_PrivProvisioningBlobsType2 = 2U, /*!< Private Provisioning Type 2 blobs. */
  136. kCAAM_NormalOperationBlobs = 3U, /*!< Normal operation blobs. */
  137. } caam_priblob_t;
  138. /*! @brief CAAM configuration structure. */
  139. typedef struct _caam_config
  140. {
  141. caam_job_ring_interface_t *jobRingInterface[4];
  142. caam_rng_sample_mode_t rngSampleMode; /*!< RTMCTL Sample Mode. */
  143. caam_rng_ring_osc_div_t rngRingOscDiv; /*!< RTMCTL Oscillator Divide. */
  144. bool scfgrLockTrngProgramMode; /*!< SCFGR Lock TRNG Program Mode. */
  145. bool scfgrEnableRandomDataBuffer; /*!< SCFGR Enable random data buffer. */
  146. bool scfgrRandomRngStateHandle0; /*!< SCFGR Random Number Generator State Handle 0. */
  147. bool scfgrRandomDpaResistance; /*!< SCFGR Random Differential Power Analysis Resistance. */
  148. caam_priblob_t scfgrPriblob; /*!< SCFGR Private Blob. */
  149. } caam_config_t;
  150. /*! @brief CAAM External Key Transfer command SRC (The source from which the key will be obtained) */
  151. typedef enum _caam_ext_key_xfr_source
  152. {
  153. kCAAM_ExtKeyXfr_KeyRegisterClass1 = 1U, /*!< The Class 1 Key Register is the source. */
  154. kCAAM_ExtKeyXfr_KeyRegisterClass2 = 2U, /*!< The Class 2 Key Register is the source. */
  155. kCAAM_ExtKeyXfr_PkhaRamE = 3U, /*!< The PKHA E RAM is the source. */
  156. } caam_ext_key_xfr_source_t;
  157. /*! @} */ /* end of caam_driver */
  158. /*******************************************************************************
  159. * AES Definitions
  160. *******************************************************************************/
  161. /*!
  162. * @addtogroup caam_driver_aes
  163. * @{
  164. */
  165. /*! AES block size in bytes */
  166. #define CAAM_AES_BLOCK_SIZE 16
  167. /*!
  168. *@}
  169. */ /* end of caam_driver_aes */
  170. /*******************************************************************************
  171. * DES Definitions
  172. *******************************************************************************/
  173. /*!
  174. * @addtogroup caam_driver_des
  175. * @{
  176. */
  177. /*! @brief CAAM DES key size - 64 bits. */
  178. #define CAAM_DES_KEY_SIZE 8U
  179. /*! @brief CAAM DES IV size - 8 bytes */
  180. #define CAAM_DES_IV_SIZE 8
  181. /*!
  182. *@}
  183. */ /* end of caam_driver_des */
  184. /*******************************************************************************
  185. * HASH Definitions
  186. ******************************************************************************/
  187. /*!
  188. * @addtogroup caam_driver_hash
  189. * @{
  190. */
  191. /*! @brief Supported cryptographic block cipher functions for HASH creation */
  192. typedef enum _caam_hash_algo_t
  193. {
  194. kCAAM_XcbcMac = 0, /*!< XCBC-MAC (AES engine) */
  195. kCAAM_Cmac, /*!< CMAC (AES engine) */
  196. kCAAM_Sha1, /*!< SHA_1 (MDHA engine) */
  197. kCAAM_Sha224, /*!< SHA_224 (MDHA engine) */
  198. kCAAM_Sha256, /*!< SHA_256 (MDHA engine) */
  199. kCAAM_Sha384, /*!< SHA_384 (MDHA engine) */
  200. kCAAM_Sha512, /*!< SHA_512 (MDHA engine) */
  201. } caam_hash_algo_t;
  202. /*! @brief CAAM HASH Context size. */
  203. #define CAAM_SHA_BLOCK_SIZE 128U /*!< up to SHA-512 block size */
  204. #define CAAM_HASH_BLOCK_SIZE CAAM_SHA_BLOCK_SIZE /*!< CAAM hash block size */
  205. /*! @brief CAAM HASH Context size. */
  206. #define CAAM_HASH_CTX_SIZE 58
  207. /*! @brief Storage type used to save hash context. */
  208. typedef uint32_t caam_hash_ctx_t[CAAM_HASH_CTX_SIZE];
  209. /*!
  210. *@}
  211. */ /* end of caam_driver_hash */
  212. /*******************************************************************************
  213. * RNG Definitions
  214. ******************************************************************************/
  215. /*!
  216. * @addtogroup caam_driver_rng
  217. * @{
  218. */
  219. /*! @brief CAAM RNG state handle */
  220. typedef enum _caam_rng_state_handle
  221. {
  222. kCAAM_RngStateHandle0 = 0u, /*!< CAAM RNG state handle 0 */
  223. kCAAM_RngStateHandle1 = 1u, /*!< CAAM RNG state handle 1 */
  224. } caam_rng_state_handle_t;
  225. /*! @brief Type of random data to generate */
  226. typedef enum _caam_rng_random_type
  227. {
  228. kCAAM_RngDataAny = 0u, /*!< CAAM RNG any random data bytes */
  229. kCAAM_RngDataOddParity = 1u, /*!< CAAM RNG odd parity random data bytes */
  230. kCAAM_RngDataNonZero = 2u, /*!< CAAM RNG non zero random data bytes */
  231. } caam_rng_random_type_t;
  232. /*! @brief 256-bit value used as optional additional entropy input */
  233. typedef uint32_t caam_rng_generic256_t[256 / sizeof(uint32_t)];
  234. /*! @brief CAAM RNG configuration */
  235. typedef struct _caam_rng_user_config
  236. {
  237. uint32_t autoReseedInterval; /*!< Automatic reseed internal. If set to zero, CAAM RNG will use hardware default
  238. interval of 10.000.000 generate requests. */
  239. caam_rng_generic256_t *personalString; /*!< NULL or pointer to optional personalization string */
  240. } caam_rng_config_t;
  241. /*!
  242. *@}
  243. */ /* end of caam_driver_rng */
  244. /*******************************************************************************
  245. * PKHA Definitions
  246. ******************************************************************************/
  247. /*!
  248. * @addtogroup caam_driver_pkha
  249. * @{
  250. */
  251. /*! PKHA ECC point structure */
  252. typedef struct _caam_pkha_ecc_point_t
  253. {
  254. uint8_t *X; /*!< X coordinate (affine) */
  255. uint8_t *Y; /*!< Y coordinate (affine) */
  256. } caam_pkha_ecc_point_t;
  257. /*! @brief Use of timing equalized version of a PKHA function. */
  258. typedef enum _caam_pkha_timing_t
  259. {
  260. kCAAM_PKHA_NoTimingEqualized = 0U, /*!< Normal version of a PKHA operation */
  261. kCAAM_PKHA_TimingEqualized = 1U /*!< Timing-equalized version of a PKHA operation */
  262. } caam_pkha_timing_t;
  263. /*! @brief Integer vs binary polynomial arithmetic selection. */
  264. typedef enum _caam_pkha_f2m_t
  265. {
  266. kCAAM_PKHA_IntegerArith = 0U, /*!< Use integer arithmetic */
  267. kCAAM_PKHA_F2mArith = 1U /*!< Use binary polynomial arithmetic */
  268. } caam_pkha_f2m_t;
  269. /*! @brief Montgomery or normal PKHA input format. */
  270. typedef enum _caam_pkha_montgomery_form_t
  271. {
  272. kCAAM_PKHA_NormalValue = 0U, /*!< PKHA number is normal integer */
  273. kCAAM_PKHA_MontgomeryFormat = 1U /*!< PKHA number is in montgomery format */
  274. } caam_pkha_montgomery_form_t;
  275. /*!
  276. *@}
  277. */ /* end of caam_driver_pkha */
  278. /*******************************************************************************
  279. * API
  280. ******************************************************************************/
  281. #if defined(__cplusplus)
  282. extern "C" {
  283. #endif
  284. /*!
  285. * @addtogroup caam_driver
  286. * @{
  287. */
  288. /*!
  289. * @brief Initializes the CAAM driver.
  290. *
  291. * This function initializes the CAAM driver, including CAAM's internal RNG.
  292. * @param base CAAM peripheral base address
  293. * @param config Pointer to configuration structure.
  294. * @return kStatus_Success the CAAM Init has completed with zero termination status word
  295. * @return kStatus_Fail the CAAM Init has completed with non-zero termination status word
  296. */
  297. status_t CAAM_Init(CAAM_Type *base, const caam_config_t *config);
  298. /*!
  299. * @brief Deinitializes the CAAM driver.
  300. * This function deinitializes the CAAM driver.
  301. * @param base CAAM peripheral base address
  302. * @return kStatus_Success the CAAM Deinit has completed with zero termination status word
  303. * @return kStatus_Fail the CAAM Deinit has completed with non-zero termination status word
  304. */
  305. status_t CAAM_Deinit(CAAM_Type *base);
  306. /*!
  307. * @brief Gets the default configuration structure.
  308. *
  309. * This function initializes the CAAM configuration structure to a default value. The default
  310. * values are as follows.
  311. * caamConfig->rngSampleMode = kCAAM_RNG_SampleModeVonNeumann;
  312. * caamConfig->rngRingOscDiv = kCAAM_RNG_RingOscDiv4;
  313. *
  314. * @param[out] config Pointer to configuration structure.
  315. */
  316. void CAAM_GetDefaultConfig(caam_config_t *config);
  317. /*!
  318. * @brief Wait for a CAAM job to complete.
  319. *
  320. * This function polls CAAM output ring for a specific job.
  321. *
  322. * The CAAM job ring is specified by the jobRing field in the caam_handle_t structure.
  323. * The job to be waited is specified by it's descriptor address.
  324. *
  325. * This function has two modes, determined by the mode argument.
  326. * In blocking mode, the function polls the specified jobRing until the descriptor
  327. * is available in the CAAM output job ring.
  328. * In non-blocking mode, it polls the output ring once and returns status
  329. * immediately.
  330. *
  331. * The function can be called from multiple threads or interrupt service routines,
  332. * as internally it uses global critical section (global interrupt disable enable)
  333. * to protect it's operation against concurrent accesses.
  334. * The global interrupt is disabled only when the descriptor is found
  335. * in the output ring, for a very short time, to remove the descriptor from the output ring
  336. * safely.
  337. *
  338. * @param base CAAM peripheral base address
  339. * @param handle Data structure with CAAM jobRing used for this request
  340. * @param descriptor
  341. * @param mode Blocking and non-blocking mode. Zero is blocking. Non-zero is non-blocking.
  342. * @return kStatus_Success the CAAM job has completed with zero job termination status word
  343. * @return kStatus_Fail the CAAM job has completed with non-zero job termination status word
  344. * @return kStatus_Again In non-blocking mode, the job is not ready in the CAAM Output Ring
  345. */
  346. status_t CAAM_Wait(CAAM_Type *base, caam_handle_t *handle, uint32_t *descriptor, caam_wait_mode_t mode);
  347. /*!
  348. * @brief External Key Transfer.
  349. *
  350. * This function loads the given key source to an CAAM external destination via a private interface,
  351. * such as Inline Encryption Engine IEE Private Key bus.
  352. *
  353. * The CAAM job ring is specified by the jobRing field in the caam_handle_t structure.
  354. *
  355. * This function is blocking.
  356. *
  357. * @param base CAAM peripheral base address
  358. * @param handle Data structure with CAAM jobRing used for this request.
  359. * @param keySource The source from which the key will be obtained.
  360. * @param keySize Size of the key in bytes.
  361. * @return kStatus_Success the CAAM job has completed with zero job termination status word
  362. * @return kStatus_Fail the CAAM job has completed with non-zero job termination status word
  363. */
  364. status_t CAAM_ExternalKeyTransfer(CAAM_Type *base,
  365. caam_handle_t *handle,
  366. caam_ext_key_xfr_source_t keySource,
  367. size_t keySize);
  368. /*!
  369. *@}
  370. */ /* end of caam_driver */
  371. /*******************************************************************************
  372. * AES API
  373. ******************************************************************************/
  374. /*!
  375. * @addtogroup caam_driver_aes
  376. * @{
  377. */
  378. /*!
  379. * @brief Encrypts AES using the ECB block mode.
  380. *
  381. * Encrypts AES using the ECB block mode.
  382. *
  383. * @param base CAAM peripheral base address
  384. * @param handle Handle used for this request. Specifies jobRing.
  385. * @param plaintext Input plain text to encrypt
  386. * @param[out] ciphertext Output cipher text
  387. * @param size Size of input and output data in bytes. Must be multiple of 16 bytes.
  388. * @param key Input key to use for encryption
  389. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  390. * @return Status from encrypt operation
  391. */
  392. status_t CAAM_AES_EncryptEcb(CAAM_Type *base,
  393. caam_handle_t *handle,
  394. const uint8_t *plaintext,
  395. uint8_t *ciphertext,
  396. size_t size,
  397. const uint8_t *key,
  398. size_t keySize);
  399. /*!
  400. * @brief Decrypts AES using ECB block mode.
  401. *
  402. * Decrypts AES using ECB block mode.
  403. *
  404. * @param base CAAM peripheral base address
  405. * @param handle Handle used for this request. Specifies jobRing.
  406. * @param ciphertext Input cipher text to decrypt
  407. * @param[out] plaintext Output plain text
  408. * @param size Size of input and output data in bytes. Must be multiple of 16 bytes.
  409. * @param key Input key.
  410. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  411. * @return Status from decrypt operation
  412. */
  413. status_t CAAM_AES_DecryptEcb(CAAM_Type *base,
  414. caam_handle_t *handle,
  415. const uint8_t *ciphertext,
  416. uint8_t *plaintext,
  417. size_t size,
  418. const uint8_t *key,
  419. size_t keySize);
  420. /*!
  421. * @brief Encrypts AES using CBC block mode.
  422. *
  423. * @param base CAAM peripheral base address
  424. * @param handle Handle used for this request. Specifies jobRing.
  425. * @param plaintext Input plain text to encrypt
  426. * @param[out] ciphertext Output cipher text
  427. * @param size Size of input and output data in bytes. Must be multiple of 16 bytes.
  428. * @param iv Input initial vector to combine with the first input block.
  429. * @param key Input key to use for encryption
  430. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  431. * @return Status from encrypt operation
  432. */
  433. status_t CAAM_AES_EncryptCbc(CAAM_Type *base,
  434. caam_handle_t *handle,
  435. const uint8_t *plaintext,
  436. uint8_t *ciphertext,
  437. size_t size,
  438. const uint8_t iv[CAAM_AES_BLOCK_SIZE],
  439. const uint8_t *key,
  440. size_t keySize);
  441. /*!
  442. * @brief Decrypts AES using CBC block mode.
  443. *
  444. * @param base CAAM peripheral base address
  445. * @param handle Handle used for this request. Specifies jobRing.
  446. * @param ciphertext Input cipher text to decrypt
  447. * @param[out] plaintext Output plain text
  448. * @param size Size of input and output data in bytes. Must be multiple of 16 bytes.
  449. * @param iv Input initial vector to combine with the first input block.
  450. * @param key Input key to use for decryption
  451. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  452. * @return Status from decrypt operation
  453. */
  454. status_t CAAM_AES_DecryptCbc(CAAM_Type *base,
  455. caam_handle_t *handle,
  456. const uint8_t *ciphertext,
  457. uint8_t *plaintext,
  458. size_t size,
  459. const uint8_t iv[CAAM_AES_BLOCK_SIZE],
  460. const uint8_t *key,
  461. size_t keySize);
  462. /*!
  463. * @brief Encrypts or decrypts AES using CTR block mode.
  464. *
  465. * Encrypts or decrypts AES using CTR block mode.
  466. * AES CTR mode uses only forward AES cipher and same algorithm for encryption and decryption.
  467. * The only difference between encryption and decryption is that, for encryption, the input argument
  468. * is plain text and the output argument is cipher text. For decryption, the input argument is cipher text
  469. * and the output argument is plain text.
  470. *
  471. * @param base CAAM peripheral base address
  472. * @param handle Handle used for this request. Specifies jobRing.
  473. * @param input Input data for CTR block mode
  474. * @param[out] output Output data for CTR block mode
  475. * @param size Size of input and output data in bytes
  476. * @param[in,out] counter Input counter (updates on return)
  477. * @param key Input key to use for forward AES cipher
  478. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  479. * @param[out] counterlast Output cipher of last counter, for chained CTR calls. NULL can be passed if chained calls are
  480. * not used.
  481. * @param[out] szLeft Output number of bytes in left unused in counterlast block. NULL can be passed if chained calls
  482. * are not used.
  483. * @return Status from encrypt operation
  484. */
  485. status_t CAAM_AES_CryptCtr(CAAM_Type *base,
  486. caam_handle_t *handle,
  487. const uint8_t *input,
  488. uint8_t *output,
  489. size_t size,
  490. uint8_t counter[CAAM_AES_BLOCK_SIZE],
  491. const uint8_t *key,
  492. size_t keySize,
  493. uint8_t counterlast[CAAM_AES_BLOCK_SIZE],
  494. size_t *szLeft);
  495. /*!
  496. * @brief Encrypts AES and tags using CCM block mode.
  497. *
  498. * Encrypts AES and optionally tags using CCM block mode.
  499. *
  500. * @param base CAAM peripheral base address
  501. * @param handle Handle used for this request. Specifies jobRing.
  502. * @param plaintext Input plain text to encrypt
  503. * @param[out] ciphertext Output cipher text.
  504. * @param size Size of input and output data in bytes. Zero means authentication only.
  505. * @param iv Nonce
  506. * @param ivSize Length of the Nonce in bytes. Must be 7, 8, 9, 10, 11, 12, or 13.
  507. * @param aad Input additional authentication data. Can be NULL if aadSize is zero.
  508. * @param aadSize Input size in bytes of AAD. Zero means data mode only (authentication skipped).
  509. * @param key Input key to use for encryption
  510. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  511. * @param[out] tag Generated output tag. Set to NULL to skip tag processing.
  512. * @param tagSize Input size of the tag to generate, in bytes. Must be 4, 6, 8, 10, 12, 14, or 16.
  513. * @return Status from encrypt operation
  514. */
  515. status_t CAAM_AES_EncryptTagCcm(CAAM_Type *base,
  516. caam_handle_t *handle,
  517. const uint8_t *plaintext,
  518. uint8_t *ciphertext,
  519. size_t size,
  520. const uint8_t *iv,
  521. size_t ivSize,
  522. const uint8_t *aad,
  523. size_t aadSize,
  524. const uint8_t *key,
  525. size_t keySize,
  526. uint8_t *tag,
  527. size_t tagSize);
  528. /*!
  529. * @brief Decrypts AES and authenticates using CCM block mode.
  530. *
  531. * Decrypts AES and optionally authenticates using CCM block mode.
  532. *
  533. * @param base CAAM peripheral base address
  534. * @param handle Handle used for this request. Specifies jobRing.
  535. * @param ciphertext Input cipher text to decrypt
  536. * @param[out] plaintext Output plain text.
  537. * @param size Size of input and output data in bytes. Zero means authentication data only.
  538. * @param iv Nonce
  539. * @param ivSize Length of the Nonce in bytes. Must be 7, 8, 9, 10, 11, 12, or 13.
  540. * @param aad Input additional authentication data. Can be NULL if aadSize is zero.
  541. * @param aadSize Input size in bytes of AAD. Zero means data mode only (authentication data skipped).
  542. * @param key Input key to use for decryption
  543. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  544. * @param tag Received tag. Set to NULL to skip tag processing.
  545. * @param tagSize Input size of the received tag to compare with the computed tag, in bytes. Must be 4, 6, 8, 10, 12,
  546. * 14, or 16.
  547. * @return Status from decrypt operation
  548. */
  549. status_t CAAM_AES_DecryptTagCcm(CAAM_Type *base,
  550. caam_handle_t *handle,
  551. const uint8_t *ciphertext,
  552. uint8_t *plaintext,
  553. size_t size,
  554. const uint8_t *iv,
  555. size_t ivSize,
  556. const uint8_t *aad,
  557. size_t aadSize,
  558. const uint8_t *key,
  559. size_t keySize,
  560. const uint8_t *tag,
  561. size_t tagSize);
  562. /*!
  563. * @brief Encrypts AES and tags using GCM block mode.
  564. *
  565. * Encrypts AES and optionally tags using GCM block mode. If plaintext is NULL, only the GHASH is calculated and output
  566. * in the 'tag' field.
  567. *
  568. * @param base CAAM peripheral base address
  569. * @param handle Handle used for this request. Specifies jobRing.
  570. * @param plaintext Input plain text to encrypt
  571. * @param[out] ciphertext Output cipher text.
  572. * @param size Size of input and output data in bytes
  573. * @param iv Input initial vector
  574. * @param ivSize Size of the IV
  575. * @param aad Input additional authentication data
  576. * @param aadSize Input size in bytes of AAD
  577. * @param key Input key to use for encryption
  578. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  579. * @param[out] tag Output hash tag. Set to NULL to skip tag processing.
  580. * @param tagSize Input size of the tag to generate, in bytes. Must be 4,8,12,13,14,15 or 16.
  581. * @return Status from encrypt operation
  582. */
  583. status_t CAAM_AES_EncryptTagGcm(CAAM_Type *base,
  584. caam_handle_t *handle,
  585. const uint8_t *plaintext,
  586. uint8_t *ciphertext,
  587. size_t size,
  588. const uint8_t *iv,
  589. size_t ivSize,
  590. const uint8_t *aad,
  591. size_t aadSize,
  592. const uint8_t *key,
  593. size_t keySize,
  594. uint8_t *tag,
  595. size_t tagSize);
  596. /*!
  597. * @brief Decrypts AES and authenticates using GCM block mode.
  598. *
  599. * Decrypts AES and optionally authenticates using GCM block mode. If ciphertext is NULL, only the GHASH is calculated
  600. * and compared with the received GHASH in 'tag' field.
  601. *
  602. * @param base CAAM peripheral base address
  603. * @param handle Handle used for this request. Specifies jobRing.
  604. * @param ciphertext Input cipher text to decrypt
  605. * @param[out] plaintext Output plain text.
  606. * @param size Size of input and output data in bytes
  607. * @param iv Input initial vector
  608. * @param ivSize Size of the IV
  609. * @param aad Input additional authentication data
  610. * @param aadSize Input size in bytes of AAD
  611. * @param key Input key to use for encryption
  612. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  613. * @param tag Input hash tag to compare. Set to NULL to skip tag processing.
  614. * @param tagSize Input size of the tag, in bytes. Must be 4, 8, 12, 13, 14, 15, or 16.
  615. * @return Status from decrypt operation
  616. */
  617. status_t CAAM_AES_DecryptTagGcm(CAAM_Type *base,
  618. caam_handle_t *handle,
  619. const uint8_t *ciphertext,
  620. uint8_t *plaintext,
  621. size_t size,
  622. const uint8_t *iv,
  623. size_t ivSize,
  624. const uint8_t *aad,
  625. size_t aadSize,
  626. const uint8_t *key,
  627. size_t keySize,
  628. const uint8_t *tag,
  629. size_t tagSize);
  630. /*!
  631. *@}
  632. */ /* end of caam_driver_aes */
  633. /*!
  634. * @addtogroup caam_nonblocking_driver_aes
  635. * @{
  636. */
  637. /*!
  638. * @brief Encrypts AES using the ECB block mode.
  639. *
  640. * Puts AES ECB encrypt descriptor to CAAM input job ring.
  641. *
  642. * @param base CAAM peripheral base address
  643. * @param handle Handle used for this request. Specifies jobRing.
  644. * @param plaintext Input plain text to encrypt
  645. * @param[out] descriptor Memory for the CAAM descriptor.
  646. * @param[out] ciphertext Output cipher text
  647. * @param size Size of input and output data in bytes. Must be multiple of 16 bytes.
  648. * @param key Input key to use for encryption
  649. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  650. * @return Status from job descriptor push
  651. */
  652. status_t CAAM_AES_EncryptEcbNonBlocking(CAAM_Type *base,
  653. caam_handle_t *handle,
  654. caam_desc_aes_ecb_t descriptor,
  655. const uint8_t *plaintext,
  656. uint8_t *ciphertext,
  657. size_t size,
  658. const uint8_t *key,
  659. size_t keySize);
  660. /*!
  661. * @brief Decrypts AES using ECB block mode.
  662. *
  663. * Puts AES ECB decrypt descriptor to CAAM input job ring.
  664. *
  665. * @param base CAAM peripheral base address
  666. * @param handle Handle used for this request. Specifies jobRing.
  667. * @param[out] descriptor Memory for the CAAM descriptor.
  668. * @param ciphertext Input cipher text to decrypt
  669. * @param[out] plaintext Output plain text
  670. * @param size Size of input and output data in bytes. Must be multiple of 16 bytes.
  671. * @param key Input key.
  672. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  673. * @return Status from job descriptor push
  674. */
  675. status_t CAAM_AES_DecryptEcbNonBlocking(CAAM_Type *base,
  676. caam_handle_t *handle,
  677. caam_desc_aes_ecb_t descriptor,
  678. const uint8_t *ciphertext,
  679. uint8_t *plaintext,
  680. size_t size,
  681. const uint8_t *key,
  682. size_t keySize);
  683. /*!
  684. * @brief Encrypts AES using CBC block mode.
  685. *
  686. * Puts AES CBC encrypt descriptor to CAAM input job ring.
  687. *
  688. * @param base CAAM peripheral base address
  689. * @param handle Handle used for this request. Specifies jobRing.
  690. * @param[out] descriptor Memory for the CAAM descriptor.
  691. * @param plaintext Input plain text to encrypt
  692. * @param[out] ciphertext Output cipher text
  693. * @param size Size of input and output data in bytes. Must be multiple of 16 bytes.
  694. * @param iv Input initial vector to combine with the first input block.
  695. * @param key Input key to use for encryption
  696. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  697. * @return Status from job descriptor push
  698. */
  699. status_t CAAM_AES_EncryptCbcNonBlocking(CAAM_Type *base,
  700. caam_handle_t *handle,
  701. caam_desc_aes_cbc_t descriptor,
  702. const uint8_t *plaintext,
  703. uint8_t *ciphertext,
  704. size_t size,
  705. const uint8_t *iv,
  706. const uint8_t *key,
  707. size_t keySize);
  708. /*!
  709. * @brief Decrypts AES using CBC block mode.
  710. *
  711. * Puts AES CBC decrypt descriptor to CAAM input job ring.
  712. *
  713. * @param base CAAM peripheral base address
  714. * @param handle Handle used for this request. Specifies jobRing.
  715. * @param[out] descriptor Memory for the CAAM descriptor.
  716. * @param ciphertext Input cipher text to decrypt
  717. * @param[out] plaintext Output plain text
  718. * @param size Size of input and output data in bytes. Must be multiple of 16 bytes.
  719. * @param iv Input initial vector to combine with the first input block.
  720. * @param key Input key to use for decryption
  721. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  722. * @return Status from job descriptor push
  723. */
  724. status_t CAAM_AES_DecryptCbcNonBlocking(CAAM_Type *base,
  725. caam_handle_t *handle,
  726. caam_desc_aes_cbc_t descriptor,
  727. const uint8_t *ciphertext,
  728. uint8_t *plaintext,
  729. size_t size,
  730. const uint8_t *iv,
  731. const uint8_t *key,
  732. size_t keySize);
  733. /*!
  734. * @brief Encrypts or decrypts AES using CTR block mode.
  735. *
  736. * Encrypts or decrypts AES using CTR block mode.
  737. * AES CTR mode uses only forward AES cipher and same algorithm for encryption and decryption.
  738. * The only difference between encryption and decryption is that, for encryption, the input argument
  739. * is plain text and the output argument is cipher text. For decryption, the input argument is cipher text
  740. * and the output argument is plain text.
  741. *
  742. * Puts AES CTR crypt descriptor to CAAM input job ring.
  743. *
  744. * @param base CAAM peripheral base address
  745. * @param handle Handle used for this request. Specifies jobRing.
  746. * @param[out] descriptor Memory for the CAAM descriptor.
  747. * @param input Input data for CTR block mode
  748. * @param[out] output Output data for CTR block mode
  749. * @param size Size of input and output data in bytes
  750. * @param[in,out] counter Input counter (updates on return)
  751. * @param key Input key to use for forward AES cipher
  752. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  753. * @param[out] counterlast Output cipher of last counter, for chained CTR calls. NULL can be passed if chained calls are
  754. * not used.
  755. * @param[out] szLeft Output number of bytes in left unused in counterlast block. NULL can be passed if chained calls
  756. * are not used.
  757. * @return Status from job descriptor push
  758. */
  759. status_t CAAM_AES_CryptCtrNonBlocking(CAAM_Type *base,
  760. caam_handle_t *handle,
  761. caam_desc_aes_ctr_t descriptor,
  762. const uint8_t *input,
  763. uint8_t *output,
  764. size_t size,
  765. uint8_t *counter,
  766. const uint8_t *key,
  767. size_t keySize,
  768. uint8_t *counterlast,
  769. size_t *szLeft);
  770. /*!
  771. * @brief Encrypts AES and tags using CCM block mode.
  772. *
  773. * Puts AES CCM encrypt and tag descriptor to CAAM input job ring.
  774. *
  775. * @param base CAAM peripheral base address
  776. * @param handle Handle used for this request. Specifies jobRing.
  777. * @param[out] descriptor Memory for the CAAM descriptor.
  778. * @param plaintext Input plain text to encrypt
  779. * @param[out] ciphertext Output cipher text.
  780. * @param size Size of input and output data in bytes. Zero means authentication only.
  781. * @param iv Nonce
  782. * @param ivSize Length of the Nonce in bytes. Must be 7, 8, 9, 10, 11, 12, or 13.
  783. * @param aad Input additional authentication data. Can be NULL if aadSize is zero.
  784. * @param aadSize Input size in bytes of AAD. Zero means data mode only (authentication skipped).
  785. * @param key Input key to use for encryption
  786. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  787. * @param[out] tag Generated output tag. Set to NULL to skip tag processing.
  788. * @param tagSize Input size of the tag to generate, in bytes. Must be 4, 6, 8, 10, 12, 14, or 16.
  789. * @return Status from job descriptor push
  790. */
  791. status_t CAAM_AES_EncryptTagCcmNonBlocking(CAAM_Type *base,
  792. caam_handle_t *handle,
  793. caam_desc_aes_ccm_t descriptor,
  794. const uint8_t *plaintext,
  795. uint8_t *ciphertext,
  796. size_t size,
  797. const uint8_t *iv,
  798. size_t ivSize,
  799. const uint8_t *aad,
  800. size_t aadSize,
  801. const uint8_t *key,
  802. size_t keySize,
  803. uint8_t *tag,
  804. size_t tagSize);
  805. /*!
  806. * @brief Decrypts AES and authenticates using CCM block mode.
  807. *
  808. * Puts AES CCM decrypt and check tag descriptor to CAAM input job ring.
  809. *
  810. * @param base CAAM peripheral base address
  811. * @param handle Handle used for this request. Specifies jobRing.
  812. * @param[out] descriptor Memory for the CAAM descriptor.
  813. * @param ciphertext Input cipher text to decrypt
  814. * @param[out] plaintext Output plain text.
  815. * @param size Size of input and output data in bytes. Zero means authentication data only.
  816. * @param iv Nonce
  817. * @param ivSize Length of the Nonce in bytes. Must be 7, 8, 9, 10, 11, 12, or 13.
  818. * @param aad Input additional authentication data. Can be NULL if aadSize is zero.
  819. * @param aadSize Input size in bytes of AAD. Zero means data mode only (authentication data skipped).
  820. * @param key Input key to use for decryption
  821. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  822. * @param tag Received tag. Set to NULL to skip tag processing.
  823. * @param tagSize Input size of the received tag to compare with the computed tag, in bytes. Must be 4, 6, 8, 10, 12,
  824. * 14, or 16.
  825. * @return Status from job descriptor push
  826. */
  827. status_t CAAM_AES_DecryptTagCcmNonBlocking(CAAM_Type *base,
  828. caam_handle_t *handle,
  829. caam_desc_aes_ccm_t descriptor,
  830. const uint8_t *ciphertext,
  831. uint8_t *plaintext,
  832. size_t size,
  833. const uint8_t *iv,
  834. size_t ivSize,
  835. const uint8_t *aad,
  836. size_t aadSize,
  837. const uint8_t *key,
  838. size_t keySize,
  839. const uint8_t *tag,
  840. size_t tagSize);
  841. /*!
  842. * @brief Encrypts AES and tags using GCM block mode.
  843. *
  844. * Encrypts AES and optionally tags using GCM block mode. If plaintext is NULL, only the GHASH is calculated and output
  845. * in the 'tag' field.
  846. * Puts AES GCM encrypt and tag descriptor to CAAM input job ring.
  847. *
  848. * @param base CAAM peripheral base address
  849. * @param handle Handle used for this request. Specifies jobRing.
  850. * @param[out] descriptor Memory for the CAAM descriptor.
  851. * @param plaintext Input plain text to encrypt
  852. * @param[out] ciphertext Output cipher text.
  853. * @param size Size of input and output data in bytes
  854. * @param iv Input initial vector
  855. * @param ivSize Size of the IV
  856. * @param aad Input additional authentication data
  857. * @param aadSize Input size in bytes of AAD
  858. * @param key Input key to use for encryption
  859. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  860. * @param[out] tag Output hash tag. Set to NULL to skip tag processing.
  861. * @param tagSize Input size of the tag to generate, in bytes. Must be 4,8,12,13,14,15 or 16.
  862. * @return Status from job descriptor push
  863. */
  864. status_t CAAM_AES_EncryptTagGcmNonBlocking(CAAM_Type *base,
  865. caam_handle_t *handle,
  866. caam_desc_aes_gcm_t descriptor,
  867. const uint8_t *plaintext,
  868. uint8_t *ciphertext,
  869. size_t size,
  870. const uint8_t *iv,
  871. size_t ivSize,
  872. const uint8_t *aad,
  873. size_t aadSize,
  874. const uint8_t *key,
  875. size_t keySize,
  876. uint8_t *tag,
  877. size_t tagSize);
  878. /*!
  879. * @brief Decrypts AES and authenticates using GCM block mode.
  880. *
  881. * Decrypts AES and optionally authenticates using GCM block mode. If ciphertext is NULL, only the GHASH is calculated
  882. * and compared with the received GHASH in 'tag' field.
  883. * Puts AES GCM decrypt and check tag descriptor to CAAM input job ring.
  884. *
  885. * @param base CAAM peripheral base address
  886. * @param handle Handle used for this request. Specifies jobRing.
  887. * @param[out] descriptor Memory for the CAAM descriptor.
  888. * @param ciphertext Input cipher text to decrypt
  889. * @param[out] plaintext Output plain text.
  890. * @param size Size of input and output data in bytes
  891. * @param iv Input initial vector
  892. * @param ivSize Size of the IV
  893. * @param aad Input additional authentication data
  894. * @param aadSize Input size in bytes of AAD
  895. * @param key Input key to use for encryption
  896. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  897. * @param tag Input hash tag to compare. Set to NULL to skip tag processing.
  898. * @param tagSize Input size of the tag, in bytes. Must be 4, 8, 12, 13, 14, 15, or 16.
  899. * @return Status from job descriptor push
  900. */
  901. status_t CAAM_AES_DecryptTagGcmNonBlocking(CAAM_Type *base,
  902. caam_handle_t *handle,
  903. caam_desc_aes_gcm_t descriptor,
  904. const uint8_t *ciphertext,
  905. uint8_t *plaintext,
  906. size_t size,
  907. const uint8_t *iv,
  908. size_t ivSize,
  909. const uint8_t *aad,
  910. size_t aadSize,
  911. const uint8_t *key,
  912. size_t keySize,
  913. const uint8_t *tag,
  914. size_t tagSize);
  915. /*!
  916. *@}
  917. */ /* end of caam_nonblocking_driver_aes */
  918. /*******************************************************************************
  919. * HASH API
  920. ******************************************************************************/
  921. /*!
  922. * @addtogroup caam_driver_hash
  923. * @{
  924. */
  925. /*!
  926. * @brief Initialize HASH context
  927. *
  928. * This function initializes the HASH.
  929. * Key shall be supplied if the underlaying algoritm is AES XCBC-MAC or CMAC.
  930. * Key shall be NULL if the underlaying algoritm is SHA.
  931. *
  932. * For XCBC-MAC, the key length must be 16. For CMAC, the key length can be
  933. * the AES key lengths supported by AES engine. For MDHA the key length argument
  934. * is ignored.
  935. *
  936. * This functions is used to initialize the context for both blocking and non-blocking
  937. * CAAM_HASH API.
  938. * For blocking CAAM HASH API, the HASH context contains all information required for context switch,
  939. * such as running hash or MAC. For non-blocking CAAM HASH API, the HASH context is used
  940. * to hold SGT. Therefore, the HASH context cannot be shared between blocking and non-blocking HASH API.
  941. * With one HASH context, either use only blocking HASH API or only non-blocking HASH API.
  942. *
  943. *
  944. * @param base CAAM peripheral base address
  945. * @param handle Handle used for this request.
  946. * @param[out] ctx Output hash context
  947. * @param algo Underlaying algorithm to use for hash computation.
  948. * @param key Input key (NULL if underlaying algorithm is SHA)
  949. * @param keySize Size of input key in bytes
  950. * @return Status of initialization
  951. */
  952. status_t CAAM_HASH_Init(CAAM_Type *base,
  953. caam_handle_t *handle,
  954. caam_hash_ctx_t *ctx,
  955. caam_hash_algo_t algo,
  956. const uint8_t *key,
  957. size_t keySize);
  958. /*!
  959. * @brief Add data to current HASH
  960. *
  961. * Add data to current HASH. This can be called repeatedly with an arbitrary amount of data to be
  962. * hashed. The functions blocks. If it returns kStatus_Success, the running hash or mac
  963. * has been updated (CAAM has processed the input data), so the memory at input pointer
  964. * can be released back to system. The context is updated with the running hash or mac
  965. * and with all necessary information to support possible context switch.
  966. *
  967. * @param[in,out] ctx HASH context
  968. * @param input Input data
  969. * @param inputSize Size of input data in bytes
  970. * @return Status of the hash update operation
  971. */
  972. status_t CAAM_HASH_Update(caam_hash_ctx_t *ctx, const uint8_t *input, size_t inputSize);
  973. /*!
  974. * @brief Finalize hashing
  975. *
  976. * Outputs the final hash (computed by CAAM_HASH_Update()) and erases the context.
  977. *
  978. * @param[in,out] ctx Input hash context
  979. * @param[out] output Output hash data
  980. * @param[out] outputSize Output parameter storing the size of the output hash in bytes
  981. * @return Status of the hash finish operation
  982. */
  983. status_t CAAM_HASH_Finish(caam_hash_ctx_t *ctx, uint8_t *output, size_t *outputSize);
  984. /*!
  985. * @brief Create HASH on given data
  986. *
  987. * Perform the full keyed XCBC-MAC/CMAC or SHA in one function call.
  988. *
  989. * Key shall be supplied if the underlaying algoritm is AES XCBC-MAC or CMAC.
  990. * Key shall be NULL if the underlaying algoritm is SHA.
  991. *
  992. * For XCBC-MAC, the key length must be 16. For CMAC, the key length can be
  993. * the AES key lengths supported by AES engine. For MDHA the key length argument
  994. * is ignored.
  995. *
  996. * The function is blocking.
  997. *
  998. * @param base CAAM peripheral base address
  999. * @param handle Handle used for this request.
  1000. * @param algo Underlaying algorithm to use for hash computation.
  1001. * @param input Input data
  1002. * @param inputSize Size of input data in bytes
  1003. * @param key Input key (NULL if underlaying algorithm is SHA)
  1004. * @param keySize Size of input key in bytes
  1005. * @param[out] output Output hash data
  1006. * @param[out] outputSize Output parameter storing the size of the output hash in bytes
  1007. * @return Status of the one call hash operation.
  1008. */
  1009. status_t CAAM_HASH(CAAM_Type *base,
  1010. caam_handle_t *handle,
  1011. caam_hash_algo_t algo,
  1012. const uint8_t *input,
  1013. size_t inputSize,
  1014. const uint8_t *key,
  1015. size_t keySize,
  1016. uint8_t *output,
  1017. size_t *outputSize);
  1018. /*!
  1019. *@}
  1020. */ /* end of caam_driver_hash */
  1021. /*!
  1022. * @addtogroup caam_nonblocking_driver_hash
  1023. * @{
  1024. */
  1025. /*!
  1026. * @brief Add input address and size to input data table
  1027. *
  1028. * Add data input pointer to a table maintained internally in the context.
  1029. * Each call of this function creates one entry in the table.
  1030. * The entry consists of the input pointer and inputSize.
  1031. * All entries created by one or multiple calls of this function can be processed
  1032. * in one call to CAAM_HASH_FinishNonBlocking() function.
  1033. * Individual entries can point to non-continuous data in the memory.
  1034. * The processing will occur in the order in which the CAAM_HASH_UpdateNonBlocking()
  1035. * have been called.
  1036. *
  1037. * Memory pointers will be later accessed by CAAM (at time of CAAM_HASH_FinishNonBlocking()),
  1038. * so the memory must stay valid
  1039. * until CAAM_HASH_FinishNonBlocking() has been called and CAAM completes the processing.
  1040. *
  1041. * @param[in,out] ctx HASH context
  1042. * @param input Input data
  1043. * @param inputSize Size of input data in bytes
  1044. * @return Status of the hash update operation
  1045. */
  1046. status_t CAAM_HASH_UpdateNonBlocking(caam_hash_ctx_t *ctx, const uint8_t *input, size_t inputSize);
  1047. /*!
  1048. * @brief Finalize hashing
  1049. *
  1050. * The actual algorithm is computed with all input data, the memory pointers
  1051. * are accessed by CAAM after the function returns.
  1052. * The input data chunks have been specified by prior calls to CAAM_HASH_UpdateNonBlocking().
  1053. * The function schedules the request at CAAM, then returns.
  1054. * After a while, when the CAAM completes processing of the input data chunks,
  1055. * the result is written to the output[] array, outputSize is written and the context
  1056. * is cleared.
  1057. *
  1058. * @param[in,out] ctx Input hash context
  1059. * @param[out] descriptor Memory for the CAAM descriptor.
  1060. * @param[out] output Output hash data
  1061. * @param[out] outputSize Output parameter storing the size of the output hash in bytes
  1062. * @return Status of the hash finish operation
  1063. */
  1064. status_t CAAM_HASH_FinishNonBlocking(caam_hash_ctx_t *ctx,
  1065. caam_desc_hash_t descriptor,
  1066. uint8_t *output,
  1067. size_t *outputSize);
  1068. /*!
  1069. * @brief Create HASH on given data
  1070. *
  1071. * Perform the full keyed XCBC-MAC/CMAC or SHA in one function call.
  1072. *
  1073. * Key shall be supplied if the underlaying algoritm is AES XCBC-MAC or CMAC.
  1074. * Key shall be NULL if the underlaying algoritm is SHA.
  1075. *
  1076. * For XCBC-MAC, the key length must be 16. For CMAC, the key length can be
  1077. * the AES key lengths supported by AES engine. For MDHA the key length argument
  1078. * is ignored.
  1079. *
  1080. * The function is non-blocking. The request is scheduled at CAAM.
  1081. *
  1082. * @param base CAAM peripheral base address
  1083. * @param handle Handle used for this request.
  1084. * @param[out] descriptor Memory for the CAAM descriptor.
  1085. * @param algo Underlaying algorithm to use for hash computation.
  1086. * @param input Input data
  1087. * @param inputSize Size of input data in bytes
  1088. * @param key Input key (NULL if underlaying algorithm is SHA)
  1089. * @param keySize Size of input key in bytes
  1090. * @param[out] output Output hash data
  1091. * @param[out] outputSize Output parameter storing the size of the output hash in bytes
  1092. * @return Status of the one call hash operation.
  1093. */
  1094. status_t CAAM_HASH_NonBlocking(CAAM_Type *base,
  1095. caam_handle_t *handle,
  1096. caam_desc_hash_t descriptor,
  1097. caam_hash_algo_t algo,
  1098. const uint8_t *input,
  1099. size_t inputSize,
  1100. const uint8_t *key,
  1101. size_t keySize,
  1102. uint8_t *output,
  1103. size_t *outputSize);
  1104. /*!
  1105. *@}
  1106. */ /* end of caam_nonblocking_driver_hash */
  1107. /*******************************************************************************
  1108. * RNG API
  1109. ******************************************************************************/
  1110. /*!
  1111. * @addtogroup caam_driver_rng
  1112. * @{
  1113. */
  1114. /*!
  1115. * @brief Initializes user configuration structure to default.
  1116. *
  1117. * This function initializes the configure structure to default value. the default
  1118. * value are:
  1119. * @code
  1120. * config->autoReseedInterval = 0;
  1121. * config->personalString = NULL;
  1122. * @endcode
  1123. *
  1124. * @param config User configuration structure.
  1125. * @return status of the request
  1126. */
  1127. status_t CAAM_RNG_GetDefaultConfig(caam_rng_config_t *config);
  1128. /*!
  1129. * @brief Instantiate the CAAM RNG state handle
  1130. *
  1131. * This function instantiates CAAM RNG state handle.
  1132. * The function is blocking and returns after CAAM has processed the request.
  1133. *
  1134. * @param base CAAM peripheral base address
  1135. * @param handle CAAM jobRing used for this request
  1136. * @param stateHandle RNG state handle to instantiate
  1137. * @param config Pointer to configuration structure.
  1138. * @return Status of the request
  1139. */
  1140. status_t CAAM_RNG_Init(CAAM_Type *base,
  1141. caam_handle_t *handle,
  1142. caam_rng_state_handle_t stateHandle,
  1143. const caam_rng_config_t *config);
  1144. /*!
  1145. * @brief Uninstantiate the CAAM RNG state handle
  1146. *
  1147. * This function uninstantiates CAAM RNG state handle.
  1148. * The function is blocking and returns after CAAM has processed the request.
  1149. *
  1150. * @param base CAAM peripheral base address
  1151. * @param handle jobRing used for this request.
  1152. * @param stateHandle RNG state handle to uninstantiate
  1153. * @return Status of the request
  1154. */
  1155. status_t CAAM_RNG_Deinit(CAAM_Type *base, caam_handle_t *handle, caam_rng_state_handle_t stateHandle);
  1156. /*!
  1157. * @brief Generate Secure Key
  1158. *
  1159. * This function generates random data writes it to Secure Key registers.
  1160. * The function is blocking and returns after CAAM has processed the request.
  1161. * RNG state handle 0 is always used.
  1162. *
  1163. * @param base CAAM peripheral base address
  1164. * @param handle jobRing used for this request
  1165. * @param additionalEntropy NULL or Pointer to optional 256-bit additional entropy.
  1166. * @return Status of the request
  1167. */
  1168. status_t CAAM_RNG_GenerateSecureKey(CAAM_Type *base, caam_handle_t *handle, caam_rng_generic256_t additionalEntropy);
  1169. /*!
  1170. * @brief Reseed the CAAM RNG state handle
  1171. *
  1172. * This function reseeds the CAAM RNG state handle.
  1173. * For a state handle in nondeterministic mode, the DRNG is seeded with 384 bits of
  1174. * entropy from the TRNG and an optional 256-bit additional input from the descriptor
  1175. * via the Class 1 Context Register.
  1176. *
  1177. * The function is blocking and returns after CAAM has processed the request.
  1178. *
  1179. * @param base CAAM peripheral base address
  1180. * @param handle jobRing used for this request
  1181. * @param stateHandle RNG state handle to reseed
  1182. * @param additionalEntropy NULL or Pointer to optional 256-bit additional entropy.
  1183. * @return Status of the request
  1184. */
  1185. status_t CAAM_RNG_Reseed(CAAM_Type *base,
  1186. caam_handle_t *handle,
  1187. caam_rng_state_handle_t stateHandle,
  1188. caam_rng_generic256_t additionalEntropy);
  1189. /*!
  1190. * @brief Get random data
  1191. *
  1192. * This function gets random data from CAAM RNG.
  1193. *
  1194. * The function is blocking and returns after CAAM has generated the requested data or an error occurred.
  1195. *
  1196. * @param base CAAM peripheral base address
  1197. * @param handle jobRing used for this request
  1198. * @param stateHandle RNG state handle used to generate random data
  1199. * @param[out] data Pointer address used to store random data
  1200. * @param dataSize Size of the buffer pointed by the data parameter
  1201. * @param dataType Type of random data to be generated
  1202. * @param additionalEntropy NULL or Pointer to optional 256-bit additional entropy.
  1203. * @return Status of the request
  1204. */
  1205. status_t CAAM_RNG_GetRandomData(CAAM_Type *base,
  1206. caam_handle_t *handle,
  1207. caam_rng_state_handle_t stateHandle,
  1208. void *data,
  1209. size_t dataSize,
  1210. caam_rng_random_type_t dataType,
  1211. caam_rng_generic256_t additionalEntropy);
  1212. /*!
  1213. *@}
  1214. */ /* end of caam_driver_rng */
  1215. /*!
  1216. * @addtogroup caam_nonblocking_driver_rng
  1217. * @{
  1218. */
  1219. /*!
  1220. * @brief Request random data
  1221. *
  1222. * This function schedules the request for random data from CAAM RNG.
  1223. * Memory at memory pointers will be accessed by CAAM shortly after this function
  1224. * returns, according to actual CAAM schedule.
  1225. *
  1226. * @param base CAAM peripheral base address
  1227. * @param handle RNG handle used for this request
  1228. * @param stateHandle RNG state handle used to generate random data
  1229. * @param[out] descriptor memory for CAAM commands
  1230. * @param[out] data Pointer address used to store random data
  1231. * @param dataSize Size of the buffer pointed by the data parameter, in bytes.
  1232. * @param dataType Type of random data to be generated.
  1233. * @param additionalEntropy NULL or Pointer to optional 256-bit additional entropy.
  1234. * @return status of the request
  1235. */
  1236. status_t CAAM_RNG_GetRandomDataNonBlocking(CAAM_Type *base,
  1237. caam_handle_t *handle,
  1238. caam_rng_state_handle_t stateHandle,
  1239. caam_desc_rng_t descriptor,
  1240. void *data,
  1241. size_t dataSize,
  1242. caam_rng_random_type_t dataType,
  1243. caam_rng_generic256_t additionalEntropy);
  1244. /*!
  1245. *@}
  1246. */ /* end of caam_nonblocking_driver_rng */
  1247. /*******************************************************************************
  1248. * DES API
  1249. ******************************************************************************/
  1250. /*!
  1251. * @addtogroup caam_driver_des
  1252. * @{
  1253. */
  1254. /*!
  1255. * @brief Encrypts DES using ECB block mode.
  1256. *
  1257. * Encrypts DES using ECB block mode.
  1258. *
  1259. * @param base CAAM peripheral base address
  1260. * @param handle Handle used for this request. Specifies jobRing.
  1261. * @param plaintext Input plaintext to encrypt
  1262. * @param[out] ciphertext Output ciphertext
  1263. * @param size Size of input and output data in bytes. Must be multiple of 8 bytes.
  1264. * @param key Input key to use for encryption
  1265. * @return Status from encrypt/decrypt operation
  1266. */
  1267. status_t CAAM_DES_EncryptEcb(CAAM_Type *base,
  1268. caam_handle_t *handle,
  1269. const uint8_t *plaintext,
  1270. uint8_t *ciphertext,
  1271. size_t size,
  1272. const uint8_t key[CAAM_DES_KEY_SIZE]);
  1273. /*!
  1274. * @brief Decrypts DES using ECB block mode.
  1275. *
  1276. * Decrypts DES using ECB block mode.
  1277. *
  1278. * @param base CAAM peripheral base address
  1279. * @param handle Handle used for this request. Specifies jobRing.
  1280. * @param ciphertext Input ciphertext to decrypt
  1281. * @param[out] plaintext Output plaintext
  1282. * @param size Size of input and output data in bytes. Must be multiple of 8 bytes.
  1283. * @param key Input key to use for decryption
  1284. * @return Status from encrypt/decrypt operation
  1285. */
  1286. status_t CAAM_DES_DecryptEcb(CAAM_Type *base,
  1287. caam_handle_t *handle,
  1288. const uint8_t *ciphertext,
  1289. uint8_t *plaintext,
  1290. size_t size,
  1291. const uint8_t key[CAAM_DES_KEY_SIZE]);
  1292. /*!
  1293. * @brief Encrypts DES using CBC block mode.
  1294. *
  1295. * Encrypts DES using CBC block mode.
  1296. *
  1297. * @param base CAAM peripheral base address
  1298. * @param handle Handle used for this request. Specifies jobRing.
  1299. * @param plaintext Input plaintext to encrypt
  1300. * @param[out] ciphertext Ouput ciphertext
  1301. * @param size Size of input and output data in bytes
  1302. * @param iv Input initial vector to combine with the first plaintext block.
  1303. * The iv does not need to be secret, but it must be unpredictable.
  1304. * @param key Input key to use for encryption
  1305. * @return Status from encrypt/decrypt operation
  1306. */
  1307. status_t CAAM_DES_EncryptCbc(CAAM_Type *base,
  1308. caam_handle_t *handle,
  1309. const uint8_t *plaintext,
  1310. uint8_t *ciphertext,
  1311. size_t size,
  1312. const uint8_t iv[CAAM_DES_IV_SIZE],
  1313. const uint8_t key[CAAM_DES_KEY_SIZE]);
  1314. /*!
  1315. * @brief Decrypts DES using CBC block mode.
  1316. *
  1317. * Decrypts DES using CBC block mode.
  1318. *
  1319. * @param base CAAM peripheral base address
  1320. * @param handle Handle used for this request. Specifies jobRing.
  1321. * @param ciphertext Input ciphertext to decrypt
  1322. * @param[out] plaintext Output plaintext
  1323. * @param size Size of input data in bytes
  1324. * @param iv Input initial vector to combine with the first plaintext block.
  1325. * The iv does not need to be secret, but it must be unpredictable.
  1326. * @param key Input key to use for decryption
  1327. * @return Status from encrypt/decrypt operation
  1328. */
  1329. status_t CAAM_DES_DecryptCbc(CAAM_Type *base,
  1330. caam_handle_t *handle,
  1331. const uint8_t *ciphertext,
  1332. uint8_t *plaintext,
  1333. size_t size,
  1334. const uint8_t iv[CAAM_DES_IV_SIZE],
  1335. const uint8_t key[CAAM_DES_KEY_SIZE]);
  1336. /*!
  1337. * @brief Encrypts DES using CFB block mode.
  1338. *
  1339. * Encrypts DES using CFB block mode.
  1340. *
  1341. * @param base CAAM peripheral base address
  1342. * @param handle Handle used for this request. Specifies jobRing.
  1343. * @param plaintext Input plaintext to encrypt
  1344. * @param size Size of input data in bytes
  1345. * @param iv Input initial block.
  1346. * @param key Input key to use for encryption
  1347. * @param[out] ciphertext Output ciphertext
  1348. * @return Status from encrypt/decrypt operation
  1349. */
  1350. status_t CAAM_DES_EncryptCfb(CAAM_Type *base,
  1351. caam_handle_t *handle,
  1352. const uint8_t *plaintext,
  1353. uint8_t *ciphertext,
  1354. size_t size,
  1355. const uint8_t iv[CAAM_DES_IV_SIZE],
  1356. const uint8_t key[CAAM_DES_KEY_SIZE]);
  1357. /*!
  1358. * @brief Decrypts DES using CFB block mode.
  1359. *
  1360. * Decrypts DES using CFB block mode.
  1361. *
  1362. * @param base CAAM peripheral base address
  1363. * @param handle Handle used for this request. Specifies jobRing.
  1364. * @param ciphertext Input ciphertext to decrypt
  1365. * @param[out] plaintext Output plaintext
  1366. * @param size Size of input and output data in bytes
  1367. * @param iv Input initial block.
  1368. * @param key Input key to use for decryption
  1369. * @return Status from encrypt/decrypt operation
  1370. */
  1371. status_t CAAM_DES_DecryptCfb(CAAM_Type *base,
  1372. caam_handle_t *handle,
  1373. const uint8_t *ciphertext,
  1374. uint8_t *plaintext,
  1375. size_t size,
  1376. const uint8_t iv[CAAM_DES_IV_SIZE],
  1377. const uint8_t key[CAAM_DES_KEY_SIZE]);
  1378. /*!
  1379. * @brief Encrypts DES using OFB block mode.
  1380. *
  1381. * Encrypts DES using OFB block mode.
  1382. *
  1383. * @param base CAAM peripheral base address
  1384. * @param handle Handle used for this request. Specifies jobRing.
  1385. * @param plaintext Input plaintext to encrypt
  1386. * @param[out] ciphertext Output ciphertext
  1387. * @param size Size of input and output data in bytes
  1388. * @param iv Input unique input vector. The OFB mode requires that the IV be unique
  1389. * for each execution of the mode under the given key.
  1390. * @param key Input key to use for encryption
  1391. * @return Status from encrypt/decrypt operation
  1392. */
  1393. status_t CAAM_DES_EncryptOfb(CAAM_Type *base,
  1394. caam_handle_t *handle,
  1395. const uint8_t *plaintext,
  1396. uint8_t *ciphertext,
  1397. size_t size,
  1398. const uint8_t iv[CAAM_DES_IV_SIZE],
  1399. const uint8_t key[CAAM_DES_KEY_SIZE]);
  1400. /*!
  1401. * @brief Decrypts DES using OFB block mode.
  1402. *
  1403. * Decrypts DES using OFB block mode.
  1404. *
  1405. * @param base CAAM peripheral base address
  1406. * @param handle Handle used for this request. Specifies jobRing.
  1407. * @param ciphertext Input ciphertext to decrypt
  1408. * @param[out] plaintext Output plaintext
  1409. * @param size Size of input and output data in bytes. Must be multiple of 8 bytes.
  1410. * @param iv Input unique input vector. The OFB mode requires that the IV be unique
  1411. * for each execution of the mode under the given key.
  1412. * @param key Input key to use for decryption
  1413. * @return Status from encrypt/decrypt operation
  1414. */
  1415. status_t CAAM_DES_DecryptOfb(CAAM_Type *base,
  1416. caam_handle_t *handle,
  1417. const uint8_t *ciphertext,
  1418. uint8_t *plaintext,
  1419. size_t size,
  1420. const uint8_t iv[CAAM_DES_IV_SIZE],
  1421. const uint8_t key[CAAM_DES_KEY_SIZE]);
  1422. /*!
  1423. * @brief Encrypts triple DES using ECB block mode with two keys.
  1424. *
  1425. * Encrypts triple DES using ECB block mode with two keys.
  1426. *
  1427. * @param base CAAM peripheral base address
  1428. * @param handle Handle used for this request. Specifies jobRing.
  1429. * @param plaintext Input plaintext to encrypt
  1430. * @param[out] ciphertext Output ciphertext
  1431. * @param size Size of input and output data in bytes. Must be multiple of 8 bytes.
  1432. * @param key1 First input key for key bundle
  1433. * @param key2 Second input key for key bundle
  1434. * @return Status from encrypt/decrypt operation
  1435. */
  1436. status_t CAAM_DES2_EncryptEcb(CAAM_Type *base,
  1437. caam_handle_t *handle,
  1438. const uint8_t *plaintext,
  1439. uint8_t *ciphertext,
  1440. size_t size,
  1441. const uint8_t key1[CAAM_DES_KEY_SIZE],
  1442. const uint8_t key2[CAAM_DES_KEY_SIZE]);
  1443. /*!
  1444. * @brief Decrypts triple DES using ECB block mode with two keys.
  1445. *
  1446. * Decrypts triple DES using ECB block mode with two keys.
  1447. *
  1448. * @param base CAAM peripheral base address
  1449. * @param handle Handle used for this request. Specifies jobRing.
  1450. * @param ciphertext Input ciphertext to decrypt
  1451. * @param[out] plaintext Output plaintext
  1452. * @param size Size of input and output data in bytes. Must be multiple of 8 bytes.
  1453. * @param key1 First input key for key bundle
  1454. * @param key2 Second input key for key bundle
  1455. * @return Status from encrypt/decrypt operation
  1456. */
  1457. status_t CAAM_DES2_DecryptEcb(CAAM_Type *base,
  1458. caam_handle_t *handle,
  1459. const uint8_t *ciphertext,
  1460. uint8_t *plaintext,
  1461. size_t size,
  1462. const uint8_t key1[CAAM_DES_KEY_SIZE],
  1463. const uint8_t key2[CAAM_DES_KEY_SIZE]);
  1464. /*!
  1465. * @brief Encrypts triple DES using CBC block mode with two keys.
  1466. *
  1467. * Encrypts triple DES using CBC block mode with two keys.
  1468. *
  1469. * @param base CAAM peripheral base address
  1470. * @param handle Handle used for this request. Specifies jobRing.
  1471. * @param plaintext Input plaintext to encrypt
  1472. * @param[out] ciphertext Output ciphertext
  1473. * @param size Size of input and output data in bytes
  1474. * @param iv Input initial vector to combine with the first plaintext block.
  1475. * The iv does not need to be secret, but it must be unpredictable.
  1476. * @param key1 First input key for key bundle
  1477. * @param key2 Second input key for key bundle
  1478. * @return Status from encrypt/decrypt operation
  1479. */
  1480. status_t CAAM_DES2_EncryptCbc(CAAM_Type *base,
  1481. caam_handle_t *handle,
  1482. const uint8_t *plaintext,
  1483. uint8_t *ciphertext,
  1484. size_t size,
  1485. const uint8_t iv[CAAM_DES_IV_SIZE],
  1486. const uint8_t key1[CAAM_DES_KEY_SIZE],
  1487. const uint8_t key2[CAAM_DES_KEY_SIZE]);
  1488. /*!
  1489. * @brief Decrypts triple DES using CBC block mode with two keys.
  1490. *
  1491. * Decrypts triple DES using CBC block mode with two keys.
  1492. *
  1493. * @param base CAAM peripheral base address
  1494. * @param handle Handle used for this request. Specifies jobRing.
  1495. * @param ciphertext Input ciphertext to decrypt
  1496. * @param[out] plaintext Output plaintext
  1497. * @param size Size of input and output data in bytes
  1498. * @param iv Input initial vector to combine with the first plaintext block.
  1499. * The iv does not need to be secret, but it must be unpredictable.
  1500. * @param key1 First input key for key bundle
  1501. * @param key2 Second input key for key bundle
  1502. * @return Status from encrypt/decrypt operation
  1503. */
  1504. status_t CAAM_DES2_DecryptCbc(CAAM_Type *base,
  1505. caam_handle_t *handle,
  1506. const uint8_t *ciphertext,
  1507. uint8_t *plaintext,
  1508. size_t size,
  1509. const uint8_t iv[CAAM_DES_IV_SIZE],
  1510. const uint8_t key1[CAAM_DES_KEY_SIZE],
  1511. const uint8_t key2[CAAM_DES_KEY_SIZE]);
  1512. /*!
  1513. * @brief Encrypts triple DES using CFB block mode with two keys.
  1514. *
  1515. * Encrypts triple DES using CFB block mode with two keys.
  1516. *
  1517. * @param base CAAM peripheral base address
  1518. * @param handle Handle used for this request. Specifies jobRing.
  1519. * @param plaintext Input plaintext to encrypt
  1520. * @param[out] ciphertext Output ciphertext
  1521. * @param size Size of input and output data in bytes
  1522. * @param iv Input initial block.
  1523. * @param key1 First input key for key bundle
  1524. * @param key2 Second input key for key bundle
  1525. * @return Status from encrypt/decrypt operation
  1526. */
  1527. status_t CAAM_DES2_EncryptCfb(CAAM_Type *base,
  1528. caam_handle_t *handle,
  1529. const uint8_t *plaintext,
  1530. uint8_t *ciphertext,
  1531. size_t size,
  1532. const uint8_t iv[CAAM_DES_IV_SIZE],
  1533. const uint8_t key1[CAAM_DES_KEY_SIZE],
  1534. const uint8_t key2[CAAM_DES_KEY_SIZE]);
  1535. /*!
  1536. * @brief Decrypts triple DES using CFB block mode with two keys.
  1537. *
  1538. * Decrypts triple DES using CFB block mode with two keys.
  1539. *
  1540. * @param base CAAM peripheral base address
  1541. * @param handle Handle used for this request. Specifies jobRing.
  1542. * @param ciphertext Input ciphertext to decrypt
  1543. * @param[out] plaintext Output plaintext
  1544. * @param size Size of input and output data in bytes
  1545. * @param iv Input initial block.
  1546. * @param key1 First input key for key bundle
  1547. * @param key2 Second input key for key bundle
  1548. * @return Status from encrypt/decrypt operation
  1549. */
  1550. status_t CAAM_DES2_DecryptCfb(CAAM_Type *base,
  1551. caam_handle_t *handle,
  1552. const uint8_t *ciphertext,
  1553. uint8_t *plaintext,
  1554. size_t size,
  1555. const uint8_t iv[CAAM_DES_IV_SIZE],
  1556. const uint8_t key1[CAAM_DES_KEY_SIZE],
  1557. const uint8_t key2[CAAM_DES_KEY_SIZE]);
  1558. /*!
  1559. * @brief Encrypts triple DES using OFB block mode with two keys.
  1560. *
  1561. * Encrypts triple DES using OFB block mode with two keys.
  1562. *
  1563. * @param base CAAM peripheral base address
  1564. * @param handle Handle used for this request. Specifies jobRing.
  1565. * @param plaintext Input plaintext to encrypt
  1566. * @param[out] ciphertext Output ciphertext
  1567. * @param size Size of input and output data in bytes
  1568. * @param iv Input unique input vector. The OFB mode requires that the IV be unique
  1569. * for each execution of the mode under the given key.
  1570. * @param key1 First input key for key bundle
  1571. * @param key2 Second input key for key bundle
  1572. * @return Status from encrypt/decrypt operation
  1573. */
  1574. status_t CAAM_DES2_EncryptOfb(CAAM_Type *base,
  1575. caam_handle_t *handle,
  1576. const uint8_t *plaintext,
  1577. uint8_t *ciphertext,
  1578. size_t size,
  1579. const uint8_t iv[CAAM_DES_IV_SIZE],
  1580. const uint8_t key1[CAAM_DES_KEY_SIZE],
  1581. const uint8_t key2[CAAM_DES_KEY_SIZE]);
  1582. /*!
  1583. * @brief Decrypts triple DES using OFB block mode with two keys.
  1584. *
  1585. * Decrypts triple DES using OFB block mode with two keys.
  1586. *
  1587. * @param base CAAM peripheral base address
  1588. * @param handle Handle used for this request. Specifies jobRing.
  1589. * @param ciphertext Input ciphertext to decrypt
  1590. * @param[out] plaintext Output plaintext
  1591. * @param size Size of input and output data in bytes
  1592. * @param iv Input unique input vector. The OFB mode requires that the IV be unique
  1593. * for each execution of the mode under the given key.
  1594. * @param key1 First input key for key bundle
  1595. * @param key2 Second input key for key bundle
  1596. * @return Status from encrypt/decrypt operation
  1597. */
  1598. status_t CAAM_DES2_DecryptOfb(CAAM_Type *base,
  1599. caam_handle_t *handle,
  1600. const uint8_t *ciphertext,
  1601. uint8_t *plaintext,
  1602. size_t size,
  1603. const uint8_t iv[CAAM_DES_IV_SIZE],
  1604. const uint8_t key1[CAAM_DES_KEY_SIZE],
  1605. const uint8_t key2[CAAM_DES_KEY_SIZE]);
  1606. /*!
  1607. * @brief Encrypts triple DES using ECB block mode with three keys.
  1608. *
  1609. * Encrypts triple DES using ECB block mode with three keys.
  1610. *
  1611. * @param base CAAM peripheral base address
  1612. * @param handle Handle used for this request. Specifies jobRing.
  1613. * @param plaintext Input plaintext to encrypt
  1614. * @param[out] ciphertext Output ciphertext
  1615. * @param size Size of input and output data in bytes. Must be multiple of 8 bytes.
  1616. * @param key1 First input key for key bundle
  1617. * @param key2 Second input key for key bundle
  1618. * @param key3 Third input key for key bundle
  1619. * @return Status from encrypt/decrypt operation
  1620. */
  1621. status_t CAAM_DES3_EncryptEcb(CAAM_Type *base,
  1622. caam_handle_t *handle,
  1623. const uint8_t *plaintext,
  1624. uint8_t *ciphertext,
  1625. size_t size,
  1626. const uint8_t key1[CAAM_DES_KEY_SIZE],
  1627. const uint8_t key2[CAAM_DES_KEY_SIZE],
  1628. const uint8_t key3[CAAM_DES_KEY_SIZE]);
  1629. /*!
  1630. * @brief Decrypts triple DES using ECB block mode with three keys.
  1631. *
  1632. * Decrypts triple DES using ECB block mode with three keys.
  1633. *
  1634. * @param base CAAM peripheral base address
  1635. * @param handle Handle used for this request. Specifies jobRing.
  1636. * @param ciphertext Input ciphertext to decrypt
  1637. * @param[out] plaintext Output plaintext
  1638. * @param size Size of input and output data in bytes. Must be multiple of 8 bytes.
  1639. * @param key1 First input key for key bundle
  1640. * @param key2 Second input key for key bundle
  1641. * @param key3 Third input key for key bundle
  1642. * @return Status from encrypt/decrypt operation
  1643. */
  1644. status_t CAAM_DES3_DecryptEcb(CAAM_Type *base,
  1645. caam_handle_t *handle,
  1646. const uint8_t *ciphertext,
  1647. uint8_t *plaintext,
  1648. size_t size,
  1649. const uint8_t key1[CAAM_DES_KEY_SIZE],
  1650. const uint8_t key2[CAAM_DES_KEY_SIZE],
  1651. const uint8_t key3[CAAM_DES_KEY_SIZE]);
  1652. /*!
  1653. * @brief Encrypts triple DES using CBC block mode with three keys.
  1654. *
  1655. * Encrypts triple DES using CBC block mode with three keys.
  1656. *
  1657. * @param base CAAM peripheral base address
  1658. * @param handle Handle used for this request. Specifies jobRing.
  1659. * @param plaintext Input plaintext to encrypt
  1660. * @param[out] ciphertext Output ciphertext
  1661. * @param size Size of input data in bytes
  1662. * @param iv Input initial vector to combine with the first plaintext block.
  1663. * The iv does not need to be secret, but it must be unpredictable.
  1664. * @param key1 First input key for key bundle
  1665. * @param key2 Second input key for key bundle
  1666. * @param key3 Third input key for key bundle
  1667. * @return Status from encrypt/decrypt operation
  1668. */
  1669. status_t CAAM_DES3_EncryptCbc(CAAM_Type *base,
  1670. caam_handle_t *handle,
  1671. const uint8_t *plaintext,
  1672. uint8_t *ciphertext,
  1673. size_t size,
  1674. const uint8_t iv[CAAM_DES_IV_SIZE],
  1675. const uint8_t key1[CAAM_DES_KEY_SIZE],
  1676. const uint8_t key2[CAAM_DES_KEY_SIZE],
  1677. const uint8_t key3[CAAM_DES_KEY_SIZE]);
  1678. /*!
  1679. * @brief Decrypts triple DES using CBC block mode with three keys.
  1680. *
  1681. * Decrypts triple DES using CBC block mode with three keys.
  1682. *
  1683. * @param base CAAM peripheral base address
  1684. * @param handle Handle used for this request. Specifies jobRing.
  1685. * @param ciphertext Input ciphertext to decrypt
  1686. * @param[out] plaintext Output plaintext
  1687. * @param size Size of input and output data in bytes
  1688. * @param iv Input initial vector to combine with the first plaintext block.
  1689. * The iv does not need to be secret, but it must be unpredictable.
  1690. * @param key1 First input key for key bundle
  1691. * @param key2 Second input key for key bundle
  1692. * @param key3 Third input key for key bundle
  1693. * @return Status from encrypt/decrypt operation
  1694. */
  1695. status_t CAAM_DES3_DecryptCbc(CAAM_Type *base,
  1696. caam_handle_t *handle,
  1697. const uint8_t *ciphertext,
  1698. uint8_t *plaintext,
  1699. size_t size,
  1700. const uint8_t iv[CAAM_DES_IV_SIZE],
  1701. const uint8_t key1[CAAM_DES_KEY_SIZE],
  1702. const uint8_t key2[CAAM_DES_KEY_SIZE],
  1703. const uint8_t key3[CAAM_DES_KEY_SIZE]);
  1704. /*!
  1705. * @brief Encrypts triple DES using CFB block mode with three keys.
  1706. *
  1707. * Encrypts triple DES using CFB block mode with three keys.
  1708. *
  1709. * @param base CAAM peripheral base address
  1710. * @param handle Handle used for this request. Specifies jobRing.
  1711. * @param plaintext Input plaintext to encrypt
  1712. * @param[out] ciphertext Output ciphertext
  1713. * @param size Size of input and ouput data in bytes
  1714. * @param iv Input initial block.
  1715. * @param key1 First input key for key bundle
  1716. * @param key2 Second input key for key bundle
  1717. * @param key3 Third input key for key bundle
  1718. * @return Status from encrypt/decrypt operation
  1719. */
  1720. status_t CAAM_DES3_EncryptCfb(CAAM_Type *base,
  1721. caam_handle_t *handle,
  1722. const uint8_t *plaintext,
  1723. uint8_t *ciphertext,
  1724. size_t size,
  1725. const uint8_t iv[CAAM_DES_IV_SIZE],
  1726. const uint8_t key1[CAAM_DES_KEY_SIZE],
  1727. const uint8_t key2[CAAM_DES_KEY_SIZE],
  1728. const uint8_t key3[CAAM_DES_KEY_SIZE]);
  1729. /*!
  1730. * @brief Decrypts triple DES using CFB block mode with three keys.
  1731. *
  1732. * Decrypts triple DES using CFB block mode with three keys.
  1733. *
  1734. * @param base CAAM peripheral base address
  1735. * @param handle Handle used for this request. Specifies jobRing.
  1736. * @param ciphertext Input ciphertext to decrypt
  1737. * @param[out] plaintext Output plaintext
  1738. * @param size Size of input data in bytes
  1739. * @param iv Input initial block.
  1740. * @param key1 First input key for key bundle
  1741. * @param key2 Second input key for key bundle
  1742. * @param key3 Third input key for key bundle
  1743. * @return Status from encrypt/decrypt operation
  1744. */
  1745. status_t CAAM_DES3_DecryptCfb(CAAM_Type *base,
  1746. caam_handle_t *handle,
  1747. const uint8_t *ciphertext,
  1748. uint8_t *plaintext,
  1749. size_t size,
  1750. const uint8_t iv[CAAM_DES_IV_SIZE],
  1751. const uint8_t key1[CAAM_DES_KEY_SIZE],
  1752. const uint8_t key2[CAAM_DES_KEY_SIZE],
  1753. const uint8_t key3[CAAM_DES_KEY_SIZE]);
  1754. /*!
  1755. * @brief Encrypts triple DES using OFB block mode with three keys.
  1756. *
  1757. * Encrypts triple DES using OFB block mode with three keys.
  1758. *
  1759. * @param base CAAM peripheral base address
  1760. * @param handle Handle used for this request. Specifies jobRing.
  1761. * @param plaintext Input plaintext to encrypt
  1762. * @param[out] ciphertext Output ciphertext
  1763. * @param size Size of input and output data in bytes
  1764. * @param iv Input unique input vector. The OFB mode requires that the IV be unique
  1765. * for each execution of the mode under the given key.
  1766. * @param key1 First input key for key bundle
  1767. * @param key2 Second input key for key bundle
  1768. * @param key3 Third input key for key bundle
  1769. * @return Status from encrypt/decrypt operation
  1770. */
  1771. status_t CAAM_DES3_EncryptOfb(CAAM_Type *base,
  1772. caam_handle_t *handle,
  1773. const uint8_t *plaintext,
  1774. uint8_t *ciphertext,
  1775. size_t size,
  1776. const uint8_t iv[CAAM_DES_IV_SIZE],
  1777. const uint8_t key1[CAAM_DES_KEY_SIZE],
  1778. const uint8_t key2[CAAM_DES_KEY_SIZE],
  1779. const uint8_t key3[CAAM_DES_KEY_SIZE]);
  1780. /*!
  1781. * @brief Decrypts triple DES using OFB block mode with three keys.
  1782. *
  1783. * Decrypts triple DES using OFB block mode with three keys.
  1784. *
  1785. * @param base CAAM peripheral base address
  1786. * @param handle Handle used for this request. Specifies jobRing.
  1787. * @param ciphertext Input ciphertext to decrypt
  1788. * @param[out] plaintext Output plaintext
  1789. * @param size Size of input and output data in bytes
  1790. * @param iv Input unique input vector. The OFB mode requires that the IV be unique
  1791. * for each execution of the mode under the given key.
  1792. * @param key1 First input key for key bundle
  1793. * @param key2 Second input key for key bundle
  1794. * @param key3 Third input key for key bundle
  1795. * @return Status from encrypt/decrypt operation
  1796. */
  1797. status_t CAAM_DES3_DecryptOfb(CAAM_Type *base,
  1798. caam_handle_t *handle,
  1799. const uint8_t *ciphertext,
  1800. uint8_t *plaintext,
  1801. size_t size,
  1802. const uint8_t iv[CAAM_DES_IV_SIZE],
  1803. const uint8_t key1[CAAM_DES_KEY_SIZE],
  1804. const uint8_t key2[CAAM_DES_KEY_SIZE],
  1805. const uint8_t key3[CAAM_DES_KEY_SIZE]);
  1806. /*!
  1807. *@}
  1808. */ /* end of caam_driver_des */
  1809. /*!
  1810. * @addtogroup caam_nonblocking_driver_des
  1811. * @{
  1812. */
  1813. /*!
  1814. * @brief Encrypts DES using ECB block mode.
  1815. *
  1816. * Encrypts DES using ECB block mode.
  1817. *
  1818. * @param base CAAM peripheral base address
  1819. * @param handle Handle used for this request. Specifies jobRing.
  1820. * @param[out] descriptor memory for CAAM commands
  1821. * @param plaintext Input plaintext to encrypt
  1822. * @param[out] ciphertext Output ciphertext
  1823. * @param size Size of input and output data in bytes. Must be multiple of 8 bytes.
  1824. * @param key Input key to use for encryption
  1825. * @return Status from descriptor push
  1826. */
  1827. status_t CAAM_DES_EncryptEcbNonBlocking(CAAM_Type *base,
  1828. caam_handle_t *handle,
  1829. caam_desc_cipher_des_t descriptor,
  1830. const uint8_t *plaintext,
  1831. uint8_t *ciphertext,
  1832. size_t size,
  1833. const uint8_t key[CAAM_DES_KEY_SIZE]);
  1834. /*!
  1835. * @brief Decrypts DES using ECB block mode.
  1836. *
  1837. * Decrypts DES using ECB block mode.
  1838. *
  1839. * @param base CAAM peripheral base address
  1840. * @param handle Handle used for this request. Specifies jobRing.
  1841. * @param[out] descriptor memory for CAAM commands
  1842. * @param ciphertext Input ciphertext to decrypt
  1843. * @param[out] plaintext Output plaintext
  1844. * @param size Size of input and output data in bytes. Must be multiple of 8 bytes.
  1845. * @param key Input key to use for decryption
  1846. * @return Status from descriptor push
  1847. */
  1848. status_t CAAM_DES_DecryptEcbNonBlocking(CAAM_Type *base,
  1849. caam_handle_t *handle,
  1850. caam_desc_cipher_des_t descriptor,
  1851. const uint8_t *ciphertext,
  1852. uint8_t *plaintext,
  1853. size_t size,
  1854. const uint8_t key[CAAM_DES_KEY_SIZE]);
  1855. /*!
  1856. * @brief Encrypts DES using CBC block mode.
  1857. *
  1858. * Encrypts DES using CBC block mode.
  1859. *
  1860. * @param base CAAM peripheral base address
  1861. * @param handle Handle used for this request. Specifies jobRing.
  1862. * @param[out] descriptor memory for CAAM commands
  1863. * @param plaintext Input plaintext to encrypt
  1864. * @param[out] ciphertext Ouput ciphertext
  1865. * @param size Size of input and output data in bytes
  1866. * @param iv Input initial vector to combine with the first plaintext block.
  1867. * The iv does not need to be secret, but it must be unpredictable.
  1868. * @param key Input key to use for encryption
  1869. * @return Status from descriptor push
  1870. */
  1871. status_t CAAM_DES_EncryptCbcNonBlocking(CAAM_Type *base,
  1872. caam_handle_t *handle,
  1873. caam_desc_cipher_des_t descriptor,
  1874. const uint8_t *plaintext,
  1875. uint8_t *ciphertext,
  1876. size_t size,
  1877. const uint8_t iv[CAAM_DES_IV_SIZE],
  1878. const uint8_t key[CAAM_DES_KEY_SIZE]);
  1879. /*!
  1880. * @brief Decrypts DES using CBC block mode.
  1881. *
  1882. * Decrypts DES using CBC block mode.
  1883. *
  1884. * @param base CAAM peripheral base address
  1885. * @param handle Handle used for this request. Specifies jobRing.
  1886. * @param[out] descriptor memory for CAAM commands
  1887. * @param ciphertext Input ciphertext to decrypt
  1888. * @param[out] plaintext Output plaintext
  1889. * @param size Size of input data in bytes
  1890. * @param iv Input initial vector to combine with the first plaintext block.
  1891. * The iv does not need to be secret, but it must be unpredictable.
  1892. * @param key Input key to use for decryption
  1893. * @return Status from descriptor push
  1894. */
  1895. status_t CAAM_DES_DecryptCbcNonBlocking(CAAM_Type *base,
  1896. caam_handle_t *handle,
  1897. caam_desc_cipher_des_t descriptor,
  1898. const uint8_t *ciphertext,
  1899. uint8_t *plaintext,
  1900. size_t size,
  1901. const uint8_t iv[CAAM_DES_IV_SIZE],
  1902. const uint8_t key[CAAM_DES_KEY_SIZE]);
  1903. /*!
  1904. * @brief Encrypts DES using CFB block mode.
  1905. *
  1906. * Encrypts DES using CFB block mode.
  1907. *
  1908. * @param base CAAM peripheral base address
  1909. * @param handle Handle used for this request. Specifies jobRing.
  1910. * @param[out] descriptor memory for CAAM commands
  1911. * @param plaintext Input plaintext to encrypt
  1912. * @param size Size of input data in bytes
  1913. * @param iv Input initial block.
  1914. * @param key Input key to use for encryption
  1915. * @param[out] ciphertext Output ciphertext
  1916. * @return Status from descriptor push
  1917. */
  1918. status_t CAAM_DES_EncryptCfbNonBlocking(CAAM_Type *base,
  1919. caam_handle_t *handle,
  1920. caam_desc_cipher_des_t descriptor,
  1921. const uint8_t *plaintext,
  1922. uint8_t *ciphertext,
  1923. size_t size,
  1924. const uint8_t iv[CAAM_DES_IV_SIZE],
  1925. const uint8_t key[CAAM_DES_KEY_SIZE]);
  1926. /*!
  1927. * @brief Decrypts DES using CFB block mode.
  1928. *
  1929. * Decrypts DES using CFB block mode.
  1930. *
  1931. * @param base CAAM peripheral base address
  1932. * @param handle Handle used for this request. Specifies jobRing.
  1933. * @param[out] descriptor memory for CAAM commands
  1934. * @param ciphertext Input ciphertext to decrypt
  1935. * @param[out] plaintext Output plaintext
  1936. * @param size Size of input and output data in bytes
  1937. * @param iv Input initial block.
  1938. * @param key Input key to use for decryption
  1939. * @return Status from descriptor push
  1940. */
  1941. status_t CAAM_DES_DecryptCfbNonBlocking(CAAM_Type *base,
  1942. caam_handle_t *handle,
  1943. caam_desc_cipher_des_t descriptor,
  1944. const uint8_t *ciphertext,
  1945. uint8_t *plaintext,
  1946. size_t size,
  1947. const uint8_t iv[CAAM_DES_IV_SIZE],
  1948. const uint8_t key[CAAM_DES_KEY_SIZE]);
  1949. /*!
  1950. * @brief Encrypts DES using OFB block mode.
  1951. *
  1952. * Encrypts DES using OFB block mode.
  1953. *
  1954. * @param base CAAM peripheral base address
  1955. * @param handle Handle used for this request. Specifies jobRing.
  1956. * @param[out] descriptor memory for CAAM commands
  1957. * @param plaintext Input plaintext to encrypt
  1958. * @param[out] ciphertext Output ciphertext
  1959. * @param size Size of input and output data in bytes
  1960. * @param iv Input unique input vector. The OFB mode requires that the IV be unique
  1961. * for each execution of the mode under the given key.
  1962. * @param key Input key to use for encryption
  1963. * @return Status from descriptor push
  1964. */
  1965. status_t CAAM_DES_EncryptOfbNonBlocking(CAAM_Type *base,
  1966. caam_handle_t *handle,
  1967. caam_desc_cipher_des_t descriptor,
  1968. const uint8_t *plaintext,
  1969. uint8_t *ciphertext,
  1970. size_t size,
  1971. const uint8_t iv[CAAM_DES_IV_SIZE],
  1972. const uint8_t key[CAAM_DES_KEY_SIZE]);
  1973. /*!
  1974. * @brief Decrypts DES using OFB block mode.
  1975. *
  1976. * Decrypts DES using OFB block mode.
  1977. *
  1978. * @param base CAAM peripheral base address
  1979. * @param handle Handle used for this request. Specifies jobRing.
  1980. * @param[out] descriptor memory for CAAM commands
  1981. * @param ciphertext Input ciphertext to decrypt
  1982. * @param[out] plaintext Output plaintext
  1983. * @param size Size of input and output data in bytes. Must be multiple of 8 bytes.
  1984. * @param iv Input unique input vector. The OFB mode requires that the IV be unique
  1985. * for each execution of the mode under the given key.
  1986. * @param key Input key to use for decryption
  1987. * @return Status from descriptor push
  1988. */
  1989. status_t CAAM_DES_DecryptOfbNonBlocking(CAAM_Type *base,
  1990. caam_handle_t *handle,
  1991. caam_desc_cipher_des_t descriptor,
  1992. const uint8_t *ciphertext,
  1993. uint8_t *plaintext,
  1994. size_t size,
  1995. const uint8_t iv[CAAM_DES_IV_SIZE],
  1996. const uint8_t key[CAAM_DES_KEY_SIZE]);
  1997. /*!
  1998. * @brief Encrypts triple DES using ECB block mode with two keys.
  1999. *
  2000. * Encrypts triple DES using ECB block mode with two keys.
  2001. *
  2002. * @param base CAAM peripheral base address
  2003. * @param handle Handle used for this request. Specifies jobRing.
  2004. * @param[out] descriptor memory for CAAM commands
  2005. * @param plaintext Input plaintext to encrypt
  2006. * @param[out] ciphertext Output ciphertext
  2007. * @param size Size of input and output data in bytes. Must be multiple of 8 bytes.
  2008. * @param key1 First input key for key bundle
  2009. * @param key2 Second input key for key bundle
  2010. * @return Status from descriptor push
  2011. */
  2012. status_t CAAM_DES2_EncryptEcbNonBlocking(CAAM_Type *base,
  2013. caam_handle_t *handle,
  2014. caam_desc_cipher_des_t descriptor,
  2015. const uint8_t *plaintext,
  2016. uint8_t *ciphertext,
  2017. size_t size,
  2018. const uint8_t key1[CAAM_DES_KEY_SIZE],
  2019. const uint8_t key2[CAAM_DES_KEY_SIZE]);
  2020. /*!
  2021. * @brief Decrypts triple DES using ECB block mode with two keys.
  2022. *
  2023. * Decrypts triple DES using ECB block mode with two keys.
  2024. *
  2025. * @param base CAAM peripheral base address
  2026. * @param handle Handle used for this request. Specifies jobRing.
  2027. * @param[out] descriptor memory for CAAM commands
  2028. * @param ciphertext Input ciphertext to decrypt
  2029. * @param[out] plaintext Output plaintext
  2030. * @param size Size of input and output data in bytes. Must be multiple of 8 bytes.
  2031. * @param key1 First input key for key bundle
  2032. * @param key2 Second input key for key bundle
  2033. * @return Status from descriptor push
  2034. */
  2035. status_t CAAM_DES2_DecryptEcbNonBlocking(CAAM_Type *base,
  2036. caam_handle_t *handle,
  2037. caam_desc_cipher_des_t descriptor,
  2038. const uint8_t *ciphertext,
  2039. uint8_t *plaintext,
  2040. size_t size,
  2041. const uint8_t key1[CAAM_DES_KEY_SIZE],
  2042. const uint8_t key2[CAAM_DES_KEY_SIZE]);
  2043. /*!
  2044. * @brief Encrypts triple DES using CBC block mode with two keys.
  2045. *
  2046. * Encrypts triple DES using CBC block mode with two keys.
  2047. *
  2048. * @param base CAAM peripheral base address
  2049. * @param handle Handle used for this request. Specifies jobRing.
  2050. * @param[out] descriptor memory for CAAM commands
  2051. * @param plaintext Input plaintext to encrypt
  2052. * @param[out] ciphertext Output ciphertext
  2053. * @param size Size of input and output data in bytes
  2054. * @param iv Input initial vector to combine with the first plaintext block.
  2055. * The iv does not need to be secret, but it must be unpredictable.
  2056. * @param key1 First input key for key bundle
  2057. * @param key2 Second input key for key bundle
  2058. * @return Status from descriptor push
  2059. */
  2060. status_t CAAM_DES2_EncryptCbcNonBlocking(CAAM_Type *base,
  2061. caam_handle_t *handle,
  2062. caam_desc_cipher_des_t descriptor,
  2063. const uint8_t *plaintext,
  2064. uint8_t *ciphertext,
  2065. size_t size,
  2066. const uint8_t iv[CAAM_DES_IV_SIZE],
  2067. const uint8_t key1[CAAM_DES_KEY_SIZE],
  2068. const uint8_t key2[CAAM_DES_KEY_SIZE]);
  2069. /*!
  2070. * @brief Decrypts triple DES using CBC block mode with two keys.
  2071. *
  2072. * Decrypts triple DES using CBC block mode with two keys.
  2073. *
  2074. * @param base CAAM peripheral base address
  2075. * @param handle Handle used for this request. Specifies jobRing.
  2076. * @param[out] descriptor memory for CAAM commands
  2077. * @param ciphertext Input ciphertext to decrypt
  2078. * @param[out] plaintext Output plaintext
  2079. * @param size Size of input and output data in bytes
  2080. * @param iv Input initial vector to combine with the first plaintext block.
  2081. * The iv does not need to be secret, but it must be unpredictable.
  2082. * @param key1 First input key for key bundle
  2083. * @param key2 Second input key for key bundle
  2084. * @return Status from descriptor push
  2085. */
  2086. status_t CAAM_DES2_DecryptCbcNonBlocking(CAAM_Type *base,
  2087. caam_handle_t *handle,
  2088. caam_desc_cipher_des_t descriptor,
  2089. const uint8_t *ciphertext,
  2090. uint8_t *plaintext,
  2091. size_t size,
  2092. const uint8_t iv[CAAM_DES_IV_SIZE],
  2093. const uint8_t key1[CAAM_DES_KEY_SIZE],
  2094. const uint8_t key2[CAAM_DES_KEY_SIZE]);
  2095. /*!
  2096. * @brief Encrypts triple DES using CFB block mode with two keys.
  2097. *
  2098. * Encrypts triple DES using CFB block mode with two keys.
  2099. *
  2100. * @param base CAAM peripheral base address
  2101. * @param handle Handle used for this request. Specifies jobRing.
  2102. * @param[out] descriptor memory for CAAM commands
  2103. * @param plaintext Input plaintext to encrypt
  2104. * @param[out] ciphertext Output ciphertext
  2105. * @param size Size of input and output data in bytes
  2106. * @param iv Input initial block.
  2107. * @param key1 First input key for key bundle
  2108. * @param key2 Second input key for key bundle
  2109. * @return Status from descriptor push
  2110. */
  2111. status_t CAAM_DES2_EncryptCfbNonBlocking(CAAM_Type *base,
  2112. caam_handle_t *handle,
  2113. caam_desc_cipher_des_t descriptor,
  2114. const uint8_t *plaintext,
  2115. uint8_t *ciphertext,
  2116. size_t size,
  2117. const uint8_t iv[CAAM_DES_IV_SIZE],
  2118. const uint8_t key1[CAAM_DES_KEY_SIZE],
  2119. const uint8_t key2[CAAM_DES_KEY_SIZE]);
  2120. /*!
  2121. * @brief Decrypts triple DES using CFB block mode with two keys.
  2122. *
  2123. * Decrypts triple DES using CFB block mode with two keys.
  2124. *
  2125. * @param base CAAM peripheral base address
  2126. * @param handle Handle used for this request. Specifies jobRing.
  2127. * @param[out] descriptor memory for CAAM commands
  2128. * @param ciphertext Input ciphertext to decrypt
  2129. * @param[out] plaintext Output plaintext
  2130. * @param size Size of input and output data in bytes
  2131. * @param iv Input initial block.
  2132. * @param key1 First input key for key bundle
  2133. * @param key2 Second input key for key bundle
  2134. * @return Status from descriptor push
  2135. */
  2136. status_t CAAM_DES2_DecryptCfbNonBlocking(CAAM_Type *base,
  2137. caam_handle_t *handle,
  2138. caam_desc_cipher_des_t descriptor,
  2139. const uint8_t *ciphertext,
  2140. uint8_t *plaintext,
  2141. size_t size,
  2142. const uint8_t iv[CAAM_DES_IV_SIZE],
  2143. const uint8_t key1[CAAM_DES_KEY_SIZE],
  2144. const uint8_t key2[CAAM_DES_KEY_SIZE]);
  2145. /*!
  2146. * @brief Encrypts triple DES using OFB block mode with two keys.
  2147. *
  2148. * Encrypts triple DES using OFB block mode with two keys.
  2149. *
  2150. * @param base CAAM peripheral base address
  2151. * @param handle Handle used for this request. Specifies jobRing.
  2152. * @param[out] descriptor memory for CAAM commands
  2153. * @param plaintext Input plaintext to encrypt
  2154. * @param[out] ciphertext Output ciphertext
  2155. * @param size Size of input and output data in bytes
  2156. * @param iv Input unique input vector. The OFB mode requires that the IV be unique
  2157. * for each execution of the mode under the given key.
  2158. * @param key1 First input key for key bundle
  2159. * @param key2 Second input key for key bundle
  2160. * @return Status from descriptor push
  2161. */
  2162. status_t CAAM_DES2_EncryptOfbNonBlocking(CAAM_Type *base,
  2163. caam_handle_t *handle,
  2164. caam_desc_cipher_des_t descriptor,
  2165. const uint8_t *plaintext,
  2166. uint8_t *ciphertext,
  2167. size_t size,
  2168. const uint8_t iv[CAAM_DES_IV_SIZE],
  2169. const uint8_t key1[CAAM_DES_KEY_SIZE],
  2170. const uint8_t key2[CAAM_DES_KEY_SIZE]);
  2171. /*!
  2172. * @brief Decrypts triple DES using OFB block mode with two keys.
  2173. *
  2174. * Decrypts triple DES using OFB block mode with two keys.
  2175. *
  2176. * @param base CAAM peripheral base address
  2177. * @param handle Handle used for this request. Specifies jobRing.
  2178. * @param[out] descriptor memory for CAAM commands
  2179. * @param ciphertext Input ciphertext to decrypt
  2180. * @param[out] plaintext Output plaintext
  2181. * @param size Size of input and output data in bytes
  2182. * @param iv Input unique input vector. The OFB mode requires that the IV be unique
  2183. * for each execution of the mode under the given key.
  2184. * @param key1 First input key for key bundle
  2185. * @param key2 Second input key for key bundle
  2186. * @return Status from descriptor push
  2187. */
  2188. status_t CAAM_DES2_DecryptOfbNonBlocking(CAAM_Type *base,
  2189. caam_handle_t *handle,
  2190. caam_desc_cipher_des_t descriptor,
  2191. const uint8_t *ciphertext,
  2192. uint8_t *plaintext,
  2193. size_t size,
  2194. const uint8_t iv[CAAM_DES_IV_SIZE],
  2195. const uint8_t key1[CAAM_DES_KEY_SIZE],
  2196. const uint8_t key2[CAAM_DES_KEY_SIZE]);
  2197. /*!
  2198. * @brief Encrypts triple DES using ECB block mode with three keys.
  2199. *
  2200. * Encrypts triple DES using ECB block mode with three keys.
  2201. *
  2202. * @param base CAAM peripheral base address
  2203. * @param handle Handle used for this request. Specifies jobRing.
  2204. * @param[out] descriptor memory for CAAM commands
  2205. * @param plaintext Input plaintext to encrypt
  2206. * @param[out] ciphertext Output ciphertext
  2207. * @param size Size of input and output data in bytes. Must be multiple of 8 bytes.
  2208. * @param key1 First input key for key bundle
  2209. * @param key2 Second input key for key bundle
  2210. * @param key3 Third input key for key bundle
  2211. * @return Status from descriptor push
  2212. */
  2213. status_t CAAM_DES3_EncryptEcbNonBlocking(CAAM_Type *base,
  2214. caam_handle_t *handle,
  2215. caam_desc_cipher_des_t descriptor,
  2216. const uint8_t *plaintext,
  2217. uint8_t *ciphertext,
  2218. size_t size,
  2219. const uint8_t key1[CAAM_DES_KEY_SIZE],
  2220. const uint8_t key2[CAAM_DES_KEY_SIZE],
  2221. const uint8_t key3[CAAM_DES_KEY_SIZE]);
  2222. /*!
  2223. * @brief Decrypts triple DES using ECB block mode with three keys.
  2224. *
  2225. * Decrypts triple DES using ECB block mode with three keys.
  2226. *
  2227. * @param base CAAM peripheral base address
  2228. * @param handle Handle used for this request. Specifies jobRing.
  2229. * @param[out] descriptor memory for CAAM commands
  2230. * @param ciphertext Input ciphertext to decrypt
  2231. * @param[out] plaintext Output plaintext
  2232. * @param size Size of input and output data in bytes. Must be multiple of 8 bytes.
  2233. * @param key1 First input key for key bundle
  2234. * @param key2 Second input key for key bundle
  2235. * @param key3 Third input key for key bundle
  2236. * @return Status from descriptor push
  2237. */
  2238. status_t CAAM_DES3_DecryptEcbNonBlocking(CAAM_Type *base,
  2239. caam_handle_t *handle,
  2240. caam_desc_cipher_des_t descriptor,
  2241. const uint8_t *ciphertext,
  2242. uint8_t *plaintext,
  2243. size_t size,
  2244. const uint8_t key1[CAAM_DES_KEY_SIZE],
  2245. const uint8_t key2[CAAM_DES_KEY_SIZE],
  2246. const uint8_t key3[CAAM_DES_KEY_SIZE]);
  2247. /*!
  2248. * @brief Encrypts triple DES using CBC block mode with three keys.
  2249. *
  2250. * Encrypts triple DES using CBC block mode with three keys.
  2251. *
  2252. * @param base CAAM peripheral base address
  2253. * @param handle Handle used for this request. Specifies jobRing.
  2254. * @param[out] descriptor memory for CAAM commands
  2255. * @param plaintext Input plaintext to encrypt
  2256. * @param[out] ciphertext Output ciphertext
  2257. * @param size Size of input data in bytes
  2258. * @param iv Input initial vector to combine with the first plaintext block.
  2259. * The iv does not need to be secret, but it must be unpredictable.
  2260. * @param key1 First input key for key bundle
  2261. * @param key2 Second input key for key bundle
  2262. * @param key3 Third input key for key bundle
  2263. * @return Status from descriptor push
  2264. */
  2265. status_t CAAM_DES3_EncryptCbcNonBlocking(CAAM_Type *base,
  2266. caam_handle_t *handle,
  2267. caam_desc_cipher_des_t descriptor,
  2268. const uint8_t *plaintext,
  2269. uint8_t *ciphertext,
  2270. size_t size,
  2271. const uint8_t iv[CAAM_DES_IV_SIZE],
  2272. const uint8_t key1[CAAM_DES_KEY_SIZE],
  2273. const uint8_t key2[CAAM_DES_KEY_SIZE],
  2274. const uint8_t key3[CAAM_DES_KEY_SIZE]);
  2275. /*!
  2276. * @brief Decrypts triple DES using CBC block mode with three keys.
  2277. *
  2278. * Decrypts triple DES using CBC block mode with three keys.
  2279. *
  2280. * @param base CAAM peripheral base address
  2281. * @param handle Handle used for this request. Specifies jobRing.
  2282. * @param[out] descriptor memory for CAAM commands
  2283. * @param ciphertext Input ciphertext to decrypt
  2284. * @param[out] plaintext Output plaintext
  2285. * @param size Size of input and output data in bytes
  2286. * @param iv Input initial vector to combine with the first plaintext block.
  2287. * The iv does not need to be secret, but it must be unpredictable.
  2288. * @param key1 First input key for key bundle
  2289. * @param key2 Second input key for key bundle
  2290. * @param key3 Third input key for key bundle
  2291. * @return Status from descriptor push
  2292. */
  2293. status_t CAAM_DES3_DecryptCbcNonBlocking(CAAM_Type *base,
  2294. caam_handle_t *handle,
  2295. caam_desc_cipher_des_t descriptor,
  2296. const uint8_t *ciphertext,
  2297. uint8_t *plaintext,
  2298. size_t size,
  2299. const uint8_t iv[CAAM_DES_IV_SIZE],
  2300. const uint8_t key1[CAAM_DES_KEY_SIZE],
  2301. const uint8_t key2[CAAM_DES_KEY_SIZE],
  2302. const uint8_t key3[CAAM_DES_KEY_SIZE]);
  2303. /*!
  2304. * @brief Encrypts triple DES using CFB block mode with three keys.
  2305. *
  2306. * Encrypts triple DES using CFB block mode with three keys.
  2307. *
  2308. * @param base CAAM peripheral base address
  2309. * @param handle Handle used for this request. Specifies jobRing.
  2310. * @param[out] descriptor memory for CAAM commands
  2311. * @param plaintext Input plaintext to encrypt
  2312. * @param[out] ciphertext Output ciphertext
  2313. * @param size Size of input and ouput data in bytes
  2314. * @param iv Input initial block.
  2315. * @param key1 First input key for key bundle
  2316. * @param key2 Second input key for key bundle
  2317. * @param key3 Third input key for key bundle
  2318. * @return Status from descriptor push
  2319. */
  2320. status_t CAAM_DES3_EncryptCfbNonBlocking(CAAM_Type *base,
  2321. caam_handle_t *handle,
  2322. caam_desc_cipher_des_t descriptor,
  2323. const uint8_t *plaintext,
  2324. uint8_t *ciphertext,
  2325. size_t size,
  2326. const uint8_t iv[CAAM_DES_IV_SIZE],
  2327. const uint8_t key1[CAAM_DES_KEY_SIZE],
  2328. const uint8_t key2[CAAM_DES_KEY_SIZE],
  2329. const uint8_t key3[CAAM_DES_KEY_SIZE]);
  2330. /*!
  2331. * @brief Decrypts triple DES using CFB block mode with three keys.
  2332. *
  2333. * Decrypts triple DES using CFB block mode with three keys.
  2334. *
  2335. * @param base CAAM peripheral base address
  2336. * @param handle Handle used for this request. Specifies jobRing.
  2337. * @param[out] descriptor memory for CAAM commands
  2338. * @param ciphertext Input ciphertext to decrypt
  2339. * @param[out] plaintext Output plaintext
  2340. * @param size Size of input data in bytes
  2341. * @param iv Input initial block.
  2342. * @param key1 First input key for key bundle
  2343. * @param key2 Second input key for key bundle
  2344. * @param key3 Third input key for key bundle
  2345. * @return Status from descriptor push
  2346. */
  2347. status_t CAAM_DES3_DecryptCfbNonBlocking(CAAM_Type *base,
  2348. caam_handle_t *handle,
  2349. caam_desc_cipher_des_t descriptor,
  2350. const uint8_t *ciphertext,
  2351. uint8_t *plaintext,
  2352. size_t size,
  2353. const uint8_t iv[CAAM_DES_IV_SIZE],
  2354. const uint8_t key1[CAAM_DES_KEY_SIZE],
  2355. const uint8_t key2[CAAM_DES_KEY_SIZE],
  2356. const uint8_t key3[CAAM_DES_KEY_SIZE]);
  2357. /*!
  2358. * @brief Encrypts triple DES using OFB block mode with three keys.
  2359. *
  2360. * Encrypts triple DES using OFB block mode with three keys.
  2361. *
  2362. * @param base CAAM peripheral base address
  2363. * @param handle Handle used for this request. Specifies jobRing.
  2364. * @param[out] descriptor memory for CAAM commands
  2365. * @param plaintext Input plaintext to encrypt
  2366. * @param[out] ciphertext Output ciphertext
  2367. * @param size Size of input and output data in bytes
  2368. * @param iv Input unique input vector. The OFB mode requires that the IV be unique
  2369. * for each execution of the mode under the given key.
  2370. * @param key1 First input key for key bundle
  2371. * @param key2 Second input key for key bundle
  2372. * @param key3 Third input key for key bundle
  2373. * @return Status from descriptor push
  2374. */
  2375. status_t CAAM_DES3_EncryptOfbNonBlocking(CAAM_Type *base,
  2376. caam_handle_t *handle,
  2377. caam_desc_cipher_des_t descriptor,
  2378. const uint8_t *plaintext,
  2379. uint8_t *ciphertext,
  2380. size_t size,
  2381. const uint8_t iv[CAAM_DES_IV_SIZE],
  2382. const uint8_t key1[CAAM_DES_KEY_SIZE],
  2383. const uint8_t key2[CAAM_DES_KEY_SIZE],
  2384. const uint8_t key3[CAAM_DES_KEY_SIZE]);
  2385. /*!
  2386. * @brief Decrypts triple DES using OFB block mode with three keys.
  2387. *
  2388. * Decrypts triple DES using OFB block mode with three keys.
  2389. *
  2390. * @param base CAAM peripheral base address
  2391. * @param handle Handle used for this request. Specifies jobRing.
  2392. * @param[out] descriptor memory for CAAM commands
  2393. * @param ciphertext Input ciphertext to decrypt
  2394. * @param[out] plaintext Output plaintext
  2395. * @param size Size of input and output data in bytes
  2396. * @param iv Input unique input vector. The OFB mode requires that the IV be unique
  2397. * for each execution of the mode under the given key.
  2398. * @param key1 First input key for key bundle
  2399. * @param key2 Second input key for key bundle
  2400. * @param key3 Third input key for key bundle
  2401. * @return Status from descriptor push
  2402. */
  2403. status_t CAAM_DES3_DecryptOfbNonBlocking(CAAM_Type *base,
  2404. caam_handle_t *handle,
  2405. caam_desc_cipher_des_t descriptor,
  2406. const uint8_t *ciphertext,
  2407. uint8_t *plaintext,
  2408. size_t size,
  2409. const uint8_t iv[CAAM_DES_IV_SIZE],
  2410. const uint8_t key1[CAAM_DES_KEY_SIZE],
  2411. const uint8_t key2[CAAM_DES_KEY_SIZE],
  2412. const uint8_t key3[CAAM_DES_KEY_SIZE]);
  2413. /*!
  2414. *@}
  2415. */ /* end of caam_nonblocking_driver_des */
  2416. /*!
  2417. * @addtogroup caam_driver_pkha
  2418. * @{
  2419. */
  2420. int CAAM_PKHA_CompareBigNum(const uint8_t *a, size_t sizeA, const uint8_t *b, size_t sizeB);
  2421. /*!
  2422. * @brief Converts from integer to Montgomery format.
  2423. *
  2424. * This function computes R2 mod N and optionally converts A or B into Montgomery format of A or B.
  2425. *
  2426. * @param base CAAM peripheral base address
  2427. * @param handle Handle used for this request. Specifies jobRing.
  2428. * @param N modulus
  2429. * @param sizeN size of N in bytes
  2430. * @param[in,out] A The first input in non-Montgomery format. Output Montgomery format of the first input.
  2431. * @param[in,out] sizeA pointer to size variable. On input it holds size of input A in bytes. On output it holds size of
  2432. * Montgomery format of A in bytes.
  2433. * @param[in,out] B Second input in non-Montgomery format. Output Montgomery format of the second input.
  2434. * @param[in,out] sizeB pointer to size variable. On input it holds size of input B in bytes. On output it holds size of
  2435. * Montgomery format of B in bytes.
  2436. * @param[out] R2 Output Montgomery factor R2 mod N.
  2437. * @param[out] sizeR2 pointer to size variable. On output it holds size of Montgomery factor R2 mod N in bytes.
  2438. * @param equalTime Run the function time equalized or no timing equalization.
  2439. * @param arithType Type of arithmetic to perform (integer or F2m)
  2440. * @return Operation status.
  2441. */
  2442. status_t CAAM_PKHA_NormalToMontgomery(CAAM_Type *base,
  2443. caam_handle_t *handle,
  2444. const uint8_t *N,
  2445. size_t sizeN,
  2446. uint8_t *A,
  2447. size_t *sizeA,
  2448. uint8_t *B,
  2449. size_t *sizeB,
  2450. uint8_t *R2,
  2451. size_t *sizeR2,
  2452. caam_pkha_timing_t equalTime,
  2453. caam_pkha_f2m_t arithType);
  2454. /*!
  2455. * @brief Converts from Montgomery format to int.
  2456. *
  2457. * This function converts Montgomery format of A or B into int A or B.
  2458. *
  2459. * @param base CAAM peripheral base address
  2460. * @param handle Handle used for this request. Specifies jobRing.
  2461. * @param N modulus.
  2462. * @param sizeN size of N modulus in bytes.
  2463. * @param[in,out] A Input first number in Montgomery format. Output is non-Montgomery format.
  2464. * @param[in,out] sizeA pointer to size variable. On input it holds size of the input A in bytes. On output it holds
  2465. * size of non-Montgomery A in bytes.
  2466. * @param[in,out] B Input first number in Montgomery format. Output is non-Montgomery format.
  2467. * @param[in,out] sizeB pointer to size variable. On input it holds size of the input B in bytes. On output it holds
  2468. * size of non-Montgomery B in bytes.
  2469. * @param equalTime Run the function time equalized or no timing equalization.
  2470. * @param arithType Type of arithmetic to perform (integer or F2m)
  2471. * @return Operation status.
  2472. */
  2473. status_t CAAM_PKHA_MontgomeryToNormal(CAAM_Type *base,
  2474. caam_handle_t *handle,
  2475. const uint8_t *N,
  2476. size_t sizeN,
  2477. uint8_t *A,
  2478. size_t *sizeA,
  2479. uint8_t *B,
  2480. size_t *sizeB,
  2481. caam_pkha_timing_t equalTime,
  2482. caam_pkha_f2m_t arithType);
  2483. /*!
  2484. * @brief Performs modular addition - (A + B) mod N.
  2485. *
  2486. * This function performs modular addition of (A + B) mod N, with either
  2487. * integer or binary polynomial (F2m) inputs. In the F2m form, this function is
  2488. * equivalent to a bitwise XOR and it is functionally the same as subtraction.
  2489. *
  2490. * @param base CAAM peripheral base address
  2491. * @param handle Handle used for this request. Specifies jobRing.
  2492. * @param A first addend (integer or binary polynomial)
  2493. * @param sizeA Size of A in bytes
  2494. * @param B second addend (integer or binary polynomial)
  2495. * @param sizeB Size of B in bytes
  2496. * @param N modulus.
  2497. * @param sizeN Size of N in bytes.
  2498. * @param[out] result Output array to store result of operation
  2499. * @param[out] resultSize Output size of operation in bytes
  2500. * @param arithType Type of arithmetic to perform (integer or F2m)
  2501. * @return Operation status.
  2502. */
  2503. status_t CAAM_PKHA_ModAdd(CAAM_Type *base,
  2504. caam_handle_t *handle,
  2505. const uint8_t *A,
  2506. size_t sizeA,
  2507. const uint8_t *B,
  2508. size_t sizeB,
  2509. const uint8_t *N,
  2510. size_t sizeN,
  2511. uint8_t *result,
  2512. size_t *resultSize,
  2513. caam_pkha_f2m_t arithType);
  2514. /*!
  2515. * @brief Performs modular subtraction - (A - B) mod N.
  2516. *
  2517. * This function performs modular subtraction of (A - B) mod N with
  2518. * integer inputs.
  2519. *
  2520. * @param base CAAM peripheral base address
  2521. * @param handle Handle used for this request. Specifies jobRing.
  2522. * @param A first addend (integer or binary polynomial)
  2523. * @param sizeA Size of A in bytes
  2524. * @param B second addend (integer or binary polynomial)
  2525. * @param sizeB Size of B in bytes
  2526. * @param N modulus
  2527. * @param sizeN Size of N in bytes
  2528. * @param[out] result Output array to store result of operation
  2529. * @param[out] resultSize Output size of operation in bytes
  2530. * @return Operation status.
  2531. */
  2532. status_t CAAM_PKHA_ModSub1(CAAM_Type *base,
  2533. caam_handle_t *handle,
  2534. const uint8_t *A,
  2535. size_t sizeA,
  2536. const uint8_t *B,
  2537. size_t sizeB,
  2538. const uint8_t *N,
  2539. size_t sizeN,
  2540. uint8_t *result,
  2541. size_t *resultSize);
  2542. /*!
  2543. * @brief Performs modular subtraction - (B - A) mod N.
  2544. *
  2545. * This function performs modular subtraction of (B - A) mod N,
  2546. * with integer inputs.
  2547. *
  2548. * @param base CAAM peripheral base address
  2549. * @param handle Handle used for this request. Specifies jobRing.
  2550. * @param A first addend (integer or binary polynomial)
  2551. * @param sizeA Size of A in bytes
  2552. * @param B second addend (integer or binary polynomial)
  2553. * @param sizeB Size of B in bytes
  2554. * @param N modulus
  2555. * @param sizeN Size of N in bytes
  2556. * @param[out] result Output array to store result of operation
  2557. * @param[out] resultSize Output size of operation in bytes
  2558. * @return Operation status.
  2559. */
  2560. status_t CAAM_PKHA_ModSub2(CAAM_Type *base,
  2561. caam_handle_t *handle,
  2562. const uint8_t *A,
  2563. size_t sizeA,
  2564. const uint8_t *B,
  2565. size_t sizeB,
  2566. const uint8_t *N,
  2567. size_t sizeN,
  2568. uint8_t *result,
  2569. size_t *resultSize);
  2570. /*!
  2571. * @brief Performs modular multiplication - (A x B) mod N.
  2572. *
  2573. * This function performs modular multiplication with either integer or
  2574. * binary polynomial (F2m) inputs. It can optionally specify whether inputs
  2575. * and/or outputs will be in Montgomery form or not.
  2576. *
  2577. * @param base CAAM peripheral base address
  2578. * @param handle Handle used for this request. Specifies jobRing.
  2579. * @param A first addend (integer or binary polynomial)
  2580. * @param sizeA Size of A in bytes
  2581. * @param B second addend (integer or binary polynomial)
  2582. * @param sizeB Size of B in bytes
  2583. * @param N modulus.
  2584. * @param sizeN Size of N in bytes
  2585. * @param[out] result Output array to store result of operation
  2586. * @param[out] resultSize Output size of operation in bytes
  2587. * @param arithType Type of arithmetic to perform (integer or F2m)
  2588. * @param montIn Format of inputs
  2589. * @param montOut Format of output
  2590. * @param equalTime Run the function time equalized or no timing equalization. This argument is ignored for F2m modular
  2591. * multiplication.
  2592. * @return Operation status.
  2593. */
  2594. status_t CAAM_PKHA_ModMul(CAAM_Type *base,
  2595. caam_handle_t *handle,
  2596. const uint8_t *A,
  2597. size_t sizeA,
  2598. const uint8_t *B,
  2599. size_t sizeB,
  2600. const uint8_t *N,
  2601. size_t sizeN,
  2602. uint8_t *result,
  2603. size_t *resultSize,
  2604. caam_pkha_f2m_t arithType,
  2605. caam_pkha_montgomery_form_t montIn,
  2606. caam_pkha_montgomery_form_t montOut,
  2607. caam_pkha_timing_t equalTime);
  2608. /*!
  2609. * @brief Performs modular exponentiation - (A^E) mod N.
  2610. *
  2611. * This function performs modular exponentiation with either integer or
  2612. * binary polynomial (F2m) inputs.
  2613. *
  2614. * @param base CAAM peripheral base address
  2615. * @param handle Handle used for this request. Specifies jobRing.
  2616. * @param A first addend (integer or binary polynomial)
  2617. * @param sizeA Size of A in bytes
  2618. * @param N modulus
  2619. * @param sizeN Size of N in bytes
  2620. * @param E exponent
  2621. * @param sizeE Size of E in bytes
  2622. * @param[out] result Output array to store result of operation
  2623. * @param[out] resultSize Output size of operation in bytes
  2624. * @param montIn Format of A input (normal or Montgomery)
  2625. * @param arithType Type of arithmetic to perform (integer or F2m)
  2626. * @param equalTime Run the function time equalized or no timing equalization.
  2627. * @return Operation status.
  2628. */
  2629. status_t CAAM_PKHA_ModExp(CAAM_Type *base,
  2630. caam_handle_t *handle,
  2631. const uint8_t *A,
  2632. size_t sizeA,
  2633. const uint8_t *N,
  2634. size_t sizeN,
  2635. const uint8_t *E,
  2636. size_t sizeE,
  2637. uint8_t *result,
  2638. size_t *resultSize,
  2639. caam_pkha_f2m_t arithType,
  2640. caam_pkha_montgomery_form_t montIn,
  2641. caam_pkha_timing_t equalTime);
  2642. /*!
  2643. * @brief Performs modular reduction - (A) mod N.
  2644. *
  2645. * This function performs modular reduction with either integer or
  2646. * binary polynomial (F2m) inputs.
  2647. *
  2648. * @param base CAAM peripheral base address
  2649. * @param handle Handle used for this request. Specifies jobRing.
  2650. * @param A first addend (integer or binary polynomial)
  2651. * @param sizeA Size of A in bytes
  2652. * @param N modulus
  2653. * @param sizeN Size of N in bytes
  2654. * @param[out] result Output array to store result of operation
  2655. * @param[out] resultSize Output size of operation in bytes
  2656. * @param arithType Type of arithmetic to perform (integer or F2m)
  2657. * @return Operation status.
  2658. */
  2659. status_t CAAM_PKHA_ModRed(CAAM_Type *base,
  2660. caam_handle_t *handle,
  2661. const uint8_t *A,
  2662. size_t sizeA,
  2663. const uint8_t *N,
  2664. size_t sizeN,
  2665. uint8_t *result,
  2666. size_t *resultSize,
  2667. caam_pkha_f2m_t arithType);
  2668. /*!
  2669. * @brief Performs modular inversion - (A^-1) mod N.
  2670. *
  2671. * This function performs modular inversion with either integer or
  2672. * binary polynomial (F2m) inputs.
  2673. *
  2674. * @param base CAAM peripheral base address
  2675. * @param handle Handle used for this request. Specifies jobRing.
  2676. * @param A first addend (integer or binary polynomial)
  2677. * @param sizeA Size of A in bytes
  2678. * @param N modulus
  2679. * @param sizeN Size of N in bytes
  2680. * @param[out] result Output array to store result of operation
  2681. * @param[out] resultSize Output size of operation in bytes
  2682. * @param arithType Type of arithmetic to perform (integer or F2m)
  2683. * @return Operation status.
  2684. */
  2685. status_t CAAM_PKHA_ModInv(CAAM_Type *base,
  2686. caam_handle_t *handle,
  2687. const uint8_t *A,
  2688. size_t sizeA,
  2689. const uint8_t *N,
  2690. size_t sizeN,
  2691. uint8_t *result,
  2692. size_t *resultSize,
  2693. caam_pkha_f2m_t arithType);
  2694. /*!
  2695. * @brief Computes integer Montgomery factor R^2 mod N.
  2696. *
  2697. * This function computes a constant to assist in converting operands
  2698. * into the Montgomery residue system representation.
  2699. *
  2700. * @param base CAAM peripheral base address
  2701. * @param handle Handle used for this request. Specifies jobRing.
  2702. * @param N modulus
  2703. * @param sizeN Size of N in bytes
  2704. * @param[out] result Output array to store result of operation
  2705. * @param[out] resultSize Output size of operation in bytes
  2706. * @param arithType Type of arithmetic to perform (integer or F2m)
  2707. * @return Operation status.
  2708. */
  2709. status_t CAAM_PKHA_ModR2(CAAM_Type *base,
  2710. caam_handle_t *handle,
  2711. const uint8_t *N,
  2712. size_t sizeN,
  2713. uint8_t *result,
  2714. size_t *resultSize,
  2715. caam_pkha_f2m_t arithType);
  2716. /*!
  2717. * @brief Calculates the greatest common divisor - GCD (A, N).
  2718. *
  2719. * This function calculates the greatest common divisor of two inputs with
  2720. * either integer or binary polynomial (F2m) inputs.
  2721. *
  2722. * @param base CAAM peripheral base address
  2723. * @param handle Handle used for this request. Specifies jobRing.
  2724. * @param A first value (must be smaller than or equal to N)
  2725. * @param sizeA Size of A in bytes
  2726. * @param N second value (must be non-zero)
  2727. * @param sizeN Size of N in bytes
  2728. * @param[out] result Output array to store result of operation
  2729. * @param[out] resultSize Output size of operation in bytes
  2730. * @param arithType Type of arithmetic to perform (integer or F2m)
  2731. * @return Operation status.
  2732. */
  2733. status_t CAAM_PKHA_ModGcd(CAAM_Type *base,
  2734. caam_handle_t *handle,
  2735. const uint8_t *A,
  2736. size_t sizeA,
  2737. const uint8_t *N,
  2738. size_t sizeN,
  2739. uint8_t *result,
  2740. size_t *resultSize,
  2741. caam_pkha_f2m_t arithType);
  2742. /*!
  2743. * @brief Executes Miller-Rabin primality test.
  2744. *
  2745. * This function calculates whether or not a candidate prime number is likely
  2746. * to be a prime.
  2747. *
  2748. * @param base CAAM peripheral base address
  2749. * @param handle Handle used for this request. Specifies jobRing.
  2750. * @param A initial random seed
  2751. * @param sizeA Size of A in bytes
  2752. * @param B number of trial runs
  2753. * @param sizeB Size of B in bytes
  2754. * @param N candidate prime integer
  2755. * @param sizeN Size of N in bytes
  2756. * @param[out] res True if the value is likely prime or false otherwise
  2757. * @return Operation status.
  2758. */
  2759. status_t CAAM_PKHA_PrimalityTest(CAAM_Type *base,
  2760. caam_handle_t *handle,
  2761. const uint8_t *A,
  2762. size_t sizeA,
  2763. const uint8_t *B,
  2764. size_t sizeB,
  2765. const uint8_t *N,
  2766. size_t sizeN,
  2767. bool *res);
  2768. /*!
  2769. * @brief Adds elliptic curve points - A + B.
  2770. *
  2771. * This function performs ECC point addition over a prime field (Fp) or binary field (F2m) using
  2772. * affine coordinates.
  2773. *
  2774. * @param base CAAM peripheral base address
  2775. * @param handle Handle used for this request. Specifies jobRing.
  2776. * @param A Left-hand point
  2777. * @param B Right-hand point
  2778. * @param N Prime modulus of the field
  2779. * @param R2modN NULL (the function computes R2modN internally) or pointer to pre-computed R2modN (obtained from
  2780. * CAAM_PKHA_ModR2() function).
  2781. * @param aCurveParam A parameter from curve equation
  2782. * @param bCurveParam B parameter from curve equation (constant)
  2783. * @param size Size in bytes of curve points and parameters
  2784. * @param arithType Type of arithmetic to perform (integer or F2m)
  2785. * @param[out] result Result point
  2786. * @return Operation status.
  2787. */
  2788. status_t CAAM_PKHA_ECC_PointAdd(CAAM_Type *base,
  2789. caam_handle_t *handle,
  2790. const caam_pkha_ecc_point_t *A,
  2791. const caam_pkha_ecc_point_t *B,
  2792. const uint8_t *N,
  2793. const uint8_t *R2modN,
  2794. const uint8_t *aCurveParam,
  2795. const uint8_t *bCurveParam,
  2796. size_t size,
  2797. caam_pkha_f2m_t arithType,
  2798. caam_pkha_ecc_point_t *result);
  2799. /*!
  2800. * @brief Doubles elliptic curve points - B + B.
  2801. *
  2802. * This function performs ECC point doubling over a prime field (Fp) or binary field (F2m) using
  2803. * affine coordinates.
  2804. *
  2805. * @param base CAAM peripheral base address
  2806. * @param handle Handle used for this request. Specifies jobRing.
  2807. * @param B Point to double
  2808. * @param N Prime modulus of the field
  2809. * @param aCurveParam A parameter from curve equation
  2810. * @param bCurveParam B parameter from curve equation (constant)
  2811. * @param size Size in bytes of curve points and parameters
  2812. * @param arithType Type of arithmetic to perform (integer or F2m)
  2813. * @param[out] result Result point
  2814. * @return Operation status.
  2815. */
  2816. status_t CAAM_PKHA_ECC_PointDouble(CAAM_Type *base,
  2817. caam_handle_t *handle,
  2818. const caam_pkha_ecc_point_t *B,
  2819. const uint8_t *N,
  2820. const uint8_t *aCurveParam,
  2821. const uint8_t *bCurveParam,
  2822. size_t size,
  2823. caam_pkha_f2m_t arithType,
  2824. caam_pkha_ecc_point_t *result);
  2825. /*!
  2826. * @brief Multiplies an elliptic curve point by a scalar - E x (A0, A1).
  2827. *
  2828. * This function performs ECC point multiplication to multiply an ECC point by
  2829. * a scalar integer multiplier over a prime field (Fp) or a binary field (F2m).
  2830. *
  2831. * @param base CAAM peripheral base address
  2832. * @param handle Handle used for this request. Specifies jobRing.
  2833. * @param A Point as multiplicand
  2834. * @param E Scalar multiple
  2835. * @param sizeE The size of E, in bytes
  2836. * @param N Modulus, a prime number for the Fp field or Irreducible polynomial for F2m field.
  2837. * @param R2modN NULL (the function computes R2modN internally) or pointer to pre-computed R2modN (obtained from
  2838. * CAAM_PKHA_ModR2() function).
  2839. * @param aCurveParam A parameter from curve equation
  2840. * @param bCurveParam B parameter from curve equation (C parameter for operation over F2m).
  2841. * @param size Size in bytes of curve points and parameters
  2842. * @param equalTime Run the function time equalized or no timing equalization.
  2843. * @param arithType Type of arithmetic to perform (integer or F2m)
  2844. * @param[out] result Result point
  2845. * @return Operation status.
  2846. */
  2847. status_t CAAM_PKHA_ECC_PointMul(CAAM_Type *base,
  2848. caam_handle_t *handle,
  2849. const caam_pkha_ecc_point_t *A,
  2850. const uint8_t *E,
  2851. size_t sizeE,
  2852. const uint8_t *N,
  2853. const uint8_t *R2modN,
  2854. const uint8_t *aCurveParam,
  2855. const uint8_t *bCurveParam,
  2856. size_t size,
  2857. caam_pkha_timing_t equalTime,
  2858. caam_pkha_f2m_t arithType,
  2859. caam_pkha_ecc_point_t *result);
  2860. /*!
  2861. *@}
  2862. */ /* end of caam_driver_pkha */
  2863. #if defined(__cplusplus)
  2864. }
  2865. #endif
  2866. #endif /* _FSL_CAAM_H_ */