File: crypto_impl.h

package info (click to toggle)
optee-os 4.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,960 kB
  • sloc: ansic: 444,388; asm: 12,922; python: 3,719; makefile: 1,681; sh: 238
file content (560 lines) | stat: -rw-r--r-- 17,840 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
/* SPDX-License-Identifier: BSD-2-Clause */
/*
 * Copyright (c) 2019, Linaro Limited
 * Copyright (c) 2021, SumUp Services GmbH
 */

#ifndef __CRYPTO_CRYPTO_IMPL_H
#define __CRYPTO_CRYPTO_IMPL_H

#include <crypto/crypto.h>
#include <tee_api_types.h>

/*
 * The crypto context used by the crypto_hash_*() functions is defined by
 * struct crypto_hash_ctx.
 */
struct crypto_hash_ctx {
	const struct crypto_hash_ops *ops;
};

struct crypto_hash_ops {
	TEE_Result (*init)(struct crypto_hash_ctx *ctx);
	TEE_Result (*update)(struct crypto_hash_ctx *ctx, const uint8_t *data,
			     size_t len);
	TEE_Result (*final)(struct crypto_hash_ctx *ctx, uint8_t *digest,
			    size_t len);
	void (*free_ctx)(struct crypto_hash_ctx *ctx);
	void (*copy_state)(struct crypto_hash_ctx *dst_ctx,
			   struct crypto_hash_ctx *src_ctx);
};

#define CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(name, type) \
	static inline TEE_Result \
	crypto_##name##_alloc_ctx(struct crypto_##type##_ctx **ctx __unused) \
	{ return TEE_ERROR_NOT_IMPLEMENTED; }

