chiark / gitweb /
resolver: construct comm_addr; honour multiple addresses from the resolver
[secnet.git] / aes.h
1 /*
2   * aes.h
3   *
4   * Header file declaring AES functions.
5   *
6   * Copied from the upstream qemu git tree revision
7   *   55616505876d6683130076b810a27c7889321560
8   * but was introduced there by Fabrice Bellard in
9   *   e4d4fe3c34cdd6e26f9b9975efec7d1e81ad00b6
10   *   AES crypto support
11   *   git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1036 \
12   *     c046a42c-6fe2-441c-8c8c-71466251a162
13   *
14   * Modified by Ian Jackson to change the guard #define from
15   * QEMU_AES_H to AES_H and to add some needed system #include's.
16   *
17   * The header file doesn't appear to have a separate copyright notice
18   * but is clearly a lightly edited (by Bellard) version of code from
19   * Rijmen, Bosselaers and Barreto.
20   *
21   * The original is from rijndael-alg-fst.c, with this copyright
22   * notice:
23   *
24   *   rijndael-alg-fst.c
25   *   
26   *   @version 3.0 (December 2000)
27   *   
28   *   Optimised ANSI C code for the Rijndael cipher (now AES)
29   *   
30   *   @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
31   *   @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
32   *   @author Paulo Barreto <paulo.barreto@terra.com.br>
33   *   
34   *   This code is hereby placed in the public domain.
35   *   
36   *   THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
37   *   OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
38   *   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39   *   ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
40   *   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
41   *   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
42   *   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43   *   BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44   *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
45   *   OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
46   *   EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47   *
48   */
49
50 #ifndef AES_H
51 #define AES_H
52
53 #include <stdint.h>
54 #include <assert.h>
55 #include <string.h>
56
57 #define AES_MAXNR 14
58 #define AES_BLOCK_SIZE 16
59
60 struct aes_key_st {
61     uint32_t rd_key[4 *(AES_MAXNR + 1)];
62     int rounds;
63 };
64 typedef struct aes_key_st AES_KEY;
65
66 int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
67         AES_KEY *key);
68 int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
69         AES_KEY *key);
70
71 void AES_encrypt(const unsigned char *in, unsigned char *out,
72         const AES_KEY *key);
73 void AES_decrypt(const unsigned char *in, unsigned char *out,
74         const AES_KEY *key);
75 void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
76                      const unsigned long length, const AES_KEY *key,
77                      unsigned char *ivec, const int enc);
78
79 #endif /* AES_H */