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