A look at SHA-1 and ESP8266

Description

In cryptography, SHA-1 (Secure Hash Algorithm 1) is a cryptographic hash function which takes an input and produces a 160-bit (20-byte) hash value known as a message digest – typically rendered as a hexadecimal number, 40 digits long

Cipher detail
Digest sizes 160 bits
Block sizes 512 bits
Structure Merkle–Damgård construction
Rounds 80

These are examples of SHA-1 message digests in hexadecimal and in Base64 binary to ASCII text encoding.

SHA1("The quick brown fox jumps over the lazy dog")
gives hexadecimal: 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12
gives Base64 binary to ASCII text encoding: L9ThxnotKPzthJ7hu3bnORuT6xI=

Even a small change in the message will, with overwhelming probability, result in many bits changing due to the avalanche effect. For example, changing dog to cog produces a hash with different values for 81 of the 160 bits:

SHA1("The quick brown fox jumps over the lazy cog")
gives hexadecimal: de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3
gives Base64 binary to ASCII text encoding: 3p8sf9JeGzr60+haC9F9mxANtLM=

The hash of the zero-length string is:

SHA1("")
gives hexadecimal: da39a3ee5e6b4b0d3255bfef95601890afd80709
gives Base64 binary to ASCII text encoding: 2jmj7l5rSw0yVb/vlWAYkK/YBwk=

more – https://en.wikipedia.org/wiki/SHA-1

Code

 

#include "Hash.h"
 
void setup()
{
Serial.begin(115200);
 
String result = sha1("testing sha1");
 
Serial.println();
Serial.print(result);
 
}
 
void loop() {}

 

Output

I saw the following in the serial monitor

47d4387d5b2dcf196e295d48219b2c535c023eea

LEAVE A REPLY

Please enter your comment!
Please enter your name here

*