libkeepass
0.2.0
KeePass key database importer/exporter library
Loading...
Searching...
No Matches
constant_time.hh
Go to the documentation of this file.
1
/*
2
* libkeepass - KeePass key database importer/exporter
3
* Copyright (C) 2014 Christian Kindahl
4
* Copyright (C) 2024 Dominik Krümpelmann
5
*
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
25
#pragma once
26
#include <array>
27
#include <cstddef>
28
#include <cstdint>
29
30
#include <openssl/crypto.h>
31
32
namespace
keepass {
33
namespace
detail {
34
36
49
inline
bool
constant_time_eq
(
const
void
* a, std::size_t a_size,
const
void
* b,
50
std::size_t b_size)
noexcept
{
51
if
(a_size != b_size)
52
return
false
;
53
if
(a_size == 0)
54
return
true
;
55
return
CRYPTO_memcmp(a, b, a_size) == 0;
56
}
57
59
64
template
<std::
size_t
N>
65
inline
bool
constant_time_eq
(
const
std::array<uint8_t, N>& a,
66
const
std::array<uint8_t, N>& b)
noexcept
{
67
return
constant_time_eq
(a.data(), N, b.data(), N);
68
}
69
70
}
// namespace detail
71
}
// namespace keepass
keepass::detail::constant_time_eq
bool constant_time_eq(const void *a, std::size_t a_size, const void *b, std::size_t b_size) noexcept
Compares two byte ranges in constant time.
Definition
constant_time.hh:49
src
include
libkeepass
detail
constant_time.hh
Generated by
1.9.8