Merge pull request #275 from PQClean/fix-remaining-leaks

Fix remaining memory leaks
This commit is contained in:
mergify[bot] 2020-03-04 03:11:09 +00:00 committed by GitHub
commit 9023fef558
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 25 additions and 7 deletions

View File

@ -109,7 +109,7 @@ matrix:
# MacOS builds # MacOS builds
- name: "KEMs: MacOS + Clang" - name: "KEMs: MacOS + Clang"
os: osx os: osx
osx_image: xcode11.2 osx_image: xcode11.3
compiler: clang compiler: clang
before_install: before_install:
- pip3 install -r requirements.txt - pip3 install -r requirements.txt
@ -131,15 +131,17 @@ matrix:
PQCLEAN_SKIP_SCHEMES: sphincs-haraka-128f-robust,sphincs-haraka-192s-robust,sphincs-sha256-128f-robust,sphincs-sha256-192s-robust,sphincs-shake256-128f-robust,sphincs-shake256-192s-robust,sphincs-haraka-128f-simple,sphincs-haraka-192s-simple,sphincs-sha256-128f-simple,sphincs-sha256-192s-simple,sphincs-shake256-128f-simple,sphincs-shake256-192s-simple,sphincs-haraka-128s-robust,sphincs-haraka-256f-robust,sphincs-sha256-128s-robust,sphincs-sha256-256f-robust,sphincs-shake256-128s-robust,sphincs-shake256-256f-robust,sphincs-haraka-128s-simple,sphincs-haraka-256f-simple,sphincs-sha256-128s-simple,sphincs-sha256-256f-simple,sphincs-shake256-128s-simple,sphincs-shake256-256f-simple,sphincs-haraka-192f-robust,sphincs-haraka-256s-robust,sphincs-sha256-192f-robust,sphincs-sha256-256s-robust,sphincs-shake256-192f-robust,sphincs-shake256-256s-robust,sphincs-haraka-192f-simple,sphincs-haraka-256s-simple,sphincs-sha256-192f-simple,sphincs-sha256-256s-simple,sphincs-shake256-192f-simple,sphincs-shake256-256s-simple PQCLEAN_SKIP_SCHEMES: sphincs-haraka-128f-robust,sphincs-haraka-192s-robust,sphincs-sha256-128f-robust,sphincs-sha256-192s-robust,sphincs-shake256-128f-robust,sphincs-shake256-192s-robust,sphincs-haraka-128f-simple,sphincs-haraka-192s-simple,sphincs-sha256-128f-simple,sphincs-sha256-192s-simple,sphincs-shake256-128f-simple,sphincs-shake256-192s-simple,sphincs-haraka-128s-robust,sphincs-haraka-256f-robust,sphincs-sha256-128s-robust,sphincs-sha256-256f-robust,sphincs-shake256-128s-robust,sphincs-shake256-256f-robust,sphincs-haraka-128s-simple,sphincs-haraka-256f-simple,sphincs-sha256-128s-simple,sphincs-sha256-256f-simple,sphincs-shake256-128s-simple,sphincs-shake256-256f-simple,sphincs-haraka-192f-robust,sphincs-haraka-256s-robust,sphincs-sha256-192f-robust,sphincs-sha256-256s-robust,sphincs-shake256-192f-robust,sphincs-shake256-256s-robust,sphincs-haraka-192f-simple,sphincs-haraka-256s-simple,sphincs-sha256-192f-simple,sphincs-sha256-256s-simple,sphincs-shake256-192f-simple,sphincs-shake256-256s-simple
addons: addons:
homebrew: homebrew:
update: true
packages: packages:
- astyle - astyle
- ccache - ccache
- name: "KEMs: MacOS + GCC9" - name: "KEMs: MacOS + GCC9"
os: osx os: osx
osx_image: xcode11.2 osx_image: xcode11.3
compiler: gcc compiler: gcc
addons: addons:
homebrew: homebrew:
update: true
packages: packages:
- astyle - astyle
- ccache - ccache
@ -167,7 +169,7 @@ matrix:
- "cd test && travis_wait 60 python3 -m pytest --numprocesses=auto" - "cd test && travis_wait 60 python3 -m pytest --numprocesses=auto"
- name: "SIGs on MacOS + Clang" - name: "SIGs on MacOS + Clang"
os: osx os: osx
osx_image: xcode11.2 osx_image: xcode11.3
compiler: clang compiler: clang
before_install: before_install:
- pip3 install -r requirements.txt - pip3 install -r requirements.txt
@ -189,15 +191,17 @@ matrix:
PQCLEAN_SKIP_SCHEMES: sphincs-haraka-128f-robust,sphincs-haraka-192s-robust,sphincs-sha256-128f-robust,sphincs-sha256-192s-robust,sphincs-shake256-128f-robust,sphincs-shake256-192s-robust,sphincs-haraka-128f-simple,sphincs-haraka-192s-simple,sphincs-sha256-128f-simple,sphincs-sha256-192s-simple,sphincs-shake256-128f-simple,sphincs-shake256-192s-simple,sphincs-haraka-128s-robust,sphincs-haraka-256f-robust,sphincs-sha256-128s-robust,sphincs-sha256-256f-robust,sphincs-shake256-128s-robust,sphincs-shake256-256f-robust,sphincs-haraka-128s-simple,sphincs-haraka-256f-simple,sphincs-sha256-128s-simple,sphincs-sha256-256f-simple,sphincs-shake256-128s-simple,sphincs-shake256-256f-simple,sphincs-haraka-192f-robust,sphincs-haraka-256s-robust,sphincs-sha256-192f-robust,sphincs-sha256-256s-robust,sphincs-shake256-192f-robust,sphincs-shake256-256s-robust,sphincs-haraka-192f-simple,sphincs-haraka-256s-simple,sphincs-sha256-192f-simple,sphincs-sha256-256s-simple,sphincs-shake256-192f-simple,sphincs-shake256-256s-simple PQCLEAN_SKIP_SCHEMES: sphincs-haraka-128f-robust,sphincs-haraka-192s-robust,sphincs-sha256-128f-robust,sphincs-sha256-192s-robust,sphincs-shake256-128f-robust,sphincs-shake256-192s-robust,sphincs-haraka-128f-simple,sphincs-haraka-192s-simple,sphincs-sha256-128f-simple,sphincs-sha256-192s-simple,sphincs-shake256-128f-simple,sphincs-shake256-192s-simple,sphincs-haraka-128s-robust,sphincs-haraka-256f-robust,sphincs-sha256-128s-robust,sphincs-sha256-256f-robust,sphincs-shake256-128s-robust,sphincs-shake256-256f-robust,sphincs-haraka-128s-simple,sphincs-haraka-256f-simple,sphincs-sha256-128s-simple,sphincs-sha256-256f-simple,sphincs-shake256-128s-simple,sphincs-shake256-256f-simple,sphincs-haraka-192f-robust,sphincs-haraka-256s-robust,sphincs-sha256-192f-robust,sphincs-sha256-256s-robust,sphincs-shake256-192f-robust,sphincs-shake256-256s-robust,sphincs-haraka-192f-simple,sphincs-haraka-256s-simple,sphincs-sha256-192f-simple,sphincs-sha256-256s-simple,sphincs-shake256-192f-simple,sphincs-shake256-256s-simple
addons: addons:
homebrew: homebrew:
update: true
packages: packages:
- astyle - astyle
- ccache - ccache
- name: "SIGs on MacOS + GCC9" - name: "SIGs on MacOS + GCC9"
os: osx os: osx
osx_image: xcode11.2 osx_image: xcode11.3
compiler: gcc compiler: gcc
addons: addons:
homebrew: homebrew:
update: true
packages: packages:
- astyle - astyle
- ccache - ccache

