def handle_INF(self, data): if self.state not in ("IDENTIFY", "NORMAL"): self.status(44, "Invalid state", "FCBINF") return sid, data = data.split(" ", 1) self.inf.update(flag_dict(data)) # Verify that tiger(PID) == CID. if "ID" in self.inf and "PD" in self.inf: hashed = b32d(self.inf["ID"]) unhashed = b32d(self.inf["PD"]) if tiger.new(unhashed).digest() != hashed: self.status(27, "PID does not match CID") return # If the IP address was not provided, or if it was blank, write down # their actual connecting IP. if "I4" not in self.inf or self.inf["I4"] == "0.0.0.0": self.inf["I4"] = self.addr.host # If we weren't identified before, transition to VERIFY and ask for a # password. if self.state == "IDENTIFY": if pass_ip_check(self.addr.host): self.enter() return self.state = "VERIFY" self.nonce = rand32(16) gpa = "IGPA %s" % self.nonce self.sendLine(gpa)
def hash(self, f): """Build the tree.""" if self.inited: return h = open(f, "rb") leaves = [] # Need to read once, to figure out if file's empty. # This part is really lame. buf = h.read(self.blocksize) if not len(buf): leaves.append(tiger.new("\x00").digest()) else: while len(buf): buf = '\x00' + buf leaves.append(tiger.new(buf).digest()) buf = h.read(self.blocksize) h.close() return leaves
def buildTree(self, leaves): levels = int(math.ceil(math.log(len(leaves),2))) tree = [leaves] for i in range(levels): l = [] for j in range(len(tree[i])): if j % 2: continue try: buf = '\x01' + tree[i][j] + tree[i][j+1] l.append(tiger.new(buf).digest()) except IndexError: l.append(tree[i][j]) tree.append(l) tree.reverse() if self.maxlevels: del tree[self.maxlevels:] return levels, tree
def test_instance(self): tiger.new() pass
def test_pangram_update(self): t = tiger.new() t.update("The quick brown fox jumps over the lazy dog") self.assertEqual("6d12a41e72e644f017b6f0e2f7b44c6285f06dd5d2c5b075", t.hexdigest())
def test_empty_hash(self): self.assertEqual("3293ac630c13f0245f92bbb1766e16167a4e58492dde73f3", tiger.new().hexdigest())
def _hash(self, data): return tiger.new(data).hexdigest()
if __name__ == '__main__': from os import getcwd from os import sys sys.path.append(getcwd()) from MOAL.helpers.display import Section from MOAL.helpers.display import print_simple from MOAL.helpers.display import print_h2 import tiger import hashlib import hmac DEBUG = True if __name__ == '__main__' else False if DEBUG: with Section('Message digest cryptography functions'): sekrit = 'A very very secret thing' print_h2('Hashlib algorithms') for algo in hashlib.algorithms: hashed = hashlib.new(algo).hexdigest() print_simple(algo, hashed, newline=False) print_h2('HMAC') _hmac = hmac.new('*****@*****.**', sekrit) print(_hmac.hexdigest()) _tiger = tiger.new(sekrit).hexdigest() print_simple('Tiger (TTH)', _tiger)
def hash_password(password, nonce): return b32e(tiger.new(password + b32d(nonce)).digest())
__author__ = """Chris Tabor ([email protected])""" if __name__ == '__main__': from os import getcwd from os import sys sys.path.append(getcwd()) from MOAL.helpers.display import Section from MOAL.helpers.display import print_simple from MOAL.helpers.display import print_h2 import tiger import hashlib import hmac DEBUG = True if __name__ == '__main__' else False if DEBUG: with Section('Message digest cryptography functions'): sekrit = 'A very very secret thing' print_h2('Hashlib algorithms') for algo in hashlib.algorithms: hashed = hashlib.new(algo).hexdigest() print_simple(algo, hashed, newline=False) print_h2('HMAC') _hmac = hmac.new('*****@*****.**', sekrit) print(_hmac.hexdigest()) _tiger = tiger.new(sekrit).hexdigest() print_simple('Tiger (TTH)', _tiger)