Home | History | Annotate | Line # | Download | only in man7
      1 =pod
      2 
      3 =head1 NAME
      4 
      5 provider-signature - The signature library E<lt>-E<gt> provider functions
      6 
      7 =head1 SYNOPSIS
      8 
      9 =for openssl multiple includes
     10 
     11  #include <openssl/core_dispatch.h>
     12  #include <openssl/core_names.h>
     13 
     14  /*
     15   * None of these are actual functions, but are displayed like this for
     16   * the function signatures for functions that are offered as function
     17   * pointers in OSSL_DISPATCH arrays.
     18   */
     19 
     20  /* Context management */
     21  void *OSSL_FUNC_signature_newctx(void *provctx, const char *propq);
     22  void OSSL_FUNC_signature_freectx(void *ctx);
     23  void *OSSL_FUNC_signature_dupctx(void *ctx);
     24 
     25  /* Get the key types that a signature algorithm supports */
     26  const char **OSSL_FUNC_signature_query_key_types(void);
     27 
     28  /* Signing */
     29  int OSSL_FUNC_signature_sign_init(void *ctx, void *provkey,
     30                                    const OSSL_PARAM params[]);
     31  int OSSL_FUNC_signature_sign(void *ctx, unsigned char *sig, size_t *siglen,
     32                               size_t sigsize, const unsigned char *tbs, size_t tbslen);
     33  int OSSL_FUNC_signature_sign_message_init(void *ctx, void *provkey,
     34                                            const OSSL_PARAM params[]);
     35  int OSSL_FUNC_signature_sign_message_update(void *ctx, const unsigned char *in,
     36                                              size_t inlen);
     37  int OSSL_FUNC_signature_sign_message_final(void *ctx, unsigned char *sig,
     38                                             size_t *siglen, size_t sigsize);
     39 
     40  /* Verifying */
     41  int OSSL_FUNC_signature_verify_init(void *ctx, void *provkey,
     42                                      const OSSL_PARAM params[]);
     43  int OSSL_FUNC_signature_verify(void *ctx, const unsigned char *sig, size_t siglen,
     44                                 const unsigned char *tbs, size_t tbslen);
     45  int OSSL_FUNC_signature_verify_message_init(void *ctx, void *provkey,
     46                                              const OSSL_PARAM params[]);
     47  int OSSL_FUNC_signature_verify_message_update(void *ctx, const unsigned char *in,
     48                                                size_t inlen);
     49  /*
     50   * OSSL_FUNC_signature_verify_message_final requires that the signature to be
     51   * verified is specified via a "signature" OSSL_PARAM, which is given with a
     52   * previous call of OSSL_FUNC_signature_set_ctx_params().
     53   */
     54  int OSSL_FUNC_signature_verify_message_final(void *ctx);
     55 
     56  /* Verify Recover */
     57  int OSSL_FUNC_signature_verify_recover_init(void *ctx, void *provkey,
     58                                              const OSSL_PARAM params[]);
     59  int OSSL_FUNC_signature_verify_recover(void *ctx, unsigned char *rout,
     60                                         size_t *routlen, size_t routsize,
     61                                         const unsigned char *sig, size_t siglen);
     62 
     63  /* Digest Sign */
     64  int OSSL_FUNC_signature_digest_sign_init(void *ctx, const char *mdname,
     65                                           void *provkey,
     66                                           const OSSL_PARAM params[]);
     67  int OSSL_FUNC_signature_digest_sign_update(void *ctx, const unsigned char *data,
     68                                      size_t datalen);
     69  int OSSL_FUNC_signature_digest_sign_final(void *ctx, unsigned char *sig,
     70                                            size_t *siglen, size_t sigsize);
     71  int OSSL_FUNC_signature_digest_sign(void *ctx,
     72                               unsigned char *sig, size_t *siglen,
     73                               size_t sigsize, const unsigned char *tbs,
     74                               size_t tbslen);
     75 
     76  /* Digest Verify */
     77  int OSSL_FUNC_signature_digest_verify_init(void *ctx, const char *mdname,
     78                                             void *provkey,
     79                                             const OSSL_PARAM params[]);
     80  int OSSL_FUNC_signature_digest_verify_update(void *ctx,
     81                                               const unsigned char *data,
     82                                               size_t datalen);
     83  int OSSL_FUNC_signature_digest_verify_final(void *ctx, const unsigned char *sig,
     84                                       size_t siglen);
     85  int OSSL_FUNC_signature_digest_verify(void *ctx, const unsigned char *sig,
     86                                 size_t siglen, const unsigned char *tbs,
     87                                 size_t tbslen);
     88 
     89  /* Signature parameters */
     90  int OSSL_FUNC_signature_get_ctx_params(void *ctx, OSSL_PARAM params[]);
     91  const OSSL_PARAM *OSSL_FUNC_signature_gettable_ctx_params(void *ctx,
     92                                                            void *provctx);
     93  int OSSL_FUNC_signature_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
     94  const OSSL_PARAM *OSSL_FUNC_signature_settable_ctx_params(void *ctx,
     95                                                            void *provctx);
     96  /* MD parameters */
     97  int OSSL_FUNC_signature_get_ctx_md_params(void *ctx, OSSL_PARAM params[]);
     98  const OSSL_PARAM * OSSL_FUNC_signature_gettable_ctx_md_params(void *ctx);
     99  int OSSL_FUNC_signature_set_ctx_md_params(void *ctx, const OSSL_PARAM params[]);
    100  const OSSL_PARAM * OSSL_FUNC_signature_settable_ctx_md_params(void *ctx);
    101 
    102 =head1 DESCRIPTION
    103 
    104 This documentation is primarily aimed at provider authors. See L<provider(7)>
    105 for further information.
    106 
    107 The signature (OSSL_OP_SIGNATURE) operation enables providers to implement
    108 signature algorithms and make them available to applications via the API
    109 functions L<EVP_PKEY_sign(3)>, L<EVP_PKEY_verify(3)>,
    110 and L<EVP_PKEY_verify_recover(3)> (as well as other related functions).
    111 
    112 All "functions" mentioned here are passed as function pointers between
    113 F<libcrypto> and the provider in L<OSSL_DISPATCH(3)> arrays via
    114 L<OSSL_ALGORITHM(3)> arrays that are returned by the provider's
    115 provider_query_operation() function
    116 (see L<provider-base(7)/Provider Functions>).
    117 
    118 All these "functions" have a corresponding function type definition
    119 named B<OSSL_FUNC_{name}_fn>, and a helper function to retrieve the
    120 function pointer from an L<OSSL_DISPATCH(3)> element named
    121 B<OSSL_FUNC_{name}>.
    122 For example, the "function" OSSL_FUNC_signature_newctx() has these:
    123 
    124  typedef void *(OSSL_FUNC_signature_newctx_fn)(void *provctx, const char *propq);
    125  static ossl_inline OSSL_FUNC_signature_newctx_fn
    126      OSSL_FUNC_signature_newctx(const OSSL_DISPATCH *opf);
    127 
    128 L<OSSL_DISPATCH(3)> arrays are indexed by numbers that are provided as
    129 macros in L<openssl-core_dispatch.h(7)>, as follows:
    130 
    131  OSSL_FUNC_signature_newctx                 OSSL_FUNC_SIGNATURE_NEWCTX
    132  OSSL_FUNC_signature_freectx                OSSL_FUNC_SIGNATURE_FREECTX
    133  OSSL_FUNC_signature_dupctx                 OSSL_FUNC_SIGNATURE_DUPCTX
    134 
    135  OSSL_FUNC_signature_query_key_types        OSSL_FUNC_SIGNATURE_QUERY_KEY_TYPES
    136 
    137  OSSL_FUNC_signature_sign_init              OSSL_FUNC_SIGNATURE_SIGN_INIT
    138  OSSL_FUNC_signature_sign                   OSSL_FUNC_SIGNATURE_SIGN
    139  OSSL_FUNC_signature_sign_message_init      OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_INIT
    140  OSSL_FUNC_signature_sign_message_update    OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_UPDATE
    141  OSSL_FUNC_signature_sign_message_final     OSSL_FUNC_SIGNATURE_SIGN_MESSAGE_FINAL
    142 
    143  OSSL_FUNC_signature_verify_init            OSSL_FUNC_SIGNATURE_VERIFY_INIT
    144  OSSL_FUNC_signature_verify                 OSSL_FUNC_SIGNATURE_VERIFY
    145  OSSL_FUNC_signature_verify_message_init    OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_INIT
    146  OSSL_FUNC_signature_verify_message_update  OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_UPDATE
    147  OSSL_FUNC_signature_verify_message_final   OSSL_FUNC_SIGNATURE_VERIFY_MESSAGE_FINAL
    148 
    149  OSSL_FUNC_signature_verify_recover_init    OSSL_FUNC_SIGNATURE_VERIFY_RECOVER_INIT
    150  OSSL_FUNC_signature_verify_recover         OSSL_FUNC_SIGNATURE_VERIFY_RECOVER
    151 
    152  OSSL_FUNC_signature_digest_sign_init       OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT
    153  OSSL_FUNC_signature_digest_sign_update     OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE
    154  OSSL_FUNC_signature_digest_sign_final      OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL
    155  OSSL_FUNC_signature_digest_sign            OSSL_FUNC_SIGNATURE_DIGEST_SIGN
    156 
    157  OSSL_FUNC_signature_digest_verify_init     OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT
    158  OSSL_FUNC_signature_digest_verify_update   OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE
    159  OSSL_FUNC_signature_digest_verify_final    OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL
    160  OSSL_FUNC_signature_digest_verify          OSSL_FUNC_SIGNATURE_DIGEST_VERIFY
    161 
    162  OSSL_FUNC_signature_get_ctx_params         OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS
    163  OSSL_FUNC_signature_gettable_ctx_params    OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS
    164  OSSL_FUNC_signature_set_ctx_params         OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS
    165  OSSL_FUNC_signature_settable_ctx_params    OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS
    166 
    167  OSSL_FUNC_signature_get_ctx_md_params      OSSL_FUNC_SIGNATURE_GET_CTX_MD_PARAMS
    168  OSSL_FUNC_signature_gettable_ctx_md_params OSSL_FUNC_SIGNATURE_GETTABLE_CTX_MD_PARAMS
    169  OSSL_FUNC_signature_set_ctx_md_params      OSSL_FUNC_SIGNATURE_SET_CTX_MD_PARAMS
    170  OSSL_FUNC_signature_settable_ctx_md_params OSSL_FUNC_SIGNATURE_SETTABLE_CTX_MD_PARAMS
    171 
    172 A signature algorithm implementation may not implement all of these functions.
    173 In order to be a consistent set of functions we must have at least a set of
    174 context functions (OSSL_FUNC_signature_newctx and OSSL_FUNC_signature_freectx) as well as a
    175 set of "signature" functions, i.e. at least one of:
    176 
    177 =over 4
    178 
    179 =item OSSL_FUNC_signature_sign_init and OSSL_FUNC_signature_sign
    180 
    181 Used via L<EVP_PKEY_sign_init(3)> and L<EVP_PKEY_sign(3)>.
    182 These functions operate on pre-digested data (the "to be signed" or TBS value).
    183 
    184 =item OSSL_FUNC_signature_sign_message_init and OSSL_FUNC_signature_sign
    185 
    186 Used via L<EVP_PKEY_sign_message_init(3)> and L<EVP_PKEY_sign(3)> when signing a complete message.
    187 The implementation internally handles message digesting.
    188 
    189 =item OSSL_FUNC_signature_sign_message_init, OSSL_FUNC_signature_sign_message_update and OSSL_FUNC_signature_sign_message_final
    190 
    191 Streaming variant of message signing, used via L<EVP_PKEY_sign_message_init(3)>,
    192 L<EVP_PKEY_sign_message_update(3)>, and L<EVP_PKEY_sign_message_final(3)>.
    193 
    194 =item OSSL_FUNC_signature_verify_init and OSSL_FUNC_signature_verify
    195 
    196 Used via L<EVP_PKEY_verify_init(3)> and L<EVP_PKEY_verify(3)>.
    197 These functions operate on pre-digested data.
    198 
    199 =item OSSL_FUNC_signature_verify_message_init and OSSL_FUNC_signature_verify
    200 
    201 Used via L<EVP_PKEY_verify_message_init(3)> and L<EVP_PKEY_verify(3)> when verifying a complete message.
    202 The implementation internally handles message digesting.
    203 
    204 =item OSSL_FUNC_signature_verify_message_init, OSSL_FUNC_signature_verify_message_update and OSSL_FUNC_signature_verify_message_final
    205 
    206 Streaming variant of message verification, used via L<EVP_PKEY_verify_message_init(3)>,
    207 L<EVP_PKEY_verify_message_update(3)>, and L<EVP_PKEY_verify_message_final(3)>.
    208 
    209 =item OSSL_FUNC_signature_verify_recover_init and OSSL_FUNC_signature_verify_recover
    210 
    211 Used via L<EVP_PKEY_verify_recover_init(3)> and L<EVP_PKEY_verify_recover(3)>.
    212 Applicable only to signature schemes that support signature recovery (such as RSA).
    213 
    214 =item OSSL_FUNC_signature_digest_sign_init, OSSL_FUNC_signature_digest_sign_update and OSSL_FUNC_signature_digest_sign_final
    215 
    216 Streaming digest-sign variant, used via L<EVP_DigestSignInit(3)>,
    217 L<EVP_DigestSignUpdate(3)>, and L<EVP_DigestSignFinal(3)>.
    218 
    219 =item OSSL_FUNC_signature_digest_verify_init, OSSL_FUNC_signature_digest_verify_update and OSSL_FUNC_signature_digest_verify_final
    220 
    221 Streaming digest-verify variant, used via L<EVP_DigestVerifyInit(3)>,
    222 L<EVP_DigestVerifyUpdate(3)>, and L<EVP_DigestVerifyFinal(3)>.
    223 
    224 =item OSSL_FUNC_signature_digest_sign_init and OSSL_FUNC_signature_digest_sign
    225 
    226 One-shot digest-sign variant, used via L<EVP_DigestSign(3)>.
    227 
    228 =item OSSL_FUNC_signature_digest_verify_init and OSSL_FUNC_signature_digest_verify
    229 
    230 One-shot digest-verify variant, used via L<EVP_DigestVerify(3)>.
    231 
    232 =back
    233 
    234 B<Important Note for TLS Support:> For a provider signature implementation to
    235 be usable within F<libssl> for TLS connections, it B<must> implement the
    236 digest-sign and digest-verify functions
    237 (OSSL_FUNC_signature_digest_sign_init/update/final or the one-shot variant, and
    238 OSSL_FUNC_signature_digest_verify_init/update/final or the one-shot variant).
    239 The TLS handshake code in F<libssl> specifically requires these digest functions
    240 and will not use implementations that only provide the basic sign/verify functions
    241 (OSSL_FUNC_signature_sign_init/sign or OSSL_FUNC_signature_verify_init/verify).
    242 
    243 The choice of which function set to implement depends on your use case:
    244 
    245 =over 4
    246 
    247 =item *
    248 
    249 For general-purpose signature operations and TLS support: implement the
    250 digest-sign and digest-verify functions.
    251 
    252 =item *
    253 
    254 For operations on pre-digested data only: implement the basic sign and verify
    255 functions.
    256 
    257 =item *
    258 
    259 For signature schemes with recovery capability: additionally implement the
    260 verify-recover functions.
    261 
    262 =back
    263 
    264 The OSSL_FUNC_signature_set_ctx_params() and
    265 OSSL_FUNC_signature_settable_ctx_params() functions are optional,
    266 but if one of them is provided then the other one must also be provided.
    267 The same applies to the OSSL_FUNC_signature_get_ctx_params() and
    268 OSSL_FUNC_signature_gettable_ctx_params() functions,
    269 as well as the "md_params" functions.
    270 
    271 The OSSL_FUNC_signature_dupctx() function is optional.
    272 
    273 The OSSL_FUNC_signature_query_key_types() function is optional.
    274 When present, it should return a NULL-terminated array of strings
    275 indicating the key types supported by the provider for signature operations.
    276 Otherwise the signature algorithm name must match the given key
    277 or match the default signature algorithm name of the key,
    278 both checked using L<EVP_SIGNATURE_is_a(3)>.
    279 
    280 A signature algorithm must also implement some mechanism for generating,
    281 loading or importing keys via the key management (OSSL_OP_KEYMGMT) operation.
    282 See L<provider-keymgmt(7)> for further details.
    283 
    284 =head2 Context Management Functions
    285 
    286 OSSL_FUNC_signature_newctx() should create and return a pointer to a provider side
    287 structure for holding context information during a signature operation.
    288 A pointer to this context will be passed back in a number of the other signature
    289 operation function calls.
    290 The parameter I<provctx> is the provider context generated during provider
    291 initialisation (see L<provider(7)>). The I<propq> parameter is a property query
    292 string that may be (optionally) used by the provider during any "fetches" that
    293 it may perform (if it performs any).
    294 
    295 OSSL_FUNC_signature_freectx() is passed a pointer to the provider side signature
    296 context in the I<ctx> parameter.
    297 This function should free any resources associated with that context.
    298 
    299 OSSL_FUNC_signature_dupctx() should duplicate the provider side signature context in
    300 the I<ctx> parameter and return the duplicate copy.
    301 
    302 =head2 Signing Functions
    303 
    304 OSSL_FUNC_signature_sign_init() initialises a context for signing given a provider side
    305 signature context in the I<ctx> parameter, and a pointer to a provider key object
    306 in the I<provkey> parameter.
    307 The I<params>, if not NULL, should be set on the context in a manner similar to
    308 using OSSL_FUNC_signature_set_ctx_params().
    309 The key object should have been previously generated, loaded or imported into
    310 the provider using the key management (OSSL_OP_KEYMGMT) operation (see
    311 L<provider-keymgmt(7)>).
    312 
    313 OSSL_FUNC_signature_sign() performs the actual signing itself.
    314 A previously initialised signature context is passed in the I<ctx>
    315 parameter.
    316 The data to be signed is pointed to be the I<tbs> parameter which is I<tbslen>
    317 bytes long.
    318 Unless I<sig> is NULL, the signature should be written to the location pointed
    319 to by the I<sig> parameter and it should not exceed I<sigsize> bytes in length.
    320 The length of the signature should be written to I<*siglen>.
    321 If I<sig> is NULL then the maximum length of the signature should be written to
    322 I<*siglen>.
    323 
    324 =head2 Message Signing Functions
    325 
    326 These functions are suitable for providers that implement algorithms that
    327 accumulate a full message and sign the result of that accumulation, such as
    328 RSA-SHA256.
    329 
    330 OSSL_FUNC_signature_sign_message_init() initialises a context for signing a
    331 message given a provider side signature context in the I<ctx> parameter, and a
    332 pointer to a provider key object in the I<provkey> parameter.
    333 The I<params>, if not NULL, should be set on the context in a manner similar to
    334 using OSSL_FUNC_signature_set_ctx_params().
    335 The key object should have been previously generated, loaded or imported into
    336 the provider using the key management (OSSL_OP_KEYMGMT) operation (see
    337 L<provider-keymgmt(7)>).
    338 
    339 OSSL_FUNC_signature_sign_message_update() gathers the data pointed at by
    340 I<in>, which is I<inlen> bytes long.
    341 
    342 OSSL_FUNC_signature_sign_message_final() performs the actual signing on the
    343 data that was gathered with OSSL_FUNC_signature_sign_message_update().
    344 
    345 OSSL_FUNC_signature_sign() can be used for one-shot signature calls.  In that
    346 case, I<tbs> is expected to be the whole message to be signed, I<tbslen> bytes
    347 long.
    348 
    349 For both OSSL_FUNC_signature_sign_message_final() and OSSL_FUNC_signature_sign(),
    350 if I<sig> is not NULL, the signature should be written to the location pointed
    351 to by I<sig>, and it should not exceed I<sigsize> bytes in length.
    352 The length of the signature should be written to I<*siglen>.
    353 If I<sig> is NULL then the maximum length of the signature should be written to
    354 I<*siglen>.
    355 
    356 =head2 Verify Functions
    357 
    358 OSSL_FUNC_signature_verify_init() initialises a context for verifying a signature given
    359 a provider side signature context in the I<ctx> parameter, and a pointer to a
    360 provider key object in the I<provkey> parameter.
    361 The I<params>, if not NULL, should be set on the context in a manner similar to
    362 using OSSL_FUNC_signature_set_ctx_params().
    363 The key object should have been previously generated, loaded or imported into
    364 the provider using the key management (OSSL_OP_KEYMGMT) operation (see
    365 L<provider-keymgmt(7)>).
    366 
    367 OSSL_FUNC_signature_verify() performs the actual verification itself.
    368 A previously initialised signature context is passed in the I<ctx> parameter.
    369 The data that the signature covers is pointed to be the I<tbs> parameter which
    370 is I<tbslen> bytes long.
    371 The signature is pointed to by the I<sig> parameter which is I<siglen> bytes
    372 long.
    373 
    374 =head2 Message Verify Functions
    375 
    376 These functions are suitable for providers that implement algorithms that
    377 accumulate a full message and verify a signature on the result of that
    378 accumulation, such as RSA-SHA256.
    379 
    380 OSSL_FUNC_signature_verify_message_init() initialises a context for verifying
    381 a signature on a message given a provider side signature context in the I<ctx>
    382 parameter, and a pointer to a provider key object in the I<provkey> parameter.
    383 The I<params>, if not NULL, should be set on the context in a manner similar to
    384 using OSSL_FUNC_signature_set_ctx_params().
    385 The key object should have been previously generated, loaded or imported into
    386 the provider using the key management (OSSL_OP_KEYMGMT) operation (see
    387 L<provider-keymgmt(7)>).
    388 
    389 OSSL_FUNC_signature_verify_message_update() gathers the data pointed at by
    390 I<in>, which is I<inlen> bytes long.
    391 
    392 OSSL_FUNC_signature_verify_message_final() performs the actual verification on
    393 the data that was gathered with OSSL_FUNC_signature_verify_message_update().
    394 The signature itself must have been passed through the "signature"
    395 (B<OSSL_SIGNATURE_PARAM_SIGNATURE>) L<Signature parameter|/Signature parameters>
    396 before this function is called.
    397 
    398 OSSL_FUNC_signature_verify() can be used for one-shot verification calls.  In
    399 that case, I<tbs> is expected to be the whole message to be verified on,
    400 I<tbslen> bytes long.
    401 
    402 =head2 Verify Recover Functions
    403 
    404 OSSL_FUNC_signature_verify_recover_init() initialises a context for recovering the
    405 signed data given a provider side signature context in the I<ctx> parameter, and
    406 a pointer to a provider key object in the I<provkey> parameter.
    407 The I<params>, if not NULL, should be set on the context in a manner similar to
    408 using OSSL_FUNC_signature_set_ctx_params().
    409 The key object should have been previously generated, loaded or imported into
    410 the provider using the key management (OSSL_OP_KEYMGMT) operation (see
    411 L<provider-keymgmt(7)>).
    412 
    413 OSSL_FUNC_signature_verify_recover() performs the actual verify recover itself.
    414 A previously initialised signature context is passed in the I<ctx> parameter.
    415 The signature is pointed to by the I<sig> parameter which is I<siglen> bytes
    416 long.
    417 Unless I<rout> is NULL, the recovered data should be written to the location
    418 pointed to by I<rout> which should not exceed I<routsize> bytes in length.
    419 The length of the recovered data should be written to I<*routlen>.
    420 If I<rout> is NULL then the maximum size of the output buffer is written to
    421 the I<routlen> parameter.
    422 
    423 =head2 Digest Sign Functions
    424 
    425 OSSL_FUNC_signature_digest_sign_init() initialises a context for signing given a
    426 provider side signature context in the I<ctx> parameter, and a pointer to a
    427 provider key object in the I<provkey> parameter.
    428 The I<params>, if not NULL, should be set on the context in a manner similar to
    429 using OSSL_FUNC_signature_set_ctx_params() and
    430 OSSL_FUNC_signature_set_ctx_md_params().
    431 The key object should have been
    432 previously generated, loaded or imported into the provider using the
    433 key management (OSSL_OP_KEYMGMT) operation (see L<provider-keymgmt(7)>).
    434 The name of the digest to be used will be in the I<mdname> parameter.
    435 
    436 OSSL_FUNC_signature_digest_sign_update() provides data to be signed in the I<data>
    437 parameter which should be of length I<datalen>. A previously initialised
    438 signature context is passed in the I<ctx> parameter. This function may be called
    439 multiple times to cumulatively add data to be signed.
    440 
    441 OSSL_FUNC_signature_digest_sign_final() finalises a signature operation previously
    442 started through OSSL_FUNC_signature_digest_sign_init() and
    443 OSSL_FUNC_signature_digest_sign_update() calls. Once finalised no more data will be
    444 added through OSSL_FUNC_signature_digest_sign_update(). A previously initialised
    445 signature context is passed in the I<ctx> parameter. Unless I<sig> is NULL, the
    446 signature should be written to the location pointed to by the I<sig> parameter
    447 and it should not exceed I<sigsize> bytes in length. The length of the signature
    448 should be written to I<*siglen>. If I<sig> is NULL then the maximum length of
    449 the signature should be written to I<*siglen>.
    450 
    451 OSSL_FUNC_signature_digest_sign() implements a "one shot" digest sign operation
    452 previously started through OSSL_FUNC_signature_digest_sign_init(). A previously
    453 initialised signature context is passed in the I<ctx> parameter. The data to be
    454 signed is in I<tbs> which should be I<tbslen> bytes long. Unless I<sig> is NULL,
    455 the signature should be written to the location pointed to by the I<sig>
    456 parameter and it should not exceed I<sigsize> bytes in length. The length of the
    457 signature should be written to I<*siglen>. If I<sig> is NULL then the maximum
    458 length of the signature should be written to I<*siglen>.
    459 
    460 =head2 Digest Verify Functions
    461 
    462 OSSL_FUNC_signature_digest_verify_init() initialises a context for verifying given a
    463 provider side verification context in the I<ctx> parameter, and a pointer to a
    464 provider key object in the I<provkey> parameter.
    465 The I<params>, if not NULL, should be set on the context in a manner similar to
    466 OSSL_FUNC_signature_set_ctx_params() and
    467 OSSL_FUNC_signature_set_ctx_md_params().
    468 The key object should have been
    469 previously generated, loaded or imported into the provider using the
    470 key management (OSSL_OP_KEYMGMT) operation (see L<provider-keymgmt(7)>).
    471 The name of the digest to be used will be in the I<mdname> parameter.
    472 
    473 OSSL_FUNC_signature_digest_verify_update() provides data to be verified in the I<data>
    474 parameter which should be of length I<datalen>. A previously initialised
    475 verification context is passed in the I<ctx> parameter. This function may be
    476 called multiple times to cumulatively add data to be verified.
    477 
    478 OSSL_FUNC_signature_digest_verify_final() finalises a verification operation previously
    479 started through OSSL_FUNC_signature_digest_verify_init() and
    480 OSSL_FUNC_signature_digest_verify_update() calls. Once finalised no more data will be
    481 added through OSSL_FUNC_signature_digest_verify_update(). A previously initialised
    482 verification context is passed in the I<ctx> parameter. The signature to be
    483 verified is in I<sig> which is I<siglen> bytes long.
    484 
    485 OSSL_FUNC_signature_digest_verify() implements a "one shot" digest verify operation
    486 previously started through OSSL_FUNC_signature_digest_verify_init(). A previously
    487 initialised verification context is passed in the I<ctx> parameter. The data to be
    488 verified is in I<tbs> which should be I<tbslen> bytes long. The signature to be
    489 verified is in I<sig> which is I<siglen> bytes long.
    490 
    491 =head2 Signature parameters
    492 
    493 See L<OSSL_PARAM(3)> for further details on the parameters structure used by
    494 the OSSL_FUNC_signature_get_ctx_params() and OSSL_FUNC_signature_set_ctx_params() functions.
    495 
    496 OSSL_FUNC_signature_get_ctx_params() gets signature parameters associated with the
    497 given provider side signature context I<ctx> and stored them in I<params>.
    498 Passing NULL for I<params> should return true.
    499 
    500 OSSL_FUNC_signature_set_ctx_params() sets the signature parameters associated with the
    501 given provider side signature context I<ctx> to I<params>.
    502 Any parameter settings are additional to any that were previously set.
    503 Passing NULL for I<params> should return true.
    504 
    505 Common parameters currently recognised by built-in signature algorithms are as
    506 follows.
    507 
    508 =over 4
    509 
    510 =item "digest" (B<OSSL_SIGNATURE_PARAM_DIGEST>) <UTF8 string>
    511 
    512 Get or sets the name of the digest algorithm used for the input to the
    513 signature functions. It is required in order to calculate the "algorithm-id".
    514 
    515 =item "properties" (B<OSSL_SIGNATURE_PARAM_PROPERTIES>) <UTF8 string>
    516 
    517 Sets the name of the property query associated with the "digest" algorithm.
    518 NULL is used if this optional value is not set.
    519 
    520 =back
    521 
    522 Note that when implementing a signature algorithm that gathers a full message,
    523 like RSA-SHA256, the "digest" and "properties" parameters should not be used.
    524 For such implementations, it's acceptable to simply ignore them if they happen
    525 to be passed in a call to OSSL_FUNC_signature_set_ctx_params().  For such
    526 implementations, however, it is not acceptable to have them in the B<OSSL_PARAM>
    527 array that's returned by OSSL_FUNC_signature_settable_ctx_params().
    528 
    529 =over 4
    530 
    531 =item "signature" (B<OSSL_SIGNATURE_PARAM_SIGNATURE>) <octet string>
    532 
    533 Sets the signature to verify, specifically when
    534 OSSL_FUNC_signature_verify_message_final() is used.
    535 
    536 =item "digest-size" (B<OSSL_SIGNATURE_PARAM_DIGEST_SIZE>) <unsigned integer>
    537 
    538 Gets or sets the output size of the digest algorithm used for the input to the
    539 signature functions.
    540 The length of the "digest-size" parameter should not exceed that of a B<size_t>.
    541 
    542 =item "algorithm-id" (B<OSSL_SIGNATURE_PARAM_ALGORITHM_ID>) <octet string>
    543 
    544 Gets the DER-encoded AlgorithmIdentifier for the signature operation.
    545 This typically corresponds to the combination of a digest algorithm
    546 with a purely asymmetric signature algorithm, such as SHA256WithECDSA.
    547 
    548 The L<ASN1_item_sign_ctx(3)> function relies on this operation and is used by
    549 many other functions that sign ASN.1 structures such as X.509 certificates,
    550 certificate requests, and CRLs, as well as OCSP, CMP, and CMS messages.
    551 
    552 =item "nonce-type" (B<OSSL_SIGNATURE_PARAM_NONCE_TYPE>) <unsigned integer>
    553 
    554 Set this to 1 to use deterministic digital signature generation with
    555 ECDSA or DSA, as defined in RFC 6979 (see Section 3.2 "Generation of
    556 k").  In this case, the "digest" parameter must be explicitly set
    557 (otherwise, deterministic nonce generation will fail).  Before using
    558 deterministic digital signature generation, please read RFC 6979
    559 Section 4 "Security Considerations".  The default value for
    560 "nonce-type" is 0 and results in a random value being used for the
    561 nonce B<k> as defined in FIPS 186-4 Section 6.3 "Secret Number
    562 Generation".
    563 
    564 The FIPS provider does not support deterministic digital signature generation.
    565 
    566 =item "kat" (B<OSSL_SIGNATURE_PARAM_KAT>) <unsigned integer>
    567 
    568 Sets a flag to modify the sign operation to return an error if the initial
    569 calculated signature is invalid.
    570 In the normal mode of operation - new random values are chosen until the
    571 signature operation succeeds.
    572 By default it retries until a signature is calculated.
    573 Setting the value to 0 causes the sign operation to retry,
    574 otherwise the sign operation is only tried once and returns whether or not it
    575 was successful.
    576 Known answer tests can be performed if the random generator is overridden to
    577 supply known values that either pass or fail.
    578 
    579 =back
    580 
    581 The following parameters are used by the OpenSSL FIPS provider:
    582 
    583 =over 4
    584 
    585 =item "fips-indicator" (B<OSSL_SIGNATURE_PARAM_FIPS_APPROVED_INDICATOR>) <integer>
    586 
    587 A getter that returns 1 if the operation is FIPS approved, or 0 otherwise.
    588 This may be used after calling either the sign or verify final functions. It may
    589 return 0 if either the "digest-check", "key-check", or "sign-check" are set to 0.
    590 
    591 =item "verify-message" (B<OSSL_SIGNATURE_PARAM_FIPS_VERIFY_MESSAGE> <integer>
    592 
    593 A getter that returns 1 if a signature verification operation acted on
    594 a raw message, or 0 if it verified a predigested message.  A value of 0
    595 indicates likely non-approved usage of the FIPS provider.  This flag is
    596 set when any signature verification initialisation function is called.
    597 It is also set to 1 when any signing operation is performed to signify
    598 compliance.  See FIPS 140-3 IG 2.4.B for further information.
    599 
    600 =item "key-check" (B<OSSL_SIGNATURE_PARAM_FIPS_KEY_CHECK>) <integer>
    601 
    602 If required this parameter should be set early via an init function
    603 (e.g. OSSL_FUNC_signature_sign_init() or OSSL_FUNC_signature_verify_init()).
    604 The default value of 1 causes an error during the init if the key is not FIPS
    605 approved (e.g. The key has a security strength of less than 112 bits).
    606 Setting this to 0 will ignore the error and set the approved "indicator" to 0.
    607 This option breaks FIPS compliance if it causes the approved "fips-indicator"
    608 to return 0.
    609 
    610 =item "digest-check" (B<OSSL_SIGNATURE_PARAM_FIPS_DIGEST_CHECK>) <integer>
    611 
    612 If required this parameter should be set before the signature digest is set.
    613 The default value of 1 causes an error when the digest is set if the digest is
    614 not FIPS approved (e.g. SHA1 is used for signing). Setting this to 0 will ignore
    615 the error and set the approved "fips-indicator" to 0.
    616 This option breaks FIPS compliance if it causes the approved "fips-indicator"
    617 to return 0.
    618 
    619 =item "sign-check" (B<OSSL_SIGNATURE_PARAM_FIPS_SIGN_CHECK>) <integer>
    620 
    621 If required this parameter should be set early via an init function.
    622 The default value of 1 causes an error when a signing algorithm is used. (This
    623 is triggered by deprecated signing algorithms).
    624 Setting this to 0 will ignore the error and set the approved "fips-indicator" to 0.
    625 This option breaks FIPS compliance if it causes the approved "fips-indicator" to
    626 return 0.
    627 
    628 =item "sign-x931-pad-check" (B<OSSL_SIGNATURE_PARAM_FIPS_SIGN_X931_PAD_CHECK>) <integer>
    629 
    630 If required this parameter should be set before the padding mode is set.
    631 The default value of 1 causes an error if the padding mode is set to X9.31 padding
    632 for a RSA signing operation. Setting this to 0 will ignore the error and set the
    633 approved "fips-indicator" to 0.
    634 This option breaks FIPS compliance if it causes the approved "fips-indicator"
    635 to return 0.
    636 
    637 =back
    638 
    639 OSSL_FUNC_signature_gettable_ctx_params() and OSSL_FUNC_signature_settable_ctx_params() get a
    640 constant L<OSSL_PARAM(3)> array that describes the gettable and settable parameters,
    641 i.e. parameters that can be used with OSSL_FUNC_signature_get_ctx_params() and
    642 OSSL_FUNC_signature_set_ctx_params() respectively.
    643 
    644 =head2 MD parameters
    645 
    646 See L<OSSL_PARAM(3)> for further details on the parameters structure used by
    647 the OSSL_FUNC_signature_get_md_ctx_params() and OSSL_FUNC_signature_set_md_ctx_params()
    648 functions.
    649 
    650 OSSL_FUNC_signature_get_md_ctx_params() gets digest parameters associated with the
    651 given provider side digest signature context I<ctx> and stores them in I<params>.
    652 Passing NULL for I<params> should return true.
    653 
    654 OSSL_FUNC_signature_set_ms_ctx_params() sets the digest parameters associated with the
    655 given provider side digest signature context I<ctx> to I<params>.
    656 Any parameter settings are additional to any that were previously set.
    657 Passing NULL for I<params> should return true.
    658 
    659 Parameters currently recognised by built-in signature algorithms are the same
    660 as those for built-in digest algorithms. See
    661 L<provider-digest(7)/Digest Parameters> for further information.
    662 
    663 OSSL_FUNC_signature_gettable_md_ctx_params() and OSSL_FUNC_signature_settable_md_ctx_params()
    664 get a constant L<OSSL_PARAM(3)> array that describes the gettable and settable
    665 digest parameters, i.e. parameters that can be used with
    666 OSSL_FUNC_signature_get_md_ctx_params() and OSSL_FUNC_signature_set_md_ctx_params()
    667 respectively.
    668 
    669 =head1 RETURN VALUES
    670 
    671 OSSL_FUNC_signature_newctx() and OSSL_FUNC_signature_dupctx() should return the newly created
    672 provider side signature context, or NULL on failure.
    673 
    674 OSSL_FUNC_signature_gettable_ctx_params(), OSSL_FUNC_signature_settable_ctx_params(),
    675 OSSL_FUNC_signature_gettable_md_ctx_params() and OSSL_FUNC_signature_settable_md_ctx_params(),
    676 return the gettable or settable parameters in a constant L<OSSL_PARAM(3)> array.
    677 
    678 OSSL_FUNC_signature_query_key_types() should return a NULL-terminated array of strings.
    679 
    680 All verification functions should return 1 for success,
    681 0 for a non-matching signature, and a negative value for operation failure.
    682 
    683 All other functions should return 1 for success
    684 and 0 or a negative value for failure.
    685 
    686 =head1 SEE ALSO
    687 
    688 L<provider(7)>, L<provider-base(7)/Provider Functions>,
    689 L<OSSL_PARAM(3)>, L<OSSL_DISPATCH(3)>, L<OSSL_ALGORITHM(3)>,
    690 L<EVP_PKEY_sign(3)>, L<EVP_PKEY_verify(3)>, L<EVP_PKEY_verify_recover(3)>,
    691 L<EVP_SIGNATURE_is_a(3)>, L<ASN1_item_sign_ctx(3)>
    692 
    693 =head1 HISTORY
    694 
    695 The provider SIGNATURE interface was introduced in OpenSSL 3.0.
    696 
    697 The OSSL_FUNC_signature_sign_message_init(), OSSL_FUNC_signature_sign_message_update(),
    698 OSSL_FUNC_signature_sign_message_final(), OSSL_FUNC_signature_verify_message_init(),
    699 OSSL_FUNC_signature_verify_message_update() and OSSL_FUNC_signature_verify_message_final()
    700 functions were added in OpenSSL 3.4.
    701 
    702 The Signature Parameters "fips-indicator", "key-check" and "digest-check" were added in
    703 OpenSSL 3.4.
    704 
    705 Deterministic digital signature generation for ECDSA was added to the FIPS provider in OpenSSL
    706 3.6.
    707 
    708 =head1 COPYRIGHT
    709 
    710 Copyright 2019-2026 The OpenSSL Project Authors. All Rights Reserved.
    711 
    712 Licensed under the Apache License 2.0 (the "License").  You may not use
    713 this file except in compliance with the License.  You can obtain a copy
    714 in the file LICENSE in the source distribution or at
    715 L<https://www.openssl.org/source/license.html>.
    716 
    717 =cut
    718