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_SERVICE_FAILURE: return "PSA_ERROR_SERVICE_FAILURE";
27 case PSA_ERROR_STORAGE_FAILURE: return "PSA_ERROR_STORAGE_FAILURE";
28 case PSA_SUCCESS: return "PSA_SUCCESS";
29 default: return NULL;
30 }
31 }
32
psa_ecc_family_name(psa_ecc_family_t curve)33 static const char *psa_ecc_family_name(psa_ecc_family_t curve)
34 {
35 switch (curve) {
36 case PSA_ECC_FAMILY_BRAINPOOL_P_R1: return "PSA_ECC_FAMILY_BRAINPOOL_P_R1";
37 case PSA_ECC_FAMILY_MONTGOMERY: return "PSA_ECC_FAMILY_MONTGOMERY";
38 case PSA_ECC_FAMILY_SECP_K1: return "PSA_ECC_FAMILY_SECP_K1";
39 case PSA_ECC_FAMILY_SECP_R1: return "PSA_ECC_FAMILY_SECP_R1";
40 case PSA_ECC_FAMILY_SECP_R2: return "PSA_ECC_FAMILY_SECP_R2";
41 case PSA_ECC_FAMILY_SECT_K1: return "PSA_ECC_FAMILY_SECT_K1";
42 case PSA_ECC_FAMILY_SECT_R1: return "PSA_ECC_FAMILY_SECT_R1";
43 case PSA_ECC_FAMILY_SECT_R2: return "PSA_ECC_FAMILY_SECT_R2";
44 case PSA_ECC_FAMILY_TWISTED_EDWARDS: return "PSA_ECC_FAMILY_TWISTED_EDWARDS";
45 default: return NULL;
46 }
47 }
48
psa_dh_family_name(psa_dh_family_t group)49 static const char *psa_dh_family_name(psa_dh_family_t group)
50 {
51 switch (group) {
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_MD5: return "PSA_ALG_MD5";
63 case PSA_ALG_RIPEMD160: return "PSA_ALG_RIPEMD160";
64 case PSA_ALG_SHA3_224: return "PSA_ALG_SHA3_224";
65 case PSA_ALG_SHA3_256: return "PSA_ALG_SHA3_256";
66 case PSA_ALG_SHA3_384: return "PSA_ALG_SHA3_384";
67 case PSA_ALG_SHA3_512: return "PSA_ALG_SHA3_512";
68 case PSA_ALG_SHAKE256_512: return "PSA_ALG_SHAKE256_512";
69 case PSA_ALG_SHA_1: return "PSA_ALG_SHA_1";
70 case PSA_ALG_SHA_224: return "PSA_ALG_SHA_224";
71 case PSA_ALG_SHA_256: return "PSA_ALG_SHA_256";
72 case PSA_ALG_SHA_384: return "PSA_ALG_SHA_384";
73 case PSA_ALG_SHA_512: return "PSA_ALG_SHA_512";
74 case PSA_ALG_SHA_512_224: return "PSA_ALG_SHA_512_224";
75 case PSA_ALG_SHA_512_256: return "PSA_ALG_SHA_512_256";
76 default: return NULL;
77 }
78 }
79
psa_ka_algorithm_name(psa_algorithm_t ka_alg)80 static const char *psa_ka_algorithm_name(psa_algorithm_t ka_alg)
81 {
82 switch (ka_alg) {
83 case PSA_ALG_CATEGORY_KEY_AGREEMENT: return "PSA_ALG_CATEGORY_KEY_AGREEMENT";
84 case PSA_ALG_ECDH: return "PSA_ALG_ECDH";
85 case PSA_ALG_FFDH: return "PSA_ALG_FFDH";
86 default: return NULL;
87 }
88 }
89
psa_snprint_key_type(char * buffer,size_t buffer_size,psa_key_type_t type)90 static int psa_snprint_key_type(char *buffer, size_t buffer_size,
91 psa_key_type_t type)
92 {
93 size_t required_size = 0;
94 switch (type) {
95 case PSA_KEY_TYPE_AES: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_AES", 16); break;
96 case PSA_KEY_TYPE_ARIA: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_ARIA", 17); break;
97 case PSA_KEY_TYPE_CAMELLIA: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_CAMELLIA", 21); break;
98 case PSA_KEY_TYPE_CATEGORY_FLAG_PAIR: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_CATEGORY_FLAG_PAIR", 31); break;
99 case PSA_KEY_TYPE_CATEGORY_KEY_PAIR: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_CATEGORY_KEY_PAIR", 30); break;
100 case PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY", 32); break;
101 case PSA_KEY_TYPE_CATEGORY_RAW: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_CATEGORY_RAW", 25); break;
102 case PSA_KEY_TYPE_CATEGORY_SYMMETRIC: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_CATEGORY_SYMMETRIC", 31); break;
103 case PSA_KEY_TYPE_CHACHA20: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_CHACHA20", 21); break;
104 case PSA_KEY_TYPE_DERIVE: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_DERIVE", 19); break;
105 case PSA_KEY_TYPE_DES: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_DES", 16); break;
106 case PSA_KEY_TYPE_DH_KEY_PAIR_BASE: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_DH_KEY_PAIR_BASE", 29); break;
107 case PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE", 31); break;
108 case PSA_KEY_TYPE_DSA_KEY_PAIR: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_DSA_KEY_PAIR", 25); break;
109 case PSA_KEY_TYPE_DSA_PUBLIC_KEY: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_DSA_PUBLIC_KEY", 27); break;
110 case PSA_KEY_TYPE_ECC_KEY_PAIR_BASE: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_ECC_KEY_PAIR_BASE", 30); break;
111 case PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE", 32); break;
112 case PSA_KEY_TYPE_HMAC: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_HMAC", 17); break;
113 case PSA_KEY_TYPE_NONE: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_NONE", 17); break;
114 case PSA_KEY_TYPE_PASSWORD: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_PASSWORD", 21); break;
115 case PSA_KEY_TYPE_PASSWORD_HASH: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_PASSWORD_HASH", 26); break;
116 case PSA_KEY_TYPE_PEPPER: append(&buffer, buffer_size, &required_size, "PSA_KEY_TYPE_PEPPER", 19); 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_PAKE: append(&buffer, buffer_size, &required_size, "PSA_ALG_CATEGORY_PAKE", 21); break;
199 case PSA_ALG_CATEGORY_SIGN: append(&buffer, buffer_size, &required_size, "PSA_ALG_CATEGORY_SIGN", 21); break;
200 case PSA_ALG_CBC_MAC: append(&buffer, buffer_size, &required_size, "PSA_ALG_CBC_MAC", 15); break;
201 case PSA_ALG_CBC_NO_PADDING: append(&buffer, buffer_size, &required_size, "PSA_ALG_CBC_NO_PADDING", 22); break;
202 case PSA_ALG_CBC_PKCS7: append(&buffer, buffer_size, &required_size, "PSA_ALG_CBC_PKCS7", 17); break;
203 case PSA_ALG_CCM: append(&buffer, buffer_size, &required_size, "PSA_ALG_CCM", 11); break;
204 case PSA_ALG_CCM_STAR_NO_TAG: append(&buffer, buffer_size, &required_size, "PSA_ALG_CCM_STAR_NO_TAG", 23); break;
205 case PSA_ALG_CFB: append(&buffer, buffer_size, &required_size, "PSA_ALG_CFB", 11); break;
206 case PSA_ALG_CHACHA20_POLY1305: append(&buffer, buffer_size, &required_size, "PSA_ALG_CHACHA20_POLY1305", 25); break;
207 case PSA_ALG_CIPHER_MAC_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_CIPHER_MAC_BASE", 23); break;
208 case PSA_ALG_CMAC: append(&buffer, buffer_size, &required_size, "PSA_ALG_CMAC", 12); break;
209 case PSA_ALG_CTR: append(&buffer, buffer_size, &required_size, "PSA_ALG_CTR", 11); break;
210 case PSA_ALG_DETERMINISTIC_DSA_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_DETERMINISTIC_DSA_BASE", 30); break;
211 case PSA_ALG_DETERMINISTIC_ECDSA_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_DETERMINISTIC_ECDSA_BASE", 32); break;
212 case PSA_ALG_DSA_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_DSA_BASE", 16); break;
213 case PSA_ALG_ECB_NO_PADDING: append(&buffer, buffer_size, &required_size, "PSA_ALG_ECB_NO_PADDING", 22); break;
214 case PSA_ALG_ECDH: append(&buffer, buffer_size, &required_size, "PSA_ALG_ECDH", 12); break;
215 case PSA_ALG_ECDSA_ANY: append(&buffer, buffer_size, &required_size, "PSA_ALG_ECDSA_ANY", 17); break;
216 case PSA_ALG_ED25519PH: append(&buffer, buffer_size, &required_size, "PSA_ALG_ED25519PH", 17); break;
217 case PSA_ALG_ED448PH: append(&buffer, buffer_size, &required_size, "PSA_ALG_ED448PH", 15); break;
218 case PSA_ALG_FFDH: append(&buffer, buffer_size, &required_size, "PSA_ALG_FFDH", 12); break;
219 case PSA_ALG_GCM: append(&buffer, buffer_size, &required_size, "PSA_ALG_GCM", 11); break;
220 case PSA_ALG_HASH_EDDSA_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_HASH_EDDSA_BASE", 23); break;
221 case PSA_ALG_HKDF_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_HKDF_BASE", 17); break;
222 case PSA_ALG_HKDF_EXPAND_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_HKDF_EXPAND_BASE", 24); break;
223 case PSA_ALG_HKDF_EXTRACT_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_HKDF_EXTRACT_BASE", 25); break;
224 case PSA_ALG_HMAC_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_HMAC_BASE", 17); break;
225 case PSA_ALG_JPAKE: append(&buffer, buffer_size, &required_size, "PSA_ALG_JPAKE", 13); break;
226 case PSA_ALG_MD5: append(&buffer, buffer_size, &required_size, "PSA_ALG_MD5", 11); break;
227 case PSA_ALG_NONE: append(&buffer, buffer_size, &required_size, "PSA_ALG_NONE", 12); break;
228 case PSA_ALG_OFB: append(&buffer, buffer_size, &required_size, "PSA_ALG_OFB", 11); break;
229 case PSA_ALG_PBKDF2_AES_CMAC_PRF_128: append(&buffer, buffer_size, &required_size, "PSA_ALG_PBKDF2_AES_CMAC_PRF_128", 31); break;
230 case PSA_ALG_PBKDF2_HMAC_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_PBKDF2_HMAC_BASE", 24); break;
231 case PSA_ALG_PURE_EDDSA: append(&buffer, buffer_size, &required_size, "PSA_ALG_PURE_EDDSA", 18); break;
232 case PSA_ALG_RIPEMD160: append(&buffer, buffer_size, &required_size, "PSA_ALG_RIPEMD160", 17); break;
233 case PSA_ALG_RSA_OAEP_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_RSA_OAEP_BASE", 21); break;
234 case PSA_ALG_RSA_PKCS1V15_CRYPT: append(&buffer, buffer_size, &required_size, "PSA_ALG_RSA_PKCS1V15_CRYPT", 26); break;
235 case PSA_ALG_RSA_PKCS1V15_SIGN_RAW: append(&buffer, buffer_size, &required_size, "PSA_ALG_RSA_PKCS1V15_SIGN_RAW", 29); break;
236 case PSA_ALG_RSA_PSS_ANY_SALT_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_RSA_PSS_ANY_SALT_BASE", 29); break;
237 case PSA_ALG_RSA_PSS_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_RSA_PSS_BASE", 20); break;
238 case PSA_ALG_SHA3_224: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA3_224", 16); break;
239 case PSA_ALG_SHA3_256: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA3_256", 16); break;
240 case PSA_ALG_SHA3_384: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA3_384", 16); break;
241 case PSA_ALG_SHA3_512: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA3_512", 16); break;
242 case PSA_ALG_SHAKE256_512: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHAKE256_512", 20); break;
243 case PSA_ALG_SHA_1: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA_1", 13); break;
244 case PSA_ALG_SHA_224: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA_224", 15); break;
245 case PSA_ALG_SHA_256: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA_256", 15); break;
246 case PSA_ALG_SHA_384: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA_384", 15); break;
247 case PSA_ALG_SHA_512: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA_512", 15); break;
248 case PSA_ALG_SHA_512_224: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA_512_224", 19); break;
249 case PSA_ALG_SHA_512_256: append(&buffer, buffer_size, &required_size, "PSA_ALG_SHA_512_256", 19); break;
250 case PSA_ALG_STREAM_CIPHER: append(&buffer, buffer_size, &required_size, "PSA_ALG_STREAM_CIPHER", 21); break;
251 case PSA_ALG_TLS12_ECJPAKE_TO_PMS: append(&buffer, buffer_size, &required_size, "PSA_ALG_TLS12_ECJPAKE_TO_PMS", 28); break;
252 case PSA_ALG_TLS12_PRF_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_TLS12_PRF_BASE", 22); break;
253 case PSA_ALG_TLS12_PSK_TO_MS_BASE: append(&buffer, buffer_size, &required_size, "PSA_ALG_TLS12_PSK_TO_MS_BASE", 28); break;
254 case PSA_ALG_XTS: append(&buffer, buffer_size, &required_size, "PSA_ALG_XTS", 11); break;
255 default:
256 if (PSA_ALG_IS_DETERMINISTIC_DSA(core_alg)) {
257 append(&buffer, buffer_size, &required_size,
258 "PSA_ALG_DETERMINISTIC_DSA(", 25 + 1);
259 append_with_alg(&buffer, buffer_size, &required_size,
260 psa_hash_algorithm_name,
261 PSA_ALG_GET_HASH(core_alg));
262 append(&buffer, buffer_size, &required_size, ")", 1);
263 } else if (PSA_ALG_IS_DETERMINISTIC_ECDSA(core_alg)) {
264 append(&buffer, buffer_size, &required_size,
265 "PSA_ALG_DETERMINISTIC_ECDSA(", 27 + 1);
266 append_with_alg(&buffer, buffer_size, &required_size,
267 psa_hash_algorithm_name,
268 PSA_ALG_GET_HASH(core_alg));
269 append(&buffer, buffer_size, &required_size, ")", 1);
270 } else if (PSA_ALG_IS_RANDOMIZED_DSA(core_alg)) {
271 append(&buffer, buffer_size, &required_size,
272 "PSA_ALG_DSA(", 11 + 1);
273 append_with_alg(&buffer, buffer_size, &required_size,
274 psa_hash_algorithm_name,
275 PSA_ALG_GET_HASH(core_alg));
276 append(&buffer, buffer_size, &required_size, ")", 1);
277 } else if (PSA_ALG_IS_RANDOMIZED_ECDSA(core_alg)) {
278 append(&buffer, buffer_size, &required_size,
279 "PSA_ALG_ECDSA(", 13 + 1);
280 append_with_alg(&buffer, buffer_size, &required_size,
281 psa_hash_algorithm_name,
282 PSA_ALG_GET_HASH(core_alg));
283 append(&buffer, buffer_size, &required_size, ")", 1);
284 } else if (PSA_ALG_IS_HKDF(core_alg)) {
285 append(&buffer, buffer_size, &required_size,
286 "PSA_ALG_HKDF(", 12 + 1);
287 append_with_alg(&buffer, buffer_size, &required_size,
288 psa_hash_algorithm_name,
289 PSA_ALG_GET_HASH(core_alg));
290 append(&buffer, buffer_size, &required_size, ")", 1);
291 } else if (PSA_ALG_IS_HKDF_EXPAND(core_alg)) {
292 append(&buffer, buffer_size, &required_size,
293 "PSA_ALG_HKDF_EXPAND(", 19 + 1);
294 append_with_alg(&buffer, buffer_size, &required_size,
295 psa_hash_algorithm_name,
296 PSA_ALG_GET_HASH(core_alg));
297 append(&buffer, buffer_size, &required_size, ")", 1);
298 } else if (PSA_ALG_IS_HKDF_EXTRACT(core_alg)) {
299 append(&buffer, buffer_size, &required_size,
300 "PSA_ALG_HKDF_EXTRACT(", 20 + 1);
301 append_with_alg(&buffer, buffer_size, &required_size,
302 psa_hash_algorithm_name,
303 PSA_ALG_GET_HASH(core_alg));
304 append(&buffer, buffer_size, &required_size, ")", 1);
305 } else if (PSA_ALG_IS_HMAC(core_alg)) {
306 append(&buffer, buffer_size, &required_size,
307 "PSA_ALG_HMAC(", 12 + 1);
308 append_with_alg(&buffer, buffer_size, &required_size,
309 psa_hash_algorithm_name,
310 PSA_ALG_GET_HASH(core_alg));
311 append(&buffer, buffer_size, &required_size, ")", 1);
312 } else if (PSA_ALG_IS_PBKDF2_HMAC(core_alg)) {
313 append(&buffer, buffer_size, &required_size,
314 "PSA_ALG_PBKDF2_HMAC(", 19 + 1);
315 append_with_alg(&buffer, buffer_size, &required_size,
316 psa_hash_algorithm_name,
317 PSA_ALG_GET_HASH(core_alg));
318 append(&buffer, buffer_size, &required_size, ")", 1);
319 } else if (PSA_ALG_IS_RSA_OAEP(core_alg)) {
320 append(&buffer, buffer_size, &required_size,
321 "PSA_ALG_RSA_OAEP(", 16 + 1);
322 append_with_alg(&buffer, buffer_size, &required_size,
323 psa_hash_algorithm_name,
324 PSA_ALG_GET_HASH(core_alg));
325 append(&buffer, buffer_size, &required_size, ")", 1);
326 } else if (PSA_ALG_IS_RSA_PKCS1V15_SIGN(core_alg)) {
327 append(&buffer, buffer_size, &required_size,
328 "PSA_ALG_RSA_PKCS1V15_SIGN(", 25 + 1);
329 append_with_alg(&buffer, buffer_size, &required_size,
330 psa_hash_algorithm_name,
331 PSA_ALG_GET_HASH(core_alg));
332 append(&buffer, buffer_size, &required_size, ")", 1);
333 } else if (PSA_ALG_IS_RSA_PSS_STANDARD_SALT(core_alg)) {
334 append(&buffer, buffer_size, &required_size,
335 "PSA_ALG_RSA_PSS(", 15 + 1);
336 append_with_alg(&buffer, buffer_size, &required_size,
337 psa_hash_algorithm_name,
338 PSA_ALG_GET_HASH(core_alg));
339 append(&buffer, buffer_size, &required_size, ")", 1);
340 } else if (PSA_ALG_IS_RSA_PSS_ANY_SALT(core_alg)) {
341 append(&buffer, buffer_size, &required_size,
342 "PSA_ALG_RSA_PSS_ANY_SALT(", 24 + 1);
343 append_with_alg(&buffer, buffer_size, &required_size,
344 psa_hash_algorithm_name,
345 PSA_ALG_GET_HASH(core_alg));
346 append(&buffer, buffer_size, &required_size, ")", 1);
347 } else if (PSA_ALG_IS_TLS12_PRF(core_alg)) {
348 append(&buffer, buffer_size, &required_size,
349 "PSA_ALG_TLS12_PRF(", 17 + 1);
350 append_with_alg(&buffer, buffer_size, &required_size,
351 psa_hash_algorithm_name,
352 PSA_ALG_GET_HASH(core_alg));
353 append(&buffer, buffer_size, &required_size, ")", 1);
354 } else if (PSA_ALG_IS_TLS12_PSK_TO_MS(core_alg)) {
355 append(&buffer, buffer_size, &required_size,
356 "PSA_ALG_TLS12_PSK_TO_MS(", 23 + 1);
357 append_with_alg(&buffer, buffer_size, &required_size,
358 psa_hash_algorithm_name,
359 PSA_ALG_GET_HASH(core_alg));
360 append(&buffer, buffer_size, &required_size, ")", 1);
361 } else {
362 append_integer(&buffer, buffer_size, &required_size,
363 "0x%08lx", (unsigned long) core_alg);
364 }
365 break;
366 }
367 if (core_alg != alg) {
368 if (length_modifier != NO_LENGTH_MODIFIER) {
369 append(&buffer, buffer_size, &required_size, ", ", 2);
370 append_integer(&buffer, buffer_size, &required_size,
371 "%lu", length_modifier);
372 }
373 append(&buffer, buffer_size, &required_size, ")", 1);
374 }
375 buffer[0] = 0;
376 return (int) required_size;
377 }
378
psa_snprint_key_usage(char * buffer,size_t buffer_size,psa_key_usage_t usage)379 static int psa_snprint_key_usage(char *buffer, size_t buffer_size,
380 psa_key_usage_t usage)
381 {
382 size_t required_size = 0;
383 if (usage == 0) {
384 if (buffer_size > 1) {
385 buffer[0] = '0';
386 buffer[1] = 0;
387 } else if (buffer_size == 1) {
388 buffer[0] = 0;
389 }
390 return 1;
391 }
392 if (usage & PSA_KEY_USAGE_COPY) {
393 if (required_size != 0) {
394 append(&buffer, buffer_size, &required_size, " | ", 3);
395 }
396 append(&buffer, buffer_size, &required_size, "PSA_KEY_USAGE_COPY", 18);
397 usage ^= PSA_KEY_USAGE_COPY;
398 }
399 if (usage & PSA_KEY_USAGE_DECRYPT) {
400 if (required_size != 0) {
401 append(&buffer, buffer_size, &required_size, " | ", 3);
402 }
403 append(&buffer, buffer_size, &required_size, "PSA_KEY_USAGE_DECRYPT", 21);
404 usage ^= PSA_KEY_USAGE_DECRYPT;
405 }
406 if (usage & PSA_KEY_USAGE_DERIVE) {
407 if (required_size != 0) {
408 append(&buffer, buffer_size, &required_size, " | ", 3);
409 }
410 append(&buffer, buffer_size, &required_size, "PSA_KEY_USAGE_DERIVE", 20);
411 usage ^= PSA_KEY_USAGE_DERIVE;
412 }
413 if (usage & PSA_KEY_USAGE_ENCRYPT) {
414 if (required_size != 0) {
415 append(&buffer, buffer_size, &required_size, " | ", 3);
416 }
417 append(&buffer, buffer_size, &required_size, "PSA_KEY_USAGE_ENCRYPT", 21);
418 usage ^= PSA_KEY_USAGE_ENCRYPT;
419 }
420 if (usage & PSA_KEY_USAGE_EXPORT) {
421 if (required_size != 0) {
422 append(&buffer, buffer_size, &required_size, " | ", 3);
423 }
424 append(&buffer, buffer_size, &required_size, "PSA_KEY_USAGE_EXPORT", 20);
425 usage ^= PSA_KEY_USAGE_EXPORT;
426 }
427 if (usage & PSA_KEY_USAGE_SIGN_HASH) {
428 if (required_size != 0) {
429 append(&buffer, buffer_size, &required_size, " | ", 3);
430 }
431 append(&buffer, buffer_size, &required_size, "PSA_KEY_USAGE_SIGN_HASH", 23);
432 usage ^= PSA_KEY_USAGE_SIGN_HASH;
433 }
434 if (usage & PSA_KEY_USAGE_SIGN_MESSAGE) {
435 if (required_size != 0) {
436 append(&buffer, buffer_size, &required_size, " | ", 3);
437 }
438 append(&buffer, buffer_size, &required_size, "PSA_KEY_USAGE_SIGN_MESSAGE", 26);
439 usage ^= PSA_KEY_USAGE_SIGN_MESSAGE;
440 }
441 if (usage & PSA_KEY_USAGE_VERIFY_DERIVATION) {
442 if (required_size != 0) {
443 append(&buffer, buffer_size, &required_size, " | ", 3);
444 }
445 append(&buffer, buffer_size, &required_size, "PSA_KEY_USAGE_VERIFY_DERIVATION", 31);
446 usage ^= PSA_KEY_USAGE_VERIFY_DERIVATION;
447 }
448 if (usage & PSA_KEY_USAGE_VERIFY_HASH) {
449 if (required_size != 0) {
450 append(&buffer, buffer_size, &required_size, " | ", 3);
451 }
452 append(&buffer, buffer_size, &required_size, "PSA_KEY_USAGE_VERIFY_HASH", 25);
453 usage ^= PSA_KEY_USAGE_VERIFY_HASH;
454 }
455 if (usage & PSA_KEY_USAGE_VERIFY_MESSAGE) {
456 if (required_size != 0) {
457 append(&buffer, buffer_size, &required_size, " | ", 3);
458 }
459 append(&buffer, buffer_size, &required_size, "PSA_KEY_USAGE_VERIFY_MESSAGE", 28);
460 usage ^= PSA_KEY_USAGE_VERIFY_MESSAGE;
461 }
462 if (usage != 0) {
463 if (required_size != 0) {
464 append(&buffer, buffer_size, &required_size, " | ", 3);
465 }
466 append_integer(&buffer, buffer_size, &required_size,
467 "0x%08lx", (unsigned long) usage);
468 } else {
469 buffer[0] = 0;
470 }
471 return (int) required_size;
472 }
473
474 /* End of automatically generated file. */
475