/src/Botan-3.4.0/src/lib/utils/mem_ops.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * (C) 2017 Jack Lloyd |
3 | | * |
4 | | * Botan is released under the Simplified BSD License (see license.txt) |
5 | | */ |
6 | | |
7 | | #include <botan/mem_ops.h> |
8 | | |
9 | | #include <botan/internal/ct_utils.h> |
10 | | |
11 | | namespace Botan { |
12 | | |
13 | 0 | uint8_t ct_compare_u8(const uint8_t x[], const uint8_t y[], size_t len) { |
14 | 0 | return CT::is_equal(x, y, len).value(); |
15 | 0 | } |
16 | | |
17 | 0 | bool constant_time_compare(std::span<const uint8_t> x, std::span<const uint8_t> y) { |
18 | 0 | const auto min_size = CT::Mask<size_t>::is_lte(x.size(), y.size()).select(x.size(), y.size()); |
19 | 0 | const auto equal_size = CT::Mask<size_t>::is_equal(x.size(), y.size()); |
20 | 0 | const auto equal_content = CT::Mask<size_t>::expand(CT::is_equal(x.data(), y.data(), min_size)); |
21 | 0 | return (equal_content & equal_size).as_bool(); |
22 | 0 | } |
23 | | |
24 | | } // namespace Botan |