Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkberg committed Apr 27, 2016
1 parent de03e67 commit 03538d9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions sketches/lights-lamp/lights-lamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void set_rgb_color(uint8_t r, uint8_t g, uint8_t b, bool blink) {

}

static inline void print_hash(char *sig) {
static inline void print_hash(const char *sig) {
Serial.print(F("[HASH] "));
for (uint8_t i = 0; i < crypto_hash_BYTES; i++) Serial.print((unsigned char) sig[i], 16);
Serial.println();
Expand Down Expand Up @@ -214,8 +214,6 @@ void process_response(char *response, char *&payload, char *&signature) {

// extract signature and decode it
base64_decode(tmp_signature, (response + token[index].start), token[index].end - token[index].start);
print_hash(tmp_signature);

} else if (jsoneq(response, token[index], P_PAYLOAD) == 0 && token[index + 1].type == JSMN_OBJECT) {
index++;
Serial.print(F("payload: "));
Expand Down Expand Up @@ -282,6 +280,7 @@ bool verify_payload(const char *payload, const char *signature) {

crypto_hash_sha512((unsigned char *) payload_hash, (const unsigned char *) payload, strlen(payload));
print_hash(payload_hash);
print_hash(signature);

signature_verified = !memcmp(signature, payload_hash, crypto_hash_BYTES);
if (!signature_verified) error_flag |= E_SIG_VRFY_FAIL;
Expand Down
5 changes: 2 additions & 3 deletions sketches/lights-sensor/lights-sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static unsigned int to_uint(const char *ptr, size_t len) {
}

// print a hex representation of the has byte array
static inline void print_hash(char *sig) {
static inline void print_hash(const char *sig) {
Serial.print(F("[HASH] "));
for (uint8_t i = 0; i < crypto_hash_BYTES; i++) Serial.print((unsigned char) sig[i], 16);
Serial.println();
Expand Down Expand Up @@ -151,8 +151,6 @@ void process_response(char *response, char *&payload, char *&signature) {

// extract signature and decode it
base64_decode(tmp_signature, (response + token[index].start), token[index].end - token[index].start);
print_hash(tmp_signature);

} else if (jsoneq(response, token[index], P_PAYLOAD) == 0 && token[index + 1].type == JSMN_OBJECT) {
index++;
Serial.print(F("payload: "));
Expand Down Expand Up @@ -219,6 +217,7 @@ bool verify_payload(const char *payload, const char *signature) {

crypto_hash_sha512((unsigned char *) payload_hash, (const unsigned char *) payload, strlen(payload));
print_hash(payload_hash);
print_hash(signature);

signature_verified = !memcmp(signature, payload_hash, crypto_hash_BYTES);
if (!signature_verified) error_flag |= E_SIG_VRFY_FAIL;
Expand Down

0 comments on commit 03538d9

Please sign in to comment.