HASH 06: SHA-512
This example shows how calculate message digest with SHA-512 Algorithm

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_06 SHA-512 Message Digest--------
3
*
4
* This example shows how to calculate SHA-512 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_sha512[62];
36
37
38
void setup()
39
{
40
USB.ON();
41
USB.println(F("HASH_06 example"));
42
USB.println(F("- SHA-512 algorithm"));
43
USB.println(F("- Message Digest length of 512 bits (62 Bytes)"));
44
USB.println();
45
46
USB.print(F("Original message: "));
47
USB.println(message);
48
}
49
50
void loop()
51
{
52
// Calculate hash of original message with MD5 Algorithm
53
HASH.sha( SHA512, hash_message_sha512, (uint8_t*)message, strlen(message)*8);
54
55
// Printing message digest SHA-512
56
HASH.printMessageDigest("SHA-512:", hash_message_sha512, 62);
57
58
delay(5000);
59
}
60
61
Copied!

Output

1
H#
2
HASH_06 example
3
- SHA-512 algorithm
4
- Message Digest length of 512 bits (62 Bytes)
5
6
Original message: Libelium
7
SHA-512:"9801DC63FFE5113E3E1665E1193B515BACA00A51C197BA618A5E20A03A9124E79B5884C6AD38FB9D101385C63102A65CC69B03EE125DBE88A77B381A4996"
Copied!
Last modified 1yr ago