"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.16.7/lib/isc/include/isc/hmac.h" (4 Sep 2020, 3969 Bytes) of package /linux/misc/dns/bind9/9.16.7/bind-9.16.7.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "hmac.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 /*!
   13  * \file isc/hmac.h
   14  * \brief This is the header for for message authentication code.
   15  */
   16 
   17 #pragma once
   18 
   19 #include <isc/lang.h>
   20 #include <isc/md.h>
   21 #include <isc/platform.h>
   22 #include <isc/result.h>
   23 #include <isc/types.h>
   24 
   25 typedef void isc_hmac_t;
   26 
   27 /**
   28  * isc_hmac:
   29  * @type: the digest type
   30  * @key: the key
   31  * @keylen: the length of the key
   32  * @buf: data to hash
   33  * @len: length of the data to hash
   34  * @digest: the output buffer
   35  * @digestlen: the length of the data written to @digest
   36  *
   37  * This function computes the message authentication code using a digest type
   38  * @type with key @key which is @keylen bytes long from data in @buf which is
   39  * @len bytes long, and places the output into @digest, which must have space
   40  * for the hash function output (use ISC_MAX_MD_SIZE if unsure).  If the
   41  * @digestlen parameter is not NULL then the number of bytes of data written
   42  * (i.e. the length of the digest) will be written to the @digestlen.
   43  */
   44 isc_result_t
   45 isc_hmac(const isc_md_type_t *type, const void *key, const int keylen,
   46      const unsigned char *buf, const size_t len, unsigned char *digest,
   47      unsigned int *digestlen);
   48 
   49 /**
   50  * isc_hmac_new:
   51  *
   52  * This function allocates, initializes and returns HMAC context.
   53  */
   54 isc_hmac_t *
   55 isc_hmac_new(void);
   56 
   57 /**
   58  * isc_hmac_free:
   59  * @md: HMAC context
   60  *
   61  * This function cleans up HMAC context and frees up the space allocated to it.
   62  */
   63 void
   64 isc_hmac_free(isc_hmac_t *hmac);
   65 
   66 /**
   67  * isc_hmac_init:
   68  * @md: HMAC context
   69  * @key: HMAC key
   70  * @keylen: HMAC key length
   71  * @type: digest type
   72  *
   73  * This function sets up HMAC context to use a hash function of @type and key
   74  * @key which is @keylen bytes long.
   75  */
   76 
   77 isc_result_t
   78 isc_hmac_init(isc_hmac_t *hmac, const void *key, size_t keylen,
   79           const isc_md_type_t *type);
   80 
   81 /**
   82  * isc_hmac_reset:
   83  * @hmac: HMAC context
   84  *
   85  * This function resets the HMAC context.  This can be used to reuse an already
   86  * existing context.
   87  */
   88 isc_result_t
   89 isc_hmac_reset(isc_hmac_t *hmac);
   90 
   91 /**
   92  * isc_hmac_update:
   93  * @hmac: HMAC context
   94  * @buf: data to hash
   95  * @len: length of the data to hash
   96  *
   97  * This function can be called repeatedly with chunks of the message @buf to be
   98  * authenticated which is @len bytes long.
   99  */
  100 isc_result_t
  101 isc_hmac_update(isc_hmac_t *hmac, const unsigned char *buf, const size_t len);
  102 
  103 /**
  104  * isc_hmac_final:
  105  * @hmac: HMAC context
  106  * @digest: the output buffer
  107  * @digestlen: the length of the data written to @digest
  108  *
  109  * This function retrieves the message authentication code from @hmac and places
  110  * it in @digest, which must have space for the hash function output.  If the
  111  * @digestlen parameter is not NULL then the number of bytes of data written
  112  * (i.e. the length of the digest) will be written to the @digestlen.  After
  113  * calling this function no additional calls to isc_hmac_update() can be made.
  114  */
  115 isc_result_t
  116 isc_hmac_final(isc_hmac_t *hmac, unsigned char *digest,
  117            unsigned int *digestlen);
  118 
  119 /**
  120  * isc_hmac_md_type:
  121  * @hmac: HMAC context
  122  *
  123  * This function return the isc_md_type_t previously set for the supplied
  124  * HMAC context or NULL if no isc_md_type_t has been set.
  125  */
  126 const isc_md_type_t *
  127 isc_hmac_get_md_type(isc_hmac_t *hmac);
  128 
  129 /**
  130  * isc_hmac_get_size:
  131  *
  132  * This function return the size of the message digest when passed an isc_hmac_t
  133  * structure, i.e. the size of the hash.
  134  */
  135 size_t
  136 isc_hmac_get_size(isc_hmac_t *hmac);
  137 
  138 /**
  139  * isc_hmac_get_block_size:
  140  *
  141  * This function return the block size of the message digest when passed an
  142  * isc_hmac_t structure.
  143  */
  144 int
  145 isc_hmac_get_block_size(isc_hmac_t *hmac);