def genhash(cls, secret, config): uh.validate_secret(secret) secret = to_bytes(secret, 'utf-8') self = cls.from_string(config) if self.type_d: type = _argon2_cffi.low_level.Type.D else: type = _argon2_cffi.low_level.Type.I try: result = bascii_to_str( _argon2_cffi.low_level.hash_secret( type=type, memory_cost=self.memory_cost, time_cost=self.rounds, parallelism=self.parallelism, salt=to_bytes(self.salt), hash_len=self.checksum_size, secret=secret, version=self.version)) except _argon2_cffi.exceptions.HashingError as err: raise cls._adapt_backend_error(err, hash=config) if self.version == 16: result = result.replace('$v=16$', '$') return result
def to_string(self): ident = str(self.ident_values[self.type_d]) version = self.version if version == 16: vstr = '' else: vstr = 'v=%d$' % version data = self.data if data: kdstr = ',data=' + bascii_to_str(b64s_encode(self.data)) else: kdstr = '' return '%s%sm=%d,t=%d,p=%d%s$%s$%s' % ( ident, vstr, self.memory_cost, self.rounds, self.parallelism, kdstr, bascii_to_str(b64s_encode( self.salt)), bascii_to_str(b64s_encode(self.checksum)))
def to_string(self): ident = self.ident if ident == IDENT_SCRYPT: return '$scrypt$ln=%d,r=%d,p=%d$%s$%s' % ( self.rounds, self.block_size, self.parallelism, bascii_to_str(b64s_encode( self.salt)), bascii_to_str(b64s_encode(self.checksum))) salt = self.salt try: salt.decode('ascii') except UnicodeDecodeError: raise suppress_cause( NotImplementedError( 'scrypt $7$ hashes dont support non-ascii salts')) return bascii_to_str(('').join([ '$7$', h64.encode_int6(self.rounds), h64.encode_int30(self.block_size), h64.encode_int30(self.parallelism), self.salt, '$', h64.encode_bytes(self.checksum) ]))
def hash(cls, secret): uh.validate_secret(secret) secret = to_bytes(secret, 'utf-8') try: return bascii_to_str( _argon2_cffi.low_level.hash_secret( type=_argon2_cffi.low_level.Type.I, memory_cost=cls.memory_cost, time_cost=cls.default_rounds, parallelism=cls.parallelism, salt=to_bytes(cls._generate_salt()), hash_len=cls.checksum_size, secret=secret)) except _argon2_cffi.exceptions.HashingError as err: raise cls._adapt_backend_error(err)
def to_string(self): chk = self.checksum salt = self.salt data = bascii_to_str(b64encode(salt + chk)) return '{FSHP%d|%d|%d}%s' % (self.variant, len(salt), self.rounds, data)
def hex_key(self): return bascii_to_str(base64.b16encode(self.key)).lower()
def to_string(self): raw = self.salt + self.checksum return '0x0100' + bascii_to_str(hexlify(raw).upper())
def hexstr(data): return bascii_to_str(hexlify(data))
def b32encode(source): return bascii_to_str(_b32encode(source).rstrip(B_EQUAL))
def test_md4_digest(self): md4 = self.get_md4_const() for input, hex in self.vectors: out = bascii_to_str(hexlify(md4(input).digest())) self.assertEqual(out, hex)
def to_string(self): salt = bascii_to_str(ab64_encode(self.salt)) chkmap = self.checksum chk_str = (',').join('%s=%s' % (alg, bascii_to_str(ab64_encode(chkmap[alg]))) for alg in self.algs) return '$scram$%d$%s$%s' % (self.rounds, salt, chk_str)
def hexdigest(self): return bascii_to_str(hexlify(self.digest()))