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
19a7fb5d
Commit
19a7fb5d
authored
May 25, 2016
by
Mark Haines
Browse files
Fix an integer wrap around bug and add a couple more tests
parent
01ea3d4b
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/megolm.c
View file @
19a7fb5d
...
...
@@ -116,7 +116,11 @@ void megolm_advance_to(Megolm *megolm, uint32_t advance_to) {
((
advance_to
>>
shift
)
-
(
megolm
->
counter
>>
shift
))
&
0xff
;
if
(
steps
==
0
)
{
continue
;
if
(
advance_to
<
megolm
->
counter
)
{
steps
=
0x100
;
}
else
{
continue
;
}
}
/* for all but the last step, we can just bump R(j) without regard
...
...
tests/test_megolm.cpp
View file @
19a7fb5d
...
...
@@ -98,4 +98,37 @@ std::uint8_t random_bytes[] =
assert_equals
(
megolm_get_data
(
&
mr2
),
megolm_get_data
(
&
mr1
),
MEGOLM_RATCHET_LENGTH
);
}
{
TestCase
test_case
(
"Megolm::advance overflow by one"
);
Megolm
mr1
,
mr2
;
megolm_init
(
&
mr1
,
random_bytes
,
0xffffffffUL
);
megolm_advance_to
(
&
mr1
,
0x0
);
assert_equals
(
0x0U
,
mr1
.
counter
);
megolm_init
(
&
mr2
,
random_bytes
,
0xffffffffUL
);
megolm_advance
(
&
mr2
);
assert_equals
(
0x0U
,
mr2
.
counter
);
assert_equals
(
megolm_get_data
(
&
mr2
),
megolm_get_data
(
&
mr1
),
MEGOLM_RATCHET_LENGTH
);
}
{
TestCase
test_case
(
"Megolm::advance overflow"
);
Megolm
mr1
,
mr2
;
megolm_init
(
&
mr1
,
random_bytes
,
0x1UL
);
megolm_advance_to
(
&
mr1
,
0x80000000UL
);
megolm_advance_to
(
&
mr1
,
0x0
);
assert_equals
(
0x0U
,
mr1
.
counter
);
megolm_init
(
&
mr2
,
random_bytes
,
0x1UL
);
megolm_advance_to
(
&
mr2
,
0x0UL
);
assert_equals
(
0x0U
,
mr2
.
counter
);
assert_equals
(
megolm_get_data
(
&
mr2
),
megolm_get_data
(
&
mr1
),
MEGOLM_RATCHET_LENGTH
);
}
}
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