1 // Copyright (C) 2022 Beken Corporation 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 #define SEC_DEV_NAME "sec" 22 23 void hal_sha_update( void *ctx, const unsigned char *input,size_t ilen ); 24 void hal_sha_finish( void *ctx, unsigned char output[32] ); 25 extern void bk_secrity_init(void); 26 extern void bk_secrity_exit(void); 27 28 /********************************************************/ 29 //sha256 30 /* @brief sha256_init 31 * @retval ctx 32 */ 33 void * hal_sha256_init(void); 34 35 /** 36 * @brief Append SHA256 data to calculate. 37 * @param ct: from hal_sha256_init 38 * @param input: the data needed to calculate sha256. 39 * @param ilen: size of data. 40 */ 41 #define hal_sha256_update hal_sha_update 42 /** 43 * @brief Calculate the SHA256 of all appended data. 44 * @param ct: from hal_sha256_init 45 * @param output: Store the result of calculation of SHA1, result 46 * need 32 bytes space. 47 */ 48 #define hal_sha256_finish hal_sha_finish 49 50 //sha1 51 /* @brief sha1_init 52 * @retval ctx 53 */ 54 void * hal_sha1_init(void); 55 /** 56 * @brief Append SHA1 data to calculate. 57 * @param ct: from hal_sha1_init 58 * @param input: the data needed to calculate sha1. 59 * @param ilen: size of data. 60 */ 61 #define hal_sha1_update hal_sha_update 62 /** 63 * @brief Calculate the SHA1 of all appended data. 64 * @param ct: from hal_sha1_init 65 * @param output: Store the result of calculation of SHA1, result 66 * need 20 bytes space. 67 */ 68 #define hal_sha1_finish hal_sha_finish 69 70 //aes 71 72 /* @brief aes context init 73 * @param key: the aes key 74 * @param key: the aes key len,must be 32,24,16. 75 * @retval ctx 76 */ 77 void *hal_aes_init(const u8 *key, size_t key_size); 78 79 /* @brief aes_encrypt 80 * @param ctx: from hal_aes_init 81 * @param plain: plain data which is need to be encrypt. 82 * @param cipher: cipher data which is store the encrpyted data. 83 */ 84 void hal_aes_encrypt(void *ctx, const u8 *plain, u8 *cipher); 85 86 /* @brief aes_decrypt 87 * @param ctx: from hal_aes_init 88 * @param cipher: cipher data which is needed to be decrypted. 89 * @param plain: plain data which store the decrypted data. 90 */ 91 void hal_aes_decrypt(void *ctx, const u8 *cipher, u8 *plain); 92 93 /* @brief deinit free ctx 94 * @param ctx: from hal_aes_init 95 */ 96 void hal_aes_deinit(void *ctx); 97 /********************************************************/ 98 99 #ifdef __cplusplus 100 } 101 #endif 102