summaryrefslogtreecommitdiff
path: root/lib/freebl/ec.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/freebl/ec.c')
-rw-r--r--lib/freebl/ec.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/freebl/ec.c b/lib/freebl/ec.c
index 7f4e903a0..73a625a69 100644
--- a/lib/freebl/ec.c
+++ b/lib/freebl/ec.c
@@ -7,6 +7,7 @@
#endif
#include "blapi.h"
+#include "blapii.h"
#include "prerr.h"
#include "secerr.h"
#include "secmpi.h"
@@ -146,6 +147,10 @@ ec_points_mul(const ECParams *params, const mp_int *k1, const mp_int *k2,
CHECK_MPI_OK(ECPoints_mul(group, k1, NULL, NULL, NULL, &Qx, &Qy));
}
+ /* our ECC codes uses large stack variables to store intermediate results,
+ * clear our stack before returning to prevent CSP leakage */
+ BLAPI_CLEAR_STACK(2048)
+
/* Construct the SECItem representation of point Q */
pointQ->data[0] = EC_POINT_FORM_UNCOMPRESSED;
CHECK_MPI_OK(mp_to_fixlen_octets(&Qx, pointQ->data + 1,
@@ -531,7 +536,6 @@ ECDH_Derive(SECItem *publicValue,
unsigned int len = 0;
SECItem pointQ = { siBuffer, NULL, 0 };
mp_int k; /* to hold the private value */
- mp_int cofactor;
mp_err err = MP_OKAY;
#if EC_DEBUG
int i;
@@ -596,11 +600,13 @@ ECDH_Derive(SECItem *publicValue,
(mp_size)privateValue->len));
if (withCofactor && (ecParams->cofactor != 1)) {
+ mp_int cofactor;
/* multiply k with the cofactor */
MP_DIGITS(&cofactor) = 0;
CHECK_MPI_OK(mp_init(&cofactor));
mp_set(&cofactor, ecParams->cofactor);
CHECK_MPI_OK(mp_mul(&k, &cofactor, &k));
+ mp_clear(&cofactor);
}
/* Multiply our private key and peer's public point */
@@ -858,7 +864,7 @@ cleanup:
mp_clear(&ar);
if (t2) {
- PORT_Free(t2);
+ PORT_ZFree(t2, 2 * ecParams->order.len);
}
if (kGpoint.data) {