ec.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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_EC_H
  10. #define GMSSL_EC_H
  11. #include <time.h>
  12. #include <string.h>
  13. #include <stdint.h>
  14. #include <stdlib.h>
  15. #include <gmssl/sm2.h>
  16. #include <gmssl/oid.h>
  17. #include <gmssl/asn1.h>
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /*
  22. NamedCurve:
  23. OID_sm2
  24. OID_prime192v1
  25. OID_prime256v1
  26. OID_secp256k1
  27. OID_secp384r1
  28. OID_secp521r1
  29. */
  30. const char *ec_named_curve_name(int curve);
  31. int ec_named_curve_from_name(const char *name);
  32. int ec_named_curve_to_der(int curve, uint8_t **out, size_t *outlen);
  33. int ec_named_curve_from_der(int *curve, const uint8_t **in, size_t *inlen);
  34. /*
  35. ECPoint ::= OCTET STRING -- uncompressed point
  36. */
  37. int ec_point_print(FILE *fp, int fmt, int ind, const char *label, const uint8_t *d, size_t dlen);
  38. /*
  39. ECPrivateKey ::= SEQUENCE {
  40. version INTEGER, -- value MUST be (1)
  41. privateKey OCTET STRING, -- big endian encoding of integer
  42. parameters [0] EXPLICIT OBJECT IDENTIFIER OPTIONAL, -- namedCurve
  43. publicKey [1] EXPLICIT BIT STRING OPTIONAL -- ECPoint
  44. }
  45. */
  46. enum {
  47. EC_private_key_version = 1,
  48. };
  49. int ec_private_key_print(FILE *fp, int fmt, int ind, const char *label, const uint8_t *d, size_t dlen);
  50. #ifdef __cplusplus
  51. }
  52. #endif
  53. #endif