"Fossies" - the Fresh Open Source Software Archive

Member "knot-2.8.3/src/knot/nameserver/tsig_ctx.h" (16 Jul 2019, 2587 Bytes) of package /linux/misc/dns/knot-2.8.3.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 "tsig_ctx.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.7.6_vs_2.8.0.

    1 /*  Copyright (C) 2015 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
    2 
    3     This program is free software: you can redistribute it and/or modify
    4     it under the terms of the GNU General Public License as published by
    5     the Free Software Foundation, either version 3 of the License, or
    6     (at your option) any later version.
    7 
    8     This program is distributed in the hope that it will be useful,
    9     but WITHOUT ANY WARRANTY; without even the implied warranty of
   10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11     GNU General Public License for more details.
   12 
   13     You should have received a copy of the GNU General Public License
   14     along with this program.  If not, see <https://www.gnu.org/licenses/>.
   15  */
   16 
   17 #pragma once
   18 
   19 #include <stdint.h>
   20 
   21 #include "libknot/packet/pkt.h"
   22 #include "libknot/tsig.h"
   23 
   24 #define TSIG_MAX_DIGEST_SIZE 64
   25 
   26 /*!
   27   \brief TSIG context.
   28  */
   29 typedef struct tsig_ctx {
   30     const knot_tsig_key_t *key;
   31     uint64_t prev_signed_time;
   32 
   33     uint8_t digest[TSIG_MAX_DIGEST_SIZE];
   34     size_t digest_size;
   35 
   36     /* Unsigned packets handling. */
   37     unsigned unsigned_count;
   38     uint8_t *buffer;
   39     size_t buffer_used;
   40     size_t buffer_size;
   41 } tsig_ctx_t;
   42 
   43 /*!
   44  * \brief Initialize TSIG context.
   45  *
   46  * \param ctx  TSIG context to be initialized.
   47  * \param key  Key to be used for signing. If NULL, all performed operations
   48  *             will do nothing and always successful.
   49  */
   50 void tsig_init(tsig_ctx_t *ctx, const knot_tsig_key_t *key);
   51 
   52 /*!
   53  * \brief Cleanup TSIG context.
   54  *
   55  * \param ctx TSIG context to be cleaned up.
   56  */
   57 void tsig_cleanup(tsig_ctx_t *ctx);
   58 
   59 /*!
   60  * \brief Reset TSIG context for new message exchange.
   61  */
   62 void tsig_reset(tsig_ctx_t *ctx);
   63 
   64 /*!
   65  * \brief Sign outgoing packet.
   66  *
   67  * \param ctx     TSIG signing context.
   68  * \param packet  Packet to be signed.
   69  *
   70  * \return Error code, KNOT_EOK if successful.
   71  */
   72 int tsig_sign_packet(tsig_ctx_t *ctx, knot_pkt_t *packet);
   73 
   74 /*!
   75  * \brief Verify incoming packet.
   76  *
   77  * If the packet is not signed, the function will succeed, but an internal
   78  * counter of unsigned packets is increased. When a packet is signed, the
   79  * same counter is reset to zero.
   80  *
   81  * \see tsig_unsigned_count
   82  *
   83  * \param ctx     TSIG signing context.
   84  * \param packet  Packet to be verified.
   85  *
   86  * \return Error code, KNOT_EOK if successful.
   87  */
   88 int tsig_verify_packet(tsig_ctx_t *ctx, knot_pkt_t *packet);
   89 
   90 /*!
   91  * \brief Get number of unsigned packets since the last signed one.
   92  *
   93  * \param ctx  TSIG signing context.
   94  *
   95  * \return Number of unsigned packets since the last signed one.
   96  */
   97 unsigned tsig_unsigned_count(tsig_ctx_t *ctx);