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
8123ce62
Commit
8123ce62
authored
10 years ago
by
Mark Haines
Browse files
Options
Downloads
Patches
Plain Diff
Constant time comparison for mac
parent
2f2e0340
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/axolotl/memory.hh
+9
-2
9 additions, 2 deletions
include/axolotl/memory.hh
src/memory.cpp
+17
-3
17 additions, 3 deletions
src/memory.cpp
src/ratchet.cpp
+1
-1
1 addition, 1 deletion
src/ratchet.cpp
with
27 additions
and
6 deletions
include/axolotl/memory.hh
+
9
−
2
View file @
8123ce62
#include
<cstddef>
#include
<cstdint>
namespace
axolotl
{
/** Clear the memory held in the buffer */
void
unset
(
volatile
void
*
buffer
,
std
::
size_t
buffer_length
void
volatile
*
buffer
,
std
::
size_t
buffer_length
);
/** Clear the memory backing an object */
template
<
typename
T
>
void
unset
(
T
&
value
)
{
unset
(
reinterpret_cast
<
volatile
void
*>
(
&
value
),
sizeof
(
T
));
unset
(
reinterpret_cast
<
void
volatile
*>
(
&
value
),
sizeof
(
T
));
}
/** Check if two buffers are equal in constant time. */
bool
is_equal
(
std
::
uint8_t
const
*
buffer_a
,
std
::
uint8_t
const
*
buffer_b
,
std
::
size_t
length
);
}
// namespace axolotl
This diff is collapsed.
Click to expand it.
src/memory.cpp
+
17
−
3
View file @
8123ce62
#include
"axolotl/memory.hh"
void
axolotl
::
unset
(
volatile
void
*
buffer
,
std
::
size_t
buffer_length
void
volatile
*
buffer
,
std
::
size_t
buffer_length
)
{
volatile
char
*
pos
=
reinterpret_cast
<
volatile
char
*>
(
buffer
);
volatile
char
*
end
=
pos
+
buffer_length
;
char
volatile
*
pos
=
reinterpret_cast
<
char
volatile
*>
(
buffer
);
char
volatile
*
end
=
pos
+
buffer_length
;
while
(
pos
!=
end
)
{
*
(
pos
++
)
=
0
;
}
}
bool
axolotl
::
is_equal
(
std
::
uint8_t
const
*
buffer_a
,
std
::
uint8_t
const
*
buffer_b
,
std
::
size_t
length
)
{
std
::
uint8_t
volatile
result
=
0
;
while
(
length
--
)
{
result
|=
(
*
(
buffer_a
++
))
^
(
*
(
buffer_b
++
));
}
return
result
==
0
;
}
This diff is collapsed.
Click to expand it.
src/ratchet.cpp
+
1
−
1
View file @
8123ce62
...
...
@@ -104,7 +104,7 @@ bool verify_mac(
mac
);
bool
result
=
std
::
memcmp
(
mac
,
reader
.
mac
,
MAC_LENGTH
)
==
0
;
bool
result
=
axolotl
::
is_equal
(
mac
,
reader
.
mac
,
MAC_LENGTH
);
axolotl
::
unset
(
mac
);
return
result
;
}
...
...
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