On Sun, 25 May 2014 10:08:06 +0100 Stuart Henderson <[email protected]> wrote:
> There are a couple like this:
>
> > - pre_comp = malloc(num_points * 17 * 3 * sizeof(felem));
> > + pre_comp = calloc(num_points * 17 * 3, sizeof(felem));
>
> Wouldn't they be better like this?
>
> pre_comp = calloc(num_points, 17 * 3 * sizeof(felem));
>
Yes indeed. But once you(I) start worrying about overflow, it's opening
pandoras box, and I'm not quite there yet.
i.e. what do you make of this?
tmp_felems = malloc((num_points * 17 + 1) * sizeof(felem));
Nevertheless...
Index: ecp_nistp224.c
===================================================================
RCS file: /cvs/src/lib/libssl/src/crypto/ec/ecp_nistp224.c,v
retrieving revision 1.7
diff -u -p -r1.7 ecp_nistp224.c
--- ecp_nistp224.c 15 May 2014 11:25:59 -0000 1.7
+++ ecp_nistp224.c 25 May 2014 09:41:35 -0000
@@ -1435,8 +1435,8 @@ ec_GFp_nistp224_points_mul(const EC_GROU
*/
mixed = 1;
}
- secrets = malloc(num_points * sizeof(felem_bytearray));
- pre_comp = malloc(num_points * 17 * 3 * sizeof(felem));
+ secrets = calloc(num_points, sizeof(felem_bytearray));
+ pre_comp = calloc(num_points, 17 * 3 * sizeof(felem));
if (mixed)
tmp_felems = malloc((num_points * 17 + 1) *
sizeof(felem));
if ((secrets == NULL) || (pre_comp == NULL) || (mixed &&
(tmp_felems == NULL))) {
@@ -1448,8 +1448,6 @@ ec_GFp_nistp224_points_mul(const EC_GROU
* infinity, i.e., they contribute nothing to the linear
* combination
*/
- memset(secrets, 0, num_points * sizeof(felem_bytearray));
- memset(pre_comp, 0, num_points * 17 * 3 * sizeof(felem));
for (i = 0; i < num_points; ++i) {
if (i == num)
/* the generator */
Index: ecp_nistp256.c
===================================================================
RCS file: /cvs/src/lib/libssl/src/crypto/ec/ecp_nistp256.c,v
retrieving revision 1.7
diff -u -p -r1.7 ecp_nistp256.c
--- ecp_nistp256.c 15 May 2014 11:25:59 -0000 1.7
+++ ecp_nistp256.c 25 May 2014 09:43:43 -0000
@@ -1985,8 +1985,8 @@ ec_GFp_nistp256_points_mul(const EC_GROU
*/
mixed = 1;
}
- secrets = malloc(num_points * sizeof(felem_bytearray));
- pre_comp = malloc(num_points * 17 * 3 * sizeof(smallfelem));
+ secrets = calloc(num_points, sizeof(felem_bytearray));
+ pre_comp = calloc(num_points, 17 * 3 * sizeof(smallfelem));
if (mixed)
tmp_smallfelems = malloc((num_points * 17 + 1) *
sizeof(smallfelem));
if ((secrets == NULL) || (pre_comp == NULL) || (mixed &&
(tmp_smallfelems == NULL))) {
@@ -1998,8 +1998,6 @@ ec_GFp_nistp256_points_mul(const EC_GROU
* infinity, i.e., they contribute nothing to the linear
* combination
*/
- memset(secrets, 0, num_points * sizeof(felem_bytearray));
- memset(pre_comp, 0, num_points * 17 * 3 * sizeof(smallfelem));
for (i = 0; i < num_points; ++i) {
if (i == num)
/*
Index: ecp_nistp521.c
===================================================================
RCS file: /cvs/src/lib/libssl/src/crypto/ec/ecp_nistp521.c,v
retrieving revision 1.8
diff -u -p -r1.8 ecp_nistp521.c
--- ecp_nistp521.c 15 May 2014 11:25:59 -0000 1.8
+++ ecp_nistp521.c 25 May 2014 09:45:06 -0000
@@ -1872,8 +1872,8 @@ ec_GFp_nistp521_points_mul(const EC_GROU
*/
mixed = 1;
}
- secrets = malloc(num_points * sizeof(felem_bytearray));
- pre_comp = malloc(num_points * 17 * 3 * sizeof(felem));
+ secrets = calloc(num_points, sizeof(felem_bytearray));
+ pre_comp = calloc(num_points, 17 * 3 * sizeof(felem));
if (mixed)
tmp_felems = malloc((num_points * 17 + 1) *
sizeof(felem));
if ((secrets == NULL) || (pre_comp == NULL) || (mixed &&
(tmp_felems == NULL))) {
@@ -1885,8 +1885,6 @@ ec_GFp_nistp521_points_mul(const EC_GROU
* infinity, i.e., they contribute nothing to the linear
* combination
*/
- memset(secrets, 0, num_points * sizeof(felem_bytearray));
- memset(pre_comp, 0, num_points * 17 * 3 * sizeof(felem));
for (i = 0; i < num_points; ++i) {
if (i == num)
/*