File tree 6 files changed +30
-54
lines changed
6 files changed +30
-54
lines changed Original file line number Diff line number Diff line change 9
9
*/
10
10
11
11
#include < Arduino_SHA256.h>
12
+ #include < Arduino_HEX.h>
12
13
#include " buffer.h"
13
14
14
15
void setup () {
15
16
Serial.begin (9600 );
16
17
while (!Serial);
17
18
18
- uint8_t sha[SHA256::HASH_SIZE ];
19
+ uint8_t sha[SHA256_DIGEST_SIZE ];
19
20
20
21
SHA256 sha256;
21
22
sha256.begin ();
22
23
sha256.update (buffer, sizeof (buffer));
23
24
sha256.finalize (sha);
24
25
25
- Serial.println (hexEncode (sha, sizeof (sha)));
26
+ Serial.println (THEXT::encode (sha, sizeof (sha)));
26
27
27
28
/* One-shot */
28
- arduino::sha256::sha256 (buffer, sizeof (buffer), sha);
29
- Serial.println (hexEncode (sha, sizeof (sha)));
30
- }
31
-
32
- static String hexEncode (uint8_t * in, uint32_t size) {
33
- String out;
34
- out.reserve ((size * 2 ) + 1 );
35
-
36
- char * ptr = out.begin ();
37
- for (uint32_t i = 0 ; i < size; i++) {
38
- ptr += sprintf (ptr, " %02X" , in[i]);
39
- }
40
- return String (out.c_str ());
29
+ SHA256::sha256 (buffer, sizeof (buffer), sha);
30
+ Serial.println (THEXT::encode (sha, sizeof (sha)));
41
31
}
42
32
43
33
void loop () { }
Original file line number Diff line number Diff line change 10
10
#pragma once
11
11
12
12
#include " ./hex/hex.h"
13
+ using namespace arduino ;
13
14
using namespace hex ;
Original file line number Diff line number Diff line change 10
10
#pragma once
11
11
12
12
#include " ./sha256/SHA256.h"
13
+ using namespace arduino ;
14
+ using namespace sha256 ;
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ namespace arduino { namespace bpid {
38
38
if (!get (data, sizeof (data))) {
39
39
return String (" " );
40
40
}
41
- uint8_t out[SHA256::HASH_SIZE ];
41
+ uint8_t out[SHA256_DIGEST_SIZE ];
42
42
arduino::sha256::sha256 (data, sizeof (data), out);
43
43
return arduino::hex::encode (out, sizeof (out));
44
44
}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 12
12
13
13
#include " sha2.h"
14
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
15
namespace arduino { namespace sha256 {
31
16
32
17
inline void begin (sha256_ctx * ctx) {
@@ -42,4 +27,25 @@ namespace arduino { namespace sha256 {
42
27
::sha256 (input, ilen, output);
43
28
}
44
29
30
+ class SHA256 {
31
+ public:
32
+
33
+ inline void begin () {
34
+ return arduino::sha256::begin (&_ctx);
35
+ }
36
+ inline void update (uint8_t const * data, uint32_t const len) {
37
+ return arduino::sha256::update (&_ctx, data, len);
38
+ }
39
+ inline void finalize (uint8_t * hash) {
40
+ return arduino::sha256::finalize (&_ctx, hash);
41
+ }
42
+ static inline void sha256 (uint8_t const * data, uint32_t const len, uint8_t * hash) {
43
+ return arduino::sha256::sha256 (data, len, hash);
44
+ }
45
+
46
+ private:
47
+
48
+ sha256_ctx _ctx;
49
+ };
50
+
45
51
}} // arduino::sha256
You can’t perform that action at this time.
0 commit comments