EVP_SignInit.pod 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. =pod
  2. =head1 NAME
  3. EVP_SignInit, EVP_SignInit_ex, EVP_SignUpdate, EVP_SignFinal - EVP signing
  4. functions
  5. =head1 SYNOPSIS
  6. #include <openssl/evp.h>
  7. int EVP_SignInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
  8. int EVP_SignUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
  9. int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *sig,unsigned int *s, EVP_PKEY *pkey);
  10. void EVP_SignInit(EVP_MD_CTX *ctx, const EVP_MD *type);
  11. int EVP_PKEY_size(EVP_PKEY *pkey);
  12. =head1 DESCRIPTION
  13. The EVP signature routines are a high level interface to digital
  14. signatures.
  15. EVP_SignInit_ex() sets up signing context B<ctx> to use digest
  16. B<type> from ENGINE B<impl>. B<ctx> must be initialized with
  17. EVP_MD_CTX_init() before calling this function.
  18. EVP_SignUpdate() hashes B<cnt> bytes of data at B<d> into the
  19. signature context B<ctx>. This function can be called several times on the
  20. same B<ctx> to include additional data.
  21. EVP_SignFinal() signs the data in B<ctx> using the private key B<pkey> and
  22. places the signature in B<sig>. B<sig> must be at least EVP_PKEY_size(pkey)
  23. bytes in size. B<s> is an OUT paramter, and not used as an IN parameter.
  24. The number of bytes of data written (i.e. the length of the signature)
  25. will be written to the integer at B<s>, at most EVP_PKEY_size(pkey) bytes
  26. will be written.
  27. EVP_SignInit() initializes a signing context B<ctx> to use the default
  28. implementation of digest B<type>.
  29. EVP_PKEY_size() returns the maximum size of a signature in bytes. The actual
  30. signature returned by EVP_SignFinal() may be smaller.
  31. =head1 RETURN VALUES
  32. EVP_SignInit_ex(), EVP_SignUpdate() and EVP_SignFinal() return 1
  33. for success and 0 for failure.
  34. EVP_PKEY_size() returns the maximum size of a signature in bytes.
  35. The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
  36. =head1 NOTES
  37. The B<EVP> interface to digital signatures should almost always be used in
  38. preference to the low level interfaces. This is because the code then becomes
  39. transparent to the algorithm used and much more flexible.
  40. Due to the link between message digests and public key algorithms the correct
  41. digest algorithm must be used with the correct public key type. A list of
  42. algorithms and associated public key algorithms appears in
  43. L<EVP_DigestInit(3)|EVP_DigestInit(3)>.
  44. When signing with DSA private keys the random number generator must be seeded
  45. or the operation will fail. The random number generator does not need to be
  46. seeded for RSA signatures.
  47. The call to EVP_SignFinal() internally finalizes a copy of the digest context.
  48. This means that calls to EVP_SignUpdate() and EVP_SignFinal() can be called
  49. later to digest and sign additional data.
  50. Since only a copy of the digest context is ever finalized the context must
  51. be cleaned up after use by calling EVP_MD_CTX_cleanup() or a memory leak
  52. will occur.
  53. =head1 BUGS
  54. Older versions of this documentation wrongly stated that calls to
  55. EVP_SignUpdate() could not be made after calling EVP_SignFinal().
  56. Since the private key is passed in the call to EVP_SignFinal() any error
  57. relating to the private key (for example an unsuitable key and digest
  58. combination) will not be indicated until after potentially large amounts of
  59. data have been passed through EVP_SignUpdate().
  60. It is not possible to change the signing parameters using these function.
  61. The previous two bugs are fixed in the newer EVP_SignDigest*() function.
  62. =head1 SEE ALSO
  63. L<EVP_VerifyInit(3)|EVP_VerifyInit(3)>,
  64. L<EVP_DigestInit(3)|EVP_DigestInit(3)>, L<err(3)|err(3)>,
  65. L<evp(3)|evp(3)>, L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>,
  66. L<md5(3)|md5(3)>, L<mdc2(3)|mdc2(3)>, L<ripemd(3)|ripemd(3)>,
  67. L<sha(3)|sha(3)>, L<dgst(1)|dgst(1)>
  68. =head1 HISTORY
  69. EVP_SignInit(), EVP_SignUpdate() and EVP_SignFinal() are
  70. available in all versions of SSLeay and OpenSSL.
  71. EVP_SignInit_ex() was added in OpenSSL 0.9.7.
  72. =cut