/src/mbedtls/library/ctr.h
Line | Count | Source (jump to first uncovered line) |
1 | | /** |
2 | | * \file ctr.h |
3 | | * |
4 | | * \brief This file contains common functionality for counter algorithms. |
5 | | * |
6 | | * Copyright The Mbed TLS Contributors |
7 | | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
8 | | */ |
9 | | |
10 | | #ifndef MBEDTLS_CTR_H |
11 | | #define MBEDTLS_CTR_H |
12 | | |
13 | | #include "common.h" |
14 | | |
15 | | /** |
16 | | * \brief Increment a big-endian 16-byte value. |
17 | | * This is quite performance-sensitive for AES-CTR and CTR-DRBG. |
18 | | * |
19 | | * \param n A 16-byte value to be incremented. |
20 | | */ |
21 | | static inline void mbedtls_ctr_increment_counter(uint8_t n[16]) |
22 | 30 | { |
23 | | // The 32-bit version seems to perform about the same as a 64-bit version |
24 | | // on 64-bit architectures, so no need to define a 64-bit version. |
25 | 30 | for (int i = 3;; i--) { |
26 | 30 | uint32_t x = MBEDTLS_GET_UINT32_BE(n, i << 2); |
27 | 30 | x += 1; |
28 | 30 | MBEDTLS_PUT_UINT32_BE(x, n, i << 2); |
29 | 30 | if (x != 0 || i == 0) { |
30 | 30 | break; |
31 | 30 | } |
32 | 30 | } |
33 | 30 | } ctr_drbg.c:mbedtls_ctr_increment_counter Line | Count | Source | 22 | 30 | { | 23 | | // The 32-bit version seems to perform about the same as a 64-bit version | 24 | | // on 64-bit architectures, so no need to define a 64-bit version. | 25 | 30 | for (int i = 3;; i--) { | 26 | 30 | uint32_t x = MBEDTLS_GET_UINT32_BE(n, i << 2); | 27 | 30 | x += 1; | 28 | 30 | MBEDTLS_PUT_UINT32_BE(x, n, i << 2); | 29 | 30 | if (x != 0 || i == 0) { | 30 | 30 | break; | 31 | 30 | } | 32 | 30 | } | 33 | 30 | } |
Unexecuted instantiation: aes.c:mbedtls_ctr_increment_counter |
34 | | |
35 | | #endif /* MBEDTLS_CTR_H */ |