Line data Source code
1 : /**
2 : * The MIT License (MIT)
3 : *
4 : * Copyright (c) 2021 RSK Labs Ltd
5 : *
6 : * Permission is hereby granted, free of charge, to any person obtaining a copy
7 : * of this software and associated documentation files (the "Software"), to
8 : * deal in the Software without restriction, including without limitation the
9 : * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 : * sell copies of the Software, and to permit persons to whom the Software is
11 : * furnished to do so, subject to the following conditions:
12 : *
13 : * The above copyright notice and this permission notice shall be included in
14 : * all copies or substantial portions of the Software.
15 : *
16 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 : * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 : * IN THE SOFTWARE.
23 : */
24 :
25 : #include "hal/hash.h"
26 :
27 : // *** sha256 ***
28 1 : bool hash_sha256_init(hash_sha256_ctx_t* ctx) {
29 1 : sha256_init(ctx);
30 1 : return true;
31 : }
32 :
33 1 : bool hash_sha256_update(hash_sha256_ctx_t* ctx,
34 : const uint8_t* data,
35 : size_t len) {
36 1 : sha256_update(ctx, data, len);
37 1 : return true;
38 : }
39 :
40 1 : bool hash_sha256_final(hash_sha256_ctx_t* ctx, uint8_t* out_hash) {
41 1 : sha256_final(ctx, out_hash);
42 1 : return true;
43 : }
44 :
45 : // *** sha256 with midstate support ***
46 1 : bool hash_sha256_ms_init(hash_sha256_ms_ctx_t* ctx) {
47 1 : sha256_init(ctx);
48 1 : return true;
49 : }
50 :
51 1 : bool hash_sha256_ms_midstate(hash_sha256_ms_ctx_t* ctx, uint8_t* midstate) {
52 1 : sha256_midstate(ctx, midstate);
53 1 : return true;
54 : }
55 :
56 1 : bool hash_sha256_ms_update(hash_sha256_ms_ctx_t* ctx,
57 : const uint8_t* data,
58 : size_t len) {
59 1 : sha256_update(ctx, data, len);
60 1 : return true;
61 : }
62 :
63 1 : bool hash_sha256_ms_final(hash_sha256_ms_ctx_t* ctx, uint8_t* out_hash) {
64 1 : sha256_final(ctx, out_hash);
65 1 : return true;
66 : }
67 :
68 : // *** keccak256 ***
69 1 : bool hash_keccak256_init(hash_keccak256_ctx_t* ctx) {
70 1 : keccak_init(ctx);
71 1 : return true;
72 : }
73 :
74 1 : bool hash_keccak256_update(hash_keccak256_ctx_t* ctx,
75 : const uint8_t* data,
76 : size_t len) {
77 1 : keccak_update(ctx, data, len);
78 1 : return true;
79 : }
80 :
81 1 : bool hash_keccak256_final(hash_keccak256_ctx_t* ctx, uint8_t* out_hash) {
82 1 : keccak_final(ctx, out_hash);
83 1 : return true;
84 : }
|