From 896ee758458e7d17dd2014f065480b5085e6be10 Mon Sep 17 00:00:00 2001 From: tedu <> Date: Sun, 25 May 2014 20:28:50 +0000 Subject: calloc instead of malloc/memset. from Benjamin Baier --- src/lib/libcrypto/ec/ecp_nistp224.c | 6 ++---- src/lib/libcrypto/ec/ecp_nistp256.c | 6 ++---- src/lib/libcrypto/ec/ecp_nistp521.c | 6 ++---- 3 files changed, 6 insertions(+), 12 deletions(-) (limited to 'src/lib/libcrypto/ec') diff --git a/src/lib/libcrypto/ec/ecp_nistp224.c b/src/lib/libcrypto/ec/ecp_nistp224.c index bd8f65b097..53aced54d5 100644 --- a/src/lib/libcrypto/ec/ecp_nistp224.c +++ b/src/lib/libcrypto/ec/ecp_nistp224.c @@ -1435,8 +1435,8 @@ ec_GFp_nistp224_points_mul(const EC_GROUP * group, EC_POINT * r, */ 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_GROUP * group, EC_POINT * r, * 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 */ diff --git a/src/lib/libcrypto/ec/ecp_nistp256.c b/src/lib/libcrypto/ec/ecp_nistp256.c index 558c29c5ba..df80cc2b8a 100644 --- a/src/lib/libcrypto/ec/ecp_nistp256.c +++ b/src/lib/libcrypto/ec/ecp_nistp256.c @@ -1985,8 +1985,8 @@ ec_GFp_nistp256_points_mul(const EC_GROUP * group, EC_POINT * r, */ 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_GROUP * group, EC_POINT * r, * 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) /* diff --git a/src/lib/libcrypto/ec/ecp_nistp521.c b/src/lib/libcrypto/ec/ecp_nistp521.c index 0c40f08346..6792c5b71d 100644 --- a/src/lib/libcrypto/ec/ecp_nistp521.c +++ b/src/lib/libcrypto/ec/ecp_nistp521.c @@ -1872,8 +1872,8 @@ ec_GFp_nistp521_points_mul(const EC_GROUP * group, EC_POINT * r, */ 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_GROUP * group, EC_POINT * r, * 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) /* -- cgit v1.2.3-55-g6feb