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