diff --git a/ctaocrypt/src/ecc.c b/ctaocrypt/src/ecc.c index e572d5832..3fec64215 100644 --- a/ctaocrypt/src/ecc.c +++ b/ctaocrypt/src/ecc.c @@ -3658,17 +3658,27 @@ static void ecc_ctx_init(ecEncCtx* ctx, int flags) } +/* allow ecc context reset so user doesn't have to init/free for resue */ +int ecc_ctx_reset(ecEncCtx* ctx, RNG* rng) +{ + if (ctx == NULL || rng == NULL) + return BAD_FUNC_ARG; + + ecc_ctx_init(ctx, ctx->protocol); + return ecc_ctx_set_salt(ctx, ctx->protocol, rng); +} + + /* alloc/init and set defaults, return new Context */ ecEncCtx* ecc_ctx_new(int flags, RNG* rng) { int ret = 0; ecEncCtx* ctx = (ecEncCtx*)XMALLOC(sizeof(ecEncCtx), 0, DYNAMIC_TYPE_ECC); - ecc_ctx_init(ctx, flags); - - if (ctx && flags) - ret = ecc_ctx_set_salt(ctx, flags, rng); + if (ctx) + ctx->protocol = (byte)flags; + ret = ecc_ctx_reset(ctx, rng); if (ret != 0) { ecc_ctx_free(ctx); ctx = NULL; diff --git a/cyassl/ctaocrypt/ecc.h b/cyassl/ctaocrypt/ecc.h index 2434a6844..5cd5b2cf3 100644 --- a/cyassl/ctaocrypt/ecc.h +++ b/cyassl/ctaocrypt/ecc.h @@ -157,6 +157,8 @@ CYASSL_API ecEncCtx* ecc_ctx_new(int flags, RNG* rng); CYASSL_API void ecc_ctx_free(ecEncCtx*); +CYASSL_API +int ecc_ctx_reset(ecEncCtx*, RNG*); /* reset for use again w/o alloc/free */ CYASSL_API const byte* ecc_ctx_get_own_salt(ecEncCtx*);