Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Olm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
Olm
Commits
8df4d9e9
Commit
8df4d9e9
authored
10 years ago
by
Mark Haines
Browse files
Options
Downloads
Patches
Plain Diff
Tweak AES cbc to add pcks7 padding bytes
parent
38332e0a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
include/axolotl/crypto.hh
+2
-8
2 additions, 8 deletions
include/axolotl/crypto.hh
include/axolotl/list.hh
+5
-0
5 additions, 0 deletions
include/axolotl/list.hh
src/crypto.cpp
+19
-19
19 additions, 19 deletions
src/crypto.cpp
tests/test_crypto.cpp
+10
-7
10 additions, 7 deletions
tests/test_crypto.cpp
with
36 additions
and
34 deletions
include/axolotl/crypto.hh
+
2
−
8
View file @
8df4d9e9
...
...
@@ -42,17 +42,11 @@ struct Aes256Iv {
};
std
::
size_t
aes_
pkcs_7_padded
_length
(
std
::
size_t
aes_
encrypt_cbc
_length
(
std
::
size_t
input_length
);
void
aes_pkcs_7_padding
(
std
::
uint8_t
const
*
input
,
std
::
size_t
input_length
,
std
::
uint8_t
*
output
);
void
aes_encrypt_cbc
(
Aes256Key
const
&
key
,
Aes256Iv
const
&
iv
,
...
...
@@ -61,7 +55,7 @@ void aes_encrypt_cbc(
);
void
aes_decrypt_cbc
(
std
::
size_t
aes_decrypt_cbc
(
Aes256Key
const
&
key
,
Aes256Iv
const
&
iv
,
std
::
uint8_t
const
*
input
,
std
::
size_t
input_length
,
...
...
This diff is collapsed.
Click to expand it.
include/axolotl/list.hh
+
5
−
0
View file @
8df4d9e9
...
...
@@ -15,6 +15,11 @@ public:
T
const
*
begin
()
const
{
return
_data
;
}
T
const
*
end
()
const
{
return
_end
;
}
/**
* Is the list empty?
*/
bool
empty
()
{
return
_end
==
_data
;
}
/**
* The number of items in the list.
*/
...
...
This diff is collapsed.
Click to expand it.
src/crypto.cpp
+
19
−
19
View file @
8df4d9e9
...
...
@@ -107,26 +107,13 @@ void axolotl::curve25519_shared_secret(
}
std
::
size_t
axolotl
::
aes_
pkcs_7_padded
_length
(
std
::
size_t
axolotl
::
aes_
encrypt_cbc
_length
(
std
::
size_t
input_length
)
{
return
input_length
+
AES_BLOCK_LENGTH
-
input_length
%
AES_BLOCK_LENGTH
;
}
void
axolotl
::
aes_pkcs_7_padding
(
std
::
uint8_t
const
*
input
,
std
::
size_t
input_length
,
std
::
uint8_t
*
output
)
{
std
::
memcpy
(
output
,
input
,
input_length
);
std
::
size_t
padded_length
=
axolotl
::
aes_pkcs_7_padded_length
(
input_length
);
std
::
uint8_t
padding
=
padded_length
-
input_length
;
for
(
std
::
size_t
i
=
input_length
;
i
<
padded_length
;
++
i
)
{
output
[
i
]
=
padding
;
}
}
void
axolotl
::
aes_encrypt_cbc
(
axolotl
::
Aes256Key
const
&
key
,
axolotl
::
Aes256Iv
const
&
iv
,
...
...
@@ -137,17 +124,28 @@ void axolotl::aes_encrypt_cbc(
::
aes_key_setup
(
key
.
key
,
key_schedule
,
256
);
std
::
uint8_t
input_block
[
AES_BLOCK_LENGTH
];
std
::
memcpy
(
input_block
,
iv
.
iv
,
AES_BLOCK_LENGTH
);
for
(
std
::
size_t
i
=
0
;
i
<
input_length
;
i
+=
AES_BLOCK_LENGTH
)
{
xor_block
<
AES_BLOCK_LENGTH
>
(
input_block
,
&
input
[
i
]);
::
aes_encrypt
(
input_block
,
&
output
[
i
],
key_schedule
,
256
);
std
::
memcpy
(
input_block
,
&
output
[
i
],
AES_BLOCK_LENGTH
);
while
(
input_length
>=
AES_BLOCK_LENGTH
)
{
xor_block
<
AES_BLOCK_LENGTH
>
(
input_block
,
input
);
::
aes_encrypt
(
input_block
,
output
,
key_schedule
,
256
);
std
::
memcpy
(
input_block
,
output
,
AES_BLOCK_LENGTH
);
input
+=
AES_BLOCK_LENGTH
;
output
+=
AES_BLOCK_LENGTH
;
input_length
-=
AES_BLOCK_LENGTH
;
}
std
::
size_t
i
=
0
;
for
(;
i
<
input_length
;
++
i
)
{
input_block
[
i
]
^=
input
[
i
];
}
for
(;
i
<
AES_BLOCK_LENGTH
;
++
i
)
{
input_block
[
i
]
^=
AES_BLOCK_LENGTH
-
input_length
;
}
::
aes_encrypt
(
input_block
,
output
,
key_schedule
,
256
);
std
::
memset
(
key_schedule
,
0
,
sizeof
(
key_schedule
));
std
::
memset
(
input_block
,
0
,
sizeof
(
AES_BLOCK_LENGTH
));
}
void
axolotl
::
aes_decrypt_cbc
(
std
::
size_t
axolotl
::
aes_decrypt_cbc
(
axolotl
::
Aes256Key
const
&
key
,
axolotl
::
Aes256Iv
const
&
iv
,
std
::
uint8_t
const
*
input
,
std
::
size_t
input_length
,
...
...
@@ -164,6 +162,8 @@ void axolotl::aes_decrypt_cbc(
}
}
std
::
memset
(
key_schedule
,
0
,
sizeof
(
key_schedule
));
std
::
size_t
padding
=
output
[
input_length
-
1
];
return
(
padding
>
input_length
)
?
std
::
size_t
(
-
1
)
:
(
input_length
-
padding
);
}
...
...
This diff is collapsed.
Click to expand it.
tests/test_crypto.cpp
+
10
−
7
View file @
8df4d9e9
...
...
@@ -73,24 +73,27 @@ TestCase test_case("AES Test Case 1");
axolotl
::
Aes256Key
key
=
{};
axolotl
::
Aes256Iv
iv
=
{};
std
::
uint8_t
input
[
32
]
=
{};
std
::
uint8_t
input
[
16
]
=
{};
std
::
uint8_t
expected
[
32
]
=
{
0xDC
,
0x95
,
0xC0
,
0x78
,
0xA2
,
0x40
,
0x89
,
0x89
,
0xAD
,
0x48
,
0xA2
,
0x14
,
0x92
,
0x84
,
0x20
,
0x87
,
0x
08
,
0xC
3
,
0x
74
,
0x
84
,
0x
8
C
,
0x
22
,
0x8
2
,
0x
33
,
0x
C2
,
0x
B3
,
0x
4
F
,
0x
33
,
0x
2B
,
0x
D
2
,
0x
E9
,
0x
D
3
0x
F3
,
0xC
0
,
0x
03
,
0x
DD
,
0xC
4
,
0x
A7
,
0x
B
8
,
0x
A9
,
0x
4B
,
0x
AE
,
0x
D
F
,
0x
FC
,
0x
3D
,
0x2
1
,
0x
4C
,
0x3
8
};
std
::
size_t
length
=
axolotl
::
aes_encrypt_cbc_length
(
sizeof
(
input
));
assert_equals
(
std
::
size_t
(
32
),
length
);
std
::
uint8_t
actual
[
32
]
=
{};
axolotl
::
aes_encrypt_cbc
(
key
,
iv
,
input
,
sizeof
(
input
),
actual
);
assert_equals
(
expected
,
actual
,
32
);
axolotl
::
aes_decrypt_cbc
(
key
,
iv
,
expected
,
sizeof
(
expected
),
actual
);
assert_equals
(
input
,
actual
,
32
);
length
=
axolotl
::
aes_decrypt_cbc
(
key
,
iv
,
expected
,
sizeof
(
expected
),
actual
);
assert_equals
(
std
::
size_t
(
16
),
length
);
assert_equals
(
input
,
actual
,
length
);
}
/* AES Test Case 1 */
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment