2016-05-17 18:52:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
2000-07-19 21:43:23 +00:00
|
|
|
*
|
2016-05-17 18:52:22 +00:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
2000-07-19 21:43:23 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HEADER_RAND_LCL_H
|
2015-01-22 03:40:55 +00:00
|
|
|
# define HEADER_RAND_LCL_H
|
2000-07-19 21:43:23 +00:00
|
|
|
|
2017-06-27 16:04:37 +00:00
|
|
|
# include <openssl/aes.h>
|
|
|
|
# include <openssl/evp.h>
|
|
|
|
# include <openssl/sha.h>
|
|
|
|
# include <openssl/hmac.h>
|
|
|
|
# include <openssl/ec.h>
|
2017-07-20 09:58:28 +00:00
|
|
|
# include "internal/rand.h"
|
2017-06-27 16:04:37 +00:00
|
|
|
|
2017-06-22 13:21:43 +00:00
|
|
|
/* we require 256 bits of randomness */
|
|
|
|
# define RANDOMNESS_NEEDED (256 / 8)
|
2000-07-19 21:43:23 +00:00
|
|
|
|
2017-07-19 21:41:26 +00:00
|
|
|
/* Maximum count allowed in reseeding */
|
|
|
|
#define MAX_RESEED (1 << 24)
|
|
|
|
|
2017-06-27 16:04:37 +00:00
|
|
|
/* DRBG status values */
|
|
|
|
#define DRBG_STATUS_UNINITIALISED 0
|
|
|
|
#define DRBG_STATUS_READY 1
|
|
|
|
#define DRBG_STATUS_RESEED 2
|
|
|
|
#define DRBG_STATUS_ERROR 3
|
|
|
|
|
|
|
|
/* A default maximum length: larger than any reasonable value used in pratice */
|
|
|
|
#define DRBG_MAX_LENGTH 0x7ffffff0
|
|
|
|
|
|
|
|
typedef struct drbg_ctr_ctx_st {
|
|
|
|
AES_KEY ks;
|
|
|
|
size_t keylen;
|
|
|
|
unsigned char K[32];
|
|
|
|
unsigned char V[16];
|
|
|
|
/* Temp variables used by derivation function */
|
|
|
|
AES_KEY df_ks;
|
|
|
|
AES_KEY df_kxks;
|
|
|
|
/* Temporary block storage used by ctr_df */
|
|
|
|
unsigned char bltmp[16];
|
|
|
|
size_t bltmp_pos;
|
|
|
|
unsigned char KX[48];
|
|
|
|
} DRBG_CTR_CTX;
|
|
|
|
|
|
|
|
struct drbg_ctx_st {
|
|
|
|
CRYPTO_RWLOCK *lock;
|
|
|
|
DRBG_CTX *parent;
|
|
|
|
int nid; /* the NID of the underlying algorithm */
|
|
|
|
unsigned int flags; /* various external flags */
|
|
|
|
|
|
|
|
/* The following parameters are setup by mechanism drbg_init() call */
|
|
|
|
int strength;
|
|
|
|
size_t blocklength;
|
|
|
|
size_t max_request;
|
|
|
|
size_t min_entropy, max_entropy;
|
|
|
|
size_t min_nonce, max_nonce;
|
|
|
|
size_t max_pers, max_adin;
|
|
|
|
unsigned int reseed_counter;
|
|
|
|
unsigned int reseed_interval;
|
|
|
|
size_t seedlen;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
/* Application data: typically (only?) used by test get_entropy */
|
|
|
|
CRYPTO_EX_DATA ex_data;
|
|
|
|
|
|
|
|
/* Implementation specific structures */
|
|
|
|
DRBG_CTR_CTX ctr;
|
|
|
|
|
|
|
|
/* entropy gathering function */
|
2017-07-19 22:32:08 +00:00
|
|
|
RAND_DRBG_get_entropy_fn get_entropy;
|
2017-06-27 16:04:37 +00:00
|
|
|
/* Indicates we have finished with entropy buffer */
|
2017-07-19 22:32:08 +00:00
|
|
|
RAND_DRBG_cleanup_entropy_fn cleanup_entropy;
|
2017-06-27 16:04:37 +00:00
|
|
|
/* nonce gathering function */
|
2017-07-19 22:32:08 +00:00
|
|
|
RAND_DRBG_get_nonce_fn get_nonce;
|
2017-06-27 16:04:37 +00:00
|
|
|
/* Indicates we have finished with nonce buffer */
|
2017-07-19 22:32:08 +00:00
|
|
|
RAND_DRBG_cleanup_nonce_fn cleanup_nonce;
|
2017-06-27 16:04:37 +00:00
|
|
|
};
|
2017-06-22 13:21:43 +00:00
|
|
|
|
2000-07-19 21:43:23 +00:00
|
|
|
|
2017-06-22 13:21:43 +00:00
|
|
|
extern RAND_METHOD openssl_rand_meth;
|
2017-06-27 16:04:37 +00:00
|
|
|
void rand_drbg_cleanup(void);
|
|
|
|
|
|
|
|
int ctr_init(DRBG_CTX *dctx);
|
|
|
|
int drbg_hash_init(DRBG_CTX *dctx);
|
|
|
|
int drbg_hmac_init(DRBG_CTX *dctx);
|
|
|
|
int ctr_uninstantiate(DRBG_CTX *dctx);
|
|
|
|
int ctr_instantiate(DRBG_CTX *dctx,
|
|
|
|
const unsigned char *ent, size_t entlen,
|
|
|
|
const unsigned char *nonce, size_t noncelen,
|
|
|
|
const unsigned char *pers, size_t perslen);
|
|
|
|
int ctr_reseed(DRBG_CTX *dctx,
|
|
|
|
const unsigned char *ent, size_t entlen,
|
|
|
|
const unsigned char *adin, size_t adinlen);
|
|
|
|
int ctr_generate(DRBG_CTX *dctx,
|
|
|
|
unsigned char *out, size_t outlen,
|
|
|
|
const unsigned char *adin, size_t adinlen);
|
2000-07-19 21:43:23 +00:00
|
|
|
|
|
|
|
#endif
|