xref: /optee_os/core/include/tee/tee_svc_cryp.h (revision 983d02116743476904b68d52ca432d0f79c38c43)
1 /*
2 * Copyright (c) 2014, STMicroelectronics International N.V.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27 #ifndef TEE_SVC_CRYP_H
28 #define TEE_SVC_CRYP_H
29 
30 #include <tee_api_types.h>
31 #include <utee_types.h>
32 #include <tee/tee_obj.h>
33 
34 struct user_ta_ctx;
35 
36 TEE_Result syscall_cryp_obj_get_info(unsigned long obj, TEE_ObjectInfo *info);
37 TEE_Result syscall_cryp_obj_restrict_usage(unsigned long obj,
38 			unsigned long usage);
39 TEE_Result syscall_cryp_obj_get_attr(unsigned long obj, unsigned long attr_id,
40 			void *buffer, uint64_t *size);
41 
42 TEE_Result syscall_cryp_obj_alloc(unsigned long obj_type,
43 			unsigned long max_key_size, uint32_t *obj);
44 TEE_Result syscall_cryp_obj_close(unsigned long obj);
45 TEE_Result syscall_cryp_obj_reset(unsigned long obj);
46 TEE_Result syscall_cryp_obj_populate(unsigned long obj,
47 			struct utee_attribute *attrs, unsigned long attr_count);
48 TEE_Result syscall_cryp_obj_copy(unsigned long dst_obj,
49 			unsigned long src_obj);
50 TEE_Result syscall_obj_generate_key(unsigned long obj, unsigned long key_size,
51 			const struct utee_attribute *params,
52 			unsigned long param_count);
53 
54 TEE_Result syscall_cryp_state_alloc(unsigned long algo, unsigned long op_mode,
55 			unsigned long key1, unsigned long key2,
56 			uint32_t *state);
57 TEE_Result syscall_cryp_state_copy(unsigned long dst, unsigned long src);
58 TEE_Result syscall_cryp_state_free(unsigned long state);
59 void tee_svc_cryp_free_states(struct user_ta_ctx *utc);
60 
61 /* iv and iv_len are ignored for hash algorithms */
62 TEE_Result syscall_hash_init(unsigned long state, const void *iv,
63 			size_t iv_len);
64 TEE_Result syscall_hash_update(unsigned long state, const void *chunk,
65 			size_t chunk_size);
66 TEE_Result syscall_hash_final(unsigned long state, const void *chunk,
67 			size_t chunk_size, void *hash, uint64_t *hash_len);
68 
69 TEE_Result syscall_cipher_init(unsigned long state, const void *iv,
70 			size_t iv_len);
71 TEE_Result syscall_cipher_update(unsigned long state, const void *src,
72 			size_t src_len, void *dest, uint64_t *dest_len);
73 TEE_Result syscall_cipher_final(unsigned long state, const void *src,
74 			size_t src_len, void *dest, uint64_t *dest_len);
75 
76 TEE_Result syscall_cryp_derive_key(unsigned long state,
77 			const struct utee_attribute *params,
78 			unsigned long param_count, unsigned long derived_key);
79 
80 TEE_Result syscall_cryp_random_number_generate(void *buf, size_t blen);
81 
82 TEE_Result syscall_authenc_init(unsigned long state, const void *nonce,
83 			size_t nonce_len, size_t tag_len,
84 			size_t aad_len, size_t payload_len);
85 TEE_Result syscall_authenc_update_aad(unsigned long state,
86 			const void *aad_data, size_t aad_data_len);
87 TEE_Result syscall_authenc_update_payload(unsigned long state,
88 			const void *src_data, size_t src_len, void *dest_data,
89 			uint64_t *dest_len);
90 TEE_Result syscall_authenc_enc_final(unsigned long state,
91 			const void *src_data, size_t src_len, void *dest_data,
92 			uint64_t *dest_len, void *tag, uint64_t *tag_len);
93 TEE_Result syscall_authenc_dec_final(unsigned long state,
94 			const void *src_data, size_t src_len, void *dest_data,
95 			uint64_t *dest_len, const void *tag, size_t tag_len);
96 
97 TEE_Result syscall_asymm_operate(unsigned long state,
98 			const struct utee_attribute *usr_params,
99 			size_t num_params, const void *src_data,
100 			size_t src_len, void *dest_data, uint64_t *dest_len);
101 TEE_Result syscall_asymm_verify(unsigned long state,
102 			const struct utee_attribute *usr_params,
103 			size_t num_params, const void *data, size_t data_len,
104 			const void *sig, size_t sig_len);
105 
106 TEE_Result tee_obj_set_type(struct tee_obj *o, uint32_t obj_type,
107 			    size_t max_key_size);
108 
109 void tee_obj_attr_free(struct tee_obj *o);
110 void tee_obj_attr_clear(struct tee_obj *o);
111 TEE_Result tee_obj_attr_to_binary(struct tee_obj *o, void *data,
112 				  size_t *data_len);
113 TEE_Result tee_obj_attr_from_binary(struct tee_obj *o, const void *data,
114 				    size_t data_len);
115 TEE_Result tee_obj_attr_copy_from(struct tee_obj *o, const struct tee_obj *src);
116 
117 #endif /* TEE_SVC_CRYP_H */
118