des_crypt_4.py 757 B

1234567891011121314151617181920212223
  1. def _raw_bsdi_crypt(secret, rounds, salt):
  2. """pure-python backend for bsdi_crypt"""
  3. # decode salt
  4. salt_value = h64.decode_int24(salt)
  5. # gotta do something - no official policy since this predates unicode
  6. if isinstance(secret, unicode):
  7. secret = secret.encode("utf-8")
  8. assert isinstance(secret, bytes)
  9. # forbidding NULL char because underlying crypt() rejects them too.
  10. if _BNULL in secret:
  11. raise uh.exc.NullPasswordError(bsdi_crypt)
  12. # convert secret string into an integer
  13. key_value = _bsdi_secret_to_key(secret)
  14. # run data through des using input of 0
  15. result = des_encrypt_int_block(key_value, 0, salt_value, rounds)
  16. # run h64 encode on result
  17. return h64big.encode_int64(result)