Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nettle
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Brian Smith
nettle
Commits
bb2131cb
Commit
bb2131cb
authored
Jun 25, 2013
by
Niels Möller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New interface for AES-128.
parent
b27be3a6
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
257 additions
and
30 deletions
+257
-30
ChangeLog
ChangeLog
+18
-0
Makefile.in
Makefile.in
+2
-0
aes-decrypt.c
aes-decrypt.c
+10
-0
aes-encrypt.c
aes-encrypt.c
+10
-0
aes-meta.c
aes-meta.c
+0
-3
aes.h
aes.h
+28
-0
aes128-meta.c
aes128-meta.c
+57
-0
aes128-set-decrypt-key.c
aes128-set-decrypt-key.c
+46
-0
aes128-set-encrypt-key.c
aes128-set-encrypt-key.c
+38
-0
nettle-internal.c
nettle-internal.c
+5
-0
nettle-internal.h
nettle-internal.h
+2
-0
testsuite/aes-test.c
testsuite/aes-test.c
+41
-27
No files found.
ChangeLog
View file @
bb2131cb
2013-06-25 Niels Möller <nisse@lysator.liu.se>
* aes.h (struct aes128_ctx): New aes128 declarations.
* aes-decrypt.c (aes128_decrypt): New function.
* aes-encrypt.c (aes128_encrypt): New function.
* aes128-meta.c: New file.
* aes128-set-encrypt-key.c (aes128_set_encrypt_key): New file and
function.
* aes128-set-decrypt-key.c (aes128_set_decrypt_key)
(aes128_invert_key): New file and functions.
* Makefile.in (nettle_SOURCES): Added aes128-set-encrypt-key.c,
aes128-set-decrypt-key.c and aes128-meta.c.
* nettle-internal.c (nettle_unified_aes128): For testing the old
AES interface.
* testsuite/aes-test.c (test_cipher2): New function.
(test_main): Test both nettle_aes128 and nettle_unified_aes128.
2013-05-22 Niels Möller <nisse@lysator.liu.se>
2013-05-22 Niels Möller <nisse@lysator.liu.se>
* Makefile.in (nettle_SOURCES): Added aes-invert-internal.c and
* Makefile.in (nettle_SOURCES): Added aes-invert-internal.c and
...
...
Makefile.in
View file @
bb2131cb
...
@@ -65,6 +65,8 @@ nettle_SOURCES = aes-decrypt-internal.c aes-decrypt.c \
...
@@ -65,6 +65,8 @@ nettle_SOURCES = aes-decrypt-internal.c aes-decrypt.c \
aes-encrypt-internal.c aes-encrypt.c aes-encrypt-table.c
\
aes-encrypt-internal.c aes-encrypt.c aes-encrypt-table.c
\
aes-invert-internal.c aes-set-key-internal.c
\
aes-invert-internal.c aes-set-key-internal.c
\
aes-set-encrypt-key.c aes-set-decrypt-key.c aes-meta.c
\
aes-set-encrypt-key.c aes-set-decrypt-key.c aes-meta.c
\
aes128-set-encrypt-key.c aes128-set-decrypt-key.c
\
aes128-meta.c
\
arcfour.c arcfour-crypt.c arcfour-meta.c
\
arcfour.c arcfour-crypt.c arcfour-meta.c
\
arctwo.c arctwo-meta.c gosthash94-meta.c
\
arctwo.c arctwo-meta.c gosthash94-meta.c
\
base16-encode.c base16-decode.c base16-meta.c
\
base16-encode.c base16-decode.c base16-meta.c
\
...
...
aes-decrypt.c
View file @
bb2131cb
...
@@ -345,3 +345,13 @@ aes_decrypt(const struct aes_ctx *ctx,
...
@@ -345,3 +345,13 @@ aes_decrypt(const struct aes_ctx *ctx,
_aes_decrypt
(
ctx
->
rounds
,
ctx
->
keys
,
&
_aes_decrypt_table
,
_aes_decrypt
(
ctx
->
rounds
,
ctx
->
keys
,
&
_aes_decrypt_table
,
length
,
dst
,
src
);
length
,
dst
,
src
);
}
}
void
aes128_decrypt
(
const
struct
aes128_ctx
*
ctx
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
)
{
assert
(
!
(
length
%
AES_BLOCK_SIZE
)
);
_aes_decrypt
(
_AES128_ROUNDS
,
ctx
->
keys
,
&
_aes_decrypt_table
,
length
,
dst
,
src
);
}
aes-encrypt.c
View file @
bb2131cb
...
@@ -43,3 +43,13 @@ aes_encrypt(const struct aes_ctx *ctx,
...
@@ -43,3 +43,13 @@ aes_encrypt(const struct aes_ctx *ctx,
_aes_encrypt
(
ctx
->
rounds
,
ctx
->
keys
,
&
_aes_encrypt_table
,
_aes_encrypt
(
ctx
->
rounds
,
ctx
->
keys
,
&
_aes_encrypt_table
,
length
,
dst
,
src
);
length
,
dst
,
src
);
}
}
void
aes128_encrypt
(
const
struct
aes128_ctx
*
ctx
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
)
{
assert
(
!
(
length
%
AES_BLOCK_SIZE
)
);
_aes_encrypt
(
_AES128_ROUNDS
,
ctx
->
keys
,
&
_aes_encrypt_table
,
length
,
dst
,
src
);
}
aes-meta.c
View file @
bb2131cb
...
@@ -28,9 +28,6 @@
...
@@ -28,9 +28,6 @@
#include "aes.h"
#include "aes.h"
const
struct
nettle_cipher
nettle_aes128
=
_NETTLE_CIPHER_SEP
(
aes
,
AES
,
128
);
const
struct
nettle_cipher
nettle_aes192
const
struct
nettle_cipher
nettle_aes192
=
_NETTLE_CIPHER_SEP
(
aes
,
AES
,
192
);
=
_NETTLE_CIPHER_SEP
(
aes
,
AES
,
192
);
...
...
aes.h
View file @
bb2131cb
...
@@ -38,6 +38,11 @@ extern "C" {
...
@@ -38,6 +38,11 @@ extern "C" {
#define aes_invert_key nettle_aes_invert_key
#define aes_invert_key nettle_aes_invert_key
#define aes_encrypt nettle_aes_encrypt
#define aes_encrypt nettle_aes_encrypt
#define aes_decrypt nettle_aes_decrypt
#define aes_decrypt nettle_aes_decrypt
#define aes128_set_encrypt_key nettle_aes128set_encrypt_key
#define aes128_set_decrypt_key nettle_aes128set_decrypt_key
#define aes128_invert_key nettle_aes128invert_key
#define aes128_encrypt nettle_aes128encrypt
#define aes128_decrypt nettle_aes128decrypt
#define AES_BLOCK_SIZE 16
#define AES_BLOCK_SIZE 16
...
@@ -53,6 +58,8 @@ extern "C" {
...
@@ -53,6 +58,8 @@ extern "C" {
#define AES_MIN_KEY_SIZE AES128_KEY_SIZE
#define AES_MIN_KEY_SIZE AES128_KEY_SIZE
#define AES_MAX_KEY_SIZE AES256_KEY_SIZE
#define AES_MAX_KEY_SIZE AES256_KEY_SIZE
/* Older nettle-2.7 interface */
#define AES_KEY_SIZE 32
#define AES_KEY_SIZE 32
struct
aes_ctx
struct
aes_ctx
...
@@ -82,6 +89,27 @@ aes_decrypt(const struct aes_ctx *ctx,
...
@@ -82,6 +89,27 @@ aes_decrypt(const struct aes_ctx *ctx,
size_t
length
,
uint8_t
*
dst
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
);
const
uint8_t
*
src
);
struct
aes128_ctx
{
uint32_t
keys
[
4
*
(
_AES128_ROUNDS
+
1
)];
};
void
aes128_set_encrypt_key
(
struct
aes128_ctx
*
ctx
,
const
uint8_t
*
key
);
void
aes128_set_decrypt_key
(
struct
aes128_ctx
*
ctx
,
const
uint8_t
*
key
);
void
aes128_invert_key
(
struct
aes128_ctx
*
dst
,
const
struct
aes128_ctx
*
src
);
void
aes128_encrypt
(
const
struct
aes128_ctx
*
ctx
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
);
void
aes128_decrypt
(
const
struct
aes128_ctx
*
ctx
,
size_t
length
,
uint8_t
*
dst
,
const
uint8_t
*
src
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
aes128-meta.c
0 → 100644
View file @
bb2131cb
/* aes128-meta.c */
/* nettle, low-level cryptographics library
*
* Copyright (C) 2013 Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <assert.h>
#include "nettle-meta.h"
#include "aes.h"
static
nettle_set_key_func
aes128_set_encrypt_key_wrapper
;
static
nettle_set_key_func
aes128_set_decrypt_key_wrapper
;
static
void
aes128_set_encrypt_key_wrapper
(
void
*
ctx
,
size_t
length
,
const
uint8_t
*
key
)
{
assert
(
length
==
AES128_KEY_SIZE
);
aes128_set_encrypt_key
(
ctx
,
key
);
}
static
void
aes128_set_decrypt_key_wrapper
(
void
*
ctx
,
size_t
length
,
const
uint8_t
*
key
)
{
assert
(
length
==
AES128_KEY_SIZE
);
aes128_set_decrypt_key
(
ctx
,
key
);
}
const
struct
nettle_cipher
nettle_aes128
=
{
"aes128"
,
sizeof
(
struct
aes128_ctx
),
AES_BLOCK_SIZE
,
AES128_KEY_SIZE
,
aes128_set_encrypt_key_wrapper
,
aes128_set_decrypt_key_wrapper
,
(
nettle_crypt_func
*
)
aes128_encrypt
,
(
nettle_crypt_func
*
)
aes128_decrypt
};
aes128-set-decrypt-key.c
0 → 100644
View file @
bb2131cb
/* aes128-set-decrypt-key.c
*
* Key setup for the aes/rijndael block cipher.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2013, Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <assert.h>
#include "aes-internal.h"
#include "macros.h"
void
aes128_invert_key
(
struct
aes128_ctx
*
dst
,
const
struct
aes128_ctx
*
src
)
{
_aes_invert
(
_AES128_ROUNDS
,
dst
->
keys
,
src
->
keys
);
}
void
aes128_set_decrypt_key
(
struct
aes128_ctx
*
ctx
,
const
uint8_t
*
key
)
{
aes128_set_encrypt_key
(
ctx
,
key
);
aes128_invert_key
(
ctx
,
ctx
);
}
aes128-set-encrypt-key.c
0 → 100644
View file @
bb2131cb
/* aes128-set-encrypt-key.c
*
* Key setup for the aes/rijndael block cipher.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2013, Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02111-1301, USA.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <assert.h>
#include "aes-internal.h"
void
aes128_set_encrypt_key
(
struct
aes128_ctx
*
ctx
,
const
uint8_t
*
key
)
{
_aes_set_key
(
_AES128_ROUNDS
,
AES128_KEY_SIZE
/
4
,
ctx
->
keys
,
key
);
}
nettle-internal.c
View file @
bb2131cb
...
@@ -112,3 +112,8 @@ const struct nettle_aead
...
@@ -112,3 +112,8 @@ const struct nettle_aead
nettle_gcm_aes192
=
_NETTLE_AEAD
(
gcm
,
GCM
,
aes
,
192
);
nettle_gcm_aes192
=
_NETTLE_AEAD
(
gcm
,
GCM
,
aes
,
192
);
const
struct
nettle_aead
const
struct
nettle_aead
nettle_gcm_aes256
=
_NETTLE_AEAD
(
gcm
,
GCM
,
aes
,
256
);
nettle_gcm_aes256
=
_NETTLE_AEAD
(
gcm
,
GCM
,
aes
,
256
);
/* Old, unified, interface */
const
struct
nettle_cipher
nettle_unified_aes128
=
_NETTLE_CIPHER_SEP
(
aes
,
AES
,
128
);
nettle-internal.h
View file @
bb2131cb
...
@@ -64,6 +64,8 @@ extern const struct nettle_cipher nettle_blowfish128;
...
@@ -64,6 +64,8 @@ extern const struct nettle_cipher nettle_blowfish128;
extern
const
struct
nettle_cipher
nettle_salsa20
;
extern
const
struct
nettle_cipher
nettle_salsa20
;
extern
const
struct
nettle_cipher
nettle_salsa20r12
;
extern
const
struct
nettle_cipher
nettle_salsa20r12
;
extern
const
struct
nettle_cipher
nettle_unified_aes128
;
/* Glue to openssl, for comparative benchmarking. Code in
/* Glue to openssl, for comparative benchmarking. Code in
* examples/nettle-openssl.c. */
* examples/nettle-openssl.c. */
extern
const
struct
nettle_cipher
nettle_openssl_aes128
;
extern
const
struct
nettle_cipher
nettle_openssl_aes128
;
...
...
testsuite/aes-test.c
View file @
bb2131cb
#include "testutils.h"
#include "testutils.h"
#include "aes.h"
#include "aes.h"
#include "nettle-internal.h"
static
void
static
void
test_invert
(
const
struct
tstring
*
key
,
test_invert
(
const
struct
tstring
*
key
,
...
@@ -45,29 +46,42 @@ test_invert(const struct tstring *key,
...
@@ -45,29 +46,42 @@ test_invert(const struct tstring *key,
free
(
data
);
free
(
data
);
}
}
static
void
test_cipher2
(
const
struct
nettle_cipher
*
c1
,
const
struct
nettle_cipher
*
c2
,
const
struct
tstring
*
key
,
const
struct
tstring
*
cleartext
,
const
struct
tstring
*
ciphertext
)
{
test_cipher
(
c1
,
key
,
cleartext
,
ciphertext
);
test_cipher
(
c2
,
key
,
cleartext
,
ciphertext
);
}
void
void
test_main
(
void
)
test_main
(
void
)
{
{
/* Test both the new interface and the older unified interface. */
/* 128 bit keys */
/* 128 bit keys */
test_cipher
(
&
nettle_aes128
,
test_cipher
2
(
&
nettle_aes128
,
&
nettle_unified_aes128
,
SHEX
(
"0001020305060708 0A0B0C0D0F101112"
),
SHEX
(
"0001020305060708 0A0B0C0D0F101112"
),
SHEX
(
"506812A45F08C889 B97F5980038B8359"
),
SHEX
(
"506812A45F08C889 B97F5980038B8359"
),
SHEX
(
"D8F532538289EF7D 06B506A4FD5BE9C9"
));
SHEX
(
"D8F532538289EF7D 06B506A4FD5BE9C9"
));
test_cipher
(
&
nettle_aes128
,
test_cipher
2
(
&
nettle_aes128
,
&
nettle_unified_aes128
,
SHEX
(
"14151617191A1B1C 1E1F202123242526"
),
SHEX
(
"14151617191A1B1C 1E1F202123242526"
),
SHEX
(
"5C6D71CA30DE8B8B 00549984D2EC7D4B"
),
SHEX
(
"5C6D71CA30DE8B8B 00549984D2EC7D4B"
),
SHEX
(
"59AB30F4D4EE6E4F F9907EF65B1FB68C"
));
SHEX
(
"59AB30F4D4EE6E4F F9907EF65B1FB68C"
));
test_cipher
(
&
nettle_aes128
,
test_cipher
2
(
&
nettle_aes128
,
&
nettle_unified_aes128
,
SHEX
(
"28292A2B2D2E2F30 323334353738393A"
),
SHEX
(
"28292A2B2D2E2F30 323334353738393A"
),
SHEX
(
"53F3F4C64F8616E4 E7C56199F48F21F6"
),
SHEX
(
"53F3F4C64F8616E4 E7C56199F48F21F6"
),
SHEX
(
"BF1ED2FCB2AF3FD4 1443B56D85025CB1"
));
SHEX
(
"BF1ED2FCB2AF3FD4 1443B56D85025CB1"
));
test_cipher
(
&
nettle_aes128
,
test_cipher
2
(
&
nettle_aes128
,
&
nettle_unified_aes128
,
SHEX
(
"A0A1A2A3A5A6A7A8 AAABACADAFB0B1B2"
),
SHEX
(
"A0A1A2A3A5A6A7A8 AAABACADAFB0B1B2"
),
SHEX
(
"F5F4F7F684878689 A6A7A0A1D2CDCCCF"
),
SHEX
(
"F5F4F7F684878689 A6A7A0A1D2CDCCCF"
),
SHEX
(
"CE52AF650D088CA5 59425223F4D32694"
));
SHEX
(
"CE52AF650D088CA5 59425223F4D32694"
));
/* 192 bit keys */
/* 192 bit keys */
...
@@ -104,16 +118,16 @@ test_main(void)
...
@@ -104,16 +118,16 @@ test_main(void)
* F.1.1 ECB-AES128-Encrypt
* F.1.1 ECB-AES128-Encrypt
*/
*/
test_cipher
(
&
nettle
_aes128
,
test_cipher
2
(
&
nettle_aes128
,
&
nettle_unified
_aes128
,
SHEX
(
"2b7e151628aed2a6abf7158809cf4f3c"
),
SHEX
(
"2b7e151628aed2a6abf7158809cf4f3c"
),
SHEX
(
"6bc1bee22e409f96e93d7e117393172a"
SHEX
(
"6bc1bee22e409f96e93d7e117393172a"
"ae2d8a571e03ac9c9eb76fac45af8e51"
"ae2d8a571e03ac9c9eb76fac45af8e51"
"30c81c46a35ce411e5fbc1191a0a52ef"
"30c81c46a35ce411e5fbc1191a0a52ef"
"f69f2445df4f9b17ad2b417be66c3710"
),
"f69f2445df4f9b17ad2b417be66c3710"
),
SHEX
(
"3ad77bb40d7a3660a89ecaf32466ef97"
SHEX
(
"3ad77bb40d7a3660a89ecaf32466ef97"
"f5d3d58503b9699de785895a96fdbaaf"
"f5d3d58503b9699de785895a96fdbaaf"
"43b1cd7f598ece23881b00e3ed030688"
"43b1cd7f598ece23881b00e3ed030688"
"7b0c785e27e8ad3f8223207104725dd4"
));
"7b0c785e27e8ad3f8223207104725dd4"
));
/* F.1.3 ECB-AES192-Encrypt */
/* F.1.3 ECB-AES192-Encrypt */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment