Skip to content

Commit

Permalink
Use new Poly1305 class methods from cryptography 2.8 release
Browse files Browse the repository at this point in the history
This commit switches the Chacha20-Poly1305 code to use the one-line
class methods to generate and verify Poly1305 tags.
  • Loading branch information
ronf committed Oct 22, 2019
1 parent a033ddd commit 386432c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 2 additions & 7 deletions asyncssh/crypto/chacha.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,13 @@ def poly1305_key(key, nonce):
def poly1305(key, data, nonce):
"""Compute a Poly1305 tag for a block of data"""

poly = Poly1305(poly1305_key(key, nonce))
poly.update(data)
return poly.finalize()
return Poly1305.generate_tag(poly1305_key(key, nonce), data)

def poly1305_verify(key, data, nonce, tag):
"""Verify a Poly1305 tag for a block of data"""

poly = Poly1305(poly1305_key(key, nonce))

try:
poly.update(data)
poly.verify(tag)
Poly1305.verify_tag(poly1305_key(key, nonce), data, tag)
return True
except InvalidSignature:
return False
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
long_description = long_description,
platforms = 'Any',
python_requires = '>= 3.6',
install_requires = ['cryptography >= 2.7'],
install_requires = ['cryptography >= 2.8'],
extras_require = {
'bcrypt': ['bcrypt >= 3.1.3'],
'gssapi': ['gssapi >= 1.2.0'],
Expand Down

0 comments on commit 386432c

Please sign in to comment.