sm4_rng.h 974 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the License); you may
  5. * not use this file except in compliance with the License.
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. */
  9. #ifndef GMSSL_SM4_RNG_H
  10. #define GMSSL_SM4_RNG_H
  11. #include <time.h>
  12. #include <stdint.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #define SM4_RNG_MAX_RESEED_COUNTER (1<<20)
  17. #define SM4_RNG_MAX_RESEED_SECONDS 600
  18. typedef struct {
  19. uint8_t V[16];
  20. uint8_t K[16];
  21. uint32_t reseed_counter;
  22. time_t last_reseed_time;
  23. } SM4_RNG;
  24. int sm4_rng_init(SM4_RNG *rng, const uint8_t *nonce, size_t nonce_len,
  25. const uint8_t *label, size_t label_len);
  26. int sm4_rng_update(SM4_RNG *rng, const uint8_t seed[32]);
  27. int sm4_rng_reseed(SM4_RNG *rng, const uint8_t *addin, size_t addin_len);
  28. int sm4_rng_generate(SM4_RNG *rng, const uint8_t *addin, size_t addin_len,
  29. uint8_t *out, size_t outlen);
  30. #ifdef __cplusplus
  31. }
  32. #endif
  33. #endif