summaryrefslogtreecommitdiffstats
path: root/crypto/evp/evp_rand.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/evp/evp_rand.c')
-rw-r--r--crypto/evp/evp_rand.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/crypto/evp/evp_rand.c b/crypto/evp/evp_rand.c
index 3031ecbcc0..f7fc6c3344 100644
--- a/crypto/evp/evp_rand.c
+++ b/crypto/evp/evp_rand.c
@@ -47,6 +47,8 @@ struct evp_rand_st {
OSSL_FUNC_rand_get_ctx_params_fn *get_ctx_params;
OSSL_FUNC_rand_set_ctx_params_fn *set_ctx_params;
OSSL_FUNC_rand_verify_zeroization_fn *verify_zeroization;
+ OSSL_FUNC_rand_get_seed_fn *get_seed;
+ OSSL_FUNC_rand_clear_seed_fn *clear_seed;
} /* EVP_RAND */ ;
static int evp_rand_up_ref(void *vrand)
@@ -236,6 +238,16 @@ static void *evp_rand_from_algorithm(int name_id,
fnzeroizecnt++;
#endif
break;
+ case OSSL_FUNC_RAND_GET_SEED:
+ if (rand->get_seed != NULL)
+ break;
+ rand->get_seed = OSSL_FUNC_rand_get_seed(fns);
+ break;
+ case OSSL_FUNC_RAND_CLEAR_SEED:
+ if (rand->clear_seed != NULL)
+ break;
+ rand->clear_seed = OSSL_FUNC_rand_clear_seed(fns);
+ break;
}
}
/*
@@ -680,3 +692,59 @@ int EVP_RAND_verify_zeroization(EVP_RAND_CTX *ctx)
evp_rand_unlock(ctx);
return res;
}
+
+int evp_rand_can_seed(EVP_RAND_CTX *ctx)
+{
+ return ctx->meth->get_seed != NULL;
+}
+
+static size_t evp_rand_get_seed_locked(EVP_RAND_CTX *ctx,
+ unsigned char **buffer,
+ int entropy,
+ size_t min_len, size_t max_len,
+ int prediction_resistance,
+ const unsigned char *adin,
+ size_t adin_len)
+{
+ if (ctx->meth->get_seed != NULL)
+ return ctx->meth->get_seed(ctx->algctx, buffer,
+ entropy, min_len, max_len,
+ prediction_resistance,
+ adin, adin_len);
+ return 0;
+}
+
+size_t evp_rand_get_seed(EVP_RAND_CTX *ctx,
+ unsigned char **buffer,
+ int entropy, size_t min_len, size_t max_len,
+ int prediction_resistance,
+ const unsigned char *adin, size_t adin_len)
+{
+ int res;
+
+ if (!evp_rand_lock(ctx))
+ return 0;
+ res = evp_rand_get_seed_locked(ctx,
+ buffer,
+ entropy, min_len, max_len,
+ prediction_resistance,
+ adin, adin_len);
+ evp_rand_unlock(ctx);
+ return res;
+}
+
+static void evp_rand_clear_seed_locked(EVP_RAND_CTX *ctx,
+ unsigned char *buffer, size_t b_len)
+{
+ if (ctx->meth->clear_seed != NULL)
+ ctx->meth->clear_seed(ctx->algctx, buffer, b_len);
+}
+
+void evp_rand_clear_seed(EVP_RAND_CTX *ctx,
+ unsigned char *buffer, size_t b_len)
+{
+ if (!evp_rand_lock(ctx))
+ return;
+ evp_rand_clear_seed_locked(ctx, buffer, b_len);
+ evp_rand_unlock(ctx);
+}