Sortix nightly manual
This manual documents Sortix nightly, a development build that has not been officially released. You can instead view this document in the latest official manual.
NAME
EVP_PKEY_sign_init, EVP_PKEY_sign — sign using a public key algorithmSYNOPSIS
#include <openssl/evp.h>EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx);
EVP_PKEY_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbslen);
DESCRIPTION
The EVP_PKEY_sign_init() function initializes a public key algorithm context using the key ctx->pkey for a signing operation.RETURN VALUES
EVP_PKEY_sign_init() and EVP_PKEY_sign() return 1 for success and 0 or a negative value for failure. In particular, a return value of -2 indicates the operation is not supported by the public key algorithm.EXAMPLES
Sign data using RSA with PKCS#1 padding and SHA256 digest:#include <openssl/evp.h> #include <openssl/rsa.h> EVP_PKEY_CTX *ctx; /* md is a SHA-256 digest in this example. */ unsigned char *md, *sig; size_t mdlen = 32, siglen; EVP_PKEY *signing_key; /* * NB: assumes signing_key and md are set up before the next * step. signing_key must be an RSA private key and md must * point to the SHA-256 digest to be signed. */ ctx = EVP_PKEY_CTX_new(signing_key, NULL /* no engine */); if (!ctx) /* Error occurred */ if (EVP_PKEY_sign_init(ctx) <= 0) /* Error */ if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0) /* Error */ if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0) /* Error */ /* Determine buffer length */ if (EVP_PKEY_sign(ctx, NULL, &siglen, md, mdlen) <= 0) /* Error */ sig = malloc(siglen); if (!sig) /* malloc failure */ if (EVP_PKEY_sign(ctx, sig, &siglen, md, mdlen) <= 0) /* Error */ /* Signature is siglen bytes written to buffer sig */