sm2_committest.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #include <stdio.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include <stdint.h>
  13. #include <gmssl/sm2.h>
  14. #include <gmssl/sm2_commit.h>
  15. #include <gmssl/error.h>
  16. static int test_sm2_commit(void)
  17. {
  18. uint8_t x[32];
  19. uint8_t xvec[8][32];
  20. uint8_t r[32];
  21. uint8_t commit[65];
  22. size_t commitlen;
  23. int ret;
  24. rand_bytes(x, sizeof(x));
  25. format_bytes(stderr, 0, 0, "secret", x, sizeof(x));
  26. sm2_commit_generate(x, r, commit, &commitlen);
  27. format_bytes(stderr, 0, 0, "random", r, sizeof(r));
  28. format_bytes(stderr, 0, 0, "commitment", commit, commitlen);
  29. ret = sm2_commit_open(x, r, commit, commitlen);
  30. printf("open commitment: %s\n", ret == 1 ? "success" : "failure");
  31. sm2_commit_vector_generate(&x, 1, r, commit, &commitlen);
  32. format_bytes(stderr, 0, 0, "random", r, sizeof(r));
  33. format_bytes(stderr, 0, 0, "commitment", commit, commitlen);
  34. ret = sm2_commit_vector_open(&x, 1, r, commit, commitlen);
  35. printf("open commitment: %s\n", ret == 1 ? "success" : "failure");
  36. rand_bytes(xvec[0], sizeof(xvec));
  37. sm2_commit_vector_generate(xvec, 8, r, commit, &commitlen);
  38. ret = sm2_commit_vector_open(xvec, 8, r, commit, commitlen);
  39. printf("open commitment: %s\n", ret == 1 ? "success" : "failure");
  40. return 1;
  41. }
  42. int main(void)
  43. {
  44. if (test_sm2_commit() != 1) { error_print(); return -1; }
  45. return 0;
  46. }