asn1.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. /* Internal ASN1 structures and functions: not for application use */
  10. /* ASN1 public key method structure */
  11. #include <openssl/core.h>
  12. struct evp_pkey_asn1_method_st {
  13. int pkey_id;
  14. int pkey_base_id;
  15. unsigned long pkey_flags;
  16. char *pem_str;
  17. char *info;
  18. int (*pub_decode) (EVP_PKEY *pk, const X509_PUBKEY *pub);
  19. int (*pub_encode) (X509_PUBKEY *pub, const EVP_PKEY *pk);
  20. int (*pub_cmp) (const EVP_PKEY *a, const EVP_PKEY *b);
  21. int (*pub_print) (BIO *out, const EVP_PKEY *pkey, int indent,
  22. ASN1_PCTX *pctx);
  23. int (*priv_decode) (EVP_PKEY *pk, const PKCS8_PRIV_KEY_INFO *p8inf);
  24. int (*priv_encode) (PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk);
  25. int (*priv_print) (BIO *out, const EVP_PKEY *pkey, int indent,
  26. ASN1_PCTX *pctx);
  27. int (*pkey_size) (const EVP_PKEY *pk);
  28. int (*pkey_bits) (const EVP_PKEY *pk);
  29. int (*pkey_security_bits) (const EVP_PKEY *pk);
  30. int (*param_decode) (EVP_PKEY *pkey,
  31. const unsigned char **pder, int derlen);
  32. int (*param_encode) (const EVP_PKEY *pkey, unsigned char **pder);
  33. int (*param_missing) (const EVP_PKEY *pk);
  34. int (*param_copy) (EVP_PKEY *to, const EVP_PKEY *from);
  35. int (*param_cmp) (const EVP_PKEY *a, const EVP_PKEY *b);
  36. int (*param_print) (BIO *out, const EVP_PKEY *pkey, int indent,
  37. ASN1_PCTX *pctx);
  38. int (*sig_print) (BIO *out,
  39. const X509_ALGOR *sigalg, const ASN1_STRING *sig,
  40. int indent, ASN1_PCTX *pctx);
  41. void (*pkey_free) (EVP_PKEY *pkey);
  42. int (*pkey_ctrl) (EVP_PKEY *pkey, int op, long arg1, void *arg2);
  43. /* Legacy functions for old PEM */
  44. int (*old_priv_decode) (EVP_PKEY *pkey,
  45. const unsigned char **pder, int derlen);
  46. int (*old_priv_encode) (const EVP_PKEY *pkey, unsigned char **pder);
  47. /* Custom ASN1 signature verification */
  48. int (*item_verify) (EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
  49. X509_ALGOR *a, ASN1_BIT_STRING *sig, EVP_PKEY *pkey);
  50. int (*item_sign) (EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
  51. X509_ALGOR *alg1, X509_ALGOR *alg2,
  52. ASN1_BIT_STRING *sig);
  53. int (*siginf_set) (X509_SIG_INFO *siginf, const X509_ALGOR *alg,
  54. const ASN1_STRING *sig);
  55. /* Check */
  56. int (*pkey_check) (const EVP_PKEY *pk);
  57. int (*pkey_public_check) (const EVP_PKEY *pk);
  58. int (*pkey_param_check) (const EVP_PKEY *pk);
  59. /* Get/set raw private/public key data */
  60. int (*set_priv_key) (EVP_PKEY *pk, const unsigned char *priv, size_t len);
  61. int (*set_pub_key) (EVP_PKEY *pk, const unsigned char *pub, size_t len);
  62. int (*get_priv_key) (const EVP_PKEY *pk, unsigned char *priv, size_t *len);
  63. int (*get_pub_key) (const EVP_PKEY *pk, unsigned char *pub, size_t *len);
  64. /*
  65. * TODO: Make sure these functions are defined for key types that are
  66. * implemented in providers.
  67. */
  68. /* Exports and imports to / from providers */
  69. size_t (*dirty_cnt) (const EVP_PKEY *pk);
  70. int (*export_to) (const EVP_PKEY *pk, void *to_keydata,
  71. EVP_KEYMGMT *to_keymgmt, OPENSSL_CTX *libctx,
  72. const char *propq);
  73. OSSL_CALLBACK *import_from;
  74. int (*priv_decode_with_libctx) (EVP_PKEY *pk,
  75. const PKCS8_PRIV_KEY_INFO *p8inf,
  76. OPENSSL_CTX *libctx,
  77. const char *propq);
  78. } /* EVP_PKEY_ASN1_METHOD */ ;
  79. DEFINE_STACK_OF_CONST(EVP_PKEY_ASN1_METHOD)
  80. extern const EVP_PKEY_ASN1_METHOD cmac_asn1_meth;
  81. extern const EVP_PKEY_ASN1_METHOD dh_asn1_meth;
  82. extern const EVP_PKEY_ASN1_METHOD dhx_asn1_meth;
  83. extern const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[5];
  84. extern const EVP_PKEY_ASN1_METHOD eckey_asn1_meth;
  85. extern const EVP_PKEY_ASN1_METHOD ecx25519_asn1_meth;
  86. extern const EVP_PKEY_ASN1_METHOD ecx448_asn1_meth;
  87. extern const EVP_PKEY_ASN1_METHOD ed25519_asn1_meth;
  88. extern const EVP_PKEY_ASN1_METHOD ed448_asn1_meth;
  89. extern const EVP_PKEY_ASN1_METHOD sm2_asn1_meth;
  90. extern const EVP_PKEY_ASN1_METHOD poly1305_asn1_meth;
  91. extern const EVP_PKEY_ASN1_METHOD hmac_asn1_meth;
  92. extern const EVP_PKEY_ASN1_METHOD rsa_asn1_meths[2];
  93. extern const EVP_PKEY_ASN1_METHOD rsa_pss_asn1_meth;
  94. extern const EVP_PKEY_ASN1_METHOD siphash_asn1_meth;
  95. /*
  96. * These are used internally in the ASN1_OBJECT to keep track of whether the
  97. * names and data need to be free()ed
  98. */
  99. # define ASN1_OBJECT_FLAG_DYNAMIC 0x01/* internal use */
  100. # define ASN1_OBJECT_FLAG_CRITICAL 0x02/* critical x509v3 object id */
  101. # define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04/* internal use */
  102. # define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08/* internal use */
  103. struct asn1_object_st {
  104. const char *sn, *ln;
  105. int nid;
  106. int length;
  107. const unsigned char *data; /* data remains const after init */
  108. int flags; /* Should we free this one */
  109. };
  110. /* ASN1 print context structure */
  111. struct asn1_pctx_st {
  112. unsigned long flags;
  113. unsigned long nm_flags;
  114. unsigned long cert_flags;
  115. unsigned long oid_flags;
  116. unsigned long str_flags;
  117. } /* ASN1_PCTX */ ;
  118. int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb);