utils.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* utils.h - TinyCrypt interface to platform-dependent run-time operations */
  2. /*
  3. * Copyright (C) 2017 by Intel Corporation, All Rights Reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * - Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. *
  11. * - Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * - Neither the name of Intel Corporation nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  23. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. * POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. /**
  32. * @file
  33. * @brief Interface to platform-dependent run-time operations.
  34. *
  35. */
  36. #ifndef __TC_UTILS_H__
  37. #define __TC_UTILS_H__
  38. #include <stdint.h>
  39. #include <stddef.h>
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /**
  44. * @brief Copy the the buffer 'from' to the buffer 'to'.
  45. * @return returns TC_CRYPTO_SUCCESS (1)
  46. * returns TC_CRYPTO_FAIL (0) if:
  47. * from_len > to_len.
  48. *
  49. * @param to OUT -- destination buffer
  50. * @param to_len IN -- length of destination buffer
  51. * @param from IN -- origin buffer
  52. * @param from_len IN -- length of origin buffer
  53. */
  54. unsigned int _copy(uint8_t *to, unsigned int to_len,
  55. const uint8_t *from, unsigned int from_len);
  56. /**
  57. * @brief Set the value 'val' into the buffer 'to', 'len' times.
  58. *
  59. * @param to OUT -- destination buffer
  60. * @param val IN -- value to be set in 'to'
  61. * @param len IN -- number of times the value will be copied
  62. */
  63. void _set(void *to, uint8_t val, unsigned int len);
  64. /*
  65. * @brief AES specific doubling function, which utilizes
  66. * the finite field used by AES.
  67. * @return Returns a^2
  68. *
  69. * @param a IN/OUT -- value to be doubled
  70. */
  71. uint8_t _double_byte(uint8_t a);
  72. /*
  73. * @brief Constant-time algorithm to compare if two sequences of bytes are equal
  74. * @return Returns 0 if equal, and non-zero otherwise
  75. *
  76. * @param a IN -- sequence of bytes a
  77. * @param b IN -- sequence of bytes b
  78. * @param size IN -- size of sequences a and b
  79. */
  80. int _compare(const uint8_t *a, const uint8_t *b, size_t size);
  81. #ifdef __cplusplus
  82. }
  83. #endif
  84. #endif /* __TC_UTILS_H__ */