2
0

provider-signature.pod 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. =pod
  2. =head1 NAME
  3. provider-signature - The signature library E<lt>-E<gt> provider functions
  4. =head1 SYNOPSIS
  5. =for openssl multiple includes
  6. #include <openssl/core_numbers.h>
  7. #include <openssl/core_names.h>
  8. /*
  9. * None of these are actual functions, but are displayed like this for
  10. * the function signatures for functions that are offered as function
  11. * pointers in OSSL_DISPATCH arrays.
  12. */
  13. /* Context management */
  14. void *OP_signature_newctx(void *provctx);
  15. void OP_signature_freectx(void *ctx);
  16. void *OP_signature_dupctx(void *ctx);
  17. /* Signing */
  18. int OP_signature_sign_init(void *ctx, void *provkey);
  19. int OP_signature_sign(void *ctx, unsigned char *sig, size_t *siglen,
  20. size_t sigsize, const unsigned char *tbs, size_t tbslen);
  21. /* Verifying */
  22. int OP_signature_verify_init(void *ctx, void *provkey);
  23. int OP_signature_verify(void *ctx, const unsigned char *sig, size_t siglen,
  24. const unsigned char *tbs, size_t tbslen);
  25. /* Verify Recover */
  26. int OP_signature_verify_recover_init(void *ctx, void *provkey);
  27. int OP_signature_verify_recover(void *ctx, unsigned char *rout,
  28. size_t *routlen, size_t routsize,
  29. const unsigned char *sig, size_t siglen);
  30. /* Signature parameters */
  31. int OP_signature_get_ctx_params(void *ctx, OSSL_PARAM params[]);
  32. const OSSL_PARAM *OP_signature_gettable_ctx_params(void);
  33. int OP_signature_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
  34. const OSSL_PARAM *OP_signature_settable_ctx_params(void);
  35. =head1 DESCRIPTION
  36. This documentation is primarily aimed at provider authors. See L<provider(7)>
  37. for further information.
  38. The signature (OSSL_OP_SIGNATURE) operation enables providers to implement
  39. signature algorithms and make them available to applications via the API
  40. functions L<EVP_PKEY_sign(3)>,
  41. L<EVP_PKEY_verify(3)>,
  42. and L<EVP_PKEY_verify_recover(3)> (as well
  43. as other related functions).
  44. All "functions" mentioned here are passed as function pointers between
  45. F<libcrypto> and the provider in B<OSSL_DISPATCH> arrays via
  46. B<OSSL_ALGORITHM> arrays that are returned by the provider's
  47. provider_query_operation() function
  48. (see L<provider-base(7)/Provider Functions>).
  49. All these "functions" have a corresponding function type definition
  50. named B<OSSL_{name}_fn>, and a helper function to retrieve the
  51. function pointer from an B<OSSL_DISPATCH> element named
  52. B<OSSL_get_{name}>.
  53. For example, the "function" OP_signature_newctx() has these:
  54. typedef void *(OSSL_OP_signature_newctx_fn)(void *provctx);
  55. static ossl_inline OSSL_OP_signature_newctx_fn
  56. OSSL_get_OP_signature_newctx(const OSSL_DISPATCH *opf);
  57. B<OSSL_DISPATCH> arrays are indexed by numbers that are provided as
  58. macros in L<openssl-core_numbers.h(7)>, as follows:
  59. OP_signature_newctx OSSL_FUNC_SIGNATURE_NEWCTX
  60. OP_signature_freectx OSSL_FUNC_SIGNATURE_FREECTX
  61. OP_signature_dupctx OSSL_FUNC_SIGNATURE_DUPCTX
  62. OP_signature_sign_init OSSL_FUNC_SIGNATURE_SIGN_INIT
  63. OP_signature_sign OSSL_FUNC_SIGNATURE_SIGN
  64. OP_signature_verify_init OSSL_FUNC_SIGNATURE_VERIFY_INIT
  65. OP_signature_verify OSSL_FUNC_SIGNATURE_VERIFY
  66. OP_signature_verify_recover_init OSSL_FUNC_SIGNATURE_VERIFY_RECOVER_INIT
  67. OP_signature_verify_recover OSSL_FUNC_SIGNATURE_VERIFY_RECOVER
  68. OP_signature_get_ctx_params OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS
  69. OP_signature_gettable_ctx_params OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS
  70. OP_signature_set_ctx_params OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS
  71. OP_signature_settable_ctx_params OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS
  72. A signature algorithm implementation may not implement all of these functions.
  73. In order to be a consistent set of functions a provider must implement
  74. OP_signature_newctx and OP_signature_freectx.
  75. It must also implement both of OP_signature_sign_init and OP_signature_sign,
  76. or both of OP_signature_verify_init and OP_signature_verify, or both of
  77. OP_signature_verify_recover_init and OP_signature_verify_recover.
  78. All other functions are optional.
  79. A signature algorithm must also implement some mechanism for generating,
  80. loading or importing keys via the key management (OSSL_OP_KEYMGMT) operation.
  81. See L<provider-keymgmt(7)> for further details.
  82. =head2 Context Management Functions
  83. OP_signature_newctx() should create and return a pointer to a provider side
  84. structure for holding context information during a signature operation.
  85. A pointer to this context will be passed back in a number of the other signature
  86. operation function calls.
  87. The parameter I<provctx> is the provider context generated during provider
  88. initialisation (see L<provider(7)>).
  89. OP_signature_freectx() is passed a pointer to the provider side signature
  90. context in the I<ctx> parameter.
  91. This function should free any resources associated with that context.
  92. OP_signature_dupctx() should duplicate the provider side signature context in
  93. the I<ctx> parameter and return the duplicate copy.
  94. =head2 Signing Functions
  95. OP_signature_sign_init() initialises a context for signing given a provider side
  96. signature context in the I<ctx> parameter, and a pointer to a provider key object
  97. in the I<provkey> parameter.
  98. The key object should have been previously generated, loaded or imported into
  99. the provider using the key management (OSSL_OP_KEYMGMT) operation (see
  100. provider-keymgmt(7)>.
  101. OP_signature_sign() performs the actual signing itself.
  102. A previously initialised signature context is passed in the I<ctx>
  103. parameter.
  104. The data to be signed is pointed to be the I<tbs> parameter which is I<tbslen>
  105. bytes long.
  106. Unless I<sig> is NULL, the signature should be written to the location pointed
  107. to by the I<sig> parameter and it should not exceed I<sigsize> bytes in length.
  108. The length of the signature should be written to I<*siglen>.
  109. If I<sig> is NULL then the maximum length of the signature should be written to
  110. I<*siglen>.
  111. =head2 Verify Functions
  112. OP_signature_verify_init() initialises a context for verifying a signature given
  113. a provider side signature context in the I<ctx> parameter, and a pointer to a
  114. provider key object in the I<provkey> parameter.
  115. The key object should have been previously generated, loaded or imported into
  116. the provider using the key management (OSSL_OP_KEYMGMT) operation (see
  117. provider-keymgmt(7)>.
  118. OP_signature_verify() performs the actual verification itself.
  119. A previously initialised signature context is passed in the I<ctx> parameter.
  120. The data that the signature covers is pointed to be the I<tbs> parameter which
  121. is I<tbslen> bytes long.
  122. The signature is pointed to by the I<sig> parameter which is I<siglen> bytes
  123. long.
  124. =head2 Verify Recover Functions
  125. OP_signature_verify_recover_init() initialises a context for recovering the
  126. signed data given a provider side signature context in the I<ctx> parameter, and
  127. a pointer to a provider key object in the I<provkey> parameter.
  128. The key object should have been previously generated, loaded or imported into
  129. the provider using the key management (OSSL_OP_KEYMGMT) operation (see
  130. provider-keymgmt(7)>.
  131. OP_signature_verify_recover() performs the actual verify recover itself.
  132. A previously initialised signature context is passed in the I<ctx> parameter.
  133. The signature is pointed to by the I<sig> parameter which is I<siglen> bytes
  134. long.
  135. Unless I<rout> is NULL, the recovered data should be written to the location
  136. pointed to by I<rout> which should not exceed I<routsize> bytes in length.
  137. The length of the recovered data should be written to I<*routlen>.
  138. If I<rout> is NULL then the maximum size of the output buffer is written to
  139. the I<routlen> parameter.
  140. =head2 Signature Parameters
  141. See L<OSSL_PARAM(3)> for further details on the parameters structure used by
  142. the OP_signature_get_ctx_params() and OP_signature_set_ctx_params() functions.
  143. OP_signature_get_ctx_params() gets signature parameters associated with the
  144. given provider side signature context I<ctx> and stored them in I<params>.
  145. OP_signature_set_ctx_params() sets the signature parameters associated with the
  146. given provider side signature context I<ctx> to I<params>.
  147. Any parameter settings are additional to any that were previously set.
  148. Parameters currently recognised by built-in signature algorithms are as
  149. follows.
  150. Not all parameters are relevant to, or are understood by all signature
  151. algorithms:
  152. =over 4
  153. =item "digest" (B<OSSL_SIGNATURE_PARAM_DIGEST>) <UTF8 string>
  154. Get or sets the name of the digest algorithm used for the input to the signature
  155. functions.
  156. =item "digest-size" (B<OSSL_SIGNATURE_PARAM_DIGEST_SIZE>) <unsigned integer>
  157. Gets or sets the output size of the digest algorithm used for the input to the
  158. signature functions.
  159. The length of the "digest-size" parameter should not exceed that of a B<size_t>.
  160. =back
  161. OP_signature_gettable_ctx_params() and OP_signature_settable_ctx_params() get a
  162. constant B<OSSL_PARAM> array that describes the gettable and settable parameters,
  163. i.e. parameters that can be used with OP_signature_get_ctx_params() and
  164. OP_signature_set_ctx_params() respectively.
  165. See L<OSSL_PARAM(3)> for the use of B<OSSL_PARAM> as parameter descriptor.
  166. =head1 RETURN VALUES
  167. OP_signature_newctx() and OP_signature_dupctx() should return the newly created
  168. provider side signature, or NULL on failure.
  169. All other functions should return 1 for success or 0 on error.
  170. =head1 SEE ALSO
  171. L<provider(7)>
  172. =head1 HISTORY
  173. The provider SIGNATURE interface was introduced in OpenSSL 3.0.
  174. =head1 COPYRIGHT
  175. Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
  176. Licensed under the Apache License 2.0 (the "License"). You may not use
  177. this file except in compliance with the License. You can obtain a copy
  178. in the file LICENSE in the source distribution or at
  179. L<https://www.openssl.org/source/license.html>.
  180. =cut