OpenZWave Library  1.4.3493
aescpp.h
Go to the documentation of this file.
1 /*
2 ---------------------------------------------------------------------------
3 Copyright (c) 1998-2013, Brian Gladman, Worcester, UK. All rights reserved.
4 
5 The redistribution and use of this software (with or without changes)
6 is allowed without the payment of fees or royalties provided that:
7 
8  source code distributions include the above copyright notice, this
9  list of conditions and the following disclaimer;
10 
11  binary distributions include the above copyright notice, this list
12  of conditions and the following disclaimer in their documentation.
13 
14 This software is provided 'as is' with no explicit or implied warranties
15 in respect of its operation, including, but not limited to, correctness
16 and fitness for purpose.
17 ---------------------------------------------------------------------------
18 Issue Date: 20/12/2007
19 
20  This file contains the definitions required to use AES (Rijndael) in C++.
21 */
22 
23 #ifndef _AESCPP_H
24 #define _AESCPP_H
25 
26 #include "aes.h"
27 
28 #if defined( AES_ENCRYPT )
29 
31 {
32 public:
34  AESencrypt(void) { aes_init(); };
35 #if defined(AES_128)
36  AESencrypt(const unsigned char key[])
38  AES_RETURN key128(const unsigned char key[])
39  { return aes_encrypt_key128(key, cx); }
40 #endif
41 #if defined(AES_192)
42  AES_RETURN key192(const unsigned char key[])
43  { return aes_encrypt_key192(key, cx); }
44 #endif
45 #if defined(AES_256)
46  AES_RETURN key256(const unsigned char key[])
47  { return aes_encrypt_key256(key, cx); }
48 #endif
49 #if defined(AES_VAR)
50  AES_RETURN key(const unsigned char key[], int key_len)
51  { return aes_encrypt_key(key, key_len, cx); }
52 #endif
53  AES_RETURN encrypt(const unsigned char in[], unsigned char out[]) const
54  { return aes_encrypt(in, out, cx); }
55 #ifndef AES_MODES
56  AES_RETURN ecb_encrypt(const unsigned char in[], unsigned char out[], int nb) const
57  { while(nb--)
58  { aes_encrypt(in, out, cx), in += AES_BLOCK_SIZE, out += AES_BLOCK_SIZE; }
59  }
60 #endif
61 #ifdef AES_MODES
63 
64  AES_RETURN ecb_encrypt(const unsigned char in[], unsigned char out[], int nb) const
65  { return aes_ecb_encrypt(in, out, nb, cx); }
66 
67  AES_RETURN cbc_encrypt(const unsigned char in[], unsigned char out[], int nb,
68  unsigned char iv[]) const
69  { return aes_cbc_encrypt(in, out, nb, iv, cx); }
70 
71  AES_RETURN cfb_encrypt(const unsigned char in[], unsigned char out[], int nb,
72  unsigned char iv[])
73  { return aes_cfb_encrypt(in, out, nb, iv, cx); }
74 
75  AES_RETURN cfb_decrypt(const unsigned char in[], unsigned char out[], int nb,
76  unsigned char iv[])
77  { return aes_cfb_decrypt(in, out, nb, iv, cx); }
78 
79  AES_RETURN ofb_crypt(const unsigned char in[], unsigned char out[], int nb,
80  unsigned char iv[])
81  { return aes_ofb_crypt(in, out, nb, iv, cx); }
82 
83  typedef void ctr_fn(unsigned char ctr[]);
84 
85  AES_RETURN ctr_crypt(const unsigned char in[], unsigned char out[], int nb,
86  unsigned char iv[], ctr_fn cf)
87  { return aes_ctr_crypt(in, out, nb, iv, cf, cx); }
88 
89 #endif
90 
91 };
92 
93 #endif
94 
95 #if defined( AES_DECRYPT )
96 
98 {
99 public:
101  AESdecrypt(void) { aes_init(); };
102 #if defined(AES_128)
103  AESdecrypt(const unsigned char key[])
104  { aes_decrypt_key128(key, cx); }
105  AES_RETURN key128(const unsigned char key[])
106  { return aes_decrypt_key128(key, cx); }
107 #endif
108 #if defined(AES_192)
109  AES_RETURN key192(const unsigned char key[])
110  { return aes_decrypt_key192(key, cx); }
111 #endif
112 #if defined(AES_256)
113  AES_RETURN key256(const unsigned char key[])
114  { return aes_decrypt_key256(key, cx); }
115 #endif
116 #if defined(AES_VAR)
117  AES_RETURN key(const unsigned char key[], int key_len)
118  { return aes_decrypt_key(key, key_len, cx); }
119 #endif
120  AES_RETURN decrypt(const unsigned char in[], unsigned char out[]) const
121  { return aes_decrypt(in, out, cx); }
122 #ifndef AES_MODES
123  AES_RETURN ecb_decrypt(const unsigned char in[], unsigned char out[], int nb) const
124  { while(nb--)
125  { aes_decrypt(in, out, cx), in += AES_BLOCK_SIZE, out += AES_BLOCK_SIZE; }
126  }
127 #endif
128 #ifdef AES_MODES
129 
130  AES_RETURN ecb_decrypt(const unsigned char in[], unsigned char out[], int nb) const
131  { return aes_ecb_decrypt(in, out, nb, cx); }
132 
133  AES_RETURN cbc_decrypt(const unsigned char in[], unsigned char out[], int nb,
134  unsigned char iv[]) const
135  { return aes_cbc_decrypt(in, out, nb, iv, cx); }
136 #endif
137 };
138 
139 #endif
140 
141 #endif
AES_RETURN aes_ecb_decrypt(const unsigned char *ibuf, unsigned char *obuf, int len, const aes_decrypt_ctx cx[1])
Definition: aes_modes.c:199
Definition: aescpp.h:97
AES_RETURN aes_ofb_crypt(const unsigned char *ibuf, unsigned char *obuf, int len, unsigned char *iv, aes_encrypt_ctx cx[1])
Definition: aes_modes.c:723
AES_RETURN key256(const unsigned char key[])
Definition: aescpp.h:46
AES_RETURN ofb_crypt(const unsigned char in[], unsigned char out[], int nb, unsigned char iv[])
Definition: aescpp.h:79
AES_RETURN key(const unsigned char key[], int key_len)
Definition: aescpp.h:50
AESencrypt(void)
Definition: aescpp.h:34
AES_RETURN cbc_encrypt(const unsigned char in[], unsigned char out[], int nb, unsigned char iv[]) const
Definition: aescpp.h:67
AES_RETURN aes_encrypt_key192(const unsigned char *key, aes_encrypt_ctx cx[1])
Definition: aes.h:90
AES_RETURN decrypt(const unsigned char in[], unsigned char out[]) const
Definition: aescpp.h:120
AES_RETURN ecb_decrypt(const unsigned char in[], unsigned char out[], int nb) const
Definition: aescpp.h:130
AES_RETURN key192(const unsigned char key[])
Definition: aescpp.h:42
AES_RETURN aes_cbc_decrypt(const unsigned char *ibuf, unsigned char *obuf, int len, unsigned char *iv, const aes_decrypt_ctx cx[1])
Definition: aes_modes.c:358
void ctr_fn(unsigned char ctr[])
Definition: aescpp.h:83
AES_RETURN cfb_encrypt(const unsigned char in[], unsigned char out[], int nb, unsigned char iv[])
Definition: aescpp.h:71
AES_RETURN aes_decrypt(const unsigned char *in, unsigned char *out, const aes_decrypt_ctx cx[1])
aes_decrypt_ctx cx[1]
Definition: aescpp.h:100
AES_RETURN aes_decrypt_key256(const unsigned char *key, aes_decrypt_ctx cx[1])
AES_RETURN aes_encrypt(const unsigned char *in, unsigned char *out, const aes_encrypt_ctx cx[1])
Definition: aescpp.h:30
AESdecrypt(void)
Definition: aescpp.h:101
AES_RETURN aes_mode_reset(aes_encrypt_ctx cx[1])
Definition: aes_modes.c:131
AES_RETURN ctr_crypt(const unsigned char in[], unsigned char out[], int nb, unsigned char iv[], ctr_fn cf)
Definition: aescpp.h:85
AES_RETURN aes_ctr_crypt(const unsigned char *ibuf, unsigned char *obuf, int len, unsigned char *cbuf, cbuf_inc ctr_inc, aes_encrypt_ctx cx[1])
Definition: aes_modes.c:850
AES_RETURN aes_encrypt_key256(const unsigned char *key, aes_encrypt_ctx cx[1])
AES_RETURN key(const unsigned char key[], int key_len)
Definition: aescpp.h:117
AES_RETURN aes_cfb_encrypt(const unsigned char *ibuf, unsigned char *obuf, int len, unsigned char *iv, aes_encrypt_ctx cx[1])
Definition: aes_modes.c:457
AES_RETURN aes_encrypt_key(const unsigned char *key, int key_len, aes_encrypt_ctx cx[1])
Definition: aeskey.c:528
AES_RETURN encrypt(const unsigned char in[], unsigned char out[]) const
Definition: aescpp.h:53
AES_RETURN aes_init(void)
Definition: aestab.c:187
AES_RETURN aes_cfb_decrypt(const unsigned char *ibuf, unsigned char *obuf, int len, unsigned char *iv, aes_encrypt_ctx cx[1])
Definition: aes_modes.c:582
AESencrypt(const unsigned char key[])
Definition: aescpp.h:36
AESdecrypt(const unsigned char key[])
Definition: aescpp.h:103
aes_encrypt_ctx cx[1]
Definition: aescpp.h:33
#define AES_BLOCK_SIZE
Definition: aes.h:48
#define AES_RETURN
Definition: aes.h:63
AES_RETURN ecb_encrypt(const unsigned char in[], unsigned char out[], int nb) const
Definition: aescpp.h:64
AES_RETURN aes_ecb_encrypt(const unsigned char *ibuf, unsigned char *obuf, int len, const aes_encrypt_ctx cx[1])
Definition: aes_modes.c:137
Definition: aes.h:82
AES_RETURN key256(const unsigned char key[])
Definition: aescpp.h:113
AES_RETURN key128(const unsigned char key[])
Definition: aescpp.h:105
AES_RETURN key128(const unsigned char key[])
Definition: aescpp.h:38
AES_RETURN key192(const unsigned char key[])
Definition: aescpp.h:109
AES_RETURN aes_cbc_encrypt(const unsigned char *ibuf, unsigned char *obuf, int len, unsigned char *iv, const aes_encrypt_ctx cx[1])
Definition: aes_modes.c:261
AES_RETURN cfb_decrypt(const unsigned char in[], unsigned char out[], int nb, unsigned char iv[])
Definition: aescpp.h:75
AES_RETURN aes_decrypt_key192(const unsigned char *key, aes_decrypt_ctx cx[1])
AES_RETURN cbc_decrypt(const unsigned char in[], unsigned char out[], int nb, unsigned char iv[]) const
Definition: aescpp.h:133
AES_RETURN mode_reset(void)
Definition: aescpp.h:62
AES_RETURN aes_decrypt_key(const unsigned char *key, int key_len, aes_decrypt_ctx cx[1])
Definition: aeskey.c:539
AES_RETURN aes_decrypt_key128(const unsigned char *key, aes_decrypt_ctx cx[1])
AES_RETURN aes_encrypt_key128(const unsigned char *key, aes_encrypt_ctx cx[1])