1 /* 2 * Copyright (C) 2022 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 16 #ifndef FILLP_SHA256_H 17 #define FILLP_SHA256_H 18 19 #include "fillptypes.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #define FILLP_SHA256_DIGEST_SIZE 32 /* hash size in bytes 8 * sizeof(FILLP_UINT32) */ 26 #define FILLP_SHA256_BLOCK_SIZE 64 /* wbuf size in bytes 16 * sizeof(FILLP_UINT32) */ 27 28 typedef struct { 29 FILLP_UINT32 count[2]; 30 FILLP_UINT32 hash[8]; 31 FILLP_UINT32 wbuf[16]; 32 } FillpSha256Ctx; 33 34 /******************************************************************************* 35 Function : FillpSha256Set 36 Description : init sha256 context 37 38 Input : 39 ctx[1] : Partition number 40 Output :None 41 *******************************************************************************/ 42 void FillpSha256Set(FillpSha256Ctx ctx[1]); 43 44 /******************************************************************************* 45 Function : FillpSha256Upd 46 Description : update sha256 context with data in an array of bytes 47 48 Input : 49 ctx[1] : sha256 context 50 data[] : data to calculate 51 len : size in byte of data array 52 Output :None 53 *******************************************************************************/ 54 void FillpSha256Upd(FillpSha256Ctx ctx[1], const FILLP_UINT8 data[], size_t len); 55 56 /******************************************************************************* 57 Function : FillpSha256Set 58 Description : Final padding and digest calculation 59 60 Input : 61 ctx[1] : sha256 context 62 Output : 63 hashVal[]: hash value 64 *******************************************************************************/ 65 void FillpSha256Fin(FillpSha256Ctx ctx[1], FILLP_UINT8 hashVal[], FILLP_UINT32 hashValLen); 66 67 68 #ifdef __cplusplus 69 } 70 #endif 71 72 73 #endif /* FILLP_SHA256_H */ 74 75