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
1933872b
Unverified
Commit
1933872b
authored
Mar 07, 2020
by
kokke
Committed by
GitHub
Mar 07, 2020
Browse files
Merge pull request #157 from dmitrystu/optimized-loop
loop optimization
parents
3fe133ff
6be2e11a
Changes
1
Show whitespace changes
Inline
Side-by-side
aes.c
View file @
1933872b
...
@@ -416,19 +416,19 @@ static void Cipher(state_t* state, const uint8_t* RoundKey)
...
@@ -416,19 +416,19 @@ static void Cipher(state_t* state, const uint8_t* 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
);
}
}
...
@@ -442,20 +442,19 @@ static void InvCipher(state_t* state, const uint8_t* RoundKey)
...
@@ -442,20 +442,19 @@ static void InvCipher(state_t* state, const uint8_t* 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