NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
hmac_prng.h
Go to the documentation of this file.
1/* hmac_prng.h - TinyCrypt interface to an HMAC-PRNG implementation */
2
3/*
4 * Copyright (C) 2017 by Intel Corporation, All Rights Reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * - Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * - Neither the name of Intel Corporation nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
68#ifndef __TC_HMAC_PRNG_H__
69#define __TC_HMAC_PRNG_H__
70
71#include "sha256.h"
72#include "hmac.h"
73
74#ifdef __cplusplus
75extern "C" {
76#endif
77
78#define TC_HMAC_PRNG_RESEED_REQ -1
79
80struct tc_hmac_prng_struct {
81 /* the HMAC instance for this PRNG */
82 struct tc_hmac_state_struct h;
83 /* the PRNG key */
84 uint8_t key[TC_SHA256_DIGEST_SIZE];
85 /* PRNG state */
86 uint8_t v[TC_SHA256_DIGEST_SIZE];
87 /* calls to tc_hmac_prng_generate left before re-seed */
88 unsigned int countdown;
89};
90
91typedef struct tc_hmac_prng_struct *TCHmacPrng_t;
92
115int tc_hmac_prng_init(TCHmacPrng_t prng,
116 const uint8_t *personalization,
117 unsigned int plen);
118
139int tc_hmac_prng_reseed(TCHmacPrng_t prng, const uint8_t *seed,
140 unsigned int seedlen, const uint8_t *additional_input,
141 unsigned int additionallen);
142
158int tc_hmac_prng_generate(uint8_t *out, unsigned int outlen, TCHmacPrng_t prng);
159
160#ifdef __cplusplus
161}
162#endif
163
164#endif /* __TC_HMAC_PRNG_H__ */
Interface to an HMAC implementation.
int tc_hmac_prng_init(TCHmacPrng_t prng, const uint8_t *personalization, unsigned int plen)
HMAC-PRNG initialization procedure Initializes prng with personalization, disables tc_hmac_prng_gener...
Definition hmac_prng.c:112
int tc_hmac_prng_generate(uint8_t *out, unsigned int outlen, TCHmacPrng_t prng)
HMAC-PRNG generate procedure Generates outlen pseudo-random bytes into out buffer,...
Definition hmac_prng.c:177
int tc_hmac_prng_reseed(TCHmacPrng_t prng, const uint8_t *seed, unsigned int seedlen, const uint8_t *additional_input, unsigned int additionallen)
HMAC-PRNG reseed procedure Mixes seed into prng, enables tc_hmac_prng_generate.
Definition hmac_prng.c:138
Interface to a SHA-256 implementation.