xref: /optee_os/core/include/tee/tee_svc_cryp.h (revision b01047730e77127c23a36591643eeb8bb0487d68)
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 tee_svc_cryp_obj_get_info(uint32_t obj, TEE_ObjectInfo *info);
34 TEE_Result tee_svc_cryp_obj_restrict_usage(uint32_t obj, uint32_t usage);
35 TEE_Result tee_svc_cryp_obj_get_attr(uint32_t obj, uint32_t attr_id,
36 				     void *buffer, size_t *size);
37 
38 TEE_Result tee_svc_cryp_obj_alloc(TEE_ObjectType obj_type,
39 				  uint32_t max_obj_size, uint32_t *obj);
40 TEE_Result tee_svc_cryp_obj_close(uint32_t obj);
41 TEE_Result tee_svc_cryp_obj_reset(uint32_t obj);
42 TEE_Result tee_svc_cryp_obj_populate(uint32_t obj, TEE_Attribute *attrs,
43 				     uint32_t attr_count);
44 TEE_Result tee_svc_cryp_obj_copy(uint32_t dst_obj, uint32_t src_obj);
45 TEE_Result tee_svc_obj_generate_key(uint32_t obj, uint32_t key_size,
46 				    const TEE_Attribute *params,
47 				    uint32_t param_count);
48 
49 TEE_Result tee_svc_cryp_state_alloc(uint32_t algo, uint32_t op_mode,
50 				    uint32_t key1, uint32_t key2,
51 				    uint32_t *state);
52 TEE_Result tee_svc_cryp_state_copy(uint32_t dst, uint32_t src);
53 TEE_Result tee_svc_cryp_state_free(uint32_t state);
54 void tee_svc_cryp_free_states(struct tee_ta_ctx *ctx);
55 
56 /* iv and iv_len are ignored for hash algorithms */
57 TEE_Result tee_svc_hash_init(uint32_t state, const void *iv, size_t iv_len);
58 TEE_Result tee_svc_hash_update(uint32_t state, const void *chunk,
59 			       size_t chunk_size);
60 TEE_Result tee_svc_hash_final(uint32_t state, const void *chunk,
61 			      size_t chunk_size, void *hash, size_t *hash_len);
62 
63 TEE_Result tee_svc_cipher_init(uint32_t state, const void *iv, size_t iv_len);
64 TEE_Result tee_svc_cipher_update(uint32_t state, const void *src,
65 				 size_t src_len, void *dest, size_t *dest_len);
66 TEE_Result tee_svc_cipher_final(uint32_t state, const void *src,
67 				size_t src_len, void *dest, size_t *dest_len);
68 
69 TEE_Result tee_svc_cryp_derive_key(uint32_t state, const TEE_Attribute *params,
70 				   uint32_t param_count, uint32_t derived_key);
71 
72 TEE_Result tee_svc_cryp_random_number_generate(void *buf, size_t blen);
73 
74 TEE_Result tee_svc_authenc_init(uint32_t state, const void *nonce,
75 				size_t nonce_len, size_t tag_len,
76 				size_t aad_len, size_t payload_len);
77 TEE_Result tee_svc_authenc_update_aad(uint32_t state, const void *aad_data,
78 				      size_t aad_data_len);
79 TEE_Result tee_svc_authenc_update_payload(uint32_t state, const void *src_data,
80 					  size_t src_len, void *dest_data,
81 					  size_t *dest_len);
82 TEE_Result tee_svc_authenc_enc_final(uint32_t state, const void *src_data,
83 				     size_t src_len, void *dest_data,
84 				     size_t *dest_len, void *tag,
85 				     size_t *tag_len);
86 TEE_Result tee_svc_authenc_dec_final(uint32_t state, const void *src_data,
87 				     size_t src_len, void *dest_data,
88 				     size_t *dest_len, const void *tag,
89 				     size_t tag_len);
90 
91 TEE_Result tee_svc_asymm_operate(uint32_t state, const TEE_Attribute *params,
92 				 uint32_t num_params, const void *src_data,
93 				 size_t src_len, void *dest_data,
94 				 size_t *dest_len);
95 TEE_Result tee_svc_asymm_verify(uint32_t state, const TEE_Attribute *params,
96 				uint32_t num_params, const void *data,
97 				size_t data_len, const void *sig,
98 				size_t sig_len);
99 
100 TEE_Result get_rng_array(void *buffer, int len);
101 
102 #endif /* TEE_SVC_CRYP_H */
103