crypto.py 671 B

1234567891011121314151617181920
  1. """ Cryptographic primitives. """
  2. from Crypto.Signature import PKCS1_v1_5
  3. from Crypto.Hash import SHA512
  4. def get_hasher():
  5. """ Returns a object that you can use for hashing. Currently SHA512, swap it out for something if you feel like it! """
  6. return SHA512.new()
  7. MAX_HASH = (1 << 512) - 1
  8. def verify_sign(hashed_value, signature, pub_key):
  9. """ Verify a signature for a already hashed value and a public key. """
  10. ver = PKCS1_v1_5.new(pub_key)
  11. return ver.verify(hashed_value, signature)
  12. def sign(hashed_value, priv_key):
  13. """ Sign a hashed value with a private key. """
  14. signer = PKCS1_v1_5.new(priv_key)
  15. return signer.sign(hashed_value)