PROVIDER-SIGNATURE(7)

NAME
provider-signature - The signature library <-> provider functions

SYNOPSIS
 #include <openssl/core_numbers.h>
 #include <openssl/core_names.h>

 /*
  * None of these are actual functions, but are displayed like this for
  * the function signatures for functions that are offered as function
  * pointers in OSSL_DISPATCH arrays.
  */

 /* Context management */
 void *OP_signature_newctx(void *provctx);
 void OP_signature_freectx(void *ctx);
 void *OP_signature_dupctx(void *ctx);

 /* Signing */
 int OP_signature_sign_init(void *ctx, void *provkey);
 int OP_signature_sign(void *ctx, unsigned char *sig, size_t *siglen,
                       size_t sigsize, const unsigned char *tbs, size_t tbslen);

 /* Verifying */
 int OP_signature_verify_init(void *ctx, void *provkey);
 int OP_signature_verify(void *ctx, const unsigned char *sig, size_t siglen,
                         const unsigned char *tbs, size_t tbslen);

 /* Verify Recover */
 int OP_signature_verify_recover_init(void *ctx, void *provkey);
 int OP_signature_verify_recover(void *ctx, unsigned char *rout,
                                 size_t *routlen, size_t routsize,
                                 const unsigned char *sig, size_t siglen);

 /* Signature parameters */
 int OP_signature_get_ctx_params(void *ctx, OSSL_PARAM params[]);
 const OSSL_PARAM *OP_signature_gettable_ctx_params(void);
 int OP_signature_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
 const OSSL_PARAM *OP_signature_settable_ctx_params(void);

DESCRIPTION
This documentation is primarily aimed at provider authors. See provider(7) for further information.

The signature (OSSL_OP_SIGNATURE) operation enables providers to implement signature algorithms and make them available to applications via the API functions EVP_PKEY_sign(3), EVP_PKEY_verify(3), and EVP_PKEY_verify_recover(3) (as well as other related functions).

All "functions" mentioned here are passed as function pointers between libcrypto and the provider in OSSL_DISPATCH arrays via OSSL_ALGORITHM arrays that are returned by the provider's provider_query_operation() function (see "Provider Functions" in provider-base(7)).

All these "functions" have a corresponding function type definition named OSSL_{name}_fn, and a helper function to retrieve the function pointer from an OSSL_DISPATCH element named OSSL_get_{name}. For example, the "function" OP_signature_newctx() has these:

 typedef void *(OSSL_OP_signature_newctx_fn)(void *provctx);
 static ossl_inline OSSL_OP_signature_newctx_fn
     OSSL_get_OP_signature_newctx(const OSSL_DISPATCH *opf);

OSSL_DISPATCH arrays are indexed by numbers that are provided as macros in openssl-core_numbers.h(7), as follows:

 OP_signature_newctx                 OSSL_FUNC_SIGNATURE_NEWCTX
 OP_signature_freectx                OSSL_FUNC_SIGNATURE_FREECTX
 OP_signature_dupctx                 OSSL_FUNC_SIGNATURE_DUPCTX

 OP_signature_sign_init              OSSL_FUNC_SIGNATURE_SIGN_INIT
 OP_signature_sign                   OSSL_FUNC_SIGNATURE_SIGN

 OP_signature_verify_init            OSSL_FUNC_SIGNATURE_VERIFY_INIT
 OP_signature_verify                 OSSL_FUNC_SIGNATURE_VERIFY

 OP_signature_verify_recover_init    OSSL_FUNC_SIGNATURE_VERIFY_RECOVER_INIT
 OP_signature_verify_recover         OSSL_FUNC_SIGNATURE_VERIFY_RECOVER

 OP_signature_get_ctx_params         OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS
 OP_signature_gettable_ctx_params    OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS
 OP_signature_set_ctx_params         OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS
 OP_signature_settable_ctx_params    OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS

A signature algorithm implementation may not implement all of these functions. In order to be a consistent set of functions a provider must implement OP_signature_newctx and OP_signature_freectx. It must also implement both of OP_signature_sign_init and OP_signature_sign, or both of OP_signature_verify_init and OP_signature_verify, or both of OP_signature_verify_recover_init and OP_signature_verify_recover. All other functions are optional.

