Yen Lin | 5b1a545 | 2012-04-05 11:54:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The Chromium OS Authors. |
| 3 | * (C) Copyright 2010 - 2011 NVIDIA Corporation <www.nvidia.com> |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #ifndef _AES_REF_H_ |
| 25 | #define _AES_REF_H_ |
| 26 | |
| 27 | /* |
| 28 | * AES encryption library, with small code size, supporting only 128-bit AES |
| 29 | * |
| 30 | * AES is a stream cipher which works a block at a time, with each block |
| 31 | * in this case being AES_KEY_LENGTH bytes. |
| 32 | */ |
| 33 | |
| 34 | enum { |
| 35 | AES_STATECOLS = 4, /* columns in the state & expanded key */ |
| 36 | AES_KEYCOLS = 4, /* columns in a key */ |
| 37 | AES_ROUNDS = 10, /* rounds in encryption */ |
| 38 | |
| 39 | AES_KEY_LENGTH = 128 / 8, |
| 40 | AES_EXPAND_KEY_LENGTH = 4 * AES_STATECOLS * (AES_ROUNDS + 1), |
| 41 | }; |
| 42 | |
| 43 | /** |
| 44 | * Expand a key into a key schedule, which is then used for the other |
| 45 | * operations. |
| 46 | * |
| 47 | * \param key Key, of length AES_KEY_LENGTH bytes |
| 48 | * \param expkey Buffer to place expanded key, AES_EXPAND_KEY_LENGTH |
| 49 | */ |
| 50 | void aes_expand_key(u8 *key, u8 *expkey); |
| 51 | |
| 52 | /** |
| 53 | * Encrypt a single block of data |
| 54 | * |
| 55 | * in Input data |
| 56 | * expkey Expanded key to use for encryption (from aes_expand_key()) |
| 57 | * out Output data |
| 58 | */ |
| 59 | void aes_encrypt(u8 *in, u8 *expkey, u8 *out); |
| 60 | |
| 61 | /** |
| 62 | * Decrypt a single block of data |
| 63 | * |
| 64 | * in Input data |
| 65 | * expkey Expanded key to use for decryption (from aes_expand_key()) |
| 66 | * out Output data |
| 67 | */ |
| 68 | void aes_decrypt(u8 *in, u8 *expkey, u8 *out); |
| 69 | |
| 70 | #endif /* _AES_REF_H_ */ |