AES 05: AES 192, CBC, ZEROS
This example shows how to encrypt plain text using: - AES algorithm - 192-bit key size - ZEROS Padding - CBC Cipher Mode

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 AES_05 Encryption 128 CBC ZEROS --------
3
*
4
* This example shows how to encrypt plain text using:
5
* - AES algorithm
6
* - 192-bit key size
7
* - ZEROS Padding
8
* - CBC Cipher Mode
9
*
10
* Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
11
* http://www.libelium.com
12
*
13
* This program is free software: you can redistribute it and/or modify
14
* it under the terms of the GNU General Public License as published by
15
* the Free Software Foundation, either version 2 of the License, or
16
* (at your option) any later version.
17
*
18
* This program is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
22
*
23
* You should have received a copy of the GNU General Public License
24
* along with this program. If not, see <http://www.gnu.org/licenses/>.
25
*
26
* Version: 3.0
27
* Design: David Gascón
28
* Implementation: Alvaro Gonzalez, Yuri Carmona
29
*/
30
31
#include "WaspAES.h"
32
33
// Define a 24-Byte (AES-192) private key to encrypt message
34
char password[] = "libeliumlibeliumlibelium";
35
36
// original message on which the algorithm will be applied
37
char message[] = "This_is_a_message";
38
39
// Define Initial Vector
40
uint8_t IV[16] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F};
41
42
// Variable for encrypted message's length
43
uint16_t encrypted_length;
44
45
// Declaration of variable encrypted message
46
uint8_t encrypted_message[300];
47
48
49
void setup()
50
{
51
// init USB port
52
USB.ON();
53
USB.println(F("AES_05 example:"));
54
USB.println(F("- 192-bit Key Size"));
55
USB.println(F("- CBC Cipher Mode"));
56
USB.println(F("- ZEROS padding"));
57
USB.println();
58
59
USB.print(F("\nOriginal message:"));
60
USB.println(message);
61
62
USB.print(F("Original length:"));
63
USB.println((int)strlen(message));
64
USB.println();
65
66
}
67
68
void loop()
69
{
70
////////////////////////////////////////////////////////////////
71
// 1. Encrypt message
72
////////////////////////////////////////////////////////////////
73
USB.println(F("1. Encrypt message"));
74
75
// 1.1. Calculate length in Bytes of the encrypted message
76
encrypted_length = AES.sizeOfBlocks(message);
77
78
// 1.2. Calculate encrypted message with CBC cipher mode and ZEROS padding.
79
AES.encrypt( AES_192
80
, password
81
, message
82
, encrypted_message
83
, CBC
84
, ZEROS
85
, IV);
86
87
88
// 1.3. Printing encrypted message
89
USB.print(F("AES Encrypted message:"));
90
AES.printMessage( encrypted_message, encrypted_length);
91
92
// 1.4. Printing encrypted message's length
93
USB.print(F("AES Encrypted length:"));
94
USB.println( (int)encrypted_length);
95
USB.println();
96
97
delay(5000);
98
USB.println(F("***********************"));
99
100
}
Copied!

Output

1
H#
2
AES_05 example:
3
- 192-bit Key Size
4
- CBC Cipher Mode
5
- ZEROS padding
6
7
Original message:This_is_a_message
8
Original length:17
9
10
1. Encrypt message
11
AES Encrypted message: "DA0E39CC0C7A3E280984B57ED23C77025EFB6BB15E88243B8A4E8275C56E7530"
12
AES Encrypted length:32
13
14
***********************
15
1. Encrypt message
16
AES Encrypted message: "DA0E39CC0C7A3E280984B57ED23C77025EFB6BB15E88243B8A4E8275C56E7530"
17
AES Encrypted length:32
18
19
***********************
20
1. Encrypt message
21
AES Encrypted message: "DA0E39CC0C7A3E280984B57ED23C77025EFB6BB15E88243B8A4E8275C56E7530"
22
AES Encrypted length:32
23
24
***********************
25
1. Encrypt message
26
AES Encrypted message: "DA0E39CC0C7A3E280984B57ED23C77025EFB6BB15E88243B8A4E8275C56E7530"
27
AES Encrypted length:32
Copied!
Last modified 1yr ago