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