A signature algorithm must also implement some mechanism for generating, loading or importing keys via the key management (OSSL_OP_KEYMGMT) operation. See provider-keymgmt(7) for further details.

  Context Management Functions
OP_signature_newctx() should create and return a pointer to a provider side structure for holding context information during a signature operation. A pointer to this context will be passed back in a number of the other signature operation function calls. The parameter provctx is the provider context generated during provider initialisation (see provider(7)).

OP_signature_freectx() is passed a pointer to the provider side signature context in the ctx parameter. This function should free any resources associated with that context.

OP_signature_dupctx() should duplicate the provider side signature context in the ctx parameter and return the duplicate copy.

  Signing Functions
OP_signature_sign_init() initialises a context for signing given a provider side signature context in the ctx parameter, and a pointer to a provider key object in the provkey parameter. The key object should have been previously generated, loaded or imported into the provider using the key management (OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)>.

OP_signature_sign() performs the actual signing itself. A previously initialised signature context is passed in the ctx parameter. The data to be signed is pointed to be the tbs parameter which is tbslen bytes long. Unless sig is NULL, the signature should be written to the location pointed to by the sig parameter and it should not exceed sigsize bytes in length. The length of the signature should be written to *siglen. If sig is NULL then the maximum length of the signature should be written to *siglen.

  Verify Functions
OP_signature_verify_init() initialises a context for verifying a signature given a provider side signature context in the ctx parameter, and a pointer to a provider key object in the provkey parameter. The key object should have been previously generated, loaded or imported into the provider using the key management (OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)>.

OP_signature_verify() performs the actual verification itself. A previously initialised signature context is passed in the ctx parameter. The data that the signature covers is pointed to be the tbs parameter which is tbslen bytes long. The signature is pointed to by the sig parameter which is siglen bytes long.

  Verify Recover Functions
OP_signature_verify_recover_init() initialises a context for recovering the signed data given a provider side signature context in the ctx parameter, and a pointer to a provider key object in the provkey parameter. The key object should have been previously generated, loaded or imported into the provider using the key management (OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)>.

OP_signature_verify_recover() performs the actual verify recover itself. A previously initialised signature context is passed in the ctx parameter. The signature is pointed to by the sig parameter which is siglen bytes long. Unless rout is NULL, the recovered data should be written to the location pointed to by rout which should not exceed routsize bytes in length. The length of the recovered data should be written to *routlen. If rout is NULL then the maximum size of the output buffer is written to the routlen parameter.

  Signature Parameters
See OSSL_PARAM(3) for further details on the parameters structure used by the OP_signature_get_ctx_params() and OP_signature_set_ctx_params() functions.

OP_signature_get_ctx_params() gets signature parameters associated with the given provider side signature context ctx and stored them in params. OP_signature_set_ctx_params() sets the signature parameters associated with the given provider side signature context ctx to params. Any parameter settings are additional to any that were previously set.

Parameters currently recognised by built-in signature algorithms are as follows. Not all parameters are relevant to, or are understood by all signature algorithms:

"digest" (OSSL_SIGNATURE_PARAM_DIGEST) <UTF8 string>
    Get or sets the name of the digest algorithm used for the input to the signature functions.

"digest-size" (OSSL_SIGNATURE_PARAM_DIGEST_SIZE) <unsigned integer>
    Gets or sets the output size of the digest algorithm used for the input to the signature functions. The length of the "digest-size" parameter should not exceed that of a size_t.

OP_signature_gettable_ctx_params() and OP_signature_settable_ctx_params() get a constant OSSL_PARAM array that describes the gettable and settable parameters, i.e. parameters that can be used with OP_signature_get_ctx_params() and OP_signature_set_ctx_params() respectively. See OSSL_PARAM(3) for the use of OSSL_PARAM as parameter descriptor.

RETURN VALUES
OP_signature_newctx() and OP_signature_dupctx() should return the newly created provider side signature, or NULL on failure.

All other functions should return 1 for success or 0 on error.

SEE ALSO
provider(7)

HISTORY
The provider SIGNATURE interface was introduced in OpenSSL 3.0.

COPYRIGHT
Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.