#if defined(CFG_CRYPTO_MD5)
TEE_Result crypto_md5_alloc_ctx(struct crypto_hash_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(md5, hash)
#endif

#if defined(CFG_CRYPTO_SHA1)
TEE_Result crypto_sha1_alloc_ctx(struct crypto_hash_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha1, hash)
#endif

#if defined(CFG_CRYPTO_SHA224)
TEE_Result crypto_sha224_alloc_ctx(struct crypto_hash_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha224, hash)
#endif

#if defined(CFG_CRYPTO_SHA256)
TEE_Result crypto_sha256_alloc_ctx(struct crypto_hash_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha256, hash)
#endif

#if defined(CFG_CRYPTO_SHA384)
TEE_Result crypto_sha384_alloc_ctx(struct crypto_hash_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha384, hash)
#endif

#if defined(CFG_CRYPTO_SHA512)
TEE_Result crypto_sha512_alloc_ctx(struct crypto_hash_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha512, hash)
#endif

#if defined(CFG_CRYPTO_SM3)
TEE_Result crypto_sm3_alloc_ctx(struct crypto_hash_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sm3, hash)
#endif

#if defined(CFG_CRYPTO_SHA3_224)
TEE_Result crypto_sha3_224_alloc_ctx(struct crypto_hash_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha3_224, hash)
#endif

#if defined(CFG_CRYPTO_SHA3_256)
TEE_Result crypto_sha3_256_alloc_ctx(struct crypto_hash_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha3_256, hash)
#endif

#if defined(CFG_CRYPTO_SHA3_384)
TEE_Result crypto_sha3_384_alloc_ctx(struct crypto_hash_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha3_384, hash)
#endif

#if defined(CFG_CRYPTO_SHA3_512)
TEE_Result crypto_sha3_512_alloc_ctx(struct crypto_hash_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha3_512, hash)
#endif

#if defined(CFG_CRYPTO_SHAKE128)
TEE_Result crypto_shake128_alloc_ctx(struct crypto_hash_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(shake128, hash)
#endif

#if defined(CFG_CRYPTO_SHAKE256)
TEE_Result crypto_shake256_alloc_ctx(struct crypto_hash_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(shake256, hash)
#endif

/*
 * The crypto context used by the crypto_mac_*() functions is defined by
 * struct crypto_mac_ctx.
 */
struct crypto_mac_ctx {
	const struct crypto_mac_ops *ops;
};

struct crypto_mac_ops {
	TEE_Result (*init)(struct crypto_mac_ctx *ctx, const uint8_t *key,
			   size_t len);
	TEE_Result (*update)(struct crypto_mac_ctx *ctx, const uint8_t *data,
			     size_t len);
	TEE_Result (*final)(struct crypto_mac_ctx *ctx, uint8_t *digest,
			    size_t len);
	void (*free_ctx)(struct crypto_mac_ctx *ctx);
	void (*copy_state)(struct crypto_mac_ctx *dst_ctx,
			   struct crypto_mac_ctx *src_ctx);
};

#if defined(CFG_CRYPTO_HMAC) && defined(CFG_CRYPTO_MD5)
TEE_Result crypto_hmac_md5_alloc_ctx(struct crypto_mac_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_md5, mac)
#endif

#if defined(CFG_CRYPTO_HMAC) && defined(CFG_CRYPTO_SHA1)
TEE_Result crypto_hmac_sha1_alloc_ctx(struct crypto_mac_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha1, mac)
#endif

#if defined(CFG_CRYPTO_HMAC) && defined(CFG_CRYPTO_SHA224)
TEE_Result crypto_hmac_sha224_alloc_ctx(struct crypto_mac_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha224, mac)
#endif

#if defined(CFG_CRYPTO_HMAC) && defined(CFG_CRYPTO_SHA256)
TEE_Result crypto_hmac_sha256_alloc_ctx(struct crypto_mac_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha256, mac)
#endif

#if defined(CFG_CRYPTO_HMAC) && defined(CFG_CRYPTO_SHA384)
TEE_Result crypto_hmac_sha384_alloc_ctx(struct crypto_mac_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha384, mac)
#endif

#if defined(CFG_CRYPTO_HMAC) && defined(CFG_CRYPTO_SHA512)
TEE_Result crypto_hmac_sha512_alloc_ctx(struct crypto_mac_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha512, mac)
#endif

#if defined(CFG_CRYPTO_HMAC) && defined(CFG_CRYPTO_SHA3_224)
TEE_Result crypto_hmac_sha3_224_alloc_ctx(struct crypto_mac_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha3_224, mac)
#endif

#if defined(CFG_CRYPTO_HMAC) && defined(CFG_CRYPTO_SHA3_256)
TEE_Result crypto_hmac_sha3_256_alloc_ctx(struct crypto_mac_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha3_256, mac)
#endif

#if defined(CFG_CRYPTO_HMAC) && defined(CFG_CRYPTO_SHA3_384)
TEE_Result crypto_hmac_sha3_384_alloc_ctx(struct crypto_mac_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha3_384, mac)
#endif

#if defined(CFG_CRYPTO_HMAC) && defined(CFG_CRYPTO_SHA3_512)
TEE_Result crypto_hmac_sha3_512_alloc_ctx(struct crypto_mac_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha3_512, mac)
#endif

#if defined(CFG_CRYPTO_SM3) && defined(CFG_CRYPTO_HMAC)
TEE_Result crypto_hmac_sm3_alloc_ctx(struct crypto_mac_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sm3, mac)
#endif

#if defined(CFG_CRYPTO_CBC_MAC)
TEE_Result crypto_aes_cbc_mac_nopad_alloc_ctx(struct crypto_mac_ctx **ctx);
TEE_Result crypto_aes_cbc_mac_pkcs5_alloc_ctx(struct crypto_mac_ctx **ctx);
TEE_Result crypto_des_cbc_mac_nopad_alloc_ctx(struct crypto_mac_ctx **ctx);
TEE_Result crypto_des_cbc_mac_pkcs5_alloc_ctx(struct crypto_mac_ctx **ctx);
TEE_Result crypto_des3_cbc_mac_nopad_alloc_ctx(struct crypto_mac_ctx **ctx);
TEE_Result crypto_des3_cbc_mac_pkcs5_alloc_ctx(struct crypto_mac_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_cbc_mac_nopad, mac)
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_cbc_mac_pkcs5, mac)
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des_cbc_mac_nopad, mac)
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des_cbc_mac_pkcs5, mac)
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des3_cbc_mac_nopad, mac)
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des3_cbc_mac_pkcs5, mac)
#endif

#if defined(CFG_CRYPTO_CMAC)
TEE_Result crypto_aes_cmac_alloc_ctx(struct crypto_mac_ctx **ctx);
TEE_Result crypto_des3_cmac_alloc_ctx(struct crypto_mac_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_cmac, mac)
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des3_cmac, mac)
#endif

/*
 * The crypto context used by the crypto_cipher_*() functions is defined by
 * struct crypto_cipher_ctx.
 */
struct crypto_cipher_ctx {
	const struct crypto_cipher_ops *ops;
};

struct crypto_cipher_ops {
	TEE_Result (*init)(struct crypto_cipher_ctx *ctx,
			   TEE_OperationMode mode,
			   const uint8_t *key1, size_t key1_len,
			   const uint8_t *key2, size_t key2_len,
			   const uint8_t *iv, size_t iv_len);
	TEE_Result (*update)(struct crypto_cipher_ctx *ctx, bool last_block,
			     const uint8_t *data, size_t len, uint8_t *dst);
	void (*final)(struct crypto_cipher_ctx *ctx);

