EVP_SIGNINIT(3ossl)

πŸ’– EVP_SIGNINIT β€” bestie edition πŸ’–

okay so you opened the EVP_SignInit man page from the OpenSSL crew (that's 3ossl, the whole family of pages) and you're like "what is this". don't worry, i got you. sit down, hydrate, let's talk about signing things. ✨


✨ NAME ✨

EVP_SignInit, EVP_SignInit_ex, EVP_SignUpdate, EVP_SignFinal_ex, EVP_SignFinal β€” the EVP signing girlies. digital signatures, high level, no drama. 🫢


πŸŽ€ SYNOPSIS πŸŽ€

#include <openssl/evp.h>

int EVP_SignInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
int EVP_SignUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
int EVP_SignFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s,
                     EVP_PKEY *pkey, OSSL_LIB_CTX *libctx, const char *propq);
int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sig, unsigned int *s,
                  EVP_PKEY *pkey);

void EVP_SignInit(EVP_MD_CTX *ctx, const EVP_MD *type);

🌸 DESCRIPTION 🌸

The EVP signature routines are a high-level interface to digital signatures. like, the glow-up version. the main character version. πŸ”₯

  • EVP_SignInit_ex() β€” sets up signing context ctx to use digest type from ENGINE impl. lowkey important: ctx must be created with EVP_MD_CTX_new() before you call this. no context, no vibes.
  • EVP_SignUpdate() β€” hashes cnt bytes of data at d into the signature context ctx. you can call this multiple times on the same ctx to keep adding more data. it's giving "keep going bestie". πŸ’…
  • EVP_SignFinal_ex() β€” signs the data in ctx using the private key pkey and puts the signature in sig. the library context libctx and property query propq get used when creating a context to use with the key pkey. sig must be at least EVP_PKEY_get_size(pkey) bytes in size. s is an OUT parameter β€” not used as an IN parameter, okay? don't put anything in there expecting it to matter. the number of bytes of data written (i.e. the length of the signature) gets written to the integer at s, and at most EVP_PKEY_get_size(pkey) bytes will be written. ✨
  • EVP_SignFinal() β€” same as EVP_SignFinal_ex() but it uses default values of NULL for the library context libctx and the property query propq. the "just use the defaults, it's fine" option. πŸ¦‹
  • EVP_SignInit() β€” initializes a signing context ctx to use the default implementation of digest type.

πŸ’œ RETURN VALUES πŸ’œ

EVP_SignInit_ex(), EVP_SignUpdate(), EVP_SignFinal_ex() and EVP_SignFinal() return 1 for success and 0 for failure. that's it, that's the whole vibe check. βœ…/❌

The error codes can be obtained by ERR_get_error(3). go read that one if something went wrong, it will tell you what. 😭


🧚 NOTES 🧚

The EVP interface to digital signatures should almost always be used in preference to the low-level interfaces. why? because your code then becomes transparent to the algorithm used and much more flexible. it's called being adaptable, bestie. πŸ’

When signing with some private key types the random number generator must be seeded. If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to external circumstances (see RAND(7)), the operation will fail. πŸ’€ (not your fault, but still. the operation will fail.)

The call to EVP_SignFinal() internally finalizes a copy of the digest context. this means that calls to EVP_SignUpdate() and EVP_SignFinal() can be called later to digest and sign additional data.cApplications may disable this behavior by setting the EVP_MD_CTX_FLAG_FINALISE context flag via EVP_MD_CTX_set_flags(3). πŸŽ€

Since only a copy of the digest context is ever finalized, the context must be cleaned up after use by calling EVP_MD_CTX_free() or a memory leak will occur. not the cute kind of leak. clean up after yourself, babe. πŸ™ˆ

Note that not all providers support continuation. in case the selected provider does not allow to duplicate contexts, EVP_SignFinal() will finalize the digest context and attempting to process additional data via EVP_SignUpdate() will result in an error. iykyk. 😭


😭 BUGS 😭

Older versions of this documentation wrongly stated that calls to EVP_SignUpdate() could not be made after calling EVP_SignFinal(). they lied. moving on. πŸ™„

Since the private key is passed in the call to EVP_SignFinal(), any error relating to the private key (for example an unsuitable key and digest combination) will not be indicated until after potentially large amounts of data have been passed through EVP_SignUpdate(). like, you do all the work and then it tells you no. brutal. πŸ’€

It is not possible to change the signing parameters using these functions. periodt.

The previous two bugs are fixed in the newer EVP_DigestSign*() functions. slay. go use those if you can. πŸ‘‘


πŸ¦‹ SEE ALSO πŸ¦‹

EVP_PKEY_get_size(3), EVP_PKEY_get_bits(3), EVP_PKEY_get_security_bits(3), EVP_VerifyInit(3), EVP_DigestInit(3), evp(7), HMAC(3), MD2(3), MD5(3), MDC2(3), RIPEMD160(3), SHA1(3), openssl-dgst(1)


⭐ HISTORY ⭐

The function EVP_SignFinal_ex() was added in OpenSSL 3.0. newer, shinier, iconic. ✨


Copyright 2000-2023 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


and that's the whole page, bestie!! πŸŽ€ no cap, you now know more about EVP_SignInit than most of the internet. this was OpenSSL 3.5.9, dated 2026-09-29 β€” love that for us. now go forth and sign things responsibly. mwah. πŸ’–πŸ’…πŸ«Ά

πŸ“¦ where this page comes from