View File

@ -81,7 +81,7 @@ int PQCLEAN_LEDAKEMLT12_LEAKTIME_seedexpander(AES_XOF_struct *ctx, uint8_t *x, s
memcpy(x + offset, ctx->buffer + ctx->buffer_pos, xlen); memcpy(x + offset, ctx->buffer + ctx->buffer_pos, xlen);
ctx->buffer_pos += xlen; ctx->buffer_pos += xlen;
return RNG_SUCCESS; goto end;
} }
// take what's in the buffer // take what's in the buffer
@ -103,6 +103,7 @@ int PQCLEAN_LEDAKEMLT12_LEAKTIME_seedexpander(AES_XOF_struct *ctx, uint8_t *x, s
} }
} }
end:
aes256_ctx_release(&ctx256); aes256_ctx_release(&ctx256);
return RNG_SUCCESS; return RNG_SUCCESS;

View File

@ -81,7 +81,7 @@ int PQCLEAN_LEDAKEMLT32_LEAKTIME_seedexpander(AES_XOF_struct *ctx, uint8_t *x, s
memcpy(x + offset, ctx->buffer + ctx->buffer_pos, xlen); memcpy(x + offset, ctx->buffer + ctx->buffer_pos, xlen);
ctx->buffer_pos += xlen; ctx->buffer_pos += xlen;
return RNG_SUCCESS; goto end;
} }
// take what's in the buffer // take what's in the buffer
@ -103,6 +103,7 @@ int PQCLEAN_LEDAKEMLT32_LEAKTIME_seedexpander(AES_XOF_struct *ctx, uint8_t *x, s
} }
} }
end:
aes256_ctx_release(&ctx256); aes256_ctx_release(&ctx256);
return RNG_SUCCESS; return RNG_SUCCESS;

View File

