1 1.1 christos /* 2 1.1 christos * Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved. 3 1.1 christos * 4 1.1 christos * Licensed under the OpenSSL license (the "License"). You may not use 5 1.1 christos * this file except in compliance with the License. You can obtain a copy 6 1.1 christos * in the file LICENSE in the source distribution or at 7 1.1 christos * https://www.openssl.org/source/license.html 8 1.1 christos */ 9 1.1 christos 10 1.1 christos #ifndef HEADER_DRBG_RAND_H 11 1.1 christos # define HEADER_DRBG_RAND_H 12 1.1 christos 13 1.1 christos # include <time.h> 14 1.1 christos # include <openssl/ossl_typ.h> 15 1.1 christos # include <openssl/obj_mac.h> 16 1.1 christos 17 1.1 christos /* 18 1.1 christos * RAND_DRBG flags 19 1.1 christos * 20 1.1 christos * Note: if new flags are added, the constant `rand_drbg_used_flags` 21 1.1 christos * in drbg_lib.c needs to be updated accordingly. 22 1.1 christos */ 23 1.1 christos 24 1.1 christos /* In CTR mode, disable derivation function ctr_df */ 25 1.1 christos # define RAND_DRBG_FLAG_CTR_NO_DF 0x1 26 1.1 christos 27 1.1 christos 28 1.1 christos # if OPENSSL_API_COMPAT < 0x10200000L 29 1.1 christos /* This #define was replaced by an internal constant and should not be used. */ 30 1.1 christos # define RAND_DRBG_USED_FLAGS (RAND_DRBG_FLAG_CTR_NO_DF) 31 1.1 christos # endif 32 1.1 christos 33 1.1 christos /* 34 1.1 christos * Default security strength (in the sense of [NIST SP 800-90Ar1]) 35 1.1 christos * 36 1.1 christos * NIST SP 800-90Ar1 supports the strength of the DRBG being smaller than that 37 1.1 christos * of the cipher by collecting less entropy. The current DRBG implementation 38 1.1 christos * does not take RAND_DRBG_STRENGTH into account and sets the strength of the 39 1.1 christos * DRBG to that of the cipher. 40 1.1 christos * 41 1.1 christos * RAND_DRBG_STRENGTH is currently only used for the legacy RAND 42 1.1 christos * implementation. 43 1.1 christos * 44 1.1 christos * Currently supported ciphers are: NID_aes_128_ctr, NID_aes_192_ctr and 45 1.1 christos * NID_aes_256_ctr 46 1.1 christos */ 47 1.1 christos # define RAND_DRBG_STRENGTH 256 48 1.1 christos /* Default drbg type */ 49 1.1 christos # define RAND_DRBG_TYPE NID_aes_256_ctr 50 1.1 christos /* Default drbg flags */ 51 1.1 christos # define RAND_DRBG_FLAGS 0 52 1.1 christos 53 1.1 christos 54 1.1 christos # ifdef __cplusplus 55 1.1 christos extern "C" { 56 1.1 christos # endif 57 1.1 christos 58 1.1 christos /* 59 1.1 christos * Object lifetime functions. 60 1.1 christos */ 61 1.1 christos RAND_DRBG *RAND_DRBG_new(int type, unsigned int flags, RAND_DRBG *parent); 62 1.1 christos RAND_DRBG *RAND_DRBG_secure_new(int type, unsigned int flags, RAND_DRBG *parent); 63 1.1 christos int RAND_DRBG_set(RAND_DRBG *drbg, int type, unsigned int flags); 64 1.1 christos int RAND_DRBG_set_defaults(int type, unsigned int flags); 65 1.1 christos int RAND_DRBG_instantiate(RAND_DRBG *drbg, 66 1.1 christos const unsigned char *pers, size_t perslen); 67 1.1 christos int RAND_DRBG_uninstantiate(RAND_DRBG *drbg); 68 1.1 christos void RAND_DRBG_free(RAND_DRBG *drbg); 69 1.1 christos 70 1.1 christos /* 71 1.1 christos * Object "use" functions. 72 1.1 christos */ 73 1.1 christos int RAND_DRBG_reseed(RAND_DRBG *drbg, 74 1.1 christos const unsigned char *adin, size_t adinlen, 75 1.1 christos int prediction_resistance); 76 1.1 christos int RAND_DRBG_generate(RAND_DRBG *drbg, unsigned char *out, size_t outlen, 77 1.1 christos int prediction_resistance, 78 1.1 christos const unsigned char *adin, size_t adinlen); 79 1.1 christos int RAND_DRBG_bytes(RAND_DRBG *drbg, unsigned char *out, size_t outlen); 80 1.1 christos 81 1.1 christos int RAND_DRBG_set_reseed_interval(RAND_DRBG *drbg, unsigned int interval); 82 1.1 christos int RAND_DRBG_set_reseed_time_interval(RAND_DRBG *drbg, time_t interval); 83 1.1 christos 84 1.1 christos int RAND_DRBG_set_reseed_defaults( 85 1.1 christos unsigned int master_reseed_interval, 86 1.1 christos unsigned int slave_reseed_interval, 87 1.1 christos time_t master_reseed_time_interval, 88 1.1 christos time_t slave_reseed_time_interval 89 1.1 christos ); 90 1.1 christos 91 1.1 christos RAND_DRBG *RAND_DRBG_get0_master(void); 92 1.1 christos RAND_DRBG *RAND_DRBG_get0_public(void); 93 1.1 christos RAND_DRBG *RAND_DRBG_get0_private(void); 94 1.1 christos 95 1.1 christos /* 96 1.1 christos * EXDATA 97 1.1 christos */ 98 1.1 christos # define RAND_DRBG_get_ex_new_index(l, p, newf, dupf, freef) \ 99 1.1 christos CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DRBG, l, p, newf, dupf, freef) 100 1.1 christos int RAND_DRBG_set_ex_data(RAND_DRBG *drbg, int idx, void *arg); 101 1.1 christos void *RAND_DRBG_get_ex_data(const RAND_DRBG *drbg, int idx); 102 1.1 christos 103 1.1 christos /* 104 1.1 christos * Callback function typedefs 105 1.1 christos */ 106 1.1 christos typedef size_t (*RAND_DRBG_get_entropy_fn)(RAND_DRBG *drbg, 107 1.1 christos unsigned char **pout, 108 1.1 christos int entropy, size_t min_len, 109 1.1 christos size_t max_len, 110 1.1 christos int prediction_resistance); 111 1.1 christos typedef void (*RAND_DRBG_cleanup_entropy_fn)(RAND_DRBG *ctx, 112 1.1 christos unsigned char *out, size_t outlen); 113 1.1 christos typedef size_t (*RAND_DRBG_get_nonce_fn)(RAND_DRBG *drbg, unsigned char **pout, 114 1.1 christos int entropy, size_t min_len, 115 1.1 christos size_t max_len); 116 1.1 christos typedef void (*RAND_DRBG_cleanup_nonce_fn)(RAND_DRBG *drbg, 117 1.1 christos unsigned char *out, size_t outlen); 118 1.1 christos 119 1.1 christos int RAND_DRBG_set_callbacks(RAND_DRBG *drbg, 120 1.1 christos RAND_DRBG_get_entropy_fn get_entropy, 121 1.1 christos RAND_DRBG_cleanup_entropy_fn cleanup_entropy, 122 1.1 christos RAND_DRBG_get_nonce_fn get_nonce, 123 1.1 christos RAND_DRBG_cleanup_nonce_fn cleanup_nonce); 124 1.1 christos 125 1.1 christos 126 1.1 christos # ifdef __cplusplus 127 1.1 christos } 128 1.1 christos # endif 129 1.1 christos 130 1.1 christos #endif 131