jpayne@69: /* jpayne@69: * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved. jpayne@69: * jpayne@69: * Licensed under the OpenSSL license (the "License"). You may not use jpayne@69: * this file except in compliance with the License. You can obtain a copy jpayne@69: * in the file LICENSE in the source distribution or at jpayne@69: * https://www.openssl.org/source/license.html jpayne@69: */ jpayne@69: jpayne@69: #ifndef HEADER_DRBG_RAND_H jpayne@69: # define HEADER_DRBG_RAND_H jpayne@69: jpayne@69: # include jpayne@69: # include jpayne@69: # include jpayne@69: jpayne@69: /* jpayne@69: * RAND_DRBG flags jpayne@69: * jpayne@69: * Note: if new flags are added, the constant `rand_drbg_used_flags` jpayne@69: * in drbg_lib.c needs to be updated accordingly. jpayne@69: */ jpayne@69: jpayne@69: /* In CTR mode, disable derivation function ctr_df */ jpayne@69: # define RAND_DRBG_FLAG_CTR_NO_DF 0x1 jpayne@69: jpayne@69: jpayne@69: # if OPENSSL_API_COMPAT < 0x10200000L jpayne@69: /* This #define was replaced by an internal constant and should not be used. */ jpayne@69: # define RAND_DRBG_USED_FLAGS (RAND_DRBG_FLAG_CTR_NO_DF) jpayne@69: # endif jpayne@69: jpayne@69: /* jpayne@69: * Default security strength (in the sense of [NIST SP 800-90Ar1]) jpayne@69: * jpayne@69: * NIST SP 800-90Ar1 supports the strength of the DRBG being smaller than that jpayne@69: * of the cipher by collecting less entropy. The current DRBG implementation jpayne@69: * does not take RAND_DRBG_STRENGTH into account and sets the strength of the jpayne@69: * DRBG to that of the cipher. jpayne@69: * jpayne@69: * RAND_DRBG_STRENGTH is currently only used for the legacy RAND jpayne@69: * implementation. jpayne@69: * jpayne@69: * Currently supported ciphers are: NID_aes_128_ctr, NID_aes_192_ctr and jpayne@69: * NID_aes_256_ctr jpayne@69: */ jpayne@69: # define RAND_DRBG_STRENGTH 256 jpayne@69: /* Default drbg type */ jpayne@69: # define RAND_DRBG_TYPE NID_aes_256_ctr jpayne@69: /* Default drbg flags */ jpayne@69: # define RAND_DRBG_FLAGS 0 jpayne@69: jpayne@69: jpayne@69: # ifdef __cplusplus jpayne@69: extern "C" { jpayne@69: # endif jpayne@69: jpayne@69: /* jpayne@69: * Object lifetime functions. jpayne@69: */ jpayne@69: RAND_DRBG *RAND_DRBG_new(int type, unsigned int flags, RAND_DRBG *parent); jpayne@69: RAND_DRBG *RAND_DRBG_secure_new(int type, unsigned int flags, RAND_DRBG *parent); jpayne@69: int RAND_DRBG_set(RAND_DRBG *drbg, int type, unsigned int flags); jpayne@69: int RAND_DRBG_set_defaults(int type, unsigned int flags); jpayne@69: int RAND_DRBG_instantiate(RAND_DRBG *drbg, jpayne@69: const unsigned char *pers, size_t perslen); jpayne@69: int RAND_DRBG_uninstantiate(RAND_DRBG *drbg); jpayne@69: void RAND_DRBG_free(RAND_DRBG *drbg); jpayne@69: jpayne@69: /* jpayne@69: * Object "use" functions. jpayne@69: */ jpayne@69: int RAND_DRBG_reseed(RAND_DRBG *drbg, jpayne@69: const unsigned char *adin, size_t adinlen, jpayne@69: int prediction_resistance); jpayne@69: int RAND_DRBG_generate(RAND_DRBG *drbg, unsigned char *out, size_t outlen, jpayne@69: int prediction_resistance, jpayne@69: const unsigned char *adin, size_t adinlen); jpayne@69: int RAND_DRBG_bytes(RAND_DRBG *drbg, unsigned char *out, size_t outlen); jpayne@69: jpayne@69: int RAND_DRBG_set_reseed_interval(RAND_DRBG *drbg, unsigned int interval); jpayne@69: int RAND_DRBG_set_reseed_time_interval(RAND_DRBG *drbg, time_t interval); jpayne@69: jpayne@69: int RAND_DRBG_set_reseed_defaults( jpayne@69: unsigned int master_reseed_interval, jpayne@69: unsigned int slave_reseed_interval, jpayne@69: time_t master_reseed_time_interval, jpayne@69: time_t slave_reseed_time_interval jpayne@69: ); jpayne@69: jpayne@69: RAND_DRBG *RAND_DRBG_get0_master(void); jpayne@69: RAND_DRBG *RAND_DRBG_get0_public(void); jpayne@69: RAND_DRBG *RAND_DRBG_get0_private(void); jpayne@69: jpayne@69: /* jpayne@69: * EXDATA jpayne@69: */ jpayne@69: # define RAND_DRBG_get_ex_new_index(l, p, newf, dupf, freef) \ jpayne@69: CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DRBG, l, p, newf, dupf, freef) jpayne@69: int RAND_DRBG_set_ex_data(RAND_DRBG *drbg, int idx, void *arg); jpayne@69: void *RAND_DRBG_get_ex_data(const RAND_DRBG *drbg, int idx); jpayne@69: jpayne@69: /* jpayne@69: * Callback function typedefs jpayne@69: */ jpayne@69: typedef size_t (*RAND_DRBG_get_entropy_fn)(RAND_DRBG *drbg, jpayne@69: unsigned char **pout, jpayne@69: int entropy, size_t min_len, jpayne@69: size_t max_len, jpayne@69: int prediction_resistance); jpayne@69: typedef void (*RAND_DRBG_cleanup_entropy_fn)(RAND_DRBG *ctx, jpayne@69: unsigned char *out, size_t outlen); jpayne@69: typedef size_t (*RAND_DRBG_get_nonce_fn)(RAND_DRBG *drbg, unsigned char **pout, jpayne@69: int entropy, size_t min_len, jpayne@69: size_t max_len); jpayne@69: typedef void (*RAND_DRBG_cleanup_nonce_fn)(RAND_DRBG *drbg, jpayne@69: unsigned char *out, size_t outlen); jpayne@69: jpayne@69: int RAND_DRBG_set_callbacks(RAND_DRBG *drbg, jpayne@69: RAND_DRBG_get_entropy_fn get_entropy, jpayne@69: RAND_DRBG_cleanup_entropy_fn cleanup_entropy, jpayne@69: RAND_DRBG_get_nonce_fn get_nonce, jpayne@69: RAND_DRBG_cleanup_nonce_fn cleanup_nonce); jpayne@69: jpayne@69: jpayne@69: # ifdef __cplusplus jpayne@69: } jpayne@69: # endif jpayne@69: jpayne@69: #endif