From 4f62f5d9af4fb4c7765859967ee39252e34ceeb9 Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Tue, 3 Sep 2019 17:05:52 +0100 Subject: [PATCH] Add docs for the provider interface for signature operations Reviewed-by: Richard Levitte (Merged from https://github.com/openssl/openssl/pull/9753) --- doc/man7/provider-signature.pod | 229 ++++++++++++++++++++++++++++++++ 1 file changed, 229 insertions(+) create mode 100644 doc/man7/provider-signature.pod diff --git a/doc/man7/provider-signature.pod b/doc/man7/provider-signature.pod new file mode 100644 index 0000000000..3894afd03c --- /dev/null +++ b/doc/man7/provider-signature.pod @@ -0,0 +1,229 @@ +=pod + +=head1 NAME + +provider-signature - The signature library E-E provider functions + +=head1 SYNOPSIS + +=for comment multiple includes + + #include + #include + + /* + * 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_set_params(void *ctx, const OSSL_PARAM params[]); + + +=head1 DESCRIPTION + +This documentation is primarily aimed at provider authors. See L +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 L, L, +L, L, +L and L (as well +as other related functions). + +All "functions" mentioned here are passed as function pointers between +F and the provider in B arrays via +B arrays that are returned by the provider's +provider_query_operation() function +(see L). + +All these "functions" have a corresponding function type definition +named B, and a helper function to retrieve the +function pointer from an B element named +B. +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); + +B arrays are indexed by numbers that are provided as +macros in L, 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_set_params OSSL_FUNC_SIGNATURE_SET_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 L for further details. + +=head2 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 B is the provider context generated during provider +initialisation (see L). + +OP_signature_freectx() is passed a pointer to the provider side signature +context in the B parameter. +This function should free any resources associated with that context. + +OP_signature_dupctx() should duplicate the provider side signature context in +the B parameter and return the duplicate copy. + +=head2 Signing Functions + +OP_signature_sign_init() initialises a context for signing given a provider side +signature context in the B parameter, and a pointer to a provider key object +in the B 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 B +parameter. +The data to be signed is pointed to be the B parameter which is B +bytes long. +Unless B is NULL, the signature should be written to the location pointed +to by the B parameter and it should not exceed B bytes in length. +The length of the signature should be written to B<*siglen>. +If B is NULL then the maximum length of the signature should be written to +B<*siglen>. + +=head2 Verify Functions + +OP_signature_verify_init() initialises a context for verifying a signature given +a provider side signature context in the B parameter, and a pointer to a +provider key object in the B 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 B parameter. +The data that the signature covers is pointed to be the B parameter which +is B bytes long. +The signature is pointed to by the B parameter which is B bytes +long. + +=head2 Verify Recover Functions + +OP_signature_verify_recover_init() initialises a context for recovering the +signed data given a provider side signature context in the B parameter, and +a pointer to a provider key object in the B 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 B parameter. +The signature is pointed to by the B parameter which is B bytes +long. +Unless B is NULL, the recovered data should be written to the location +pointed to by B which should not exceed B bytes in length. +The length of the recovered data should be written to B<*routlen>. +If B is B then the maximum size of the output buffer is written to +the B parameter. + +=head2 Signature Parameters + +See L for further details on the parameters structure used by +the OP_signature_set_params() function. + +OP_signature_set_params() sets signature parameters associated with the given +provider side key exchange context B to B. +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: + +=over 4 + +=item B (UTF8 string) + +Sets the name of the digest algorithm used for the input to the signature +functions. + +=item B (size_t) + +Sets the output size of the digest algorithm used for the input to the signature +functions. + +=back + +=head1 RETURN VALUES + +OP_signature_newctx() and OP_signature_dupctx() should return the newly created +provider side signature, or NULL on failure. + +OP_signature_sign_init(), OP_signature_sign(), OP_signature_verify_init(), +OP_signature_verify(), OP_signature_verify_recover_init(), +OP_signature_verify_recover() and OP_signature_set_params() should return 1 for +success or 0 on error. + +=head1 SEE ALSO + +L + +=head1 HISTORY + +The provider SIGNATURE interface was introduced in OpenSSL 3.0. + +=head1 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 +L. + +=cut -- 2.25.1