Sortix cross-volatile manual
This manual documents Sortix cross-volatile. You can instead view this document in the latest official manual.
NAME
EVP_PKEY_new, EVP_PKEY_up_ref, EVP_PKEY_free, EVP_PKEY_new_raw_private_key, EVP_PKEY_new_raw_public_key, EVP_PKEY_new_mac_key, EVP_PKEY_get_raw_private_key, EVP_PKEY_get_raw_public_key — public and private key allocation and raw key handling functionsSYNOPSIS
library “libcrypto”#include <openssl/evp.h>
EVP_PKEY_new(void);
EVP_PKEY_up_ref(EVP_PKEY *pkey);
EVP_PKEY_free(EVP_PKEY *pkey);
EVP_PKEY_new_raw_private_key(int type, ENGINE *engine, const unsigned char *rawpriv, size_t rawlen);
EVP_PKEY_new_raw_public_key(int type, ENGINE *engine, const unsigned char *rawpub, size_t rawlen);
EVP_PKEY_new_mac_key(int type, ENGINE *engine, const unsigned char *rawpriv, int rawlen);
EVP_PKEY_get_raw_private_key(const EVP_PKEY *pkey, unsigned char *rawpriv, size_t *rawlen);
EVP_PKEY_get_raw_public_key(const EVP_PKEY *pkey, unsigned char *rawpub, size_t *rawlen);
DESCRIPTION
The EVP_PKEY structure is used by various OpenSSL functions which require a general private or public key without reference to any particular algorithm.RETURN VALUES
EVP_PKEY_new(), EVP_PKEY_new_raw_private_key(), EVP_PKEY_new_raw_public_key(), and EVP_PKEY_new_mac_key() return either the newly allocated EVP_PKEY structure or NULL if an error occurred.EXAMPLES
The following code digests a message with HMAC-SHA256:
/* Bogus key: would normally be set from another source */
const unsigned char *key = "key";
const size_t key_len = strlen(key);
const char *msg = "The quick brown fox jumps over the lazy dog";
const size_t msg_len = strlen(msg);
unsigned char *out_mac;
size_t out_len, i;
EVP_PKEY *pkey;
EVP_MD_CTX *md_ctx;
pkey = EVP_PKEY_new_raw_private_key(EVP_PKEY_HMAC, NULL,
key, key_len);
if (pkey == NULL)
err(1, "EVP_PKEY_new_raw_private_key");
md_ctx = EVP_MD_CTX_new();
if (md_ctx == NULL)
err(1, "EVP_MD_CTX_new");
if (EVP_DigestSignInit(md_ctx, NULL, EVP_sha256(), NULL, pkey) == 0)
err(1, "EVP_DigestSignInit");
if (EVP_DigestSign(md_ctx, NULL, &out_len, msg, msg_len) == 0)
err(1, "EVP_DigestSign(NULL)");
if ((out_mac = calloc(1, out_len)) == NULL)
err(1, "calloc");
if (EVP_DigestSign(md_ctx, out_mac, &out_len, msg, msg_len) == 0)
err(1, "EVP_DigestSign(MAC)");
EVP_MD_CTX_free(md_ctx);
EVP_PKEY_free(pkey);
printf(" MAC = ");
for (i = 0; i < out_len; i++)
printf("%02x", out_mac[i]);
printf("\n");
free(out_mac);
= 32 bytes long, replacing EVP_PKEY_HMAC with EVP_PKEY_ED25519, and replacing the call to EVP_sha256(3) with NULL.