ndn-lite
tc_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 "tc_sha256.h"
72 #include "tc_hmac.h"
73 
74 #ifdef __cplusplus
75 extern "C" {
76 #endif
77 
78 #define TC_HMAC_PRNG_RESEED_REQ -1
79 
81  /* the HMAC instance for this PRNG */
83  /* the PRNG key */
85  /* PRNG state */
87  /* calls to tc_hmac_prng_generate left before re-seed */
88  unsigned int countdown;
89 };
90 
92 
116  const uint8_t *personalization,
117  unsigned int plen);
118 
139 int 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 
158 int 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__ */
uint8_t v[TC_SHA256_DIGEST_SIZE]
Definition: tc_hmac_prng.h:86
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: tc_hmac_prng.c:112
#define TC_SHA256_DIGEST_SIZE
Definition: tc_sha256.h:68
unsigned int countdown
Definition: tc_hmac_prng.h:88
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: tc_hmac_prng.c:138
struct tc_hmac_state_struct h
Definition: tc_hmac_prng.h:82
Definition: tc_hmac.h:72
struct tc_hmac_prng_struct * TCHmacPrng_t
Definition: tc_hmac_prng.h:91
uint8_t key[TC_SHA256_DIGEST_SIZE]
Definition: tc_hmac_prng.h:84
Definition: tc_hmac_prng.h:80
Interface to a SHA-256 implementation.
Interface to an HMAC implementation.
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: tc_hmac_prng.c:177