File tree Expand file tree Collapse file tree 6 files changed +30
-54
lines changed
Expand file tree Collapse file tree 6 files changed +30
-54
lines changed Original file line number Diff line number Diff line change 99*/
1010
1111#include < Arduino_SHA256.h>
12+ #include < Arduino_HEX.h>
1213#include " buffer.h"
1314
1415void setup () {
1516 Serial.begin (9600 );
1617 while (!Serial);
1718
18- uint8_t sha[SHA256::HASH_SIZE ];
19+ uint8_t sha[SHA256_DIGEST_SIZE ];
1920
2021 SHA256 sha256;
2122 sha256.begin ();
2223 sha256.update (buffer, sizeof (buffer));
2324 sha256.finalize (sha);
2425
25- Serial.println (hexEncode (sha, sizeof (sha)));
26+ Serial.println (THEXT::encode (sha, sizeof (sha)));
2627
2728 /* 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)));
4131}
4232
4333void loop () { }
Original file line number Diff line number Diff line change 1010#pragma once
1111
1212#include " ./hex/hex.h"
13+ using namespace arduino ;
1314using namespace hex ;
Original file line number Diff line number Diff line change 1010#pragma once
1111
1212#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 {
3838 if (!get (data, sizeof (data))) {
3939 return String (" " );
4040 }
41- uint8_t out[SHA256::HASH_SIZE ];
41+ uint8_t out[SHA256_DIGEST_SIZE ];
4242 arduino::sha256::sha256 (data, sizeof (data), out);
4343 return arduino::hex::encode (out, sizeof (out));
4444 }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1212
1313#include " sha2.h"
1414
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-
3015namespace arduino { namespace sha256 {
3116
3217 inline void begin (sha256_ctx * ctx) {
@@ -42,4 +27,25 @@ namespace arduino { namespace sha256 {
4227 ::sha256 (input, ilen, output);
4328 }
4429
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+
4551}} // arduino::sha256
You can’t perform that action at this time.
0 commit comments