/*
* The three shared DRBG instances
*
- * There are three shared DRBG instances: <master>, <public>, and <private>.
+ * There are three shared DRBG instances: <primary>, <public>, and
+ * <private>. The <public> and <private> DRBGs are secondary ones.
+ * These are used for non-secret (e.g. nonces) and secret
+ * (e.g. private keys) data respectively.
*/
CRYPTO_RWLOCK *lock;
/*
- * The <master> DRBG
+ * The <primary> DRBG
*
* Not used directly by the application, only for reseeding the two other
* DRBGs. It reseeds itself by pulling either randomness from os entropy
* sources or by consuming randomness which was added by RAND_add().
*
- * The <master> DRBG is a global instance which is accessed concurrently by
+ * The <primary> DRBG is a global instance which is accessed concurrently by
* all threads. The necessary locking is managed automatically by its child
* DRBG instances during reseeding.
*/
- RAND_DRBG *master_drbg;
+ RAND_DRBG *primary_drbg;
/*
* The <public> DRBG
*
* Used by default for generating random bytes using RAND_bytes().
*
- * The <public> DRBG is thread-local, i.e., there is one instance per
- * thread.
+ * The <public> secondary DRBG is thread-local, i.e., there is one instance
+ * per thread.
*/
CRYPTO_THREAD_LOCAL public_drbg;
/*
*
* Used by default for generating private keys using RAND_priv_bytes()
*
- * The <private> DRBG is thread-local, i.e., there is one instance per
- * thread.
+ * The <private> secondary DRBG is thread-local, i.e., there is one
+ * instance per thread.
*/
CRYPTO_THREAD_LOCAL private_drbg;
} DRBG_GLOBAL;
#define RAND_DRBG_TYPE_FLAGS ( \
- RAND_DRBG_FLAG_MASTER | RAND_DRBG_FLAG_PUBLIC | RAND_DRBG_FLAG_PRIVATE )
+ RAND_DRBG_FLAG_PRIMARY | RAND_DRBG_FLAG_PUBLIC | RAND_DRBG_FLAG_PRIVATE )
-#define RAND_DRBG_TYPE_MASTER 0
+#define RAND_DRBG_TYPE_PRIMARY 0
#define RAND_DRBG_TYPE_PUBLIC 1
#define RAND_DRBG_TYPE_PRIVATE 2
/* Defaults */
static int rand_drbg_type[3] = {
- RAND_DRBG_TYPE, /* Master */
+ RAND_DRBG_TYPE, /* Primary */
RAND_DRBG_TYPE, /* Public */
RAND_DRBG_TYPE /* Private */
};
static unsigned int rand_drbg_flags[3] = {
- RAND_DRBG_FLAGS | RAND_DRBG_FLAG_MASTER, /* Master */
- RAND_DRBG_FLAGS | RAND_DRBG_FLAG_PUBLIC, /* Public */
- RAND_DRBG_FLAGS | RAND_DRBG_FLAG_PRIVATE /* Private */
+ RAND_DRBG_FLAGS | RAND_DRBG_FLAG_PRIMARY, /* Primary */
+ RAND_DRBG_FLAGS | RAND_DRBG_FLAG_PUBLIC, /* Public */
+ RAND_DRBG_FLAGS | RAND_DRBG_FLAG_PRIVATE /* Private */
};
-static unsigned int master_reseed_interval = MASTER_RESEED_INTERVAL;
-static unsigned int slave_reseed_interval = SLAVE_RESEED_INTERVAL;
+static unsigned int primary_reseed_interval = PRIMARY_RESEED_INTERVAL;
+static unsigned int secondary_reseed_interval = SECONDARY_RESEED_INTERVAL;
-static time_t master_reseed_time_interval = MASTER_RESEED_TIME_INTERVAL;
-static time_t slave_reseed_time_interval = SLAVE_RESEED_TIME_INTERVAL;
+static time_t primary_reseed_time_interval = PRIMARY_RESEED_TIME_INTERVAL;
+static time_t secondary_reseed_time_interval = SECONDARY_RESEED_TIME_INTERVAL;
/* A logical OR of all used DRBG flag bits (currently there is only one) */
static const unsigned int rand_drbg_used_flags =
RAND_DRBG_FLAG_CTR_NO_DF | RAND_DRBG_FLAG_HMAC | RAND_DRBG_TYPE_FLAGS;
-static RAND_DRBG *drbg_setup(OPENSSL_CTX *ctx, RAND_DRBG *parent, int drbg_type);
+static RAND_DRBG *drbg_setup(OPENSSL_CTX *ctx, RAND_DRBG *parent,
+ int drbg_type);
static int get_drbg_params(int type, unsigned int flags, const char **name,
OSSL_PARAM params[3])
return;
CRYPTO_THREAD_lock_free(dgbl->lock);
- RAND_DRBG_free(dgbl->master_drbg);
+ RAND_DRBG_free(dgbl->primary_drbg);
CRYPTO_THREAD_cleanup_local(&dgbl->private_drbg);
CRYPTO_THREAD_cleanup_local(&dgbl->public_drbg);
int use_df;
if (type == 0 && flags == 0) {
- type = rand_drbg_type[RAND_DRBG_TYPE_MASTER];
- flags = rand_drbg_flags[RAND_DRBG_TYPE_MASTER];
+ type = rand_drbg_type[RAND_DRBG_TYPE_PRIMARY];
+ flags = rand_drbg_flags[RAND_DRBG_TYPE_PRIMARY];
}
if (drbg->parent == NULL) {
- reseed_interval = master_reseed_interval;
- reseed_time_interval = master_reseed_time_interval;
+ reseed_interval = primary_reseed_interval;
+ reseed_time_interval = primary_reseed_time_interval;
} else {
- reseed_interval = slave_reseed_interval;
- reseed_time_interval = slave_reseed_time_interval;
+ reseed_interval = secondary_reseed_interval;
+ reseed_time_interval = secondary_reseed_time_interval;
}
*p++ = OSSL_PARAM_construct_uint(OSSL_DRBG_PARAM_RESEED_REQUESTS,
&reseed_interval);
}
all = ((flags & RAND_DRBG_TYPE_FLAGS) == 0);
- if (all || (flags & RAND_DRBG_FLAG_MASTER) != 0) {
- rand_drbg_type[RAND_DRBG_TYPE_MASTER] = type;
- rand_drbg_flags[RAND_DRBG_TYPE_MASTER] = flags | RAND_DRBG_FLAG_MASTER;
+ if (all || (flags & RAND_DRBG_FLAG_PRIMARY) != 0) {
+ rand_drbg_type[RAND_DRBG_TYPE_PRIMARY] = type;
+ rand_drbg_flags[RAND_DRBG_TYPE_PRIMARY] = flags
+ | RAND_DRBG_FLAG_PRIMARY;
}
if (all || (flags & RAND_DRBG_FLAG_PUBLIC) != 0) {
rand_drbg_type[RAND_DRBG_TYPE_PUBLIC] = type;
}
if (all || (flags & RAND_DRBG_FLAG_PRIVATE) != 0) {
rand_drbg_type[RAND_DRBG_TYPE_PRIVATE] = type;
- rand_drbg_flags[RAND_DRBG_TYPE_PRIVATE] = flags | RAND_DRBG_FLAG_PRIVATE;
+ rand_drbg_flags[RAND_DRBG_TYPE_PRIVATE] = flags
+ | RAND_DRBG_FLAG_PRIVATE;
}
return 1;
}
return 0;
/* The reset uses the default values for type and flags */
- if (drbg->flags & RAND_DRBG_FLAG_MASTER)
- index = RAND_DRBG_TYPE_MASTER;
+ if (drbg->flags & RAND_DRBG_FLAG_PRIMARY)
+ index = RAND_DRBG_TYPE_PRIMARY;
else if (drbg->flags & RAND_DRBG_FLAG_PRIVATE)
index = RAND_DRBG_TYPE_PRIVATE;
else if (drbg->flags & RAND_DRBG_FLAG_PUBLIC)
/*
* Set the default values for reseed (time) intervals of new DRBG instances
*
- * The default values can be set independently for master DRBG instances
- * (without a parent) and slave DRBG instances (with parent).
+ * The default values can be set independently for primary DRBG instances
+ * (without a parent) and secondary DRBG instances (with parent).
*
* Returns 1 on success, 0 on failure.
*/
int RAND_DRBG_set_reseed_defaults(
- unsigned int _master_reseed_interval,
- unsigned int _slave_reseed_interval,
- time_t _master_reseed_time_interval,
- time_t _slave_reseed_time_interval
+ unsigned int _primary_reseed_interval,
+ unsigned int _secondary_reseed_interval,
+ time_t _primary_reseed_time_interval,
+ time_t _secondary_reseed_time_interval
)
{
- if (_master_reseed_interval > MAX_RESEED_INTERVAL
- || _slave_reseed_interval > MAX_RESEED_INTERVAL)
+ if (_primary_reseed_interval > MAX_RESEED_INTERVAL
+ || _secondary_reseed_interval > MAX_RESEED_INTERVAL)
return 0;
- if (_master_reseed_time_interval > MAX_RESEED_TIME_INTERVAL
- || _slave_reseed_time_interval > MAX_RESEED_TIME_INTERVAL)
+ if (_primary_reseed_time_interval > MAX_RESEED_TIME_INTERVAL
+ || _secondary_reseed_time_interval > MAX_RESEED_TIME_INTERVAL)
return 0;
- master_reseed_interval = _master_reseed_interval;
- slave_reseed_interval = _slave_reseed_interval;
+ primary_reseed_interval = _primary_reseed_interval;
+ secondary_reseed_interval = _secondary_reseed_interval;
- master_reseed_time_interval = _master_reseed_time_interval;
- slave_reseed_time_interval = _slave_reseed_time_interval;
+ primary_reseed_time_interval = _primary_reseed_time_interval;
+ secondary_reseed_time_interval = _secondary_reseed_time_interval;
return 1;
}
if (drbg == NULL)
return NULL;
- /* Only the master DRBG needs to have a lock */
+ /* Only the primary DRBG needs to have a lock */
if (parent == NULL && EVP_RAND_enable_locking(drbg->rand) == 0)
goto err;
}
/*
- * Get the master DRBG.
+ * Get the primary DRBG.
* Returns pointer to the DRBG on success, NULL on failure.
*
*/
-RAND_DRBG *OPENSSL_CTX_get0_master_drbg(OPENSSL_CTX *ctx)
+RAND_DRBG *OPENSSL_CTX_get0_primary_drbg(OPENSSL_CTX *ctx)
{
DRBG_GLOBAL *dgbl = drbg_get_global(ctx);
if (dgbl == NULL)
return NULL;
- if (dgbl->master_drbg == NULL) {
+ if (dgbl->primary_drbg == NULL) {
if (!CRYPTO_THREAD_write_lock(dgbl->lock))
return NULL;
- if (dgbl->master_drbg == NULL)
- dgbl->master_drbg = drbg_setup(ctx, NULL, RAND_DRBG_TYPE_MASTER);
+ if (dgbl->primary_drbg == NULL)
+ dgbl->primary_drbg = drbg_setup(ctx, NULL, RAND_DRBG_TYPE_PRIMARY);
CRYPTO_THREAD_unlock(dgbl->lock);
}
- return dgbl->master_drbg;
+ return dgbl->primary_drbg;
}
RAND_DRBG *RAND_DRBG_get0_master(void)
{
- return OPENSSL_CTX_get0_master_drbg(NULL);
+ return OPENSSL_CTX_get0_primary_drbg(NULL);
}
/*
RAND_DRBG *OPENSSL_CTX_get0_public_drbg(OPENSSL_CTX *ctx)
{
DRBG_GLOBAL *dgbl = drbg_get_global(ctx);
- RAND_DRBG *drbg, *master;
+ RAND_DRBG *drbg, *primary;
if (dgbl == NULL)
return NULL;
drbg = CRYPTO_THREAD_get_local(&dgbl->public_drbg);
if (drbg == NULL) {
- master = OPENSSL_CTX_get0_master_drbg(ctx);
- if (master == NULL)
+ primary = OPENSSL_CTX_get0_primary_drbg(ctx);
+ if (primary == NULL)
return NULL;
ctx = openssl_ctx_get_concrete(ctx);
if (CRYPTO_THREAD_get_local(&dgbl->private_drbg) == NULL
&& !ossl_init_thread_start(NULL, ctx, drbg_delete_thread_state))
return NULL;
- drbg = drbg_setup(ctx, master, RAND_DRBG_TYPE_PUBLIC);
+ drbg = drbg_setup(ctx, primary, RAND_DRBG_TYPE_PUBLIC);
CRYPTO_THREAD_set_local(&dgbl->public_drbg, drbg);
}
return drbg;
RAND_DRBG *OPENSSL_CTX_get0_private_drbg(OPENSSL_CTX *ctx)
{
DRBG_GLOBAL *dgbl = drbg_get_global(ctx);
- RAND_DRBG *drbg, *master;
+ RAND_DRBG *drbg, *primary;
if (dgbl == NULL)
return NULL;
drbg = CRYPTO_THREAD_get_local(&dgbl->private_drbg);
if (drbg == NULL) {
- master = OPENSSL_CTX_get0_master_drbg(ctx);
- if (master == NULL)
+ primary = OPENSSL_CTX_get0_primary_drbg(ctx);
+ if (primary == NULL)
return NULL;
ctx = openssl_ctx_get_concrete(ctx);
if (CRYPTO_THREAD_get_local(&dgbl->public_drbg) == NULL
&& !ossl_init_thread_start(NULL, ctx, drbg_delete_thread_state))
return NULL;
- drbg = drbg_setup(ctx, master, RAND_DRBG_TYPE_PRIVATE);
+ drbg = drbg_setup(ctx, primary, RAND_DRBG_TYPE_PRIVATE);
CRYPTO_THREAD_set_local(&dgbl->private_drbg, drbg);
}
return drbg;
* expected.
*
* |expect_success|: expected outcome (as reported by RAND_status())
- * |master|, |public|, |private|: pointers to the three shared DRBGs
+ * |primary|, |public|, |private|: pointers to the three shared DRBGs
* |expect_xxx_reseed| =
* 1: it is expected that the specified DRBG is reseeded
* 0: it is expected that the specified DRBG is not reseeded
* |before_reseed| time.
*/
static int test_drbg_reseed(int expect_success,
- RAND_DRBG *master,
+ RAND_DRBG *primary,
RAND_DRBG *public,
RAND_DRBG *private,
- int expect_master_reseed,
+ int expect_primary_reseed,
int expect_public_reseed,
int expect_private_reseed,
time_t reseed_when
unsigned char buf[32];
time_t before_reseed, after_reseed;
int expected_state = (expect_success ? DRBG_READY : DRBG_ERROR);
- unsigned int master_reseed, public_reseed, private_reseed;
+ unsigned int primary_reseed, public_reseed, private_reseed;
/*
* step 1: check preconditions
*/
/* Test whether seed propagation is enabled */
- if (!TEST_int_ne(master_reseed = reseed_counter(master), 0)
+ if (!TEST_int_ne(primary_reseed = reseed_counter(primary), 0)
|| !TEST_int_ne(public_reseed = reseed_counter(public), 0)
|| !TEST_int_ne(private_reseed = reseed_counter(private), 0))
return 0;
reseed_when = time(NULL);
/* Generate random output from the public and private DRBG */
- before_reseed = expect_master_reseed == 1 ? reseed_when : 0;
+ before_reseed = expect_primary_reseed == 1 ? reseed_when : 0;
if (!TEST_int_eq(RAND_bytes(buf, sizeof(buf)), expect_success)
|| !TEST_int_eq(RAND_priv_bytes(buf, sizeof(buf)), expect_success))
return 0;
*/
/* Test whether reseeding succeeded as expected */
- if (/*!TEST_int_eq(state(master), expected_state)
+ if (/*!TEST_int_eq(state(primary), expected_state)
|| */!TEST_int_eq(state(public), expected_state)
|| !TEST_int_eq(state(private), expected_state))
return 0;
- if (expect_master_reseed >= 0) {
- /* Test whether master DRBG was reseeded as expected */
- if (!TEST_int_ge(reseed_counter(master), master_reseed))
+ if (expect_primary_reseed >= 0) {
+ /* Test whether primary DRBG was reseeded as expected */
+ if (!TEST_int_ge(reseed_counter(primary), primary_reseed))
return 0;
}
/* Test whether public DRBG was reseeded as expected */
if (!TEST_int_ge(reseed_counter(public), public_reseed)
|| !TEST_uint_ge(reseed_counter(public),
- reseed_counter(master)))
+ reseed_counter(primary)))
return 0;
}
/* Test whether public DRBG was reseeded as expected */
if (!TEST_int_ge(reseed_counter(private), private_reseed)
|| !TEST_uint_ge(reseed_counter(private),
- reseed_counter(master)))
+ reseed_counter(primary)))
return 0;
}
if (expect_success == 1) {
- /* Test whether reseed time of master DRBG is set correctly */
- if (!TEST_time_t_le(before_reseed, reseed_time(master))
- || !TEST_time_t_le(reseed_time(master), after_reseed))
+ /* Test whether reseed time of primary DRBG is set correctly */
+ if (!TEST_time_t_le(before_reseed, reseed_time(primary))
+ || !TEST_time_t_le(reseed_time(primary), after_reseed))
return 0;
- /* Test whether reseed times of child DRBGs are synchronized with master */
- if (!TEST_time_t_ge(reseed_time(public), reseed_time(master))
- || !TEST_time_t_ge(reseed_time(private), reseed_time(master)))
+ /* Test whether reseed times of child DRBGs are synchronized with primary */
+ if (!TEST_time_t_ge(reseed_time(public), reseed_time(primary))
+ || !TEST_time_t_ge(reseed_time(private), reseed_time(primary)))
return 0;
} else {
ERR_clear_error();
#if defined(OPENSSL_SYS_UNIX)
/*
- * Test whether master, public and private DRBG are reseeded after
+ * Test whether primary, public and private DRBG are reseeded after
* forking the process.
*/
-static int test_drbg_reseed_after_fork(RAND_DRBG *master,
+static int test_drbg_reseed_after_fork(RAND_DRBG *primary,
RAND_DRBG *public,
RAND_DRBG *private)
{
}
/* I'm the child; check whether all three DRBGs reseed. */
- if (!TEST_true(test_drbg_reseed(1, master, public, private, 1, 1, 1, 0)))
+ if (!TEST_true(test_drbg_reseed(1, primary, public, private, 1, 1, 1, 0)))
status = 1;
exit(status);
}
*/
static int test_rand_drbg_reseed(void)
{
- RAND_DRBG *master, *public, *private;
+ RAND_DRBG *primary, *public, *private;
unsigned char rand_add_buf[256];
int rv = 0;
time_t before_reseed;
return 0;
/* All three DRBGs should be non-null */
- if (!TEST_ptr(master = RAND_DRBG_get0_master())
+ if (!TEST_ptr(primary = RAND_DRBG_get0_master())
|| !TEST_ptr(public = RAND_DRBG_get0_public())
|| !TEST_ptr(private = RAND_DRBG_get0_private()))
return 0;
- /* There should be three distinct DRBGs, two of them chained to master */
+ /* There should be three distinct DRBGs, two of them chained to primary */
if (!TEST_ptr_ne(public, private)
- || !TEST_ptr_ne(public, master)
- || !TEST_ptr_ne(private, master)
- || !TEST_ptr_eq(public->parent, master)
- || !TEST_ptr_eq(private->parent, master))
+ || !TEST_ptr_ne(public, primary)
+ || !TEST_ptr_ne(private, primary)
+ || !TEST_ptr_eq(public->parent, primary)
+ || !TEST_ptr_eq(private->parent, primary))
return 0;
- /* Disable CRNG testing for the master DRBG */
- if (!TEST_true(disable_crngt(master)))
+ /* Disable CRNG testing for the primary DRBG */
+ if (!TEST_true(disable_crngt(primary)))
return 0;
/* uninstantiate the three global DRBGs */
- RAND_DRBG_uninstantiate(master);
+ RAND_DRBG_uninstantiate(primary);
RAND_DRBG_uninstantiate(private);
RAND_DRBG_uninstantiate(public);
/*
* Test initial seeding of shared DRBGs
*/
- if (!TEST_true(test_drbg_reseed(1, master, public, private, 1, 1, 1, 0)))
+ if (!TEST_true(test_drbg_reseed(1, primary, public, private, 1, 1, 1, 0)))
goto error;
/*
* Test initial state of shared DRBGs
*/
- if (!TEST_true(test_drbg_reseed(1, master, public, private, 0, 0, 0, 0)))
+ if (!TEST_true(test_drbg_reseed(1, primary, public, private, 0, 0, 0, 0)))
goto error;
/*
* Test whether the public and private DRBG are both reseeded when their
- * reseed counters differ from the master's reseed counter.
+ * reseed counters differ from the primary's reseed counter.
*/
- inc_reseed_counter(master);
- if (!TEST_true(test_drbg_reseed(1, master, public, private, 0, 1, 1, 0)))
+ inc_reseed_counter(primary);
+ if (!TEST_true(test_drbg_reseed(1, primary, public, private, 0, 1, 1, 0)))
goto error;
/*
* Test whether the public DRBG is reseeded when its reseed counter differs
- * from the master's reseed counter.
+ * from the primary's reseed counter.
*/
- inc_reseed_counter(master);
+ inc_reseed_counter(primary);
inc_reseed_counter(private);
- if (!TEST_true(test_drbg_reseed(1, master, public, private, 0, 1, 0, 0)))
+ if (!TEST_true(test_drbg_reseed(1, primary, public, private, 0, 1, 0, 0)))
goto error;
/*
* Test whether the private DRBG is reseeded when its reseed counter differs
- * from the master's reseed counter.
+ * from the primary's reseed counter.
*/
- inc_reseed_counter(master);
+ inc_reseed_counter(primary);
inc_reseed_counter(public);
- if (!TEST_true(test_drbg_reseed(1, master, public, private, 0, 0, 1, 0)))
+ if (!TEST_true(test_drbg_reseed(1, primary, public, private, 0, 0, 1, 0)))
goto error;
#if defined(OPENSSL_SYS_UNIX)
- if (!TEST_true(test_drbg_reseed_after_fork(master, public, private)))
+ if (!TEST_true(test_drbg_reseed_after_fork(primary, public, private)))
goto error;
#endif
/*
* Test whether all three DRBGs are reseeded by RAND_add().
* The before_reseed time has to be measured here and passed into the
- * test_drbg_reseed() test, because the master DRBG gets already reseeded
+ * test_drbg_reseed() test, because the primary DRBG gets already reseeded
* in RAND_add(), whence the check for the condition
- * before_reseed <= reseed_time(master) will fail if the time value happens
+ * before_reseed <= reseed_time(primary) will fail if the time value happens
* to increase between the RAND_add() and the test_drbg_reseed() call.
*/
before_reseed = time(NULL);
RAND_add(rand_add_buf, sizeof(rand_add_buf), sizeof(rand_add_buf));
- if (!TEST_true(test_drbg_reseed(1, master, public, private, 1, 1, 1,
+ if (!TEST_true(test_drbg_reseed(1, primary, public, private, 1, 1, 1,
before_reseed)))
goto error;
#else /* FIPS_MODULE */
*/
before_reseed = time(NULL);
RAND_add(rand_add_buf, sizeof(rand_add_buf), sizeof(rand_add_buf));
- if (!TEST_true(test_drbg_reseed(1, master, public, private, 0, 0, 0,
+ if (!TEST_true(test_drbg_reseed(1, primary, public, private, 0, 0, 0,
before_reseed)))
goto error;
#endif
static int test_rand_drbg_prediction_resistance(void)
{
- RAND_DRBG *m = NULL, *i = NULL, *s = NULL;
+ RAND_DRBG *x = NULL, *y = NULL, *z = NULL;
unsigned char buf1[51], buf2[sizeof(buf1)];
- int ret = 0, mreseed, ireseed, sreseed;
+ int ret = 0, xreseed, yreseed, zreseed;
if (crngt_skip())
return TEST_skip("CRNGT cannot be disabled");
/* Initialise a three long DRBG chain */
- if (!TEST_ptr(m = RAND_DRBG_new(0, 0, NULL))
- || !TEST_true(disable_crngt(m))
- || !TEST_true(RAND_DRBG_instantiate(m, NULL, 0))
- || !TEST_ptr(i = RAND_DRBG_new(0, 0, m))
- || !TEST_true(RAND_DRBG_instantiate(i, NULL, 0))
- || !TEST_ptr(s = RAND_DRBG_new(0, 0, i))
- || !TEST_true(RAND_DRBG_instantiate(s, NULL, 0)))
+ if (!TEST_ptr(x = RAND_DRBG_new(0, 0, NULL))
+ || !TEST_true(disable_crngt(x))
+ || !TEST_true(RAND_DRBG_instantiate(x, NULL, 0))
+ || !TEST_ptr(y = RAND_DRBG_new(0, 0, x))
+ || !TEST_true(RAND_DRBG_instantiate(y, NULL, 0))
+ || !TEST_ptr(z = RAND_DRBG_new(0, 0, y))
+ || !TEST_true(RAND_DRBG_instantiate(z, NULL, 0)))
goto err;
- /* During a normal reseed, only the slave DRBG should be reseed */
- inc_reseed_counter(i);
- mreseed = reseed_counter(m);
- ireseed = reseed_counter(i);
- sreseed = reseed_counter(s);
- if (!TEST_true(RAND_DRBG_reseed(s, NULL, 0, 0))
- || !TEST_int_eq(reseed_counter(m), mreseed)
- || !TEST_int_eq(reseed_counter(i), ireseed)
- || !TEST_int_gt(reseed_counter(s), sreseed))
+ /*
+ * During a normal reseed, only the last DRBG in the chain should
+ * be reseeded.
+ */
+ inc_reseed_counter(y);
+ xreseed = reseed_counter(x);
+ yreseed = reseed_counter(y);
+ zreseed = reseed_counter(z);
+ if (!TEST_true(RAND_DRBG_reseed(z, NULL, 0, 0))
+ || !TEST_int_eq(reseed_counter(x), xreseed)
+ || !TEST_int_eq(reseed_counter(y), yreseed)
+ || !TEST_int_gt(reseed_counter(z), zreseed))
goto err;
/*
* When prediction resistance is requested, the request should be
- * propagated to the master, so that the entire DRBG chain reseeds.
+ * propagated to the primary, so that the entire DRBG chain reseeds.
*/
- sreseed = reseed_counter(s);
- if (!TEST_true(RAND_DRBG_reseed(s, NULL, 0, 1))
- || !TEST_int_gt(reseed_counter(m), mreseed)
- || !TEST_int_gt(reseed_counter(i), ireseed)
- || !TEST_int_gt(reseed_counter(s), sreseed))
+ zreseed = reseed_counter(z);
+ if (!TEST_true(RAND_DRBG_reseed(z, NULL, 0, 1))
+ || !TEST_int_gt(reseed_counter(x), xreseed)
+ || !TEST_int_gt(reseed_counter(y), yreseed)
+ || !TEST_int_gt(reseed_counter(z), zreseed))
goto err;
- /* During a normal generate, only the slave DRBG should be reseed */
- inc_reseed_counter(i);
- mreseed = reseed_counter(m);
- ireseed = reseed_counter(i);
- sreseed = reseed_counter(s);
- if (!TEST_true(RAND_DRBG_generate(s, buf1, sizeof(buf1), 0, NULL, 0))
- || !TEST_int_eq(reseed_counter(m), mreseed)
- || !TEST_int_eq(reseed_counter(i), ireseed)
- || !TEST_int_gt(reseed_counter(s), sreseed))
+ /*
+ * During a normal generate, only the last DRBG should be reseed */
+ inc_reseed_counter(y);
+ xreseed = reseed_counter(x);
+ yreseed = reseed_counter(y);
+ zreseed = reseed_counter(z);
+ if (!TEST_true(RAND_DRBG_generate(z, buf1, sizeof(buf1), 0, NULL, 0))
+ || !TEST_int_eq(reseed_counter(x), xreseed)
+ || !TEST_int_eq(reseed_counter(y), yreseed)
+ || !TEST_int_gt(reseed_counter(z), zreseed))
goto err;
/*
* When a prediction resistant generate is requested, the request
- * should be propagated to the master, reseeding the entire DRBG chain.
+ * should be propagated to the primary, reseeding the entire DRBG chain.
*/
- sreseed = reseed_counter(s);
- if (!TEST_true(RAND_DRBG_generate(s, buf2, sizeof(buf2), 1, NULL, 0))
- || !TEST_int_gt(reseed_counter(m), mreseed)
- || !TEST_int_gt(reseed_counter(i), ireseed)
- || !TEST_int_gt(reseed_counter(s), sreseed)
+ zreseed = reseed_counter(z);
+ if (!TEST_true(RAND_DRBG_generate(z, buf2, sizeof(buf2), 1, NULL, 0))
+ || !TEST_int_gt(reseed_counter(x), xreseed)
+ || !TEST_int_gt(reseed_counter(y), yreseed)
+ || !TEST_int_gt(reseed_counter(z), zreseed)
|| !TEST_mem_ne(buf1, sizeof(buf1), buf2, sizeof(buf2)))
goto err;
- /* Verify that a normal reseed still only reseeds the slave DRBG */
- inc_reseed_counter(i);
- mreseed = reseed_counter(m);
- ireseed = reseed_counter(i);
- sreseed = reseed_counter(s);
- if (!TEST_true(RAND_DRBG_reseed(s, NULL, 0, 0))
- || !TEST_int_eq(reseed_counter(m), mreseed)
- || !TEST_int_eq(reseed_counter(i), ireseed)
- || !TEST_int_gt(reseed_counter(s), sreseed))
+ /* Verify that a normal reseed still only reseeds the last DRBG */
+ inc_reseed_counter(y);
+ xreseed = reseed_counter(x);
+ yreseed = reseed_counter(y);
+ zreseed = reseed_counter(z);
+ if (!TEST_true(RAND_DRBG_reseed(z, NULL, 0, 0))
+ || !TEST_int_eq(reseed_counter(x), xreseed)
+ || !TEST_int_eq(reseed_counter(y), yreseed)
+ || !TEST_int_gt(reseed_counter(z), zreseed))
goto err;
ret = 1;
err:
- RAND_DRBG_free(s);
- RAND_DRBG_free(i);
- RAND_DRBG_free(m);
+ RAND_DRBG_free(z);
+ RAND_DRBG_free(y);
+ RAND_DRBG_free(x);
return ret;
}
static int test_set_defaults(void)
{
- RAND_DRBG *master = NULL, *public = NULL, *private = NULL;
+ RAND_DRBG *primary = NULL, *public = NULL, *private = NULL;
- /* Check the default type and flags for master, public and private */
- return TEST_ptr(master = RAND_DRBG_get0_master())
+ /* Check the default type and flags for primary, public and private */
+ return TEST_ptr(primary = RAND_DRBG_get0_master())
&& TEST_ptr(public = RAND_DRBG_get0_public())
&& TEST_ptr(private = RAND_DRBG_get0_private())
- && TEST_int_eq(master->type, RAND_DRBG_TYPE)
- && TEST_int_eq(master->flags,
- RAND_DRBG_FLAGS | RAND_DRBG_FLAG_MASTER)
+ && TEST_int_eq(primary->type, RAND_DRBG_TYPE)
+ && TEST_int_eq(primary->flags,
+ RAND_DRBG_FLAGS | RAND_DRBG_FLAG_PRIMARY)
&& TEST_int_eq(public->type, RAND_DRBG_TYPE)
&& TEST_int_eq(public->flags,
RAND_DRBG_FLAGS | RAND_DRBG_FLAG_PUBLIC)
&& TEST_int_eq(private->flags,
RAND_DRBG_FLAGS | RAND_DRBG_FLAG_PRIVATE)
- /* change master DRBG and check again */
+ /* change primary DRBG and check again */
&& TEST_true(RAND_DRBG_set_defaults(NID_sha256,
- RAND_DRBG_FLAG_MASTER))
- && TEST_true(RAND_DRBG_uninstantiate(master))
- && TEST_int_eq(master->type, NID_sha256)
- && TEST_int_eq(master->flags, RAND_DRBG_FLAG_MASTER)
+ RAND_DRBG_FLAG_PRIMARY))
+ && TEST_true(RAND_DRBG_uninstantiate(primary))
+ && TEST_int_eq(primary->type, NID_sha256)
+ && TEST_int_eq(primary->flags, RAND_DRBG_FLAG_PRIMARY)
&& TEST_int_eq(public->type, RAND_DRBG_TYPE)
&& TEST_int_eq(public->flags,
RAND_DRBG_FLAGS | RAND_DRBG_FLAG_PUBLIC)
&& TEST_true(RAND_DRBG_set_defaults(NID_sha256,
RAND_DRBG_FLAG_PRIVATE|RAND_DRBG_FLAG_HMAC))
&& TEST_true(RAND_DRBG_uninstantiate(private))
- && TEST_int_eq(master->type, NID_sha256)
- && TEST_int_eq(master->flags, RAND_DRBG_FLAG_MASTER)
+ && TEST_int_eq(primary->type, NID_sha256)
+ && TEST_int_eq(primary->flags, RAND_DRBG_FLAG_PRIMARY)
&& TEST_int_eq(public->type, RAND_DRBG_TYPE)
&& TEST_int_eq(public->flags,
RAND_DRBG_FLAGS | RAND_DRBG_FLAG_PUBLIC)
RAND_DRBG_FLAG_PUBLIC
| RAND_DRBG_FLAG_HMAC))
&& TEST_true(RAND_DRBG_uninstantiate(public))
- && TEST_int_eq(master->type, NID_sha256)
- && TEST_int_eq(master->flags, RAND_DRBG_FLAG_MASTER)
+ && TEST_int_eq(primary->type, NID_sha256)
+ && TEST_int_eq(primary->flags, RAND_DRBG_FLAG_PRIMARY)
&& TEST_int_eq(public->type, NID_sha1)
&& TEST_int_eq(public->flags,
RAND_DRBG_FLAG_PUBLIC | RAND_DRBG_FLAG_HMAC)
/* FIPS mode doesn't support CTR DRBG without a derivation function */
#ifndef FIPS_MODULE
- /* Change DRBG defaults and change master and check again */
+ /* Change DRBG defaults and change primary and check again */
&& TEST_true(RAND_DRBG_set_defaults(NID_aes_256_ctr,
RAND_DRBG_FLAG_CTR_NO_DF))
- && TEST_true(RAND_DRBG_uninstantiate(master))
- && TEST_int_eq(master->type, NID_aes_256_ctr)
- && TEST_int_eq(master->flags,
- RAND_DRBG_FLAG_MASTER|RAND_DRBG_FLAG_CTR_NO_DF)
+ && TEST_true(RAND_DRBG_uninstantiate(primary))
+ && TEST_int_eq(primary->type, NID_aes_256_ctr)
+ && TEST_int_eq(primary->flags,
+ RAND_DRBG_FLAG_PRIMARY|RAND_DRBG_FLAG_CTR_NO_DF)
#endif
/* Reset back to the standard defaults */
&& TEST_true(RAND_DRBG_set_defaults(RAND_DRBG_TYPE,
RAND_DRBG_FLAGS
- | RAND_DRBG_FLAG_MASTER
+ | RAND_DRBG_FLAG_PRIMARY
| RAND_DRBG_FLAG_PUBLIC
| RAND_DRBG_FLAG_PRIVATE))
- && TEST_true(RAND_DRBG_uninstantiate(master))
+ && TEST_true(RAND_DRBG_uninstantiate(primary))
&& TEST_true(RAND_DRBG_uninstantiate(public))
&& TEST_true(RAND_DRBG_uninstantiate(private));
}