1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3 * Copyright (c) 2014, STMicroelectronics International N.V.
4 */
5 #ifndef TEE_SVC_CRYP_H
6 #define TEE_SVC_CRYP_H
7 
8 #include <tee_api_types.h>
9 #include <utee_types.h>
10 #include <tee/tee_obj.h>
11 
12 struct user_ta_ctx;
13 
14 TEE_Result syscall_cryp_obj_get_info(unsigned long obj, TEE_ObjectInfo *info);
15 TEE_Result syscall_cryp_obj_restrict_usage(unsigned long obj,
16 			unsigned long usage);
17 TEE_Result syscall_cryp_obj_get_attr(unsigned long obj, unsigned long attr_id,
18 			void *buffer, uint64_t *size);
19 
20 TEE_Result syscall_cryp_obj_alloc(unsigned long obj_type,
21 			unsigned long max_key_size, uint32_t *obj);
22 TEE_Result syscall_cryp_obj_close(unsigned long obj);
23 TEE_Result syscall_cryp_obj_reset(unsigned long obj);
24 TEE_Result syscall_cryp_obj_populate(unsigned long obj,
25 			struct utee_attribute *attrs, unsigned long attr_count);
26 TEE_Result syscall_cryp_obj_copy(unsigned long dst_obj,
27 			unsigned long src_obj);
28 TEE_Result syscall_obj_generate_key(unsigned long obj, unsigned long key_size,
29 			const struct utee_attribute *params,
30 			unsigned long param_count);
31 
32 TEE_Result syscall_cryp_state_alloc(unsigned long algo, unsigned long op_mode,
33 			unsigned long key1, unsigned long key2,
34 			uint32_t *state);
35 TEE_Result syscall_cryp_state_copy(unsigned long dst, unsigned long src);
36 TEE_Result syscall_cryp_state_free(unsigned long state);
37 void tee_svc_cryp_free_states(struct user_ta_ctx *utc);
38 
39 /* iv and iv_len are ignored for hash algorithms */
40 TEE_Result syscall_hash_init(unsigned long state, const void *iv,
41 			size_t iv_len);
42 TEE_Result syscall_hash_update(unsigned long state, const void *chunk,
43 			size_t chunk_size);
44 TEE_Result syscall_hash_final(unsigned long state, const void *chunk,
45 			size_t chunk_size, void *hash, uint64_t *hash_len);
46 
47 TEE_Result syscall_cipher_init(unsigned long state, const void *iv,
48 			size_t iv_len);
49 TEE_Result syscall_cipher_update(unsigned long state, const void *src,
50 			size_t src_len, void *dest, uint64_t *dest_len);
51 TEE_Result syscall_cipher_final(unsigned long state, const void *src,
52 			size_t src_len, void *dest, uint64_t *dest_len);
53 
54 TEE_Result syscall_cryp_derive_key(unsigned long state,
55 			const struct utee_attribute *params,
56 			unsigned long param_count, unsigned long derived_key);
57 
58 TEE_Result syscall_cryp_random_number_generate(void *buf, size_t blen);
59 
60 TEE_Result syscall_authenc_init(unsigned long state, const void *nonce,
61 			size_t nonce_len, size_t tag_len,
62 			size_t aad_len, size_t payload_len);
63 TEE_Result syscall_authenc_update_aad(unsigned long state,
64 			const void *aad_data, size_t aad_data_len);
65 TEE_Result syscall_authenc_update_payload(unsigned long state,
66 			const void *src_data, size_t src_len, void *dest_data,
67 			uint64_t *dest_len);
68 TEE_Result syscall_authenc_enc_final(unsigned long state,
69 			const void *src_data, size_t src_len, void *dest_data,
70 			uint64_t *dest_len, void *tag, uint64_t *tag_len);
71 TEE_Result syscall_authenc_dec_final(unsigned long state,
72 			const void *src_data, size_t src_len, void *dest_data,
73 			uint64_t *dest_len, const void *tag, size_t tag_len);
74 
75 TEE_Result syscall_asymm_operate(unsigned long state,
76 			const struct utee_attribute *usr_params,
77 			size_t num_params, const void *src_data,
78 			size_t src_len, void *dest_data, uint64_t *dest_len);
79 TEE_Result syscall_asymm_verify(unsigned long state,
80 			const struct utee_attribute *usr_params,
81 			size_t num_params, const void *data, size_t data_len,
82 			const void *sig, size_t sig_len);
83 
84 TEE_Result tee_obj_set_type(struct tee_obj *o, uint32_t obj_type,
85 			    size_t max_key_size);
86 
87 void tee_obj_attr_free(struct tee_obj *o);
88 void tee_obj_attr_clear(struct tee_obj *o);
89 TEE_Result tee_obj_attr_to_binary(struct tee_obj *o, void *data,
90 				  size_t *data_len);
91 TEE_Result tee_obj_attr_from_binary(struct tee_obj *o, const void *data,
92 				    size_t data_len);
93 TEE_Result tee_obj_attr_copy_from(struct tee_obj *o, const struct tee_obj *src);
94 
95 #endif /* TEE_SVC_CRYP_H */
96