des_crypt_27.py 1.1 KB

1234567891011121314151617181920212223242526272829
  1. def _calc_checksum(self, secret):
  2. if isinstance(secret, unicode):
  3. secret = secret.encode("utf-8")
  4. # check for truncation (during .hash() calls only)
  5. if self.use_defaults:
  6. self._check_truncate_policy(secret)
  7. # parse salt value
  8. try:
  9. salt_value = h64.decode_int12(self.salt.encode("ascii"))
  10. except ValueError: # pragma: no cover - caught by class
  11. raise suppress_cause(ValueError("invalid chars in salt"))
  12. # convert first 8 byts of secret string into an integer,
  13. key1 = _crypt_secret_to_key(secret)
  14. # run data through des using input of 0
  15. result1 = des_encrypt_int_block(key1, 0, salt_value, 20)
  16. # convert next 8 bytes of secret string into integer (key=0 if secret < 8 chars)
  17. key2 = _crypt_secret_to_key(secret[8:16])
  18. # run data through des using input of 0
  19. result2 = des_encrypt_int_block(key2, 0, salt_value, 5)
  20. # done
  21. chk = h64big.encode_int64(result1) + h64big.encode_int64(result2)
  22. return chk.decode("ascii")