2
0

asn1.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (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. struct evp_pkey_asn1_method_st {
  12. int pkey_id;
  13. int pkey_base_id;
  14. unsigned long pkey_flags;
  15. char *pem_str;
  16. char *info;
  17. int (*pub_decode) (EVP_PKEY *pk, X509_PUBKEY *pub);
  18. int (*pub_encode) (X509_PUBKEY *pub, const EVP_PKEY *pk);
  19. int (*pub_cmp) (const EVP_PKEY *a, const EVP_PKEY *b);
  20. int (*pub_print) (BIO *out, const EVP_PKEY *pkey, int indent,
  21. ASN1_PCTX *pctx);
  22. int (*priv_decode) (EVP_PKEY *pk, const PKCS8_PRIV_KEY_INFO *p8inf);
  23. int (*priv_encode) (PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk);
  24. int (*priv_print) (BIO *out, const EVP_PKEY *pkey, int indent,
  25. ASN1_PCTX *pctx);
  26. int (*pkey_size) (const EVP_PKEY *pk);
  27. int (*pkey_bits) (const EVP_PKEY *pk);
  28. int (*pkey_security_bits) (const EVP_PKEY *pk);
  29. int (*param_decode) (EVP_PKEY *pkey,
  30. const unsigned char **pder, int derlen);
  31. int (*param_encode) (const EVP_PKEY *pkey, unsigned char **pder);
  32. int (*param_missing) (const EVP_PKEY *pk);
  33. int (*param_copy) (EVP_PKEY *to, const EVP_PKEY *from);
  34. int (*param_cmp) (const EVP_PKEY *a, const EVP_PKEY *b);
  35. int (*param_print) (BIO *out, const EVP_PKEY *pkey, int indent,
  36. ASN1_PCTX *pctx);
  37. int (*sig_print) (BIO *out,
  38. const X509_ALGOR *sigalg, const ASN1_STRING *sig,
  39. int indent, ASN1_PCTX *pctx);
  40. void (*pkey_free) (EVP_PKEY *pkey);
  41. int (*pkey_ctrl) (EVP_PKEY *pkey, int op, long arg1, void *arg2);
  42. /* Legacy functions for old PEM */
  43. int (*old_priv_decode) (EVP_PKEY *pkey,
  44. const unsigned char **pder, int derlen);
  45. int (*old_priv_encode) (const EVP_PKEY *pkey, unsigned char **pder);
  46. /* Custom ASN1 signature verification */
  47. int (*item_verify) (EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
  48. X509_ALGOR *a, ASN1_BIT_STRING *sig, EVP_PKEY *pkey);
  49. int (*item_sign) (EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
  50. X509_ALGOR *alg1, X509_ALGOR *alg2,
  51. ASN1_BIT_STRING *sig);
  52. int (*siginf_set) (X509_SIG_INFO *siginf, const X509_ALGOR *alg,
  53. const ASN1_STRING *sig);
  54. /* Check */
  55. int (*pkey_check) (const EVP_PKEY *pk);
  56. int (*pkey_public_check) (const EVP_PKEY *pk);
  57. int (*pkey_param_check) (const EVP_PKEY *pk);
  58. /* Get/set raw private/public key data */
  59. int (*set_priv_key) (EVP_PKEY *pk, const unsigned char *priv, size_t len);
  60. int (*set_pub_key) (EVP_PKEY *pk, const unsigned char *pub, size_t len);
  61. int (*get_priv_key) (const EVP_PKEY *pk, unsigned char *priv, size_t *len);
  62. int (*get_pub_key) (const EVP_PKEY *pk, unsigned char *pub, size_t *len);
  63. } /* EVP_PKEY_ASN1_METHOD */ ;
  64. DEFINE_STACK_OF_CONST(EVP_PKEY_ASN1_METHOD)
  65. extern const EVP_PKEY_ASN1_METHOD cmac_asn1_meth;
  66. extern const EVP_PKEY_ASN1_METHOD dh_asn1_meth;
  67. extern const EVP_PKEY_ASN1_METHOD dhx_asn1_meth;
  68. extern const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[5];
  69. extern const EVP_PKEY_ASN1_METHOD eckey_asn1_meth;
  70. extern const EVP_PKEY_ASN1_METHOD ecx25519_asn1_meth;
  71. extern const EVP_PKEY_ASN1_METHOD ecx448_asn1_meth;
  72. extern const EVP_PKEY_ASN1_METHOD ed25519_asn1_meth;
  73. extern const EVP_PKEY_ASN1_METHOD ed448_asn1_meth;
  74. extern const EVP_PKEY_ASN1_METHOD sm2_asn1_meth;
  75. extern const EVP_PKEY_ASN1_METHOD poly1305_asn1_meth;
  76. extern const EVP_PKEY_ASN1_METHOD hmac_asn1_meth;
  77. extern const EVP_PKEY_ASN1_METHOD rsa_asn1_meths[2];
  78. extern const EVP_PKEY_ASN1_METHOD rsa_pss_asn1_meth;
  79. extern const EVP_PKEY_ASN1_METHOD siphash_asn1_meth;
  80. /*
  81. * These are used internally in the ASN1_OBJECT to keep track of whether the
  82. * names and data need to be free()ed
  83. */
  84. # define ASN1_OBJECT_FLAG_DYNAMIC 0x01/* internal use */
  85. # define ASN1_OBJECT_FLAG_CRITICAL 0x02/* critical x509v3 object id */
  86. # define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04/* internal use */
  87. # define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08/* internal use */
  88. struct asn1_object_st {
  89. const char *sn, *ln;
  90. int nid;
  91. int length;
  92. const unsigned char *data; /* data remains const after init */
  93. int flags; /* Should we free this one */
  94. };
  95. /* ASN1 print context structure */
  96. struct asn1_pctx_st {
  97. unsigned long flags;
  98. unsigned long nm_flags;
  99. unsigned long cert_flags;
  100. unsigned long oid_flags;
  101. unsigned long str_flags;
  102. } /* ASN1_PCTX */ ;
  103. int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb);