HASH 02: SHA-1
This example shows how to calculate SHA-1 message digest to provide INTEGRITY to the sending of information. Both data must be sent over the network: MESSAGE + HASH_MESSAGE

Required Materials

1 x Waspmote 1 x Battery

Notes

- The battery has to be connected. - This example can be executed in Waspmote v12 and Waspmote v15

Code

1
/*
2
* ------Waspmote HASH_02 SHA-1 Message Digest--------
3
*
4
* This example shows how to calculate SHA-1 message digest to
5
* provide INTEGRITY to the sending of information. Both data
6
* must be sent over the network: MESSAGE + HASH_MESSAGE
7
*
8
* Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
9
* http://www.libelium.com
10
*
11
* This program is free software: you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation, either version 2 of the License, or
14
* (at your option) any later version.
15
*
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
20
*
21
* You should have received a copy of the GNU General Public License
22
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
*
24
* Version: 3.0
25
* Design: David Gascón
26
* Implementation: Alvaro Gonzalez, Yuri Carmona
27
*/
28
29
#include "WaspHash.h"
30
31
// Original message
32
char message[] = "Libelium";
33
34
// Variable to store the hash message
35
uint8_t hash_message_sha1[20];
36
37
38
void setup()
39
{
40
USB.ON();
41
USB.println(F("HASH_02 example"));
42
USB.println(F("- SHA-1 algorithm"));
43
USB.println(F("- Message Digest length of 160 bits (20 Bytes)"));
44
USB.println();
45
46
USB.print(F("Original message: "));
47
USB.println(message);
48
49
}
50
51
void loop()
52
{
53
// Calculate hash of original message with SHA-1 Algorithm
54
HASH.sha( SHA1, hash_message_sha1, (uint8_t*)message, strlen(message)*8);
55
56
// Printing message digest SHA-1
57
HASH.printMessageDigest("SHA-1:", hash_message_sha1 , 20);
58
59
delay(5000);
60
}
Copied!

Output

1
H#
2
HASH_02 example
3
- SHA-1 algorithm
4
- Message Digest length of 160 bits (20 Bytes)
5
6
Original message: Libelium
7
SHA-1:"FC5BD095ECE2F96744C0C301C7F2D344E516B6B3"
8
SHA-1:"FC5BD095ECE2F96744C0C301C7F2D344E516B6B3"
Copied!
Last modified 1yr ago