provider_util.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright 2019 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. #include <openssl/provider.h>
  10. #include <openssl/engine.h>
  11. typedef struct {
  12. /*
  13. * References to the underlying cipher implementation. |cipher| caches
  14. * the cipher, always. |alloc_cipher| only holds a reference to an
  15. * explicitly fetched cipher.
  16. */
  17. const EVP_CIPHER *cipher; /* cipher */
  18. EVP_CIPHER *alloc_cipher; /* fetched cipher */
  19. /* Conditions for legacy EVP_CIPHER uses */
  20. ENGINE *engine; /* cipher engine */
  21. } PROV_CIPHER;
  22. typedef struct {
  23. /*
  24. * References to the underlying digest implementation. |md| caches
  25. * the digest, always. |alloc_md| only holds a reference to an explicitly
  26. * fetched digest.
  27. */
  28. const EVP_MD *md; /* digest */
  29. EVP_MD *alloc_md; /* fetched digest */
  30. /* Conditions for legacy EVP_MD uses */
  31. ENGINE *engine; /* digest engine */
  32. } PROV_DIGEST;
  33. /* Cipher functions */
  34. /*
  35. * Load a cipher from the specified parameters with the specified context.
  36. * The params "properties", "engine" and "cipher" are used to determine the
  37. * implementation used. If a provider cannot be found, it falls back to trying
  38. * non-provider based implementations.
  39. */
  40. int ossl_prov_cipher_load_from_params(PROV_CIPHER *pc,
  41. const OSSL_PARAM params[],
  42. OPENSSL_CTX *ctx);
  43. /* Reset the PROV_CIPHER fields and free any allocated cipher reference */
  44. void ossl_prov_cipher_reset(PROV_CIPHER *pc);
  45. /* Clone a PROV_CIPHER structure into a second */
  46. int ossl_prov_cipher_copy(PROV_CIPHER *dst, const PROV_CIPHER *src);
  47. /* Query the cipher and associated engine (if any) */
  48. const EVP_CIPHER *ossl_prov_cipher_cipher(const PROV_CIPHER *pc);
  49. ENGINE *ossl_prov_cipher_engine(const PROV_CIPHER *pc);
  50. /* Digest functions */
  51. /*
  52. * Load a digest from the specified parameters with the specified context.
  53. * The params "properties", "engine" and "digest" are used to determine the
  54. * implementation used. If a provider cannot be found, it falls back to trying
  55. * non-provider based implementations.
  56. */
  57. int ossl_prov_digest_load_from_params(PROV_DIGEST *pd,
  58. const OSSL_PARAM params[],
  59. OPENSSL_CTX *ctx);
  60. /* Reset the PROV_DIGEST fields and free any allocated digest reference */
  61. void ossl_prov_digest_reset(PROV_DIGEST *pd);
  62. /* Clone a PROV_DIGEST structure into a second */
  63. int ossl_prov_digest_copy(PROV_DIGEST *dst, const PROV_DIGEST *src);
  64. /* Query the digest and associated engine (if any) */
  65. const EVP_MD *ossl_prov_digest_md(const PROV_DIGEST *pd);
  66. ENGINE *ossl_prov_digest_engine(const PROV_DIGEST *pd);
  67. /* MAC functions */
  68. /*
  69. * Load an EVP_MAC_CTX* from the specified parameters with the specified
  70. * library context.
  71. * The params "mac" and "properties" are used to determine the implementation
  72. * used, and the parameters "digest", "cipher", "engine" and "properties" are
  73. * passed to the MAC via the created MAC context if they are given.
  74. * If there is already a created MAC context, it will be replaced if the "mac"
  75. * parameter is found, otherwise it will simply be used as is, and passed the
  76. * parameters to pilfer as it sees fit.
  77. *
  78. * As an option, a MAC name may be explicitly given, and if it is, the "mac"
  79. * parameter will be ignored.
  80. * Similarly, as an option, a cipher name or a digest name may be explicitly
  81. * given, and if any of them is, the "digest" and "cipher" parameters are
  82. * ignored.
  83. */
  84. int ossl_prov_macctx_load_from_params(EVP_MAC_CTX **macctx,
  85. const OSSL_PARAM params[],
  86. const char *macname,
  87. const char *ciphername,
  88. const char *mdname,
  89. OPENSSL_CTX *ctx);