зеркало из https://github.com/mozilla/gecko-dev.git
Bugzilla Bug 257693: code cleanup. 1. Change "X9.63" to "X9.62". 2. In
EC_ValidatePublicKey, set error codes and handle a NULL return from ECGroup_fromName. 3. In the ECGroupStr structure, move the validate_point field up. 4. In the test cases, if the tests that should fail, passed, say so in the error messages. r=douglas@stebila.ca. Modified Files: blapi.h ec.c ecl/ecl-priv.h ecl/ecl.c ecl/ecl.h ecl/tests/ec2_test.c ecl/tests/ecp_test.c
This commit is contained in:
Родитель
bb9dbb8c6c
Коммит
afccecc775
|
@ -37,7 +37,7 @@
|
|||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
/* $Id: blapi.h,v 1.21 2005/08/09 02:54:54 nelsonb%netscape.com Exp $ */
|
||||
/* $Id: blapi.h,v 1.22 2005/08/27 01:09:21 wtchang%redhat.com Exp $ */
|
||||
|
||||
#ifndef _BLAPI_H_
|
||||
#define _BLAPI_H_
|
||||
|
@ -208,7 +208,7 @@ extern SECStatus EC_NewKeyFromSeed(ECParams * params,
|
|||
int seedlen);
|
||||
|
||||
/* Validates an EC public key as described in Section 5.2.2 of
|
||||
* X9.63. Such validation prevents against small subgroup attacks
|
||||
* X9.62. Such validation prevents against small subgroup attacks
|
||||
* when the ECDH primitive is used with the cofactor.
|
||||
*/
|
||||
extern SECStatus EC_ValidatePublicKey(ECParams * params,
|
||||
|
|
|
@ -382,7 +382,7 @@ cleanup:
|
|||
}
|
||||
|
||||
/* Validates an EC public key as described in Section 5.2.2 of
|
||||
* X9.63. The ECDH primitive when used without the cofactor does
|
||||
* X9.62. The ECDH primitive when used without the cofactor does
|
||||
* not address small subgroup attacks, which may occur when the
|
||||
* public key is not valid. These attacks can be prevented by
|
||||
* validating the public key before using ECDH.
|
||||
|
@ -404,8 +404,11 @@ EC_ValidatePublicKey(ECParams *ecParams, SECItem *publicValue)
|
|||
|
||||
/* NOTE: We only support uncompressed points for now */
|
||||
len = (ecParams->fieldID.size + 7) >> 3;
|
||||
if ((publicValue->data[0] != EC_POINT_FORM_UNCOMPRESSED) ||
|
||||
(publicValue->len != (2 * len + 1))) {
|
||||
if (publicValue->data[0] != EC_POINT_FORM_UNCOMPRESSED) {
|
||||
PORT_SetError(SEC_ERROR_UNSUPPORTED_EC_POINT_FORM);
|
||||
return SECFailure;
|
||||
} else if (publicValue->len != (2 * len + 1)) {
|
||||
PORT_SetError(SEC_ERROR_INPUT_LEN);
|
||||
return SECFailure;
|
||||
};
|
||||
|
||||
|
@ -420,6 +423,8 @@ EC_ValidatePublicKey(ECParams *ecParams, SECItem *publicValue)
|
|||
|
||||
/* construct from named params */
|
||||
group = ECGroup_fromName(ecParams->name);
|
||||
if (group == NULL)
|
||||
goto cleanup;
|
||||
|
||||
/* validate public point */
|
||||
CHECK_MPI_OK( ECPoint_validate(group, &Px, &Py) );
|
||||
|
|
|
@ -144,12 +144,12 @@ struct ECGroupStr {
|
|||
mp_err (*points_mul) (const mp_int *k1, const mp_int *k2,
|
||||
const mp_int *px, const mp_int *py, mp_int *rx,
|
||||
mp_int *ry, const ECGroup *group);
|
||||
mp_err (*validate_point) (const mp_int *px, const mp_int *py, const ECGroup *group);
|
||||
/* Extra storage for implementation-specific data. Any memory
|
||||
* allocated to these extra fields will be cleared by extra_free. */
|
||||
void *extra1;
|
||||
void *extra2;
|
||||
void (*extra_free) (ECGroup *group);
|
||||
mp_err (*validate_point) (const mp_int *px, const mp_int *py, const ECGroup *group);
|
||||
};
|
||||
|
||||
/* Wrapper functions for generic prime field arithmetic. */
|
||||
|
|
|
@ -68,10 +68,10 @@ ECGroup_new()
|
|||
MP_CHECKOK(mp_init(&group->order));
|
||||
group->base_point_mul = NULL;
|
||||
group->points_mul = NULL;
|
||||
group->validate_point = NULL;
|
||||
group->extra1 = NULL;
|
||||
group->extra2 = NULL;
|
||||
group->extra_free = NULL;
|
||||
group->validate_point = NULL;
|
||||
|
||||
CLEANUP:
|
||||
if (res != MP_OKAY) {
|
||||
|
@ -394,7 +394,7 @@ ECGroup_fromName(const ECCurveName name)
|
|||
return group;
|
||||
}
|
||||
|
||||
/* Validates an EC public key as described in Section 5.2.2 of X9.63. */
|
||||
/* Validates an EC public key as described in Section 5.2.2 of X9.62. */
|
||||
mp_err ECPoint_validate(const ECGroup *group, const mp_int *px, const
|
||||
mp_int *py)
|
||||
{
|
||||
|
|
|
@ -81,7 +81,7 @@ mp_err ECPoints_mul(const ECGroup *group, const mp_int *k1,
|
|||
const mp_int *k2, const mp_int *px, const mp_int *py,
|
||||
mp_int *qx, mp_int *qy);
|
||||
|
||||
/* Validates an EC public key as described in Section 5.2.2 of X9.63. */
|
||||
/* Validates an EC public key as described in Section 5.2.2 of X9.62. */
|
||||
mp_err ECPoint_validate(const ECGroup *group, const mp_int *px, const
|
||||
mp_int *py);
|
||||
|
||||
|
|
|
@ -356,7 +356,7 @@ ectest_curve_GF2m(ECGroup *group, int ectestPrint, int ectestTime,
|
|||
}
|
||||
MP_CHECKOK(mp_add_d(&gy, 1, &ry));
|
||||
if (ECPoint_validate(group, &gx, &ry) == 0) {
|
||||
printf(" Error: validate point on invalid point failed.\n");
|
||||
printf(" Error: validate point on invalid point passed.\n");
|
||||
res = MP_NO;
|
||||
goto CLEANUP;
|
||||
}
|
||||
|
|
|
@ -318,7 +318,7 @@ ectest_curve_GFp(ECGroup *group, int ectestPrint, int ectestTime,
|
|||
}
|
||||
MP_CHECKOK(mp_add_d(&gy, 1, &ry));
|
||||
if (ECPoint_validate(group, &gx, &ry) == 0) {
|
||||
printf(" Error: validate point on invalid point failed.\n");
|
||||
printf(" Error: validate point on invalid point passed.\n");
|
||||
res = MP_NO;
|
||||
goto CLEANUP;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче