MySensors Library & Examples  2.3.2-62-ge298769
AES.h
1 #ifndef __AES_H__
2 #define __AES_H__
3 
4 #include "AES_config.h"
5 /*
6  ---------------------------------------------------------------------------
7  Copyright (c) 1998-2008, Brian Gladman, Worcester, UK. All rights reserved.
8 
9  LICENSE TERMS
10 
11  The redistribution and use of this software (with or without changes)
12  is allowed without the payment of fees or royalties provided that:
13 
14  1. source code distributions include the above copyright notice, this
15  list of conditions and the following disclaimer;
16 
17  2. binary distributions include the above copyright notice, this list
18  of conditions and the following disclaimer in their documentation;
19 
20  3. the name of the copyright holder is not used to endorse products
21  built using this software without specific written permission.
22 
23  DISCLAIMER
24 
25  This software is provided 'as is' with no explicit or implied warranties
26  in respect of its properties, including, but not limited to, correctness
27  and/or fitness for purpose.
28  ---------------------------------------------------------------------------
29  Issue 09/09/2006
30 
31  This is an AES implementation that uses only 8-bit byte operations on the
32  cipher state.
33  */
34 
35 /* code was modified by george spanos <[email protected]>
36 * 16/12/14
37 */
39 class AES
40 {
41 public:
42 
43  /* The following calls are for a precomputed key schedule
44 
45  NOTE: If the length_type used for the key length is an
46  unsigned 8-bit character, a key length of 256 bits must
47  be entered as a length in bytes (valid inputs are hence
48  128, 192, 16, 24 and 32).
49  */
55  AES();
56 
65  byte set_key (byte key[], int keylen) ;
66 
70  void clean () ; // delete key schedule after use
71 
80  void copy_n_bytes (byte * AESt, byte * src, byte n) ;
81 
94  byte encrypt (byte plain [N_BLOCK], byte cipher [N_BLOCK]) ;
95 
105  byte cbc_encrypt (byte * plain, byte * cipher, int n_block, byte iv [N_BLOCK]) ;
106 
115  byte cbc_encrypt (byte * plain, byte * cipher, int n_block) ;
116 
117 
130  byte decrypt (byte cipher [N_BLOCK], byte plain [N_BLOCK]) ;
131 
141  byte cbc_decrypt (byte * cipher, byte * plain, int n_block, byte iv [N_BLOCK]) ;
142 
151  byte cbc_decrypt (byte * cipher, byte * plain, int n_block) ;
152 
160  void set_IV(unsigned long long int IVCl);
161 
167  void iv_inc();
168 
175  int get_size();
176 
182  void set_size(int sizel);
183 
190  void get_IV(byte *out);
191 
199  void calc_size_n_pad(int p_size);
200 
211  void padPlaintext(void* in,byte* out);
212 
221  bool CheckPad(byte* in,int size);
222 
231  void printArray(byte output[],bool p_pad = true);
232 
240  void printArray(byte output[],int sizel);
241 
252  void do_aes_encrypt(byte *plain,int size_p,byte *cipher,byte *key, int bits, byte ivl [N_BLOCK]);
253 
263  void do_aes_encrypt(byte *plain,int size_p,byte *cipher,byte *key, int bits);
264 
275  void do_aes_decrypt(byte *cipher,int size_c,byte *plain,byte *key, int bits, byte ivl [N_BLOCK]);
276 
286  void do_aes_decrypt(byte *cipher,int size_c,byte *plain,byte *key, int bits);
287 
288 #if defined(AES_LINUX)
289 
294  double millis();
295 #endif
296 private:
297  int round ;
298  byte key_sched [KEY_SCHEDULE_BYTES]
299  ;
300  unsigned long long int IVC;
301  byte iv[16];
302  int pad;
303  int size;
304 #if defined(AES_LINUX)
305  timeval tv;
306  byte arr_pad[15];
307 #else
308  byte arr_pad[15];// = { 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f };/**< holds the hexadecimal padding values */
309 #endif
310 } ;
311 
312 
313 #endif
314 
AES::decrypt
byte decrypt(byte cipher[N_BLOCK], byte plain[N_BLOCK])
AES::cbc_decrypt
byte cbc_decrypt(byte *cipher, byte *plain, int n_block, byte iv[N_BLOCK])
AES
Definition: AES.h:39
AES::copy_n_bytes
void copy_n_bytes(byte *AESt, byte *src, byte n)
AES::set_IV
void set_IV(unsigned long long int IVCl)
AES::clean
void clean()
AES::do_aes_encrypt
void do_aes_encrypt(byte *plain, int size_p, byte *cipher, byte *key, int bits, byte ivl[N_BLOCK])
AES::set_key
byte set_key(byte key[], int keylen)
AES::get_IV
void get_IV(byte *out)
AES::set_size
void set_size(int sizel)
AES::CheckPad
bool CheckPad(byte *in, int size)
AES::cbc_encrypt
byte cbc_encrypt(byte *plain, byte *cipher, int n_block, byte iv[N_BLOCK])
AES::AES
AES()
AES constructor.
AES::iv_inc
void iv_inc()
AES::do_aes_decrypt
void do_aes_decrypt(byte *cipher, int size_c, byte *plain, byte *key, int bits, byte ivl[N_BLOCK])
AES::padPlaintext
void padPlaintext(void *in, byte *out)
AES::calc_size_n_pad
void calc_size_n_pad(int p_size)
AES::encrypt
byte encrypt(byte plain[N_BLOCK], byte cipher[N_BLOCK])
AES::get_size
int get_size()
AES::printArray
void printArray(byte output[], bool p_pad=true)