1 /*  Copyright (C) 2016-2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
2  *  SPDX-License-Identifier: GPL-3.0-or-later
3  */
4 
5 #pragma once
6 
7 #include "lib/defines.h"
8 
9 /* RFC7873 Appendix B.2 mentions an algorithm using two values before the
10  * actual server cookie hash. */
11 
12 /** Nonce value length. */
13 #define KR_NONCE_LEN 8
14 
15 /** Input data to generate nonce from. */
16 struct kr_nonce_input {
17 	uint32_t rand; /**< some random value */
18 	uint32_t time; /**< time stamp */
19 };
20 
21 /**
22  * @brief Writes server cookie nonce value into given buffer.
23  *
24  * @param buf     buffer to write nonce data in wire format into
25  * @param buf_len buffer size
26  * @param input   data to generate wire data from
27  * @return non-zero size of written data on success, 0 on failure
28  */
29 KR_EXPORT
30 uint16_t kr_nonce_write_wire(uint8_t *buf, uint16_t buf_len,
31                              const struct kr_nonce_input *input);
32