示例#1
0
文件: __init__.py 项目: soitun/LinOTP
    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
示例#2
0
文件: __init__.py 项目: soitun/LinOTP
    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
示例#3
0
 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
示例#4
0
 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
示例#5
0
 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