概要
wemosでsha256やってみた。
使用したライブラリー
サンプルコード
# include "sha256.h"
void setup() {
uint8_t key1[] = {0x61, 0x62, 0x63};
uint8_t key2[] = {0xd3};
uint8_t key3[] = {0x11, 0xaf};
BYTE hash[SHA256_BLOCK_SIZE];
char texthash[2 * SHA256_BLOCK_SIZE + 1];
Serial.begin(115200);
Serial.println("");
Sha256 * sha256Instance0 = new Sha256();
BYTE text[] = "abc";
//sha256Instance->update(text, strlen((const char *) text));
sha256Instance0->update(key1, 3);
Serial.println("in: abc");
sha256Instance0->final(hash);
for (int i = 0; i < SHA256_BLOCK_SIZE; i++)
sprintf(texthash + 2 * i, "%02X", hash[i]);
Serial.println(texthash);
delete sha256Instance0;
Sha256 * sha256Instance1 = new Sha256();
sha256Instance1->update(key1, 0);
Serial.println("in: ");
sha256Instance1->final(hash);
for (int i = 0; i < SHA256_BLOCK_SIZE; i++)
sprintf(texthash + 2 * i, "%02X", hash[i]);
Serial.println(texthash);
delete sha256Instance1;
Sha256 * sha256Instance2 = new Sha256();
sha256Instance2->update(key2, 1);
Serial.println("in: d3");
sha256Instance2->final(hash);
for (int i = 0; i < SHA256_BLOCK_SIZE; i++)
sprintf(texthash + 2 * i, "%02X", hash[i]);
Serial.println(texthash);
delete sha256Instance2;
Sha256 * sha256Instance3 = new Sha256();
sha256Instance3->update(key3, 2);
Serial.println("in: 11af");
sha256Instance3->final(hash);
for (int i = 0; i < SHA256_BLOCK_SIZE; i++)
sprintf(texthash + 2 * i, "%02X", hash[i]);
Serial.println(texthash);
delete sha256Instance3;
}
void loop() {
delay(10);
}
結果
in: abc
BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD
in:
E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855
in: d3
28969CDFA74A12C82F3BAD960B0B000ACA2AC329DEEA5C2328EBC6F2BA9802C1
in: 11af
5CA7133FA735326081558AC312C620EECA9970D1E70A4B95533D956F072D1F98
以上。