-
Notifications
You must be signed in to change notification settings - Fork 15
Use SHA256d Crypo Engine on 7697
Jollen edited this page Nov 15, 2018
·
1 revision
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "hal_sha.h"
hal_sha256_context_t context;
uint8_t digest[HAL_SHA256_DIGEST_SIZE];
char *payload = "abcdefg";
uint8_t *message;
hal_sha_status_t ret;
#define CONFIG_BENCHMARK 1
// Benchmark
#ifdef CONFIG_BENCHMARK
long currentMillis = 0;
long lastMillis = 0;
long loops = 0;
#endif
void setup() {
Serial.begin(9600);
hal_sha256_init(&context);
#ifdef CONFIG_BENCHMARK
currentMillis = lastMillis = millis();
#endif
}
void loop() {
#ifdef CONFIG_BENCHMARK
loops = 0;
lastMillis = millis();
#endif
message = (uint8_t*)payload;
#ifdef CONFIG_BENCHMARK
while (currentMillis - lastMillis < 1000) {
#endif
hal_sha256_append(&context, message, strlen(payload));
ret = hal_sha256_end(&context, digest);
#ifdef CONFIG_BENCHMARK
loops++;
currentMillis = millis();
}
Serial.print("Loops last second: ");
Serial.println(loops);
#endif
}