-/* $OpenBSD: ecp_mont.c,v 1.23 2023/03/04 14:38:00 jsing Exp $ */
+/* $OpenBSD: ecp_mont.c,v 1.24 2023/03/07 05:28:12 jsing Exp $ */
/*
* Originally written by Bodo Moeller for the OpenSSL project.
*/
#include "ec_local.h"
+static void
+ec_GFp_mont_group_clear(EC_GROUP *group)
+{
+ BN_MONT_CTX_free(group->mont_ctx);
+ group->mont_ctx = NULL;
+
+ BN_free(group->mont_one);
+ group->mont_one = NULL;
+}
const EC_METHOD *
EC_GFp_mont_method(void)
void
ec_GFp_mont_group_finish(EC_GROUP *group)
{
- BN_MONT_CTX_free(group->mont_ctx);
- group->mont_ctx = NULL;
- BN_free(group->mont_one);
- group->mont_one = NULL;
+ ec_GFp_mont_group_clear(group);
ec_GFp_simple_group_finish(group);
}
void
ec_GFp_mont_group_clear_finish(EC_GROUP *group)
{
- BN_MONT_CTX_free(group->mont_ctx);
- group->mont_ctx = NULL;
- BN_clear_free(group->mont_one);
- group->mont_one = NULL;
+ ec_GFp_mont_group_clear(group);
ec_GFp_simple_group_clear_finish(group);
}
int
ec_GFp_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src)
{
- BN_MONT_CTX_free(dest->mont_ctx);
- dest->mont_ctx = NULL;
- BN_clear_free(dest->mont_one);
- dest->mont_one = NULL;
+ ec_GFp_mont_group_clear(dest);
if (!ec_GFp_simple_group_copy(dest, src))
return 0;
BIGNUM *one = NULL;
int ret = 0;
- BN_MONT_CTX_free(group->mont_ctx);
- group->mont_ctx = NULL;
- BN_free(group->mont_one);
- group->mont_one = NULL;
+ ec_GFp_mont_group_clear(group);
+
if (ctx == NULL) {
ctx = new_ctx = BN_CTX_new();
if (ctx == NULL)
ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx);
- if (!ret) {
- BN_MONT_CTX_free(group->mont_ctx);
- group->mont_ctx = NULL;
- BN_free(group->mont_one);
- group->mont_one = NULL;
- }
+ if (!ret)
+ ec_GFp_mont_group_clear(group);
+
err:
BN_CTX_free(new_ctx);
BN_MONT_CTX_free(mont);