hardware_rng.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. ******************************************************************************
  3. * @file hardware_rng.c
  4. * @author MCD Application Team
  5. * @version V1.1.0
  6. * @date 17-February-2017
  7. * @brief mbedtls entropy data generator using the HAL_RNG API.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  12. *
  13. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  14. * You may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at:
  16. *
  17. * http://www.st.com/software_license_agreement_liberty_v2
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. *
  25. ******************************************************************************
  26. */
  27. #include "mbedtls_config.h"
  28. #include "rng.h"
  29. #ifdef MBEDTLS_ENTROPY_HARDWARE_ALT
  30. #include "main.h"
  31. #include <string.h>
  32. #include "mbedtls/entropy_poll.h"
  33. int mbedtls_hardware_poll( void *Data, unsigned char *Output, size_t Len, size_t *oLen )
  34. {
  35. uint32_t index;
  36. uint32_t randomValue;
  37. for (index = 0; index < Len/4; index++)
  38. {
  39. randomValue = GetRandomNumber();
  40. *oLen += 4;
  41. memset(&(Output[index * 4]), (int)randomValue, 4);
  42. }
  43. return 0;
  44. }
  45. #endif /*MBEDTLS_ENTROPY_HARDWARE_ALT*/