| 1 | /* |
| 2 | * aes.h - Header file declaring AES functions. |
| 3 | */ |
| 4 | /* |
| 5 | * This file is Free Software. It has been modified to as part of its |
| 6 | * incorporation into secnet. |
| 7 | * |
| 8 | * Copyright 2000 Vincent Rijmen, Antoon Bosselaers, Paulo Barreto |
| 9 | * Copyright 2004 Fabrice Bellard |
| 10 | * Copyright 2013 Ian Jackson |
| 11 | * |
| 12 | * You may redistribute this file and/or modify it under the terms of |
| 13 | * the permissive licence shown below. |
| 14 | * |
| 15 | * You may redistribute secnet as a whole and/or modify it under the |
| 16 | * terms of the GNU General Public License as published by the Free |
| 17 | * Software Foundation; either version 3, or (at your option) any |
| 18 | * later version. |
| 19 | * |
| 20 | * This program is distributed in the hope that it will be useful, |
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | * GNU General Public License for more details. |
| 24 | * |
| 25 | * You should have received a copy of the GNU General Public License |
| 26 | * along with this program; if not, see |
| 27 | * https://www.gnu.org/licenses/gpl.html. |
| 28 | */ |
| 29 | /* |
| 30 | * Copied from the upstream qemu git tree revision |
| 31 | * 55616505876d6683130076b810a27c7889321560 |
| 32 | * but was introduced there by Fabrice Bellard in |
| 33 | * e4d4fe3c34cdd6e26f9b9975efec7d1e81ad00b6 |
| 34 | * AES crypto support |
| 35 | * git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1036 \ |
| 36 | * c046a42c-6fe2-441c-8c8c-71466251a162 |
| 37 | * |
| 38 | * Modified by Ian Jackson to change the guard #define from |
| 39 | * QEMU_AES_H to AES_H and to add some needed system #include's. |
| 40 | * |
| 41 | * The header file doesn't appear to have a separate copyright notice |
| 42 | * but is clearly a lightly edited (by Bellard) version of code from |
| 43 | * Rijmen, Bosselaers and Barreto. |
| 44 | * |
| 45 | * The original is from rijndael-alg-fst.c, with this copyright |
| 46 | * notice: |
| 47 | * |
| 48 | * rijndael-alg-fst.c |
| 49 | * |
| 50 | * @version 3.0 (December 2000) |
| 51 | * |
| 52 | * Optimised ANSI C code for the Rijndael cipher (now AES) |
| 53 | * |
| 54 | * @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be> |
| 55 | * @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be> |
| 56 | * @author Paulo Barreto <paulo.barreto@terra.com.br> |
| 57 | * |
| 58 | * This code is hereby placed in the public domain. |
| 59 | * |
| 60 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS |
| 61 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 62 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 63 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE |
| 64 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 65 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 66 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 67 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 68 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 69 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 70 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 71 | * |
| 72 | */ |
| 73 | |
| 74 | #ifndef AES_H |
| 75 | #define AES_H |
| 76 | |
| 77 | #include <stdint.h> |
| 78 | #include <assert.h> |
| 79 | #include <string.h> |
| 80 | |
| 81 | #define AES_MAXNR 14 |
| 82 | #define AES_BLOCK_SIZE 16 |
| 83 | |
| 84 | struct aes_key_st { |
| 85 | uint32_t rd_key[4 *(AES_MAXNR + 1)]; |
| 86 | int rounds; |
| 87 | }; |
| 88 | typedef struct aes_key_st AES_KEY; |
| 89 | |
| 90 | int AES_set_encrypt_key(const unsigned char *userKey, const int bits, |
| 91 | AES_KEY *key); |
| 92 | int AES_set_decrypt_key(const unsigned char *userKey, const int bits, |
| 93 | AES_KEY *key); |
| 94 | |
| 95 | void AES_encrypt(const unsigned char *in, unsigned char *out, |
| 96 | const AES_KEY *key); |
| 97 | void AES_decrypt(const unsigned char *in, unsigned char *out, |
| 98 | const AES_KEY *key); |
| 99 | void AES_cbc_encrypt(const unsigned char *in, unsigned char *out, |
| 100 | const unsigned long length, const AES_KEY *key, |
| 101 | unsigned char *ivec, const int enc); |
| 102 | |
| 103 | #endif /* AES_H */ |