trng_api.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /** \addtogroup hal */
  2. /** @{*/
  3. /* mbed Microcontroller Library
  4. * Copyright (c) 2016 ARM Limited
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef MBED_TRNG_API_H
  19. #define MBED_TRNG_API_H
  20. #include <stddef.h>
  21. #include "device.h"
  22. #if DEVICE_TRNG
  23. /** TRNG HAL structure. trng_s is declared in the target's HAL
  24. */
  25. typedef struct trng_s trng_t;
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /**
  30. * \defgroup hal_trng TRNG hal functions
  31. * @{
  32. */
  33. /** Initialize the TRNG peripheral
  34. *
  35. * @param obj The TRNG object
  36. */
  37. void trng_init(trng_t *obj);
  38. /** Deinitialize the TRNG peripheral
  39. *
  40. * @param obj The TRNG object
  41. */
  42. void trng_free(trng_t *obj);
  43. /** Get random data from TRNG peripheral
  44. *
  45. * @param obj The TRNG object
  46. * @param output The pointer to an output array
  47. * @param length The size of output data, to avoid buffer overwrite
  48. * @param output_length The length of generated data
  49. * @return 0 success, -1 fail
  50. */
  51. int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length);
  52. /**@}*/
  53. #ifdef __cplusplus
  54. }
  55. #endif
  56. #endif
  57. #endif
  58. /** @}*/