Rizin
unix-like reverse engineering framework and cli tools
aes-set-decrypt-key.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2000, 2001, 2002 Rafael R. Sevilla, Niels Möller
2 // SPDX-FileCopyrightText: 2013 Niels Möller
3 // SPDX-License-Identifier: LGPL-3.0-only
4 
5 /* aes-set-decrypt-key.c
6 
7  Inverse key setup for the aes/rijndael block cipher.
8 
9  Copyright (C) 2000, 2001, 2002 Rafael R. Sevilla, Niels Möller
10  Copyright (C) 2013 Niels Möller
11 
12  This file is part of GNU Nettle.
13 
14  GNU Nettle is free software: you can redistribute it and/or
15  modify it under the terms of either:
16 
17  * the GNU Lesser General Public License as published by the Free
18  Software Foundation; either version 3 of the License, or (at your
19  option) any later version.
20 
21  or
22 
23  * the GNU General Public License as published by the Free
24  Software Foundation; either version 2 of the License, or (at your
25  option) any later version.
26 
27  or both in parallel, as here.
28 
29  GNU Nettle is distributed in the hope that it will be useful,
30  but WITHOUT ANY WARRANTY; without even the implied warranty of
31  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32  General Public License for more details.
33 
34  You should have received copies of the GNU General Public License and
35  the GNU Lesser General Public License along with this program. If
36  not, see http://www.gnu.org/licenses/.
37 */
38 
39 #if HAVE_CONFIG_H
40 # include "config.h"
41 #endif
42 
43 #include <stdlib.h>
44 
45 /* This file implements and uses deprecated functions */
46 #define _NETTLE_ATTRIBUTE_DEPRECATED
47 
48 #include "aes.h"
49 
50 void
52  const struct aes_ctx *src)
53 {
54  switch (src->key_size)
55  {
56  default: abort();
57  case AES128_KEY_SIZE:
58  aes128_invert_key(&dst->u.ctx128, &src->u.ctx128);
59  break;
60  case AES192_KEY_SIZE:
61  aes192_invert_key(&dst->u.ctx192, &src->u.ctx192);
62  break;
63  case AES256_KEY_SIZE:
64  aes256_invert_key(&dst->u.ctx256, &src->u.ctx256);
65  break;
66  }
67 
68  dst->key_size = src->key_size;
69 }
70 
71 void
73  size_t keysize, const uint8_t *key)
74 {
75  /* We first create subkeys for encryption,
76  * then modify the subkeys for decryption. */
77  aes_set_encrypt_key(ctx, keysize, key);
79 }
80 
void aes_set_decrypt_key(struct aes_ctx *ctx, size_t keysize, const uint8_t *key)
void aes_invert_key(struct aes_ctx *dst, const struct aes_ctx *src)
#define AES192_KEY_SIZE
Definition: aes.h:71
void aes192_invert_key(struct aes192_ctx *dst, const struct aes192_ctx *src)
#define aes_set_encrypt_key
Definition: aes.h:47
#define AES256_KEY_SIZE
Definition: aes.h:72
void aes256_invert_key(struct aes256_ctx *dst, const struct aes256_ctx *src)
void aes128_invert_key(struct aes128_ctx *dst, const struct aes128_ctx *src)
#define AES128_KEY_SIZE
Definition: aes.h:70
lzma_index * src
Definition: index.h:567
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
Definition: sflib.h:118
char * dst
Definition: lz4.h:724
unsigned char uint8_t
Definition: sftypes.h:31
Definition: aes.h:151