constant_time_invasive.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * \file constant_time_invasive.h
  3. *
  4. * \brief Constant-time module: interfaces for invasive testing only.
  5. *
  6. * The interfaces in this file are intended for testing purposes only.
  7. * They SHOULD NOT be made available in library integrations except when
  8. * building the library for testing.
  9. */
  10. /*
  11. * Copyright The Mbed TLS Contributors
  12. * SPDX-License-Identifier: Apache-2.0
  13. *
  14. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  15. * not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at
  17. *
  18. * http://www.apache.org/licenses/LICENSE-2.0
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  22. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. */
  26. #ifndef MBEDTLS_CONSTANT_TIME_INVASIVE_H
  27. #define MBEDTLS_CONSTANT_TIME_INVASIVE_H
  28. #include "common.h"
  29. #if defined(MBEDTLS_TEST_HOOKS)
  30. /** Turn a value into a mask:
  31. * - if \p low <= \p c <= \p high,
  32. * return the all-bits 1 mask, aka (unsigned) -1
  33. * - otherwise, return the all-bits 0 mask, aka 0
  34. *
  35. * \param low The value to analyze.
  36. * \param high The value to analyze.
  37. * \param c The value to analyze.
  38. *
  39. * \return All-bits-one if \p low <= \p c <= \p high, otherwise zero.
  40. */
  41. unsigned char mbedtls_ct_uchar_mask_of_range( unsigned char low,
  42. unsigned char high,
  43. unsigned char c );
  44. #endif /* MBEDTLS_TEST_HOOKS */
  45. #endif /* MBEDTLS_CONSTANT_TIME_INVASIVE_H */