Home | History | Annotate | Line # | Download | only in man3
HMAC.pod revision 1.1.1.2
      1      1.1  christos =pod
      2      1.1  christos 
      3      1.1  christos =head1 NAME
      4      1.1  christos 
      5      1.1  christos HMAC,
      6      1.1  christos HMAC_CTX_new,
      7      1.1  christos HMAC_CTX_reset,
      8      1.1  christos HMAC_CTX_free,
      9      1.1  christos HMAC_Init,
     10      1.1  christos HMAC_Init_ex,
     11      1.1  christos HMAC_Update,
     12      1.1  christos HMAC_Final,
     13      1.1  christos HMAC_CTX_copy,
     14      1.1  christos HMAC_CTX_set_flags,
     15      1.1  christos HMAC_CTX_get_md,
     16      1.1  christos HMAC_size
     17      1.1  christos - HMAC message authentication code
     18      1.1  christos 
     19      1.1  christos =head1 SYNOPSIS
     20      1.1  christos 
     21      1.1  christos  #include <openssl/hmac.h>
     22      1.1  christos 
     23      1.1  christos  unsigned char *HMAC(const EVP_MD *evp_md, const void *key,
     24      1.1  christos                      int key_len, const unsigned char *d, int n,
     25      1.1  christos                      unsigned char *md, unsigned int *md_len);
     26      1.1  christos 
     27      1.1  christos  HMAC_CTX *HMAC_CTX_new(void);
     28      1.1  christos  int HMAC_CTX_reset(HMAC_CTX *ctx);
     29      1.1  christos 
     30      1.1  christos  int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len,
     31      1.1  christos                   const EVP_MD *md, ENGINE *impl);
     32      1.1  christos  int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len);
     33      1.1  christos  int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
     34      1.1  christos 
     35      1.1  christos  void HMAC_CTX_free(HMAC_CTX *ctx);
     36      1.1  christos 
     37      1.1  christos  int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx);
     38      1.1  christos  void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags);
     39      1.1  christos  const EVP_MD *HMAC_CTX_get_md(const HMAC_CTX *ctx);
     40      1.1  christos 
     41      1.1  christos  size_t HMAC_size(const HMAC_CTX *e);
     42      1.1  christos 
     43      1.1  christos Deprecated:
     44      1.1  christos 
     45      1.1  christos  #if OPENSSL_API_COMPAT < 0x10100000L
     46      1.1  christos  int HMAC_Init(HMAC_CTX *ctx, const void *key, int key_len,
     47      1.1  christos                const EVP_MD *md);
     48      1.1  christos  #endif
     49      1.1  christos 
     50      1.1  christos =head1 DESCRIPTION
     51      1.1  christos 
     52      1.1  christos HMAC is a MAC (message authentication code), i.e. a keyed hash
     53      1.1  christos function used for message authentication, which is based on a hash
     54      1.1  christos function.
     55      1.1  christos 
     56      1.1  christos HMAC() computes the message authentication code of the B<n> bytes at
     57      1.1  christos B<d> using the hash function B<evp_md> and the key B<key> which is
     58      1.1  christos B<key_len> bytes long.
     59      1.1  christos 
     60      1.1  christos It places the result in B<md> (which must have space for the output of
     61      1.1  christos the hash function, which is no more than B<EVP_MAX_MD_SIZE> bytes).
     62      1.1  christos If B<md> is NULL, the digest is placed in a static array.  The size of
     63      1.1  christos the output is placed in B<md_len>, unless it is B<NULL>. Note: passing a NULL
     64      1.1  christos value for B<md>  to use the static array is not thread safe.
     65      1.1  christos 
     66      1.1  christos B<evp_md> can be EVP_sha1(), EVP_ripemd160() etc.
     67      1.1  christos 
     68      1.1  christos HMAC_CTX_new() creates a new HMAC_CTX in heap memory.
     69      1.1  christos 
     70      1.1  christos HMAC_CTX_reset() zeroes an existing B<HMAC_CTX> and associated
     71      1.1  christos resources, making it suitable for new computations as if it was newly
     72      1.1  christos created with HMAC_CTX_new().
     73      1.1  christos 
     74      1.1  christos HMAC_CTX_free() erases the key and other data from the B<HMAC_CTX>,
     75      1.1  christos releases any associated resources and finally frees the B<HMAC_CTX>
     76      1.1  christos itself.
     77      1.1  christos 
     78      1.1  christos The following functions may be used if the message is not completely
     79      1.1  christos stored in memory:
     80      1.1  christos 
     81      1.1  christos HMAC_Init_ex() initializes or reuses a B<HMAC_CTX> structure to use the hash
     82      1.1  christos function B<evp_md> and key B<key>. If both are NULL, or if B<key> is NULL
     83      1.1  christos and B<evp_md> is the same as the previous call, then the
     84      1.1  christos existing key is
     85      1.1  christos reused. B<ctx> must have been created with HMAC_CTX_new() before the first use
     86      1.1  christos of an B<HMAC_CTX> in this function.
     87      1.1  christos 
     88      1.1  christos If HMAC_Init_ex() is called with B<key> NULL and B<evp_md> is not the
     89      1.1  christos same as the previous digest used by B<ctx> then an error is returned
     90      1.1  christos because reuse of an existing key with a different digest is not supported.
     91      1.1  christos 
     92      1.1  christos HMAC_Init() initializes a B<HMAC_CTX> structure to use the hash
     93      1.1  christos function B<evp_md> and the key B<key> which is B<key_len> bytes
     94  1.1.1.2  christos long.
     95      1.1  christos 
     96      1.1  christos HMAC_Update() can be called repeatedly with chunks of the message to
     97      1.1  christos be authenticated (B<len> bytes at B<data>).
     98      1.1  christos 
     99      1.1  christos HMAC_Final() places the message authentication code in B<md>, which
    100      1.1  christos must have space for the hash function output.
    101      1.1  christos 
    102      1.1  christos HMAC_CTX_copy() copies all of the internal state from B<sctx> into B<dctx>.
    103      1.1  christos 
    104      1.1  christos HMAC_CTX_set_flags() applies the specified flags to the internal EVP_MD_CTXs.
    105      1.1  christos These flags have the same meaning as for L<EVP_MD_CTX_set_flags(3)>.
    106      1.1  christos 
    107      1.1  christos HMAC_CTX_get_md() returns the EVP_MD that has previously been set for the
    108      1.1  christos supplied HMAC_CTX.
    109      1.1  christos 
    110      1.1  christos HMAC_size() returns the length in bytes of the underlying hash function output.
    111      1.1  christos 
    112      1.1  christos =head1 RETURN VALUES
    113      1.1  christos 
    114      1.1  christos HMAC() returns a pointer to the message authentication code or NULL if
    115      1.1  christos an error occurred.
    116      1.1  christos 
    117      1.1  christos HMAC_CTX_new() returns a pointer to a new B<HMAC_CTX> on success or
    118      1.1  christos B<NULL> if an error occurred.
    119      1.1  christos 
    120      1.1  christos HMAC_CTX_reset(), HMAC_Init_ex(), HMAC_Update(), HMAC_Final() and
    121      1.1  christos HMAC_CTX_copy() return 1 for success or 0 if an error occurred.
    122      1.1  christos 
    123      1.1  christos HMAC_CTX_get_md() return the EVP_MD previously set for the supplied HMAC_CTX or
    124      1.1  christos NULL if no EVP_MD has been set.
    125      1.1  christos 
    126      1.1  christos HMAC_size() returns the length in bytes of the underlying hash function output
    127      1.1  christos or zero on error.
    128      1.1  christos 
    129      1.1  christos =head1 CONFORMING TO
    130      1.1  christos 
    131      1.1  christos RFC 2104
    132      1.1  christos 
    133      1.1  christos =head1 SEE ALSO
    134      1.1  christos 
    135      1.1  christos L<SHA1(3)>, L<evp(7)>
    136      1.1  christos 
    137      1.1  christos =head1 HISTORY
    138      1.1  christos 
    139      1.1  christos HMAC_CTX_init() was replaced with HMAC_CTX_reset() in OpenSSL 1.1.0.
    140      1.1  christos 
    141      1.1  christos HMAC_CTX_cleanup() existed in OpenSSL before version 1.1.0.
    142      1.1  christos 
    143      1.1  christos HMAC_CTX_new(), HMAC_CTX_free() and HMAC_CTX_get_md() are new in OpenSSL 1.1.0.
    144      1.1  christos 
    145      1.1  christos HMAC_Init_ex(), HMAC_Update() and HMAC_Final() did not return values in
    146      1.1  christos OpenSSL before version 1.0.0.
    147      1.1  christos 
    148      1.1  christos =head1 COPYRIGHT
    149      1.1  christos 
    150  1.1.1.2  christos Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
    151      1.1  christos 
    152      1.1  christos Licensed under the OpenSSL license (the "License").  You may not use
    153      1.1  christos this file except in compliance with the License.  You can obtain a copy
    154      1.1  christos in the file LICENSE in the source distribution or at
    155      1.1  christos L<https://www.openssl.org/source/license.html>.
    156      1.1  christos 
    157      1.1  christos =cut
    158