• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
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  * Description: the head File of sha256
15  */
16 
17 #ifndef SHA256_H
18 #define SHA256_H
19 
20 #include <stdint.h>
21 #include "std_def.h"
22 
23 #define SHA256_HASH_SIZE 32
24 
25 /* Hash size in 32-bit words */
26 #define SHA256_HASH_WORDS 8
27 
28 #define SHA256_BUFFER_WORDS 16
29 #define SHA256_BUFFER_BYTES 64
30 
31 struct _sha256_context {
32     uint64_t total_length;
33     uint32_t hash[SHA256_HASH_WORDS];
34     uint32_t buffer_length;
35 
36     union {
37         uint32_t words[SHA256_BUFFER_WORDS];
38         uint8_t bytes[SHA256_BUFFER_BYTES];
39     } buffer;
40 #ifdef RUNTIME_ENDIAN
41     int little_endian;
42 #endif /* RUNTIME_ENDIAN */
43 };
44 
45 typedef struct _sha256_context sha256_context_t;
46 
47 void sha256_init(sha256_context_t *sc);
48 void SHA256Update(sha256_context_t *sc, const void *vdata, uint32_t len);
49 
50 void sha256_final(sha256_context_t *sc, uint8_t hash[SHA256_HASH_SIZE], uint32_t hash_len);
51 void sha256_hash(const uint8_t *in_buff, uint32_t in_buff_len, uint8_t *out_buff, uint32_t out_buff_len);
52 
53 #endif
54