ssl_invasive.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * \file ssl_invasive.h
  3. *
  4. * \brief SSL 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_SSL_INVASIVE_H
  27. #define MBEDTLS_SSL_INVASIVE_H
  28. #include "common.h"
  29. #include "mbedtls/md.h"
  30. #if defined(MBEDTLS_TEST_HOOKS) && \
  31. defined(MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC)
  32. /** \brief Compute the HMAC of variable-length data with constant flow.
  33. *
  34. * This function computes the HMAC of the concatenation of \p add_data and \p
  35. * data, and does with a code flow and memory access pattern that does not
  36. * depend on \p data_len_secret, but only on \p min_data_len and \p
  37. * max_data_len. In particular, this function always reads exactly \p
  38. * max_data_len bytes from \p data.
  39. *
  40. * \param ctx The HMAC context. It must have keys configured
  41. * with mbedtls_md_hmac_starts() and use one of the
  42. * following hashes: SHA-384, SHA-256, SHA-1 or MD-5.
  43. * It is reset using mbedtls_md_hmac_reset() after
  44. * the computation is complete to prepare for the
  45. * next computation.
  46. * \param add_data The additional data prepended to \p data. This
  47. * must point to a readable buffer of \p add_data_len
  48. * bytes.
  49. * \param add_data_len The length of \p add_data in bytes.
  50. * \param data The data appended to \p add_data. This must point
  51. * to a readable buffer of \p max_data_len bytes.
  52. * \param data_len_secret The length of the data to process in \p data.
  53. * This must be no less than \p min_data_len and no
  54. * greater than \p max_data_len.
  55. * \param min_data_len The minimal length of \p data in bytes.
  56. * \param max_data_len The maximal length of \p data in bytes.
  57. * \param output The HMAC will be written here. This must point to
  58. * a writable buffer of sufficient size to hold the
  59. * HMAC value.
  60. *
  61. * \retval 0
  62. * Success.
  63. * \retval MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED
  64. * The hardware accelerator failed.
  65. */
  66. int mbedtls_ssl_cf_hmac(
  67. mbedtls_md_context_t *ctx,
  68. const unsigned char *add_data, size_t add_data_len,
  69. const unsigned char *data, size_t data_len_secret,
  70. size_t min_data_len, size_t max_data_len,
  71. unsigned char *output );
  72. /** \brief Copy data from a secret position with constant flow.
  73. *
  74. * This function copies \p len bytes from \p src_base + \p offset_secret to \p
  75. * dst, with a code flow and memory access pattern that does not depend on \p
  76. * offset_secret, but only on \p offset_min, \p offset_max and \p len.
  77. *
  78. * \param dst The destination buffer. This must point to a writable
  79. * buffer of at least \p len bytes.
  80. * \param src_base The base of the source buffer. This must point to a
  81. * readable buffer of at least \p offset_max + \p len
  82. * bytes.
  83. * \param offset_secret The offset in the source buffer from which to copy.
  84. * This must be no less than \p offset_min and no greater
  85. * than \p offset_max.
  86. * \param offset_min The minimal value of \p offset_secret.
  87. * \param offset_max The maximal value of \p offset_secret.
  88. * \param len The number of bytes to copy.
  89. */
  90. void mbedtls_ssl_cf_memcpy_offset( unsigned char *dst,
  91. const unsigned char *src_base,
  92. size_t offset_secret,
  93. size_t offset_min, size_t offset_max,
  94. size_t len );
  95. #endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC */
  96. #endif /* MBEDTLS_SSL_INVASIVE_H */