fsl_ltc.h 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _FSL_LTC_H_
  35. #define _FSL_LTC_H_
  36. #include "fsl_common.h"
  37. /*******************************************************************************
  38. * Definitions
  39. *******************************************************************************/
  40. /*!
  41. * @addtogroup ltc
  42. * @{
  43. */
  44. /*! @name Driver version */
  45. /*@{*/
  46. /*! @brief LTC driver version. Version 2.0.5.
  47. *
  48. * Current version: 2.0.5
  49. *
  50. * Change log:
  51. * - Version 2.0.1
  52. * - fixed warning during g++ compilation
  53. *
  54. * - Version 2.0.2
  55. * - fixed [KPSDK-10932][LTC][SHA] LTC_HASH() blocks indefinitely when message size exceeds 4080 bytes
  56. *
  57. * - Version 2.0.3
  58. * - fixed LTC_PKHA_CompareBigNum() in case an integer argument is an array of all zeroes
  59. *
  60. * - Version 2.0.4
  61. * - constant LTC_PKHA_CompareBigNum() processing time
  62. *
  63. * - Version 2.0.5
  64. * - Fix MISRA issues
  65. */
  66. #define FSL_LTC_DRIVER_VERSION (MAKE_VERSION(2, 0, 5))
  67. /*@}*/
  68. /*! @} */
  69. /*******************************************************************************
  70. * AES Definitions
  71. *******************************************************************************/
  72. /*!
  73. * @addtogroup ltc_driver_aes
  74. * @{
  75. */
  76. /*! AES block size in bytes */
  77. #define LTC_AES_BLOCK_SIZE 16
  78. /*! AES Input Vector size in bytes */
  79. #define LTC_AES_IV_SIZE 16
  80. /*! @brief Type of AES key for ECB and CBC decrypt operations. */
  81. typedef enum _ltc_aes_key_t
  82. {
  83. kLTC_EncryptKey = 0U, /*!< Input key is an encrypt key */
  84. kLTC_DecryptKey = 1U, /*!< Input key is a decrypt key */
  85. } ltc_aes_key_t;
  86. /*!
  87. *@}
  88. */
  89. /*******************************************************************************
  90. * DES Definitions
  91. *******************************************************************************/
  92. /*!
  93. * @addtogroup ltc_driver_des
  94. * @{
  95. */
  96. /*! @brief LTC DES key size - 64 bits. */
  97. #define LTC_DES_KEY_SIZE 8
  98. /*! @brief LTC DES IV size - 8 bytes */
  99. #define LTC_DES_IV_SIZE 8
  100. /*!
  101. *@}
  102. */
  103. /*******************************************************************************
  104. * HASH Definitions
  105. ******************************************************************************/
  106. /*!
  107. * @addtogroup ltc_driver_hash
  108. * @{
  109. */
  110. /*! Supported cryptographic block cipher functions for HASH creation */
  111. typedef enum _ltc_hash_algo_t
  112. {
  113. kLTC_XcbcMac = 0, /*!< XCBC-MAC (AES engine) */
  114. kLTC_Cmac, /*!< CMAC (AES engine) */
  115. #if defined(FSL_FEATURE_LTC_HAS_SHA) && FSL_FEATURE_LTC_HAS_SHA
  116. kLTC_Sha1, /*!< SHA_1 (MDHA engine) */
  117. kLTC_Sha224, /*!< SHA_224 (MDHA engine) */
  118. kLTC_Sha256, /*!< SHA_256 (MDHA engine) */
  119. #endif /* FSL_FEATURE_LTC_HAS_SHA */
  120. } ltc_hash_algo_t;
  121. /*! @brief LTC HASH Context size. */
  122. #if defined(FSL_FEATURE_LTC_HAS_SHA) && FSL_FEATURE_LTC_HAS_SHA
  123. #define LTC_HASH_CTX_SIZE 41
  124. #else
  125. #define LTC_HASH_CTX_SIZE 29
  126. #endif /* FSL_FEATURE_LTC_HAS_SHA */
  127. /*! @brief Storage type used to save hash context. */
  128. typedef struct _ltc_hash_ctx_t
  129. {
  130. uint32_t x[LTC_HASH_CTX_SIZE];
  131. } ltc_hash_ctx_t;
  132. /*!
  133. *@}
  134. */
  135. /*******************************************************************************
  136. * PKHA Definitions
  137. ******************************************************************************/
  138. /*!
  139. * @addtogroup ltc_driver_pkha
  140. * @{
  141. */
  142. /*! PKHA ECC point structure */
  143. typedef struct _ltc_pkha_ecc_point_t
  144. {
  145. uint8_t *X; /*!< X coordinate (affine) */
  146. uint8_t *Y; /*!< Y coordinate (affine) */
  147. } ltc_pkha_ecc_point_t;
  148. /*! @brief Use of timing equalized version of a PKHA function. */
  149. typedef enum _ltc_pkha_timing_t
  150. {
  151. kLTC_PKHA_NoTimingEqualized = 0U, /*!< Normal version of a PKHA operation */
  152. kLTC_PKHA_TimingEqualized = 1U /*!< Timing-equalized version of a PKHA operation */
  153. } ltc_pkha_timing_t;
  154. /*! @brief Integer vs binary polynomial arithmetic selection. */
  155. typedef enum _ltc_pkha_f2m_t
  156. {
  157. kLTC_PKHA_IntegerArith = 0U, /*!< Use integer arithmetic */
  158. kLTC_PKHA_F2mArith = 1U /*!< Use binary polynomial arithmetic */
  159. } ltc_pkha_f2m_t;
  160. /*! @brief Montgomery or normal PKHA input format. */
  161. typedef enum _ltc_pkha_montgomery_form_t
  162. {
  163. kLTC_PKHA_NormalValue = 0U, /*!< PKHA number is normal integer */
  164. kLTC_PKHA_MontgomeryFormat = 1U /*!< PKHA number is in montgomery format */
  165. } ltc_pkha_montgomery_form_t;
  166. /*!
  167. *@}
  168. */
  169. /*******************************************************************************
  170. * API
  171. ******************************************************************************/
  172. #if defined(__cplusplus)
  173. extern "C" {
  174. #endif
  175. /*!
  176. * @addtogroup ltc
  177. * @{
  178. */
  179. /*!
  180. * @brief Initializes the LTC driver.
  181. * This function initializes the LTC driver.
  182. * @param base LTC peripheral base address
  183. */
  184. void LTC_Init(LTC_Type *base);
  185. /*!
  186. * @brief Deinitializes the LTC driver.
  187. * This function deinitializes the LTC driver.
  188. * @param base LTC peripheral base address
  189. */
  190. void LTC_Deinit(LTC_Type *base);
  191. #if defined(FSL_FEATURE_LTC_HAS_DPAMS) && FSL_FEATURE_LTC_HAS_DPAMS
  192. /*!
  193. * @brief Sets the DPA Mask Seed register.
  194. *
  195. * The DPA Mask Seed register reseeds the mask that provides resistance against DPA (differential power analysis)
  196. * attacks on AES or DES keys.
  197. *
  198. * Differential Power Analysis Mask (DPA) resistance uses a randomly changing mask that introduces
  199. * "noise" into the power consumed by the AES or DES. This reduces the signal-to-noise ratio that differential
  200. * power analysis attacks use to "guess" bits of the key. This randomly changing mask should be
  201. * seeded at POR, and continues to provide DPA resistance from that point on. However, to provide even more
  202. * DPA protection it is recommended that the DPA mask be reseeded after every 50,000 blocks have
  203. * been processed. At that time, software can opt to write a new seed (preferably obtained from an RNG)
  204. * into the DPA Mask Seed register (DPAMS), or software can opt to provide the new seed earlier or
  205. * later, or not at all. DPA resistance continues even if the DPA mask is never reseeded.
  206. *
  207. * @param base LTC peripheral base address
  208. * @param mask The DPA mask seed.
  209. */
  210. void LTC_SetDpaMaskSeed(LTC_Type *base, uint32_t mask);
  211. #endif /* FSL_FEATURE_LTC_HAS_DPAMS */
  212. /*!
  213. *@}
  214. */
  215. /*******************************************************************************
  216. * AES API
  217. ******************************************************************************/
  218. /*!
  219. * @addtogroup ltc_driver_aes
  220. * @{
  221. */
  222. /*!
  223. * @brief Transforms an AES encrypt key (forward AES) into the decrypt key (inverse AES).
  224. *
  225. * Transforms the AES encrypt key (forward AES) into the decrypt key (inverse AES).
  226. * The key derived by this function can be used as a direct load decrypt key
  227. * for AES ECB and CBC decryption operations (keyType argument).
  228. *
  229. * @param base LTC peripheral base address
  230. * @param encryptKey Input key for decrypt key transformation
  231. * @param[out] decryptKey Output key, the decrypt form of the AES key.
  232. * @param keySize Size of the input key and output key in bytes. Must be 16, 24, or 32.
  233. * @return Status from key generation operation
  234. */
  235. status_t LTC_AES_GenerateDecryptKey(LTC_Type *base, const uint8_t *encryptKey, uint8_t *decryptKey, uint32_t keySize);
  236. /*!
  237. * @brief Encrypts AES using the ECB block mode.
  238. *
  239. * Encrypts AES using the ECB block mode.
  240. *
  241. * @param base LTC peripheral base address
  242. * @param plaintext Input plain text to encrypt
  243. * @param[out] ciphertext Output cipher text
  244. * @param size Size of input and output data in bytes. Must be multiple of 16 bytes.
  245. * @param key Input key to use for encryption
  246. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  247. * @return Status from encrypt operation
  248. */
  249. status_t LTC_AES_EncryptEcb(
  250. LTC_Type *base, const uint8_t *plaintext, uint8_t *ciphertext, uint32_t size, const uint8_t *key, uint32_t keySize);
  251. /*!
  252. * @brief Decrypts AES using ECB block mode.
  253. *
  254. * Decrypts AES using ECB block mode.
  255. *
  256. * @param base LTC peripheral base address
  257. * @param ciphertext Input cipher text to decrypt
  258. * @param[out] plaintext Output plain text
  259. * @param size Size of input and output data in bytes. Must be multiple of 16 bytes.
  260. * @param key Input key.
  261. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  262. * @param keyType Input type of the key (allows to directly load decrypt key for AES ECB decrypt operation.)
  263. * @return Status from decrypt operation
  264. */
  265. status_t LTC_AES_DecryptEcb(LTC_Type *base,
  266. const uint8_t *ciphertext,
  267. uint8_t *plaintext,
  268. uint32_t size,
  269. const uint8_t *key,
  270. uint32_t keySize,
  271. ltc_aes_key_t keyType);
  272. /*!
  273. * @brief Encrypts AES using CBC block mode.
  274. *
  275. * @param base LTC peripheral base address
  276. * @param plaintext Input plain text to encrypt
  277. * @param[out] ciphertext Output cipher text
  278. * @param size Size of input and output data in bytes. Must be multiple of 16 bytes.
  279. * @param iv Input initial vector to combine with the first input block.
  280. * @param key Input key to use for encryption
  281. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  282. * @return Status from encrypt operation
  283. */
  284. status_t LTC_AES_EncryptCbc(LTC_Type *base,
  285. const uint8_t *plaintext,
  286. uint8_t *ciphertext,
  287. uint32_t size,
  288. const uint8_t iv[LTC_AES_IV_SIZE],
  289. const uint8_t *key,
  290. uint32_t keySize);
  291. /*!
  292. * @brief Decrypts AES using CBC block mode.
  293. *
  294. * @param base LTC peripheral base address
  295. * @param ciphertext Input cipher text to decrypt
  296. * @param[out] plaintext Output plain text
  297. * @param size Size of input and output data in bytes. Must be multiple of 16 bytes.
  298. * @param iv Input initial vector to combine with the first input block.
  299. * @param key Input key to use for decryption
  300. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  301. * @param keyType Input type of the key (allows to directly load decrypt key for AES CBC decrypt operation.)
  302. * @return Status from decrypt operation
  303. */
  304. status_t LTC_AES_DecryptCbc(LTC_Type *base,
  305. const uint8_t *ciphertext,
  306. uint8_t *plaintext,
  307. uint32_t size,
  308. const uint8_t iv[LTC_AES_IV_SIZE],
  309. const uint8_t *key,
  310. uint32_t keySize,
  311. ltc_aes_key_t keyType);
  312. /*!
  313. * @brief Encrypts or decrypts AES using CTR block mode.
  314. *
  315. * Encrypts or decrypts AES using CTR block mode.
  316. * AES CTR mode uses only forward AES cipher and same algorithm for encryption and decryption.
  317. * The only difference between encryption and decryption is that, for encryption, the input argument
  318. * is plain text and the output argument is cipher text. For decryption, the input argument is cipher text
  319. * and the output argument is plain text.
  320. *
  321. * @param base LTC peripheral base address
  322. * @param input Input data for CTR block mode
  323. * @param[out] output Output data for CTR block mode
  324. * @param size Size of input and output data in bytes
  325. * @param[in,out] counter Input counter (updates on return)
  326. * @param key Input key to use for forward AES cipher
  327. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  328. * @param[out] counterlast Output cipher of last counter, for chained CTR calls. NULL can be passed if chained calls are
  329. * not used.
  330. * @param[out] szLeft Output number of bytes in left unused in counterlast block. NULL can be passed if chained calls
  331. * are not used.
  332. * @return Status from encrypt operation
  333. */
  334. status_t LTC_AES_CryptCtr(LTC_Type *base,
  335. const uint8_t *input,
  336. uint8_t *output,
  337. uint32_t size,
  338. uint8_t counter[LTC_AES_BLOCK_SIZE],
  339. const uint8_t *key,
  340. uint32_t keySize,
  341. uint8_t counterlast[LTC_AES_BLOCK_SIZE],
  342. uint32_t *szLeft);
  343. /*! AES CTR decrypt is mapped to the AES CTR generic operation */
  344. #define LTC_AES_DecryptCtr(base, input, output, size, counter, key, keySize, counterlast, szLeft) \
  345. LTC_AES_CryptCtr(base, input, output, size, counter, key, keySize, counterlast, szLeft)
  346. /*! AES CTR encrypt is mapped to the AES CTR generic operation */
  347. #define LTC_AES_EncryptCtr(base, input, output, size, counter, key, keySize, counterlast, szLeft) \
  348. LTC_AES_CryptCtr(base, input, output, size, counter, key, keySize, counterlast, szLeft)
  349. #if defined(FSL_FEATURE_LTC_HAS_GCM) && FSL_FEATURE_LTC_HAS_GCM
  350. /*!
  351. * @brief Encrypts AES and tags using GCM block mode.
  352. *
  353. * Encrypts AES and optionally tags using GCM block mode. If plaintext is NULL, only the GHASH is calculated and output
  354. * in the 'tag' field.
  355. *
  356. * @param base LTC peripheral base address
  357. * @param plaintext Input plain text to encrypt
  358. * @param[out] ciphertext Output cipher text.
  359. * @param size Size of input and output data in bytes
  360. * @param iv Input initial vector
  361. * @param ivSize Size of the IV
  362. * @param aad Input additional authentication data
  363. * @param aadSize Input size in bytes of AAD
  364. * @param key Input key to use for encryption
  365. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  366. * @param[out] tag Output hash tag. Set to NULL to skip tag processing.
  367. * @param tagSize Input size of the tag to generate, in bytes. Must be 4,8,12,13,14,15 or 16.
  368. * @return Status from encrypt operation
  369. */
  370. status_t LTC_AES_EncryptTagGcm(LTC_Type *base,
  371. const uint8_t *plaintext,
  372. uint8_t *ciphertext,
  373. uint32_t size,
  374. const uint8_t *iv,
  375. uint32_t ivSize,
  376. const uint8_t *aad,
  377. uint32_t aadSize,
  378. const uint8_t *key,
  379. uint32_t keySize,
  380. uint8_t *tag,
  381. uint32_t tagSize);
  382. /*!
  383. * @brief Decrypts AES and authenticates using GCM block mode.
  384. *
  385. * Decrypts AES and optionally authenticates using GCM block mode. If ciphertext is NULL, only the GHASH is calculated
  386. * and compared with the received GHASH in 'tag' field.
  387. *
  388. * @param base LTC peripheral base address
  389. * @param ciphertext Input cipher text to decrypt
  390. * @param[out] plaintext Output plain text.
  391. * @param size Size of input and output data in bytes
  392. * @param iv Input initial vector
  393. * @param ivSize Size of the IV
  394. * @param aad Input additional authentication data
  395. * @param aadSize Input size in bytes of AAD
  396. * @param key Input key to use for encryption
  397. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  398. * @param tag Input hash tag to compare. Set to NULL to skip tag processing.
  399. * @param tagSize Input size of the tag, in bytes. Must be 4, 8, 12, 13, 14, 15, or 16.
  400. * @return Status from decrypt operation
  401. */
  402. status_t LTC_AES_DecryptTagGcm(LTC_Type *base,
  403. const uint8_t *ciphertext,
  404. uint8_t *plaintext,
  405. uint32_t size,
  406. const uint8_t *iv,
  407. uint32_t ivSize,
  408. const uint8_t *aad,
  409. uint32_t aadSize,
  410. const uint8_t *key,
  411. uint32_t keySize,
  412. const uint8_t *tag,
  413. uint32_t tagSize);
  414. #endif /* FSL_FEATURE_LTC_HAS_GCM */
  415. /*!
  416. * @brief Encrypts AES and tags using CCM block mode.
  417. *
  418. * Encrypts AES and optionally tags using CCM block mode.
  419. *
  420. * @param base LTC peripheral base address
  421. * @param plaintext Input plain text to encrypt
  422. * @param[out] ciphertext Output cipher text.
  423. * @param size Size of input and output data in bytes. Zero means authentication only.
  424. * @param iv Nonce
  425. * @param ivSize Length of the Nonce in bytes. Must be 7, 8, 9, 10, 11, 12, or 13.
  426. * @param aad Input additional authentication data. Can be NULL if aadSize is zero.
  427. * @param aadSize Input size in bytes of AAD. Zero means data mode only (authentication skipped).
  428. * @param key Input key to use for encryption
  429. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  430. * @param[out] tag Generated output tag. Set to NULL to skip tag processing.
  431. * @param tagSize Input size of the tag to generate, in bytes. Must be 4, 6, 8, 10, 12, 14, or 16.
  432. * @return Status from encrypt operation
  433. */
  434. status_t LTC_AES_EncryptTagCcm(LTC_Type *base,
  435. const uint8_t *plaintext,
  436. uint8_t *ciphertext,
  437. uint32_t size,
  438. const uint8_t *iv,
  439. uint32_t ivSize,
  440. const uint8_t *aad,
  441. uint32_t aadSize,
  442. const uint8_t *key,
  443. uint32_t keySize,
  444. uint8_t *tag,
  445. uint32_t tagSize);
  446. /*!
  447. * @brief Decrypts AES and authenticates using CCM block mode.
  448. *
  449. * Decrypts AES and optionally authenticates using CCM block mode.
  450. *
  451. * @param base LTC peripheral base address
  452. * @param ciphertext Input cipher text to decrypt
  453. * @param[out] plaintext Output plain text.
  454. * @param size Size of input and output data in bytes. Zero means authentication only.
  455. * @param iv Nonce
  456. * @param ivSize Length of the Nonce in bytes. Must be 7, 8, 9, 10, 11, 12, or 13.
  457. * @param aad Input additional authentication data. Can be NULL if aadSize is zero.
  458. * @param aadSize Input size in bytes of AAD. Zero means data mode only (authentication skipped).
  459. * @param key Input key to use for decryption
  460. * @param keySize Size of the input key, in bytes. Must be 16, 24, or 32.
  461. * @param tag Received tag. Set to NULL to skip tag processing.
  462. * @param tagSize Input size of the received tag to compare with the computed tag, in bytes. Must be 4, 6, 8, 10, 12,
  463. * 14, or 16.
  464. * @return Status from decrypt operation
  465. */
  466. status_t LTC_AES_DecryptTagCcm(LTC_Type *base,
  467. const uint8_t *ciphertext,
  468. uint8_t *plaintext,
  469. uint32_t size,
  470. const uint8_t *iv,
  471. uint32_t ivSize,
  472. const uint8_t *aad,
  473. uint32_t aadSize,
  474. const uint8_t *key,
  475. uint32_t keySize,
  476. const uint8_t *tag,
  477. uint32_t tagSize);
  478. /*!
  479. *@}
  480. */
  481. /*******************************************************************************
  482. * DES API
  483. ******************************************************************************/
  484. /*!
  485. * @addtogroup ltc_driver_des
  486. * @{
  487. */
  488. /*!
  489. * @brief Encrypts DES using ECB block mode.
  490. *
  491. * Encrypts DES using ECB block mode.
  492. *
  493. * @param base LTC peripheral base address
  494. * @param plaintext Input plaintext to encrypt
  495. * @param[out] ciphertext Output ciphertext
  496. * @param size Size of input and output data in bytes. Must be multiple of 8 bytes.
  497. * @param key Input key to use for encryption
  498. * @return Status from encrypt/decrypt operation
  499. */
  500. status_t LTC_DES_EncryptEcb(
  501. LTC_Type *base, const uint8_t *plaintext, uint8_t *ciphertext, uint32_t size, const uint8_t key[LTC_DES_KEY_SIZE]);
  502. /*!
  503. * @brief Decrypts DES using ECB block mode.
  504. *
  505. * Decrypts DES using ECB block mode.
  506. *
  507. * @param base LTC peripheral base address
  508. * @param ciphertext Input ciphertext to decrypt
  509. * @param[out] plaintext Output plaintext
  510. * @param size Size of input and output data in bytes. Must be multiple of 8 bytes.
  511. * @param key Input key to use for decryption
  512. * @return Status from encrypt/decrypt operation
  513. */
  514. status_t LTC_DES_DecryptEcb(
  515. LTC_Type *base, const uint8_t *ciphertext, uint8_t *plaintext, uint32_t size, const uint8_t key[LTC_DES_KEY_SIZE]);
  516. /*!
  517. * @brief Encrypts DES using CBC block mode.
  518. *
  519. * Encrypts DES using CBC block mode.
  520. *
  521. * @param base LTC peripheral base address
  522. * @param plaintext Input plaintext to encrypt
  523. * @param[out] ciphertext Ouput ciphertext
  524. * @param size Size of input and output data in bytes
  525. * @param iv Input initial vector to combine with the first plaintext block.
  526. * The iv does not need to be secret, but it must be unpredictable.
  527. * @param key Input key to use for encryption
  528. * @return Status from encrypt/decrypt operation
  529. */
  530. status_t LTC_DES_EncryptCbc(LTC_Type *base,
  531. const uint8_t *plaintext,
  532. uint8_t *ciphertext,
  533. uint32_t size,
  534. const uint8_t iv[LTC_DES_IV_SIZE],
  535. const uint8_t key[LTC_DES_KEY_SIZE]);
  536. /*!
  537. * @brief Decrypts DES using CBC block mode.
  538. *
  539. * Decrypts DES using CBC block mode.
  540. *
  541. * @param base LTC peripheral base address
  542. * @param ciphertext Input ciphertext to decrypt
  543. * @param[out] plaintext Output plaintext
  544. * @param size Size of input data in bytes
  545. * @param iv Input initial vector to combine with the first plaintext block.
  546. * The iv does not need to be secret, but it must be unpredictable.
  547. * @param key Input key to use for decryption
  548. * @return Status from encrypt/decrypt operation
  549. */
  550. status_t LTC_DES_DecryptCbc(LTC_Type *base,
  551. const uint8_t *ciphertext,
  552. uint8_t *plaintext,
  553. uint32_t size,
  554. const uint8_t iv[LTC_DES_IV_SIZE],
  555. const uint8_t key[LTC_DES_KEY_SIZE]);
  556. /*!
  557. * @brief Encrypts DES using CFB block mode.
  558. *
  559. * Encrypts DES using CFB block mode.
  560. *
  561. * @param base LTC peripheral base address
  562. * @param plaintext Input plaintext to encrypt
  563. * @param size Size of input data in bytes
  564. * @param iv Input initial block.
  565. * @param key Input key to use for encryption
  566. * @param[out] ciphertext Output ciphertext
  567. * @return Status from encrypt/decrypt operation
  568. */
  569. status_t LTC_DES_EncryptCfb(LTC_Type *base,
  570. const uint8_t *plaintext,
  571. uint8_t *ciphertext,
  572. uint32_t size,
  573. const uint8_t iv[LTC_DES_IV_SIZE],
  574. const uint8_t key[LTC_DES_KEY_SIZE]);
  575. /*!
  576. * @brief Decrypts DES using CFB block mode.
  577. *
  578. * Decrypts DES using CFB block mode.
  579. *
  580. * @param base LTC peripheral base address
  581. * @param ciphertext Input ciphertext to decrypt
  582. * @param[out] plaintext Output plaintext
  583. * @param size Size of input and output data in bytes
  584. * @param iv Input initial block.
  585. * @param key Input key to use for decryption
  586. * @return Status from encrypt/decrypt operation
  587. */
  588. status_t LTC_DES_DecryptCfb(LTC_Type *base,
  589. const uint8_t *ciphertext,
  590. uint8_t *plaintext,
  591. uint32_t size,
  592. const uint8_t iv[LTC_DES_IV_SIZE],
  593. const uint8_t key[LTC_DES_KEY_SIZE]);
  594. /*!
  595. * @brief Encrypts DES using OFB block mode.
  596. *
  597. * Encrypts DES using OFB block mode.
  598. *
  599. * @param base LTC peripheral base address
  600. * @param plaintext Input plaintext to encrypt
  601. * @param[out] ciphertext Output ciphertext
  602. * @param size Size of input and output data in bytes
  603. * @param iv Input unique input vector. The OFB mode requires that the IV be unique
  604. * for each execution of the mode under the given key.
  605. * @param key Input key to use for encryption
  606. * @return Status from encrypt/decrypt operation
  607. */
  608. status_t LTC_DES_EncryptOfb(LTC_Type *base,
  609. const uint8_t *plaintext,
  610. uint8_t *ciphertext,
  611. uint32_t size,
  612. const uint8_t iv[LTC_DES_IV_SIZE],
  613. const uint8_t key[LTC_DES_KEY_SIZE]);
  614. /*!
  615. * @brief Decrypts DES using OFB block mode.
  616. *
  617. * Decrypts DES using OFB block mode.
  618. *
  619. * @param base LTC peripheral base address
  620. * @param ciphertext Input ciphertext to decrypt
  621. * @param[out] plaintext Output plaintext
  622. * @param size Size of input and output data in bytes. Must be multiple of 8 bytes.
  623. * @param iv Input unique input vector. The OFB mode requires that the IV be unique
  624. * for each execution of the mode under the given key.
  625. * @param key Input key to use for decryption
  626. * @return Status from encrypt/decrypt operation
  627. */
  628. status_t LTC_DES_DecryptOfb(LTC_Type *base,
  629. const uint8_t *ciphertext,
  630. uint8_t *plaintext,
  631. uint32_t size,
  632. const uint8_t iv[LTC_DES_IV_SIZE],
  633. const uint8_t key[LTC_DES_KEY_SIZE]);
  634. /*!
  635. * @brief Encrypts triple DES using ECB block mode with two keys.
  636. *
  637. * Encrypts triple DES using ECB block mode with two keys.
  638. *
  639. * @param base LTC peripheral base address
  640. * @param plaintext Input plaintext to encrypt
  641. * @param[out] ciphertext Output ciphertext
  642. * @param size Size of input and output data in bytes. Must be multiple of 8 bytes.
  643. * @param key1 First input key for key bundle
  644. * @param key2 Second input key for key bundle
  645. * @return Status from encrypt/decrypt operation
  646. */
  647. status_t LTC_DES2_EncryptEcb(LTC_Type *base,
  648. const uint8_t *plaintext,
  649. uint8_t *ciphertext,
  650. uint32_t size,
  651. const uint8_t key1[LTC_DES_KEY_SIZE],
  652. const uint8_t key2[LTC_DES_KEY_SIZE]);
  653. /*!
  654. * @brief Decrypts triple DES using ECB block mode with two keys.
  655. *
  656. * Decrypts triple DES using ECB block mode with two keys.
  657. *
  658. * @param base LTC peripheral base address
  659. * @param ciphertext Input ciphertext to decrypt
  660. * @param[out] plaintext Output plaintext
  661. * @param size Size of input and output data in bytes. Must be multiple of 8 bytes.
  662. * @param key1 First input key for key bundle
  663. * @param key2 Second input key for key bundle
  664. * @return Status from encrypt/decrypt operation
  665. */
  666. status_t LTC_DES2_DecryptEcb(LTC_Type *base,
  667. const uint8_t *ciphertext,
  668. uint8_t *plaintext,
  669. uint32_t size,
  670. const uint8_t key1[LTC_DES_KEY_SIZE],
  671. const uint8_t key2[LTC_DES_KEY_SIZE]);
  672. /*!
  673. * @brief Encrypts triple DES using CBC block mode with two keys.
  674. *
  675. * Encrypts triple DES using CBC block mode with two keys.
  676. *
  677. * @param base LTC peripheral base address
  678. * @param plaintext Input plaintext to encrypt
  679. * @param[out] ciphertext Output ciphertext
  680. * @param size Size of input and output data in bytes
  681. * @param iv Input initial vector to combine with the first plaintext block.
  682. * The iv does not need to be secret, but it must be unpredictable.
  683. * @param key1 First input key for key bundle
  684. * @param key2 Second input key for key bundle
  685. * @return Status from encrypt/decrypt operation
  686. */
  687. status_t LTC_DES2_EncryptCbc(LTC_Type *base,
  688. const uint8_t *plaintext,
  689. uint8_t *ciphertext,
  690. uint32_t size,
  691. const uint8_t iv[LTC_DES_IV_SIZE],
  692. const uint8_t key1[LTC_DES_KEY_SIZE],
  693. const uint8_t key2[LTC_DES_KEY_SIZE]);
  694. /*!
  695. * @brief Decrypts triple DES using CBC block mode with two keys.
  696. *
  697. * Decrypts triple DES using CBC block mode with two keys.
  698. *
  699. * @param base LTC peripheral base address
  700. * @param ciphertext Input ciphertext to decrypt
  701. * @param[out] plaintext Output plaintext
  702. * @param size Size of input and output data in bytes
  703. * @param iv Input initial vector to combine with the first plaintext block.
  704. * The iv does not need to be secret, but it must be unpredictable.
  705. * @param key1 First input key for key bundle
  706. * @param key2 Second input key for key bundle
  707. * @return Status from encrypt/decrypt operation
  708. */
  709. status_t LTC_DES2_DecryptCbc(LTC_Type *base,
  710. const uint8_t *ciphertext,
  711. uint8_t *plaintext,
  712. uint32_t size,
  713. const uint8_t iv[LTC_DES_IV_SIZE],
  714. const uint8_t key1[LTC_DES_KEY_SIZE],
  715. const uint8_t key2[LTC_DES_KEY_SIZE]);
  716. /*!
  717. * @brief Encrypts triple DES using CFB block mode with two keys.
  718. *
  719. * Encrypts triple DES using CFB block mode with two keys.
  720. *
  721. * @param base LTC peripheral base address
  722. * @param plaintext Input plaintext to encrypt
  723. * @param[out] ciphertext Output ciphertext
  724. * @param size Size of input and output data in bytes
  725. * @param iv Input initial block.
  726. * @param key1 First input key for key bundle
  727. * @param key2 Second input key for key bundle
  728. * @return Status from encrypt/decrypt operation
  729. */
  730. status_t LTC_DES2_EncryptCfb(LTC_Type *base,
  731. const uint8_t *plaintext,
  732. uint8_t *ciphertext,
  733. uint32_t size,
  734. const uint8_t iv[LTC_DES_IV_SIZE],
  735. const uint8_t key1[LTC_DES_KEY_SIZE],
  736. const uint8_t key2[LTC_DES_KEY_SIZE]);
  737. /*!
  738. * @brief Decrypts triple DES using CFB block mode with two keys.
  739. *
  740. * Decrypts triple DES using CFB block mode with two keys.
  741. *
  742. * @param base LTC peripheral base address
  743. * @param ciphertext Input ciphertext to decrypt
  744. * @param[out] plaintext Output plaintext
  745. * @param size Size of input and output data in bytes
  746. * @param iv Input initial block.
  747. * @param key1 First input key for key bundle
  748. * @param key2 Second input key for key bundle
  749. * @return Status from encrypt/decrypt operation
  750. */
  751. status_t LTC_DES2_DecryptCfb(LTC_Type *base,
  752. const uint8_t *ciphertext,
  753. uint8_t *plaintext,
  754. uint32_t size,
  755. const uint8_t iv[LTC_DES_IV_SIZE],
  756. const uint8_t key1[LTC_DES_KEY_SIZE],
  757. const uint8_t key2[LTC_DES_KEY_SIZE]);
  758. /*!
  759. * @brief Encrypts triple DES using OFB block mode with two keys.
  760. *
  761. * Encrypts triple DES using OFB block mode with two keys.
  762. *
  763. * @param base LTC peripheral base address
  764. * @param plaintext Input plaintext to encrypt
  765. * @param[out] ciphertext Output ciphertext
  766. * @param size Size of input and output data in bytes
  767. * @param iv Input unique input vector. The OFB mode requires that the IV be unique
  768. * for each execution of the mode under the given key.
  769. * @param key1 First input key for key bundle
  770. * @param key2 Second input key for key bundle
  771. * @return Status from encrypt/decrypt operation
  772. */
  773. status_t LTC_DES2_EncryptOfb(LTC_Type *base,
  774. const uint8_t *plaintext,
  775. uint8_t *ciphertext,
  776. uint32_t size,
  777. const uint8_t iv[LTC_DES_IV_SIZE],
  778. const uint8_t key1[LTC_DES_KEY_SIZE],
  779. const uint8_t key2[LTC_DES_KEY_SIZE]);
  780. /*!
  781. * @brief Decrypts triple DES using OFB block mode with two keys.
  782. *
  783. * Decrypts triple DES using OFB block mode with two keys.
  784. *
  785. * @param base LTC peripheral base address
  786. * @param ciphertext Input ciphertext to decrypt
  787. * @param[out] plaintext Output plaintext
  788. * @param size Size of input and output data in bytes
  789. * @param iv Input unique input vector. The OFB mode requires that the IV be unique
  790. * for each execution of the mode under the given key.
  791. * @param key1 First input key for key bundle
  792. * @param key2 Second input key for key bundle
  793. * @return Status from encrypt/decrypt operation
  794. */
  795. status_t LTC_DES2_DecryptOfb(LTC_Type *base,
  796. const uint8_t *ciphertext,
  797. uint8_t *plaintext,
  798. uint32_t size,
  799. const uint8_t iv[LTC_DES_IV_SIZE],
  800. const uint8_t key1[LTC_DES_KEY_SIZE],
  801. const uint8_t key2[LTC_DES_KEY_SIZE]);
  802. /*!
  803. * @brief Encrypts triple DES using ECB block mode with three keys.
  804. *
  805. * Encrypts triple DES using ECB block mode with three keys.
  806. *
  807. * @param base LTC peripheral base address
  808. * @param plaintext Input plaintext to encrypt
  809. * @param[out] ciphertext Output ciphertext
  810. * @param size Size of input and output data in bytes. Must be multiple of 8 bytes.
  811. * @param key1 First input key for key bundle
  812. * @param key2 Second input key for key bundle
  813. * @param key3 Third input key for key bundle
  814. * @return Status from encrypt/decrypt operation
  815. */
  816. status_t LTC_DES3_EncryptEcb(LTC_Type *base,
  817. const uint8_t *plaintext,
  818. uint8_t *ciphertext,
  819. uint32_t size,
  820. const uint8_t key1[LTC_DES_KEY_SIZE],
  821. const uint8_t key2[LTC_DES_KEY_SIZE],
  822. const uint8_t key3[LTC_DES_KEY_SIZE]);
  823. /*!
  824. * @brief Decrypts triple DES using ECB block mode with three keys.
  825. *
  826. * Decrypts triple DES using ECB block mode with three keys.
  827. *
  828. * @param base LTC peripheral base address
  829. * @param ciphertext Input ciphertext to decrypt
  830. * @param[out] plaintext Output plaintext
  831. * @param size Size of input and output data in bytes. Must be multiple of 8 bytes.
  832. * @param key1 First input key for key bundle
  833. * @param key2 Second input key for key bundle
  834. * @param key3 Third input key for key bundle
  835. * @return Status from encrypt/decrypt operation
  836. */
  837. status_t LTC_DES3_DecryptEcb(LTC_Type *base,
  838. const uint8_t *ciphertext,
  839. uint8_t *plaintext,
  840. uint32_t size,
  841. const uint8_t key1[LTC_DES_KEY_SIZE],
  842. const uint8_t key2[LTC_DES_KEY_SIZE],
  843. const uint8_t key3[LTC_DES_KEY_SIZE]);
  844. /*!
  845. * @brief Encrypts triple DES using CBC block mode with three keys.
  846. *
  847. * Encrypts triple DES using CBC block mode with three keys.
  848. *
  849. * @param base LTC peripheral base address
  850. * @param plaintext Input plaintext to encrypt
  851. * @param[out] ciphertext Output ciphertext
  852. * @param size Size of input data in bytes
  853. * @param iv Input initial vector to combine with the first plaintext block.
  854. * The iv does not need to be secret, but it must be unpredictable.
  855. * @param key1 First input key for key bundle
  856. * @param key2 Second input key for key bundle
  857. * @param key3 Third input key for key bundle
  858. * @return Status from encrypt/decrypt operation
  859. */
  860. status_t LTC_DES3_EncryptCbc(LTC_Type *base,
  861. const uint8_t *plaintext,
  862. uint8_t *ciphertext,
  863. uint32_t size,
  864. const uint8_t iv[LTC_DES_IV_SIZE],
  865. const uint8_t key1[LTC_DES_KEY_SIZE],
  866. const uint8_t key2[LTC_DES_KEY_SIZE],
  867. const uint8_t key3[LTC_DES_KEY_SIZE]);
  868. /*!
  869. * @brief Decrypts triple DES using CBC block mode with three keys.
  870. *
  871. * Decrypts triple DES using CBC block mode with three keys.
  872. *
  873. * @param base LTC peripheral base address
  874. * @param ciphertext Input ciphertext to decrypt
  875. * @param[out] plaintext Output plaintext
  876. * @param size Size of input and output data in bytes
  877. * @param iv Input initial vector to combine with the first plaintext block.
  878. * The iv does not need to be secret, but it must be unpredictable.
  879. * @param key1 First input key for key bundle
  880. * @param key2 Second input key for key bundle
  881. * @param key3 Third input key for key bundle
  882. * @return Status from encrypt/decrypt operation
  883. */
  884. status_t LTC_DES3_DecryptCbc(LTC_Type *base,
  885. const uint8_t *ciphertext,
  886. uint8_t *plaintext,
  887. uint32_t size,
  888. const uint8_t iv[LTC_DES_IV_SIZE],
  889. const uint8_t key1[LTC_DES_KEY_SIZE],
  890. const uint8_t key2[LTC_DES_KEY_SIZE],
  891. const uint8_t key3[LTC_DES_KEY_SIZE]);
  892. /*!
  893. * @brief Encrypts triple DES using CFB block mode with three keys.
  894. *
  895. * Encrypts triple DES using CFB block mode with three keys.
  896. *
  897. * @param base LTC peripheral base address
  898. * @param plaintext Input plaintext to encrypt
  899. * @param[out] ciphertext Output ciphertext
  900. * @param size Size of input and ouput data in bytes
  901. * @param iv Input initial block.
  902. * @param key1 First input key for key bundle
  903. * @param key2 Second input key for key bundle
  904. * @param key3 Third input key for key bundle
  905. * @return Status from encrypt/decrypt operation
  906. */
  907. status_t LTC_DES3_EncryptCfb(LTC_Type *base,
  908. const uint8_t *plaintext,
  909. uint8_t *ciphertext,
  910. uint32_t size,
  911. const uint8_t iv[LTC_DES_IV_SIZE],
  912. const uint8_t key1[LTC_DES_KEY_SIZE],
  913. const uint8_t key2[LTC_DES_KEY_SIZE],
  914. const uint8_t key3[LTC_DES_KEY_SIZE]);
  915. /*!
  916. * @brief Decrypts triple DES using CFB block mode with three keys.
  917. *
  918. * Decrypts triple DES using CFB block mode with three keys.
  919. *
  920. * @param base LTC peripheral base address
  921. * @param ciphertext Input ciphertext to decrypt
  922. * @param[out] plaintext Output plaintext
  923. * @param size Size of input data in bytes
  924. * @param iv Input initial block.
  925. * @param key1 First input key for key bundle
  926. * @param key2 Second input key for key bundle
  927. * @param key3 Third input key for key bundle
  928. * @return Status from encrypt/decrypt operation
  929. */
  930. status_t LTC_DES3_DecryptCfb(LTC_Type *base,
  931. const uint8_t *ciphertext,
  932. uint8_t *plaintext,
  933. uint32_t size,
  934. const uint8_t iv[LTC_DES_IV_SIZE],
  935. const uint8_t key1[LTC_DES_KEY_SIZE],
  936. const uint8_t key2[LTC_DES_KEY_SIZE],
  937. const uint8_t key3[LTC_DES_KEY_SIZE]);
  938. /*!
  939. * @brief Encrypts triple DES using OFB block mode with three keys.
  940. *
  941. * Encrypts triple DES using OFB block mode with three keys.
  942. *
  943. * @param base LTC peripheral base address
  944. * @param plaintext Input plaintext to encrypt
  945. * @param[out] ciphertext Output ciphertext
  946. * @param size Size of input and output data in bytes
  947. * @param iv Input unique input vector. The OFB mode requires that the IV be unique
  948. * for each execution of the mode under the given key.
  949. * @param key1 First input key for key bundle
  950. * @param key2 Second input key for key bundle
  951. * @param key3 Third input key for key bundle
  952. * @return Status from encrypt/decrypt operation
  953. */
  954. status_t LTC_DES3_EncryptOfb(LTC_Type *base,
  955. const uint8_t *plaintext,
  956. uint8_t *ciphertext,
  957. uint32_t size,
  958. const uint8_t iv[LTC_DES_IV_SIZE],
  959. const uint8_t key1[LTC_DES_KEY_SIZE],
  960. const uint8_t key2[LTC_DES_KEY_SIZE],
  961. const uint8_t key3[LTC_DES_KEY_SIZE]);
  962. /*!
  963. * @brief Decrypts triple DES using OFB block mode with three keys.
  964. *
  965. * Decrypts triple DES using OFB block mode with three keys.
  966. *
  967. * @param base LTC peripheral base address
  968. * @param ciphertext Input ciphertext to decrypt
  969. * @param[out] plaintext Output plaintext
  970. * @param size Size of input and output data in bytes
  971. * @param iv Input unique input vector. The OFB mode requires that the IV be unique
  972. * for each execution of the mode under the given key.
  973. * @param key1 First input key for key bundle
  974. * @param key2 Second input key for key bundle
  975. * @param key3 Third input key for key bundle
  976. * @return Status from encrypt/decrypt operation
  977. */
  978. status_t LTC_DES3_DecryptOfb(LTC_Type *base,
  979. const uint8_t *ciphertext,
  980. uint8_t *plaintext,
  981. uint32_t size,
  982. const uint8_t iv[LTC_DES_IV_SIZE],
  983. const uint8_t key1[LTC_DES_KEY_SIZE],
  984. const uint8_t key2[LTC_DES_KEY_SIZE],
  985. const uint8_t key3[LTC_DES_KEY_SIZE]);
  986. /*!
  987. *@}
  988. */
  989. /*******************************************************************************
  990. * HASH API
  991. ******************************************************************************/
  992. /*!
  993. * @addtogroup ltc_driver_hash
  994. * @{
  995. */
  996. /*!
  997. * @brief Initialize HASH context
  998. *
  999. * This function initialize the HASH.
  1000. * Key shall be supplied if the underlaying algoritm is AES XCBC-MAC or CMAC.
  1001. * Key shall be NULL if the underlaying algoritm is SHA.
  1002. *
  1003. * For XCBC-MAC, the key length must be 16. For CMAC, the key length can be
  1004. * the AES key lengths supported by AES engine. For MDHA the key length argument
  1005. * is ignored.
  1006. *
  1007. * @param base LTC peripheral base address
  1008. * @param[out] ctx Output hash context
  1009. * @param algo Underlaying algorithm to use for hash computation.
  1010. * @param key Input key (NULL if underlaying algorithm is SHA)
  1011. * @param keySize Size of input key in bytes
  1012. * @return Status of initialization
  1013. */
  1014. status_t LTC_HASH_Init(LTC_Type *base, ltc_hash_ctx_t *ctx, ltc_hash_algo_t algo, const uint8_t *key, uint32_t keySize);
  1015. /*!
  1016. * @brief Add data to current HASH
  1017. *
  1018. * Add data to current HASH. This can be called repeatedly with an arbitrary amount of data to be
  1019. * hashed.
  1020. *
  1021. * @param[in,out] ctx HASH context
  1022. * @param input Input data
  1023. * @param inputSize Size of input data in bytes
  1024. * @return Status of the hash update operation
  1025. */
  1026. status_t LTC_HASH_Update(ltc_hash_ctx_t *ctx, const uint8_t *input, uint32_t inputSize);
  1027. /*!
  1028. * @brief Finalize hashing
  1029. *
  1030. * Outputs the final hash and erases the context.
  1031. *
  1032. * @param[in,out] ctx Input hash context
  1033. * @param[out] output Output hash data
  1034. * @param[out] outputSize Output parameter storing the size of the output hash in bytes
  1035. * @return Status of the hash finish operation
  1036. */
  1037. status_t LTC_HASH_Finish(ltc_hash_ctx_t *ctx, uint8_t *output, uint32_t *outputSize);
  1038. /*!
  1039. * @brief Create HASH on given data
  1040. *
  1041. * Perform the full keyed HASH in one function call.
  1042. *
  1043. * @param base LTC peripheral base address
  1044. * @param algo Block cipher algorithm to use for CMAC creation
  1045. * @param input Input data
  1046. * @param inputSize Size of input data in bytes
  1047. * @param key Input key
  1048. * @param keySize Size of input key in bytes
  1049. * @param[out] output Output hash data
  1050. * @param[out] outputSize Output parameter storing the size of the output hash in bytes
  1051. * @return Status of the one call hash operation.
  1052. */
  1053. status_t LTC_HASH(LTC_Type *base,
  1054. ltc_hash_algo_t algo,
  1055. const uint8_t *input,
  1056. uint32_t inputSize,
  1057. const uint8_t *key,
  1058. uint32_t keySize,
  1059. uint8_t *output,
  1060. uint32_t *outputSize);
  1061. /*!
  1062. *@}
  1063. */
  1064. /*******************************************************************************
  1065. * PKHA API
  1066. ******************************************************************************/
  1067. /*!
  1068. * @addtogroup ltc_driver_pkha
  1069. * @{
  1070. */
  1071. /*!
  1072. * @brief Compare two PKHA big numbers.
  1073. *
  1074. * Compare two PKHA big numbers. Return 1 for a > b, -1 for a < b and 0 if they are same.
  1075. * PKHA big number is lsbyte first. Thus the comparison starts at msbyte which is the last member of tested arrays.
  1076. *
  1077. * @param a First integer represented as an array of bytes, lsbyte first.
  1078. * @param sizeA Size in bytes of the first integer.
  1079. * @param b Second integer represented as an array of bytes, lsbyte first.
  1080. * @param sizeB Size in bytes of the second integer.
  1081. * @return 1 if a > b.
  1082. * @return -1 if a < b.
  1083. * @return 0 if a = b.
  1084. */
  1085. int LTC_PKHA_CompareBigNum(const uint8_t *a, size_t sizeA, const uint8_t *b, size_t sizeB);
  1086. /*!
  1087. * @brief Converts from integer to Montgomery format.
  1088. *
  1089. * This function computes R2 mod N and optionally converts A or B into Montgomery format of A or B.
  1090. *
  1091. * @param base LTC peripheral base address
  1092. * @param N modulus
  1093. * @param sizeN size of N in bytes
  1094. * @param[in,out] A The first input in non-Montgomery format. Output Montgomery format of the first input.
  1095. * @param[in,out] sizeA pointer to size variable. On input it holds size of input A in bytes. On output it holds size of
  1096. * Montgomery format of A in bytes.
  1097. * @param[in,out] B Second input in non-Montgomery format. Output Montgomery format of the second input.
  1098. * @param[in,out] sizeB pointer to size variable. On input it holds size of input B in bytes. On output it holds size of
  1099. * Montgomery format of B in bytes.
  1100. * @param[out] R2 Output Montgomery factor R2 mod N.
  1101. * @param[out] sizeR2 pointer to size variable. On output it holds size of Montgomery factor R2 mod N in bytes.
  1102. * @param equalTime Run the function time equalized or no timing equalization.
  1103. * @param arithType Type of arithmetic to perform (integer or F2m)
  1104. * @return Operation status.
  1105. */
  1106. status_t LTC_PKHA_NormalToMontgomery(LTC_Type *base,
  1107. const uint8_t *N,
  1108. uint16_t sizeN,
  1109. uint8_t *A,
  1110. uint16_t *sizeA,
  1111. uint8_t *B,
  1112. uint16_t *sizeB,
  1113. uint8_t *R2,
  1114. uint16_t *sizeR2,
  1115. ltc_pkha_timing_t equalTime,
  1116. ltc_pkha_f2m_t arithType);
  1117. /*!
  1118. * @brief Converts from Montgomery format to int.
  1119. *
  1120. * This function converts Montgomery format of A or B into int A or B.
  1121. *
  1122. * @param base LTC peripheral base address
  1123. * @param N modulus.
  1124. * @param sizeN size of N modulus in bytes.
  1125. * @param[in,out] A Input first number in Montgomery format. Output is non-Montgomery format.
  1126. * @param[in,out] sizeA pointer to size variable. On input it holds size of the input A in bytes. On output it holds
  1127. * size of non-Montgomery A in bytes.
  1128. * @param[in,out] B Input first number in Montgomery format. Output is non-Montgomery format.
  1129. * @param[in,out] sizeB pointer to size variable. On input it holds size of the input B in bytes. On output it holds
  1130. * size of non-Montgomery B in bytes.
  1131. * @param equalTime Run the function time equalized or no timing equalization.
  1132. * @param arithType Type of arithmetic to perform (integer or F2m)
  1133. * @return Operation status.
  1134. */
  1135. status_t LTC_PKHA_MontgomeryToNormal(LTC_Type *base,
  1136. const uint8_t *N,
  1137. uint16_t sizeN,
  1138. uint8_t *A,
  1139. uint16_t *sizeA,
  1140. uint8_t *B,
  1141. uint16_t *sizeB,
  1142. ltc_pkha_timing_t equalTime,
  1143. ltc_pkha_f2m_t arithType);
  1144. /*!
  1145. * @brief Performs modular addition - (A + B) mod N.
  1146. *
  1147. * This function performs modular addition of (A + B) mod N, with either
  1148. * integer or binary polynomial (F2m) inputs. In the F2m form, this function is
  1149. * equivalent to a bitwise XOR and it is functionally the same as subtraction.
  1150. *
  1151. * @param base LTC peripheral base address
  1152. * @param A first addend (integer or binary polynomial)
  1153. * @param sizeA Size of A in bytes
  1154. * @param B second addend (integer or binary polynomial)
  1155. * @param sizeB Size of B in bytes
  1156. * @param N modulus. For F2m operation this can be NULL, as N is ignored during F2m polynomial addition.
  1157. * @param sizeN Size of N in bytes. This must be given for both integer and F2m polynomial additions.
  1158. * @param[out] result Output array to store result of operation
  1159. * @param[out] resultSize Output size of operation in bytes
  1160. * @param arithType Type of arithmetic to perform (integer or F2m)
  1161. * @return Operation status.
  1162. */
  1163. status_t LTC_PKHA_ModAdd(LTC_Type *base,
  1164. const uint8_t *A,
  1165. uint16_t sizeA,
  1166. const uint8_t *B,
  1167. uint16_t sizeB,
  1168. const uint8_t *N,
  1169. uint16_t sizeN,
  1170. uint8_t *result,
  1171. uint16_t *resultSize,
  1172. ltc_pkha_f2m_t arithType);
  1173. /*!
  1174. * @brief Performs modular subtraction - (A - B) mod N.
  1175. *
  1176. * This function performs modular subtraction of (A - B) mod N with
  1177. * integer inputs.
  1178. *
  1179. * @param base LTC peripheral base address
  1180. * @param A first addend (integer or binary polynomial)
  1181. * @param sizeA Size of A in bytes
  1182. * @param B second addend (integer or binary polynomial)
  1183. * @param sizeB Size of B in bytes
  1184. * @param N modulus
  1185. * @param sizeN Size of N in bytes
  1186. * @param[out] result Output array to store result of operation
  1187. * @param[out] resultSize Output size of operation in bytes
  1188. * @return Operation status.
  1189. */
  1190. status_t LTC_PKHA_ModSub1(LTC_Type *base,
  1191. const uint8_t *A,
  1192. uint16_t sizeA,
  1193. const uint8_t *B,
  1194. uint16_t sizeB,
  1195. const uint8_t *N,
  1196. uint16_t sizeN,
  1197. uint8_t *result,
  1198. uint16_t *resultSize);
  1199. /*!
  1200. * @brief Performs modular subtraction - (B - A) mod N.
  1201. *
  1202. * This function performs modular subtraction of (B - A) mod N,
  1203. * with integer inputs.
  1204. *
  1205. * @param base LTC peripheral base address
  1206. * @param A first addend (integer or binary polynomial)
  1207. * @param sizeA Size of A in bytes
  1208. * @param B second addend (integer or binary polynomial)
  1209. * @param sizeB Size of B in bytes
  1210. * @param N modulus
  1211. * @param sizeN Size of N in bytes
  1212. * @param[out] result Output array to store result of operation
  1213. * @param[out] resultSize Output size of operation in bytes
  1214. * @return Operation status.
  1215. */
  1216. status_t LTC_PKHA_ModSub2(LTC_Type *base,
  1217. const uint8_t *A,
  1218. uint16_t sizeA,
  1219. const uint8_t *B,
  1220. uint16_t sizeB,
  1221. const uint8_t *N,
  1222. uint16_t sizeN,
  1223. uint8_t *result,
  1224. uint16_t *resultSize);
  1225. /*!
  1226. * @brief Performs modular multiplication - (A x B) mod N.
  1227. *
  1228. * This function performs modular multiplication with either integer or
  1229. * binary polynomial (F2m) inputs. It can optionally specify whether inputs
  1230. * and/or outputs will be in Montgomery form or not.
  1231. *
  1232. * @param base LTC peripheral base address
  1233. * @param A first addend (integer or binary polynomial)
  1234. * @param sizeA Size of A in bytes
  1235. * @param B second addend (integer or binary polynomial)
  1236. * @param sizeB Size of B in bytes
  1237. * @param N modulus.
  1238. * @param sizeN Size of N in bytes
  1239. * @param[out] result Output array to store result of operation
  1240. * @param[out] resultSize Output size of operation in bytes
  1241. * @param arithType Type of arithmetic to perform (integer or F2m)
  1242. * @param montIn Format of inputs
  1243. * @param montOut Format of output
  1244. * @param equalTime Run the function time equalized or no timing equalization. This argument is ignored for F2m modular
  1245. * multiplication.
  1246. * @return Operation status.
  1247. */
  1248. status_t LTC_PKHA_ModMul(LTC_Type *base,
  1249. const uint8_t *A,
  1250. uint16_t sizeA,
  1251. const uint8_t *B,
  1252. uint16_t sizeB,
  1253. const uint8_t *N,
  1254. uint16_t sizeN,
  1255. uint8_t *result,
  1256. uint16_t *resultSize,
  1257. ltc_pkha_f2m_t arithType,
  1258. ltc_pkha_montgomery_form_t montIn,
  1259. ltc_pkha_montgomery_form_t montOut,
  1260. ltc_pkha_timing_t equalTime);
  1261. /*!
  1262. * @brief Performs modular exponentiation - (A^E) mod N.
  1263. *
  1264. * This function performs modular exponentiation with either integer or
  1265. * binary polynomial (F2m) inputs.
  1266. *
  1267. * @param base LTC peripheral base address
  1268. * @param A first addend (integer or binary polynomial)
  1269. * @param sizeA Size of A in bytes
  1270. * @param N modulus
  1271. * @param sizeN Size of N in bytes
  1272. * @param E exponent
  1273. * @param sizeE Size of E in bytes
  1274. * @param[out] result Output array to store result of operation
  1275. * @param[out] resultSize Output size of operation in bytes
  1276. * @param montIn Format of A input (normal or Montgomery)
  1277. * @param arithType Type of arithmetic to perform (integer or F2m)
  1278. * @param equalTime Run the function time equalized or no timing equalization.
  1279. * @return Operation status.
  1280. */
  1281. status_t LTC_PKHA_ModExp(LTC_Type *base,
  1282. const uint8_t *A,
  1283. uint16_t sizeA,
  1284. const uint8_t *N,
  1285. uint16_t sizeN,
  1286. const uint8_t *E,
  1287. uint16_t sizeE,
  1288. uint8_t *result,
  1289. uint16_t *resultSize,
  1290. ltc_pkha_f2m_t arithType,
  1291. ltc_pkha_montgomery_form_t montIn,
  1292. ltc_pkha_timing_t equalTime);
  1293. /*!
  1294. * @brief Performs modular reduction - (A) mod N.
  1295. *
  1296. * This function performs modular reduction with either integer or
  1297. * binary polynomial (F2m) inputs.
  1298. *
  1299. * @param base LTC peripheral base address
  1300. * @param A first addend (integer or binary polynomial)
  1301. * @param sizeA Size of A in bytes
  1302. * @param N modulus
  1303. * @param sizeN Size of N in bytes
  1304. * @param[out] result Output array to store result of operation
  1305. * @param[out] resultSize Output size of operation in bytes
  1306. * @param arithType Type of arithmetic to perform (integer or F2m)
  1307. * @return Operation status.
  1308. */
  1309. status_t LTC_PKHA_ModRed(LTC_Type *base,
  1310. const uint8_t *A,
  1311. uint16_t sizeA,
  1312. const uint8_t *N,
  1313. uint16_t sizeN,
  1314. uint8_t *result,
  1315. uint16_t *resultSize,
  1316. ltc_pkha_f2m_t arithType);
  1317. /*!
  1318. * @brief Performs modular inversion - (A^-1) mod N.
  1319. *
  1320. * This function performs modular inversion with either integer or
  1321. * binary polynomial (F2m) inputs.
  1322. *
  1323. * @param base LTC peripheral base address
  1324. * @param A first addend (integer or binary polynomial)
  1325. * @param sizeA Size of A in bytes
  1326. * @param N modulus
  1327. * @param sizeN Size of N in bytes
  1328. * @param[out] result Output array to store result of operation
  1329. * @param[out] resultSize Output size of operation in bytes
  1330. * @param arithType Type of arithmetic to perform (integer or F2m)
  1331. * @return Operation status.
  1332. */
  1333. status_t LTC_PKHA_ModInv(LTC_Type *base,
  1334. const uint8_t *A,
  1335. uint16_t sizeA,
  1336. const uint8_t *N,
  1337. uint16_t sizeN,
  1338. uint8_t *result,
  1339. uint16_t *resultSize,
  1340. ltc_pkha_f2m_t arithType);
  1341. /*!
  1342. * @brief Computes integer Montgomery factor R^2 mod N.
  1343. *
  1344. * This function computes a constant to assist in converting operands
  1345. * into the Montgomery residue system representation.
  1346. *
  1347. * @param base LTC peripheral base address
  1348. * @param N modulus
  1349. * @param sizeN Size of N in bytes
  1350. * @param[out] result Output array to store result of operation
  1351. * @param[out] resultSize Output size of operation in bytes
  1352. * @param arithType Type of arithmetic to perform (integer or F2m)
  1353. * @return Operation status.
  1354. */
  1355. status_t LTC_PKHA_ModR2(
  1356. LTC_Type *base, const uint8_t *N, uint16_t sizeN, uint8_t *result, uint16_t *resultSize, ltc_pkha_f2m_t arithType);
  1357. /*!
  1358. * @brief Calculates the greatest common divisor - GCD (A, N).
  1359. *
  1360. * This function calculates the greatest common divisor of two inputs with
  1361. * either integer or binary polynomial (F2m) inputs.
  1362. *
  1363. * @param base LTC peripheral base address
  1364. * @param A first value (must be smaller than or equal to N)
  1365. * @param sizeA Size of A in bytes
  1366. * @param N second value (must be non-zero)
  1367. * @param sizeN Size of N in bytes
  1368. * @param[out] result Output array to store result of operation
  1369. * @param[out] resultSize Output size of operation in bytes
  1370. * @param arithType Type of arithmetic to perform (integer or F2m)
  1371. * @return Operation status.
  1372. */
  1373. status_t LTC_PKHA_GCD(LTC_Type *base,
  1374. const uint8_t *A,
  1375. uint16_t sizeA,
  1376. const uint8_t *N,
  1377. uint16_t sizeN,
  1378. uint8_t *result,
  1379. uint16_t *resultSize,
  1380. ltc_pkha_f2m_t arithType);
  1381. /*!
  1382. * @brief Executes Miller-Rabin primality test.
  1383. *
  1384. * This function calculates whether or not a candidate prime number is likely
  1385. * to be a prime.
  1386. *
  1387. * @param base LTC peripheral base address
  1388. * @param A initial random seed
  1389. * @param sizeA Size of A in bytes
  1390. * @param B number of trial runs
  1391. * @param sizeB Size of B in bytes
  1392. * @param N candidate prime integer
  1393. * @param sizeN Size of N in bytes
  1394. * @param[out] res True if the value is likely prime or false otherwise
  1395. * @return Operation status.
  1396. */
  1397. status_t LTC_PKHA_PrimalityTest(LTC_Type *base,
  1398. const uint8_t *A,
  1399. uint16_t sizeA,
  1400. const uint8_t *B,
  1401. uint16_t sizeB,
  1402. const uint8_t *N,
  1403. uint16_t sizeN,
  1404. bool *res);
  1405. /*!
  1406. * @brief Adds elliptic curve points - A + B.
  1407. *
  1408. * This function performs ECC point addition over a prime field (Fp) or binary field (F2m) using
  1409. * affine coordinates.
  1410. *
  1411. * @param base LTC peripheral base address
  1412. * @param A Left-hand point
  1413. * @param B Right-hand point
  1414. * @param N Prime modulus of the field
  1415. * @param R2modN NULL (the function computes R2modN internally) or pointer to pre-computed R2modN (obtained from
  1416. * LTC_PKHA_ModR2() function).
  1417. * @param aCurveParam A parameter from curve equation
  1418. * @param bCurveParam B parameter from curve equation (constant)
  1419. * @param size Size in bytes of curve points and parameters
  1420. * @param arithType Type of arithmetic to perform (integer or F2m)
  1421. * @param[out] result Result point
  1422. * @return Operation status.
  1423. */
  1424. status_t LTC_PKHA_ECC_PointAdd(LTC_Type *base,
  1425. const ltc_pkha_ecc_point_t *A,
  1426. const ltc_pkha_ecc_point_t *B,
  1427. const uint8_t *N,
  1428. const uint8_t *R2modN,
  1429. const uint8_t *aCurveParam,
  1430. const uint8_t *bCurveParam,
  1431. uint8_t size,
  1432. ltc_pkha_f2m_t arithType,
  1433. ltc_pkha_ecc_point_t *result);
  1434. /*!
  1435. * @brief Doubles elliptic curve points - B + B.
  1436. *
  1437. * This function performs ECC point doubling over a prime field (Fp) or binary field (F2m) using
  1438. * affine coordinates.
  1439. *
  1440. * @param base LTC peripheral base address
  1441. * @param B Point to double
  1442. * @param N Prime modulus of the field
  1443. * @param aCurveParam A parameter from curve equation
  1444. * @param bCurveParam B parameter from curve equation (constant)
  1445. * @param size Size in bytes of curve points and parameters
  1446. * @param arithType Type of arithmetic to perform (integer or F2m)
  1447. * @param[out] result Result point
  1448. * @return Operation status.
  1449. */
  1450. status_t LTC_PKHA_ECC_PointDouble(LTC_Type *base,
  1451. const ltc_pkha_ecc_point_t *B,
  1452. const uint8_t *N,
  1453. const uint8_t *aCurveParam,
  1454. const uint8_t *bCurveParam,
  1455. uint8_t size,
  1456. ltc_pkha_f2m_t arithType,
  1457. ltc_pkha_ecc_point_t *result);
  1458. /*!
  1459. * @brief Multiplies an elliptic curve point by a scalar - E x (A0, A1).
  1460. *
  1461. * This function performs ECC point multiplication to multiply an ECC point by
  1462. * a scalar integer multiplier over a prime field (Fp) or a binary field (F2m).
  1463. *
  1464. * @param base LTC peripheral base address
  1465. * @param A Point as multiplicand
  1466. * @param E Scalar multiple
  1467. * @param sizeE The size of E, in bytes
  1468. * @param N Modulus, a prime number for the Fp field or Irreducible polynomial for F2m field.
  1469. * @param R2modN NULL (the function computes R2modN internally) or pointer to pre-computed R2modN (obtained from
  1470. * LTC_PKHA_ModR2() function).
  1471. * @param aCurveParam A parameter from curve equation
  1472. * @param bCurveParam B parameter from curve equation (C parameter for operation over F2m).
  1473. * @param size Size in bytes of curve points and parameters
  1474. * @param equalTime Run the function time equalized or no timing equalization.
  1475. * @param arithType Type of arithmetic to perform (integer or F2m)
  1476. * @param[out] result Result point
  1477. * @param[out] infinity Output true if the result is point of infinity, and false otherwise. Writing of this output will
  1478. * be ignored if the argument is NULL.
  1479. * @return Operation status.
  1480. */
  1481. status_t LTC_PKHA_ECC_PointMul(LTC_Type *base,
  1482. const ltc_pkha_ecc_point_t *A,
  1483. const uint8_t *E,
  1484. uint8_t sizeE,
  1485. const uint8_t *N,
  1486. const uint8_t *R2modN,
  1487. const uint8_t *aCurveParam,
  1488. const uint8_t *bCurveParam,
  1489. uint8_t size,
  1490. ltc_pkha_timing_t equalTime,
  1491. ltc_pkha_f2m_t arithType,
  1492. ltc_pkha_ecc_point_t *result,
  1493. bool *infinity);
  1494. /*!
  1495. *@}
  1496. */
  1497. /*******************************************************************************
  1498. * Private - only used internally to share code between fsl_ltc_edma.c and fsl_ltc.c
  1499. ******************************************************************************/
  1500. /*!
  1501. * @internal
  1502. * @{
  1503. */
  1504. #define LTC_MD_ALG_AES (0x10U) /*!< Bit field value for LTC_MD_ALG: AES */
  1505. #define LTC_MD_ALG_DES (0x20U) /*!< Bit field value for LTC_MD_ALG: DES */
  1506. #define LTC_MD_ALG_TRIPLE_DES (0x21U) /*!< Bit field value for LTC_MD_ALG: 3DES */
  1507. #define LTC_MD_ALG_SHA1 (0x41U) /*!< Bit field value for LTC_MD_ALG: SHA-1 */
  1508. #define LTC_MD_ALG_SHA224 (0x42U) /*!< Bit field value for LTC_MD_ALG: SHA-224 */
  1509. #define LTC_MD_ALG_SHA256 (0x43U) /*!< Bit field value for LTC_MD_ALG: SHA-256 */
  1510. #define LTC_MDPK_ALG_PKHA (0x80U) /*!< Bit field value for LTC_MDPK_ALG: PKHA */
  1511. #define LTC_MD_ENC_DECRYPT (0U) /*!< Bit field value for LTC_MD_ENC: Decrypt. */
  1512. #define LTC_MD_ENC_ENCRYPT (0x1U) /*!< Bit field value for LTC_MD_ENC: Encrypt. */
  1513. #define LTC_MD_AS_UPDATE (0U) /*!< Bit field value for LTC_MD_AS: Update */
  1514. #define LTC_MD_AS_INITIALIZE (0x1U) /*!< Bit field value for LTC_MD_AS: Initialize */
  1515. #define LTC_MD_AS_FINALIZE (0x2U) /*!< Bit field value for LTC_MD_AS: Finalize */
  1516. #define LTC_MD_AS_INIT_FINAL (0x3U) /*!< Bit field value for LTC_MD_AS: Initialize/Finalize */
  1517. /*! Full word representing the actual bit values for the LTC mode register. */
  1518. typedef uint32_t ltc_mode_t;
  1519. typedef enum _ltc_algorithm
  1520. {
  1521. #if defined(FSL_FEATURE_LTC_HAS_PKHA) && FSL_FEATURE_LTC_HAS_PKHA
  1522. kLTC_AlgorithmPKHA = LTC_MDPK_ALG_PKHA << LTC_MD_ALG_SHIFT,
  1523. #endif /* FSL_FEATURE_LTC_HAS_PKHA */
  1524. kLTC_AlgorithmAES = LTC_MD_ALG_AES << LTC_MD_ALG_SHIFT,
  1525. #if defined(FSL_FEATURE_LTC_HAS_DES) && FSL_FEATURE_LTC_HAS_DES
  1526. kLTC_AlgorithmDES = LTC_MD_ALG_DES << LTC_MD_ALG_SHIFT,
  1527. kLTC_Algorithm3DES = LTC_MD_ALG_TRIPLE_DES << LTC_MD_ALG_SHIFT,
  1528. #endif /* FSL_FEATURE_LTC_HAS_DES */
  1529. #if defined(FSL_FEATURE_LTC_HAS_SHA) && FSL_FEATURE_LTC_HAS_SHA
  1530. kLTC_AlgorithmSHA1 = LTC_MD_ALG_SHA1 << LTC_MD_ALG_SHIFT,
  1531. kLTC_AlgorithmSHA224 = LTC_MD_ALG_SHA224 << LTC_MD_ALG_SHIFT,
  1532. kLTC_AlgorithmSHA256 = LTC_MD_ALG_SHA256 << LTC_MD_ALG_SHIFT,
  1533. #endif /* FSL_FEATURE_LTC_HAS_SHA */
  1534. } ltc_algorithm_t;
  1535. typedef enum _ltc_mode_symmetric_alg
  1536. {
  1537. kLTC_ModeCTR = 0x00U << LTC_MD_AAI_SHIFT,
  1538. kLTC_ModeCBC = 0x10U << LTC_MD_AAI_SHIFT,
  1539. kLTC_ModeECB = 0x20U << LTC_MD_AAI_SHIFT,
  1540. kLTC_ModeCFB = 0x30U << LTC_MD_AAI_SHIFT,
  1541. kLTC_ModeOFB = 0x40U << LTC_MD_AAI_SHIFT,
  1542. kLTC_ModeCMAC = 0x60U << LTC_MD_AAI_SHIFT,
  1543. kLTC_ModeXCBCMAC = 0x70U << LTC_MD_AAI_SHIFT,
  1544. kLTC_ModeCCM = 0x80U << LTC_MD_AAI_SHIFT,
  1545. kLTC_ModeGCM = 0x90U << LTC_MD_AAI_SHIFT,
  1546. } ltc_mode_symmetric_alg_t;
  1547. typedef enum _ltc_mode_encrypt
  1548. {
  1549. kLTC_ModeDecrypt = LTC_MD_ENC_DECRYPT << LTC_MD_ENC_SHIFT,
  1550. kLTC_ModeEncrypt = LTC_MD_ENC_ENCRYPT << LTC_MD_ENC_SHIFT,
  1551. } ltc_mode_encrypt_t;
  1552. typedef enum _ltc_mode_algorithm_state
  1553. {
  1554. kLTC_ModeUpdate = LTC_MD_AS_UPDATE << LTC_MD_AS_SHIFT,
  1555. kLTC_ModeInit = LTC_MD_AS_INITIALIZE << LTC_MD_AS_SHIFT,
  1556. kLTC_ModeFinalize = LTC_MD_AS_FINALIZE << LTC_MD_AS_SHIFT,
  1557. kLTC_ModeInitFinal = LTC_MD_AS_INIT_FINAL << LTC_MD_AS_SHIFT
  1558. } ltc_mode_algorithm_state_t;
  1559. extern status_t ltc_get_context(LTC_Type *base, uint8_t *dest, uint8_t dataSize, uint8_t startIndex);
  1560. extern status_t ltc_set_context(LTC_Type *base, const uint8_t *data, uint8_t dataSize, uint8_t startIndex);
  1561. extern status_t ltc_symmetric_update(LTC_Type *base,
  1562. const uint8_t *key,
  1563. uint8_t keySize,
  1564. ltc_algorithm_t alg,
  1565. ltc_mode_symmetric_alg_t mode,
  1566. ltc_mode_encrypt_t enc);
  1567. extern void ltc_memcpy(void *dst, const void *src, size_t size);
  1568. extern bool ltc_check_key_size(const uint32_t keySize);
  1569. extern status_t ltc_wait(LTC_Type *base);
  1570. extern void ltc_clear_all(LTC_Type *base, bool addPKHA);
  1571. extern status_t ltc_3des_check_input_args(ltc_mode_symmetric_alg_t modeAs,
  1572. uint32_t size,
  1573. const uint8_t *key1,
  1574. const uint8_t *key2);
  1575. extern void ltc_symmetric_process(LTC_Type *base, uint32_t inSize, const uint8_t **inData, uint8_t **outData);
  1576. extern status_t ltc_symmetric_process_data(LTC_Type *base, const uint8_t *inData, uint32_t inSize, uint8_t *outData);
  1577. /*!
  1578. *@}
  1579. */
  1580. #if defined(__cplusplus)
  1581. }
  1582. #endif
  1583. /*!
  1584. *@}
  1585. */
  1586. #endif /* _FSL_LTC_H_ */