	void (*free_ctx)(struct crypto_cipher_ctx *ctx);
	void (*copy_state)(struct crypto_cipher_ctx *dst_ctx,
			   struct crypto_cipher_ctx *src_ctx);
};

#if defined(CFG_CRYPTO_AES) && defined(CFG_CRYPTO_ECB)
TEE_Result crypto_aes_ecb_alloc_ctx(struct crypto_cipher_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_ecb, cipher)
#endif

#if defined(CFG_CRYPTO_AES) && defined(CFG_CRYPTO_CBC)
TEE_Result crypto_aes_cbc_alloc_ctx(struct crypto_cipher_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_cbc, cipher)
#endif

#if defined(CFG_CRYPTO_AES) && defined(CFG_CRYPTO_CTR)
TEE_Result crypto_aes_ctr_alloc_ctx(struct crypto_cipher_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_ctr, cipher)
#endif

#if defined(CFG_CRYPTO_AES) && defined(CFG_CRYPTO_CTS)
TEE_Result crypto_aes_cts_alloc_ctx(struct crypto_cipher_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_cts, cipher)
#endif

#if defined(CFG_CRYPTO_AES) && defined(CFG_CRYPTO_XTS)
TEE_Result crypto_aes_xts_alloc_ctx(struct crypto_cipher_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_xts, cipher)
#endif

#if defined(CFG_CRYPTO_DES) && defined(CFG_CRYPTO_ECB)
TEE_Result crypto_des_ecb_alloc_ctx(struct crypto_cipher_ctx **ctx);
TEE_Result crypto_des3_ecb_alloc_ctx(struct crypto_cipher_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des_ecb, cipher)
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des3_ecb, cipher)
#endif

#if defined(CFG_CRYPTO_DES) && defined(CFG_CRYPTO_CBC)
TEE_Result crypto_des_cbc_alloc_ctx(struct crypto_cipher_ctx **ctx);
TEE_Result crypto_des3_cbc_alloc_ctx(struct crypto_cipher_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des_cbc, cipher)
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des3_cbc, cipher)
#endif

#if defined(CFG_CRYPTO_SM4) && defined(CFG_CRYPTO_ECB)
TEE_Result crypto_sm4_ecb_alloc_ctx(struct crypto_cipher_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sm4_ecb, cipher)
#endif

#if defined(CFG_CRYPTO_SM4) && defined(CFG_CRYPTO_CBC)
TEE_Result crypto_sm4_cbc_alloc_ctx(struct crypto_cipher_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sm4_cbc, cipher)
#endif

#if defined(CFG_CRYPTO_SM4) && defined(CFG_CRYPTO_CTR)
TEE_Result crypto_sm4_ctr_alloc_ctx(struct crypto_cipher_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sm4_ctr, cipher)
#endif

#if defined(CFG_CRYPTO_SM4) && defined(CFG_CRYPTO_XTS)
TEE_Result crypto_sm4_xts_alloc_ctx(struct crypto_cipher_ctx **ctx);
#else
CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sm4_xts, cipher)
#endif

/*
 * The crypto context used by the crypto_authen_*() functions below is
 * defined by struct crypto_authenc_ctx.
 */
struct crypto_authenc_ctx {
	const struct crypto_authenc_ops *ops;
};

struct crypto_authenc_ops {
	TEE_Result (*init)(struct crypto_authenc_ctx *ctx,
			   TEE_OperationMode mode,
			   const uint8_t *key, size_t key_len,
			   const uint8_t *nonce, size_t nonce_len,
			   size_t tag_len, size_t aad_len,
			   size_t payload_len);
	TEE_Result (*update_aad)(struct crypto_authenc_ctx *ctx,
				 const uint8_t *data, size_t len);
	TEE_Result (*update_payload)(struct crypto_authenc_ctx *ctx,
				     TEE_OperationMode mode,
				     const uint8_t *src_data, size_t len,
				     uint8_t *dst_data);
	TEE_Result (*enc_final)(struct crypto_authenc_ctx *ctx,
				const uint8_t *src_data, size_t len,
				uint8_t *dst_data, uint8_t *dst_tag,
				size_t *dst_tag_len);
	TEE_Result (*dec_final)(struct crypto_authenc_ctx *ctx,
				const uint8_t *src_data, size_t len,
				uint8_t *dst_data, const uint8_t *tag,
				size_t tag_len);
	void (*final)(struct crypto_authenc_ctx *ctx);
	void (*free_ctx)(struct crypto_authenc_ctx *ctx);
	void (*copy_state)(struct crypto_authenc_ctx *dst_ctx,
			   struct crypto_authenc_ctx *src_ctx);
};

