Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Tiny AES C
Commits
6be2e11a
Commit
6be2e11a
authored
Mar 03, 2020
by
Dmitry
Browse files
loop optimization
parent
3fe133ff
Changes
1
Hide whitespace changes
Inline
Side-by-side
aes.c
View file @
6be2e11a
...
@@ -412,23 +412,23 @@ static void Cipher(state_t* state, const uint8_t* RoundKey)
...
@@ -412,23 +412,23 @@ static void Cipher(state_t* state, const uint8_t* RoundKey)
uint8_t
round
=
0
;
uint8_t
round
=
0
;
// Add the First round key to the state before starting the rounds.
// Add the First round key to the state before starting the rounds.
AddRoundKey
(
0
,
state
,
RoundKey
);
AddRoundKey
(
0
,
state
,
RoundKey
);
// There will be Nr rounds.
// There will be Nr rounds.
// The first Nr-1 rounds are identical.
// The first Nr-1 rounds are identical.
// These Nr-1 rounds are executed in the loop below.
// These Nr rounds are executed in the loop below.
for
(
round
=
1
;
round
<
Nr
;
++
round
)
// Last one without MixColumns()
for
(
round
=
1
;
;
++
round
)
{
{
SubBytes
(
state
);
SubBytes
(
state
);
ShiftRows
(
state
);
ShiftRows
(
state
);
if
(
round
==
Nr
)
{
break
;
}
MixColumns
(
state
);
MixColumns
(
state
);
AddRoundKey
(
round
,
state
,
RoundKey
);
AddRoundKey
(
round
,
state
,
RoundKey
);
}
}
// Add round key to last round
// The last round is given below.
// The MixColumns function is not here in the last round.
SubBytes
(
state
);
ShiftRows
(
state
);
AddRoundKey
(
Nr
,
state
,
RoundKey
);
AddRoundKey
(
Nr
,
state
,
RoundKey
);
}
}
...
@@ -438,24 +438,23 @@ static void InvCipher(state_t* state, const uint8_t* RoundKey)
...
@@ -438,24 +438,23 @@ static void InvCipher(state_t* state, const uint8_t* RoundKey)
uint8_t
round
=
0
;
uint8_t
round
=
0
;
// Add the First round key to the state before starting the rounds.
// Add the First round key to the state before starting the rounds.
AddRoundKey
(
Nr
,
state
,
RoundKey
);
AddRoundKey
(
Nr
,
state
,
RoundKey
);
// There will be Nr rounds.
// There will be Nr rounds.
// The first Nr-1 rounds are identical.
// The first Nr-1 rounds are identical.
// These Nr-1 rounds are executed in the loop below.
// These Nr rounds are executed in the loop below.
for
(
round
=
(
Nr
-
1
);
round
>
0
;
--
round
)
// Last one without InvMixColumn()
for
(
round
=
(
Nr
-
1
);
;
--
round
)
{
{
InvShiftRows
(
state
);
InvShiftRows
(
state
);
InvSubBytes
(
state
);
InvSubBytes
(
state
);
AddRoundKey
(
round
,
state
,
RoundKey
);
AddRoundKey
(
round
,
state
,
RoundKey
);
if
(
round
==
0
)
{
break
;
}
InvMixColumns
(
state
);
InvMixColumns
(
state
);
}
}
// The last round is given below.
// The MixColumns function is not here in the last round.
InvShiftRows
(
state
);
InvSubBytes
(
state
);
AddRoundKey
(
0
,
state
,
RoundKey
);
}
}
#endif // #if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1)
#endif // #if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1)
...
...
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