/* * Set/initialize |drbg| to be of type |type|, with optional |flags|. * * If |type| and |flags| are zero, use the defaults * * Returns 1 on success, 0 on failure. */ int RAND_DRBG_set(RAND_DRBG *drbg, int type, unsigned int flags) { int ret = 1; if (type == 0 && flags == 0) { type = rand_drbg_type; flags = rand_drbg_flags; } drbg->state = DRBG_UNINITIALISED; drbg->flags = flags; drbg->type = type; switch (type) { default: RANDerr(RAND_F_RAND_DRBG_SET, RAND_R_UNSUPPORTED_DRBG_TYPE); return 0; case 0: /* Uninitialized; that's okay. */ return 1; case NID_aes_128_ctr: case NID_aes_192_ctr: case NID_aes_256_ctr: ret = drbg_ctr_init(drbg); break; } if (ret == 0) RANDerr(RAND_F_RAND_DRBG_SET, RAND_R_ERROR_INITIALISING_DRBG); return ret; }
/* * Set/initialize |drbg| to be of type |type|, with optional |flags|. * * If |type| and |flags| are zero, use the defaults * * Returns 1 on success, 0 on failure. */ int RAND_DRBG_set(RAND_DRBG *drbg, int type, unsigned int flags) { int ret = 1; if (type == 0 && flags == 0) { type = rand_drbg_type[RAND_DRBG_TYPE_MASTER]; flags = rand_drbg_flags[RAND_DRBG_TYPE_MASTER]; } /* If set is called multiple times - clear the old one */ if (drbg->type != 0 && (type != drbg->type || flags != drbg->flags)) { drbg->meth->uninstantiate(drbg); rand_pool_free(drbg->adin_pool); drbg->adin_pool = NULL; } drbg->state = DRBG_UNINITIALISED; drbg->flags = flags; drbg->type = type; if (type == 0) { /* Uninitialized; that's okay. */ drbg->meth = NULL; return 1; } else if (is_ctr(type)) { ret = drbg_ctr_init(drbg); } else if (is_digest(type)) { if (flags & RAND_DRBG_FLAG_HMAC) ret = drbg_hmac_init(drbg); else ret = drbg_hash_init(drbg); } else { drbg->type = 0; drbg->flags = 0; drbg->meth = NULL; RANDerr(RAND_F_RAND_DRBG_SET, RAND_R_UNSUPPORTED_DRBG_TYPE); return 0; } if (ret == 0) { drbg->state = DRBG_ERROR; RANDerr(RAND_F_RAND_DRBG_SET, RAND_R_ERROR_INITIALISING_DRBG); } return ret; }