portable method to zeroize memory when destroying a mpz number

Vicente Benjumea vicente at lcc.uma.es
Thu Mar 20 13:42:11 UTC 2014


when implementing public key cryptography algorithms, it would be nice
to have a portable method to zeroize (reset to zero) the memory that
holds the big-number bits before being destroyed, specially for private

For example, something similar to:

mpz_clear_zeroize (mpz_ptr m)
  if (PTR (m) != NULL) {
    memset(PTR (m), 0, ALLOC (m) * BYTES_PER_MP_LIMB);
  (*__gmp_free_func) (PTR (m), ALLOC (m) * BYTES_PER_MP_LIMB);
  ALLOC (m) = 0;
  PTR (m) = 0;
  SIZ (m) = 0;

if this method appears in the public interface of GMP (mpz), then it can
be safely used even if the current internal implementation changes.

Thank you very much

More information about the gmp-discuss mailing list