ndn-lite
tc_ctr_prng.h
Go to the documentation of this file.
1 /* ctr_prng.h - TinyCrypt interface to a CTR-PRNG implementation */
2 
3 /*
4  * Copyright (c) 2016, Chris Morrison
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * * Redistributions of source code must retain the above copyright notice, this
11  * list of conditions and the following disclaimer.
12  *
13  * * Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
59 #ifndef __TC_CTR_PRNG_H__
60 #define __TC_CTR_PRNG_H__
61 
62 #include "tc_aes.h"
63 
64 #define TC_CTR_PRNG_RESEED_REQ -1
65 
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69 
70 typedef struct {
71  /* updated each time another BLOCKLEN_BYTES bytes are produced */
72  uint8_t V[TC_AES_BLOCK_SIZE];
73 
74  /* updated whenever the PRNG is reseeded */
76 
77  /* number of requests since initialization/reseeding */
78  uint64_t reseedCount;
79 } TCCtrPrng_t;
80 
81 
101 int tc_ctr_prng_init(TCCtrPrng_t * const ctx,
102  uint8_t const * const entropy,
103  unsigned int entropyLen,
104  uint8_t const * const personalization,
105  unsigned int pLen);
106 
126 int tc_ctr_prng_reseed(TCCtrPrng_t * const ctx,
127  uint8_t const * const entropy,
128  unsigned int entropyLen,
129  uint8_t const * const additional_input,
130  unsigned int additionallen);
131 
148 int tc_ctr_prng_generate(TCCtrPrng_t * const ctx,
149  uint8_t const * const additional_input,
150  unsigned int additionallen,
151  uint8_t * const out,
152  unsigned int outlen);
153 
160 void tc_ctr_prng_uninstantiate(TCCtrPrng_t * const ctx);
161 
162 #ifdef __cplusplus
163 }
164 #endif
165 
166 #endif /* __TC_CTR_PRNG_H__ */
void tc_ctr_prng_uninstantiate(TCCtrPrng_t *const ctx)
CTR-PRNG uninstantiate procedure Zeroes the internal state of the supplied prng context.
Definition: tc_ctr_prng.c:272
– Interface to an AES-128 implementation.
#define TC_AES_BLOCK_SIZE
Definition: tc_aes.h:61
uint64_t reseedCount
Definition: tc_ctr_prng.h:78
Definition: tc_ctr_prng.h:70
int tc_ctr_prng_generate(TCCtrPrng_t *const ctx, uint8_t const *const additional_input, unsigned int additionallen, uint8_t *const out, unsigned int outlen)
CTR-PRNG generate procedure Generates outlen pseudo-random bytes into out buffer, updates prng.
Definition: tc_ctr_prng.c:205
int tc_ctr_prng_init(TCCtrPrng_t *const ctx, uint8_t const *const entropy, unsigned int entropyLen, uint8_t const *const personalization, unsigned int pLen)
CTR-PRNG initialization procedure Initializes prng context with entropy and personalization string (i...
Definition: tc_ctr_prng.c:117
Definition: tc_aes.h:64
int tc_ctr_prng_reseed(TCCtrPrng_t *const ctx, uint8_t const *const entropy, unsigned int entropyLen, uint8_t const *const additional_input, unsigned int additionallen)
CTR-PRNG reseed procedure Mixes entropy and additional_input into the prng context.
Definition: tc_ctr_prng.c:164