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