def hash_pin(pin): """ hash a given pin :param pin: :return: a concatenated 'iv:hashed_pin' """ iv = utils.geturandom(16) hashed_pin = utils.hash_digest(pin.encode("utf-8"), iv) return iv, hashed_pin
def check_hashed_pin(pin: str, hashed_pin: bytes, iv: bytes) -> bool: """ check a hashed against a given pin :param hashed_pin: hex binary :param iv: hex binary iv from former decryption step :param pin: string :return: boolean """ hash_pin = utils.hash_digest(pin.encode("utf-8"), iv) # TODO: position independend compare if hashed_pin == hash_pin: return True return False
def setHashedPin(self, pin): seed = geturandom(16) self.LinOtpSeed = binascii.hexlify(seed).decode('utf-8') self.LinOtpPinHash = binascii.hexlify(hash_digest( pin, seed)).decode('utf-8') return self.LinOtpPinHash
def hash_pin(pin, iv=None, hsm=None): if not iv: iv = geturandom(16) hashed_pin = hash_digest(pin, iv, hsm=hsm) return iv, hashed_pin
def setHashedPin(self, pin): seed = geturandom(16) self.LinOtpSeed = unicode(binascii.hexlify(seed)) self.LinOtpPinHash = unicode(binascii.hexlify(hash_digest(pin, seed))) return self.LinOtpPinHash