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, uint32_t *size); 37 38 TEE_Result tee_svc_cryp_obj_alloc(TEE_ObjectType obj_type, 39 uint32_t max_key_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, 43 struct abi_user32_attribute *usr_attrs, 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 struct abi_user32_attribute *usr_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, uint32_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, uint32_t *dest_len); 66 TEE_Result tee_svc_cipher_final(uint32_t state, const void *src, 67 size_t src_len, void *dest, uint32_t *dest_len); 68 69 TEE_Result tee_svc_cryp_derive_key(uint32_t state, 70 const struct abi_user32_attribute *usr_params, 71 uint32_t param_count, uint32_t derived_key); 72 73 TEE_Result tee_svc_cryp_random_number_generate(void *buf, size_t blen); 74 75 TEE_Result tee_svc_authenc_init(uint32_t state, const void *nonce, 76 size_t nonce_len, size_t tag_len, 77 size_t aad_len, size_t payload_len); 78 TEE_Result tee_svc_authenc_update_aad(uint32_t state, const void *aad_data, 79 size_t aad_data_len); 80 TEE_Result tee_svc_authenc_update_payload(uint32_t state, const void *src_data, 81 size_t src_len, void *dest_data, 82 uint32_t *dest_len); 83 TEE_Result tee_svc_authenc_enc_final(uint32_t state, const void *src_data, 84 size_t src_len, void *dest_data, 85 uint32_t *dest_len, void *tag, 86 uint32_t *tag_len); 87 TEE_Result tee_svc_authenc_dec_final(uint32_t state, const void *src_data, 88 size_t src_len, void *dest_data, 89 uint32_t *dest_len, const void *tag, 90 size_t tag_len); 91 92 TEE_Result tee_svc_asymm_operate(uint32_t state, 93 const struct abi_user32_attribute *usr_params, 94 uint32_t num_params, const void *src_data, 95 size_t src_len, void *dest_data, uint32_t *dest_len); 96 TEE_Result tee_svc_asymm_verify(uint32_t state, 97 const struct abi_user32_attribute *usr_params, 98 uint32_t num_params, const void *data, 99 size_t data_len, const void *sig, size_t sig_len); 100 101 #endif /* TEE_SVC_CRYP_H */ 102