提交 be07ae9b 编写于 作者: A Andy Polyakov

crypto/ecp_nistz256.c: harmonize error codes.

Reviewed-by: NDr. Stephen Henson <steve@openssl.org>
上级 b5ff559f
...@@ -1182,11 +1182,11 @@ void ERR_load_EC_strings(void); ...@@ -1182,11 +1182,11 @@ void ERR_load_EC_strings(void);
#define EC_F_NISTP224_PRE_COMP_NEW 227 #define EC_F_NISTP224_PRE_COMP_NEW 227
#define EC_F_NISTP256_PRE_COMP_NEW 236 #define EC_F_NISTP256_PRE_COMP_NEW 236
#define EC_F_NISTP521_PRE_COMP_NEW 237 #define EC_F_NISTP521_PRE_COMP_NEW 237
#define EC_F_NISTZ256_GET_AFFINE_COORDINATES 240 #define EC_F_ECP_NISTZ256_GET_AFFINE 240
#define EC_F_NISTZ256_POINTS_MUL 241 #define EC_F_ECP_NISTZ256_POINTS_MUL 241
#define EC_F_NISTZ256_POINTS_MUL_W 242 #define EC_F_ECP_NISTZ256_WINDOWED_MUL 242
#define EC_F_NISTZ256_PRECOMPUTE_MULT 243 #define EC_F_ECP_NISTZ256_MULT_PRECOMPUTE 243
#define EC_F_NISTZ256_PRE_COMP_NEW 244 #define EC_F_ECP_NISTZ256_PRE_COMP_NEW 244
#define EC_F_O2I_ECPUBLICKEY 152 #define EC_F_O2I_ECPUBLICKEY 152
#define EC_F_OLD_EC_PRIV_DECODE 222 #define EC_F_OLD_EC_PRIV_DECODE 222
#define EC_F_PKEY_EC_CTRL 197 #define EC_F_PKEY_EC_CTRL 197
......
...@@ -200,11 +200,11 @@ static ERR_STRING_DATA EC_str_functs[]= ...@@ -200,11 +200,11 @@ static ERR_STRING_DATA EC_str_functs[]=
{ERR_FUNC(EC_F_NISTP224_PRE_COMP_NEW), "NISTP224_PRE_COMP_NEW"}, {ERR_FUNC(EC_F_NISTP224_PRE_COMP_NEW), "NISTP224_PRE_COMP_NEW"},
{ERR_FUNC(EC_F_NISTP256_PRE_COMP_NEW), "NISTP256_PRE_COMP_NEW"}, {ERR_FUNC(EC_F_NISTP256_PRE_COMP_NEW), "NISTP256_PRE_COMP_NEW"},
{ERR_FUNC(EC_F_NISTP521_PRE_COMP_NEW), "NISTP521_PRE_COMP_NEW"}, {ERR_FUNC(EC_F_NISTP521_PRE_COMP_NEW), "NISTP521_PRE_COMP_NEW"},
{ERR_FUNC(EC_F_NISTZ256_GET_AFFINE_COORDINATES), "NISTZ256_GET_AFFINE_COORDINATES"}, {ERR_FUNC(EC_F_ECP_NISTZ256_GET_AFFINE), "ecp_nistz256_get_affine"},
{ERR_FUNC(EC_F_NISTZ256_POINTS_MUL), "NISTZ256_POINTS_MUL"}, {ERR_FUNC(EC_F_ECP_NISTZ256_POINTS_MUL), "ecp_nistz256_points_mul"},
{ERR_FUNC(EC_F_NISTZ256_POINTS_MUL_W), "NISTZ256_POINTS_MUL_W"}, {ERR_FUNC(EC_F_ECP_NISTZ256_WINDOWED_MUL), "ecp_nistz256_windowed_mul"},
{ERR_FUNC(EC_F_NISTZ256_PRECOMPUTE_MULT), "NISTZ256_PRECOMPUTE_MULT"}, {ERR_FUNC(EC_F_ECP_NISTZ256_MULT_PRECOMPUTE), "ecp_nistz256_mult_precompute"},
{ERR_FUNC(EC_F_NISTZ256_PRE_COMP_NEW), "NISTZ256_PRE_COMP_NEW"}, {ERR_FUNC(EC_F_ECP_NISTZ256_PRE_COMP_NEW), "ecp_nistz256_pre_comp_new"},
{ERR_FUNC(EC_F_O2I_ECPUBLICKEY), "o2i_ECPublicKey"}, {ERR_FUNC(EC_F_O2I_ECPUBLICKEY), "o2i_ECPublicKey"},
{ERR_FUNC(EC_F_OLD_EC_PRIV_DECODE), "OLD_EC_PRIV_DECODE"}, {ERR_FUNC(EC_F_OLD_EC_PRIV_DECODE), "OLD_EC_PRIV_DECODE"},
{ERR_FUNC(EC_F_PKEY_EC_CTRL), "PKEY_EC_CTRL"}, {ERR_FUNC(EC_F_PKEY_EC_CTRL), "PKEY_EC_CTRL"},
......
...@@ -124,10 +124,10 @@ static const BN_ULONG ONE[P256_LIMBS] = { ...@@ -124,10 +124,10 @@ static const BN_ULONG ONE[P256_LIMBS] = {
TOBN(0xffffffff, 0xffffffff), TOBN(0x00000000, 0xfffffffe) TOBN(0xffffffff, 0xffffffff), TOBN(0x00000000, 0xfffffffe)
}; };
static void *ec_pre_comp_dup(void *); static void *ecp_nistz256_pre_comp_dup(void *);
static void ec_pre_comp_free(void *); static void ecp_nistz256_pre_comp_free(void *);
static void ec_pre_comp_clear_free(void *); static void ecp_nistz256_pre_comp_clear_free(void *);
static EC_PRE_COMP *ec_pre_comp_new(const EC_GROUP * group); static EC_PRE_COMP *ecp_nistz256_pre_comp_new(const EC_GROUP * group);
/* Precomputed tables for the default generator */ /* Precomputed tables for the default generator */
#include "ecp_nistz256_table.c" #include "ecp_nistz256_table.c"
...@@ -571,7 +571,7 @@ static void ecp_nistz256_windowed_mul(const EC_GROUP * group, ...@@ -571,7 +571,7 @@ static void ecp_nistz256_windowed_mul(const EC_GROUP * group,
|| (p_str = || (p_str =
OPENSSL_malloc(num * 33 * sizeof(unsigned char))) == NULL OPENSSL_malloc(num * 33 * sizeof(unsigned char))) == NULL
|| (scalars = OPENSSL_malloc(num * sizeof(BIGNUM *))) == NULL) { || (scalars = OPENSSL_malloc(num * sizeof(BIGNUM *))) == NULL) {
ECerr(EC_F_NISTZ256_POINTS_MUL_W, ERR_R_MALLOC_FAILURE); ECerr(EC_F_ECP_NISTZ256_WINDOWED_MUL, ERR_R_MALLOC_FAILURE);
goto err; goto err;
} else { } else {
table = (void *)ALIGNPTR(table_storage, 64); table = (void *)ALIGNPTR(table_storage, 64);
...@@ -586,7 +586,7 @@ static void ecp_nistz256_windowed_mul(const EC_GROUP * group, ...@@ -586,7 +586,7 @@ static void ecp_nistz256_windowed_mul(const EC_GROUP * group,
if ((mod = BN_CTX_get(ctx)) == NULL) if ((mod = BN_CTX_get(ctx)) == NULL)
goto err; goto err;
if (!BN_nnmod(mod, scalar[i], &group->order, ctx)) { if (!BN_nnmod(mod, scalar[i], &group->order, ctx)) {
ECerr(EC_F_NISTZ256_POINTS_MUL_W, ERR_R_BN_LIB); ECerr(EC_F_ECP_NISTZ256_WINDOWED_MUL, ERR_R_BN_LIB);
goto err; goto err;
} }
scalars[i] = mod; scalars[i] = mod;
...@@ -619,7 +619,7 @@ static void ecp_nistz256_windowed_mul(const EC_GROUP * group, ...@@ -619,7 +619,7 @@ static void ecp_nistz256_windowed_mul(const EC_GROUP * group,
if (!ecp_nistz256_bignum_to_field_elem(row[1 - 1].X, &point[i]->X) if (!ecp_nistz256_bignum_to_field_elem(row[1 - 1].X, &point[i]->X)
|| !ecp_nistz256_bignum_to_field_elem(row[1 - 1].Y, &point[i]->Y) || !ecp_nistz256_bignum_to_field_elem(row[1 - 1].Y, &point[i]->Y)
|| !ecp_nistz256_bignum_to_field_elem(row[1 - 1].Z, &point[i]->Z)) { || !ecp_nistz256_bignum_to_field_elem(row[1 - 1].Z, &point[i]->Z)) {
ECerr(EC_F_NISTZ256_POINTS_MUL_W, EC_R_COORDINATES_OUT_OF_RANGE); ECerr(EC_F_ECP_NISTZ256_WINDOWED_MUL, EC_R_COORDINATES_OUT_OF_RANGE);
goto err; goto err;
} }
...@@ -736,12 +736,13 @@ static int ecp_nistz256_mult_precompute(EC_GROUP * group, BN_CTX * ctx) ...@@ -736,12 +736,13 @@ static int ecp_nistz256_mult_precompute(EC_GROUP * group, BN_CTX * ctx)
unsigned char *precomp_storage = NULL; unsigned char *precomp_storage = NULL;
/* if there is an old EC_PRE_COMP object, throw it away */ /* if there is an old EC_PRE_COMP object, throw it away */
EC_EX_DATA_free_data(&group->extra_data, ec_pre_comp_dup, EC_EX_DATA_free_data(&group->extra_data, ecp_nistz256_pre_comp_dup,
ec_pre_comp_free, ec_pre_comp_clear_free); ecp_nistz256_pre_comp_free,
ecp_nistz256_pre_comp_clear_free);
generator = EC_GROUP_get0_generator(group); generator = EC_GROUP_get0_generator(group);
if (generator == NULL) { if (generator == NULL) {
ECerr(EC_F_NISTZ256_PRECOMPUTE_MULT, EC_R_UNDEFINED_GENERATOR); ECerr(EC_F_ECP_NISTZ256_MULT_PRECOMPUTE, EC_R_UNDEFINED_GENERATOR);
return 0; return 0;
} }
...@@ -751,7 +752,7 @@ static int ecp_nistz256_mult_precompute(EC_GROUP * group, BN_CTX * ctx) ...@@ -751,7 +752,7 @@ static int ecp_nistz256_mult_precompute(EC_GROUP * group, BN_CTX * ctx)
return 1; return 1;
} }
if ((pre_comp = ec_pre_comp_new(group)) == NULL) if ((pre_comp = ecp_nistz256_pre_comp_new(group)) == NULL)
return 0; return 0;
if (ctx == NULL) { if (ctx == NULL) {
...@@ -770,7 +771,7 @@ static int ecp_nistz256_mult_precompute(EC_GROUP * group, BN_CTX * ctx) ...@@ -770,7 +771,7 @@ static int ecp_nistz256_mult_precompute(EC_GROUP * group, BN_CTX * ctx)
goto err; goto err;
if (BN_is_zero(order)) { if (BN_is_zero(order)) {
ECerr(EC_F_NISTZ256_PRECOMPUTE_MULT, EC_R_UNKNOWN_ORDER); ECerr(EC_F_ECP_NISTZ256_MULT_PRECOMPUTE, EC_R_UNKNOWN_ORDER);
goto err; goto err;
} }
...@@ -778,7 +779,7 @@ static int ecp_nistz256_mult_precompute(EC_GROUP * group, BN_CTX * ctx) ...@@ -778,7 +779,7 @@ static int ecp_nistz256_mult_precompute(EC_GROUP * group, BN_CTX * ctx)
if ((precomp_storage = if ((precomp_storage =
OPENSSL_malloc(37 * 64 * sizeof(P256_POINT_AFFINE) + 64)) == NULL) { OPENSSL_malloc(37 * 64 * sizeof(P256_POINT_AFFINE) + 64)) == NULL) {
ECerr(EC_F_NISTZ256_PRECOMPUTE_MULT, ERR_R_MALLOC_FAILURE); ECerr(EC_F_ECP_NISTZ256_MULT_PRECOMPUTE, ERR_R_MALLOC_FAILURE);
goto err; goto err;
} else { } else {
preComputedTable = (void *)ALIGNPTR(precomp_storage, 64); preComputedTable = (void *)ALIGNPTR(precomp_storage, 64);
...@@ -816,8 +817,9 @@ static int ecp_nistz256_mult_precompute(EC_GROUP * group, BN_CTX * ctx) ...@@ -816,8 +817,9 @@ static int ecp_nistz256_mult_precompute(EC_GROUP * group, BN_CTX * ctx)
precomp_storage = NULL; precomp_storage = NULL;
if (!EC_EX_DATA_set_data(&group->extra_data, pre_comp, if (!EC_EX_DATA_set_data(&group->extra_data, pre_comp,
ec_pre_comp_dup, ec_pre_comp_free, ecp_nistz256_pre_comp_dup,
ec_pre_comp_clear_free)) { ecp_nistz256_pre_comp_free,
ecp_nistz256_pre_comp_clear_free)) {
goto err; goto err;
} }
...@@ -829,7 +831,7 @@ err: ...@@ -829,7 +831,7 @@ err:
if (ctx != NULL) if (ctx != NULL)
BN_CTX_end(ctx); BN_CTX_end(ctx);
if (pre_comp) if (pre_comp)
ec_pre_comp_free(pre_comp); ecp_nistz256_pre_comp_free(pre_comp);
if (precomp_storage) if (precomp_storage)
OPENSSL_free(precomp_storage); OPENSSL_free(precomp_storage);
if (P) if (P)
...@@ -1090,7 +1092,7 @@ static int ecp_nistz256_points_mul(const EC_GROUP * group, ...@@ -1090,7 +1092,7 @@ static int ecp_nistz256_points_mul(const EC_GROUP * group,
BIGNUM *tmp_scalar; BIGNUM *tmp_scalar;
if (group->meth != r->meth) { if (group->meth != r->meth) {
ECerr(EC_F_NISTZ256_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS); ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS);
return 0; return 0;
} }
if ((scalar == NULL) && (num == 0)) if ((scalar == NULL) && (num == 0))
...@@ -1098,7 +1100,7 @@ static int ecp_nistz256_points_mul(const EC_GROUP * group, ...@@ -1098,7 +1100,7 @@ static int ecp_nistz256_points_mul(const EC_GROUP * group,
for (j = 0; j < num; j++) { for (j = 0; j < num; j++) {
if (group->meth != points[j]->meth) { if (group->meth != points[j]->meth) {
ECerr(EC_F_NISTZ256_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS); ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS);
return 0; return 0;
} }
} }
...@@ -1114,14 +1116,15 @@ static int ecp_nistz256_points_mul(const EC_GROUP * group, ...@@ -1114,14 +1116,15 @@ static int ecp_nistz256_points_mul(const EC_GROUP * group,
if (scalar) { if (scalar) {
generator = EC_GROUP_get0_generator(group); generator = EC_GROUP_get0_generator(group);
if (generator == NULL) { if (generator == NULL) {
ECerr(EC_F_NISTZ256_POINTS_MUL, EC_R_UNDEFINED_GENERATOR); ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, EC_R_UNDEFINED_GENERATOR);
goto err; goto err;
} }
/* look if we can use precomputed multiples of generator */ /* look if we can use precomputed multiples of generator */
pre_comp = pre_comp =
EC_EX_DATA_get_data(group->extra_data, ec_pre_comp_dup, EC_EX_DATA_get_data(group->extra_data, ecp_nistz256_pre_comp_dup,
ec_pre_comp_free, ec_pre_comp_clear_free); ecp_nistz256_pre_comp_free,
ecp_nistz256_pre_comp_clear_free);
if (pre_comp) { if (pre_comp) {
/* If there is a precomputed table for the generator, /* If there is a precomputed table for the generator,
...@@ -1156,7 +1159,7 @@ static int ecp_nistz256_points_mul(const EC_GROUP * group, ...@@ -1156,7 +1159,7 @@ static int ecp_nistz256_points_mul(const EC_GROUP * group,
goto err; goto err;
if (!BN_nnmod(tmp_scalar, scalar, &group->order, ctx)) { if (!BN_nnmod(tmp_scalar, scalar, &group->order, ctx)) {
ECerr(EC_F_NISTZ256_POINTS_MUL, ERR_R_BN_LIB); ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, ERR_R_BN_LIB);
goto err; goto err;
} }
scalar = tmp_scalar; scalar = tmp_scalar;
...@@ -1232,14 +1235,14 @@ static int ecp_nistz256_points_mul(const EC_GROUP * group, ...@@ -1232,14 +1235,14 @@ static int ecp_nistz256_points_mul(const EC_GROUP * group,
new_scalars = OPENSSL_malloc((num + 1) * sizeof(BIGNUM *)); new_scalars = OPENSSL_malloc((num + 1) * sizeof(BIGNUM *));
if (!new_scalars) { if (!new_scalars) {
ECerr(EC_F_NISTZ256_POINTS_MUL, ERR_R_MALLOC_FAILURE); ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, ERR_R_MALLOC_FAILURE);
return 0; return 0;
} }
new_points = OPENSSL_malloc((num + 1) * sizeof(EC_POINT *)); new_points = OPENSSL_malloc((num + 1) * sizeof(EC_POINT *));
if (!new_points) { if (!new_points) {
OPENSSL_free(new_scalars); OPENSSL_free(new_scalars);
ECerr(EC_F_NISTZ256_POINTS_MUL, ERR_R_MALLOC_FAILURE); ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, ERR_R_MALLOC_FAILURE);
return 0; return 0;
} }
...@@ -1293,15 +1296,14 @@ static int ecp_nistz256_get_affine(const EC_GROUP * group, ...@@ -1293,15 +1296,14 @@ static int ecp_nistz256_get_affine(const EC_GROUP * group,
BN_ULONG point_x[P256_LIMBS], point_y[P256_LIMBS], point_z[P256_LIMBS]; BN_ULONG point_x[P256_LIMBS], point_y[P256_LIMBS], point_z[P256_LIMBS];
if (EC_POINT_is_at_infinity(group, point)) { if (EC_POINT_is_at_infinity(group, point)) {
ECerr(EC_F_NISTZ256_GET_AFFINE_COORDINATES, EC_R_POINT_AT_INFINITY); ECerr(EC_F_ECP_NISTZ256_GET_AFFINE, EC_R_POINT_AT_INFINITY);
return 0; return 0;
} }
if (!ecp_nistz256_bignum_to_field_elem(point_x, &point->X) || if (!ecp_nistz256_bignum_to_field_elem(point_x, &point->X) ||
!ecp_nistz256_bignum_to_field_elem(point_y, &point->Y) || !ecp_nistz256_bignum_to_field_elem(point_y, &point->Y) ||
!ecp_nistz256_bignum_to_field_elem(point_z, &point->Z)) { !ecp_nistz256_bignum_to_field_elem(point_z, &point->Z)) {
ECerr(EC_F_NISTZ256_GET_AFFINE_COORDINATES, ECerr(EC_F_ECP_NISTZ256_GET_AFFINE, EC_R_COORDINATES_OUT_OF_RANGE);
EC_R_COORDINATES_OUT_OF_RANGE);
return 0; return 0;
} }
...@@ -1328,7 +1330,7 @@ static int ecp_nistz256_get_affine(const EC_GROUP * group, ...@@ -1328,7 +1330,7 @@ static int ecp_nistz256_get_affine(const EC_GROUP * group,
return 1; return 1;
} }
static EC_PRE_COMP *ec_pre_comp_new(const EC_GROUP * group) static EC_PRE_COMP *ecp_nistz256_pre_comp_new(const EC_GROUP * group)
{ {
EC_PRE_COMP *ret = NULL; EC_PRE_COMP *ret = NULL;
...@@ -1338,7 +1340,7 @@ static EC_PRE_COMP *ec_pre_comp_new(const EC_GROUP * group) ...@@ -1338,7 +1340,7 @@ static EC_PRE_COMP *ec_pre_comp_new(const EC_GROUP * group)
ret = (EC_PRE_COMP *) OPENSSL_malloc(sizeof(EC_PRE_COMP)); ret = (EC_PRE_COMP *) OPENSSL_malloc(sizeof(EC_PRE_COMP));
if (!ret) { if (!ret) {
ECerr(EC_F_NISTZ256_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE); ECerr(EC_F_ECP_NISTZ256_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE);
return ret; return ret;
} }
...@@ -1350,7 +1352,7 @@ static EC_PRE_COMP *ec_pre_comp_new(const EC_GROUP * group) ...@@ -1350,7 +1352,7 @@ static EC_PRE_COMP *ec_pre_comp_new(const EC_GROUP * group)
return ret; return ret;
} }
static void *ec_pre_comp_dup(void *src_) static void *ecp_nistz256_pre_comp_dup(void *src_)
{ {
EC_PRE_COMP *src = src_; EC_PRE_COMP *src = src_;
...@@ -1360,7 +1362,7 @@ static void *ec_pre_comp_dup(void *src_) ...@@ -1360,7 +1362,7 @@ static void *ec_pre_comp_dup(void *src_)
return src_; return src_;
} }
static void ec_pre_comp_free(void *pre_) static void ecp_nistz256_pre_comp_free(void *pre_)
{ {
int i; int i;
EC_PRE_COMP *pre = pre_; EC_PRE_COMP *pre = pre_;
...@@ -1378,7 +1380,7 @@ static void ec_pre_comp_free(void *pre_) ...@@ -1378,7 +1380,7 @@ static void ec_pre_comp_free(void *pre_)
OPENSSL_free(pre); OPENSSL_free(pre);
} }
static void ec_pre_comp_clear_free(void *pre_) static void ecp_nistz256_pre_comp_clear_free(void *pre_)
{ {
int i; int i;
EC_PRE_COMP *pre = pre_; EC_PRE_COMP *pre = pre_;
...@@ -1408,9 +1410,9 @@ static int ecp_nistz256_window_have_precompute_mult(const EC_GROUP * group) ...@@ -1408,9 +1410,9 @@ static int ecp_nistz256_window_have_precompute_mult(const EC_GROUP * group)
return 1; return 1;
} }
return EC_EX_DATA_get_data(group->extra_data, ec_pre_comp_dup, return EC_EX_DATA_get_data(group->extra_data, ecp_nistz256_pre_comp_dup,
ec_pre_comp_free, ecp_nistz256_pre_comp_free,
ec_pre_comp_clear_free) != NULL; ecp_nistz256_pre_comp_clear_free) != NULL;
} }
const EC_METHOD *EC_GFp_nistz256_method(void) const EC_METHOD *EC_GFp_nistz256_method(void)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册