psa_constant_names_generated.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. /* Automatically generated by generate_psa_constant.py. DO NOT EDIT. */
  2. static const char *psa_strerror(psa_status_t status)
  3. {
  4. switch (status) {
  5. case PSA_ERROR_ALREADY_EXISTS: return "PSA_ERROR_ALREADY_EXISTS";
  6. case PSA_ERROR_BAD_STATE: return "PSA_ERROR_BAD_STATE";
  7. case PSA_ERROR_BUFFER_TOO_SMALL: return "PSA_ERROR_BUFFER_TOO_SMALL";
  8. case PSA_ERROR_COMMUNICATION_FAILURE: return "PSA_ERROR_COMMUNICATION_FAILURE";
  9. case PSA_ERROR_CORRUPTION_DETECTED: return "PSA_ERROR_CORRUPTION_DETECTED";
  10. case PSA_ERROR_DATA_CORRUPT: return "PSA_ERROR_DATA_CORRUPT";
  11. case PSA_ERROR_DATA_INVALID: return "PSA_ERROR_DATA_INVALID";
  12. case PSA_ERROR_DOES_NOT_EXIST: return "PSA_ERROR_DOES_NOT_EXIST";
  13. case PSA_ERROR_GENERIC_ERROR: return "PSA_ERROR_GENERIC_ERROR";
  14. case PSA_ERROR_HARDWARE_FAILURE: return "PSA_ERROR_HARDWARE_FAILURE";
  15. case PSA_ERROR_INSUFFICIENT_DATA: return "PSA_ERROR_INSUFFICIENT_DATA";
  16. case PSA_ERROR_INSUFFICIENT_ENTROPY: return "PSA_ERROR_INSUFFICIENT_ENTROPY";
  17. case PSA_ERROR_INSUFFICIENT_MEMORY: return "PSA_ERROR_INSUFFICIENT_MEMORY";
  18. case PSA_ERROR_INSUFFICIENT_STORAGE: return "PSA_ERROR_INSUFFICIENT_STORAGE";
  19. case PSA_ERROR_INVALID_ARGUMENT: return "PSA_ERROR_INVALID_ARGUMENT";
  20. case PSA_ERROR_INVALID_HANDLE: return "PSA_ERROR_INVALID_HANDLE";
  21. case PSA_ERROR_INVALID_PADDING: return "PSA_ERROR_INVALID_PADDING";
  22. case PSA_ERROR_INVALID_SIGNATURE: return "PSA_ERROR_INVALID_SIGNATURE";
  23. case PSA_ERROR_NOT_PERMITTED: return "PSA_ERROR_NOT_PERMITTED";
  24. case PSA_ERROR_NOT_SUPPORTED: return "PSA_ERROR_NOT_SUPPORTED";
  25. case PSA_ERROR_STORAGE_FAILURE: return "PSA_ERROR_STORAGE_FAILURE";
  26. case PSA_SUCCESS: return "PSA_SUCCESS";
  27. default: return NULL;
  28. }
  29. }
  30. static const char *psa_ecc_family_name(psa_ecc_family_t curve)
  31. {
  32. switch (curve) {
  33. case PSA_ECC_FAMILY_BRAINPOOL_P_R1: return "PSA_ECC_FAMILY_BRAINPOOL_P_R1";
  34. case PSA_ECC_FAMILY_MONTGOMERY: return "PSA_ECC_FAMILY_MONTGOMERY";
  35. case PSA_ECC_FAMILY_SECP_K1: return "PSA_ECC_FAMILY_SECP_K1";
  36. case PSA_ECC_FAMILY_SECP_R1: return "PSA_ECC_FAMILY_SECP_R1";
  37. case PSA_ECC_FAMILY_SECP_R2: return "PSA_ECC_FAMILY_SECP_R2";
  38. case PSA_ECC_FAMILY_SECT_K1: return "PSA_ECC_FAMILY_SECT_K1";
  39. case PSA_ECC_FAMILY_SECT_R1: return "PSA_ECC_FAMILY_SECT_R1";
  40. case PSA_ECC_FAMILY_SECT_R2: return "PSA_ECC_FAMILY_SECT_R2";
  41. case PSA_ECC_FAMILY_TWISTED_EDWARDS: return "PSA_ECC_FAMILY_TWISTED_EDWARDS";
  42. default: return NULL;
  43. }
  44. }
  45. static const char *psa_dh_family_name(psa_dh_family_t group)
  46. {
  47. switch (group) {
  48. case PSA_DH_FAMILY_CUSTOM: return "PSA_DH_FAMILY_CUSTOM";
  49. case PSA_DH_FAMILY_RFC7919: return "PSA_DH_FAMILY_RFC7919";
  50. default: return NULL;
  51. }
  52. }
  53. static const char *psa_hash_algorithm_name(psa_algorithm_t hash_alg)
  54. {
  55. switch (hash_alg) {
  56. case PSA_ALG_ANY_HASH: return "PSA_ALG_ANY_HASH";
  57. case PSA_ALG_CATEGORY_HASH: return "PSA_ALG_CATEGORY_HASH";
  58. case PSA_ALG_MD2: return "PSA_ALG_MD2";
  59. case PSA_ALG_MD4: return "PSA_ALG_MD4";
  60. case PSA_ALG_MD5: return "PSA_ALG_MD5";
  61. case PSA_ALG_RIPEMD160: return "PSA_ALG_RIPEMD160";
  62. case PSA_ALG_SHA3_224: return "PSA_ALG_SHA3_224";
  63. case PSA_ALG_SHA3_256: return "PSA_ALG_SHA3_256";
  64. case PSA_ALG_SHA3_384: return "PSA_ALG_SHA3_384";
  65. case PSA_ALG_SHA3_512: return "PSA_ALG_SHA3_512";
  66. case PSA_ALG_SHAKE256_512: return "PSA_ALG_SHAKE256_512";
  67. case PSA_ALG_SHA_1: return "PSA_ALG_SHA_1";
  68. case PSA_ALG_SHA_224: return "PSA_ALG_SHA_224";
  69. case PSA_ALG_SHA_256: return "PSA_ALG_SHA_256";
  70. case PSA_ALG_SHA_384: return "PSA_ALG_SHA_384";
  71. case PSA_ALG_SHA_512: return "PSA_ALG_SHA_512";
  72. case PSA_ALG_SHA_512_224: return "PSA_ALG_SHA_512_224";
  73. case PSA_ALG_SHA_512_256: return "PSA_ALG_SHA_512_256";
  74. default: return NULL;
  75. }
  76. }
  77. static const char *psa_ka_algorithm_name(psa_algorithm_t ka_alg)
  78. {
  79. switch (ka_alg) {
  80. case PSA_ALG_CATEGORY_KEY_AGREEMENT: return "PSA_ALG_CATEGORY_KEY_AGREEMENT";
  81. case PSA_ALG_ECDH: return "PSA_ALG_ECDH";
  82. case PSA_ALG_FFDH: return "PSA_ALG_FFDH";
  83. default: return NULL;
  84. }
  85. }
  86. static int psa_snprint_key_type(char *buffer, size_t buffer_size,
  87. psa_key_type_t type)
  88. {
  89. size_t required_size = 0;
  90. switch (type) {
  91. case PSA_KEY_TYPE_AES: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_AES", 16); break;
  92. case PSA_KEY_TYPE_ARC4: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_ARC4", 17); break;
  93. case PSA_KEY_TYPE_ARIA: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_ARIA", 17); break;
  94. case PSA_KEY_TYPE_CAMELLIA: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_CAMELLIA", 21); break;
  95. case PSA_KEY_TYPE_CATEGORY_FLAG_PAIR: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_CATEGORY_FLAG_PAIR", 31); break;
  96. case PSA_KEY_TYPE_CATEGORY_KEY_PAIR: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_CATEGORY_KEY_PAIR", 30); break;
  97. case PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY", 32); break;
  98. case PSA_KEY_TYPE_CATEGORY_RAW: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_CATEGORY_RAW", 25); break;
  99. case PSA_KEY_TYPE_CATEGORY_SYMMETRIC: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_CATEGORY_SYMMETRIC", 31); break;
  100. case PSA_KEY_TYPE_CHACHA20: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_CHACHA20", 21); break;
  101. case PSA_KEY_TYPE_DERIVE: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_DERIVE", 19); break;
  102. case PSA_KEY_TYPE_DES: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_DES", 16); break;
  103. case PSA_KEY_TYPE_DH_KEY_PAIR_BASE: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_DH_KEY_PAIR_BASE", 29); break;
  104. case PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE", 31); break;
  105. case PSA_KEY_TYPE_DSA_KEY_PAIR: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_DSA_KEY_PAIR", 25); break;
  106. case PSA_KEY_TYPE_DSA_PUBLIC_KEY: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_DSA_PUBLIC_KEY", 27); break;
  107. case PSA_KEY_TYPE_ECC_KEY_PAIR_BASE: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_ECC_KEY_PAIR_BASE", 30); break;
  108. case PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE", 32); break;
  109. case PSA_KEY_TYPE_HMAC: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_HMAC", 17); break;
  110. case PSA_KEY_TYPE_NONE: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_NONE", 17); break;
  111. case PSA_KEY_TYPE_RAW_DATA: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_RAW_DATA", 21); break;
  112. case PSA_KEY_TYPE_RSA_KEY_PAIR: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_RSA_KEY_PAIR", 25); break;
  113. case PSA_KEY_TYPE_RSA_PUBLIC_KEY: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_RSA_PUBLIC_KEY", 27); break;
  114. default:
  115. if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(type)) {
  116. append_with_curve(&buffer, buffer_size, &required_size,
  117. "PSA_KEY_TYPE_ECC_KEY_PAIR", 25,
  118. PSA_KEY_TYPE_ECC_GET_FAMILY(type));
  119. } else if (PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(type)) {
  120. append_with_curve(&buffer, buffer_size, &required_size,
  121. "PSA_KEY_TYPE_ECC_PUBLIC_KEY", 27,
  122. PSA_KEY_TYPE_ECC_GET_FAMILY(type));
  123. } else if (PSA_KEY_TYPE_IS_DH_KEY_PAIR(type)) {
  124. append_with_group(&buffer, buffer_size, &required_size,
  125. "PSA_KEY_TYPE_DH_KEY_PAIR", 24,
  126. PSA_KEY_TYPE_DH_GET_FAMILY(type));
  127. } else if (PSA_KEY_TYPE_IS_DH_PUBLIC_KEY(type)) {
  128. append_with_group(&buffer, buffer_size, &required_size,
  129. "PSA_KEY_TYPE_DH_PUBLIC_KEY", 26,
  130. PSA_KEY_TYPE_DH_GET_FAMILY(type));
  131. } else {
  132. return snprintf(buffer, buffer_size,
  133. "0x%04x", (unsigned) type);
  134. }
  135. break;
  136. }
  137. buffer[0] = 0;
  138. return (int) required_size;
  139. }
  140. #define NO_LENGTH_MODIFIER 0xfffffffflu
  141. static int psa_snprint_algorithm(char *buffer, size_t buffer_size,
  142. psa_algorithm_t alg)
  143. {
  144. size_t required_size = 0;
  145. psa_algorithm_t core_alg = alg;
  146. unsigned long length_modifier = NO_LENGTH_MODIFIER;
  147. if (PSA_ALG_IS_MAC(alg)) {
  148. core_alg = PSA_ALG_TRUNCATED_MAC(alg, 0);
  149. if (alg & PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG) {
  150. append(&buffer, buffer_size, &required_size,
  151. "PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(", 33);
  152. length_modifier = PSA_MAC_TRUNCATED_LENGTH(alg);
  153. } else if (core_alg != alg) {
  154. append(&buffer, buffer_size, &required_size,
  155. "PSA_ALG_TRUNCATED_MAC(", 22);
  156. length_modifier = PSA_MAC_TRUNCATED_LENGTH(alg);
  157. }
  158. } else if (PSA_ALG_IS_AEAD(alg)) {
  159. core_alg = PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(alg);
  160. if (core_alg == 0) {
  161. /* For unknown AEAD algorithms, there is no "default tag length". */
  162. core_alg = alg;
  163. } else if (alg & PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG) {
  164. append(&buffer, buffer_size, &required_size,
  165. "PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(", 43);
  166. length_modifier = PSA_ALG_AEAD_GET_TAG_LENGTH(alg);
  167. } else if (core_alg != alg) {
  168. append(&buffer, buffer_size, &required_size,
  169. "PSA_ALG_AEAD_WITH_SHORTENED_TAG(", 32);
  170. length_modifier = PSA_ALG_AEAD_GET_TAG_LENGTH(alg);
  171. }
  172. } else if (PSA_ALG_IS_KEY_AGREEMENT(alg) &&
  173. !PSA_ALG_IS_RAW_KEY_AGREEMENT(alg)) {
  174. core_alg = PSA_ALG_KEY_AGREEMENT_GET_KDF(alg);
  175. append(&buffer, buffer_size, &required_size,
  176. "PSA_ALG_KEY_AGREEMENT(", 22);
  177. append_with_alg(&buffer, buffer_size, &required_size,
  178. psa_ka_algorithm_name,
  179. PSA_ALG_KEY_AGREEMENT_GET_BASE(alg));
  180. append(&buffer, buffer_size, &required_size, ", ", 2);
  181. }
  182. switch (core_alg) {
  183. case PSA_ALG_ANY_HASH: append(&buffer, buffer_size, &required_size, "PSA_ALG_ANY_HASH", 16); break;
  184. case PSA_ALG_CATEGORY_AEAD: append(&buffer, buffer_size, &required_size, "PSA_ALG_CATEGORY_AEAD", 21); break;
  185. case PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION: append(&buffer, buffer_size, &required_size, "PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION", 38); break;
  186. case PSA_ALG_CATEGORY_CIPHER: append(&buffer, buffer_size, &required_size, "PSA_ALG_CATEGORY_CIPHER", 23); break;
  187. case PSA_ALG_CATEGORY_HASH: append(&buffer, buffer_size, &required_size, "PSA_ALG_CATEGORY_HASH", 21); break;
  188. case PSA_ALG_CATEGORY_KEY_AGREEMENT: append(&buffer, buffer_size, &required_size, "PSA_ALG_CATEGORY_KEY_AGREEMENT", 30); break;
  189. case PSA_ALG_CATEGORY_KEY_DERIVATION: append(&buffer, buffer_size, &required_size, "PSA_ALG_CATEGORY_KEY_DERIVATION", 31); break;
  190. case PSA_ALG_CATEGORY_MAC: append(&buffer, buffer_size, &required_size, "PSA_ALG_CATEGORY_MAC", 20); break;
  191. case PSA_ALG_CATEGORY_SIGN: append(&buffer, buffer_size, &required_size, "PSA_ALG_CATEGORY_SIGN", 21); break;
  192. case PSA_ALG_CBC_MAC: append(&buffer, buffer_size, &required_size, "PSA_ALG_CBC_MAC", 15); break;
  193. case PSA_ALG_CBC_NO_PADDING: append(&buffer, buffer_size, &required_size, "PSA_ALG_CBC_NO_PADDING", 22); break;
  194. case PSA_ALG_CBC_PKCS7: append(&buffer, buffer_size, &required_size, "PSA_ALG_CBC_PKCS7", 17); break;
  195. case PSA_ALG_CCM: append(&buffer, buffer_size, &required_size, "PSA_ALG_CCM", 11); break;
  196. case PSA_ALG_CFB: append(&buffer, buffer_size, &required_size, "PSA_ALG_CFB", 11); break;
  197. case PSA_ALG_CHACHA20_POLY1305: append(&buffer, buffer_size, &required_size, "PSA_ALG_CHACHA20_POLY1305", 25); break;
  198. case PSA_ALG_CIPHER_MAC_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_CIPHER_MAC_BASE", 23); break;
  199. case PSA_ALG_CMAC: append(&buffer, buffer_size, &required_size, "PSA_ALG_CMAC", 12); break;
  200. case PSA_ALG_CTR: append(&buffer, buffer_size, &required_size, "PSA_ALG_CTR", 11); break;
  201. case PSA_ALG_DETERMINISTIC_DSA_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_DETERMINISTIC_DSA_BASE", 30); break;
  202. case PSA_ALG_DETERMINISTIC_ECDSA_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_DETERMINISTIC_ECDSA_BASE", 32); break;
  203. case PSA_ALG_DSA_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_DSA_BASE", 16); break;
  204. case PSA_ALG_ECB_NO_PADDING: append(&buffer, buffer_size, &required_size, "PSA_ALG_ECB_NO_PADDING", 22); break;
  205. case PSA_ALG_ECDH: append(&buffer, buffer_size, &required_size, "PSA_ALG_ECDH", 12); break;
  206. case PSA_ALG_ECDSA_ANY: append(&buffer, buffer_size, &required_size, "PSA_ALG_ECDSA_ANY", 17); break;
  207. case PSA_ALG_ED25519PH: append(&buffer, buffer_size, &required_size, "PSA_ALG_ED25519PH", 17); break;
  208. case PSA_ALG_ED448PH: append(&buffer, buffer_size, &required_size, "PSA_ALG_ED448PH", 15); break;
  209. case PSA_ALG_FFDH: append(&buffer, buffer_size, &required_size, "PSA_ALG_FFDH", 12); break;
  210. case PSA_ALG_GCM: append(&buffer, buffer_size, &required_size, "PSA_ALG_GCM", 11); break;
  211. case PSA_ALG_HASH_EDDSA_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_HASH_EDDSA_BASE", 23); break;
  212. case PSA_ALG_HKDF_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_HKDF_BASE", 17); break;
  213. case PSA_ALG_HMAC_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_HMAC_BASE", 17); break;
  214. case PSA_ALG_MD2: append(&buffer, buffer_size, &required_size, "PSA_ALG_MD2", 11); break;
  215. case PSA_ALG_MD4: append(&buffer, buffer_size, &required_size, "PSA_ALG_MD4", 11); break;
  216. case PSA_ALG_MD5: append(&buffer, buffer_size, &required_size, "PSA_ALG_MD5", 11); break;
  217. case PSA_ALG_NONE: append(&buffer, buffer_size, &required_size, "PSA_ALG_NONE", 12); break;
  218. case PSA_ALG_OFB: append(&buffer, buffer_size, &required_size, "PSA_ALG_OFB", 11); break;
  219. case PSA_ALG_PURE_EDDSA: append(&buffer, buffer_size, &required_size, "PSA_ALG_PURE_EDDSA", 18); break;
  220. case PSA_ALG_RIPEMD160: append(&buffer, buffer_size, &required_size, "PSA_ALG_RIPEMD160", 17); break;
  221. case PSA_ALG_RSA_OAEP_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_RSA_OAEP_BASE", 21); break;
  222. case PSA_ALG_RSA_PKCS1V15_CRYPT: append(&buffer, buffer_size, &required_size, "PSA_ALG_RSA_PKCS1V15_CRYPT", 26); break;
  223. case PSA_ALG_RSA_PKCS1V15_SIGN_RAW: append(&buffer, buffer_size, &required_size, "PSA_ALG_RSA_PKCS1V15_SIGN_RAW", 29); break;
  224. case PSA_ALG_RSA_PSS_ANY_SALT_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_RSA_PSS_ANY_SALT_BASE", 29); break;
  225. case PSA_ALG_RSA_PSS_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_RSA_PSS_BASE", 20); break;
  226. case PSA_ALG_SHA3_224: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA3_224", 16); break;
  227. case PSA_ALG_SHA3_256: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA3_256", 16); break;
  228. case PSA_ALG_SHA3_384: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA3_384", 16); break;
  229. case PSA_ALG_SHA3_512: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA3_512", 16); break;
  230. case PSA_ALG_SHAKE256_512: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHAKE256_512", 20); break;
  231. case PSA_ALG_SHA_1: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA_1", 13); break;
  232. case PSA_ALG_SHA_224: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA_224", 15); break;
  233. case PSA_ALG_SHA_256: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA_256", 15); break;
  234. case PSA_ALG_SHA_384: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA_384", 15); break;
  235. case PSA_ALG_SHA_512: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA_512", 15); break;
  236. case PSA_ALG_SHA_512_224: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA_512_224", 19); break;
  237. case PSA_ALG_SHA_512_256: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA_512_256", 19); break;
  238. case PSA_ALG_STREAM_CIPHER: append(&buffer, buffer_size, &required_size, "PSA_ALG_STREAM_CIPHER", 21); break;
  239. case PSA_ALG_TLS12_PRF_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_TLS12_PRF_BASE", 22); break;
  240. case PSA_ALG_TLS12_PSK_TO_MS_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_TLS12_PSK_TO_MS_BASE", 28); break;
  241. case PSA_ALG_XTS: append(&buffer, buffer_size, &required_size, "PSA_ALG_XTS", 11); break;
  242. default:
  243. if (PSA_ALG_IS_DETERMINISTIC_DSA(core_alg)) {
  244. append(&buffer, buffer_size, &required_size,
  245. "PSA_ALG_DETERMINISTIC_DSA(", 25 + 1);
  246. append_with_alg(&buffer, buffer_size, &required_size,
  247. psa_hash_algorithm_name,
  248. PSA_ALG_GET_HASH(core_alg));
  249. append(&buffer, buffer_size, &required_size, ")", 1);
  250. } else if (PSA_ALG_IS_DETERMINISTIC_ECDSA(core_alg)) {
  251. append(&buffer, buffer_size, &required_size,
  252. "PSA_ALG_DETERMINISTIC_ECDSA(", 27 + 1);
  253. append_with_alg(&buffer, buffer_size, &required_size,
  254. psa_hash_algorithm_name,
  255. PSA_ALG_GET_HASH(core_alg));
  256. append(&buffer, buffer_size, &required_size, ")", 1);
  257. } else if (PSA_ALG_IS_RANDOMIZED_DSA(core_alg)) {
  258. append(&buffer, buffer_size, &required_size,
  259. "PSA_ALG_DSA(", 11 + 1);
  260. append_with_alg(&buffer, buffer_size, &required_size,
  261. psa_hash_algorithm_name,
  262. PSA_ALG_GET_HASH(core_alg));
  263. append(&buffer, buffer_size, &required_size, ")", 1);
  264. } else if (PSA_ALG_IS_RANDOMIZED_ECDSA(core_alg)) {
  265. append(&buffer, buffer_size, &required_size,
  266. "PSA_ALG_ECDSA(", 13 + 1);
  267. append_with_alg(&buffer, buffer_size, &required_size,
  268. psa_hash_algorithm_name,
  269. PSA_ALG_GET_HASH(core_alg));
  270. append(&buffer, buffer_size, &required_size, ")", 1);
  271. } else if (PSA_ALG_IS_HKDF(core_alg)) {
  272. append(&buffer, buffer_size, &required_size,
  273. "PSA_ALG_HKDF(", 12 + 1);
  274. append_with_alg(&buffer, buffer_size, &required_size,
  275. psa_hash_algorithm_name,
  276. PSA_ALG_GET_HASH(core_alg));
  277. append(&buffer, buffer_size, &required_size, ")", 1);
  278. } else if (PSA_ALG_IS_HMAC(core_alg)) {
  279. append(&buffer, buffer_size, &required_size,
  280. "PSA_ALG_HMAC(", 12 + 1);
  281. append_with_alg(&buffer, buffer_size, &required_size,
  282. psa_hash_algorithm_name,
  283. PSA_ALG_GET_HASH(core_alg));
  284. append(&buffer, buffer_size, &required_size, ")", 1);
  285. } else if (PSA_ALG_IS_RSA_OAEP(core_alg)) {
  286. append(&buffer, buffer_size, &required_size,
  287. "PSA_ALG_RSA_OAEP(", 16 + 1);
  288. append_with_alg(&buffer, buffer_size, &required_size,
  289. psa_hash_algorithm_name,
  290. PSA_ALG_GET_HASH(core_alg));
  291. append(&buffer, buffer_size, &required_size, ")", 1);
  292. } else if (PSA_ALG_IS_RSA_PKCS1V15_SIGN(core_alg)) {
  293. append(&buffer, buffer_size, &required_size,
  294. "PSA_ALG_RSA_PKCS1V15_SIGN(", 25 + 1);
  295. append_with_alg(&buffer, buffer_size, &required_size,
  296. psa_hash_algorithm_name,
  297. PSA_ALG_GET_HASH(core_alg));
  298. append(&buffer, buffer_size, &required_size, ")", 1);
  299. } else if (PSA_ALG_IS_RSA_PSS_STANDARD_SALT(core_alg)) {
  300. append(&buffer, buffer_size, &required_size,
  301. "PSA_ALG_RSA_PSS(", 15 + 1);
  302. append_with_alg(&buffer, buffer_size, &required_size,
  303. psa_hash_algorithm_name,
  304. PSA_ALG_GET_HASH(core_alg));
  305. append(&buffer, buffer_size, &required_size, ")", 1);
  306. } else if (PSA_ALG_IS_RSA_PSS_ANY_SALT(core_alg)) {
  307. append(&buffer, buffer_size, &required_size,
  308. "PSA_ALG_RSA_PSS_ANY_SALT(", 24 + 1);
  309. append_with_alg(&buffer, buffer_size, &required_size,
  310. psa_hash_algorithm_name,
  311. PSA_ALG_GET_HASH(core_alg));
  312. append(&buffer, buffer_size, &required_size, ")", 1);
  313. } else if (PSA_ALG_IS_TLS12_PRF(core_alg)) {
  314. append(&buffer, buffer_size, &required_size,
  315. "PSA_ALG_TLS12_PRF(", 17 + 1);
  316. append_with_alg(&buffer, buffer_size, &required_size,
  317. psa_hash_algorithm_name,
  318. PSA_ALG_GET_HASH(core_alg));
  319. append(&buffer, buffer_size, &required_size, ")", 1);
  320. } else if (PSA_ALG_IS_TLS12_PSK_TO_MS(core_alg)) {
  321. append(&buffer, buffer_size, &required_size,
  322. "PSA_ALG_TLS12_PSK_TO_MS(", 23 + 1);
  323. append_with_alg(&buffer, buffer_size, &required_size,
  324. psa_hash_algorithm_name,
  325. PSA_ALG_GET_HASH(core_alg));
  326. append(&buffer, buffer_size, &required_size, ")", 1);
  327. } else {
  328. append_integer(&buffer, buffer_size, &required_size,
  329. "0x%08lx", (unsigned long) core_alg);
  330. }
  331. break;
  332. }
  333. if (core_alg != alg) {
  334. if (length_modifier != NO_LENGTH_MODIFIER) {
  335. append(&buffer, buffer_size, &required_size, ", ", 2);
  336. append_integer(&buffer, buffer_size, &required_size,
  337. "%lu", length_modifier);
  338. }
  339. append(&buffer, buffer_size, &required_size, ")", 1);
  340. }
  341. buffer[0] = 0;
  342. return (int) required_size;
  343. }
  344. static int psa_snprint_key_usage(char *buffer, size_t buffer_size,
  345. psa_key_usage_t usage)
  346. {
  347. size_t required_size = 0;
  348. if (usage == 0) {
  349. if (buffer_size > 1) {
  350. buffer[0] = '0';
  351. buffer[1] = 0;
  352. } else if (buffer_size == 1) {
  353. buffer[0] = 0;
  354. }
  355. return 1;
  356. }
  357. if (usage & PSA_KEY_USAGE_COPY) {
  358. if (required_size != 0) {
  359. append(&buffer, buffer_size, &required_size, " | ", 3);
  360. }
  361. append(&buffer, buffer_size, &required_size, "PSA_KEY_USAGE_COPY", 18);
  362. usage ^= PSA_KEY_USAGE_COPY;
  363. }
  364. if (usage & PSA_KEY_USAGE_DECRYPT) {
  365. if (required_size != 0) {
  366. append(&buffer, buffer_size, &required_size, " | ", 3);
  367. }
  368. append(&buffer, buffer_size, &required_size, "PSA_KEY_USAGE_DECRYPT", 21);
  369. usage ^= PSA_KEY_USAGE_DECRYPT;
  370. }
  371. if (usage & PSA_KEY_USAGE_DERIVE) {
  372. if (required_size != 0) {
  373. append(&buffer, buffer_size, &required_size, " | ", 3);
  374. }
  375. append(&buffer, buffer_size, &required_size, "PSA_KEY_USAGE_DERIVE", 20);
  376. usage ^= PSA_KEY_USAGE_DERIVE;
  377. }
  378. if (usage & PSA_KEY_USAGE_ENCRYPT) {
  379. if (required_size != 0) {
  380. append(&buffer, buffer_size, &required_size, " | ", 3);
  381. }
  382. append(&buffer, buffer_size, &required_size, "PSA_KEY_USAGE_ENCRYPT", 21);
  383. usage ^= PSA_KEY_USAGE_ENCRYPT;
  384. }
  385. if (usage & PSA_KEY_USAGE_EXPORT) {
  386. if (required_size != 0) {
  387. append(&buffer, buffer_size, &required_size, " | ", 3);
  388. }
  389. append(&buffer, buffer_size, &required_size, "PSA_KEY_USAGE_EXPORT", 20);
  390. usage ^= PSA_KEY_USAGE_EXPORT;
  391. }
  392. if (usage & PSA_KEY_USAGE_SIGN_HASH) {
  393. if (required_size != 0) {
  394. append(&buffer, buffer_size, &required_size, " | ", 3);
  395. }
  396. append(&buffer, buffer_size, &required_size, "PSA_KEY_USAGE_SIGN_HASH", 23);
  397. usage ^= PSA_KEY_USAGE_SIGN_HASH;
  398. }
  399. if (usage & PSA_KEY_USAGE_SIGN_MESSAGE) {
  400. if (required_size != 0) {
  401. append(&buffer, buffer_size, &required_size, " | ", 3);
  402. }
  403. append(&buffer, buffer_size, &required_size, "PSA_KEY_USAGE_SIGN_MESSAGE", 26);
  404. usage ^= PSA_KEY_USAGE_SIGN_MESSAGE;
  405. }
  406. if (usage & PSA_KEY_USAGE_VERIFY_HASH) {
  407. if (required_size != 0) {
  408. append(&buffer, buffer_size, &required_size, " | ", 3);
  409. }
  410. append(&buffer, buffer_size, &required_size, "PSA_KEY_USAGE_VERIFY_HASH", 25);
  411. usage ^= PSA_KEY_USAGE_VERIFY_HASH;
  412. }
  413. if (usage & PSA_KEY_USAGE_VERIFY_MESSAGE) {
  414. if (required_size != 0) {
  415. append(&buffer, buffer_size, &required_size, " | ", 3);
  416. }
  417. append(&buffer, buffer_size, &required_size, "PSA_KEY_USAGE_VERIFY_MESSAGE", 28);
  418. usage ^= PSA_KEY_USAGE_VERIFY_MESSAGE;
  419. }
  420. if (usage != 0) {
  421. if (required_size != 0) {
  422. append(&buffer, buffer_size, &required_size, " | ", 3);
  423. }
  424. append_integer(&buffer, buffer_size, &required_size,
  425. "0x%08lx", (unsigned long) usage);
  426. } else {
  427. buffer[0] = 0;
  428. }
  429. return (int) required_size;
  430. }
  431. /* End of automatically generated file. */