TEE_Result crypto_aes_ccm_alloc_ctx(struct crypto_authenc_ctx **ctx);
TEE_Result crypto_aes_gcm_alloc_ctx(struct crypto_authenc_ctx **ctx);

#ifdef CFG_CRYPTO_DRV_HASH
TEE_Result drvcrypt_hash_alloc_ctx(struct crypto_hash_ctx **ctx, uint32_t algo);
#else
static inline TEE_Result
drvcrypt_hash_alloc_ctx(struct crypto_hash_ctx **ctx __unused,
			uint32_t algo __unused)
{
	return TEE_ERROR_NOT_IMPLEMENTED;
}
#endif /* CFG_CRYPTO_DRV_HASH */

#ifdef CFG_CRYPTO_DRV_CIPHER
TEE_Result drvcrypt_cipher_alloc_ctx(struct crypto_cipher_ctx **ctx,
				     uint32_t algo);
#else
static inline TEE_Result
drvcrypt_cipher_alloc_ctx(struct crypto_cipher_ctx **ctx __unused,
			  uint32_t algo __unused)
{
	return TEE_ERROR_NOT_IMPLEMENTED;
}
#endif /* CFG_CRYPTO_DRV_CIPHER */

#ifdef CFG_CRYPTO_DRV_MAC
/* Cryptographic MAC driver context allocation */
TEE_Result drvcrypt_mac_alloc_ctx(struct crypto_mac_ctx **ctx, uint32_t algo);
#else
static inline TEE_Result
drvcrypt_mac_alloc_ctx(struct crypto_mac_ctx **ctx __unused,
		       uint32_t algo __unused)
{
	return TEE_ERROR_NOT_IMPLEMENTED;
}
#endif /* CFG_CRYPTO_DRV_MAC */

#ifdef CFG_CRYPTO_DRV_AUTHENC
/* Cryptographic Authenticated Encryption driver context allocation */
TEE_Result drvcrypt_authenc_alloc_ctx(struct crypto_authenc_ctx **ctx,
				      uint32_t algo);
#else
static inline TEE_Result
drvcrypt_authenc_alloc_ctx(struct crypto_authenc_ctx **ctx __unused,
			   uint32_t algo __unused)
{
	return TEE_ERROR_NOT_IMPLEMENTED;
}
#endif /* CFG_CRYPTO_DRV_AUTHENC */
/*
 * The ECC public key operations used by the crypto_acipher_ecc_*() and
 * crypto_acipher_free_ecc_*() functions.
 * Reference set in ecc_public_key when key allocated.
 *
 * @free    is mandatory
 * @verify  is optional
 * @encrypt is optional
 */
struct crypto_ecc_public_ops {
	void (*free)(struct ecc_public_key *key);
	TEE_Result (*verify)(uint32_t algo, struct ecc_public_key *key,
			     const uint8_t *msg, size_t msg_len,
			     const uint8_t *sig, size_t sig_len);
	TEE_Result (*encrypt)(struct ecc_public_key *key, const uint8_t *src,
			      size_t src_len, uint8_t *dst, size_t *dst_len);
};

/*
 * The ECC keypair operations used by the crypto_acipher_ecc_*() and
 * crypto_acipher_gen_ecc_*() functions.
 * Reference set in ecc_keypair when key allocated.
 *
 * @generate      is mandatory
 * @sign          is optional
 * @shared_secret is optional
 * @decrypt       is optional
 */
struct crypto_ecc_keypair_ops {
	TEE_Result (*generate)(struct ecc_keypair *key, size_t key_size_bits);
	TEE_Result (*sign)(uint32_t algo, struct ecc_keypair *key,
			   const uint8_t *msg, size_t msg_len, uint8_t *sig,
			   size_t *sig_len);
	TEE_Result (*shared_secret)(struct ecc_keypair *private_key,
				    struct ecc_public_key *public_key,
				    void *secret, unsigned long *secret_len);
	TEE_Result (*decrypt)(struct ecc_keypair *key, const uint8_t *src,
			      size_t src_len, uint8_t *dst, size_t *dst_len);
};

#ifdef CFG_CRYPTO_ECC
const struct crypto_ecc_keypair_ops *
crypto_asym_get_ecc_keypair_ops(uint32_t key_type);

