Yen Lin | 2f87903 | 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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Yen Lin | 2f87903 | 2012-04-05 11:54:58 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef _AES_REF_H_ |
| 9 | #define _AES_REF_H_ |
| 10 | |
| 11 | /* |
| 12 | * AES encryption library, with small code size, supporting only 128-bit AES |
| 13 | * |
| 14 | * AES is a stream cipher which works a block at a time, with each block |
| 15 | * in this case being AES_KEY_LENGTH bytes. |
| 16 | */ |
| 17 | |
| 18 | enum { |
| 19 | AES_STATECOLS = 4, /* columns in the state & expanded key */ |
| 20 | AES_KEYCOLS = 4, /* columns in a key */ |
| 21 | AES_ROUNDS = 10, /* rounds in encryption */ |
| 22 | |
| 23 | AES_KEY_LENGTH = 128 / 8, |
| 24 | AES_EXPAND_KEY_LENGTH = 4 * AES_STATECOLS * (AES_ROUNDS + 1), |
| 25 | }; |
| 26 | |
| 27 | /** |
| 28 | * Expand a key into a key schedule, which is then used for the other |
| 29 | * operations. |
| 30 | * |
| 31 | * \param key Key, of length AES_KEY_LENGTH bytes |
| 32 | * \param expkey Buffer to place expanded key, AES_EXPAND_KEY_LENGTH |
| 33 | */ |
| 34 | void aes_expand_key(u8 *key, u8 *expkey); |
| 35 | |
| 36 | /** |
| 37 | * Encrypt a single block of data |
| 38 | * |
| 39 | * in Input data |
| 40 | * expkey Expanded key to use for encryption (from aes_expand_key()) |
| 41 | * out Output data |
| 42 | */ |
| 43 | void aes_encrypt(u8 *in, u8 *expkey, u8 *out); |
| 44 | |
| 45 | /** |
| 46 | * Decrypt a single block of data |
| 47 | * |
| 48 | * in Input data |
| 49 | * expkey Expanded key to use for decryption (from aes_expand_key()) |
| 50 | * out Output data |
| 51 | */ |
| 52 | void aes_decrypt(u8 *in, u8 *expkey, u8 *out); |
| 53 | |
| 54 | #endif /* _AES_REF_H_ */ |