Skip to content

Commit 149e503

Browse files
Merge branch 'master' of https://bearssl.org/git/BearSSL
2 parents 5c771be + dda1f8a commit 149e503

File tree

4 files changed

+33
-34
lines changed

4 files changed

+33
-34
lines changed

src/ec/ec_p256_m15.c

+8-14
Original file line numberDiff line numberDiff line change
@@ -2026,12 +2026,13 @@ api_mul(unsigned char *G, size_t Glen,
20262026
p256_jacobian P;
20272027

20282028
(void)curve;
2029+
if (Glen != 65) {
2030+
return 0;
2031+
}
20292032
r = p256_decode(&P, G, Glen);
20302033
p256_mul(&P, x, xlen);
2031-
if (Glen >= 65) {
2032-
p256_to_affine(&P);
2033-
p256_encode(G, &P);
2034-
}
2034+
p256_to_affine(&P);
2035+
p256_encode(G, &P);
20352036
return r;
20362037
}
20372038

@@ -2046,16 +2047,6 @@ api_mulgen(unsigned char *R,
20462047
p256_to_affine(&P);
20472048
p256_encode(R, &P);
20482049
return 65;
2049-
2050-
/*
2051-
const unsigned char *G;
2052-
size_t Glen;
2053-
2054-
G = api_generator(curve, &Glen);
2055-
memcpy(R, G, Glen);
2056-
api_mul(R, Glen, x, xlen, curve);
2057-
return Glen;
2058-
*/
20592050
}
20602051

20612052
static uint32_t
@@ -2068,6 +2059,9 @@ api_muladd(unsigned char *A, const unsigned char *B, size_t len,
20682059
int i;
20692060

20702061
(void)curve;
2062+
if (len != 65) {
2063+
return 0;
2064+
}
20712065
r = p256_decode(&P, A, len);
20722066
p256_mul(&P, x, xlen);
20732067
if (B == NULL) {

src/ec/ec_p256_m31.c

+8-14
Original file line numberDiff line numberDiff line change
@@ -1384,12 +1384,13 @@ api_mul(unsigned char *G, size_t Glen,
13841384
p256_jacobian P;
13851385

13861386
(void)curve;
1387+
if (Glen != 65) {
1388+
return 0;
1389+
}
13871390
r = p256_decode(&P, G, Glen);
13881391
p256_mul(&P, x, xlen);
1389-
if (Glen >= 65) {
1390-
p256_to_affine(&P);
1391-
p256_encode(G, &P);
1392-
}
1392+
p256_to_affine(&P);
1393+
p256_encode(G, &P);
13931394
return r;
13941395
}
13951396

@@ -1404,16 +1405,6 @@ api_mulgen(unsigned char *R,
14041405
p256_to_affine(&P);
14051406
p256_encode(R, &P);
14061407
return 65;
1407-
1408-
/*
1409-
const unsigned char *G;
1410-
size_t Glen;
1411-
1412-
G = api_generator(curve, &Glen);
1413-
memcpy(R, G, Glen);
1414-
api_mul(R, Glen, x, xlen, curve);
1415-
return Glen;
1416-
*/
14171408
}
14181409

14191410
static uint32_t
@@ -1426,6 +1417,9 @@ api_muladd(unsigned char *A, const unsigned char *B, size_t len,
14261417
int i;
14271418

14281419
(void)curve;
1420+
if (len != 65) {
1421+
return 0;
1422+
}
14291423
r = p256_decode(&P, A, len);
14301424
p256_mul(&P, x, xlen);
14311425
if (B == NULL) {

src/ec/ec_prime_i15.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -735,11 +735,12 @@ api_mul(unsigned char *G, size_t Glen,
735735
jacobian P;
736736

737737
cc = id_to_curve(curve);
738+
if (Glen != cc->point_len) {
739+
return 0;
740+
}
738741
r = point_decode(&P, G, Glen, cc);
739742
point_mul(&P, x, xlen, cc);
740-
if (Glen == cc->point_len) {
741-
point_encode(G, &P, cc);
742-
}
743+
point_encode(G, &P, cc);
743744
return r;
744745
}
745746

@@ -772,6 +773,9 @@ api_muladd(unsigned char *A, const unsigned char *B, size_t len,
772773
*/
773774

774775
cc = id_to_curve(curve);
776+
if (len != cc->point_len) {
777+
return 0;
778+
}
775779
r = point_decode(&P, A, len, cc);
776780
if (B == NULL) {
777781
size_t Glen;

src/ec/ec_prime_i31.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,16 @@ typedef struct {
107107
const uint32_t *b;
108108
const uint32_t *R2;
109109
uint32_t p0i;
110+
size_t point_len;
110111
} curve_params;
111112

112113
static inline const curve_params *
113114
id_to_curve(int curve)
114115
{
115116
static const curve_params pp[] = {
116-
{ P256_P, P256_B, P256_R2, 0x00000001 },
117-
{ P384_P, P384_B, P384_R2, 0x00000001 },
118-
{ P521_P, P521_B, P521_R2, 0x00000001 }
117+
{ P256_P, P256_B, P256_R2, 0x00000001, 65 },
118+
{ P384_P, P384_B, P384_R2, 0x00000001, 97 },
119+
{ P521_P, P521_B, P521_R2, 0x00000001, 133 }
119120
};
120121

121122
return &pp[curve - BR_EC_secp256r1];
@@ -736,6 +737,9 @@ api_mul(unsigned char *G, size_t Glen,
736737
jacobian P;
737738

738739
cc = id_to_curve(curve);
740+
if (Glen != cc->point_len) {
741+
return 0;
742+
}
739743
r = point_decode(&P, G, Glen, cc);
740744
point_mul(&P, x, xlen, cc);
741745
point_encode(G, &P, cc);
@@ -771,6 +775,9 @@ api_muladd(unsigned char *A, const unsigned char *B, size_t len,
771775
*/
772776

773777
cc = id_to_curve(curve);
778+
if (len != cc->point_len) {
779+
return 0;
780+
}
774781
r = point_decode(&P, A, len, cc);
775782
if (B == NULL) {
776783
size_t Glen;

0 commit comments

Comments
 (0)