File tree 2 files changed +68
-0
lines changed
2 files changed +68
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ This file is part of the Arduino_CloudUtils library.
3
+
4
+ Copyright (c) 2024 Arduino SA
5
+
6
+ This Source Code Form is subject to the terms of the Mozilla Public
7
+ License, v. 2.0. If a copy of the MPL was not distributed with this
8
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
+ */
10
+
11
+ #include " SHA256.h"
12
+
13
+ void SHA256::begin () {
14
+ sha256_init (&_ctx);
15
+ }
16
+
17
+ void SHA256::update (uint8_t const * data, uint32_t const len) {
18
+ sha256_update (&_ctx, data, len);
19
+ }
20
+
21
+ void SHA256::finalize (uint8_t * hash) {
22
+ sha256_final (&_ctx, hash);
23
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ This file is part of the Arduino_CloudUtils library.
3
+
4
+ Copyright (c) 2024 Arduino SA
5
+
6
+ This Source Code Form is subject to the terms of the Mozilla Public
7
+ License, v. 2.0. If a copy of the MPL was not distributed with this
8
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
+ */
10
+
11
+ #pragma once
12
+
13
+ #include " sha256.h"
14
+
15
+ class SHA256 {
16
+
17
+ public:
18
+
19
+ static constexpr uint32_t HASH_SIZE = SHA256_DIGEST_SIZE;
20
+
21
+ void begin ();
22
+ void update (uint8_t const * data, uint32_t const len);
23
+ void finalize (uint8_t * hash);
24
+
25
+ private:
26
+
27
+ sha256_ctx _ctx;
28
+ };
29
+
30
+ namespace arduino { namespace sha256 {
31
+
32
+ inline void begin (sha256_ctx * ctx) {
33
+ return sha256_init (ctx);
34
+ }
35
+ inline void update (sha256_ctx *ctx, const uint8_t *input, uint32_t length) {
36
+ return sha256_update (ctx, input, length);
37
+ }
38
+ inline void finalize (sha256_ctx * ctx, uint8_t digest[SHA256_DIGEST_SIZE]) {
39
+ return sha256_final (ctx, digest);
40
+ }
41
+ inline void oneshot (const unsigned char *input, unsigned int ilen, unsigned char *output) {
42
+ ::sha256 (input, ilen, output);
43
+ }
44
+
45
+ }} // arduino::sha256
You can’t perform that action at this time.
0 commit comments