1EVP_PKEY_sign(3)                    OpenSSL                   EVP_PKEY_sign(3)
2
3
4

NAME

6       EVP_PKEY_sign_init, EVP_PKEY_sign - sign using a public key algorithm
7

SYNOPSIS

9        #include <openssl/evp.h>
10
11        int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx);
12        int EVP_PKEY_sign(EVP_PKEY_CTX *ctx,
13                               unsigned char *sig, size_t *siglen,
14                               const unsigned char *tbs, size_t tbslen);
15

DESCRIPTION

17       The EVP_PKEY_sign_init() function initializes a public key algorithm
18       context using key pkey for a signing operation.
19
20       The EVP_PKEY_sign() function performs a public key signing operation
21       using ctx. The data to be signed is specified using the tbs and tbslen
22       parameters. If sig is NULL then the maximum size of the output buffer
23       is written to the siglen parameter. If sig is not NULL then before the
24       call the siglen parameter should contain the length of the sig buffer,
25       if the call is successful the signature is written to sig and the
26       amount of data written to siglen.
27

NOTES

29       EVP_PKEY_sign() does not hash the data to be signed, and therefore is
30       normally used to sign digests. For signing arbitrary messages, see the
31       EVP_DigestSignInit(3) and EVP_SignInit(3) signing interfaces instead.
32
33       After the call to EVP_PKEY_sign_init() algorithm specific control
34       operations can be performed to set any appropriate parameters for the
35       operation (see EVP_PKEY_CTX_ctrl(3)).
36
37       The function EVP_PKEY_sign() can be called more than once on the same
38       context if several operations are performed using the same parameters.
39

RETURN VALUES

41       EVP_PKEY_sign_init() and EVP_PKEY_sign() return 1 for success and 0 or
42       a negative value for failure. In particular a return value of -2
43       indicates the operation is not supported by the public key algorithm.
44

EXAMPLE

46       Sign data using RSA with PKCS#1 padding and SHA256 digest:
47
48        #include <openssl/evp.h>
49        #include <openssl/rsa.h>
50
51        EVP_PKEY_CTX *ctx;
52        /* md is a SHA-256 digest in this example. */
53        unsigned char *md, *sig;
54        size_t mdlen = 32, siglen;
55        EVP_PKEY *signing_key;
56
57        /*
58         * NB: assumes signing_key and md are set up before the next
59         * step. signing_key must be an RSA private key and md must
60         * point to the SHA-256 digest to be signed.
61         */
62        ctx = EVP_PKEY_CTX_new(signing_key, NULL /* no engine */);
63        if (!ctx)
64               /* Error occurred */
65        if (EVP_PKEY_sign_init(ctx) <= 0)
66               /* Error */
67        if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0)
68               /* Error */
69        if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0)
70               /* Error */
71
72        /* Determine buffer length */
73        if (EVP_PKEY_sign(ctx, NULL, &siglen, md, mdlen) <= 0)
74               /* Error */
75
76        sig = OPENSSL_malloc(siglen);
77
78        if (!sig)
79               /* malloc failure */
80
81        if (EVP_PKEY_sign(ctx, sig, &siglen, md, mdlen) <= 0)
82               /* Error */
83
84        /* Signature is siglen bytes written to buffer sig */
85

SEE ALSO

87       EVP_PKEY_CTX_new(3), EVP_PKEY_CTX_ctrl(3), EVP_PKEY_encrypt(3),
88       EVP_PKEY_decrypt(3), EVP_PKEY_verify(3), EVP_PKEY_verify_recover(3),
89       EVP_PKEY_derive(3)
90

HISTORY

92       These functions were first added to OpenSSL 1.0.0.
93
94
95
961.0.2o                            2019-09-10                  EVP_PKEY_sign(3)
Impressum