1=pod 2 3=head1 NAME 4 5EVP_PKEY_sign_init, EVP_PKEY_sign - sign using a public key algorithm 6 7=head1 SYNOPSIS 8 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 16=head1 DESCRIPTION 17 18The EVP_PKEY_sign_init() function initializes a public key algorithm 19context using key B<pkey> for a signing operation. 20 21The EVP_PKEY_sign() function performs a public key signing operation 22using B<ctx>. The data to be signed is specified using the B<tbs> and 23B<tbslen> parameters. If B<sig> is B<NULL> then the maximum size of the output 24buffer is written to the B<siglen> parameter. If B<sig> is not B<NULL> then 25before the call the B<siglen> parameter should contain the length of the 26B<sig> buffer, if the call is successful the signature is written to 27B<sig> and the amount of data written to B<siglen>. 28 29=head1 NOTES 30 31After the call to EVP_PKEY_sign_init() algorithm specific control 32operations can be performed to set any appropriate parameters for the 33operation. 34 35The function EVP_PKEY_sign() can be called more than once on the same 36context if several operations are performed using the same parameters. 37 38=head1 RETURN VALUES 39 40EVP_PKEY_sign_init() and EVP_PKEY_sign() return 1 for success and 0 41or a negative value for failure. In particular a return value of -2 42indicates the operation is not supported by the public key algorithm. 43 44=head1 EXAMPLE 45 46Sign 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 unsigned char *md, *sig; 53 size_t mdlen, siglen; 54 EVP_PKEY *signing_key; 55 /* NB: assumes signing_key, md and mdlen are already set up 56 * and that signing_key is an RSA private key 57 */ 58 ctx = EVP_PKEY_CTX_new(signing_key); 59 if (!ctx) 60 /* Error occurred */ 61 if (EVP_PKEY_sign_init(ctx) <= 0) 62 /* Error */ 63 if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0) 64 /* Error */ 65 if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0) 66 /* Error */ 67 68 /* Determine buffer length */ 69 if (EVP_PKEY_sign(ctx, NULL, &siglen, md, mdlen) <= 0) 70 /* Error */ 71 72 sig = OPENSSL_malloc(siglen); 73 74 if (!sig) 75 /* malloc failure */ 76 77 if (EVP_PKEY_sign(ctx, sig, &siglen, md, mdlen) <= 0) 78 /* Error */ 79 80 /* Signature is siglen bytes written to buffer sig */ 81 82 83=head1 SEE ALSO 84 85L<EVP_PKEY_CTX_new(3)|EVP_PKEY_CTX_new(3)>, 86L<EVP_PKEY_encrypt(3)|EVP_PKEY_encrypt(3)>, 87L<EVP_PKEY_decrypt(3)|EVP_PKEY_decrypt(3)>, 88L<EVP_PKEY_verify(3)|EVP_PKEY_verify(3)>, 89L<EVP_PKEY_verify_recover(3)|EVP_PKEY_verify_recover(3)>, 90L<EVP_PKEY_derive(3)|EVP_PKEY_derive(3)> 91 92=head1 HISTORY 93 94These functions were first added to OpenSSL 1.0.0. 95 96=cut 97