@ -81,7 +81,7 @@ int PQCLEAN_LEDAKEMLT52_LEAKTIME_seedexpander(AES_XOF_struct *ctx, uint8_t *x, s
memcpy(x + offset, ctx->buffer + ctx->buffer_pos, xlen); memcpy(x + offset, ctx->buffer + ctx->buffer_pos, xlen);
ctx->buffer_pos += xlen; ctx->buffer_pos += xlen;
return RNG_SUCCESS; goto end;
} }
// take what's in the buffer // take what's in the buffer
@ -103,6 +103,7 @@ int PQCLEAN_LEDAKEMLT52_LEAKTIME_seedexpander(AES_XOF_struct *ctx, uint8_t *x, s
} }
} }
end:
aes256_ctx_release(&ctx256); aes256_ctx_release(&ctx256);
return RNG_SUCCESS; return RNG_SUCCESS;

View File

@ -225,6 +225,7 @@ void PQCLEAN_NEWHOPE1024CCA_CLEAN_poly_uniform(poly *a, const unsigned char *see
} }
} }
} }
shake128_ctx_release(&state);
} }
} }

View File

@ -225,6 +225,7 @@ void PQCLEAN_NEWHOPE1024CPA_CLEAN_poly_uniform(poly *a, const unsigned char *see
} }
} }
} }
shake128_ctx_release(&state);
} }
} }

View File

@ -221,6 +221,7 @@ void PQCLEAN_NEWHOPE512CCA_CLEAN_poly_uniform(poly *a, const unsigned char *seed
} }
} }
} }
shake128_ctx_release(&state);
} }
} }

View File

@ -221,6 +221,7 @@ void PQCLEAN_NEWHOPE512CPA_CLEAN_poly_uniform(poly *a, const unsigned char *seed
} }
} }
} }
shake128_ctx_release(&state);
} }
} }

View File

@ -95,6 +95,7 @@ void PQCLEAN_DILITHIUM2_AVX2_challenge(poly *c,
c->coeffs[b] ^= -(signs & 1) & (1 ^ (Q - 1)); c->coeffs[b] ^= -(signs & 1) & (1 ^ (Q - 1));
signs >>= 1; signs >>= 1;
} }
shake256_ctx_release(&state);
} }
/************************************************* /*************************************************

View File

@ -85,6 +85,7 @@ void PQCLEAN_DILITHIUM2_CLEAN_challenge(poly *c,
c->coeffs[b] ^= -((int32_t)signs & 1) & (1 ^ (Q - 1)); c->coeffs[b] ^= -((int32_t)signs & 1) & (1 ^ (Q - 1));
signs >>= 1; signs >>= 1;
} }
shake256_ctx_release(&state);
} }
/************************************************* /*************************************************

View File

@ -107,6 +107,7 @@ void PQCLEAN_DILITHIUM3_AVX2_challenge(poly *c,
c->coeffs[b] ^= -(signs & 1) & (1 ^ (Q - 1)); c->coeffs[b] ^= -(signs & 1) & (1 ^ (Q - 1));
signs >>= 1; signs >>= 1;
} }
shake256_ctx_release(&state);
} }
/************************************************* /*************************************************

View File

@ -85,6 +85,7 @@ void PQCLEAN_DILITHIUM3_CLEAN_challenge(poly *c,
c->coeffs[b] ^= -((int32_t)signs & 1) & (1 ^ (Q - 1)); c->coeffs[b] ^= -((int32_t)signs & 1) & (1 ^ (Q - 1));
signs >>= 1; signs >>= 1;
} }
shake256_ctx_release(&state);
} }
/************************************************* /*************************************************

View File

@ -122,6 +122,7 @@ void PQCLEAN_DILITHIUM4_AVX2_challenge(poly *c,
c->coeffs[b] ^= -(signs & 1) & (1 ^ (Q - 1)); c->coeffs[b] ^= -(signs & 1) & (1 ^ (Q - 1));
signs >>= 1; signs >>= 1;
} }
shake256_ctx_release(&state);
} }
/************************************************* /*************************************************

View File

@ -85,6 +85,7 @@ void PQCLEAN_DILITHIUM4_CLEAN_challenge(poly *c,
c->coeffs[b] ^= -((int32_t)signs & 1) & (1 ^ (Q - 1)); c->coeffs[b] ^= -((int32_t)signs & 1) & (1 ^ (Q - 1));
signs >>= 1; signs >>= 1;
} }
shake256_ctx_release(&state);
} }
/************************************************* /*************************************************

View File

@ -54,6 +54,7 @@ def test_valgrind(implementation: pqclean.Implementation, impl_path, test_dir,
helpers.run_subprocess( helpers.run_subprocess(
['valgrind', ['valgrind',
'--error-exitcode=1', '--error-exitcode=1',
'--leak-check=yes',
*(['--exit-on-first-error=yes'] *(['--exit-on-first-error=yes']
if valgrind_supports_exit_early() if valgrind_supports_exit_early()
else []), else []),