716 lines
32 KiB
HTML
Executable File
716 lines
32 KiB
HTML
Executable File
<?xml version="1.0" ?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>EVP_DigestInit</title>
|
|
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
|
<link rev="made" href="mailto:root@localhost" />
|
|
</head>
|
|
|
|
<body style="background-color: white">
|
|
|
|
|
|
<!-- INDEX BEGIN -->
|
|
<div name="index">
|
|
<p><a name="__index__"></a></p>
|
|
|
|
<ul>
|
|
|
|
<li><a href="#name">NAME</a></li>
|
|
<li><a href="#synopsis">SYNOPSIS</a></li>
|
|
<li><a href="#description">DESCRIPTION</a></li>
|
|
<li><a href="#parameters">PARAMETERS</a></li>
|
|
<li><a href="#controls">CONTROLS</a></li>
|
|
<li><a href="#flags">FLAGS</a></li>
|
|
<li><a href="#return_values">RETURN VALUES</a></li>
|
|
<li><a href="#notes">NOTES</a></li>
|
|
<li><a href="#examples">EXAMPLES</a></li>
|
|
<li><a href="#see_also">SEE ALSO</a></li>
|
|
<li><a href="#history">HISTORY</a></li>
|
|
<li><a href="#copyright">COPYRIGHT</a></li>
|
|
</ul>
|
|
|
|
<hr name="index" />
|
|
</div>
|
|
<!-- INDEX END -->
|
|
|
|
<p>
|
|
</p>
|
|
<hr />
|
|
<h1><a name="name">NAME</a></h1>
|
|
<p>EVP_MD_fetch, EVP_MD_up_ref, EVP_MD_free,
|
|
EVP_MD_get_params, EVP_MD_gettable_params,
|
|
EVP_MD_CTX_new, EVP_MD_CTX_reset, EVP_MD_CTX_free, EVP_MD_CTX_copy,
|
|
EVP_MD_CTX_copy_ex, EVP_MD_CTX_ctrl,
|
|
EVP_MD_CTX_set_params, EVP_MD_CTX_get_params,
|
|
EVP_MD_settable_ctx_params, EVP_MD_gettable_ctx_params,
|
|
EVP_MD_CTX_settable_params, EVP_MD_CTX_gettable_params,
|
|
EVP_MD_CTX_set_flags, EVP_MD_CTX_clear_flags, EVP_MD_CTX_test_flags,
|
|
EVP_Digest, EVP_DigestInit_ex, EVP_DigestInit, EVP_DigestUpdate,
|
|
EVP_DigestFinal_ex, EVP_DigestFinalXOF, EVP_DigestFinal,
|
|
EVP_MD_is_a, EVP_MD_name, EVP_MD_number, EVP_MD_names_do_all, EVP_MD_provider,
|
|
EVP_MD_type, EVP_MD_pkey_type, EVP_MD_size, EVP_MD_block_size, EVP_MD_flags,
|
|
EVP_MD_CTX_name,
|
|
EVP_MD_CTX_md, EVP_MD_CTX_type, EVP_MD_CTX_size, EVP_MD_CTX_block_size,
|
|
EVP_MD_CTX_md_data, EVP_MD_CTX_update_fn, EVP_MD_CTX_set_update_fn,
|
|
EVP_md_null,
|
|
EVP_get_digestbyname, EVP_get_digestbynid, EVP_get_digestbyobj,
|
|
EVP_MD_CTX_pkey_ctx, EVP_MD_CTX_set_pkey_ctx,
|
|
EVP_MD_do_all_provided
|
|
- EVP digest routines</p>
|
|
<p>
|
|
</p>
|
|
<hr />
|
|
<h1><a name="synopsis">SYNOPSIS</a></h1>
|
|
<pre>
|
|
#include <openssl/evp.h></pre>
|
|
<pre>
|
|
EVP_MD *EVP_MD_fetch(OPENSSL_CTX *ctx, const char *algorithm,
|
|
const char *properties);
|
|
int EVP_MD_up_ref(EVP_MD *md);
|
|
void EVP_MD_free(EVP_MD *md);
|
|
int EVP_MD_get_params(const EVP_MD *digest, OSSL_PARAM params[]);
|
|
const OSSL_PARAM *EVP_MD_gettable_params(const EVP_MD *digest);
|
|
EVP_MD_CTX *EVP_MD_CTX_new(void);
|
|
int EVP_MD_CTX_reset(EVP_MD_CTX *ctx);
|
|
void EVP_MD_CTX_free(EVP_MD_CTX *ctx);
|
|
void EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void* p2);
|
|
int EVP_MD_CTX_get_params(EVP_MD_CTX *ctx, OSSL_PARAM params[]);
|
|
int EVP_MD_CTX_set_params(EVP_MD_CTX *ctx, const OSSL_PARAM params[]);
|
|
const OSSL_PARAM *EVP_MD_settable_ctx_params(const EVP_MD *md);
|
|
const OSSL_PARAM *EVP_MD_gettable_ctx_params(const EVP_MD *md);
|
|
const OSSL_PARAM *EVP_MD_CTX_settable_params(EVP_MD_CTX *ctx);
|
|
const OSSL_PARAM *EVP_MD_CTX_gettable_params(EVP_MD_CTX *ctx);
|
|
void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags);
|
|
void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags);
|
|
int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags);</pre>
|
|
<pre>
|
|
int EVP_Digest(const void *data, size_t count, unsigned char *md,
|
|
unsigned int *size, const EVP_MD *type, ENGINE *impl);
|
|
int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
|
|
int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt);
|
|
int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s);
|
|
int EVP_DigestFinalXOF(EVP_MD_CTX *ctx, unsigned char *md, size_t len);</pre>
|
|
<pre>
|
|
int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in);</pre>
|
|
<pre>
|
|
int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
|
|
int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s);</pre>
|
|
<pre>
|
|
int EVP_MD_CTX_copy(EVP_MD_CTX *out, EVP_MD_CTX *in);</pre>
|
|
<pre>
|
|
const char *EVP_MD_name(const EVP_MD *md);
|
|
int EVP_MD_number(const EVP_MD *md);
|
|
int EVP_MD_is_a(const EVP_MD *md, const char *name);
|
|
void EVP_MD_names_do_all(const EVP_MD *md,
|
|
void (*fn)(const char *name, void *data),
|
|
void *data);
|
|
const OSSL_PROVIDER *EVP_MD_provider(const EVP_MD *md);
|
|
int EVP_MD_type(const EVP_MD *md);
|
|
int EVP_MD_pkey_type(const EVP_MD *md);
|
|
int EVP_MD_size(const EVP_MD *md);
|
|
int EVP_MD_block_size(const EVP_MD *md);
|
|
unsigned long EVP_MD_flags(const EVP_MD *md);</pre>
|
|
<pre>
|
|
const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx);
|
|
const char *EVP_MD_CTX_name(const EVP_MD_CTX *ctx);
|
|
int EVP_MD_CTX_size(const EVP_MD_CTX *ctx);
|
|
int EVP_MD_CTX_block_size(const EVP_MD_CTX *ctx);
|
|
int EVP_MD_CTX_type(const EVP_MD_CTX *ctx);
|
|
void *EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx);
|
|
int (*EVP_MD_CTX_update_fn(EVP_MD_CTX *ctx))(EVP_MD_CTX *ctx,
|
|
const void *data, size_t count);
|
|
void EVP_MD_CTX_set_update_fn(EVP_MD_CTX *ctx,
|
|
int (*update)(EVP_MD_CTX *ctx,
|
|
const void *data, size_t count));</pre>
|
|
<pre>
|
|
const EVP_MD *EVP_md_null(void);</pre>
|
|
<pre>
|
|
const EVP_MD *EVP_get_digestbyname(const char *name);
|
|
const EVP_MD *EVP_get_digestbynid(int type);
|
|
const EVP_MD *EVP_get_digestbyobj(const ASN1_OBJECT *o);</pre>
|
|
<pre>
|
|
EVP_PKEY_CTX *EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx);
|
|
void EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx);</pre>
|
|
<pre>
|
|
void EVP_MD_do_all_provided(OPENSSL_CTX *libctx,
|
|
void (*fn)(EVP_MD *mac, void *arg),
|
|
void *arg);</pre>
|
|
<p>
|
|
</p>
|
|
<hr />
|
|
<h1><a name="description">DESCRIPTION</a></h1>
|
|
<p>The EVP digest routines are a high level interface to message digests,
|
|
and should be used instead of the digest-specific functions.</p>
|
|
<p>The <strong>EVP_MD</strong> type is a structure for digest method implementation.</p>
|
|
<dl>
|
|
<dt><strong><a name="evp_md_fetch" class="item"><code>EVP_MD_fetch()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Fetches the digest implementation for the given <strong>algorithm</strong> from any
|
|
provider offering it, within the criteria given by the <strong>properties</strong>.
|
|
See <em>provider(7)/Fetching algorithms</em> for further information.</p>
|
|
<p>The returned value must eventually be freed with <a href="#evp_md_free"><code>EVP_MD_free()</code></a>.</p>
|
|
<p>Fetched <strong>EVP_MD</strong> structures are reference counted.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_up_ref" class="item"><code>EVP_MD_up_ref()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Increments the reference count for an <strong>EVP_MD</strong> structure.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_free" class="item"><code>EVP_MD_free()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Decrements the reference count for the fetched <strong>EVP_MD</strong> structure.
|
|
If the reference count drops to 0 then the structure is freed.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_ctx_new" class="item"><code>EVP_MD_CTX_new()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Allocates and returns a digest context.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_ctx_reset" class="item"><code>EVP_MD_CTX_reset()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Resets the digest context <strong>ctx</strong>. This can be used to reuse an already
|
|
existing context.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_ctx_free" class="item"><code>EVP_MD_CTX_free()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Cleans up digest context <strong>ctx</strong> and frees up the space allocated to it.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_ctx_ctrl" class="item"><code>EVP_MD_CTX_ctrl()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>This is a legacy method. <a href="#evp_md_ctx_set_params"><code>EVP_MD_CTX_set_params()</code></a> and <a href="#evp_md_ctx_get_params"><code>EVP_MD_CTX_get_params()</code></a>
|
|
is the mechanism that should be used to set and get parameters that are used by
|
|
providers.
|
|
Performs digest-specific control actions on context <strong>ctx</strong>. The control command
|
|
is indicated in <strong>cmd</strong> and any additional arguments in <strong>p1</strong> and <strong>p2</strong>.
|
|
<a href="#evp_md_ctx_ctrl"><code>EVP_MD_CTX_ctrl()</code></a> must be called after <a href="#evp_digestinit_ex"><code>EVP_DigestInit_ex()</code></a>. Other restrictions
|
|
may apply depending on the control type and digest implementation.
|
|
See <a href="#controls">CONTROLS</a> below for more information.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_get_params" class="item"><code>EVP_MD_get_params()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Retrieves the requested list of <strong>params</strong> from a MD <strong>md</strong>.
|
|
See <a href="#parameters">PARAMETERS</a> below for more information.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_ctx_get_params" class="item"><code>EVP_MD_CTX_get_params()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Retrieves the requested list of <strong>params</strong> from a MD context <strong>ctx</strong>.
|
|
See <a href="#parameters">PARAMETERS</a> below for more information.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_ctx_set_params" class="item"><code>EVP_MD_CTX_set_params()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Sets the list of <strong>params</strong> into a MD context <strong>ctx</strong>.
|
|
See <a href="#parameters">PARAMETERS</a> below for more information.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_gettable_params" class="item"><code>EVP_MD_gettable_params()</code>, <code>EVP_MD_gettable_ctx_params()</code>,
|
|
<code>EVP_MD_settable_ctx_params()</code>, <code>EVP_MD_CTX_gettable_params()</code>,
|
|
<a href="#evp_md_ctx_settable_params"><code>EVP_MD_CTX_settable_params()</code></a></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Get a <strong>OSSL_PARAM</strong> array that describes the retrievable and settable
|
|
parameters. <a href="#evp_md_gettable_params"><code>EVP_MD_gettable_params()</code></a> returns parameters that can be used with
|
|
<a href="#evp_md_get_params"><code>EVP_MD_get_params()</code></a>. <code>EVP_MD_gettable_ctx_params()</code> and
|
|
<code>EVP_MD_CTX_gettable_params()</code> return parameters that can be used with
|
|
<a href="#evp_md_ctx_get_params"><code>EVP_MD_CTX_get_params()</code></a>. <code>EVP_MD_settable_ctx_params()</code> and
|
|
<a href="#evp_md_ctx_settable_params"><code>EVP_MD_CTX_settable_params()</code></a> return parameters that can be used with
|
|
<a href="#evp_md_ctx_set_params"><code>EVP_MD_CTX_set_params()</code></a>.
|
|
See <em>OSSL_PARAM(3)</em> for the use of <strong>OSSL_PARAM</strong> as parameter descriptor.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_ctx_set_flags" class="item"><code>EVP_MD_CTX_set_flags()</code>, <code>EVP_MD_CTX_clear_flags()</code>, <code>EVP_MD_CTX_test_flags()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Sets, clears and tests <strong>ctx</strong> flags. See <a href="#flags">FLAGS</a> below for more information.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_digest" class="item"><code>EVP_Digest()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>A wrapper around the Digest Init_ex, Update and Final_ex functions.
|
|
Hashes <strong>count</strong> bytes of data at <strong>data</strong> using a digest <strong>type</strong> from ENGINE
|
|
<strong>impl</strong>. The digest value is placed in <strong>md</strong> and its length is written at <strong>size</strong>
|
|
if the pointer is not NULL. At most <strong>EVP_MAX_MD_SIZE</strong> bytes will be written.
|
|
If <strong>impl</strong> is NULL the default implementation of digest <strong>type</strong> is used.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_digestinit_ex" class="item"><code>EVP_DigestInit_ex()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Sets up digest context <strong>ctx</strong> to use a digest <strong>type</strong>.
|
|
<strong>type</strong> is typically supplied by a function such as EVP_sha1(), or a
|
|
value explicitly fetched with <a href="#evp_md_fetch"><code>EVP_MD_fetch()</code></a>.</p>
|
|
<p>If <strong>impl</strong> is non-NULL, its implementation of the digest <strong>type</strong> is used if
|
|
there is one, and if not, the default implementation is used.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_digestupdate" class="item"><code>EVP_DigestUpdate()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Hashes <strong>cnt</strong> bytes of data at <strong>d</strong> into the digest context <strong>ctx</strong>. This
|
|
function can be called several times on the same <strong>ctx</strong> to hash additional
|
|
data.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_digestfinal_ex" class="item"><code>EVP_DigestFinal_ex()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Retrieves the digest value from <strong>ctx</strong> and places it in <strong>md</strong>. If the <strong>s</strong>
|
|
parameter is not NULL then the number of bytes of data written (i.e. the
|
|
length of the digest) will be written to the integer at <strong>s</strong>, at most
|
|
<strong>EVP_MAX_MD_SIZE</strong> bytes will be written. After calling <a href="#evp_digestfinal_ex"><code>EVP_DigestFinal_ex()</code></a>
|
|
no additional calls to <a href="#evp_digestupdate"><code>EVP_DigestUpdate()</code></a> can be made, but
|
|
<a href="#evp_digestinit_ex"><code>EVP_DigestInit_ex()</code></a> can be called to initialize a new digest operation.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_digestfinalxof" class="item"><code>EVP_DigestFinalXOF()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Interfaces to extendable-output functions, XOFs, such as SHAKE128 and SHAKE256.
|
|
It retrieves the digest value from <strong>ctx</strong> and places it in <strong>len</strong>-sized <B>md.
|
|
After calling this function no additional calls to <a href="#evp_digestupdate"><code>EVP_DigestUpdate()</code></a> can be
|
|
made, but <a href="#evp_digestinit_ex"><code>EVP_DigestInit_ex()</code></a> can be called to initialize a new operation.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_ctx_copy_ex" class="item"><code>EVP_MD_CTX_copy_ex()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Can be used to copy the message digest state from <strong>in</strong> to <strong>out</strong>. This is
|
|
useful if large amounts of data are to be hashed which only differ in the last
|
|
few bytes.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_digestinit" class="item"><code>EVP_DigestInit()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Behaves in the same way as <a href="#evp_digestinit_ex"><code>EVP_DigestInit_ex()</code></a> except it always uses the
|
|
default digest implementation and calls <a href="#evp_md_ctx_reset"><code>EVP_MD_CTX_reset()</code></a>.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_digestfinal" class="item"><code>EVP_DigestFinal()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Similar to <a href="#evp_digestfinal_ex"><code>EVP_DigestFinal_ex()</code></a> except the digest context <strong>ctx</strong> is
|
|
automatically cleaned up.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_ctx_copy" class="item"><code>EVP_MD_CTX_copy()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Similar to <a href="#evp_md_ctx_copy_ex"><code>EVP_MD_CTX_copy_ex()</code></a> except the destination <strong>out</strong> does not have to
|
|
be initialized.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_is_a" class="item"><code>EVP_MD_is_a()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Returns 1 if <em>md</em> is an implementation of an algorithm that's
|
|
identifiable with <em>name</em>, otherwise 0.</p>
|
|
<p>If <em>md</em> is a legacy digest (it's the return value from the likes of
|
|
EVP_sha256() rather than the result of an EVP_MD_fetch()), only cipher
|
|
names registered with the default library context (see
|
|
<em>OPENSSL_CTX(3)</em>) will be considered.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_number" class="item"><code>EVP_MD_number()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Returns the internal dynamic number assigned to the <em>md</em>. This is
|
|
only useful with fetched <strong>EVP_MD</strong>s.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_name" class="item"><code>EVP_MD_name()</code>,
|
|
<code>EVP_MD_CTX_name()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Return the name of the given message digest. For fetched message
|
|
digests with multiple names, only one of them is returned; it's
|
|
recommended to use <a href="#evp_md_names_do_all"><code>EVP_MD_names_do_all()</code></a> instead.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_names_do_all" class="item"><code>EVP_MD_names_do_all()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Traverses all names for the <em>md</em>, and calls <em>fn</em> with each name and
|
|
<em>data</em>. This is only useful with fetched <strong>EVP_MD</strong>s.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_provider" class="item"><code>EVP_MD_provider()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Returns an <strong>OSSL_PROVIDER</strong> pointer to the provider that implements the given
|
|
<strong>EVP_MD</strong>.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_size" class="item"><code>EVP_MD_size()</code>,
|
|
<code>EVP_MD_CTX_size()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Return the size of the message digest when passed an <strong>EVP_MD</strong> or an
|
|
<strong>EVP_MD_CTX</strong> structure, i.e. the size of the hash.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_block_size" class="item"><code>EVP_MD_block_size()</code>,
|
|
<code>EVP_MD_CTX_block_size()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Return the block size of the message digest when passed an <strong>EVP_MD</strong> or an
|
|
<strong>EVP_MD_CTX</strong> structure.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_type" class="item"><code>EVP_MD_type()</code>,
|
|
<code>EVP_MD_CTX_type()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Return the NID of the OBJECT IDENTIFIER representing the given message digest
|
|
when passed an <strong>EVP_MD</strong> structure. For example, <a href="#evp_md_type"><code>EVP_MD_type(EVP_sha1())</code></a>
|
|
returns <strong>NID_sha1</strong>. This function is normally used when setting ASN1 OIDs.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_ctx_md_data" class="item"><code>EVP_MD_CTX_md_data()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Return the digest method private data for the passed <strong>EVP_MD_CTX</strong>.
|
|
The space is allocated by OpenSSL and has the size originally set with
|
|
<code>EVP_MD_meth_set_app_datasize()</code>.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_ctx_md" class="item"><code>EVP_MD_CTX_md()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Returns the <strong>EVP_MD</strong> structure corresponding to the passed <strong>EVP_MD_CTX</strong>. This
|
|
will be the same <strong>EVP_MD</strong> object originally passed to <a href="#evp_digestinit_ex"><code>EVP_DigestInit_ex()</code></a> (or
|
|
other similar function) when the EVP_MD_CTX was first initialised. Note that
|
|
where explicit fetch is in use (see <a href="#evp_md_fetch">EVP_MD_fetch(3)</a>) the value returned from
|
|
this function will not have its reference count incremented and therefore it
|
|
should not be used after the EVP_MD_CTX is freed.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_ctx_set_update_fn" class="item"><code>EVP_MD_CTX_set_update_fn()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Sets the update function for <strong>ctx</strong> to <strong>update</strong>.
|
|
This is the function that is called by EVP_DigestUpdate. If not set, the
|
|
update function from the <strong>EVP_MD</strong> type specified at initialization is used.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_ctx_update_fn" class="item"><code>EVP_MD_CTX_update_fn()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Returns the update function for <strong>ctx</strong>.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_flags" class="item"><code>EVP_MD_flags()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Returns the <strong>md</strong> flags. Note that these are different from the <strong>EVP_MD_CTX</strong>
|
|
ones. See <em>EVP_MD_meth_set_flags(3)</em> for more information.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_pkey_type" class="item"><code>EVP_MD_pkey_type()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Returns the NID of the public key signing algorithm associated with this
|
|
digest. For example EVP_sha1() is associated with RSA so this will return
|
|
<strong>NID_sha1WithRSAEncryption</strong>. Since digests and signature algorithms are no
|
|
longer linked this function is only retained for compatibility reasons.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_null" class="item"><code>EVP_md_null()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>A "null" message digest that does nothing: i.e. the hash it returns is of zero
|
|
length.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_get_digestbyname" class="item"><code>EVP_get_digestbyname()</code>,
|
|
<code>EVP_get_digestbynid()</code>,
|
|
<code>EVP_get_digestbyobj()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Returns an <strong>EVP_MD</strong> structure when passed a digest name, a digest <strong>NID</strong> or an
|
|
<strong>ASN1_OBJECT</strong> structure respectively.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_ctx_pkey_ctx" class="item"><code>EVP_MD_CTX_pkey_ctx()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Returns the <strong>EVP_PKEY_CTX</strong> assigned to <strong>ctx</strong>. The returned pointer should not
|
|
be freed by the caller.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_ctx_set_pkey_ctx" class="item"><code>EVP_MD_CTX_set_pkey_ctx()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Assigns an <strong>EVP_PKEY_CTX</strong> to <strong>EVP_MD_CTX</strong>. This is usually used to provide
|
|
a customized <strong>EVP_PKEY_CTX</strong> to <em>EVP_DigestSignInit(3)</em> or
|
|
<em>EVP_DigestVerifyInit(3)</em>. The <strong>pctx</strong> passed to this function should be freed
|
|
by the caller. A NULL <strong>pctx</strong> pointer is also allowed to clear the <strong>EVP_PKEY_CTX</strong>
|
|
assigned to <strong>ctx</strong>. In such case, freeing the cleared <strong>EVP_PKEY_CTX</strong> or not
|
|
depends on how the <strong>EVP_PKEY_CTX</strong> is created.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_do_all_provided" class="item"><code>EVP_MD_do_all_provided()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Traverses all messages digests implemented by all activated providers
|
|
in the given library context <em>libctx</em>, and for each of the implementations,
|
|
calls the given function <em>fn</em> with the implementation method and the given
|
|
<em>arg</em> as argument.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>
|
|
</p>
|
|
<hr />
|
|
<h1><a name="parameters">PARAMETERS</a></h1>
|
|
<p>See <em>OSSL_PARAM(3)</em> for information about passing parameters.</p>
|
|
<p><a href="#evp_md_ctx_set_params"><code>EVP_MD_CTX_set_params()</code></a> can be used with the following OSSL_PARAM keys:</p>
|
|
<dl>
|
|
<dt><strong><a name="xoflen_ossl_param_digest_key_xoflen_unsigned_integer" class="item">"xoflen" (<strong>OSSL_PARAM_DIGEST_KEY_XOFLEN</strong>) <unsigned integer></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Sets the digest length for extendable output functions.
|
|
It is used by the SHAKE algorithm and should not exceed what can be given
|
|
using a <strong>size_t</strong>.</p>
|
|
</dd>
|
|
<dt><strong><a name="pad_type_ossl_param_digest_key_pad_type_integer" class="item">"pad_type" (<strong>OSSL_PARAM_DIGEST_KEY_PAD_TYPE</strong>) <integer></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Sets the pad type.
|
|
It is used by the MDC2 algorithm.</p>
|
|
</dd>
|
|
</dl>
|
|
<p><a href="#evp_md_ctx_get_params"><code>EVP_MD_CTX_get_params()</code></a> can be used with the following OSSL_PARAM keys:</p>
|
|
<dl>
|
|
<dt><strong><a name="micalg_ossl_param_digest_key_micalg_utf8_string" class="item">"micalg" (<strong>OSSL_PARAM_DIGEST_KEY_MICALG</strong>) <UTF8 string>.</a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Gets the digest Message Integrity Check algorithm string. This is used when
|
|
creating S/MIME multipart/signed messages, as specified in <a href="http://www.ietf.org/rfc/rfc3851.txt" class="rfc">RFC 3851</a>.
|
|
It may be used by external engines or providers.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>
|
|
</p>
|
|
<hr />
|
|
<h1><a name="controls">CONTROLS</a></h1>
|
|
<p><a href="#evp_md_ctx_ctrl"><code>EVP_MD_CTX_ctrl()</code></a> can be used to send the following standard controls:</p>
|
|
<dl>
|
|
<dt><strong><a name="evp_md_ctrl_micalg" class="item">EVP_MD_CTRL_MICALG</a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Gets the digest Message Integrity Check algorithm string. This is used when
|
|
creating S/MIME multipart/signed messages, as specified in <a href="http://www.ietf.org/rfc/rfc3851.txt" class="rfc">RFC 3851</a>.
|
|
The string value is written to <strong>p2</strong>.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_ctrl_xof_len" class="item">EVP_MD_CTRL_XOF_LEN</a></strong></dt>
|
|
|
|
<dd>
|
|
<p>This control sets the digest length for extendable output functions to <strong>p1</strong>.
|
|
Sending this control directly should not be necessary, the use of
|
|
<a href="#evp_digestfinalxof"><code>EVP_DigestFinalXOF()</code></a> is preferred.
|
|
Currently used by SHAKE.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>
|
|
</p>
|
|
<hr />
|
|
<h1><a name="flags">FLAGS</a></h1>
|
|
<p><a href="#evp_md_ctx_set_flags"><code>EVP_MD_CTX_set_flags()</code></a>, <code>EVP_MD_CTX_clear_flags()</code> and <code>EVP_MD_CTX_test_flags()</code>
|
|
can be used the manipulate and test these <strong>EVP_MD_CTX</strong> flags:</p>
|
|
<dl>
|
|
<dt><strong><a name="evp_md_ctx_flag_oneshot" class="item">EVP_MD_CTX_FLAG_ONESHOT</a></strong></dt>
|
|
|
|
<dd>
|
|
<p>This flag instructs the digest to optimize for one update only, if possible.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_ctx_flag_no_init" class="item">EVP_MD_CTX_FLAG_NO_INIT</a></strong></dt>
|
|
|
|
<dd>
|
|
<p>This flag instructs <a href="#evp_digestinit"><code>EVP_DigestInit()</code></a> and similar not to initialise the
|
|
implementation specific data.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_ctx_flag_finalise" class="item">EVP_MD_CTX_FLAG_FINALISE</a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Some functions such as EVP_DigestSign only finalise copies of internal
|
|
contexts so additional data can be included after the finalisation call.
|
|
This is inefficient if this functionality is not required, and can be
|
|
disabled with this flag.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>
|
|
</p>
|
|
<hr />
|
|
<h1><a name="return_values">RETURN VALUES</a></h1>
|
|
<dl>
|
|
<dt><strong><code>EVP_MD_fetch()</code></strong></dt>
|
|
|
|
<dd>
|
|
<p>Returns a pointer to a <strong>EVP_MD</strong> for success or NULL for failure.</p>
|
|
</dd>
|
|
<dt><strong><code>EVP_MD_up_ref()</code></strong></dt>
|
|
|
|
<dd>
|
|
<p>Returns 1 for success or 0 for failure.</p>
|
|
</dd>
|
|
<dt><strong><code>EVP_DigestInit_ex()</code>,
|
|
<a href="#evp_digestupdate"><code>EVP_DigestUpdate()</code></a>,
|
|
<a href="#evp_digestfinal_ex"><code>EVP_DigestFinal_ex()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Returns 1 for
|
|
success and 0 for failure.</p>
|
|
</dd>
|
|
<dt><strong><code>EVP_MD_CTX_ctrl()</code></strong></dt>
|
|
|
|
<dd>
|
|
<p>Returns 1 if successful or 0 for failure.</p>
|
|
</dd>
|
|
<dt><strong><code>EVP_MD_CTX_set_params()</code>,
|
|
<a href="#evp_md_ctx_get_params"><code>EVP_MD_CTX_get_params()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Returns 1 if successful or 0 for failure.</p>
|
|
</dd>
|
|
<dt><strong><a name="evp_md_ctx_settable_params" class="item"><code>EVP_MD_CTX_settable_params()</code>,
|
|
<code>EVP_MD_CTX_gettable_params()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Return an array of constant <strong>OSSL_PARAM</strong>s, or NULL if there is none
|
|
to get.</p>
|
|
</dd>
|
|
<dt><strong><code>EVP_MD_CTX_copy_ex()</code></strong></dt>
|
|
|
|
<dd>
|
|
<p>Returns 1 if successful or 0 for failure.</p>
|
|
</dd>
|
|
<dt><strong><code>EVP_MD_type()</code>,
|
|
<a href="#evp_md_pkey_type"><code>EVP_MD_pkey_type()</code></a></strong></dt>
|
|
|
|
<dd>
|
|
<p>Returns the NID of the corresponding OBJECT IDENTIFIER or NID_undef if none
|
|
exists.</p>
|
|
</dd>
|
|
<dt><strong><code>EVP_MD_size()</code>,
|
|
<a href="#evp_md_block_size"><code>EVP_MD_block_size()</code></a>,
|
|
<code>EVP_MD_CTX_size()</code>,
|
|
<code>EVP_MD_CTX_block_size()</code></strong></dt>
|
|
|
|
<dd>
|
|
<p>Returns the digest or block size in bytes.</p>
|
|
</dd>
|
|
<dt><strong><code>EVP_md_null()</code></strong></dt>
|
|
|
|
<dd>
|
|
<p>Returns a pointer to the <strong>EVP_MD</strong> structure of the "null" message digest.</p>
|
|
</dd>
|
|
<dt><strong><code>EVP_get_digestbyname()</code>,
|
|
<code>EVP_get_digestbynid()</code>,
|
|
<code>EVP_get_digestbyobj()</code></strong></dt>
|
|
|
|
<dd>
|
|
<p>Returns either an <strong>EVP_MD</strong> structure or NULL if an error occurs.</p>
|
|
</dd>
|
|
<dt><strong><code>EVP_MD_CTX_set_pkey_ctx()</code></strong></dt>
|
|
|
|
<dd>
|
|
<p>This function has no return value.</p>
|
|
</dd>
|
|
</dl>
|
|
<p>
|
|
</p>
|
|
<hr />
|
|
<h1><a name="notes">NOTES</a></h1>
|
|
<p>The <strong>EVP</strong> interface to message digests should almost always be used in
|
|
preference to the low level interfaces. This is because the code then becomes
|
|
transparent to the digest used and much more flexible.</p>
|
|
<p>New applications should use the SHA-2 (such as <em>EVP_sha256(3)</em>) or the SHA-3
|
|
digest algorithms (such as <em>EVP_sha3_512(3)</em>). The other digest algorithms
|
|
are still in common use.</p>
|
|
<p>For most applications the <strong>impl</strong> parameter to <a href="#evp_digestinit_ex"><code>EVP_DigestInit_ex()</code></a> will be
|
|
set to NULL to use the default digest implementation.</p>
|
|
<p>The functions <a href="#evp_digestinit"><code>EVP_DigestInit()</code></a>, <a href="#evp_digestfinal"><code>EVP_DigestFinal()</code></a> and <a href="#evp_md_ctx_copy"><code>EVP_MD_CTX_copy()</code></a> are
|
|
obsolete but are retained to maintain compatibility with existing code. New
|
|
applications should use <a href="#evp_digestinit_ex"><code>EVP_DigestInit_ex()</code></a>, <a href="#evp_digestfinal_ex"><code>EVP_DigestFinal_ex()</code></a> and
|
|
<a href="#evp_md_ctx_copy_ex"><code>EVP_MD_CTX_copy_ex()</code></a> because they can efficiently reuse a digest context
|
|
instead of initializing and cleaning it up on each call and allow non default
|
|
implementations of digests to be specified.</p>
|
|
<p>If digest contexts are not cleaned up after use,
|
|
memory leaks will occur.</p>
|
|
<p><code>EVP_MD_CTX_name()</code>, <code>EVP_MD_CTX_size()</code>, <code>EVP_MD_CTX_block_size()</code>,
|
|
<code>EVP_MD_CTX_type()</code>, <code>EVP_get_digestbynid()</code> and <code>EVP_get_digestbyobj()</code> are defined
|
|
as macros.</p>
|
|
<p><a href="#evp_md_ctx_ctrl"><code>EVP_MD_CTX_ctrl()</code></a> sends commands to message digests for additional configuration
|
|
or control.</p>
|
|
<p>
|
|
</p>
|
|
<hr />
|
|
<h1><a name="examples">EXAMPLES</a></h1>
|
|
<p>This example digests the data "Test Message\n" and "Hello World\n", using the
|
|
digest name passed on the command line.</p>
|
|
<pre>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <openssl/evp.h></pre>
|
|
<pre>
|
|
int main(int argc, char *argv[])
|
|
{
|
|
EVP_MD_CTX *mdctx;
|
|
const EVP_MD *md;
|
|
char mess1[] = "Test Message\n";
|
|
char mess2[] = "Hello World\n";
|
|
unsigned char md_value[EVP_MAX_MD_SIZE];
|
|
unsigned int md_len, i;</pre>
|
|
<pre>
|
|
if (argv[1] == NULL) {
|
|
printf("Usage: mdtest digestname\n");
|
|
exit(1);
|
|
}</pre>
|
|
<pre>
|
|
md = EVP_get_digestbyname(argv[1]);
|
|
if (md == NULL) {
|
|
printf("Unknown message digest %s\n", argv[1]);
|
|
exit(1);
|
|
}</pre>
|
|
<pre>
|
|
mdctx = EVP_MD_CTX_new();
|
|
EVP_DigestInit_ex(mdctx, md, NULL);
|
|
EVP_DigestUpdate(mdctx, mess1, strlen(mess1));
|
|
EVP_DigestUpdate(mdctx, mess2, strlen(mess2));
|
|
EVP_DigestFinal_ex(mdctx, md_value, &md_len);
|
|
EVP_MD_CTX_free(mdctx);</pre>
|
|
<pre>
|
|
printf("Digest is: ");
|
|
for (i = 0; i < md_len; i++)
|
|
printf("%02x", md_value[i]);
|
|
printf("\n");</pre>
|
|
<pre>
|
|
exit(0);
|
|
}</pre>
|
|
<p>
|
|
</p>
|
|
<hr />
|
|
<h1><a name="see_also">SEE ALSO</a></h1>
|
|
<p><em>EVP_MD_meth_new(3)</em>,
|
|
<em>openssl-dgst(1)</em>,
|
|
<em>evp(7)</em>,
|
|
<em>OSSL_PROVIDER(3)</em>,
|
|
<em>OSSL_PARAM(3)</em></p>
|
|
<p>The full list of digest algorithms are provided below.</p>
|
|
<p><em>EVP_blake2b512(3)</em>,
|
|
<em>EVP_md2(3)</em>,
|
|
<em>EVP_md4(3)</em>,
|
|
<em>EVP_md5(3)</em>,
|
|
<em>EVP_mdc2(3)</em>,
|
|
<em>EVP_ripemd160(3)</em>,
|
|
<em>EVP_sha1(3)</em>,
|
|
<em>EVP_sha224(3)</em>,
|
|
<em>EVP_sha3_224(3)</em>,
|
|
<em>EVP_sm3(3)</em>,
|
|
<em>EVP_whirlpool(3)</em>
|
|
<em>provider(7)/Fetching algorithms</em></p>
|
|
<p>
|
|
</p>
|
|
<hr />
|
|
<h1><a name="history">HISTORY</a></h1>
|
|
<p>The <code>EVP_MD_CTX_create()</code> and <code>EVP_MD_CTX_destroy()</code> functions were renamed to
|
|
<a href="#evp_md_ctx_new"><code>EVP_MD_CTX_new()</code></a> and <a href="#evp_md_ctx_free"><code>EVP_MD_CTX_free()</code></a> in OpenSSL 1.1.0, respectively.</p>
|
|
<p>The link between digests and signing algorithms was fixed in OpenSSL 1.0 and
|
|
later, so now EVP_sha1() can be used with RSA and DSA.</p>
|
|
<p>The EVP_dss1() function was removed in OpenSSL 1.1.0.</p>
|
|
<p>The <a href="#evp_md_ctx_set_pkey_ctx"><code>EVP_MD_CTX_set_pkey_ctx()</code></a> function was added in 1.1.1.</p>
|
|
<p>The <a href="#evp_md_fetch"><code>EVP_MD_fetch()</code></a>, <a href="#evp_md_free"><code>EVP_MD_free()</code></a>, <a href="#evp_md_up_ref"><code>EVP_MD_up_ref()</code></a>, <a href="#evp_md_ctx_set_params"><code>EVP_MD_CTX_set_params()</code></a>
|
|
and <a href="#evp_md_ctx_get_params"><code>EVP_MD_CTX_get_params()</code></a> functions were added in 3.0.</p>
|
|
<p>
|
|
</p>
|
|
<hr />
|
|
<h1><a name="copyright">COPYRIGHT</a></h1>
|
|
<p>Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.</p>
|
|
<p>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
|
|
<a href="https://www.openssl.org/source/license.html">https://www.openssl.org/source/license.html</a>.</p>
|
|
|
|
</body>
|
|
|
|
</html>
|