11bb92983SJerome Forissier /* SPDX-License-Identifier: BSD-2-Clause */ 2e1770e71SJens Wiklander /* 3e1770e71SJens Wiklander * Copyright (c) 2014-2017, Linaro Limited 4e1770e71SJens Wiklander */ 5e1770e71SJens Wiklander 6e1770e71SJens Wiklander /* 7e1770e71SJens Wiklander * This is the Cryptographic Provider API (CP API). 8e1770e71SJens Wiklander * 9e1770e71SJens Wiklander * This defines how most crypto syscalls that implement the Cryptographic 10e1770e71SJens Wiklander * Operations API can invoke the actual providers of cryptographic algorithms 11e1770e71SJens Wiklander * (such as LibTomCrypt). 12e1770e71SJens Wiklander * 13e1770e71SJens Wiklander * To add a new provider, you need to provide an implementation of this 14e1770e71SJens Wiklander * interface. 15e1770e71SJens Wiklander * 16e1770e71SJens Wiklander * The following parameters are commonly used. 17e1770e71SJens Wiklander * 18e1770e71SJens Wiklander * @ctx: context allocated by the syscall, for later use by the algorithm 19e1770e71SJens Wiklander * @algo: algorithm identifier (TEE_ALG_*) 20e1770e71SJens Wiklander */ 21e1770e71SJens Wiklander 22e1770e71SJens Wiklander #ifndef __CRYPTO_CRYPTO_H 23e1770e71SJens Wiklander #define __CRYPTO_CRYPTO_H 24e1770e71SJens Wiklander 25e1770e71SJens Wiklander #include <tee_api_types.h> 26e1770e71SJens Wiklander 27e1770e71SJens Wiklander TEE_Result crypto_init(void); 28e1770e71SJens Wiklander 29e1770e71SJens Wiklander /* Message digest functions */ 30ecf2e014SJens Wiklander TEE_Result crypto_hash_alloc_ctx(void **ctx, uint32_t algo); 316b3a371cSJens Wiklander TEE_Result crypto_hash_init(void *ctx); 326b3a371cSJens Wiklander TEE_Result crypto_hash_update(void *ctx, const uint8_t *data, size_t len); 336b3a371cSJens Wiklander TEE_Result crypto_hash_final(void *ctx, uint8_t *digest, size_t len); 346b3a371cSJens Wiklander void crypto_hash_free_ctx(void *ctx); 356b3a371cSJens Wiklander void crypto_hash_copy_state(void *dst_ctx, void *src_ctx); 36e1770e71SJens Wiklander 37e1770e71SJens Wiklander /* Symmetric ciphers */ 3872a9b1a0SJens Wiklander TEE_Result crypto_cipher_alloc_ctx(void **ctx, uint32_t algo); 39cbda7091SJens Wiklander TEE_Result crypto_cipher_init(void *ctx, TEE_OperationMode mode, 40e1770e71SJens Wiklander const uint8_t *key1, size_t key1_len, 41e1770e71SJens Wiklander const uint8_t *key2, size_t key2_len, 42e1770e71SJens Wiklander const uint8_t *iv, size_t iv_len); 43cbda7091SJens Wiklander TEE_Result crypto_cipher_update(void *ctx, TEE_OperationMode mode, 44cbda7091SJens Wiklander bool last_block, const uint8_t *data, 45cbda7091SJens Wiklander size_t len, uint8_t *dst); 46cbda7091SJens Wiklander void crypto_cipher_final(void *ctx); 47e1770e71SJens Wiklander TEE_Result crypto_cipher_get_block_size(uint32_t algo, size_t *size); 48cbda7091SJens Wiklander void crypto_cipher_free_ctx(void *ctx); 49cbda7091SJens Wiklander void crypto_cipher_copy_state(void *dst_ctx, void *src_ctx); 50e1770e71SJens Wiklander 51e1770e71SJens Wiklander /* Message Authentication Code functions */ 5282ef73bcSJens Wiklander TEE_Result crypto_mac_alloc_ctx(void **ctx, uint32_t algo); 53c69bc615SJens Wiklander TEE_Result crypto_mac_init(void *ctx, const uint8_t *key, size_t len); 54c69bc615SJens Wiklander TEE_Result crypto_mac_update(void *ctx, const uint8_t *data, size_t len); 55c69bc615SJens Wiklander TEE_Result crypto_mac_final(void *ctx, uint8_t *digest, size_t digest_len); 56c69bc615SJens Wiklander void crypto_mac_free_ctx(void *ctx); 57c69bc615SJens Wiklander void crypto_mac_copy_state(void *dst_ctx, void *src_ctx); 58e1770e71SJens Wiklander 59e1770e71SJens Wiklander /* Authenticated encryption */ 60d7ac7d0fSJens Wiklander TEE_Result crypto_authenc_alloc_ctx(void **ctx, uint32_t algo); 6152ee414bSJens Wiklander TEE_Result crypto_authenc_init(void *ctx, TEE_OperationMode mode, 62e1770e71SJens Wiklander const uint8_t *key, size_t key_len, 63e1770e71SJens Wiklander const uint8_t *nonce, size_t nonce_len, 64e1770e71SJens Wiklander size_t tag_len, size_t aad_len, 65e1770e71SJens Wiklander size_t payload_len); 6652ee414bSJens Wiklander TEE_Result crypto_authenc_update_aad(void *ctx, TEE_OperationMode mode, 67e1770e71SJens Wiklander const uint8_t *data, size_t len); 6852ee414bSJens Wiklander TEE_Result crypto_authenc_update_payload(void *ctx, TEE_OperationMode mode, 69e1770e71SJens Wiklander const uint8_t *src_data, 70e1770e71SJens Wiklander size_t src_len, uint8_t *dst_data, 71e1770e71SJens Wiklander size_t *dst_len); 7252ee414bSJens Wiklander TEE_Result crypto_authenc_enc_final(void *ctx, const uint8_t *src_data, 7352ee414bSJens Wiklander size_t src_len, uint8_t *dst_data, 7452ee414bSJens Wiklander size_t *dst_len, uint8_t *dst_tag, 7552ee414bSJens Wiklander size_t *dst_tag_len); 7652ee414bSJens Wiklander TEE_Result crypto_authenc_dec_final(void *ctx, const uint8_t *src_data, 7752ee414bSJens Wiklander size_t src_len, uint8_t *dst_data, 7852ee414bSJens Wiklander size_t *dst_len, const uint8_t *tag, 7952ee414bSJens Wiklander size_t tag_len); 8052ee414bSJens Wiklander void crypto_authenc_final(void *ctx); 8152ee414bSJens Wiklander void crypto_authenc_free_ctx(void *ctx); 8252ee414bSJens Wiklander void crypto_authenc_copy_state(void *dst_ctx, void *src_ctx); 83e1770e71SJens Wiklander 84e1770e71SJens Wiklander /* Implementation-defined big numbers */ 85e1770e71SJens Wiklander 86e1770e71SJens Wiklander /* 87e1770e71SJens Wiklander * Allocate a bignum capable of holding an unsigned integer value of 88e1770e71SJens Wiklander * up to bitsize bits 89e1770e71SJens Wiklander */ 90e1770e71SJens Wiklander struct bignum *crypto_bignum_allocate(size_t size_bits); 91e1770e71SJens Wiklander TEE_Result crypto_bignum_bin2bn(const uint8_t *from, size_t fromsize, 92e1770e71SJens Wiklander struct bignum *to); 93e1770e71SJens Wiklander size_t crypto_bignum_num_bytes(struct bignum *a); 94e1770e71SJens Wiklander size_t crypto_bignum_num_bits(struct bignum *a); 95e1770e71SJens Wiklander void crypto_bignum_bn2bin(const struct bignum *from, uint8_t *to); 96e1770e71SJens Wiklander void crypto_bignum_copy(struct bignum *to, const struct bignum *from); 97e1770e71SJens Wiklander void crypto_bignum_free(struct bignum *a); 98e1770e71SJens Wiklander void crypto_bignum_clear(struct bignum *a); 99e1770e71SJens Wiklander 100e1770e71SJens Wiklander /* return -1 if a<b, 0 if a==b, +1 if a>b */ 101e1770e71SJens Wiklander int32_t crypto_bignum_compare(struct bignum *a, struct bignum *b); 102e1770e71SJens Wiklander 103e1770e71SJens Wiklander /* Asymmetric algorithms */ 104e1770e71SJens Wiklander 105e1770e71SJens Wiklander struct rsa_keypair { 106e1770e71SJens Wiklander struct bignum *e; /* Public exponent */ 107e1770e71SJens Wiklander struct bignum *d; /* Private exponent */ 108e1770e71SJens Wiklander struct bignum *n; /* Modulus */ 109e1770e71SJens Wiklander 110e1770e71SJens Wiklander /* Optional CRT parameters (all NULL if unused) */ 111e1770e71SJens Wiklander struct bignum *p; /* N = pq */ 112e1770e71SJens Wiklander struct bignum *q; 113e1770e71SJens Wiklander struct bignum *qp; /* 1/q mod p */ 114e1770e71SJens Wiklander struct bignum *dp; /* d mod (p-1) */ 115e1770e71SJens Wiklander struct bignum *dq; /* d mod (q-1) */ 116e1770e71SJens Wiklander }; 117e1770e71SJens Wiklander 118e1770e71SJens Wiklander struct rsa_public_key { 119e1770e71SJens Wiklander struct bignum *e; /* Public exponent */ 120e1770e71SJens Wiklander struct bignum *n; /* Modulus */ 121e1770e71SJens Wiklander }; 122e1770e71SJens Wiklander 123e1770e71SJens Wiklander struct dsa_keypair { 124e1770e71SJens Wiklander struct bignum *g; /* Generator of subgroup (public) */ 125e1770e71SJens Wiklander struct bignum *p; /* Prime number (public) */ 126e1770e71SJens Wiklander struct bignum *q; /* Order of subgroup (public) */ 127e1770e71SJens Wiklander struct bignum *y; /* Public key */ 128e1770e71SJens Wiklander struct bignum *x; /* Private key */ 129e1770e71SJens Wiklander }; 130e1770e71SJens Wiklander 131e1770e71SJens Wiklander struct dsa_public_key { 132e1770e71SJens Wiklander struct bignum *g; /* Generator of subgroup (public) */ 133e1770e71SJens Wiklander struct bignum *p; /* Prime number (public) */ 134e1770e71SJens Wiklander struct bignum *q; /* Order of subgroup (public) */ 135e1770e71SJens Wiklander struct bignum *y; /* Public key */ 136e1770e71SJens Wiklander }; 137e1770e71SJens Wiklander 138e1770e71SJens Wiklander struct dh_keypair { 139e1770e71SJens Wiklander struct bignum *g; /* Generator of Z_p (shared) */ 140e1770e71SJens Wiklander struct bignum *p; /* Prime modulus (shared) */ 141e1770e71SJens Wiklander struct bignum *x; /* Private key */ 142e1770e71SJens Wiklander struct bignum *y; /* Public key y = g^x */ 143e1770e71SJens Wiklander 144e1770e71SJens Wiklander /* 145e1770e71SJens Wiklander * Optional parameters used by key generation. 146e1770e71SJens Wiklander * When not used, q == NULL and xbits == 0 147e1770e71SJens Wiklander */ 148e1770e71SJens Wiklander struct bignum *q; /* x must be in the range [2, q-2] */ 149e1770e71SJens Wiklander uint32_t xbits; /* Number of bits in the private key */ 150e1770e71SJens Wiklander }; 151e1770e71SJens Wiklander 152e1770e71SJens Wiklander struct ecc_public_key { 153e1770e71SJens Wiklander struct bignum *x; /* Public value x */ 154e1770e71SJens Wiklander struct bignum *y; /* Public value y */ 155e1770e71SJens Wiklander uint32_t curve; /* Curve type */ 156e1770e71SJens Wiklander }; 157e1770e71SJens Wiklander 158e1770e71SJens Wiklander struct ecc_keypair { 159e1770e71SJens Wiklander struct bignum *d; /* Private value */ 160e1770e71SJens Wiklander struct bignum *x; /* Public value x */ 161e1770e71SJens Wiklander struct bignum *y; /* Public value y */ 162e1770e71SJens Wiklander uint32_t curve; /* Curve type */ 163e1770e71SJens Wiklander }; 164e1770e71SJens Wiklander 165e1770e71SJens Wiklander /* 166e1770e71SJens Wiklander * Key allocation functions 167e1770e71SJens Wiklander * Allocate the bignum's inside a key structure. 168e1770e71SJens Wiklander * TEE core will later use crypto_bignum_free(). 169e1770e71SJens Wiklander */ 170e1770e71SJens Wiklander TEE_Result crypto_acipher_alloc_rsa_keypair(struct rsa_keypair *s, 171e1770e71SJens Wiklander size_t key_size_bits); 172e1770e71SJens Wiklander TEE_Result crypto_acipher_alloc_rsa_public_key(struct rsa_public_key *s, 173e1770e71SJens Wiklander size_t key_size_bits); 174e1770e71SJens Wiklander void crypto_acipher_free_rsa_public_key(struct rsa_public_key *s); 175e1770e71SJens Wiklander TEE_Result crypto_acipher_alloc_dsa_keypair(struct dsa_keypair *s, 176e1770e71SJens Wiklander size_t key_size_bits); 177e1770e71SJens Wiklander TEE_Result crypto_acipher_alloc_dsa_public_key(struct dsa_public_key *s, 178e1770e71SJens Wiklander size_t key_size_bits); 179e1770e71SJens Wiklander TEE_Result crypto_acipher_alloc_dh_keypair(struct dh_keypair *s, 180e1770e71SJens Wiklander size_t key_size_bits); 181e1770e71SJens Wiklander TEE_Result crypto_acipher_alloc_ecc_public_key(struct ecc_public_key *s, 182e1770e71SJens Wiklander size_t key_size_bits); 183e1770e71SJens Wiklander TEE_Result crypto_acipher_alloc_ecc_keypair(struct ecc_keypair *s, 184e1770e71SJens Wiklander size_t key_size_bits); 185e1770e71SJens Wiklander void crypto_acipher_free_ecc_public_key(struct ecc_public_key *s); 186e1770e71SJens Wiklander 187e1770e71SJens Wiklander /* 188e1770e71SJens Wiklander * Key generation functions 189e1770e71SJens Wiklander */ 190e1770e71SJens Wiklander TEE_Result crypto_acipher_gen_rsa_key(struct rsa_keypair *key, size_t key_size); 191e1770e71SJens Wiklander TEE_Result crypto_acipher_gen_dsa_key(struct dsa_keypair *key, size_t key_size); 192e1770e71SJens Wiklander TEE_Result crypto_acipher_gen_dh_key(struct dh_keypair *key, struct bignum *q, 193e1770e71SJens Wiklander size_t xbits); 194e1770e71SJens Wiklander TEE_Result crypto_acipher_gen_ecc_key(struct ecc_keypair *key); 195e1770e71SJens Wiklander 196e1770e71SJens Wiklander TEE_Result crypto_acipher_dh_shared_secret(struct dh_keypair *private_key, 197e1770e71SJens Wiklander struct bignum *public_key, 198e1770e71SJens Wiklander struct bignum *secret); 199e1770e71SJens Wiklander 200e1770e71SJens Wiklander TEE_Result crypto_acipher_rsanopad_decrypt(struct rsa_keypair *key, 201e1770e71SJens Wiklander const uint8_t *src, size_t src_len, 202e1770e71SJens Wiklander uint8_t *dst, size_t *dst_len); 203e1770e71SJens Wiklander TEE_Result crypto_acipher_rsanopad_encrypt(struct rsa_public_key *key, 204e1770e71SJens Wiklander const uint8_t *src, size_t src_len, 205e1770e71SJens Wiklander uint8_t *dst, size_t *dst_len); 206e1770e71SJens Wiklander TEE_Result crypto_acipher_rsaes_decrypt(uint32_t algo, struct rsa_keypair *key, 207e1770e71SJens Wiklander const uint8_t *label, size_t label_len, 208e1770e71SJens Wiklander const uint8_t *src, size_t src_len, 209e1770e71SJens Wiklander uint8_t *dst, size_t *dst_len); 210e1770e71SJens Wiklander TEE_Result crypto_acipher_rsaes_encrypt(uint32_t algo, 211e1770e71SJens Wiklander struct rsa_public_key *key, 212e1770e71SJens Wiklander const uint8_t *label, size_t label_len, 213e1770e71SJens Wiklander const uint8_t *src, size_t src_len, 214e1770e71SJens Wiklander uint8_t *dst, size_t *dst_len); 215e1770e71SJens Wiklander /* RSA SSA sign/verify: if salt_len == -1, use default value */ 216e1770e71SJens Wiklander TEE_Result crypto_acipher_rsassa_sign(uint32_t algo, struct rsa_keypair *key, 217e1770e71SJens Wiklander int salt_len, const uint8_t *msg, 218e1770e71SJens Wiklander size_t msg_len, uint8_t *sig, 219e1770e71SJens Wiklander size_t *sig_len); 220e1770e71SJens Wiklander TEE_Result crypto_acipher_rsassa_verify(uint32_t algo, 221e1770e71SJens Wiklander struct rsa_public_key *key, 222e1770e71SJens Wiklander int salt_len, const uint8_t *msg, 223e1770e71SJens Wiklander size_t msg_len, const uint8_t *sig, 224e1770e71SJens Wiklander size_t sig_len); 225e1770e71SJens Wiklander TEE_Result crypto_acipher_dsa_sign(uint32_t algo, struct dsa_keypair *key, 226e1770e71SJens Wiklander const uint8_t *msg, size_t msg_len, 227e1770e71SJens Wiklander uint8_t *sig, size_t *sig_len); 228e1770e71SJens Wiklander TEE_Result crypto_acipher_dsa_verify(uint32_t algo, struct dsa_public_key *key, 229e1770e71SJens Wiklander const uint8_t *msg, size_t msg_len, 230e1770e71SJens Wiklander const uint8_t *sig, size_t sig_len); 231e1770e71SJens Wiklander TEE_Result crypto_acipher_ecc_sign(uint32_t algo, struct ecc_keypair *key, 232e1770e71SJens Wiklander const uint8_t *msg, size_t msg_len, 233e1770e71SJens Wiklander uint8_t *sig, size_t *sig_len); 234e1770e71SJens Wiklander TEE_Result crypto_acipher_ecc_verify(uint32_t algo, struct ecc_public_key *key, 235e1770e71SJens Wiklander const uint8_t *msg, size_t msg_len, 236e1770e71SJens Wiklander const uint8_t *sig, size_t sig_len); 237e1770e71SJens Wiklander TEE_Result crypto_acipher_ecc_shared_secret(struct ecc_keypair *private_key, 238e1770e71SJens Wiklander struct ecc_public_key *public_key, 239e1770e71SJens Wiklander void *secret, 240e1770e71SJens Wiklander unsigned long *secret_len); 24191fc6bd8SJerome Forissier TEE_Result crypto_acipher_sm2_pke_decrypt(struct ecc_keypair *key, 24291fc6bd8SJerome Forissier const uint8_t *src, size_t src_len, 24391fc6bd8SJerome Forissier uint8_t *dst, size_t *dst_len); 24491fc6bd8SJerome Forissier TEE_Result crypto_acipher_sm2_pke_encrypt(struct ecc_public_key *key, 24591fc6bd8SJerome Forissier const uint8_t *src, size_t src_len, 24691fc6bd8SJerome Forissier uint8_t *dst, size_t *dst_len); 2470f151943SJerome Forissier TEE_Result crypto_acipher_sm2_dsa_sign(uint32_t algo, struct ecc_keypair *key, 2480f151943SJerome Forissier const uint8_t *msg, size_t msg_len, 2490f151943SJerome Forissier uint8_t *sig, size_t *sig_len); 2500f151943SJerome Forissier TEE_Result crypto_acipher_sm2_dsa_verify(uint32_t algo, 2510f151943SJerome Forissier struct ecc_public_key *key, 2520f151943SJerome Forissier const uint8_t *msg, size_t msg_len, 2530f151943SJerome Forissier const uint8_t *sig, size_t sig_len); 254e1770e71SJens Wiklander 255*5b385b3fSJerome Forissier struct sm2_kep_parms { 256*5b385b3fSJerome Forissier uint8_t *out; 257*5b385b3fSJerome Forissier size_t out_len; 258*5b385b3fSJerome Forissier bool is_initiator; 259*5b385b3fSJerome Forissier const uint8_t *initiator_id; 260*5b385b3fSJerome Forissier size_t initiator_id_len; 261*5b385b3fSJerome Forissier const uint8_t *responder_id; 262*5b385b3fSJerome Forissier size_t responder_id_len; 263*5b385b3fSJerome Forissier const uint8_t *conf_in; 264*5b385b3fSJerome Forissier size_t conf_in_len; 265*5b385b3fSJerome Forissier uint8_t *conf_out; 266*5b385b3fSJerome Forissier size_t conf_out_len; 267*5b385b3fSJerome Forissier }; 268*5b385b3fSJerome Forissier 269*5b385b3fSJerome Forissier TEE_Result crypto_acipher_sm2_kep_derive(struct ecc_keypair *my_key, 270*5b385b3fSJerome Forissier struct ecc_keypair *my_eph_key, 271*5b385b3fSJerome Forissier struct ecc_public_key *peer_key, 272*5b385b3fSJerome Forissier struct ecc_public_key *peer_eph_key, 273*5b385b3fSJerome Forissier struct sm2_kep_parms *p); 274*5b385b3fSJerome Forissier 275e1770e71SJens Wiklander /* 276e1770e71SJens Wiklander * Verifies a SHA-256 hash, doesn't require crypto_init() to be called in 277e1770e71SJens Wiklander * advance and has as few dependencies as possible. 278e1770e71SJens Wiklander * 279e1770e71SJens Wiklander * This function is primarily used by pager and early initialization code 280e1770e71SJens Wiklander * where the complete crypto library isn't available. 281e1770e71SJens Wiklander */ 282e1770e71SJens Wiklander TEE_Result hash_sha256_check(const uint8_t *hash, const uint8_t *data, 283e1770e71SJens Wiklander size_t data_size); 284e1770e71SJens Wiklander 285b8bb0afaSSumit Garg /* 286b8bb0afaSSumit Garg * Computes a SHA-512/256 hash, vetted conditioner as per NIST.SP.800-90B. 287b8bb0afaSSumit Garg * It doesn't require crypto_init() to be called in advance and has as few 288b8bb0afaSSumit Garg * dependencies as possible. 289b8bb0afaSSumit Garg * 290b8bb0afaSSumit Garg * This function could be used inside interrupt context where the crypto 291b8bb0afaSSumit Garg * library can't be used due to mutex handling. 292b8bb0afaSSumit Garg */ 293b8bb0afaSSumit Garg TEE_Result hash_sha512_256_compute(uint8_t *digest, const uint8_t *data, 294b8bb0afaSSumit Garg size_t data_size); 295b8bb0afaSSumit Garg 2966e954a6eSJens Wiklander #define CRYPTO_RNG_SRC_IS_QUICK(sid) (!!((sid) & 1)) 297e1770e71SJens Wiklander 2986e954a6eSJens Wiklander /* 2996e954a6eSJens Wiklander * enum crypto_rng_src - RNG entropy source 3006e954a6eSJens Wiklander * 3016e954a6eSJens Wiklander * Identifiers for different RNG entropy sources. The lowest bit indicates 3026e954a6eSJens Wiklander * if the source is to be merely queued (bit is 1) or if it's delivered 3036e954a6eSJens Wiklander * directly to the pool. The difference is that in the latter case RPC to 3046e954a6eSJens Wiklander * normal world can be performed and in the former it must not. 3056e954a6eSJens Wiklander */ 3066e954a6eSJens Wiklander enum crypto_rng_src { 3076e954a6eSJens Wiklander CRYPTO_RNG_SRC_JITTER_SESSION = (0 << 1 | 0), 3086e954a6eSJens Wiklander CRYPTO_RNG_SRC_JITTER_RPC = (1 << 1 | 1), 3096e954a6eSJens Wiklander CRYPTO_RNG_SRC_NONSECURE = (1 << 1 | 0), 3106e954a6eSJens Wiklander }; 311e1770e71SJens Wiklander 3126e954a6eSJens Wiklander /* 3136e954a6eSJens Wiklander * crypto_rng_init() - initialize the RNG 3146e954a6eSJens Wiklander * @data: buffer with initial seed 3156e954a6eSJens Wiklander * @dlen: length of @data 3166e954a6eSJens Wiklander */ 3176e954a6eSJens Wiklander TEE_Result crypto_rng_init(const void *data, size_t dlen); 3186e954a6eSJens Wiklander 3196e954a6eSJens Wiklander /* 3206e954a6eSJens Wiklander * crypto_rng_add_event() - supply entropy to RNG from a source 3216e954a6eSJens Wiklander * @sid: Source identifier, should be unique for a specific source 3226e954a6eSJens Wiklander * @pnum: Pool number, acquired using crypto_rng_get_next_pool_num() 3236e954a6eSJens Wiklander * @data: Data associated with the event 3246e954a6eSJens Wiklander * @dlen: Length of @data 3256e954a6eSJens Wiklander * 3266e954a6eSJens Wiklander * @sid controls whether the event is merly queued in a ring buffer or if 3276e954a6eSJens Wiklander * it's added to one of the pools directly. If CRYPTO_RNG_SRC_IS_QUICK() is 3286e954a6eSJens Wiklander * true (lowest bit set) events are queue otherwise added to corresponding 3296e954a6eSJens Wiklander * pool. If CRYPTO_RNG_SRC_IS_QUICK() is false, eventual queued events are 3306e954a6eSJens Wiklander * added to their queues too. 3316e954a6eSJens Wiklander */ 3326e954a6eSJens Wiklander void crypto_rng_add_event(enum crypto_rng_src sid, unsigned int *pnum, 3336e954a6eSJens Wiklander const void *data, size_t dlen); 3346e954a6eSJens Wiklander 3356e954a6eSJens Wiklander /* 3366e954a6eSJens Wiklander * crypto_rng_read() - read cryptograhically secure RNG 3376e954a6eSJens Wiklander * @buf: Buffer to hold the data 3386e954a6eSJens Wiklander * @len: Length of buffer. 3396e954a6eSJens Wiklander * 3406e954a6eSJens Wiklander * Eventual queued events are also added to their pools during this 3416e954a6eSJens Wiklander * function call. 3426e954a6eSJens Wiklander */ 3436e954a6eSJens Wiklander TEE_Result crypto_rng_read(void *buf, size_t len); 344e1770e71SJens Wiklander 345e7dbc357SSummer Qin /* 346e7dbc357SSummer Qin * crypto_aes_expand_enc_key() - Expand an AES key 347e7dbc357SSummer Qin * @key: AES key buffer 348e7dbc357SSummer Qin * @key_len: Size of the the @key buffer in bytes 349e7dbc357SSummer Qin * @enc_key: Expanded AES encryption key buffer 350e7dbc357SSummer Qin * @enc_keylen: Size of the @enc_key buffer in bytes 351e7dbc357SSummer Qin * @rounds: Number of rounds to be used during encryption 352e7dbc357SSummer Qin */ 3530d360202SJens Wiklander TEE_Result crypto_aes_expand_enc_key(const void *key, size_t key_len, 354e7dbc357SSummer Qin void *enc_key, size_t enc_keylen, 355e7dbc357SSummer Qin unsigned int *rounds); 356e7dbc357SSummer Qin 357e7dbc357SSummer Qin /* 358e7dbc357SSummer Qin * crypto_aes_enc_block() - Encrypt an AES block 359e7dbc357SSummer Qin * @enc_key: Expanded AES encryption key 360e7dbc357SSummer Qin * @enc_keylen: Size of @enc_key in bytes 361e7dbc357SSummer Qin * @rounds: Number of rounds 362e7dbc357SSummer Qin * @src: Source buffer of one AES block (16 bytes) 363e7dbc357SSummer Qin * @dst: Destination buffer of one AES block (16 bytes) 364e7dbc357SSummer Qin */ 365e7dbc357SSummer Qin void crypto_aes_enc_block(const void *enc_key, size_t enc_keylen, 366e7dbc357SSummer Qin unsigned int rounds, const void *src, void *dst); 3670d360202SJens Wiklander 368e1770e71SJens Wiklander #endif /* __CRYPTO_CRYPTO_H */ 369