1 /* 2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 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 #ifndef __HVB_HASH_SM3_H__ 16 #define __HVB_HASH_SM3_H__ 17 18 #include <stdint.h> 19 20 #define SM3_BLK_WORD_SIZE 16 21 #define SM3_BLK_BYTE_SIZE (SM3_BLK_WORD_SIZE * sizeof(uint32_t)) 22 23 #define SM3_IV_WORD_SIZE 8 24 #define SM3_IV_BYTE_SIZE (SM3_IV_WORD_SIZE * sizeof(uint32_t)) 25 26 #define SM3_OUT_BYTE_SIZE SM3_IV_BYTE_SIZE 27 28 #define SM3_OK 0 29 #define SM3_POINTER_NULL (-1) 30 #define SM3_BUF_LEN_ERR (-2) 31 #define SM3_OVER_MAX_LEN (-3) 32 #define SM3_OUTBUF_NOT_ENOUGH (-4) 33 #define SM3_MSG_LEN_ERR (-5) 34 #define SM3_MEMORY_ERR (-6) 35 struct sm3_ctx_t { 36 uint32_t buf_len; 37 38 uint64_t total_len; 39 40 uint32_t iv[SM3_IV_WORD_SIZE]; 41 42 uint8_t blk_buf[SM3_BLK_BYTE_SIZE]; 43 }; 44 45 int hvb_sm3_init(struct sm3_ctx_t *hash_ctx); 46 47 int hvb_sm3_update(struct sm3_ctx_t *hash_ctx, const void *msg, uint32_t msg_len); 48 49 int hvb_sm3_final(struct sm3_ctx_t *hash_ctx, uint8_t *out, uint32_t *out_len); 50 51 int hvb_sm3_single(const void *msg, uint32_t msg_len, uint8_t *out, uint32_t *out_len); 52 53 #endif 54