/**1* \file ctr.h2*3* \brief This file contains common functionality for counter algorithms.4*5* Copyright The Mbed TLS Contributors6* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later7*/89#ifndef MBEDTLS_CTR_H10#define MBEDTLS_CTR_H1112#include "common.h"1314/**15* \brief Increment a big-endian 16-byte value.16* This is quite performance-sensitive for AES-CTR and CTR-DRBG.17*18* \param n A 16-byte value to be incremented.19*/20static inline void mbedtls_ctr_increment_counter(uint8_t n[16])21{22// The 32-bit version seems to perform about the same as a 64-bit version23// on 64-bit architectures, so no need to define a 64-bit version.24for (int i = 3;; i--) {25uint32_t x = MBEDTLS_GET_UINT32_BE(n, i << 2);26x += 1;27MBEDTLS_PUT_UINT32_BE(x, n, i << 2);28if (x != 0 || i == 0) {29break;30}31}32}3334#endif /* MBEDTLS_CTR_H */353637