1*e71b7053SJung-uk Kim=pod 2*e71b7053SJung-uk Kim 3*e71b7053SJung-uk Kim=head1 NAME 4*e71b7053SJung-uk Kim 5*e71b7053SJung-uk KimEVP_DigestSignInit, EVP_DigestSignUpdate, EVP_DigestSignFinal, 6*e71b7053SJung-uk KimEVP_DigestSign - EVP signing functions 7*e71b7053SJung-uk Kim 8*e71b7053SJung-uk Kim=head1 SYNOPSIS 9*e71b7053SJung-uk Kim 10*e71b7053SJung-uk Kim #include <openssl/evp.h> 11*e71b7053SJung-uk Kim 12*e71b7053SJung-uk Kim int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, 13*e71b7053SJung-uk Kim const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey); 14*e71b7053SJung-uk Kim int EVP_DigestSignUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt); 15*e71b7053SJung-uk Kim int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen); 16*e71b7053SJung-uk Kim 17*e71b7053SJung-uk Kim int EVP_DigestSign(EVP_MD_CTX *ctx, unsigned char *sigret, 18*e71b7053SJung-uk Kim size_t *siglen, const unsigned char *tbs, 19*e71b7053SJung-uk Kim size_t tbslen); 20*e71b7053SJung-uk Kim 21*e71b7053SJung-uk Kim=head1 DESCRIPTION 22*e71b7053SJung-uk Kim 23*e71b7053SJung-uk KimThe EVP signature routines are a high level interface to digital signatures. 24*e71b7053SJung-uk Kim 25*e71b7053SJung-uk KimEVP_DigestSignInit() sets up signing context B<ctx> to use digest B<type> from 26*e71b7053SJung-uk KimENGINE B<e> and private key B<pkey>. B<ctx> must be created with 27*e71b7053SJung-uk KimEVP_MD_CTX_new() before calling this function. If B<pctx> is not NULL, the 28*e71b7053SJung-uk KimEVP_PKEY_CTX of the signing operation will be written to B<*pctx>: this can 29*e71b7053SJung-uk Kimbe used to set alternative signing options. Note that any existing value in 30*e71b7053SJung-uk KimB<*pctx> is overwritten. The EVP_PKEY_CTX value returned must not be freed 31*e71b7053SJung-uk Kimdirectly by the application if B<ctx> is not assigned an EVP_PKEY_CTX value before 32*e71b7053SJung-uk Kimbeing passed to EVP_DigestSignInit() (which means the EVP_PKEY_CTX is created 33*e71b7053SJung-uk Kiminside EVP_DigestSignInit() and it will be freed automatically when the 34*e71b7053SJung-uk KimEVP_MD_CTX is freed). 35*e71b7053SJung-uk Kim 36*e71b7053SJung-uk KimThe digest B<type> may be NULL if the signing algorithm supports it. 37*e71b7053SJung-uk Kim 38*e71b7053SJung-uk KimNo B<EVP_PKEY_CTX> will be created by EVP_DigsetSignInit() if the passed B<ctx> 39*e71b7053SJung-uk Kimhas already been assigned one via L<EVP_MD_CTX_set_ctx(3)>. See also L<SM2(7)>. 40*e71b7053SJung-uk Kim 41*e71b7053SJung-uk KimOnly EVP_PKEY types that support signing can be used with these functions. This 42*e71b7053SJung-uk Kimincludes MAC algorithms where the MAC generation is considered as a form of 43*e71b7053SJung-uk Kim"signing". Built-in EVP_PKEY types supported by these functions are CMAC, 44*e71b7053SJung-uk KimPoly1305, DSA, ECDSA, HMAC, RSA, SipHash, Ed25519 and Ed448. 45*e71b7053SJung-uk Kim 46*e71b7053SJung-uk KimNot all digests can be used for all key types. The following combinations apply. 47*e71b7053SJung-uk Kim 48*e71b7053SJung-uk Kim=over 4 49*e71b7053SJung-uk Kim 50*e71b7053SJung-uk Kim=item DSA 51*e71b7053SJung-uk Kim 52*e71b7053SJung-uk KimSupports SHA1, SHA224, SHA256, SHA384 and SHA512 53*e71b7053SJung-uk Kim 54*e71b7053SJung-uk Kim=item ECDSA 55*e71b7053SJung-uk Kim 56*e71b7053SJung-uk KimSupports SHA1, SHA224, SHA256, SHA384, SHA512 and SM3 57*e71b7053SJung-uk Kim 58*e71b7053SJung-uk Kim=item RSA with no padding 59*e71b7053SJung-uk Kim 60*e71b7053SJung-uk KimSupports no digests (the digest B<type> must be NULL) 61*e71b7053SJung-uk Kim 62*e71b7053SJung-uk Kim=item RSA with X931 padding 63*e71b7053SJung-uk Kim 64*e71b7053SJung-uk KimSupports SHA1, SHA256, SHA384 and SHA512 65*e71b7053SJung-uk Kim 66*e71b7053SJung-uk Kim=item All other RSA padding types 67*e71b7053SJung-uk Kim 68*e71b7053SJung-uk KimSupport SHA1, SHA224, SHA256, SHA384, SHA512, MD5, MD5_SHA1, MD2, MD4, MDC2, 69*e71b7053SJung-uk KimSHA3-224, SHA3-256, SHA3-384, SHA3-512 70*e71b7053SJung-uk Kim 71*e71b7053SJung-uk Kim=item Ed25519 and Ed448 72*e71b7053SJung-uk Kim 73*e71b7053SJung-uk KimSupport no digests (the digest B<type> must be NULL) 74*e71b7053SJung-uk Kim 75*e71b7053SJung-uk Kim=item HMAC 76*e71b7053SJung-uk Kim 77*e71b7053SJung-uk KimSupports any digest 78*e71b7053SJung-uk Kim 79*e71b7053SJung-uk Kim=item CMAC, Poly1305 and SipHash 80*e71b7053SJung-uk Kim 81*e71b7053SJung-uk KimWill ignore any digest provided. 82*e71b7053SJung-uk Kim 83*e71b7053SJung-uk Kim=back 84*e71b7053SJung-uk Kim 85*e71b7053SJung-uk KimIf RSA-PSS is used and restrictions apply then the digest must match. 86*e71b7053SJung-uk Kim 87*e71b7053SJung-uk KimEVP_DigestSignUpdate() hashes B<cnt> bytes of data at B<d> into the 88*e71b7053SJung-uk Kimsignature context B<ctx>. This function can be called several times on the 89*e71b7053SJung-uk Kimsame B<ctx> to include additional data. This function is currently implemented 90*e71b7053SJung-uk Kimusing a macro. 91*e71b7053SJung-uk Kim 92*e71b7053SJung-uk KimEVP_DigestSignFinal() signs the data in B<ctx> and places the signature in B<sig>. 93*e71b7053SJung-uk KimIf B<sig> is B<NULL> then the maximum size of the output buffer is written to 94*e71b7053SJung-uk Kimthe B<siglen> parameter. If B<sig> is not B<NULL> then before the call the 95*e71b7053SJung-uk KimB<siglen> parameter should contain the length of the B<sig> buffer. If the 96*e71b7053SJung-uk Kimcall is successful the signature is written to B<sig> and the amount of data 97*e71b7053SJung-uk Kimwritten to B<siglen>. 98*e71b7053SJung-uk Kim 99*e71b7053SJung-uk KimEVP_DigestSign() signs B<tbslen> bytes of data at B<tbs> and places the 100*e71b7053SJung-uk Kimsignature in B<sig> and its length in B<siglen> in a similar way to 101*e71b7053SJung-uk KimEVP_DigestSignFinal(). 102*e71b7053SJung-uk Kim 103*e71b7053SJung-uk Kim=head1 RETURN VALUES 104*e71b7053SJung-uk Kim 105*e71b7053SJung-uk KimEVP_DigestSignInit(), EVP_DigestSignUpdate(), EVP_DigestSignaFinal() and 106*e71b7053SJung-uk KimEVP_DigestSign() return 1 for success and 0 or a negative value for failure. In 107*e71b7053SJung-uk Kimparticular, a return value of -2 indicates the operation is not supported by the 108*e71b7053SJung-uk Kimpublic key algorithm. 109*e71b7053SJung-uk Kim 110*e71b7053SJung-uk KimThe error codes can be obtained from L<ERR_get_error(3)>. 111*e71b7053SJung-uk Kim 112*e71b7053SJung-uk Kim=head1 NOTES 113*e71b7053SJung-uk Kim 114*e71b7053SJung-uk KimThe B<EVP> interface to digital signatures should almost always be used in 115*e71b7053SJung-uk Kimpreference to the low level interfaces. This is because the code then becomes 116*e71b7053SJung-uk Kimtransparent to the algorithm used and much more flexible. 117*e71b7053SJung-uk Kim 118*e71b7053SJung-uk KimEVP_DigestSign() is a one shot operation which signs a single block of data 119*e71b7053SJung-uk Kimin one function. For algorithms that support streaming it is equivalent to 120*e71b7053SJung-uk Kimcalling EVP_DigestSignUpdate() and EVP_DigestSignFinal(). For algorithms which 121*e71b7053SJung-uk Kimdo not support streaming (e.g. PureEdDSA) it is the only way to sign data. 122*e71b7053SJung-uk Kim 123*e71b7053SJung-uk KimIn previous versions of OpenSSL there was a link between message digest types 124*e71b7053SJung-uk Kimand public key algorithms. This meant that "clone" digests such as EVP_dss1() 125*e71b7053SJung-uk Kimneeded to be used to sign using SHA1 and DSA. This is no longer necessary and 126*e71b7053SJung-uk Kimthe use of clone digest is now discouraged. 127*e71b7053SJung-uk Kim 128*e71b7053SJung-uk KimFor some key types and parameters the random number generator must be seeded 129*e71b7053SJung-uk Kimor the operation will fail. 130*e71b7053SJung-uk Kim 131*e71b7053SJung-uk KimThe call to EVP_DigestSignFinal() internally finalizes a copy of the digest 132*e71b7053SJung-uk Kimcontext. This means that calls to EVP_DigestSignUpdate() and 133*e71b7053SJung-uk KimEVP_DigestSignFinal() can be called later to digest and sign additional data. 134*e71b7053SJung-uk Kim 135*e71b7053SJung-uk KimSince only a copy of the digest context is ever finalized, the context must 136*e71b7053SJung-uk Kimbe cleaned up after use by calling EVP_MD_CTX_free() or a memory leak 137*e71b7053SJung-uk Kimwill occur. 138*e71b7053SJung-uk Kim 139*e71b7053SJung-uk KimThe use of EVP_PKEY_size() with these functions is discouraged because some 140*e71b7053SJung-uk Kimsignature operations may have a signature length which depends on the 141*e71b7053SJung-uk Kimparameters set. As a result EVP_PKEY_size() would have to return a value 142*e71b7053SJung-uk Kimwhich indicates the maximum possible signature for any set of parameters. 143*e71b7053SJung-uk Kim 144*e71b7053SJung-uk Kim=head1 SEE ALSO 145*e71b7053SJung-uk Kim 146*e71b7053SJung-uk KimL<EVP_DigestVerifyInit(3)>, 147*e71b7053SJung-uk KimL<EVP_DigestInit(3)>, 148*e71b7053SJung-uk KimL<evp(7)>, L<HMAC(3)>, L<MD2(3)>, 149*e71b7053SJung-uk KimL<MD5(3)>, L<MDC2(3)>, L<RIPEMD160(3)>, 150*e71b7053SJung-uk KimL<SHA1(3)>, L<dgst(1)> 151*e71b7053SJung-uk Kim 152*e71b7053SJung-uk Kim=head1 HISTORY 153*e71b7053SJung-uk Kim 154*e71b7053SJung-uk KimEVP_DigestSignInit(), EVP_DigestSignUpdate() and EVP_DigestSignFinal() 155*e71b7053SJung-uk Kimwere first added to OpenSSL 1.0.0. 156*e71b7053SJung-uk Kim 157*e71b7053SJung-uk Kim=head1 COPYRIGHT 158*e71b7053SJung-uk Kim 159*e71b7053SJung-uk KimCopyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved. 160*e71b7053SJung-uk Kim 161*e71b7053SJung-uk KimLicensed under the OpenSSL license (the "License"). You may not use 162*e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 163*e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 164*e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 165*e71b7053SJung-uk Kim 166*e71b7053SJung-uk Kim=cut 167