Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
matrix-org
Olm
Commits
01abe0cf
Commit
01abe0cf
authored
Feb 26, 2015
by
Mark Haines
Browse files
Add test for axolotl ratchet
parent
4844c1b9
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/test_axolotl.cpp
0 → 100644
View file @
01abe0cf
#include "axolotl/axolotl.hh"
#include "unittest.hh"
int
main
()
{
{
/* Loopback test case */
TestCase
test_case
(
"Axolotl Loopback 1"
);
std
::
uint8_t
root_info
[]
=
"Axolotl"
;
std
::
uint8_t
ratchet_info
[]
=
"AxolotlRatchet"
;
std
::
uint8_t
message_info
[]
=
"AxolotlMessageKeys"
;
axolotl
::
KdfInfo
kdf_info
=
{
root_info
,
sizeof
(
root_info
)
-
1
,
ratchet_info
,
sizeof
(
ratchet_info
-
1
),
message_info
,
sizeof
(
ratchet_info
-
1
)
};
axolotl
::
Session
alice
(
kdf_info
);
axolotl
::
Session
bob
(
kdf_info
);
std
::
uint8_t
random_bytes
[]
=
"0123456789ABDEF0123456789ABCDEF"
;
axolotl
::
Curve25519KeyPair
bob_key
;
axolotl
::
generate_key
(
random_bytes
,
bob_key
);
std
::
uint8_t
shared_secret
[]
=
"A secret"
;
alice
.
initialise_as_bob
(
shared_secret
,
sizeof
(
shared_secret
)
-
1
,
bob_key
);
bob
.
initialise_as_alice
(
shared_secret
,
sizeof
(
shared_secret
)
-
1
,
bob_key
);
std
::
uint8_t
plaintext
[]
=
"Message"
;
std
::
size_t
plaintext_length
=
sizeof
(
plaintext
)
-
1
;
std
::
size_t
message_length
,
random_length
,
actual_length
;
std
::
size_t
encrypt_length
,
decrypt_length
;
message_length
=
bob
.
encrypt_max_output_length
(
plaintext_length
);
random_length
=
bob
.
encrypt_random_length
();
assert_equals
(
std
::
size_t
(
0
),
random_length
);
actual_length
=
alice
.
decrypt_max_plaintext_length
(
message_length
);
{
std
::
uint8_t
message
[
message_length
];
std
::
uint8_t
actual
[
actual_length
];
encrypt_length
=
bob
.
encrypt
(
plaintext
,
plaintext_length
,
NULL
,
0
,
message
,
message_length
);
assert_equals
(
message_length
,
encrypt_length
);
decrypt_length
=
alice
.
decrypt
(
message
,
message_length
,
actual
,
actual_length
);
assert_equals
(
plaintext_length
,
decrypt_length
);
assert_equals
(
plaintext
,
actual
,
decrypt_length
);
}
}
/* Loopback test case */
}
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