Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Nettle
nettle
Commits
8cf98222
Commit
8cf98222
authored
Apr 13, 2012
by
Niels Möller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplified aes_set_encrypt_key.
parent
5ff8ded5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
28 deletions
+16
-28
ChangeLog
ChangeLog
+4
-0
aes-set-encrypt-key.c
aes-set-encrypt-key.c
+12
-28
No files found.
ChangeLog
View file @
8cf98222
2012-04-13 Niels Möller <nisse@lysator.liu.se>
* aes-set-encrypt-key.c (aes_set_encrypt_key): Use LE_READ_UINT32.
Tabulate the needed "round constants".
(xtime): Deleted function.
* aes-internal.h (SUBBYTE): Cast to uint32_t. Use B0, ..., B3
macros.
...
...
aes-set-encrypt-key.c
View file @
8cf98222
...
...
@@ -34,26 +34,16 @@
#include "aes-internal.h"
#include "macros.h"
static
unsigned
xtime
(
unsigned
x
)
{
assert
(
x
<
0x100
);
x
<<=
1
;
if
(
x
&
0x100
)
x
^=
0x11b
;
assert
(
x
<
0x100
);
return
x
;
}
void
aes_set_encrypt_key
(
struct
aes_ctx
*
ctx
,
unsigned
keysize
,
const
uint8_t
*
key
)
{
static
const
uint8_t
rcon
[
10
]
=
{
0x01
,
0x02
,
0x04
,
0x08
,
0x10
,
0x20
,
0x40
,
0x80
,
0x1b
,
0x36
,
};
unsigned
nk
,
nr
,
i
,
lastkey
;
uint32_t
temp
,
rcon
;
uint32_t
temp
;
const
uint8_t
*
rp
;
assert
(
keysize
>=
AES_MIN_KEY_SIZE
);
assert
(
keysize
<=
AES_MAX_KEY_SIZE
);
...
...
@@ -72,25 +62,19 @@ aes_set_encrypt_key(struct aes_ctx *ctx,
lastkey
=
(
AES_BLOCK_SIZE
/
4
)
*
(
nr
+
1
);
ctx
->
nrounds
=
nr
;
rcon
=
1
;
for
(
i
=
0
;
i
<
nk
;
i
++
)
{
ctx
->
keys
[
i
]
=
key
[
i
*
4
]
+
(
key
[
i
*
4
+
1
]
<<
8
)
+
(
key
[
i
*
4
+
2
]
<<
16
)
+
(
key
[
i
*
4
+
3
]
<<
24
);
}
for
(
i
=
0
,
rp
=
rcon
;
i
<
nk
;
i
++
)
ctx
->
keys
[
i
]
=
LE_READ_UINT32
(
key
+
i
*
4
);
for
(
i
=
nk
;
i
<
lastkey
;
i
++
)
{
temp
=
ctx
->
keys
[
i
-
1
];
if
(
i
%
nk
==
0
)
{
temp
=
SUBBYTE
(
ROTL32
(
24
,
temp
),
aes_sbox
)
^
rcon
;
rcon
=
(
uint32_t
)
xtime
((
uint8_t
)
rcon
&
0xff
);
}
temp
=
SUBBYTE
(
ROTL32
(
24
,
temp
),
aes_sbox
)
^
*
rp
++
;
else
if
(
nk
>
6
&&
(
i
%
nk
)
==
4
)
{
temp
=
SUBBYTE
(
temp
,
aes_sbox
);
}
temp
=
SUBBYTE
(
temp
,
aes_sbox
);
ctx
->
keys
[
i
]
=
ctx
->
keys
[
i
-
nk
]
^
temp
;
}
}
...
...
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