Home | History | Annotate | Download | only in include
      1 /*
      2  * prng.h
      3  *
      4  * pseudorandom source
      5  *
      6  * David A. McGrew
      7  * Cisco Systems, Inc.
      8  */
      9 
     10 #ifndef PRNG_H
     11 #define PRNG_H
     12 
     13 #include "rand_source.h"  /* for rand_source_func_t definition       */
     14 #include "aes.h"          /* for aes                                 */
     15 #include "aes_icm.h"      /* for aes ctr                             */
     16 
     17 #define MAX_PRNG_OUT_LEN 0xffffffffU
     18 
     19 /*
     20  * x917_prng is an ANSI X9.17-like AES-based PRNG
     21  */
     22 
     23 typedef struct {
     24   v128_t   state;          /* state data                              */
     25   aes_expanded_key_t key;  /* secret key                              */
     26   uint32_t octet_count;    /* number of octets output since last init */
     27   rand_source_func_t rand; /* random source for re-initialization     */
     28 } x917_prng_t;
     29 
     30 err_status_t
     31 x917_prng_init(rand_source_func_t random_source);
     32 
     33 err_status_t
     34 x917_prng_get_octet_string(uint8_t *dest, uint32_t len);
     35 
     36 
     37 /*
     38  * ctr_prng is an AES-CTR based PRNG
     39  */
     40 
     41 typedef struct {
     42   uint32_t octet_count;    /* number of octets output since last init */
     43   aes_icm_ctx_t   state;   /* state data                              */
     44   rand_source_func_t rand; /* random source for re-initialization     */
     45 } ctr_prng_t;
     46 
     47 err_status_t
     48 ctr_prng_init(rand_source_func_t random_source);
     49 
     50 err_status_t
     51 ctr_prng_get_octet_string(void *dest, uint32_t len);
     52 
     53 
     54 #endif
     55