xref: /optee_os/core/include/tee/tee_svc_cryp.h (revision f17691b3f6b27866f66636a53685bd3a6f7daa8a)
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 
33 struct user_ta_ctx;
34 
35 TEE_Result syscall_cryp_obj_get_info(unsigned long obj, TEE_ObjectInfo *info);
36 TEE_Result syscall_cryp_obj_restrict_usage(unsigned long obj,
37 			unsigned long usage);
38 TEE_Result syscall_cryp_obj_get_attr(unsigned long obj, unsigned long attr_id,
39 			void *buffer, uint64_t *size);
40 
41 TEE_Result syscall_cryp_obj_alloc(unsigned long obj_type,
42 			unsigned long max_key_size, uint32_t *obj);
43 TEE_Result syscall_cryp_obj_close(unsigned long obj);
44 TEE_Result syscall_cryp_obj_reset(unsigned long obj);
45 TEE_Result syscall_cryp_obj_populate(unsigned long obj,
46 			struct utee_attribute *attrs, unsigned long attr_count);
47 TEE_Result syscall_cryp_obj_copy(unsigned long dst_obj,
48 			unsigned long src_obj);
49 TEE_Result syscall_obj_generate_key(unsigned long obj, unsigned long key_size,
50 			const struct utee_attribute *params,
51 			unsigned long param_count);
52 
53 TEE_Result syscall_cryp_state_alloc(unsigned long algo, unsigned long op_mode,
54 			unsigned long key1, unsigned long key2,
55 			uint32_t *state);
56 TEE_Result syscall_cryp_state_copy(unsigned long dst, unsigned long src);
57 TEE_Result syscall_cryp_state_free(unsigned long state);
58 void tee_svc_cryp_free_states(struct user_ta_ctx *utc);
59 
60 /* iv and iv_len are ignored for hash algorithms */
61 TEE_Result syscall_hash_init(unsigned long state, const void *iv,
62 			size_t iv_len);
63 TEE_Result syscall_hash_update(unsigned long state, const void *chunk,
64 			size_t chunk_size);
65 TEE_Result syscall_hash_final(unsigned long state, const void *chunk,
66 			size_t chunk_size, void *hash, uint64_t *hash_len);
67 
68 TEE_Result syscall_cipher_init(unsigned long state, const void *iv,
69 			size_t iv_len);
70 TEE_Result syscall_cipher_update(unsigned long state, const void *src,
71 			size_t src_len, void *dest, uint64_t *dest_len);
72 TEE_Result syscall_cipher_final(unsigned long state, const void *src,
73 			size_t src_len, void *dest, uint64_t *dest_len);
74 
75 TEE_Result syscall_cryp_derive_key(unsigned long state,
76 			const struct utee_attribute *params,
77 			unsigned long param_count, unsigned long derived_key);
78 
79 TEE_Result syscall_cryp_random_number_generate(void *buf, size_t blen);
80 
81 TEE_Result syscall_authenc_init(unsigned long state, const void *nonce,
82 			size_t nonce_len, size_t tag_len,
83 			size_t aad_len, size_t payload_len);
84 TEE_Result syscall_authenc_update_aad(unsigned long state,
85 			const void *aad_data, size_t aad_data_len);
86 TEE_Result syscall_authenc_update_payload(unsigned long state,
87 			const void *src_data, size_t src_len, void *dest_data,
88 			uint64_t *dest_len);
89 TEE_Result syscall_authenc_enc_final(unsigned long state,
90 			const void *src_data, size_t src_len, void *dest_data,
91 			uint64_t *dest_len, void *tag, uint64_t *tag_len);
92 TEE_Result syscall_authenc_dec_final(unsigned long state,
93 			const void *src_data, size_t src_len, void *dest_data,
94 			uint64_t *dest_len, const void *tag, size_t tag_len);
95 
96 TEE_Result syscall_asymm_operate(unsigned long state,
97 			const struct utee_attribute *usr_params,
98 			size_t num_params, const void *src_data,
99 			size_t src_len, void *dest_data, uint64_t *dest_len);
100 TEE_Result syscall_asymm_verify(unsigned long state,
101 			const struct utee_attribute *usr_params,
102 			size_t num_params, const void *data, size_t data_len,
103 			const void *sig, size_t sig_len);
104 
105 #endif /* TEE_SVC_CRYP_H */
106