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