Skip to content

Commit

Permalink
Avoid leaking nonce in _ecdsa_sign()
Browse files Browse the repository at this point in the history
The nonce was allocated by mpz_set_str(), so must be freed
by mpz_clear(). This makes the test by @EggPool in AntonKueltz#6 run
in constant memory.
  • Loading branch information
botovq committed Apr 14, 2021
1 parent e657c59 commit 2420058
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/_ecdsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static PyObject * _ecdsa_sign(PyObject *self, PyObject *args) {

char * resultR = mpz_get_str(NULL, 10, sig.r);
char * resultS = mpz_get_str(NULL, 10, sig.s);
mpz_clears(sig.r, sig.s, privKey, NULL);
mpz_clears(sig.r, sig.s, privKey, nonce, NULL);

PyObject * ret = Py_BuildValue("ss", resultR, resultS);
free(resultR);
Expand Down

0 comments on commit 2420058

Please sign in to comment.