sm2_key_share.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. // SM2 Key Shamir Secret Sharing
  10. #ifndef GMSSL_SM2_KEY_SHARE_H
  11. #define GMSSL_SM2_KEY_SHARE_H
  12. #include <stdio.h>
  13. #include <stdint.h>
  14. #include <stdlib.h>
  15. #include <gmssl/sm2.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #define SM2_KEY_MAX_SHARES 12 // 12! = 479001600 < 2^31 = 2147483648
  20. typedef struct {
  21. SM2_KEY key;
  22. size_t index;
  23. size_t total_cnt;
  24. } SM2_KEY_SHARE;
  25. int sm2_key_split(const SM2_KEY *key, size_t recover_cnt, size_t total_cnt, SM2_KEY_SHARE *shares);
  26. int sm2_key_recover(SM2_KEY *key, const SM2_KEY_SHARE *shares, size_t shares_cnt);
  27. int sm2_key_share_encrypt_to_file(const SM2_KEY_SHARE *share, const char *pass, const char *path_prefix);
  28. int sm2_key_share_decrypt_from_file(SM2_KEY_SHARE *share, const char *pass, const char *file);
  29. int sm2_key_share_print(FILE *fp, int fmt, int ind, const char *label, const SM2_KEY_SHARE *share);
  30. #ifdef __cplusplus
  31. }
  32. #endif
  33. #endif