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       After the call to EVP_PKEY_sign_init() algorithm specific control
30       operations can be performed to set any appropriate parameters for the
31       operation.
32
33       The function EVP_PKEY_sign() can be called more than once on the same
34       context if several operations are performed using the same parameters.
35

RETURN VALUES

37       EVP_PKEY_sign_init() and EVP_PKEY_sign() return 1 for success and 0 or
38       a negative value for failure. In particular a return value of -2
39       indicates the operation is not supported by the public key algorithm.
40

EXAMPLE

42       Sign data using RSA with PKCS#1 padding and SHA256 digest:
43
44        #include <openssl/evp.h>
45        #include <openssl/rsa.h>
46
47        EVP_PKEY_CTX *ctx;
48        unsigned char *md, *sig;
49        size_t mdlen, siglen;
50        EVP_PKEY *signing_key;
51        /* NB: assumes signing_key, md and mdlen are already set up
52         * and that signing_key is an RSA private key
53         */
54        ctx = EVP_PKEY_CTX_new(signing_key);
55        if (!ctx)
56               /* Error occurred */
57        if (EVP_PKEY_sign_init(ctx) <= 0)
58               /* Error */
59        if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0)
60               /* Error */
61        if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0)
62               /* Error */
63
64        /* Determine buffer length */
65        if (EVP_PKEY_sign(ctx, NULL, &siglen, md, mdlen) <= 0)
66               /* Error */
67
68        sig = OPENSSL_malloc(siglen);
69
70        if (!sig)
71               /* malloc failure */
72
73        if (EVP_PKEY_sign(ctx, sig, &siglen, md, mdlen) <= 0)
74               /* Error */
75
76        /* Signature is siglen bytes written to buffer sig */
77

SEE ALSO

79       EVP_PKEY_CTX_new(3), EVP_PKEY_encrypt(3), EVP_PKEY_decrypt(3),
80       EVP_PKEY_verify(3), EVP_PKEY_verify_recover(3), EVP_PKEY_derive(3)
81

HISTORY

83       These functions were first added to OpenSSL 1.0.0.
84
85
86
871.0.1e                            2013-02-11                  EVP_PKEY_sign(3)
Impressum