Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opt no wipe argon2 32 pyx #11

Merged
merged 3 commits into from
Aug 17, 2024

Conversation

ioerror
Copy link
Contributor

@ioerror ioerror commented Aug 17, 2024

On line 350 of c_monocypher.pyx there is an unconditional call to crypto_wipe. Starting on line 155 the definition of wipe includes a comment that says: "WARNING: this violates the Python memory model and may result in corrupted data. Ensure that the data to wipe is the only active reference!"""

While developing a cryptographic protocol that optionally uses very short passwords, we appear to have encountered this issue. We outlined this finding in our comments but we only seem to trigger it for passwords with a length that is less than two bytes: https://codeberg.org/rendezvous/reunion/src/branch/main/reunion/primitives.py#L17 We additionally make a copy of the original password for use over long periods of time.

We would prefer to not corrupt memory for the single password cases in our protocol, if that is indeed happening. We would also prefer not to need to make a copy of the original passphrase to work around this specific use case as erasing the password in memory is problematic for long running protocol runs.

This change optionally allows a caller to avoid argon2i_32 calling wipe or crypto_wipe internally by passing the optional value _wipe=False when using argon2i_32 . By default the original behavior is retained (e.g.: _wipe=True and wipe is called by argon2i_32 ). This change would only impact callers who want to disable wiping.

While using pymonocypher for a cryptographic protocol, we encountered an
AttributeError:

    File "c_monocypher.pyx", line 328, in monocypher.argon2i_32
  AttributeError: 'dict' object has no attribute 'nb_block'

Using the Python console to reproduce the error with monocypher 4.0.2.3:

>>> import monocypher
>>> monocypher.argon2i_32(nb_blocks=100000, nb_iterations=3,
                          password=password, salt=salt, key=None,
                          ad=None)

This will result in the following exception:

   Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "c_monocypher.pyx", line 328, in monocypher.argon2i_32
  AttributeError: 'dict' object has no attribute 'nb_block'

It appears that the c_monocypher.pyx is defined in the singular
'nb_block' for the binding when it should be 'nb_blocks'. After changing
that value to 'nb_blocks', it works as expected:

  >>> password  = b'123456'
  >>> salt = b'00125235'
  >>> monocypher.argon2i_32(nb_blocks=100000, nb_iterations=3,
                            password=password, salt=salt, key=None,
                            ad=None)

This produces a bytes object as expected:

  b'\x8cj\x88\xc7\xda}\x7f\x18Z\x01\xbf\xbb\xd5\x01\x13\xd9<\xb4\xb9\'c\x8f\x98\xee\x96\x04E-\xfc"\xd9o'
@mliberty1 mliberty1 merged commit 923757f into jetperch:main Aug 17, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants