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

Output

1
H#
2
HASH_03 example
3
- SHA-224 algorithm
4
- Message Digest length of 224 bits (28 Bytes)
5
6
Original message: Libelium
7
SHA-224:"29A0CCCB235730C96348B029A7E97F088DFBC3C47EB1D45F1B8CACEC"
8
SHA-224:"29A0CCCB235730C96348B029A7E97F088DFBC3C47EB1D45F1B8CACEC"
Copied!
Last modified 1yr ago