const struct crypto_ecc_public_ops *
crypto_asym_get_ecc_public_ops(uint32_t key_type);

TEE_Result crypto_asym_alloc_ecc_public_key(struct ecc_public_key *key,
					    uint32_t key_type,
					    size_t key_size_bits);
TEE_Result crypto_asym_alloc_ecc_keypair(struct ecc_keypair *key,
					 uint32_t key_type,
					 size_t key_size_bits);
#else
static inline TEE_Result
crypto_asym_alloc_ecc_public_key(struct ecc_public_key *key __unused,
				 uint32_t key_type __unused,
				 size_t key_size_bits __unused)
{
	return TEE_ERROR_NOT_IMPLEMENTED;
}

static inline const struct crypto_ecc_keypair_ops *
crypto_asym_get_ecc_keypair_ops(uint32_t key_type __unused)
{
	return NULL;
}

static inline const struct crypto_ecc_public_ops *
crypto_asym_get_ecc_public_ops(uint32_t key_type __unused)
{
	return NULL;
}

static inline TEE_Result
crypto_asym_alloc_ecc_keypair(struct ecc_keypair *key __unused,
			      uint32_t key_type __unused,
			      size_t key_size_bits __unused)
{
	return TEE_ERROR_NOT_IMPLEMENTED;
}
#endif /* CFG_CRYPTO_ECC */

#ifdef CFG_CRYPTO_DRV_ECC
TEE_Result drvcrypt_asym_alloc_ecc_public_key(struct ecc_public_key *key,
					      uint32_t key_type,
					      size_t key_size_bits);
TEE_Result drvcrypt_asym_alloc_ecc_keypair(struct ecc_keypair *key,
					   uint32_t key_type,
					   size_t key_size_bits);
#else
static inline TEE_Result
drvcrypt_asym_alloc_ecc_public_key(struct ecc_public_key *key __unused,
				   uint32_t key_type __unused,
				   size_t key_size_bits __unused)
{
	return TEE_ERROR_NOT_IMPLEMENTED;
}

static inline TEE_Result
drvcrypt_asym_alloc_ecc_keypair(struct ecc_keypair *key __unused,
				uint32_t key_type __unused,
				size_t key_size_bits __unused)
{
	return TEE_ERROR_NOT_IMPLEMENTED;
}
#endif /* CFG_CRYPTO_DRV_ECC */

TEE_Result sw_crypto_acipher_alloc_rsa_keypair(struct rsa_keypair *s,
					       size_t key_size_bits);

TEE_Result sw_crypto_acipher_alloc_rsa_public_key(struct rsa_public_key *s,
						  size_t key_size_bits);

void sw_crypto_acipher_free_rsa_public_key(struct rsa_public_key *s);

void sw_crypto_acipher_free_rsa_keypair(struct rsa_keypair *s);

TEE_Result sw_crypto_acipher_gen_rsa_key(struct rsa_keypair *key,
					 size_t key_size);

TEE_Result sw_crypto_acipher_rsanopad_decrypt(struct rsa_keypair *key,
					      const uint8_t *src,
					      size_t src_len, uint8_t *dst,
					      size_t *dst_len);
TEE_Result sw_crypto_acipher_rsanopad_encrypt(struct rsa_public_key *key,
					      const uint8_t *src,
					      size_t src_len, uint8_t *dst,
					      size_t *dst_len);
TEE_Result sw_crypto_acipher_rsaes_decrypt(uint32_t algo,
					   struct rsa_keypair *key,
					   const uint8_t *label,
					   size_t label_len,
					   uint32_t mgf_algo,
					   const uint8_t *src,
					   size_t src_len, uint8_t *dst,
					   size_t *dst_len);

TEE_Result sw_crypto_acipher_rsaes_encrypt(uint32_t algo,
					   struct rsa_public_key *key,
					   const uint8_t *label,
					   size_t label_len,
					   uint32_t mgf_algo,
					   const uint8_t *src,
					   size_t src_len, uint8_t *dst,
					   size_t *dst_len);

TEE_Result sw_crypto_acipher_rsassa_sign(uint32_t algo, struct rsa_keypair *key,
					 int salt_len, const uint8_t *msg,
					 size_t msg_len, uint8_t *sig,
					 size_t *sig_len);

TEE_Result sw_crypto_acipher_rsassa_verify(uint32_t algo,
					   struct rsa_public_key *key,
					   int salt_len, const uint8_t *msg,
					   size_t msg_len, const uint8_t *sig,
					   size_t sig_len);
#endif /*__CRYPTO_CRYPTO_IMPL_H*/