1 /* 2 * Copyright (C) 2022 Huawei Technologies Co., Ltd. 3 * Licensed under the Mulan PSL v2. 4 * You can use this software according to the terms and conditions of the Mulan PSL v2. 5 * You may obtain a copy of Mulan PSL v2 at: 6 * http://license.coscl.org.cn/MulanPSL2 7 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR 8 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR 9 * PURPOSE. 10 * See the Mulan PSL v2 for more details. 11 */ 12 #ifndef _SOFT_COMMON_API_H 13 #define _SOFT_COMMON_API_H 14 15 #include <crypto_inner_defines.h> 16 #include "crypto_driver_adaptor.h" 17 18 #define AES_MAX_IV_SIZE 16 19 #define AES_TEN_ROUNDS_KEY_SIZE 16 20 #define AES_TWELVE_ROUNDS_KEY_SIZE 24 21 #define AES_FOURTEEN_ROUNDS_KEY_SIZE 32 22 #define SM4_GCM_KEY_SIZE 16 23 #define AES_MAX_KEY_SIZE 64 24 #define DES_KEY_SIZE 8 25 #define DES3_KEY_SIZE 24 26 #define ARRAY_NUM(array) (sizeof(array) / sizeof((array)[0])) 27 #define ED25519_SIGN_LEN 64 28 #define X25519_SHARE_KEY_LEN 32 29 #define SHARE_KEY_MAX_LEN 128 30 #define BORINGSSL_OK 1 31 #define BORINGSSL_ERR 0 32 #define AES_CCM_MAX_TAG_LEN 16 33 #define AES_MODE_ENCRYPT 1 34 #define AES_MODE_DECRYPT 0 35 #define SOFT_NUMBER_TWO 2 36 #define OPENSSL_OK 1 37 #define MD5_LEN 16 38 #define SHA1_LEN 20 39 #define SHA224_LEN 28 40 #define SHA256_LEN 32 41 #define SHA384_LEN 48 42 #define SHA512_LEN 64 43 #define MAX_VALID_ALGO_SIZE 32 44 #define CRYPTO_TYPE_DIGEST 0x50000000 45 #define CRYPTO_TYPE_HMAC 0x30000000 46 #define CRYPTO_TYPE_CIPHER 0x10000000 47 #define CRYPTO_TYPE_AES_MAC 0x30000010 48 #define CRYPTO_TYPE_AES 0x40000000 49 #define TEE_PARAM_MAX 9 50 51 int32_t check_params(const struct asymmetric_params_t *params); 52 int32_t check_valid_algorithm(uint32_t algorithm, const uint32_t *array, uint32_t array_size); 53 uint32_t get_hash_context_size(uint32_t algorithm); 54 void free_cipher_context(uint64_t *ctx); 55 void free_hmac_context(uint64_t *ctx); 56 int32_t soft_crypto_ctx_copy(const struct ctx_handle_t *src_ctx, struct ctx_handle_t *dest_ctx); 57 int32_t get_boring_nid_by_tee_curve(uint32_t tee_domain, uint32_t *nid); 58 int32_t get_openssl_rand(unsigned char *buf, int num); 59 #ifdef OPENSSL_ENABLE 60 void free_openssl_drbg_mem(void); 61 #endif 62 #endif 63