New internal functions _aes_set_key and _aes_invert.
[gd/nettle] / aes-set-decrypt-key.c
1 /* aes-set-decrypt-key.c
2  *
3  * Inverse key setup for the aes/rijndael block cipher.
4  */
5
6 /* nettle, low-level cryptographics library
7  *
8  * Copyright (C) 2000, 2001, 2002 Rafael R. Sevilla, Niels Möller
9  * Copyright (C) 2013 Niels Möller
10  *  
11  * The nettle library is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation; either version 2.1 of the License, or (at your
14  * option) any later version.
15  * 
16  * The nettle library is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
19  * License for more details.
20  * 
21  * You should have received a copy of the GNU Lesser General Public License
22  * along with the nettle library; see the file COPYING.LIB.  If not, write to
23  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24  * MA 02111-1301, USA.
25  */
26
27 /* Originally written by Rafael R. Sevilla <dido@pacific.net.ph> */
28
29 #if HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include "aes-internal.h"
34
35 void
36 aes_invert_key(struct aes_ctx *dst,
37                const struct aes_ctx *src)
38 {
39   _aes_invert (src->rounds, dst->keys, src->keys);
40   dst->rounds = src->rounds;
41 }
42
43 void
44 aes_set_decrypt_key(struct aes_ctx *ctx,
45                     size_t keysize, const uint8_t *key)
46 {
47   /* We first create subkeys for encryption,
48    * then modify the subkeys for decryption. */
49   aes_set_encrypt_key(ctx, keysize, key);
50   aes_invert_key(ctx, ctx);
51 }
52