From fbbd54fe017717706ffe48b168ff0639e88f4b43 Mon Sep 17 00:00:00 2001 From: Tux Date: Sat, 8 Dec 2018 18:15:51 -0700 Subject: Raise MemoryError when backend.derive_scrypt can't malloc enough (#4592) * Raise MemoryError when backend.derive_scrypt can't malloc enough * Expose ERR_R_MALLOC_FAILURE and use the reason_match pattern to catch it * Add test_scrypt_malloc_failure in test_scrypt * let's see if this passes * add comment to filippo's blog post about scrypt's params --- tests/hazmat/primitives/test_scrypt.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests') diff --git a/tests/hazmat/primitives/test_scrypt.py b/tests/hazmat/primitives/test_scrypt.py index 64abfe79..25d2c615 100644 --- a/tests/hazmat/primitives/test_scrypt.py +++ b/tests/hazmat/primitives/test_scrypt.py @@ -80,6 +80,20 @@ class TestScrypt(object): Scrypt(salt, length, work_factor, block_size, parallelization_factor, backend) + def test_scrypt_malloc_failure(self, backend): + password = b"NaCl" + work_factor = 1024 ** 3 + block_size = 589824 + parallelization_factor = 16 + length = 64 + salt = b"NaCl" + + scrypt = Scrypt(salt, length, work_factor, block_size, + parallelization_factor, backend) + + with pytest.raises(MemoryError): + scrypt.derive(password) + def test_password_not_bytes(self, backend): password = 1 work_factor = 1024 -- cgit v1.2.3