crypto_values.h 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218
  1. /**
  2. * \file psa/crypto_values.h
  3. *
  4. * \brief PSA cryptography module: macros to build and analyze integer values.
  5. *
  6. * \note This file may not be included directly. Applications must
  7. * include psa/crypto.h. Drivers must include the appropriate driver
  8. * header file.
  9. *
  10. * This file contains portable definitions of macros to build and analyze
  11. * values of integral types that encode properties of cryptographic keys,
  12. * designations of cryptographic algorithms, and error codes returned by
  13. * the library.
  14. *
  15. * This header file only defines preprocessor macros.
  16. */
  17. /*
  18. * Copyright The Mbed TLS Contributors
  19. * SPDX-License-Identifier: Apache-2.0
  20. *
  21. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  22. * not use this file except in compliance with the License.
  23. * You may obtain a copy of the License at
  24. *
  25. * http://www.apache.org/licenses/LICENSE-2.0
  26. *
  27. * Unless required by applicable law or agreed to in writing, software
  28. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  29. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  30. * See the License for the specific language governing permissions and
  31. * limitations under the License.
  32. */
  33. #ifndef PSA_CRYPTO_VALUES_H
  34. #define PSA_CRYPTO_VALUES_H
  35. /** \defgroup error Error codes
  36. * @{
  37. */
  38. /* PSA error codes */
  39. /** The action was completed successfully. */
  40. #define PSA_SUCCESS ((psa_status_t)0)
  41. /** An error occurred that does not correspond to any defined
  42. * failure cause.
  43. *
  44. * Implementations may use this error code if none of the other standard
  45. * error codes are applicable. */
  46. #define PSA_ERROR_GENERIC_ERROR ((psa_status_t)-132)
  47. /** The requested operation or a parameter is not supported
  48. * by this implementation.
  49. *
  50. * Implementations should return this error code when an enumeration
  51. * parameter such as a key type, algorithm, etc. is not recognized.
  52. * If a combination of parameters is recognized and identified as
  53. * not valid, return #PSA_ERROR_INVALID_ARGUMENT instead. */
  54. #define PSA_ERROR_NOT_SUPPORTED ((psa_status_t)-134)
  55. /** The requested action is denied by a policy.
  56. *
  57. * Implementations should return this error code when the parameters
  58. * are recognized as valid and supported, and a policy explicitly
  59. * denies the requested operation.
  60. *
  61. * If a subset of the parameters of a function call identify a
  62. * forbidden operation, and another subset of the parameters are
  63. * not valid or not supported, it is unspecified whether the function
  64. * returns #PSA_ERROR_NOT_PERMITTED, #PSA_ERROR_NOT_SUPPORTED or
  65. * #PSA_ERROR_INVALID_ARGUMENT. */
  66. #define PSA_ERROR_NOT_PERMITTED ((psa_status_t)-133)
  67. /** An output buffer is too small.
  68. *
  69. * Applications can call the \c PSA_xxx_SIZE macro listed in the function
  70. * description to determine a sufficient buffer size.
  71. *
  72. * Implementations should preferably return this error code only
  73. * in cases when performing the operation with a larger output
  74. * buffer would succeed. However implementations may return this
  75. * error if a function has invalid or unsupported parameters in addition
  76. * to the parameters that determine the necessary output buffer size. */
  77. #define PSA_ERROR_BUFFER_TOO_SMALL ((psa_status_t)-138)
  78. /** Asking for an item that already exists
  79. *
  80. * Implementations should return this error, when attempting
  81. * to write an item (like a key) that already exists. */
  82. #define PSA_ERROR_ALREADY_EXISTS ((psa_status_t)-139)
  83. /** Asking for an item that doesn't exist
  84. *
  85. * Implementations should return this error, if a requested item (like
  86. * a key) does not exist. */
  87. #define PSA_ERROR_DOES_NOT_EXIST ((psa_status_t)-140)
  88. /** The requested action cannot be performed in the current state.
  89. *
  90. * Multipart operations return this error when one of the
  91. * functions is called out of sequence. Refer to the function
  92. * descriptions for permitted sequencing of functions.
  93. *
  94. * Implementations shall not return this error code to indicate
  95. * that a key either exists or not,
  96. * but shall instead return #PSA_ERROR_ALREADY_EXISTS or #PSA_ERROR_DOES_NOT_EXIST
  97. * as applicable.
  98. *
  99. * Implementations shall not return this error code to indicate that a
  100. * key identifier is invalid, but shall return #PSA_ERROR_INVALID_HANDLE
  101. * instead. */
  102. #define PSA_ERROR_BAD_STATE ((psa_status_t)-137)
  103. /** The parameters passed to the function are invalid.
  104. *
  105. * Implementations may return this error any time a parameter or
  106. * combination of parameters are recognized as invalid.
  107. *
  108. * Implementations shall not return this error code to indicate that a
  109. * key identifier is invalid, but shall return #PSA_ERROR_INVALID_HANDLE
  110. * instead.
  111. */
  112. #define PSA_ERROR_INVALID_ARGUMENT ((psa_status_t)-135)
  113. /** There is not enough runtime memory.
  114. *
  115. * If the action is carried out across multiple security realms, this
  116. * error can refer to available memory in any of the security realms. */
  117. #define PSA_ERROR_INSUFFICIENT_MEMORY ((psa_status_t)-141)
  118. /** There is not enough persistent storage.
  119. *
  120. * Functions that modify the key storage return this error code if
  121. * there is insufficient storage space on the host media. In addition,
  122. * many functions that do not otherwise access storage may return this
  123. * error code if the implementation requires a mandatory log entry for
  124. * the requested action and the log storage space is full. */
  125. #define PSA_ERROR_INSUFFICIENT_STORAGE ((psa_status_t)-142)
  126. /** There was a communication failure inside the implementation.
  127. *
  128. * This can indicate a communication failure between the application
  129. * and an external cryptoprocessor or between the cryptoprocessor and
  130. * an external volatile or persistent memory. A communication failure
  131. * may be transient or permanent depending on the cause.
  132. *
  133. * \warning If a function returns this error, it is undetermined
  134. * whether the requested action has completed or not. Implementations
  135. * should return #PSA_SUCCESS on successful completion whenever
  136. * possible, however functions may return #PSA_ERROR_COMMUNICATION_FAILURE
  137. * if the requested action was completed successfully in an external
  138. * cryptoprocessor but there was a breakdown of communication before
  139. * the cryptoprocessor could report the status to the application.
  140. */
  141. #define PSA_ERROR_COMMUNICATION_FAILURE ((psa_status_t)-145)
  142. /** There was a storage failure that may have led to data loss.
  143. *
  144. * This error indicates that some persistent storage is corrupted.
  145. * It should not be used for a corruption of volatile memory
  146. * (use #PSA_ERROR_CORRUPTION_DETECTED), for a communication error
  147. * between the cryptoprocessor and its external storage (use
  148. * #PSA_ERROR_COMMUNICATION_FAILURE), or when the storage is
  149. * in a valid state but is full (use #PSA_ERROR_INSUFFICIENT_STORAGE).
  150. *
  151. * Note that a storage failure does not indicate that any data that was
  152. * previously read is invalid. However this previously read data may no
  153. * longer be readable from storage.
  154. *
  155. * When a storage failure occurs, it is no longer possible to ensure
  156. * the global integrity of the keystore. Depending on the global
  157. * integrity guarantees offered by the implementation, access to other
  158. * data may or may not fail even if the data is still readable but
  159. * its integrity cannot be guaranteed.
  160. *
  161. * Implementations should only use this error code to report a
  162. * permanent storage corruption. However application writers should
  163. * keep in mind that transient errors while reading the storage may be
  164. * reported using this error code. */
  165. #define PSA_ERROR_STORAGE_FAILURE ((psa_status_t)-146)
  166. /** A hardware failure was detected.
  167. *
  168. * A hardware failure may be transient or permanent depending on the
  169. * cause. */
  170. #define PSA_ERROR_HARDWARE_FAILURE ((psa_status_t)-147)
  171. /** A tampering attempt was detected.
  172. *
  173. * If an application receives this error code, there is no guarantee
  174. * that previously accessed or computed data was correct and remains
  175. * confidential. Applications should not perform any security function
  176. * and should enter a safe failure state.
  177. *
  178. * Implementations may return this error code if they detect an invalid
  179. * state that cannot happen during normal operation and that indicates
  180. * that the implementation's security guarantees no longer hold. Depending
  181. * on the implementation architecture and on its security and safety goals,
  182. * the implementation may forcibly terminate the application.
  183. *
  184. * This error code is intended as a last resort when a security breach
  185. * is detected and it is unsure whether the keystore data is still
  186. * protected. Implementations shall only return this error code
  187. * to report an alarm from a tampering detector, to indicate that
  188. * the confidentiality of stored data can no longer be guaranteed,
  189. * or to indicate that the integrity of previously returned data is now
  190. * considered compromised. Implementations shall not use this error code
  191. * to indicate a hardware failure that merely makes it impossible to
  192. * perform the requested operation (use #PSA_ERROR_COMMUNICATION_FAILURE,
  193. * #PSA_ERROR_STORAGE_FAILURE, #PSA_ERROR_HARDWARE_FAILURE,
  194. * #PSA_ERROR_INSUFFICIENT_ENTROPY or other applicable error code
  195. * instead).
  196. *
  197. * This error indicates an attack against the application. Implementations
  198. * shall not return this error code as a consequence of the behavior of
  199. * the application itself. */
  200. #define PSA_ERROR_CORRUPTION_DETECTED ((psa_status_t)-151)
  201. /** There is not enough entropy to generate random data needed
  202. * for the requested action.
  203. *
  204. * This error indicates a failure of a hardware random generator.
  205. * Application writers should note that this error can be returned not
  206. * only by functions whose purpose is to generate random data, such
  207. * as key, IV or nonce generation, but also by functions that execute
  208. * an algorithm with a randomized result, as well as functions that
  209. * use randomization of intermediate computations as a countermeasure
  210. * to certain attacks.
  211. *
  212. * Implementations should avoid returning this error after psa_crypto_init()
  213. * has succeeded. Implementations should generate sufficient
  214. * entropy during initialization and subsequently use a cryptographically
  215. * secure pseudorandom generator (PRNG). However implementations may return
  216. * this error at any time if a policy requires the PRNG to be reseeded
  217. * during normal operation. */
  218. #define PSA_ERROR_INSUFFICIENT_ENTROPY ((psa_status_t)-148)
  219. /** The signature, MAC or hash is incorrect.
  220. *
  221. * Verification functions return this error if the verification
  222. * calculations completed successfully, and the value to be verified
  223. * was determined to be incorrect.
  224. *
  225. * If the value to verify has an invalid size, implementations may return
  226. * either #PSA_ERROR_INVALID_ARGUMENT or #PSA_ERROR_INVALID_SIGNATURE. */
  227. #define PSA_ERROR_INVALID_SIGNATURE ((psa_status_t)-149)
  228. /** The decrypted padding is incorrect.
  229. *
  230. * \warning In some protocols, when decrypting data, it is essential that
  231. * the behavior of the application does not depend on whether the padding
  232. * is correct, down to precise timing. Applications should prefer
  233. * protocols that use authenticated encryption rather than plain
  234. * encryption. If the application must perform a decryption of
  235. * unauthenticated data, the application writer should take care not
  236. * to reveal whether the padding is invalid.
  237. *
  238. * Implementations should strive to make valid and invalid padding
  239. * as close as possible to indistinguishable to an external observer.
  240. * In particular, the timing of a decryption operation should not
  241. * depend on the validity of the padding. */
  242. #define PSA_ERROR_INVALID_PADDING ((psa_status_t)-150)
  243. /** Return this error when there's insufficient data when attempting
  244. * to read from a resource. */
  245. #define PSA_ERROR_INSUFFICIENT_DATA ((psa_status_t)-143)
  246. /** The key identifier is not valid. See also :ref:\`key-handles\`.
  247. */
  248. #define PSA_ERROR_INVALID_HANDLE ((psa_status_t)-136)
  249. /** Stored data has been corrupted.
  250. *
  251. * This error indicates that some persistent storage has suffered corruption.
  252. * It does not indicate the following situations, which have specific error
  253. * codes:
  254. *
  255. * - A corruption of volatile memory - use #PSA_ERROR_CORRUPTION_DETECTED.
  256. * - A communication error between the cryptoprocessor and its external
  257. * storage - use #PSA_ERROR_COMMUNICATION_FAILURE.
  258. * - When the storage is in a valid state but is full - use
  259. * #PSA_ERROR_INSUFFICIENT_STORAGE.
  260. * - When the storage fails for other reasons - use
  261. * #PSA_ERROR_STORAGE_FAILURE.
  262. * - When the stored data is not valid - use #PSA_ERROR_DATA_INVALID.
  263. *
  264. * \note A storage corruption does not indicate that any data that was
  265. * previously read is invalid. However this previously read data might no
  266. * longer be readable from storage.
  267. *
  268. * When a storage failure occurs, it is no longer possible to ensure the
  269. * global integrity of the keystore.
  270. */
  271. #define PSA_ERROR_DATA_CORRUPT ((psa_status_t)-152)
  272. /** Data read from storage is not valid for the implementation.
  273. *
  274. * This error indicates that some data read from storage does not have a valid
  275. * format. It does not indicate the following situations, which have specific
  276. * error codes:
  277. *
  278. * - When the storage or stored data is corrupted - use #PSA_ERROR_DATA_CORRUPT
  279. * - When the storage fails for other reasons - use #PSA_ERROR_STORAGE_FAILURE
  280. * - An invalid argument to the API - use #PSA_ERROR_INVALID_ARGUMENT
  281. *
  282. * This error is typically a result of either storage corruption on a
  283. * cleartext storage backend, or an attempt to read data that was
  284. * written by an incompatible version of the library.
  285. */
  286. #define PSA_ERROR_DATA_INVALID ((psa_status_t)-153)
  287. /**@}*/
  288. /** \defgroup crypto_types Key and algorithm types
  289. * @{
  290. */
  291. /** An invalid key type value.
  292. *
  293. * Zero is not the encoding of any key type.
  294. */
  295. #define PSA_KEY_TYPE_NONE ((psa_key_type_t)0x0000)
  296. /** Vendor-defined key type flag.
  297. *
  298. * Key types defined by this standard will never have the
  299. * #PSA_KEY_TYPE_VENDOR_FLAG bit set. Vendors who define additional key types
  300. * must use an encoding with the #PSA_KEY_TYPE_VENDOR_FLAG bit set and should
  301. * respect the bitwise structure used by standard encodings whenever practical.
  302. */
  303. #define PSA_KEY_TYPE_VENDOR_FLAG ((psa_key_type_t)0x8000)
  304. #define PSA_KEY_TYPE_CATEGORY_MASK ((psa_key_type_t)0x7000)
  305. #define PSA_KEY_TYPE_CATEGORY_RAW ((psa_key_type_t)0x1000)
  306. #define PSA_KEY_TYPE_CATEGORY_SYMMETRIC ((psa_key_type_t)0x2000)
  307. #define PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY ((psa_key_type_t)0x4000)
  308. #define PSA_KEY_TYPE_CATEGORY_KEY_PAIR ((psa_key_type_t)0x7000)
  309. #define PSA_KEY_TYPE_CATEGORY_FLAG_PAIR ((psa_key_type_t)0x3000)
  310. /** Whether a key type is vendor-defined.
  311. *
  312. * See also #PSA_KEY_TYPE_VENDOR_FLAG.
  313. */
  314. #define PSA_KEY_TYPE_IS_VENDOR_DEFINED(type) \
  315. (((type) & PSA_KEY_TYPE_VENDOR_FLAG) != 0)
  316. /** Whether a key type is an unstructured array of bytes.
  317. *
  318. * This encompasses both symmetric keys and non-key data.
  319. */
  320. #define PSA_KEY_TYPE_IS_UNSTRUCTURED(type) \
  321. (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_RAW || \
  322. ((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_SYMMETRIC)
  323. /** Whether a key type is asymmetric: either a key pair or a public key. */
  324. #define PSA_KEY_TYPE_IS_ASYMMETRIC(type) \
  325. (((type) & PSA_KEY_TYPE_CATEGORY_MASK \
  326. & ~PSA_KEY_TYPE_CATEGORY_FLAG_PAIR) == \
  327. PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY)
  328. /** Whether a key type is the public part of a key pair. */
  329. #define PSA_KEY_TYPE_IS_PUBLIC_KEY(type) \
  330. (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY)
  331. /** Whether a key type is a key pair containing a private part and a public
  332. * part. */
  333. #define PSA_KEY_TYPE_IS_KEY_PAIR(type) \
  334. (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_KEY_PAIR)
  335. /** The key pair type corresponding to a public key type.
  336. *
  337. * You may also pass a key pair type as \p type, it will be left unchanged.
  338. *
  339. * \param type A public key type or key pair type.
  340. *
  341. * \return The corresponding key pair type.
  342. * If \p type is not a public key or a key pair,
  343. * the return value is undefined.
  344. */
  345. #define PSA_KEY_TYPE_KEY_PAIR_OF_PUBLIC_KEY(type) \
  346. ((type) | PSA_KEY_TYPE_CATEGORY_FLAG_PAIR)
  347. /** The public key type corresponding to a key pair type.
  348. *
  349. * You may also pass a key pair type as \p type, it will be left unchanged.
  350. *
  351. * \param type A public key type or key pair type.
  352. *
  353. * \return The corresponding public key type.
  354. * If \p type is not a public key or a key pair,
  355. * the return value is undefined.
  356. */
  357. #define PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) \
  358. ((type) & ~PSA_KEY_TYPE_CATEGORY_FLAG_PAIR)
  359. /** Raw data.
  360. *
  361. * A "key" of this type cannot be used for any cryptographic operation.
  362. * Applications may use this type to store arbitrary data in the keystore. */
  363. #define PSA_KEY_TYPE_RAW_DATA ((psa_key_type_t)0x1001)
  364. /** HMAC key.
  365. *
  366. * The key policy determines which underlying hash algorithm the key can be
  367. * used for.
  368. *
  369. * HMAC keys should generally have the same size as the underlying hash.
  370. * This size can be calculated with #PSA_HASH_LENGTH(\c alg) where
  371. * \c alg is the HMAC algorithm or the underlying hash algorithm. */
  372. #define PSA_KEY_TYPE_HMAC ((psa_key_type_t)0x1100)
  373. /** A secret for key derivation.
  374. *
  375. * The key policy determines which key derivation algorithm the key
  376. * can be used for.
  377. */
  378. #define PSA_KEY_TYPE_DERIVE ((psa_key_type_t)0x1200)
  379. /** Key for a cipher, AEAD or MAC algorithm based on the AES block cipher.
  380. *
  381. * The size of the key can be 16 bytes (AES-128), 24 bytes (AES-192) or
  382. * 32 bytes (AES-256).
  383. */
  384. #define PSA_KEY_TYPE_AES ((psa_key_type_t)0x2400)
  385. /** Key for a cipher or MAC algorithm based on DES or 3DES (Triple-DES).
  386. *
  387. * The size of the key can be 64 bits (single DES), 128 bits (2-key 3DES) or
  388. * 192 bits (3-key 3DES).
  389. *
  390. * Note that single DES and 2-key 3DES are weak and strongly
  391. * deprecated and should only be used to decrypt legacy data. 3-key 3DES
  392. * is weak and deprecated and should only be used in legacy protocols.
  393. */
  394. #define PSA_KEY_TYPE_DES ((psa_key_type_t)0x2301)
  395. /** Key for a cipher, AEAD or MAC algorithm based on the
  396. * Camellia block cipher. */
  397. #define PSA_KEY_TYPE_CAMELLIA ((psa_key_type_t)0x2403)
  398. /** Key for the RC4 stream cipher.
  399. *
  400. * Note that RC4 is weak and deprecated and should only be used in
  401. * legacy protocols. */
  402. #define PSA_KEY_TYPE_ARC4 ((psa_key_type_t)0x2002)
  403. /** Key for the ChaCha20 stream cipher or the Chacha20-Poly1305 AEAD algorithm.
  404. *
  405. * ChaCha20 and the ChaCha20_Poly1305 construction are defined in RFC 7539.
  406. *
  407. * Implementations must support 12-byte nonces, may support 8-byte nonces,
  408. * and should reject other sizes.
  409. */
  410. #define PSA_KEY_TYPE_CHACHA20 ((psa_key_type_t)0x2004)
  411. /** RSA public key.
  412. *
  413. * The size of an RSA key is the bit size of the modulus.
  414. */
  415. #define PSA_KEY_TYPE_RSA_PUBLIC_KEY ((psa_key_type_t)0x4001)
  416. /** RSA key pair (private and public key).
  417. *
  418. * The size of an RSA key is the bit size of the modulus.
  419. */
  420. #define PSA_KEY_TYPE_RSA_KEY_PAIR ((psa_key_type_t)0x7001)
  421. /** Whether a key type is an RSA key (pair or public-only). */
  422. #define PSA_KEY_TYPE_IS_RSA(type) \
  423. (PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) == PSA_KEY_TYPE_RSA_PUBLIC_KEY)
  424. #define PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE ((psa_key_type_t)0x4100)
  425. #define PSA_KEY_TYPE_ECC_KEY_PAIR_BASE ((psa_key_type_t)0x7100)
  426. #define PSA_KEY_TYPE_ECC_CURVE_MASK ((psa_key_type_t)0x00ff)
  427. /** Elliptic curve key pair.
  428. *
  429. * The size of an elliptic curve key is the bit size associated with the curve,
  430. * i.e. the bit size of *q* for a curve over a field *F<sub>q</sub>*.
  431. * See the documentation of `PSA_ECC_FAMILY_xxx` curve families for details.
  432. *
  433. * \param curve A value of type ::psa_ecc_family_t that
  434. * identifies the ECC curve to be used.
  435. */
  436. #define PSA_KEY_TYPE_ECC_KEY_PAIR(curve) \
  437. (PSA_KEY_TYPE_ECC_KEY_PAIR_BASE | (curve))
  438. /** Elliptic curve public key.
  439. *
  440. * The size of an elliptic curve public key is the same as the corresponding
  441. * private key (see #PSA_KEY_TYPE_ECC_KEY_PAIR and the documentation of
  442. * `PSA_ECC_FAMILY_xxx` curve families).
  443. *
  444. * \param curve A value of type ::psa_ecc_family_t that
  445. * identifies the ECC curve to be used.
  446. */
  447. #define PSA_KEY_TYPE_ECC_PUBLIC_KEY(curve) \
  448. (PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE | (curve))
  449. /** Whether a key type is an elliptic curve key (pair or public-only). */
  450. #define PSA_KEY_TYPE_IS_ECC(type) \
  451. ((PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) & \
  452. ~PSA_KEY_TYPE_ECC_CURVE_MASK) == PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE)
  453. /** Whether a key type is an elliptic curve key pair. */
  454. #define PSA_KEY_TYPE_IS_ECC_KEY_PAIR(type) \
  455. (((type) & ~PSA_KEY_TYPE_ECC_CURVE_MASK) == \
  456. PSA_KEY_TYPE_ECC_KEY_PAIR_BASE)
  457. /** Whether a key type is an elliptic curve public key. */
  458. #define PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(type) \
  459. (((type) & ~PSA_KEY_TYPE_ECC_CURVE_MASK) == \
  460. PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE)
  461. /** Extract the curve from an elliptic curve key type. */
  462. #define PSA_KEY_TYPE_ECC_GET_FAMILY(type) \
  463. ((psa_ecc_family_t) (PSA_KEY_TYPE_IS_ECC(type) ? \
  464. ((type) & PSA_KEY_TYPE_ECC_CURVE_MASK) : \
  465. 0))
  466. /** SEC Koblitz curves over prime fields.
  467. *
  468. * This family comprises the following curves:
  469. * secp192k1, secp224k1, secp256k1.
  470. * They are defined in _Standards for Efficient Cryptography_,
  471. * _SEC 2: Recommended Elliptic Curve Domain Parameters_.
  472. * https://www.secg.org/sec2-v2.pdf
  473. */
  474. #define PSA_ECC_FAMILY_SECP_K1 ((psa_ecc_family_t) 0x17)
  475. /** SEC random curves over prime fields.
  476. *
  477. * This family comprises the following curves:
  478. * secp192k1, secp224r1, secp256r1, secp384r1, secp521r1.
  479. * They are defined in _Standards for Efficient Cryptography_,
  480. * _SEC 2: Recommended Elliptic Curve Domain Parameters_.
  481. * https://www.secg.org/sec2-v2.pdf
  482. */
  483. #define PSA_ECC_FAMILY_SECP_R1 ((psa_ecc_family_t) 0x12)
  484. /* SECP160R2 (SEC2 v1, obsolete) */
  485. #define PSA_ECC_FAMILY_SECP_R2 ((psa_ecc_family_t) 0x1b)
  486. /** SEC Koblitz curves over binary fields.
  487. *
  488. * This family comprises the following curves:
  489. * sect163k1, sect233k1, sect239k1, sect283k1, sect409k1, sect571k1.
  490. * They are defined in _Standards for Efficient Cryptography_,
  491. * _SEC 2: Recommended Elliptic Curve Domain Parameters_.
  492. * https://www.secg.org/sec2-v2.pdf
  493. */
  494. #define PSA_ECC_FAMILY_SECT_K1 ((psa_ecc_family_t) 0x27)
  495. /** SEC random curves over binary fields.
  496. *
  497. * This family comprises the following curves:
  498. * sect163r1, sect233r1, sect283r1, sect409r1, sect571r1.
  499. * They are defined in _Standards for Efficient Cryptography_,
  500. * _SEC 2: Recommended Elliptic Curve Domain Parameters_.
  501. * https://www.secg.org/sec2-v2.pdf
  502. */
  503. #define PSA_ECC_FAMILY_SECT_R1 ((psa_ecc_family_t) 0x22)
  504. /** SEC additional random curves over binary fields.
  505. *
  506. * This family comprises the following curve:
  507. * sect163r2.
  508. * It is defined in _Standards for Efficient Cryptography_,
  509. * _SEC 2: Recommended Elliptic Curve Domain Parameters_.
  510. * https://www.secg.org/sec2-v2.pdf
  511. */
  512. #define PSA_ECC_FAMILY_SECT_R2 ((psa_ecc_family_t) 0x2b)
  513. /** Brainpool P random curves.
  514. *
  515. * This family comprises the following curves:
  516. * brainpoolP160r1, brainpoolP192r1, brainpoolP224r1, brainpoolP256r1,
  517. * brainpoolP320r1, brainpoolP384r1, brainpoolP512r1.
  518. * It is defined in RFC 5639.
  519. */
  520. #define PSA_ECC_FAMILY_BRAINPOOL_P_R1 ((psa_ecc_family_t) 0x30)
  521. /** Curve25519 and Curve448.
  522. *
  523. * This family comprises the following Montgomery curves:
  524. * - 255-bit: Bernstein et al.,
  525. * _Curve25519: new Diffie-Hellman speed records_, LNCS 3958, 2006.
  526. * The algorithm #PSA_ALG_ECDH performs X25519 when used with this curve.
  527. * - 448-bit: Hamburg,
  528. * _Ed448-Goldilocks, a new elliptic curve_, NIST ECC Workshop, 2015.
  529. * The algorithm #PSA_ALG_ECDH performs X448 when used with this curve.
  530. */
  531. #define PSA_ECC_FAMILY_MONTGOMERY ((psa_ecc_family_t) 0x41)
  532. /** The twisted Edwards curves Ed25519 and Ed448.
  533. *
  534. * These curves are suitable for EdDSA (#PSA_ALG_PURE_EDDSA for both curves,
  535. * #PSA_ALG_ED25519PH for the 255-bit curve,
  536. * #PSA_ALG_ED448PH for the 448-bit curve).
  537. *
  538. * This family comprises the following twisted Edwards curves:
  539. * - 255-bit: Edwards25519, the twisted Edwards curve birationally equivalent
  540. * to Curve25519.
  541. * Bernstein et al., _Twisted Edwards curves_, Africacrypt 2008.
  542. * - 448-bit: Edwards448, the twisted Edwards curve birationally equivalent
  543. * to Curve448.
  544. * Hamburg, _Ed448-Goldilocks, a new elliptic curve_, NIST ECC Workshop, 2015.
  545. */
  546. #define PSA_ECC_FAMILY_TWISTED_EDWARDS ((psa_ecc_family_t) 0x42)
  547. #define PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE ((psa_key_type_t)0x4200)
  548. #define PSA_KEY_TYPE_DH_KEY_PAIR_BASE ((psa_key_type_t)0x7200)
  549. #define PSA_KEY_TYPE_DH_GROUP_MASK ((psa_key_type_t)0x00ff)
  550. /** Diffie-Hellman key pair.
  551. *
  552. * \param group A value of type ::psa_dh_family_t that identifies the
  553. * Diffie-Hellman group to be used.
  554. */
  555. #define PSA_KEY_TYPE_DH_KEY_PAIR(group) \
  556. (PSA_KEY_TYPE_DH_KEY_PAIR_BASE | (group))
  557. /** Diffie-Hellman public key.
  558. *
  559. * \param group A value of type ::psa_dh_family_t that identifies the
  560. * Diffie-Hellman group to be used.
  561. */
  562. #define PSA_KEY_TYPE_DH_PUBLIC_KEY(group) \
  563. (PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE | (group))
  564. /** Whether a key type is a Diffie-Hellman key (pair or public-only). */
  565. #define PSA_KEY_TYPE_IS_DH(type) \
  566. ((PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) & \
  567. ~PSA_KEY_TYPE_DH_GROUP_MASK) == PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE)
  568. /** Whether a key type is a Diffie-Hellman key pair. */
  569. #define PSA_KEY_TYPE_IS_DH_KEY_PAIR(type) \
  570. (((type) & ~PSA_KEY_TYPE_DH_GROUP_MASK) == \
  571. PSA_KEY_TYPE_DH_KEY_PAIR_BASE)
  572. /** Whether a key type is a Diffie-Hellman public key. */
  573. #define PSA_KEY_TYPE_IS_DH_PUBLIC_KEY(type) \
  574. (((type) & ~PSA_KEY_TYPE_DH_GROUP_MASK) == \
  575. PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE)
  576. /** Extract the group from a Diffie-Hellman key type. */
  577. #define PSA_KEY_TYPE_DH_GET_FAMILY(type) \
  578. ((psa_dh_family_t) (PSA_KEY_TYPE_IS_DH(type) ? \
  579. ((type) & PSA_KEY_TYPE_DH_GROUP_MASK) : \
  580. 0))
  581. /** Diffie-Hellman groups defined in RFC 7919 Appendix A.
  582. *
  583. * This family includes groups with the following key sizes (in bits):
  584. * 2048, 3072, 4096, 6144, 8192. A given implementation may support
  585. * all of these sizes or only a subset.
  586. */
  587. #define PSA_DH_FAMILY_RFC7919 ((psa_dh_family_t) 0x03)
  588. #define PSA_GET_KEY_TYPE_BLOCK_SIZE_EXPONENT(type) \
  589. (((type) >> 8) & 7)
  590. /** The block size of a block cipher.
  591. *
  592. * \param type A cipher key type (value of type #psa_key_type_t).
  593. *
  594. * \return The block size for a block cipher, or 1 for a stream cipher.
  595. * The return value is undefined if \p type is not a supported
  596. * cipher key type.
  597. *
  598. * \note It is possible to build stream cipher algorithms on top of a block
  599. * cipher, for example CTR mode (#PSA_ALG_CTR).
  600. * This macro only takes the key type into account, so it cannot be
  601. * used to determine the size of the data that #psa_cipher_update()
  602. * might buffer for future processing in general.
  603. *
  604. * \note This macro returns a compile-time constant if its argument is one.
  605. *
  606. * \warning This macro may evaluate its argument multiple times.
  607. */
  608. #define PSA_BLOCK_CIPHER_BLOCK_LENGTH(type) \
  609. (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_SYMMETRIC ? \
  610. 1u << PSA_GET_KEY_TYPE_BLOCK_SIZE_EXPONENT(type) : \
  611. 0u)
  612. /** Vendor-defined algorithm flag.
  613. *
  614. * Algorithms defined by this standard will never have the #PSA_ALG_VENDOR_FLAG
  615. * bit set. Vendors who define additional algorithms must use an encoding with
  616. * the #PSA_ALG_VENDOR_FLAG bit set and should respect the bitwise structure
  617. * used by standard encodings whenever practical.
  618. */
  619. #define PSA_ALG_VENDOR_FLAG ((psa_algorithm_t)0x80000000)
  620. #define PSA_ALG_CATEGORY_MASK ((psa_algorithm_t)0x7f000000)
  621. #define PSA_ALG_CATEGORY_HASH ((psa_algorithm_t)0x02000000)
  622. #define PSA_ALG_CATEGORY_MAC ((psa_algorithm_t)0x03000000)
  623. #define PSA_ALG_CATEGORY_CIPHER ((psa_algorithm_t)0x04000000)
  624. #define PSA_ALG_CATEGORY_AEAD ((psa_algorithm_t)0x05000000)
  625. #define PSA_ALG_CATEGORY_SIGN ((psa_algorithm_t)0x06000000)
  626. #define PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION ((psa_algorithm_t)0x07000000)
  627. #define PSA_ALG_CATEGORY_KEY_DERIVATION ((psa_algorithm_t)0x08000000)
  628. #define PSA_ALG_CATEGORY_KEY_AGREEMENT ((psa_algorithm_t)0x09000000)
  629. /** Whether an algorithm is vendor-defined.
  630. *
  631. * See also #PSA_ALG_VENDOR_FLAG.
  632. */
  633. #define PSA_ALG_IS_VENDOR_DEFINED(alg) \
  634. (((alg) & PSA_ALG_VENDOR_FLAG) != 0)
  635. /** Whether the specified algorithm is a hash algorithm.
  636. *
  637. * \param alg An algorithm identifier (value of type #psa_algorithm_t).
  638. *
  639. * \return 1 if \p alg is a hash algorithm, 0 otherwise.
  640. * This macro may return either 0 or 1 if \p alg is not a supported
  641. * algorithm identifier.
  642. */
  643. #define PSA_ALG_IS_HASH(alg) \
  644. (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_HASH)
  645. /** Whether the specified algorithm is a MAC algorithm.
  646. *
  647. * \param alg An algorithm identifier (value of type #psa_algorithm_t).
  648. *
  649. * \return 1 if \p alg is a MAC algorithm, 0 otherwise.
  650. * This macro may return either 0 or 1 if \p alg is not a supported
  651. * algorithm identifier.
  652. */
  653. #define PSA_ALG_IS_MAC(alg) \
  654. (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_MAC)
  655. /** Whether the specified algorithm is a symmetric cipher algorithm.
  656. *
  657. * \param alg An algorithm identifier (value of type #psa_algorithm_t).
  658. *
  659. * \return 1 if \p alg is a symmetric cipher algorithm, 0 otherwise.
  660. * This macro may return either 0 or 1 if \p alg is not a supported
  661. * algorithm identifier.
  662. */
  663. #define PSA_ALG_IS_CIPHER(alg) \
  664. (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_CIPHER)
  665. /** Whether the specified algorithm is an authenticated encryption
  666. * with associated data (AEAD) algorithm.
  667. *
  668. * \param alg An algorithm identifier (value of type #psa_algorithm_t).
  669. *
  670. * \return 1 if \p alg is an AEAD algorithm, 0 otherwise.
  671. * This macro may return either 0 or 1 if \p alg is not a supported
  672. * algorithm identifier.
  673. */
  674. #define PSA_ALG_IS_AEAD(alg) \
  675. (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_AEAD)
  676. /** Whether the specified algorithm is an asymmetric signature algorithm,
  677. * also known as public-key signature algorithm.
  678. *
  679. * \param alg An algorithm identifier (value of type #psa_algorithm_t).
  680. *
  681. * \return 1 if \p alg is an asymmetric signature algorithm, 0 otherwise.
  682. * This macro may return either 0 or 1 if \p alg is not a supported
  683. * algorithm identifier.
  684. */
  685. #define PSA_ALG_IS_SIGN(alg) \
  686. (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_SIGN)
  687. /** Whether the specified algorithm is an asymmetric encryption algorithm,
  688. * also known as public-key encryption algorithm.
  689. *
  690. * \param alg An algorithm identifier (value of type #psa_algorithm_t).
  691. *
  692. * \return 1 if \p alg is an asymmetric encryption algorithm, 0 otherwise.
  693. * This macro may return either 0 or 1 if \p alg is not a supported
  694. * algorithm identifier.
  695. */
  696. #define PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg) \
  697. (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION)
  698. /** Whether the specified algorithm is a key agreement algorithm.
  699. *
  700. * \param alg An algorithm identifier (value of type #psa_algorithm_t).
  701. *
  702. * \return 1 if \p alg is a key agreement algorithm, 0 otherwise.
  703. * This macro may return either 0 or 1 if \p alg is not a supported
  704. * algorithm identifier.
  705. */
  706. #define PSA_ALG_IS_KEY_AGREEMENT(alg) \
  707. (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_KEY_AGREEMENT)
  708. /** Whether the specified algorithm is a key derivation algorithm.
  709. *
  710. * \param alg An algorithm identifier (value of type #psa_algorithm_t).
  711. *
  712. * \return 1 if \p alg is a key derivation algorithm, 0 otherwise.
  713. * This macro may return either 0 or 1 if \p alg is not a supported
  714. * algorithm identifier.
  715. */
  716. #define PSA_ALG_IS_KEY_DERIVATION(alg) \
  717. (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_KEY_DERIVATION)
  718. #define PSA_ALG_HASH_MASK ((psa_algorithm_t)0x000000ff)
  719. /** MD2 */
  720. #define PSA_ALG_MD2 ((psa_algorithm_t)0x02000001)
  721. /** MD4 */
  722. #define PSA_ALG_MD4 ((psa_algorithm_t)0x02000002)
  723. /** MD5 */
  724. #define PSA_ALG_MD5 ((psa_algorithm_t)0x02000003)
  725. /** PSA_ALG_RIPEMD160 */
  726. #define PSA_ALG_RIPEMD160 ((psa_algorithm_t)0x02000004)
  727. /** SHA1 */
  728. #define PSA_ALG_SHA_1 ((psa_algorithm_t)0x02000005)
  729. /** SHA2-224 */
  730. #define PSA_ALG_SHA_224 ((psa_algorithm_t)0x02000008)
  731. /** SHA2-256 */
  732. #define PSA_ALG_SHA_256 ((psa_algorithm_t)0x02000009)
  733. /** SHA2-384 */
  734. #define PSA_ALG_SHA_384 ((psa_algorithm_t)0x0200000a)
  735. /** SHA2-512 */
  736. #define PSA_ALG_SHA_512 ((psa_algorithm_t)0x0200000b)
  737. /** SHA2-512/224 */
  738. #define PSA_ALG_SHA_512_224 ((psa_algorithm_t)0x0200000c)
  739. /** SHA2-512/256 */
  740. #define PSA_ALG_SHA_512_256 ((psa_algorithm_t)0x0200000d)
  741. /** SHA3-224 */
  742. #define PSA_ALG_SHA3_224 ((psa_algorithm_t)0x02000010)
  743. /** SHA3-256 */
  744. #define PSA_ALG_SHA3_256 ((psa_algorithm_t)0x02000011)
  745. /** SHA3-384 */
  746. #define PSA_ALG_SHA3_384 ((psa_algorithm_t)0x02000012)
  747. /** SHA3-512 */
  748. #define PSA_ALG_SHA3_512 ((psa_algorithm_t)0x02000013)
  749. /** The first 512 bits (64 bytes) of the SHAKE256 output.
  750. *
  751. * This is the prehashing for Ed448ph (see #PSA_ALG_ED448PH). For other
  752. * scenarios where a hash function based on SHA3/SHAKE is desired, SHA3-512
  753. * has the same output size and a (theoretically) higher security strength.
  754. */
  755. #define PSA_ALG_SHAKE256_512 ((psa_algorithm_t)0x02000015)
  756. /** In a hash-and-sign algorithm policy, allow any hash algorithm.
  757. *
  758. * This value may be used to form the algorithm usage field of a policy
  759. * for a signature algorithm that is parametrized by a hash. The key
  760. * may then be used to perform operations using the same signature
  761. * algorithm parametrized with any supported hash.
  762. *
  763. * That is, suppose that `PSA_xxx_SIGNATURE` is one of the following macros:
  764. * - #PSA_ALG_RSA_PKCS1V15_SIGN, #PSA_ALG_RSA_PSS,
  765. * - #PSA_ALG_ECDSA, #PSA_ALG_DETERMINISTIC_ECDSA.
  766. * Then you may create and use a key as follows:
  767. * - Set the key usage field using #PSA_ALG_ANY_HASH, for example:
  768. * ```
  769. * psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH); // or VERIFY
  770. * psa_set_key_algorithm(&attributes, PSA_xxx_SIGNATURE(PSA_ALG_ANY_HASH));
  771. * ```
  772. * - Import or generate key material.
  773. * - Call psa_sign_hash() or psa_verify_hash(), passing
  774. * an algorithm built from `PSA_xxx_SIGNATURE` and a specific hash. Each
  775. * call to sign or verify a message may use a different hash.
  776. * ```
  777. * psa_sign_hash(key, PSA_xxx_SIGNATURE(PSA_ALG_SHA_256), ...);
  778. * psa_sign_hash(key, PSA_xxx_SIGNATURE(PSA_ALG_SHA_512), ...);
  779. * psa_sign_hash(key, PSA_xxx_SIGNATURE(PSA_ALG_SHA3_256), ...);
  780. * ```
  781. *
  782. * This value may not be used to build other algorithms that are
  783. * parametrized over a hash. For any valid use of this macro to build
  784. * an algorithm \c alg, #PSA_ALG_IS_HASH_AND_SIGN(\c alg) is true.
  785. *
  786. * This value may not be used to build an algorithm specification to
  787. * perform an operation. It is only valid to build policies.
  788. */
  789. #define PSA_ALG_ANY_HASH ((psa_algorithm_t)0x020000ff)
  790. #define PSA_ALG_MAC_SUBCATEGORY_MASK ((psa_algorithm_t)0x00c00000)
  791. #define PSA_ALG_HMAC_BASE ((psa_algorithm_t)0x03800000)
  792. /** Macro to build an HMAC algorithm.
  793. *
  794. * For example, #PSA_ALG_HMAC(#PSA_ALG_SHA_256) is HMAC-SHA-256.
  795. *
  796. * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
  797. * #PSA_ALG_IS_HASH(\p hash_alg) is true).
  798. *
  799. * \return The corresponding HMAC algorithm.
  800. * \return Unspecified if \p hash_alg is not a supported
  801. * hash algorithm.
  802. */
  803. #define PSA_ALG_HMAC(hash_alg) \
  804. (PSA_ALG_HMAC_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
  805. #define PSA_ALG_HMAC_GET_HASH(hmac_alg) \
  806. (PSA_ALG_CATEGORY_HASH | ((hmac_alg) & PSA_ALG_HASH_MASK))
  807. /** Whether the specified algorithm is an HMAC algorithm.
  808. *
  809. * HMAC is a family of MAC algorithms that are based on a hash function.
  810. *
  811. * \param alg An algorithm identifier (value of type #psa_algorithm_t).
  812. *
  813. * \return 1 if \p alg is an HMAC algorithm, 0 otherwise.
  814. * This macro may return either 0 or 1 if \p alg is not a supported
  815. * algorithm identifier.
  816. */
  817. #define PSA_ALG_IS_HMAC(alg) \
  818. (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_MAC_SUBCATEGORY_MASK)) == \
  819. PSA_ALG_HMAC_BASE)
  820. /* In the encoding of a MAC algorithm, the bits corresponding to
  821. * PSA_ALG_MAC_TRUNCATION_MASK encode the length to which the MAC is
  822. * truncated. As an exception, the value 0 means the untruncated algorithm,
  823. * whatever its length is. The length is encoded in 6 bits, so it can
  824. * reach up to 63; the largest MAC is 64 bytes so its trivial truncation
  825. * to full length is correctly encoded as 0 and any non-trivial truncation
  826. * is correctly encoded as a value between 1 and 63. */
  827. #define PSA_ALG_MAC_TRUNCATION_MASK ((psa_algorithm_t)0x003f0000)
  828. #define PSA_MAC_TRUNCATION_OFFSET 16
  829. /* In the encoding of a MAC algorithm, the bit corresponding to
  830. * #PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG encodes the fact that the algorithm
  831. * is a wildcard algorithm. A key with such wildcard algorithm as permitted
  832. * algorithm policy can be used with any algorithm corresponding to the
  833. * same base class and having a (potentially truncated) MAC length greater or
  834. * equal than the one encoded in #PSA_ALG_MAC_TRUNCATION_MASK. */
  835. #define PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG ((psa_algorithm_t)0x00008000)
  836. /** Macro to build a truncated MAC algorithm.
  837. *
  838. * A truncated MAC algorithm is identical to the corresponding MAC
  839. * algorithm except that the MAC value for the truncated algorithm
  840. * consists of only the first \p mac_length bytes of the MAC value
  841. * for the untruncated algorithm.
  842. *
  843. * \note This macro may allow constructing algorithm identifiers that
  844. * are not valid, either because the specified length is larger
  845. * than the untruncated MAC or because the specified length is
  846. * smaller than permitted by the implementation.
  847. *
  848. * \note It is implementation-defined whether a truncated MAC that
  849. * is truncated to the same length as the MAC of the untruncated
  850. * algorithm is considered identical to the untruncated algorithm
  851. * for policy comparison purposes.
  852. *
  853. * \param mac_alg A MAC algorithm identifier (value of type
  854. * #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p mac_alg)
  855. * is true). This may be a truncated or untruncated
  856. * MAC algorithm.
  857. * \param mac_length Desired length of the truncated MAC in bytes.
  858. * This must be at most the full length of the MAC
  859. * and must be at least an implementation-specified
  860. * minimum. The implementation-specified minimum
  861. * shall not be zero.
  862. *
  863. * \return The corresponding MAC algorithm with the specified
  864. * length.
  865. * \return Unspecified if \p mac_alg is not a supported
  866. * MAC algorithm or if \p mac_length is too small or
  867. * too large for the specified MAC algorithm.
  868. */
  869. #define PSA_ALG_TRUNCATED_MAC(mac_alg, mac_length) \
  870. (((mac_alg) & ~(PSA_ALG_MAC_TRUNCATION_MASK | \
  871. PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG)) | \
  872. ((mac_length) << PSA_MAC_TRUNCATION_OFFSET & PSA_ALG_MAC_TRUNCATION_MASK))
  873. /** Macro to build the base MAC algorithm corresponding to a truncated
  874. * MAC algorithm.
  875. *
  876. * \param mac_alg A MAC algorithm identifier (value of type
  877. * #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p mac_alg)
  878. * is true). This may be a truncated or untruncated
  879. * MAC algorithm.
  880. *
  881. * \return The corresponding base MAC algorithm.
  882. * \return Unspecified if \p mac_alg is not a supported
  883. * MAC algorithm.
  884. */
  885. #define PSA_ALG_FULL_LENGTH_MAC(mac_alg) \
  886. ((mac_alg) & ~(PSA_ALG_MAC_TRUNCATION_MASK | \
  887. PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG))
  888. /** Length to which a MAC algorithm is truncated.
  889. *
  890. * \param mac_alg A MAC algorithm identifier (value of type
  891. * #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p mac_alg)
  892. * is true).
  893. *
  894. * \return Length of the truncated MAC in bytes.
  895. * \return 0 if \p mac_alg is a non-truncated MAC algorithm.
  896. * \return Unspecified if \p mac_alg is not a supported
  897. * MAC algorithm.
  898. */
  899. #define PSA_MAC_TRUNCATED_LENGTH(mac_alg) \
  900. (((mac_alg) & PSA_ALG_MAC_TRUNCATION_MASK) >> PSA_MAC_TRUNCATION_OFFSET)
  901. /** Macro to build a MAC minimum-MAC-length wildcard algorithm.
  902. *
  903. * A minimum-MAC-length MAC wildcard algorithm permits all MAC algorithms
  904. * sharing the same base algorithm, and where the (potentially truncated) MAC
  905. * length of the specific algorithm is equal to or larger then the wildcard
  906. * algorithm's minimum MAC length.
  907. *
  908. * \note When setting the minimum required MAC length to less than the
  909. * smallest MAC length allowed by the base algorithm, this effectively
  910. * becomes an 'any-MAC-length-allowed' policy for that base algorithm.
  911. *
  912. * \param mac_alg A MAC algorithm identifier (value of type
  913. * #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p mac_alg)
  914. * is true).
  915. * \param min_mac_length Desired minimum length of the message authentication
  916. * code in bytes. This must be at most the untruncated
  917. * length of the MAC and must be at least 1.
  918. *
  919. * \return The corresponding MAC wildcard algorithm with the
  920. * specified minimum length.
  921. * \return Unspecified if \p mac_alg is not a supported MAC
  922. * algorithm or if \p min_mac_length is less than 1 or
  923. * too large for the specified MAC algorithm.
  924. */
  925. #define PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(mac_alg, min_mac_length) \
  926. ( PSA_ALG_TRUNCATED_MAC(mac_alg, min_mac_length) | \
  927. PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG )
  928. #define PSA_ALG_CIPHER_MAC_BASE ((psa_algorithm_t)0x03c00000)
  929. /** The CBC-MAC construction over a block cipher
  930. *
  931. * \warning CBC-MAC is insecure in many cases.
  932. * A more secure mode, such as #PSA_ALG_CMAC, is recommended.
  933. */
  934. #define PSA_ALG_CBC_MAC ((psa_algorithm_t)0x03c00100)
  935. /** The CMAC construction over a block cipher */
  936. #define PSA_ALG_CMAC ((psa_algorithm_t)0x03c00200)
  937. /** Whether the specified algorithm is a MAC algorithm based on a block cipher.
  938. *
  939. * \param alg An algorithm identifier (value of type #psa_algorithm_t).
  940. *
  941. * \return 1 if \p alg is a MAC algorithm based on a block cipher, 0 otherwise.
  942. * This macro may return either 0 or 1 if \p alg is not a supported
  943. * algorithm identifier.
  944. */
  945. #define PSA_ALG_IS_BLOCK_CIPHER_MAC(alg) \
  946. (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_MAC_SUBCATEGORY_MASK)) == \
  947. PSA_ALG_CIPHER_MAC_BASE)
  948. #define PSA_ALG_CIPHER_STREAM_FLAG ((psa_algorithm_t)0x00800000)
  949. #define PSA_ALG_CIPHER_FROM_BLOCK_FLAG ((psa_algorithm_t)0x00400000)
  950. /** Whether the specified algorithm is a stream cipher.
  951. *
  952. * A stream cipher is a symmetric cipher that encrypts or decrypts messages
  953. * by applying a bitwise-xor with a stream of bytes that is generated
  954. * from a key.
  955. *
  956. * \param alg An algorithm identifier (value of type #psa_algorithm_t).
  957. *
  958. * \return 1 if \p alg is a stream cipher algorithm, 0 otherwise.
  959. * This macro may return either 0 or 1 if \p alg is not a supported
  960. * algorithm identifier or if it is not a symmetric cipher algorithm.
  961. */
  962. #define PSA_ALG_IS_STREAM_CIPHER(alg) \
  963. (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_CIPHER_STREAM_FLAG)) == \
  964. (PSA_ALG_CATEGORY_CIPHER | PSA_ALG_CIPHER_STREAM_FLAG))
  965. /** The stream cipher mode of a stream cipher algorithm.
  966. *
  967. * The underlying stream cipher is determined by the key type.
  968. * - To use ChaCha20, use a key type of #PSA_KEY_TYPE_CHACHA20.
  969. * - To use ARC4, use a key type of #PSA_KEY_TYPE_ARC4.
  970. */
  971. #define PSA_ALG_STREAM_CIPHER ((psa_algorithm_t)0x04800100)
  972. /** The CTR stream cipher mode.
  973. *
  974. * CTR is a stream cipher which is built from a block cipher.
  975. * The underlying block cipher is determined by the key type.
  976. * For example, to use AES-128-CTR, use this algorithm with
  977. * a key of type #PSA_KEY_TYPE_AES and a length of 128 bits (16 bytes).
  978. */
  979. #define PSA_ALG_CTR ((psa_algorithm_t)0x04c01000)
  980. /** The CFB stream cipher mode.
  981. *
  982. * The underlying block cipher is determined by the key type.
  983. */
  984. #define PSA_ALG_CFB ((psa_algorithm_t)0x04c01100)
  985. /** The OFB stream cipher mode.
  986. *
  987. * The underlying block cipher is determined by the key type.
  988. */
  989. #define PSA_ALG_OFB ((psa_algorithm_t)0x04c01200)
  990. /** The XTS cipher mode.
  991. *
  992. * XTS is a cipher mode which is built from a block cipher. It requires at
  993. * least one full block of input, but beyond this minimum the input
  994. * does not need to be a whole number of blocks.
  995. */
  996. #define PSA_ALG_XTS ((psa_algorithm_t)0x0440ff00)
  997. /** The Electronic Code Book (ECB) mode of a block cipher, with no padding.
  998. *
  999. * \warning ECB mode does not protect the confidentiality of the encrypted data
  1000. * except in extremely narrow circumstances. It is recommended that applications
  1001. * only use ECB if they need to construct an operating mode that the
  1002. * implementation does not provide. Implementations are encouraged to provide
  1003. * the modes that applications need in preference to supporting direct access
  1004. * to ECB.
  1005. *
  1006. * The underlying block cipher is determined by the key type.
  1007. *
  1008. * This symmetric cipher mode can only be used with messages whose lengths are a
  1009. * multiple of the block size of the chosen block cipher.
  1010. *
  1011. * ECB mode does not accept an initialization vector (IV). When using a
  1012. * multi-part cipher operation with this algorithm, psa_cipher_generate_iv()
  1013. * and psa_cipher_set_iv() must not be called.
  1014. */
  1015. #define PSA_ALG_ECB_NO_PADDING ((psa_algorithm_t)0x04404400)
  1016. /** The CBC block cipher chaining mode, with no padding.
  1017. *
  1018. * The underlying block cipher is determined by the key type.
  1019. *
  1020. * This symmetric cipher mode can only be used with messages whose lengths
  1021. * are whole number of blocks for the chosen block cipher.
  1022. */
  1023. #define PSA_ALG_CBC_NO_PADDING ((psa_algorithm_t)0x04404000)
  1024. /** The CBC block cipher chaining mode with PKCS#7 padding.
  1025. *
  1026. * The underlying block cipher is determined by the key type.
  1027. *
  1028. * This is the padding method defined by PKCS#7 (RFC 2315) &sect;10.3.
  1029. */
  1030. #define PSA_ALG_CBC_PKCS7 ((psa_algorithm_t)0x04404100)
  1031. #define PSA_ALG_AEAD_FROM_BLOCK_FLAG ((psa_algorithm_t)0x00400000)
  1032. /** Whether the specified algorithm is an AEAD mode on a block cipher.
  1033. *
  1034. * \param alg An algorithm identifier (value of type #psa_algorithm_t).
  1035. *
  1036. * \return 1 if \p alg is an AEAD algorithm which is an AEAD mode based on
  1037. * a block cipher, 0 otherwise.
  1038. * This macro may return either 0 or 1 if \p alg is not a supported
  1039. * algorithm identifier.
  1040. */
  1041. #define PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) \
  1042. (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_AEAD_FROM_BLOCK_FLAG)) == \
  1043. (PSA_ALG_CATEGORY_AEAD | PSA_ALG_AEAD_FROM_BLOCK_FLAG))
  1044. /** The CCM authenticated encryption algorithm.
  1045. *
  1046. * The underlying block cipher is determined by the key type.
  1047. */
  1048. #define PSA_ALG_CCM ((psa_algorithm_t)0x05500100)
  1049. /** The GCM authenticated encryption algorithm.
  1050. *
  1051. * The underlying block cipher is determined by the key type.
  1052. */
  1053. #define PSA_ALG_GCM ((psa_algorithm_t)0x05500200)
  1054. /** The Chacha20-Poly1305 AEAD algorithm.
  1055. *
  1056. * The ChaCha20_Poly1305 construction is defined in RFC 7539.
  1057. *
  1058. * Implementations must support 12-byte nonces, may support 8-byte nonces,
  1059. * and should reject other sizes.
  1060. *
  1061. * Implementations must support 16-byte tags and should reject other sizes.
  1062. */
  1063. #define PSA_ALG_CHACHA20_POLY1305 ((psa_algorithm_t)0x05100500)
  1064. /* In the encoding of a AEAD algorithm, the bits corresponding to
  1065. * PSA_ALG_AEAD_TAG_LENGTH_MASK encode the length of the AEAD tag.
  1066. * The constants for default lengths follow this encoding.
  1067. */
  1068. #define PSA_ALG_AEAD_TAG_LENGTH_MASK ((psa_algorithm_t)0x003f0000)
  1069. #define PSA_AEAD_TAG_LENGTH_OFFSET 16
  1070. /* In the encoding of an AEAD algorithm, the bit corresponding to
  1071. * #PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG encodes the fact that the algorithm
  1072. * is a wildcard algorithm. A key with such wildcard algorithm as permitted
  1073. * algorithm policy can be used with any algorithm corresponding to the
  1074. * same base class and having a tag length greater than or equal to the one
  1075. * encoded in #PSA_ALG_AEAD_TAG_LENGTH_MASK. */
  1076. #define PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG ((psa_algorithm_t)0x00008000)
  1077. /** Macro to build a shortened AEAD algorithm.
  1078. *
  1079. * A shortened AEAD algorithm is similar to the corresponding AEAD
  1080. * algorithm, but has an authentication tag that consists of fewer bytes.
  1081. * Depending on the algorithm, the tag length may affect the calculation
  1082. * of the ciphertext.
  1083. *
  1084. * \param aead_alg An AEAD algorithm identifier (value of type
  1085. * #psa_algorithm_t such that #PSA_ALG_IS_AEAD(\p aead_alg)
  1086. * is true).
  1087. * \param tag_length Desired length of the authentication tag in bytes.
  1088. *
  1089. * \return The corresponding AEAD algorithm with the specified
  1090. * length.
  1091. * \return Unspecified if \p aead_alg is not a supported
  1092. * AEAD algorithm or if \p tag_length is not valid
  1093. * for the specified AEAD algorithm.
  1094. */
  1095. #define PSA_ALG_AEAD_WITH_SHORTENED_TAG(aead_alg, tag_length) \
  1096. (((aead_alg) & ~(PSA_ALG_AEAD_TAG_LENGTH_MASK | \
  1097. PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG)) | \
  1098. ((tag_length) << PSA_AEAD_TAG_LENGTH_OFFSET & \
  1099. PSA_ALG_AEAD_TAG_LENGTH_MASK))
  1100. /** Retrieve the tag length of a specified AEAD algorithm
  1101. *
  1102. * \param aead_alg An AEAD algorithm identifier (value of type
  1103. * #psa_algorithm_t such that #PSA_ALG_IS_AEAD(\p aead_alg)
  1104. * is true).
  1105. *
  1106. * \return The tag length specified by the input algorithm.
  1107. * \return Unspecified if \p aead_alg is not a supported
  1108. * AEAD algorithm.
  1109. */
  1110. #define PSA_ALG_AEAD_GET_TAG_LENGTH(aead_alg) \
  1111. (((aead_alg) & PSA_ALG_AEAD_TAG_LENGTH_MASK) >> \
  1112. PSA_AEAD_TAG_LENGTH_OFFSET )
  1113. /** Calculate the corresponding AEAD algorithm with the default tag length.
  1114. *
  1115. * \param aead_alg An AEAD algorithm (\c PSA_ALG_XXX value such that
  1116. * #PSA_ALG_IS_AEAD(\p aead_alg) is true).
  1117. *
  1118. * \return The corresponding AEAD algorithm with the default
  1119. * tag length for that algorithm.
  1120. */
  1121. #define PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(aead_alg) \
  1122. ( \
  1123. PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG_CASE(aead_alg, PSA_ALG_CCM) \
  1124. PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG_CASE(aead_alg, PSA_ALG_GCM) \
  1125. PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG_CASE(aead_alg, PSA_ALG_CHACHA20_POLY1305) \
  1126. 0)
  1127. #define PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG_CASE(aead_alg, ref) \
  1128. PSA_ALG_AEAD_WITH_SHORTENED_TAG(aead_alg, 0) == \
  1129. PSA_ALG_AEAD_WITH_SHORTENED_TAG(ref, 0) ? \
  1130. ref :
  1131. /** Macro to build an AEAD minimum-tag-length wildcard algorithm.
  1132. *
  1133. * A minimum-tag-length AEAD wildcard algorithm permits all AEAD algorithms
  1134. * sharing the same base algorithm, and where the tag length of the specific
  1135. * algorithm is equal to or larger then the minimum tag length specified by the
  1136. * wildcard algorithm.
  1137. *
  1138. * \note When setting the minimum required tag length to less than the
  1139. * smallest tag length allowed by the base algorithm, this effectively
  1140. * becomes an 'any-tag-length-allowed' policy for that base algorithm.
  1141. *
  1142. * \param aead_alg An AEAD algorithm identifier (value of type
  1143. * #psa_algorithm_t such that
  1144. * #PSA_ALG_IS_AEAD(\p aead_alg) is true).
  1145. * \param min_tag_length Desired minimum length of the authentication tag in
  1146. * bytes. This must be at least 1 and at most the largest
  1147. * allowed tag length of the algorithm.
  1148. *
  1149. * \return The corresponding AEAD wildcard algorithm with the
  1150. * specified minimum length.
  1151. * \return Unspecified if \p aead_alg is not a supported
  1152. * AEAD algorithm or if \p min_tag_length is less than 1
  1153. * or too large for the specified AEAD algorithm.
  1154. */
  1155. #define PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(aead_alg, min_tag_length) \
  1156. ( PSA_ALG_AEAD_WITH_SHORTENED_TAG(aead_alg, min_tag_length) | \
  1157. PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG )
  1158. #define PSA_ALG_RSA_PKCS1V15_SIGN_BASE ((psa_algorithm_t)0x06000200)
  1159. /** RSA PKCS#1 v1.5 signature with hashing.
  1160. *
  1161. * This is the signature scheme defined by RFC 8017
  1162. * (PKCS#1: RSA Cryptography Specifications) under the name
  1163. * RSASSA-PKCS1-v1_5.
  1164. *
  1165. * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
  1166. * #PSA_ALG_IS_HASH(\p hash_alg) is true).
  1167. * This includes #PSA_ALG_ANY_HASH
  1168. * when specifying the algorithm in a usage policy.
  1169. *
  1170. * \return The corresponding RSA PKCS#1 v1.5 signature algorithm.
  1171. * \return Unspecified if \p hash_alg is not a supported
  1172. * hash algorithm.
  1173. */
  1174. #define PSA_ALG_RSA_PKCS1V15_SIGN(hash_alg) \
  1175. (PSA_ALG_RSA_PKCS1V15_SIGN_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
  1176. /** Raw PKCS#1 v1.5 signature.
  1177. *
  1178. * The input to this algorithm is the DigestInfo structure used by
  1179. * RFC 8017 (PKCS#1: RSA Cryptography Specifications), &sect;9.2
  1180. * steps 3&ndash;6.
  1181. */
  1182. #define PSA_ALG_RSA_PKCS1V15_SIGN_RAW PSA_ALG_RSA_PKCS1V15_SIGN_BASE
  1183. #define PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) \
  1184. (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_PKCS1V15_SIGN_BASE)
  1185. #define PSA_ALG_RSA_PSS_BASE ((psa_algorithm_t)0x06000300)
  1186. /** RSA PSS signature with hashing.
  1187. *
  1188. * This is the signature scheme defined by RFC 8017
  1189. * (PKCS#1: RSA Cryptography Specifications) under the name
  1190. * RSASSA-PSS, with the message generation function MGF1, and with
  1191. * a salt length equal to the length of the hash. The specified
  1192. * hash algorithm is used to hash the input message, to create the
  1193. * salted hash, and for the mask generation.
  1194. *
  1195. * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
  1196. * #PSA_ALG_IS_HASH(\p hash_alg) is true).
  1197. * This includes #PSA_ALG_ANY_HASH
  1198. * when specifying the algorithm in a usage policy.
  1199. *
  1200. * \return The corresponding RSA PSS signature algorithm.
  1201. * \return Unspecified if \p hash_alg is not a supported
  1202. * hash algorithm.
  1203. */
  1204. #define PSA_ALG_RSA_PSS(hash_alg) \
  1205. (PSA_ALG_RSA_PSS_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
  1206. #define PSA_ALG_IS_RSA_PSS(alg) \
  1207. (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_PSS_BASE)
  1208. #define PSA_ALG_ECDSA_BASE ((psa_algorithm_t)0x06000600)
  1209. /** ECDSA signature with hashing.
  1210. *
  1211. * This is the ECDSA signature scheme defined by ANSI X9.62,
  1212. * with a random per-message secret number (*k*).
  1213. *
  1214. * The representation of the signature as a byte string consists of
  1215. * the concatentation of the signature values *r* and *s*. Each of
  1216. * *r* and *s* is encoded as an *N*-octet string, where *N* is the length
  1217. * of the base point of the curve in octets. Each value is represented
  1218. * in big-endian order (most significant octet first).
  1219. *
  1220. * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
  1221. * #PSA_ALG_IS_HASH(\p hash_alg) is true).
  1222. * This includes #PSA_ALG_ANY_HASH
  1223. * when specifying the algorithm in a usage policy.
  1224. *
  1225. * \return The corresponding ECDSA signature algorithm.
  1226. * \return Unspecified if \p hash_alg is not a supported
  1227. * hash algorithm.
  1228. */
  1229. #define PSA_ALG_ECDSA(hash_alg) \
  1230. (PSA_ALG_ECDSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
  1231. /** ECDSA signature without hashing.
  1232. *
  1233. * This is the same signature scheme as #PSA_ALG_ECDSA(), but
  1234. * without specifying a hash algorithm. This algorithm may only be
  1235. * used to sign or verify a sequence of bytes that should be an
  1236. * already-calculated hash. Note that the input is padded with
  1237. * zeros on the left or truncated on the left as required to fit
  1238. * the curve size.
  1239. */
  1240. #define PSA_ALG_ECDSA_ANY PSA_ALG_ECDSA_BASE
  1241. #define PSA_ALG_DETERMINISTIC_ECDSA_BASE ((psa_algorithm_t)0x06000700)
  1242. /** Deterministic ECDSA signature with hashing.
  1243. *
  1244. * This is the deterministic ECDSA signature scheme defined by RFC 6979.
  1245. *
  1246. * The representation of a signature is the same as with #PSA_ALG_ECDSA().
  1247. *
  1248. * Note that when this algorithm is used for verification, signatures
  1249. * made with randomized ECDSA (#PSA_ALG_ECDSA(\p hash_alg)) with the
  1250. * same private key are accepted. In other words,
  1251. * #PSA_ALG_DETERMINISTIC_ECDSA(\p hash_alg) differs from
  1252. * #PSA_ALG_ECDSA(\p hash_alg) only for signature, not for verification.
  1253. *
  1254. * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
  1255. * #PSA_ALG_IS_HASH(\p hash_alg) is true).
  1256. * This includes #PSA_ALG_ANY_HASH
  1257. * when specifying the algorithm in a usage policy.
  1258. *
  1259. * \return The corresponding deterministic ECDSA signature
  1260. * algorithm.
  1261. * \return Unspecified if \p hash_alg is not a supported
  1262. * hash algorithm.
  1263. */
  1264. #define PSA_ALG_DETERMINISTIC_ECDSA(hash_alg) \
  1265. (PSA_ALG_DETERMINISTIC_ECDSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
  1266. #define PSA_ALG_ECDSA_DETERMINISTIC_FLAG ((psa_algorithm_t)0x00000100)
  1267. #define PSA_ALG_IS_ECDSA(alg) \
  1268. (((alg) & ~PSA_ALG_HASH_MASK & ~PSA_ALG_ECDSA_DETERMINISTIC_FLAG) == \
  1269. PSA_ALG_ECDSA_BASE)
  1270. #define PSA_ALG_ECDSA_IS_DETERMINISTIC(alg) \
  1271. (((alg) & PSA_ALG_ECDSA_DETERMINISTIC_FLAG) != 0)
  1272. #define PSA_ALG_IS_DETERMINISTIC_ECDSA(alg) \
  1273. (PSA_ALG_IS_ECDSA(alg) && PSA_ALG_ECDSA_IS_DETERMINISTIC(alg))
  1274. #define PSA_ALG_IS_RANDOMIZED_ECDSA(alg) \
  1275. (PSA_ALG_IS_ECDSA(alg) && !PSA_ALG_ECDSA_IS_DETERMINISTIC(alg))
  1276. /** Edwards-curve digital signature algorithm without prehashing (PureEdDSA),
  1277. * using standard parameters.
  1278. *
  1279. * Contexts are not supported in the current version of this specification
  1280. * because there is no suitable signature interface that can take the
  1281. * context as a parameter. A future version of this specification may add
  1282. * suitable functions and extend this algorithm to support contexts.
  1283. *
  1284. * PureEdDSA requires an elliptic curve key on a twisted Edwards curve.
  1285. * In this specification, the following curves are supported:
  1286. * - #PSA_ECC_FAMILY_TWISTED_EDWARDS, 255-bit: Ed25519 as specified
  1287. * in RFC 8032.
  1288. * The curve is Edwards25519.
  1289. * The hash function used internally is SHA-512.
  1290. * - #PSA_ECC_FAMILY_TWISTED_EDWARDS, 448-bit: Ed448 as specified
  1291. * in RFC 8032.
  1292. * The curve is Edwards448.
  1293. * The hash function used internally is the first 114 bytes of the
  1294. * SHAKE256 output.
  1295. *
  1296. * This algorithm can be used with psa_sign_message() and
  1297. * psa_verify_message(). Since there is no prehashing, it cannot be used
  1298. * with psa_sign_hash() or psa_verify_hash().
  1299. *
  1300. * The signature format is the concatenation of R and S as defined by
  1301. * RFC 8032 §5.1.6 and §5.2.6 (a 64-byte string for Ed25519, a 114-byte
  1302. * string for Ed448).
  1303. */
  1304. #define PSA_ALG_PURE_EDDSA ((psa_algorithm_t)0x06000800)
  1305. #define PSA_ALG_HASH_EDDSA_BASE ((psa_algorithm_t)0x06000900)
  1306. #define PSA_ALG_IS_HASH_EDDSA(alg) \
  1307. (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_HASH_EDDSA_BASE)
  1308. /** Edwards-curve digital signature algorithm with prehashing (HashEdDSA),
  1309. * using SHA-512 and the Edwards25519 curve.
  1310. *
  1311. * See #PSA_ALG_PURE_EDDSA regarding context support and the signature format.
  1312. *
  1313. * This algorithm is Ed25519 as specified in RFC 8032.
  1314. * The curve is Edwards25519.
  1315. * The prehash is SHA-512.
  1316. * The hash function used internally is SHA-512.
  1317. *
  1318. * This is a hash-and-sign algorithm: to calculate a signature,
  1319. * you can either:
  1320. * - call psa_sign_message() on the message;
  1321. * - or calculate the SHA-512 hash of the message
  1322. * with psa_hash_compute()
  1323. * or with a multi-part hash operation started with psa_hash_setup(),
  1324. * using the hash algorithm #PSA_ALG_SHA_512,
  1325. * then sign the calculated hash with psa_sign_hash().
  1326. * Verifying a signature is similar, using psa_verify_message() or
  1327. * psa_verify_hash() instead of the signature function.
  1328. */
  1329. #define PSA_ALG_ED25519PH \
  1330. (PSA_ALG_HASH_EDDSA_BASE | (PSA_ALG_SHA_512 & PSA_ALG_HASH_MASK))
  1331. /** Edwards-curve digital signature algorithm with prehashing (HashEdDSA),
  1332. * using SHAKE256 and the Edwards448 curve.
  1333. *
  1334. * See #PSA_ALG_PURE_EDDSA regarding context support and the signature format.
  1335. *
  1336. * This algorithm is Ed448 as specified in RFC 8032.
  1337. * The curve is Edwards448.
  1338. * The prehash is the first 64 bytes of the SHAKE256 output.
  1339. * The hash function used internally is the first 114 bytes of the
  1340. * SHAKE256 output.
  1341. *
  1342. * This is a hash-and-sign algorithm: to calculate a signature,
  1343. * you can either:
  1344. * - call psa_sign_message() on the message;
  1345. * - or calculate the first 64 bytes of the SHAKE256 output of the message
  1346. * with psa_hash_compute()
  1347. * or with a multi-part hash operation started with psa_hash_setup(),
  1348. * using the hash algorithm #PSA_ALG_SHAKE256_512,
  1349. * then sign the calculated hash with psa_sign_hash().
  1350. * Verifying a signature is similar, using psa_verify_message() or
  1351. * psa_verify_hash() instead of the signature function.
  1352. */
  1353. #define PSA_ALG_ED448PH \
  1354. (PSA_ALG_HASH_EDDSA_BASE | (PSA_ALG_SHAKE256_512 & PSA_ALG_HASH_MASK))
  1355. /* Default definition, to be overridden if the library is extended with
  1356. * more hash-and-sign algorithms that we want to keep out of this header
  1357. * file. */
  1358. #define PSA_ALG_IS_VENDOR_HASH_AND_SIGN(alg) 0
  1359. /** Whether the specified algorithm is a hash-and-sign algorithm.
  1360. *
  1361. * Hash-and-sign algorithms are asymmetric (public-key) signature algorithms
  1362. * structured in two parts: first the calculation of a hash in a way that
  1363. * does not depend on the key, then the calculation of a signature from the
  1364. * hash value and the key.
  1365. *
  1366. * \param alg An algorithm identifier (value of type #psa_algorithm_t).
  1367. *
  1368. * \return 1 if \p alg is a hash-and-sign algorithm, 0 otherwise.
  1369. * This macro may return either 0 or 1 if \p alg is not a supported
  1370. * algorithm identifier.
  1371. */
  1372. #define PSA_ALG_IS_HASH_AND_SIGN(alg) \
  1373. (PSA_ALG_IS_RSA_PSS(alg) || PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) || \
  1374. PSA_ALG_IS_ECDSA(alg) || PSA_ALG_IS_HASH_EDDSA(alg) || \
  1375. PSA_ALG_IS_VENDOR_HASH_AND_SIGN(alg))
  1376. /** Whether the specified algorithm is a signature algorithm that can be used
  1377. * with psa_sign_message() and psa_verify_message().
  1378. *
  1379. * \param alg An algorithm identifier (value of type #psa_algorithm_t).
  1380. *
  1381. * \return 1 if alg is a signature algorithm that can be used to sign a
  1382. * message. 0 if \p alg is a signature algorithm that can only be used
  1383. * to sign an already-calculated hash. 0 if \p alg is not a signature
  1384. * algorithm. This macro can return either 0 or 1 if \p alg is not a
  1385. * supported algorithm identifier.
  1386. */
  1387. #define PSA_ALG_IS_SIGN_MESSAGE(alg) \
  1388. (PSA_ALG_IS_HASH_AND_SIGN(alg) || (alg) == PSA_ALG_PURE_EDDSA )
  1389. /** Get the hash used by a hash-and-sign signature algorithm.
  1390. *
  1391. * A hash-and-sign algorithm is a signature algorithm which is
  1392. * composed of two phases: first a hashing phase which does not use
  1393. * the key and produces a hash of the input message, then a signing
  1394. * phase which only uses the hash and the key and not the message
  1395. * itself.
  1396. *
  1397. * \param alg A signature algorithm (\c PSA_ALG_XXX value such that
  1398. * #PSA_ALG_IS_SIGN(\p alg) is true).
  1399. *
  1400. * \return The underlying hash algorithm if \p alg is a hash-and-sign
  1401. * algorithm.
  1402. * \return 0 if \p alg is a signature algorithm that does not
  1403. * follow the hash-and-sign structure.
  1404. * \return Unspecified if \p alg is not a signature algorithm or
  1405. * if it is not supported by the implementation.
  1406. */
  1407. #define PSA_ALG_SIGN_GET_HASH(alg) \
  1408. (PSA_ALG_IS_HASH_AND_SIGN(alg) ? \
  1409. ((alg) & PSA_ALG_HASH_MASK) == 0 ? /*"raw" algorithm*/ 0 : \
  1410. ((alg) & PSA_ALG_HASH_MASK) | PSA_ALG_CATEGORY_HASH : \
  1411. 0)
  1412. /** RSA PKCS#1 v1.5 encryption.
  1413. */
  1414. #define PSA_ALG_RSA_PKCS1V15_CRYPT ((psa_algorithm_t)0x07000200)
  1415. #define PSA_ALG_RSA_OAEP_BASE ((psa_algorithm_t)0x07000300)
  1416. /** RSA OAEP encryption.
  1417. *
  1418. * This is the encryption scheme defined by RFC 8017
  1419. * (PKCS#1: RSA Cryptography Specifications) under the name
  1420. * RSAES-OAEP, with the message generation function MGF1.
  1421. *
  1422. * \param hash_alg The hash algorithm (\c PSA_ALG_XXX value such that
  1423. * #PSA_ALG_IS_HASH(\p hash_alg) is true) to use
  1424. * for MGF1.
  1425. *
  1426. * \return The corresponding RSA OAEP encryption algorithm.
  1427. * \return Unspecified if \p hash_alg is not a supported
  1428. * hash algorithm.
  1429. */
  1430. #define PSA_ALG_RSA_OAEP(hash_alg) \
  1431. (PSA_ALG_RSA_OAEP_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
  1432. #define PSA_ALG_IS_RSA_OAEP(alg) \
  1433. (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_OAEP_BASE)
  1434. #define PSA_ALG_RSA_OAEP_GET_HASH(alg) \
  1435. (PSA_ALG_IS_RSA_OAEP(alg) ? \
  1436. ((alg) & PSA_ALG_HASH_MASK) | PSA_ALG_CATEGORY_HASH : \
  1437. 0)
  1438. #define PSA_ALG_HKDF_BASE ((psa_algorithm_t)0x08000100)
  1439. /** Macro to build an HKDF algorithm.
  1440. *
  1441. * For example, `PSA_ALG_HKDF(PSA_ALG_SHA256)` is HKDF using HMAC-SHA-256.
  1442. *
  1443. * This key derivation algorithm uses the following inputs:
  1444. * - #PSA_KEY_DERIVATION_INPUT_SALT is the salt used in the "extract" step.
  1445. * It is optional; if omitted, the derivation uses an empty salt.
  1446. * - #PSA_KEY_DERIVATION_INPUT_SECRET is the secret key used in the "extract" step.
  1447. * - #PSA_KEY_DERIVATION_INPUT_INFO is the info string used in the "expand" step.
  1448. * You must pass #PSA_KEY_DERIVATION_INPUT_SALT before #PSA_KEY_DERIVATION_INPUT_SECRET.
  1449. * You may pass #PSA_KEY_DERIVATION_INPUT_INFO at any time after steup and before
  1450. * starting to generate output.
  1451. *
  1452. * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
  1453. * #PSA_ALG_IS_HASH(\p hash_alg) is true).
  1454. *
  1455. * \return The corresponding HKDF algorithm.
  1456. * \return Unspecified if \p hash_alg is not a supported
  1457. * hash algorithm.
  1458. */
  1459. #define PSA_ALG_HKDF(hash_alg) \
  1460. (PSA_ALG_HKDF_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
  1461. /** Whether the specified algorithm is an HKDF algorithm.
  1462. *
  1463. * HKDF is a family of key derivation algorithms that are based on a hash
  1464. * function and the HMAC construction.
  1465. *
  1466. * \param alg An algorithm identifier (value of type #psa_algorithm_t).
  1467. *
  1468. * \return 1 if \c alg is an HKDF algorithm, 0 otherwise.
  1469. * This macro may return either 0 or 1 if \c alg is not a supported
  1470. * key derivation algorithm identifier.
  1471. */
  1472. #define PSA_ALG_IS_HKDF(alg) \
  1473. (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_HKDF_BASE)
  1474. #define PSA_ALG_HKDF_GET_HASH(hkdf_alg) \
  1475. (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK))
  1476. #define PSA_ALG_TLS12_PRF_BASE ((psa_algorithm_t)0x08000200)
  1477. /** Macro to build a TLS-1.2 PRF algorithm.
  1478. *
  1479. * TLS 1.2 uses a custom pseudorandom function (PRF) for key schedule,
  1480. * specified in Section 5 of RFC 5246. It is based on HMAC and can be
  1481. * used with either SHA-256 or SHA-384.
  1482. *
  1483. * This key derivation algorithm uses the following inputs, which must be
  1484. * passed in the order given here:
  1485. * - #PSA_KEY_DERIVATION_INPUT_SEED is the seed.
  1486. * - #PSA_KEY_DERIVATION_INPUT_SECRET is the secret key.
  1487. * - #PSA_KEY_DERIVATION_INPUT_LABEL is the label.
  1488. *
  1489. * For the application to TLS-1.2 key expansion, the seed is the
  1490. * concatenation of ServerHello.Random + ClientHello.Random,
  1491. * and the label is "key expansion".
  1492. *
  1493. * For example, `PSA_ALG_TLS12_PRF(PSA_ALG_SHA256)` represents the
  1494. * TLS 1.2 PRF using HMAC-SHA-256.
  1495. *
  1496. * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
  1497. * #PSA_ALG_IS_HASH(\p hash_alg) is true).
  1498. *
  1499. * \return The corresponding TLS-1.2 PRF algorithm.
  1500. * \return Unspecified if \p hash_alg is not a supported
  1501. * hash algorithm.
  1502. */
  1503. #define PSA_ALG_TLS12_PRF(hash_alg) \
  1504. (PSA_ALG_TLS12_PRF_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
  1505. /** Whether the specified algorithm is a TLS-1.2 PRF algorithm.
  1506. *
  1507. * \param alg An algorithm identifier (value of type #psa_algorithm_t).
  1508. *
  1509. * \return 1 if \c alg is a TLS-1.2 PRF algorithm, 0 otherwise.
  1510. * This macro may return either 0 or 1 if \c alg is not a supported
  1511. * key derivation algorithm identifier.
  1512. */
  1513. #define PSA_ALG_IS_TLS12_PRF(alg) \
  1514. (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_TLS12_PRF_BASE)
  1515. #define PSA_ALG_TLS12_PRF_GET_HASH(hkdf_alg) \
  1516. (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK))
  1517. #define PSA_ALG_TLS12_PSK_TO_MS_BASE ((psa_algorithm_t)0x08000300)
  1518. /** Macro to build a TLS-1.2 PSK-to-MasterSecret algorithm.
  1519. *
  1520. * In a pure-PSK handshake in TLS 1.2, the master secret is derived
  1521. * from the PreSharedKey (PSK) through the application of padding
  1522. * (RFC 4279, Section 2) and the TLS-1.2 PRF (RFC 5246, Section 5).
  1523. * The latter is based on HMAC and can be used with either SHA-256
  1524. * or SHA-384.
  1525. *
  1526. * This key derivation algorithm uses the following inputs, which must be
  1527. * passed in the order given here:
  1528. * - #PSA_KEY_DERIVATION_INPUT_SEED is the seed.
  1529. * - #PSA_KEY_DERIVATION_INPUT_SECRET is the secret key.
  1530. * - #PSA_KEY_DERIVATION_INPUT_LABEL is the label.
  1531. *
  1532. * For the application to TLS-1.2, the seed (which is
  1533. * forwarded to the TLS-1.2 PRF) is the concatenation of the
  1534. * ClientHello.Random + ServerHello.Random,
  1535. * and the label is "master secret" or "extended master secret".
  1536. *
  1537. * For example, `PSA_ALG_TLS12_PSK_TO_MS(PSA_ALG_SHA256)` represents the
  1538. * TLS-1.2 PSK to MasterSecret derivation PRF using HMAC-SHA-256.
  1539. *
  1540. * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
  1541. * #PSA_ALG_IS_HASH(\p hash_alg) is true).
  1542. *
  1543. * \return The corresponding TLS-1.2 PSK to MS algorithm.
  1544. * \return Unspecified if \p hash_alg is not a supported
  1545. * hash algorithm.
  1546. */
  1547. #define PSA_ALG_TLS12_PSK_TO_MS(hash_alg) \
  1548. (PSA_ALG_TLS12_PSK_TO_MS_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
  1549. /** Whether the specified algorithm is a TLS-1.2 PSK to MS algorithm.
  1550. *
  1551. * \param alg An algorithm identifier (value of type #psa_algorithm_t).
  1552. *
  1553. * \return 1 if \c alg is a TLS-1.2 PSK to MS algorithm, 0 otherwise.
  1554. * This macro may return either 0 or 1 if \c alg is not a supported
  1555. * key derivation algorithm identifier.
  1556. */
  1557. #define PSA_ALG_IS_TLS12_PSK_TO_MS(alg) \
  1558. (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_TLS12_PSK_TO_MS_BASE)
  1559. #define PSA_ALG_TLS12_PSK_TO_MS_GET_HASH(hkdf_alg) \
  1560. (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK))
  1561. #define PSA_ALG_KEY_DERIVATION_MASK ((psa_algorithm_t)0xfe00ffff)
  1562. #define PSA_ALG_KEY_AGREEMENT_MASK ((psa_algorithm_t)0xffff0000)
  1563. /** Macro to build a combined algorithm that chains a key agreement with
  1564. * a key derivation.
  1565. *
  1566. * \param ka_alg A key agreement algorithm (\c PSA_ALG_XXX value such
  1567. * that #PSA_ALG_IS_KEY_AGREEMENT(\p ka_alg) is true).
  1568. * \param kdf_alg A key derivation algorithm (\c PSA_ALG_XXX value such
  1569. * that #PSA_ALG_IS_KEY_DERIVATION(\p kdf_alg) is true).
  1570. *
  1571. * \return The corresponding key agreement and derivation
  1572. * algorithm.
  1573. * \return Unspecified if \p ka_alg is not a supported
  1574. * key agreement algorithm or \p kdf_alg is not a
  1575. * supported key derivation algorithm.
  1576. */
  1577. #define PSA_ALG_KEY_AGREEMENT(ka_alg, kdf_alg) \
  1578. ((ka_alg) | (kdf_alg))
  1579. #define PSA_ALG_KEY_AGREEMENT_GET_KDF(alg) \
  1580. (((alg) & PSA_ALG_KEY_DERIVATION_MASK) | PSA_ALG_CATEGORY_KEY_DERIVATION)
  1581. #define PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) \
  1582. (((alg) & PSA_ALG_KEY_AGREEMENT_MASK) | PSA_ALG_CATEGORY_KEY_AGREEMENT)
  1583. /** Whether the specified algorithm is a raw key agreement algorithm.
  1584. *
  1585. * A raw key agreement algorithm is one that does not specify
  1586. * a key derivation function.
  1587. * Usually, raw key agreement algorithms are constructed directly with
  1588. * a \c PSA_ALG_xxx macro while non-raw key agreement algorithms are
  1589. * constructed with #PSA_ALG_KEY_AGREEMENT().
  1590. *
  1591. * \param alg An algorithm identifier (value of type #psa_algorithm_t).
  1592. *
  1593. * \return 1 if \p alg is a raw key agreement algorithm, 0 otherwise.
  1594. * This macro may return either 0 or 1 if \p alg is not a supported
  1595. * algorithm identifier.
  1596. */
  1597. #define PSA_ALG_IS_RAW_KEY_AGREEMENT(alg) \
  1598. (PSA_ALG_IS_KEY_AGREEMENT(alg) && \
  1599. PSA_ALG_KEY_AGREEMENT_GET_KDF(alg) == PSA_ALG_CATEGORY_KEY_DERIVATION)
  1600. #define PSA_ALG_IS_KEY_DERIVATION_OR_AGREEMENT(alg) \
  1601. ((PSA_ALG_IS_KEY_DERIVATION(alg) || PSA_ALG_IS_KEY_AGREEMENT(alg)))
  1602. /** The finite-field Diffie-Hellman (DH) key agreement algorithm.
  1603. *
  1604. * The shared secret produced by key agreement is
  1605. * `g^{ab}` in big-endian format.
  1606. * It is `ceiling(m / 8)` bytes long where `m` is the size of the prime `p`
  1607. * in bits.
  1608. */
  1609. #define PSA_ALG_FFDH ((psa_algorithm_t)0x09010000)
  1610. /** Whether the specified algorithm is a finite field Diffie-Hellman algorithm.
  1611. *
  1612. * This includes the raw finite field Diffie-Hellman algorithm as well as
  1613. * finite-field Diffie-Hellman followed by any supporter key derivation
  1614. * algorithm.
  1615. *
  1616. * \param alg An algorithm identifier (value of type #psa_algorithm_t).
  1617. *
  1618. * \return 1 if \c alg is a finite field Diffie-Hellman algorithm, 0 otherwise.
  1619. * This macro may return either 0 or 1 if \c alg is not a supported
  1620. * key agreement algorithm identifier.
  1621. */
  1622. #define PSA_ALG_IS_FFDH(alg) \
  1623. (PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) == PSA_ALG_FFDH)
  1624. /** The elliptic curve Diffie-Hellman (ECDH) key agreement algorithm.
  1625. *
  1626. * The shared secret produced by key agreement is the x-coordinate of
  1627. * the shared secret point. It is always `ceiling(m / 8)` bytes long where
  1628. * `m` is the bit size associated with the curve, i.e. the bit size of the
  1629. * order of the curve's coordinate field. When `m` is not a multiple of 8,
  1630. * the byte containing the most significant bit of the shared secret
  1631. * is padded with zero bits. The byte order is either little-endian
  1632. * or big-endian depending on the curve type.
  1633. *
  1634. * - For Montgomery curves (curve types `PSA_ECC_FAMILY_CURVEXXX`),
  1635. * the shared secret is the x-coordinate of `d_A Q_B = d_B Q_A`
  1636. * in little-endian byte order.
  1637. * The bit size is 448 for Curve448 and 255 for Curve25519.
  1638. * - For Weierstrass curves over prime fields (curve types
  1639. * `PSA_ECC_FAMILY_SECPXXX` and `PSA_ECC_FAMILY_BRAINPOOL_PXXX`),
  1640. * the shared secret is the x-coordinate of `d_A Q_B = d_B Q_A`
  1641. * in big-endian byte order.
  1642. * The bit size is `m = ceiling(log_2(p))` for the field `F_p`.
  1643. * - For Weierstrass curves over binary fields (curve types
  1644. * `PSA_ECC_FAMILY_SECTXXX`),
  1645. * the shared secret is the x-coordinate of `d_A Q_B = d_B Q_A`
  1646. * in big-endian byte order.
  1647. * The bit size is `m` for the field `F_{2^m}`.
  1648. */
  1649. #define PSA_ALG_ECDH ((psa_algorithm_t)0x09020000)
  1650. /** Whether the specified algorithm is an elliptic curve Diffie-Hellman
  1651. * algorithm.
  1652. *
  1653. * This includes the raw elliptic curve Diffie-Hellman algorithm as well as
  1654. * elliptic curve Diffie-Hellman followed by any supporter key derivation
  1655. * algorithm.
  1656. *
  1657. * \param alg An algorithm identifier (value of type #psa_algorithm_t).
  1658. *
  1659. * \return 1 if \c alg is an elliptic curve Diffie-Hellman algorithm,
  1660. * 0 otherwise.
  1661. * This macro may return either 0 or 1 if \c alg is not a supported
  1662. * key agreement algorithm identifier.
  1663. */
  1664. #define PSA_ALG_IS_ECDH(alg) \
  1665. (PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) == PSA_ALG_ECDH)
  1666. /** Whether the specified algorithm encoding is a wildcard.
  1667. *
  1668. * Wildcard values may only be used to set the usage algorithm field in
  1669. * a policy, not to perform an operation.
  1670. *
  1671. * \param alg An algorithm identifier (value of type #psa_algorithm_t).
  1672. *
  1673. * \return 1 if \c alg is a wildcard algorithm encoding.
  1674. * \return 0 if \c alg is a non-wildcard algorithm encoding (suitable for
  1675. * an operation).
  1676. * \return This macro may return either 0 or 1 if \c alg is not a supported
  1677. * algorithm identifier.
  1678. */
  1679. #define PSA_ALG_IS_WILDCARD(alg) \
  1680. (PSA_ALG_IS_HASH_AND_SIGN(alg) ? \
  1681. PSA_ALG_SIGN_GET_HASH(alg) == PSA_ALG_ANY_HASH : \
  1682. PSA_ALG_IS_MAC(alg) ? \
  1683. (alg & PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG) != 0 : \
  1684. PSA_ALG_IS_AEAD(alg) ? \
  1685. (alg & PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG) != 0 : \
  1686. (alg) == PSA_ALG_ANY_HASH)
  1687. /**@}*/
  1688. /** \defgroup key_lifetimes Key lifetimes
  1689. * @{
  1690. */
  1691. /** The default lifetime for volatile keys.
  1692. *
  1693. * A volatile key only exists as long as the identifier to it is not destroyed.
  1694. * The key material is guaranteed to be erased on a power reset.
  1695. *
  1696. * A key with this lifetime is typically stored in the RAM area of the
  1697. * PSA Crypto subsystem. However this is an implementation choice.
  1698. * If an implementation stores data about the key in a non-volatile memory,
  1699. * it must release all the resources associated with the key and erase the
  1700. * key material if the calling application terminates.
  1701. */
  1702. #define PSA_KEY_LIFETIME_VOLATILE ((psa_key_lifetime_t)0x00000000)
  1703. /** The default lifetime for persistent keys.
  1704. *
  1705. * A persistent key remains in storage until it is explicitly destroyed or
  1706. * until the corresponding storage area is wiped. This specification does
  1707. * not define any mechanism to wipe a storage area, but integrations may
  1708. * provide their own mechanism (for example to perform a factory reset,
  1709. * to prepare for device refurbishment, or to uninstall an application).
  1710. *
  1711. * This lifetime value is the default storage area for the calling
  1712. * application. Integrations of Mbed TLS may support other persistent lifetimes.
  1713. * See ::psa_key_lifetime_t for more information.
  1714. */
  1715. #define PSA_KEY_LIFETIME_PERSISTENT ((psa_key_lifetime_t)0x00000001)
  1716. /** The persistence level of volatile keys.
  1717. *
  1718. * See ::psa_key_persistence_t for more information.
  1719. */
  1720. #define PSA_KEY_PERSISTENCE_VOLATILE ((psa_key_persistence_t)0x00)
  1721. /** The default persistence level for persistent keys.
  1722. *
  1723. * See ::psa_key_persistence_t for more information.
  1724. */
  1725. #define PSA_KEY_PERSISTENCE_DEFAULT ((psa_key_persistence_t)0x01)
  1726. /** A persistence level indicating that a key is never destroyed.
  1727. *
  1728. * See ::psa_key_persistence_t for more information.
  1729. */
  1730. #define PSA_KEY_PERSISTENCE_READ_ONLY ((psa_key_persistence_t)0xff)
  1731. #define PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime) \
  1732. ((psa_key_persistence_t)((lifetime) & 0x000000ff))
  1733. #define PSA_KEY_LIFETIME_GET_LOCATION(lifetime) \
  1734. ((psa_key_location_t)((lifetime) >> 8))
  1735. /** Whether a key lifetime indicates that the key is volatile.
  1736. *
  1737. * A volatile key is automatically destroyed by the implementation when
  1738. * the application instance terminates. In particular, a volatile key
  1739. * is automatically destroyed on a power reset of the device.
  1740. *
  1741. * A key that is not volatile is persistent. Persistent keys are
  1742. * preserved until the application explicitly destroys them or until an
  1743. * implementation-specific device management event occurs (for example,
  1744. * a factory reset).
  1745. *
  1746. * \param lifetime The lifetime value to query (value of type
  1747. * ::psa_key_lifetime_t).
  1748. *
  1749. * \return \c 1 if the key is volatile, otherwise \c 0.
  1750. */
  1751. #define PSA_KEY_LIFETIME_IS_VOLATILE(lifetime) \
  1752. (PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime) == \
  1753. PSA_KEY_PERSISTENCE_VOLATILE)
  1754. /** Whether a key lifetime indicates that the key is read-only.
  1755. *
  1756. * Read-only keys cannot be created or destroyed through the PSA Crypto API.
  1757. * They must be created through platform-specific means that bypass the API.
  1758. *
  1759. * Some platforms may offer ways to destroy read-only keys. For example,
  1760. * consider a platform with multiple levels of privilege, where a
  1761. * low-privilege application can use a key but is not allowed to destroy
  1762. * it, and the platform exposes the key to the application with a read-only
  1763. * lifetime. High-privilege code can destroy the key even though the
  1764. * application sees the key as read-only.
  1765. *
  1766. * \param lifetime The lifetime value to query (value of type
  1767. * ::psa_key_lifetime_t).
  1768. *
  1769. * \return \c 1 if the key is read-only, otherwise \c 0.
  1770. */
  1771. #define PSA_KEY_LIFETIME_IS_READ_ONLY(lifetime) \
  1772. (PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime) == \
  1773. PSA_KEY_PERSISTENCE_READ_ONLY)
  1774. /** Construct a lifetime from a persistence level and a location.
  1775. *
  1776. * \param persistence The persistence level
  1777. * (value of type ::psa_key_persistence_t).
  1778. * \param location The location indicator
  1779. * (value of type ::psa_key_location_t).
  1780. *
  1781. * \return The constructed lifetime value.
  1782. */
  1783. #define PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(persistence, location) \
  1784. ((location) << 8 | (persistence))
  1785. /** The local storage area for persistent keys.
  1786. *
  1787. * This storage area is available on all systems that can store persistent
  1788. * keys without delegating the storage to a third-party cryptoprocessor.
  1789. *
  1790. * See ::psa_key_location_t for more information.
  1791. */
  1792. #define PSA_KEY_LOCATION_LOCAL_STORAGE ((psa_key_location_t)0x000000)
  1793. #define PSA_KEY_LOCATION_VENDOR_FLAG ((psa_key_location_t)0x800000)
  1794. /** The minimum value for a key identifier chosen by the application.
  1795. */
  1796. #define PSA_KEY_ID_USER_MIN ((psa_key_id_t)0x00000001)
  1797. /** The maximum value for a key identifier chosen by the application.
  1798. */
  1799. #define PSA_KEY_ID_USER_MAX ((psa_key_id_t)0x3fffffff)
  1800. /** The minimum value for a key identifier chosen by the implementation.
  1801. */
  1802. #define PSA_KEY_ID_VENDOR_MIN ((psa_key_id_t)0x40000000)
  1803. /** The maximum value for a key identifier chosen by the implementation.
  1804. */
  1805. #define PSA_KEY_ID_VENDOR_MAX ((psa_key_id_t)0x7fffffff)
  1806. #if !defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
  1807. #define MBEDTLS_SVC_KEY_ID_INIT ( (psa_key_id_t)0 )
  1808. #define MBEDTLS_SVC_KEY_ID_GET_KEY_ID( id ) ( id )
  1809. #define MBEDTLS_SVC_KEY_ID_GET_OWNER_ID( id ) ( 0 )
  1810. /** Utility to initialize a key identifier at runtime.
  1811. *
  1812. * \param unused Unused parameter.
  1813. * \param key_id Identifier of the key.
  1814. */
  1815. static inline mbedtls_svc_key_id_t mbedtls_svc_key_id_make(
  1816. unsigned int unused, psa_key_id_t key_id )
  1817. {
  1818. (void)unused;
  1819. return( key_id );
  1820. }
  1821. /** Compare two key identifiers.
  1822. *
  1823. * \param id1 First key identifier.
  1824. * \param id2 Second key identifier.
  1825. *
  1826. * \return Non-zero if the two key identifier are equal, zero otherwise.
  1827. */
  1828. static inline int mbedtls_svc_key_id_equal( mbedtls_svc_key_id_t id1,
  1829. mbedtls_svc_key_id_t id2 )
  1830. {
  1831. return( id1 == id2 );
  1832. }
  1833. /** Check whether a key identifier is null.
  1834. *
  1835. * \param key Key identifier.
  1836. *
  1837. * \return Non-zero if the key identifier is null, zero otherwise.
  1838. */
  1839. static inline int mbedtls_svc_key_id_is_null( mbedtls_svc_key_id_t key )
  1840. {
  1841. return( key == 0 );
  1842. }
  1843. #else /* MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */
  1844. #define MBEDTLS_SVC_KEY_ID_INIT ( (mbedtls_svc_key_id_t){ 0, 0 } )
  1845. #define MBEDTLS_SVC_KEY_ID_GET_KEY_ID( id ) ( ( id ).key_id )
  1846. #define MBEDTLS_SVC_KEY_ID_GET_OWNER_ID( id ) ( ( id ).owner )
  1847. /** Utility to initialize a key identifier at runtime.
  1848. *
  1849. * \param owner_id Identifier of the key owner.
  1850. * \param key_id Identifier of the key.
  1851. */
  1852. static inline mbedtls_svc_key_id_t mbedtls_svc_key_id_make(
  1853. mbedtls_key_owner_id_t owner_id, psa_key_id_t key_id )
  1854. {
  1855. return( (mbedtls_svc_key_id_t){ .key_id = key_id,
  1856. .owner = owner_id } );
  1857. }
  1858. /** Compare two key identifiers.
  1859. *
  1860. * \param id1 First key identifier.
  1861. * \param id2 Second key identifier.
  1862. *
  1863. * \return Non-zero if the two key identifier are equal, zero otherwise.
  1864. */
  1865. static inline int mbedtls_svc_key_id_equal( mbedtls_svc_key_id_t id1,
  1866. mbedtls_svc_key_id_t id2 )
  1867. {
  1868. return( ( id1.key_id == id2.key_id ) &&
  1869. mbedtls_key_owner_id_equal( id1.owner, id2.owner ) );
  1870. }
  1871. /** Check whether a key identifier is null.
  1872. *
  1873. * \param key Key identifier.
  1874. *
  1875. * \return Non-zero if the key identifier is null, zero otherwise.
  1876. */
  1877. static inline int mbedtls_svc_key_id_is_null( mbedtls_svc_key_id_t key )
  1878. {
  1879. return( key.key_id == 0 );
  1880. }
  1881. #endif /* !MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER */
  1882. /**@}*/
  1883. /** \defgroup policy Key policies
  1884. * @{
  1885. */
  1886. /** Whether the key may be exported.
  1887. *
  1888. * A public key or the public part of a key pair may always be exported
  1889. * regardless of the value of this permission flag.
  1890. *
  1891. * If a key does not have export permission, implementations shall not
  1892. * allow the key to be exported in plain form from the cryptoprocessor,
  1893. * whether through psa_export_key() or through a proprietary interface.
  1894. * The key may however be exportable in a wrapped form, i.e. in a form
  1895. * where it is encrypted by another key.
  1896. */
  1897. #define PSA_KEY_USAGE_EXPORT ((psa_key_usage_t)0x00000001)
  1898. /** Whether the key may be copied.
  1899. *
  1900. * This flag allows the use of psa_copy_key() to make a copy of the key
  1901. * with the same policy or a more restrictive policy.
  1902. *
  1903. * For lifetimes for which the key is located in a secure element which
  1904. * enforce the non-exportability of keys, copying a key outside the secure
  1905. * element also requires the usage flag #PSA_KEY_USAGE_EXPORT.
  1906. * Copying the key inside the secure element is permitted with just
  1907. * #PSA_KEY_USAGE_COPY if the secure element supports it.
  1908. * For keys with the lifetime #PSA_KEY_LIFETIME_VOLATILE or
  1909. * #PSA_KEY_LIFETIME_PERSISTENT, the usage flag #PSA_KEY_USAGE_COPY
  1910. * is sufficient to permit the copy.
  1911. */
  1912. #define PSA_KEY_USAGE_COPY ((psa_key_usage_t)0x00000002)
  1913. /** Whether the key may be used to encrypt a message.
  1914. *
  1915. * This flag allows the key to be used for a symmetric encryption operation,
  1916. * for an AEAD encryption-and-authentication operation,
  1917. * or for an asymmetric encryption operation,
  1918. * if otherwise permitted by the key's type and policy.
  1919. *
  1920. * For a key pair, this concerns the public key.
  1921. */
  1922. #define PSA_KEY_USAGE_ENCRYPT ((psa_key_usage_t)0x00000100)
  1923. /** Whether the key may be used to decrypt a message.
  1924. *
  1925. * This flag allows the key to be used for a symmetric decryption operation,
  1926. * for an AEAD decryption-and-verification operation,
  1927. * or for an asymmetric decryption operation,
  1928. * if otherwise permitted by the key's type and policy.
  1929. *
  1930. * For a key pair, this concerns the private key.
  1931. */
  1932. #define PSA_KEY_USAGE_DECRYPT ((psa_key_usage_t)0x00000200)
  1933. /** Whether the key may be used to sign a message.
  1934. *
  1935. * This flag allows the key to be used for a MAC calculation operation or for
  1936. * an asymmetric message signature operation, if otherwise permitted by the
  1937. * key’s type and policy.
  1938. *
  1939. * For a key pair, this concerns the private key.
  1940. */
  1941. #define PSA_KEY_USAGE_SIGN_MESSAGE ((psa_key_usage_t)0x00000400)
  1942. /** Whether the key may be used to verify a message.
  1943. *
  1944. * This flag allows the key to be used for a MAC verification operation or for
  1945. * an asymmetric message signature verification operation, if otherwise
  1946. * permitted by the key’s type and policy.
  1947. *
  1948. * For a key pair, this concerns the public key.
  1949. */
  1950. #define PSA_KEY_USAGE_VERIFY_MESSAGE ((psa_key_usage_t)0x00000800)
  1951. /** Whether the key may be used to sign a message.
  1952. *
  1953. * This flag allows the key to be used for a MAC calculation operation
  1954. * or for an asymmetric signature operation,
  1955. * if otherwise permitted by the key's type and policy.
  1956. *
  1957. * For a key pair, this concerns the private key.
  1958. */
  1959. #define PSA_KEY_USAGE_SIGN_HASH ((psa_key_usage_t)0x00001000)
  1960. /** Whether the key may be used to verify a message signature.
  1961. *
  1962. * This flag allows the key to be used for a MAC verification operation
  1963. * or for an asymmetric signature verification operation,
  1964. * if otherwise permitted by by the key's type and policy.
  1965. *
  1966. * For a key pair, this concerns the public key.
  1967. */
  1968. #define PSA_KEY_USAGE_VERIFY_HASH ((psa_key_usage_t)0x00002000)
  1969. /** Whether the key may be used to derive other keys.
  1970. */
  1971. #define PSA_KEY_USAGE_DERIVE ((psa_key_usage_t)0x00004000)
  1972. /**@}*/
  1973. /** \defgroup derivation Key derivation
  1974. * @{
  1975. */
  1976. /** A secret input for key derivation.
  1977. *
  1978. * This should be a key of type #PSA_KEY_TYPE_DERIVE
  1979. * (passed to psa_key_derivation_input_key())
  1980. * or the shared secret resulting from a key agreement
  1981. * (obtained via psa_key_derivation_key_agreement()).
  1982. *
  1983. * The secret can also be a direct input (passed to
  1984. * key_derivation_input_bytes()). In this case, the derivation operation
  1985. * may not be used to derive keys: the operation will only allow
  1986. * psa_key_derivation_output_bytes(), not psa_key_derivation_output_key().
  1987. */
  1988. #define PSA_KEY_DERIVATION_INPUT_SECRET ((psa_key_derivation_step_t)0x0101)
  1989. /** A label for key derivation.
  1990. *
  1991. * This should be a direct input.
  1992. * It can also be a key of type #PSA_KEY_TYPE_RAW_DATA.
  1993. */
  1994. #define PSA_KEY_DERIVATION_INPUT_LABEL ((psa_key_derivation_step_t)0x0201)
  1995. /** A salt for key derivation.
  1996. *
  1997. * This should be a direct input.
  1998. * It can also be a key of type #PSA_KEY_TYPE_RAW_DATA.
  1999. */
  2000. #define PSA_KEY_DERIVATION_INPUT_SALT ((psa_key_derivation_step_t)0x0202)
  2001. /** An information string for key derivation.
  2002. *
  2003. * This should be a direct input.
  2004. * It can also be a key of type #PSA_KEY_TYPE_RAW_DATA.
  2005. */
  2006. #define PSA_KEY_DERIVATION_INPUT_INFO ((psa_key_derivation_step_t)0x0203)
  2007. /** A seed for key derivation.
  2008. *
  2009. * This should be a direct input.
  2010. * It can also be a key of type #PSA_KEY_TYPE_RAW_DATA.
  2011. */
  2012. #define PSA_KEY_DERIVATION_INPUT_SEED ((psa_key_derivation_step_t)0x0204)
  2013. /**@}*/
  2014. /** \defgroup helper_macros Helper macros
  2015. * @{
  2016. */
  2017. /* Helper macros */
  2018. /** Check if two AEAD algorithm identifiers refer to the same AEAD algorithm
  2019. * regardless of the tag length they encode.
  2020. *
  2021. * \param aead_alg_1 An AEAD algorithm identifier.
  2022. * \param aead_alg_2 An AEAD algorithm identifier.
  2023. *
  2024. * \return 1 if both identifiers refer to the same AEAD algorithm,
  2025. * 0 otherwise.
  2026. * Unspecified if neither \p aead_alg_1 nor \p aead_alg_2 are
  2027. * a supported AEAD algorithm.
  2028. */
  2029. #define MBEDTLS_PSA_ALG_AEAD_EQUAL(aead_alg_1, aead_alg_2) \
  2030. (!(((aead_alg_1) ^ (aead_alg_2)) & \
  2031. ~(PSA_ALG_AEAD_TAG_LENGTH_MASK | PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG)))
  2032. /**@}*/
  2033. #endif /* PSA_CRYPTO_VALUES_H */