EVP_PKEY_SIGN(3ssl) OpenSSL EVP_PKEY_SIGN(3ssl) EVP_PKEY_sign_init, EVP_PKEY_sign_init_ex, EVP_PKEY_sign_init_ex2, EVP_PKEY_sign, EVP_PKEY_sign_message_init, EVP_PKEY_sign_message_update, EVP_PKEY_sign_message_final - #include int EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx); int EVP_PKEY_sign_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]); int EVP_PKEY_sign_init_ex2(EVP_PKEY_CTX *ctx, EVP_SIGNATURE *algo, const OSSL_PARAM params[]); int EVP_PKEY_sign_message_init(EVP_PKEY_CTX *ctx, EVP_SIGNATURE *algo, const OSSL_PARAM params[]); int EVP_PKEY_sign_message_update(EVP_PKEY_CTX *ctx, unsigned char *in, size_t inlen); int EVP_PKEY_sign_message_final(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, size_t sigsize); int EVP_PKEY_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbslen); EVP_PKEY_sign_init() ctx EVP_PKEY_CTX_new(3) . EVP_SIGNATURE " " provider(7) . EVP_PKEY_sign_init_ex() EVP_PKEY_sign_init() params . EVP_PKEY_sign_init_ex2() ctx algo EVP_PKEY_CTX_new(3) EVP_PKEY_CTX_new_from_pkey(3). ctx . EVP_PKEY_sign_init_ex() ( RSA-SHA256). . EVP_PKEY_sign_message_init() ctx algo EVP_PKEY_CTX_new(3) EVP_PKEY_CTX_new_from_pkey(3). EVP_PKEY_sign() EVP_PKEY_sign_message_update() EVP_PKEY_sign_message_final(). ED25519 RSA-SHA256 . EVP_PKEY_sign_message_update() inlen in . . "" . EVP_PKEY_sign_message_final() sig *siglen sigsize. sig NULL *siglen . EVP_PKEY_sign() . EVP_PKEY_sign_init() EVP_PKEY_sign_init_ex() EVP_PKEY_sign_init_ex2() tbs tbslen . EVP_PKEY_sign_message_init() tbs tbslen . sig NULL siglen. sig NULL siglen sig sig siglen. ( ) . . . RSA ED25519 RSA-SHA256 EVP_PKEY_sign_init_ex2() EVP_PKEY_sign_message_init(). RSA (padding) ( EVP_PKEY_CTX_set_signature_md(3) EVP_PKEY_CTX_set_rsa_padding(3) ) RSA-SHA256 . . EVP_PKEY_CTX_set_signature_md(3) OSSL_PARAM "digest" (OSSL_SIGNATURE_PARAM_DIGEST) . ctx RSA algo "RSA" SHA256 RSA-SHA256. EVP_DigestSignInit(3) . EVP_PKEY_sign_init_ex() EVP_PKEY_sign_init_ex2() EVP_PKEY_sign() . EVP_PKEY_sign_message_init() EVP_PKEY_sign() . 1 0 . EVP_PKEY_sign_init() -2 . RSA PKCS#1 SHA256 RSA PKCS#1 SHA256 : #include #include 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 == NULL) /* 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 = OPENSSL_malloc(siglen); if (sig == NULL) /* malloc failure */ if (EVP_PKEY_sign(ctx, sig, &siglen, md, mdlen) <= 0) /* Error */ /* Signature is siglen bytes written to buffer sig */ RSA-SHA256 RSA-SHA256 . RSA-SHA256 "sha256WithRSAEncryption" RSA_PKCS1_PADDING SHA256. #include #include 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 */); alg = EVP_SIGNATURE_fetch(NULL, "RSA-SHA256", NULL); if (ctx == NULL) /* Error occurred */ if (EVP_PKEY_sign_init_ex2(ctx, alg, NULL) <= 0) /* Error */ /* Determine buffer length */ if (EVP_PKEY_sign(ctx, NULL, &siglen, md, mdlen) <= 0) /* Error */ sig = OPENSSL_malloc(siglen); if (sig == NULL) /* malloc failure */ if (EVP_PKEY_sign(ctx, sig, &siglen, md, mdlen) <= 0) /* Error */ /* Signature is siglen bytes written to buffer sig */ RSA-SHA256 RSA-SHA256 . RSA-SHA256 "sha256WithRSAEncryption" RSA_PKCS1_PADDING. #include #include EVP_PKEY_CTX *ctx; /* in is the input in this example. */ unsigned char *in, *sig; /* inlen is the length of the input in this example. */ size_t inlen, siglen; EVP_PKEY *signing_key; EVP_SIGNATURE *alg; /* * NB: assumes signing_key, in and inlen are set up before * the next step. signing_key must be an RSA private key, * in must point to data to be digested and signed, and * inlen must be the size of the data in bytes. */ ctx = EVP_PKEY_CTX_new(signing_key, NULL /* no engine */); alg = EVP_SIGNATURE_fetch(NULL, "RSA-SHA256", NULL); if (ctx == NULL || alg == NULL) /* Error occurred */ if (EVP_PKEY_sign_message_init(ctx, alg, NULL) <= 0) /* Error */ /* Determine sig buffer length */ if (EVP_PKEY_sign(ctx, NULL, &siglen, in, inlen) <= 0) /* Error */ sig = OPENSSL_malloc(siglen); if (sig == NULL) /* malloc failure */ if (EVP_PKEY_sign(ctx, sig, &siglen, in, inlen) <= 0) /* Error */ /* Signature is siglen bytes written to buffer sig */ RSA-SHA256 . #include #include EVP_PKEY_CTX *ctx; /* in is the input in this example. */ unsigned char *in, *sig; /* inlen is the length of the input in this example. */ size_t inlen, siglen; EVP_PKEY *signing_key; EVP_SIGNATURE *alg; /* * NB: assumes signing_key, in and inlen are set up before * the next step. signing_key must be an RSA private key, * in must point to data to be digested and signed, and * inlen must be the size of the data in bytes. */ ctx = EVP_PKEY_CTX_new(signing_key, NULL /* no engine */); alg = EVP_SIGNATURE_fetch(NULL, "RSA-SHA256", NULL); if (ctx == NULL || alg == NULL) /* Error occurred */ if (EVP_PKEY_sign_message_init(ctx, alg, NULL) <= 0) /* Error */ while (inlen > 0) { if (EVP_PKEY_sign_message_update(ctx, in, inlen)) <= 0) /* Error */ if (inlen > 256) { inlen -= 256; in += 256; } else { inlen = 0; } } /* Determine sig buffer length */ if (EVP_PKEY_sign_message_final(ctx, NULL, &siglen) <= 0) /* Error */ sig = OPENSSL_malloc(siglen); if (sig == NULL) /* malloc failure */ if (EVP_PKEY_sign_message_final(ctx, sig, &siglen) <= 0) /* Error */ /* Signature is siglen bytes written to buffer sig */ EVP_PKEY_CTX_new(3), EVP_PKEY_CTX_ctrl(3), EVP_PKEY_encrypt(3), EVP_PKEY_decrypt(3), EVP_PKEY_verify(3), EVP_PKEY_verify_recover(3), EVP_PKEY_derive(3) EVP_PKEY_sign_init() EVP_PKEY_sign() OpenSSL 1.0.0. EVP_PKEY_sign_init_ex() OpenSSL 3.0. EVP_PKEY_sign_init_ex2() EVP_PKEY_sign_message_init() EVP_PKEY_sign_message_update() EVP_PKEY_sign_message_final() OpenSSL 3.4. 2006-2025 OpenSSL. . Apache 2.0 ( ""). . LICENSE . 3 . . : . 3.6.2 7 2026 EVP_PKEY_SIGN(3ssl)