fips_drbg.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2014, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. */
  14. #ifndef __MSM_FIPS_DRBG_H__
  15. #define __MSM_FIPS_DRBG_H__
  16. #include "ctr_drbg.h"
  17. #include "msm_rng.h"
  18. #define FIPS140_PRNG_OK (0)
  19. #define FIPS140_PRNG_ERR (-1)
  20. typedef int (*get_entropy_callback_t)(void *ctx, void *buf);
  21. struct fips_drbg_ctx_s {
  22. uint32_t magic; /* for checking that ctx is likely valid */
  23. get_entropy_callback_t get_entropy_callback;
  24. void *get_entropy_callback_ctx;
  25. struct ctr_drbg_ctx_s ctr_drbg_ctx;
  26. uint8_t fips_drbg_started;
  27. uint8_t prev_hw_drbg_block[Q_HW_DRBG_BLOCK_BYTES];
  28. };
  29. /*
  30. * initialize *ctx, requesting automatic reseed after reseed_interval
  31. * calls to qpsi_rng_gen. callback is a function to get entropy.
  32. * callback_ctx is a pointer to any context structure that function
  33. * may need. (Pass NULL if no context structure is needed.) callback
  34. * must return zero or a positive number on success, and a
  35. * negative number on an error.
  36. */
  37. int fips_drbg_init(struct msm_rng_device *msm_rng_ctx);
  38. /* generated random data. Returns 0 on success, -1 on failures */
  39. int fips_drbg_gen(struct fips_drbg_ctx_s *ctx, void *tgt, size_t len);
  40. /* free resources and zeroize state */
  41. /* Failure to call fips_drbg_final is not a security issue, since
  42. CTR_DRBG provides backtracking resistance by updating Key and V
  43. immediately after the data has been generated but before the
  44. generate function returns. But it is a resource issue (except at
  45. program termination), as it abandons a FILE structure and a file
  46. descriptor. */
  47. void fips_drbg_final(struct fips_drbg_ctx_s *ctx);
  48. #endif /* __MSM_FIPS_DRBG_H__ */