1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2019, Linaro Limited 4 * Copyright (c) 2021, SumUp Services GmbH 5 */ 6 7 #ifndef __CRYPTO_CRYPTO_IMPL_H 8 #define __CRYPTO_CRYPTO_IMPL_H 9 10 #include <crypto/crypto.h> 11 #include <tee_api_types.h> 12 13 /* 14 * The crypto context used by the crypto_hash_*() functions is defined by 15 * struct crypto_hash_ctx. 16 */ 17 struct crypto_hash_ctx { 18 const struct crypto_hash_ops *ops; 19 }; 20 21 struct crypto_hash_ops { 22 TEE_Result (*init)(struct crypto_hash_ctx *ctx); 23 TEE_Result (*update)(struct crypto_hash_ctx *ctx, const uint8_t *data, 24 size_t len); 25 TEE_Result (*final)(struct crypto_hash_ctx *ctx, uint8_t *digest, 26 size_t len); 27 void (*free_ctx)(struct crypto_hash_ctx *ctx); 28 void (*copy_state)(struct crypto_hash_ctx *dst_ctx, 29 struct crypto_hash_ctx *src_ctx); 30 }; 31 32 #define CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(name, type) \ 33 static inline TEE_Result \ 34 crypto_##name##_alloc_ctx(struct crypto_##type##_ctx **ctx __unused) \ 35 { return TEE_ERROR_NOT_IMPLEMENTED; } 36 37 #if defined(CFG_CRYPTO_MD5) 38 TEE_Result crypto_md5_alloc_ctx(struct crypto_hash_ctx **ctx); 39 #else 40 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(md5, hash) 41 #endif 42 43 #if defined(CFG_CRYPTO_SHA1) 44 TEE_Result crypto_sha1_alloc_ctx(struct crypto_hash_ctx **ctx); 45 #else 46 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha1, hash) 47 #endif 48 49 #if defined(CFG_CRYPTO_SHA224) 50 TEE_Result crypto_sha224_alloc_ctx(struct crypto_hash_ctx **ctx); 51 #else 52 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha224, hash) 53 #endif 54 55 #if defined(CFG_CRYPTO_SHA256) 56 TEE_Result crypto_sha256_alloc_ctx(struct crypto_hash_ctx **ctx); 57 #else 58 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha256, hash) 59 #endif 60 61 #if defined(CFG_CRYPTO_SHA384) 62 TEE_Result crypto_sha384_alloc_ctx(struct crypto_hash_ctx **ctx); 63 #else 64 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha384, hash) 65 #endif 66 67 #if defined(CFG_CRYPTO_SHA512) 68 TEE_Result crypto_sha512_alloc_ctx(struct crypto_hash_ctx **ctx); 69 #else 70 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha512, hash) 71 #endif 72 73 #if defined(CFG_CRYPTO_SM3) 74 TEE_Result crypto_sm3_alloc_ctx(struct crypto_hash_ctx **ctx); 75 #else 76 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sm3, hash) 77 #endif 78 79 #if defined(CFG_CRYPTO_SHA3_224) 80 TEE_Result crypto_sha3_224_alloc_ctx(struct crypto_hash_ctx **ctx); 81 #else 82 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha3_224, hash) 83 #endif 84 85 #if defined(CFG_CRYPTO_SHA3_256) 86 TEE_Result crypto_sha3_256_alloc_ctx(struct crypto_hash_ctx **ctx); 87 #else 88 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha3_256, hash) 89 #endif 90 91 #if defined(CFG_CRYPTO_SHA3_384) 92 TEE_Result crypto_sha3_384_alloc_ctx(struct crypto_hash_ctx **ctx); 93 #else 94 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha3_384, hash) 95 #endif 96 97 #if defined(CFG_CRYPTO_SHA3_512) 98 TEE_Result crypto_sha3_512_alloc_ctx(struct crypto_hash_ctx **ctx); 99 #else 100 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha3_512, hash) 101 #endif 102 103 #if defined(CFG_CRYPTO_SHAKE128) 104 TEE_Result crypto_shake128_alloc_ctx(struct crypto_hash_ctx **ctx); 105 #else 106 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(shake128, hash) 107 #endif 108 109 #if defined(CFG_CRYPTO_SHAKE256) 110 TEE_Result crypto_shake256_alloc_ctx(struct crypto_hash_ctx **ctx); 111 #else 112 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(shake256, hash) 113 #endif 114 115 /* 116 * The crypto context used by the crypto_mac_*() functions is defined by 117 * struct crypto_mac_ctx. 118 */ 119 struct crypto_mac_ctx { 120 const struct crypto_mac_ops *ops; 121 }; 122 123 struct crypto_mac_ops { 124 TEE_Result (*init)(struct crypto_mac_ctx *ctx, const uint8_t *key, 125 size_t len); 126 TEE_Result (*update)(struct crypto_mac_ctx *ctx, const uint8_t *data, 127 size_t len); 128 TEE_Result (*final)(struct crypto_mac_ctx *ctx, uint8_t *digest, 129 size_t len); 130 void (*free_ctx)(struct crypto_mac_ctx *ctx); 131 void (*copy_state)(struct crypto_mac_ctx *dst_ctx, 132 struct crypto_mac_ctx *src_ctx); 133 }; 134 135 #if defined(CFG_CRYPTO_HMAC) 136 TEE_Result crypto_hmac_md5_alloc_ctx(struct crypto_mac_ctx **ctx); 137 TEE_Result crypto_hmac_sha1_alloc_ctx(struct crypto_mac_ctx **ctx); 138 TEE_Result crypto_hmac_sha224_alloc_ctx(struct crypto_mac_ctx **ctx); 139 TEE_Result crypto_hmac_sha256_alloc_ctx(struct crypto_mac_ctx **ctx); 140 TEE_Result crypto_hmac_sha384_alloc_ctx(struct crypto_mac_ctx **ctx); 141 TEE_Result crypto_hmac_sha512_alloc_ctx(struct crypto_mac_ctx **ctx); 142 TEE_Result crypto_hmac_sha3_224_alloc_ctx(struct crypto_mac_ctx **ctx); 143 TEE_Result crypto_hmac_sha3_256_alloc_ctx(struct crypto_mac_ctx **ctx); 144 TEE_Result crypto_hmac_sha3_384_alloc_ctx(struct crypto_mac_ctx **ctx); 145 TEE_Result crypto_hmac_sha3_512_alloc_ctx(struct crypto_mac_ctx **ctx); 146 #else 147 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_md5, mac) 148 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha1, mac) 149 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha224, mac) 150 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha256, mac) 151 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha384, mac) 152 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha512, mac) 153 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha3_224, mac) 154 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha3_256, mac) 155 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha3_384, mac) 156 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha3_512, mac) 157 #endif 158 159 #if defined(CFG_CRYPTO_SM3) && defined(CFG_CRYPTO_HMAC) 160 TEE_Result crypto_hmac_sm3_alloc_ctx(struct crypto_mac_ctx **ctx); 161 #else 162 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sm3, mac) 163 #endif 164 165 #if defined(CFG_CRYPTO_CBC_MAC) 166 TEE_Result crypto_aes_cbc_mac_nopad_alloc_ctx(struct crypto_mac_ctx **ctx); 167 TEE_Result crypto_aes_cbc_mac_pkcs5_alloc_ctx(struct crypto_mac_ctx **ctx); 168 TEE_Result crypto_des_cbc_mac_nopad_alloc_ctx(struct crypto_mac_ctx **ctx); 169 TEE_Result crypto_des_cbc_mac_pkcs5_alloc_ctx(struct crypto_mac_ctx **ctx); 170 TEE_Result crypto_des3_cbc_mac_nopad_alloc_ctx(struct crypto_mac_ctx **ctx); 171 TEE_Result crypto_des3_cbc_mac_pkcs5_alloc_ctx(struct crypto_mac_ctx **ctx); 172 #else 173 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_cbc_mac_nopad, mac) 174 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_cbc_mac_pkcs5, mac) 175 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des_cbc_mac_nopad, mac) 176 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des_cbc_mac_pkcs5, mac) 177 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des3_cbc_mac_nopad, mac) 178 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des3_cbc_mac_pkcs5, mac) 179 #endif 180 181 #if defined(CFG_CRYPTO_CMAC) 182 TEE_Result crypto_aes_cmac_alloc_ctx(struct crypto_mac_ctx **ctx); 183 TEE_Result crypto_des3_cmac_alloc_ctx(struct crypto_mac_ctx **ctx); 184 #else 185 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_cmac, mac) 186 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des3_cmac, mac) 187 #endif 188 189 /* 190 * The crypto context used by the crypto_cipher_*() functions is defined by 191 * struct crypto_cipher_ctx. 192 */ 193 struct crypto_cipher_ctx { 194 const struct crypto_cipher_ops *ops; 195 }; 196 197 struct crypto_cipher_ops { 198 TEE_Result (*init)(struct crypto_cipher_ctx *ctx, 199 TEE_OperationMode mode, 200 const uint8_t *key1, size_t key1_len, 201 const uint8_t *key2, size_t key2_len, 202 const uint8_t *iv, size_t iv_len); 203 TEE_Result (*update)(struct crypto_cipher_ctx *ctx, bool last_block, 204 const uint8_t *data, size_t len, uint8_t *dst); 205 void (*final)(struct crypto_cipher_ctx *ctx); 206 207 void (*free_ctx)(struct crypto_cipher_ctx *ctx); 208 void (*copy_state)(struct crypto_cipher_ctx *dst_ctx, 209 struct crypto_cipher_ctx *src_ctx); 210 }; 211 212 #if defined(CFG_CRYPTO_AES) && defined(CFG_CRYPTO_ECB) 213 TEE_Result crypto_aes_ecb_alloc_ctx(struct crypto_cipher_ctx **ctx); 214 #else 215 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_ecb, cipher) 216 #endif 217 218 #if defined(CFG_CRYPTO_AES) && defined(CFG_CRYPTO_CBC) 219 TEE_Result crypto_aes_cbc_alloc_ctx(struct crypto_cipher_ctx **ctx); 220 #else 221 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_cbc, cipher) 222 #endif 223 224 #if defined(CFG_CRYPTO_AES) && defined(CFG_CRYPTO_CTR) 225 TEE_Result crypto_aes_ctr_alloc_ctx(struct crypto_cipher_ctx **ctx); 226 #else 227 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_ctr, cipher) 228 #endif 229 230 #if defined(CFG_CRYPTO_AES) && defined(CFG_CRYPTO_CTS) 231 TEE_Result crypto_aes_cts_alloc_ctx(struct crypto_cipher_ctx **ctx); 232 #else 233 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_cts, cipher) 234 #endif 235 236 #if defined(CFG_CRYPTO_AES) && defined(CFG_CRYPTO_XTS) 237 TEE_Result crypto_aes_xts_alloc_ctx(struct crypto_cipher_ctx **ctx); 238 #else 239 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_xts, cipher) 240 #endif 241 242 #if defined(CFG_CRYPTO_DES) && defined(CFG_CRYPTO_ECB) 243 TEE_Result crypto_des_ecb_alloc_ctx(struct crypto_cipher_ctx **ctx); 244 TEE_Result crypto_des3_ecb_alloc_ctx(struct crypto_cipher_ctx **ctx); 245 #else 246 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des_ecb, cipher) 247 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des3_ecb, cipher) 248 #endif 249 250 #if defined(CFG_CRYPTO_DES) && defined(CFG_CRYPTO_CBC) 251 TEE_Result crypto_des_cbc_alloc_ctx(struct crypto_cipher_ctx **ctx); 252 TEE_Result crypto_des3_cbc_alloc_ctx(struct crypto_cipher_ctx **ctx); 253 #else 254 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des_cbc, cipher) 255 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des3_cbc, cipher) 256 #endif 257 258 #if defined(CFG_CRYPTO_SM4) && defined(CFG_CRYPTO_ECB) 259 TEE_Result crypto_sm4_ecb_alloc_ctx(struct crypto_cipher_ctx **ctx); 260 #else 261 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sm4_ecb, cipher) 262 #endif 263 264 #if defined(CFG_CRYPTO_SM4) && defined(CFG_CRYPTO_CBC) 265 TEE_Result crypto_sm4_cbc_alloc_ctx(struct crypto_cipher_ctx **ctx); 266 #else 267 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sm4_cbc, cipher) 268 #endif 269 270 #if defined(CFG_CRYPTO_SM4) && defined(CFG_CRYPTO_CTR) 271 TEE_Result crypto_sm4_ctr_alloc_ctx(struct crypto_cipher_ctx **ctx); 272 #else 273 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sm4_ctr, cipher) 274 #endif 275 276 #if defined(CFG_CRYPTO_SM4) && defined(CFG_CRYPTO_XTS) 277 TEE_Result crypto_sm4_xts_alloc_ctx(struct crypto_cipher_ctx **ctx); 278 #else 279 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sm4_xts, cipher) 280 #endif 281 282 /* 283 * The crypto context used by the crypto_authen_*() functions below is 284 * defined by struct crypto_authenc_ctx. 285 */ 286 struct crypto_authenc_ctx { 287 const struct crypto_authenc_ops *ops; 288 }; 289 290 struct crypto_authenc_ops { 291 TEE_Result (*init)(struct crypto_authenc_ctx *ctx, 292 TEE_OperationMode mode, 293 const uint8_t *key, size_t key_len, 294 const uint8_t *nonce, size_t nonce_len, 295 size_t tag_len, size_t aad_len, 296 size_t payload_len); 297 TEE_Result (*update_aad)(struct crypto_authenc_ctx *ctx, 298 const uint8_t *data, size_t len); 299 TEE_Result (*update_payload)(struct crypto_authenc_ctx *ctx, 300 TEE_OperationMode mode, 301 const uint8_t *src_data, size_t len, 302 uint8_t *dst_data); 303 TEE_Result (*enc_final)(struct crypto_authenc_ctx *ctx, 304 const uint8_t *src_data, size_t len, 305 uint8_t *dst_data, uint8_t *dst_tag, 306 size_t *dst_tag_len); 307 TEE_Result (*dec_final)(struct crypto_authenc_ctx *ctx, 308 const uint8_t *src_data, size_t len, 309 uint8_t *dst_data, const uint8_t *tag, 310 size_t tag_len); 311 void (*final)(struct crypto_authenc_ctx *ctx); 312 void (*free_ctx)(struct crypto_authenc_ctx *ctx); 313 void (*copy_state)(struct crypto_authenc_ctx *dst_ctx, 314 struct crypto_authenc_ctx *src_ctx); 315 }; 316 317 TEE_Result crypto_aes_ccm_alloc_ctx(struct crypto_authenc_ctx **ctx); 318 TEE_Result crypto_aes_gcm_alloc_ctx(struct crypto_authenc_ctx **ctx); 319 320 #ifdef CFG_CRYPTO_DRV_HASH 321 TEE_Result drvcrypt_hash_alloc_ctx(struct crypto_hash_ctx **ctx, uint32_t algo); 322 #else 323 static inline TEE_Result 324 drvcrypt_hash_alloc_ctx(struct crypto_hash_ctx **ctx __unused, 325 uint32_t algo __unused) 326 { 327 return TEE_ERROR_NOT_IMPLEMENTED; 328 } 329 #endif /* CFG_CRYPTO_DRV_HASH */ 330 331 #ifdef CFG_CRYPTO_DRV_CIPHER 332 TEE_Result drvcrypt_cipher_alloc_ctx(struct crypto_cipher_ctx **ctx, 333 uint32_t algo); 334 #else 335 static inline TEE_Result 336 drvcrypt_cipher_alloc_ctx(struct crypto_cipher_ctx **ctx __unused, 337 uint32_t algo __unused) 338 { 339 return TEE_ERROR_NOT_IMPLEMENTED; 340 } 341 #endif /* CFG_CRYPTO_DRV_CIPHER */ 342 343 #ifdef CFG_CRYPTO_DRV_MAC 344 /* Cryptographic MAC driver context allocation */ 345 TEE_Result drvcrypt_mac_alloc_ctx(struct crypto_mac_ctx **ctx, uint32_t algo); 346 #else 347 static inline TEE_Result 348 drvcrypt_mac_alloc_ctx(struct crypto_mac_ctx **ctx __unused, 349 uint32_t algo __unused) 350 { 351 return TEE_ERROR_NOT_IMPLEMENTED; 352 } 353 #endif /* CFG_CRYPTO_DRV_MAC */ 354 355 #ifdef CFG_CRYPTO_DRV_AUTHENC 356 /* Cryptographic Authenticated Encryption driver context allocation */ 357 TEE_Result drvcrypt_authenc_alloc_ctx(struct crypto_authenc_ctx **ctx, 358 uint32_t algo); 359 #else 360 static inline TEE_Result 361 drvcrypt_authenc_alloc_ctx(struct crypto_authenc_ctx **ctx __unused, 362 uint32_t algo __unused) 363 { 364 return TEE_ERROR_NOT_IMPLEMENTED; 365 } 366 #endif /* CFG_CRYPTO_DRV_AUTHENC */ 367 /* 368 * The ECC public key operations used by the crypto_acipher_ecc_*() and 369 * crypto_acipher_free_ecc_*() functions. 370 * Reference set in ecc_public_key when key allocated. 371 * 372 * @free is mandatory 373 * @verify is optional 374 * @encrypt is optional 375 */ 376 struct crypto_ecc_public_ops { 377 void (*free)(struct ecc_public_key *key); 378 TEE_Result (*verify)(uint32_t algo, struct ecc_public_key *key, 379 const uint8_t *msg, size_t msg_len, 380 const uint8_t *sig, size_t sig_len); 381 TEE_Result (*encrypt)(struct ecc_public_key *key, const uint8_t *src, 382 size_t src_len, uint8_t *dst, size_t *dst_len); 383 }; 384 385 /* 386 * The ECC keypair operations used by the crypto_acipher_ecc_*() and 387 * crypto_acipher_gen_ecc_*() functions. 388 * Reference set in ecc_keypair when key allocated. 389 * 390 * @generate is mandatory 391 * @sign is optional 392 * @shared_secret is optional 393 * @decrypt is optional 394 */ 395 struct crypto_ecc_keypair_ops { 396 TEE_Result (*generate)(struct ecc_keypair *key, size_t key_size_bits); 397 TEE_Result (*sign)(uint32_t algo, struct ecc_keypair *key, 398 const uint8_t *msg, size_t msg_len, uint8_t *sig, 399 size_t *sig_len); 400 TEE_Result (*shared_secret)(struct ecc_keypair *private_key, 401 struct ecc_public_key *public_key, 402 void *secret, unsigned long *secret_len); 403 TEE_Result (*decrypt)(struct ecc_keypair *key, const uint8_t *src, 404 size_t src_len, uint8_t *dst, size_t *dst_len); 405 }; 406 407 #ifdef CFG_CRYPTO_ECC 408 const struct crypto_ecc_keypair_ops * 409 crypto_asym_get_ecc_keypair_ops(uint32_t key_type); 410 411 const struct crypto_ecc_public_ops * 412 crypto_asym_get_ecc_public_ops(uint32_t key_type); 413 414 TEE_Result crypto_asym_alloc_ecc_public_key(struct ecc_public_key *key, 415 uint32_t key_type, 416 size_t key_size_bits); 417 TEE_Result crypto_asym_alloc_ecc_keypair(struct ecc_keypair *key, 418 uint32_t key_type, 419 size_t key_size_bits); 420 #else 421 static inline TEE_Result 422 crypto_asym_alloc_ecc_public_key(struct ecc_public_key *key __unused, 423 uint32_t key_type __unused, 424 size_t key_size_bits __unused) 425 { 426 return TEE_ERROR_NOT_IMPLEMENTED; 427 } 428 429 static inline const struct crypto_ecc_keypair_ops * 430 crypto_asym_get_keypair_ops(uint32_t key_type __unused) 431 { 432 return NULL; 433 } 434 435 static inline const struct crypto_ecc_public_ops * 436 crypto_asym_get_ecc_public_ops(uint32_t key_type __unused) 437 { 438 return NULL; 439 } 440 441 static inline TEE_Result 442 crypto_asym_alloc_ecc_keypair(struct ecc_keypair *key __unused, 443 uint32_t key_type __unused, 444 size_t key_size_bits __unused) 445 { 446 return TEE_ERROR_NOT_IMPLEMENTED; 447 } 448 #endif /* CFG_CRYPTO_ECC */ 449 450 #ifdef CFG_CRYPTO_DRV_ECC 451 TEE_Result drvcrypt_asym_alloc_ecc_public_key(struct ecc_public_key *key, 452 uint32_t key_type, 453 size_t key_size_bits); 454 TEE_Result drvcrypt_asym_alloc_ecc_keypair(struct ecc_keypair *key, 455 uint32_t key_type, 456 size_t key_size_bits); 457 #else 458 static inline TEE_Result 459 drvcrypt_asym_alloc_ecc_public_key(struct ecc_public_key *key __unused, 460 uint32_t key_type __unused, 461 size_t key_size_bits __unused) 462 { 463 return TEE_ERROR_NOT_IMPLEMENTED; 464 } 465 466 static inline TEE_Result 467 drvcrypt_asym_alloc_ecc_keypair(struct ecc_keypair *key __unused, 468 uint32_t key_type __unused, 469 size_t key_size_bits __unused) 470 { 471 return TEE_ERROR_NOT_IMPLEMENTED; 472 } 473 #endif /* CFG_CRYPTO_DRV_ECC */ 474 475 TEE_Result sw_crypto_acipher_alloc_rsa_keypair(struct rsa_keypair *s, 476 size_t key_size_bits); 477 478 TEE_Result sw_crypto_acipher_alloc_rsa_public_key(struct rsa_public_key *s, 479 size_t key_size_bits); 480 481 void sw_crypto_acipher_free_rsa_public_key(struct rsa_public_key *s); 482 483 void sw_crypto_acipher_free_rsa_keypair(struct rsa_keypair *s); 484 485 TEE_Result sw_crypto_acipher_gen_rsa_key(struct rsa_keypair *key, 486 size_t key_size); 487 488 TEE_Result sw_crypto_acipher_rsanopad_decrypt(struct rsa_keypair *key, 489 const uint8_t *src, 490 size_t src_len, uint8_t *dst, 491 size_t *dst_len); 492 TEE_Result sw_crypto_acipher_rsanopad_encrypt(struct rsa_public_key *key, 493 const uint8_t *src, 494 size_t src_len, uint8_t *dst, 495 size_t *dst_len); 496 TEE_Result sw_crypto_acipher_rsaes_decrypt(uint32_t algo, 497 struct rsa_keypair *key, 498 const uint8_t *label, 499 size_t label_len, const uint8_t *src, 500 size_t src_len, uint8_t *dst, 501 size_t *dst_len); 502 503 TEE_Result sw_crypto_acipher_rsaes_encrypt(uint32_t algo, 504 struct rsa_public_key *key, 505 const uint8_t *label, 506 size_t label_len, const uint8_t *src, 507 size_t src_len, uint8_t *dst, 508 size_t *dst_len); 509 510 TEE_Result sw_crypto_acipher_rsassa_sign(uint32_t algo, struct rsa_keypair *key, 511 int salt_len, const uint8_t *msg, 512 size_t msg_len, uint8_t *sig, 513 size_t *sig_len); 514 515 TEE_Result sw_crypto_acipher_rsassa_verify(uint32_t algo, 516 struct rsa_public_key *key, 517 int salt_len, const uint8_t *msg, 518 size_t msg_len, const uint8_t *sig, 519 size_t sig_len); 520 #endif /*__CRYPTO_CRYPTO_IMPL_H*/ 521