def test_hash(self): msg=self.tmp_dir+'/msg' with open(msg, 'w') as fd: fd.write('0' * 1080) h=pbp.hash_handler(infile=msg, k='', outlen=16) self.assertEquals(h, b'%\x80\x1e\xc8\x0c\x17\x89Z_I\x15\x19.Z P') h=pbp.hash_handler(infile=msg, k='some random "key" with 32 byte output'.encode('utf-8'), outlen=32) self.assertEquals(h,b"\xae\xf5\x84\x9cr\xf5D1D\x9e}&\x18\xa5Q&LMw\xe3\xa08y\xbf~'\xf5\x0b\x9a\xe4\xd9\x97")
def test_hash(self): msg = self.tmp_dir + '/msg' with open(msg, 'w') as fd: fd.write('0' * 1080) h = pbp.hash_handler(infile=msg, k='', outlen=16) self.assertEquals(h, '%\x80\x1e\xc8\x0c\x17\x89Z_I\x15\x19.Z P') h = pbp.hash_handler(infile=msg, k='some random "key" with 32 byte output', outlen=32) self.assertEquals( h, "\xae\xf5\x84\x9cr\xf5D1D\x9e}&\x18\xa5Q&LMw\xe3\xa08y\xbf~'\xf5\x0b\x9a\xe4\xd9\x97" )
sec = mpecdh_end_handler(opts.name, opts.self, opts.infile, opts.outfile, opts.basedir) if sec: print >>sys.stderr, "[pbp] pushed shared secret, hash", b85encode(nacl.crypto_generichash(sec, outlen=6)) clearmem(sec) sec = None elif opts.action=='R': ensure_size_good(opts) if PITCHFORK and opts.PITCHFORK: pitchfork.init() pitchfork.rng(int(opts.size), opts.outfile) else: random_stream_handler(opts.outfile, opts.size) elif opts.action=='h': hsum = hash_handler(opts.infile, k=load_key(opts.key), outlen=int(opts.size or '16')) if hsum: print ' '.join(split_by_n(binascii.hexlify(hsum),4)) def load_key(key): # asserts that self is specified if not key: return None if os.path.exists(key): with open(key,'r') as fd: key = fd.read() return key def ensure_self_specified(opts): # asserts that self is specified if not opts.self:
sec = mpecdh_end_handler(opts.name, opts.self, opts.infile, opts.outfile, opts.basedir) if sec: print >>sys.stderr, "pushed shared secret, hash", b85encode(nacl.crypto_generichash(sec, outlen=6)) clearmem(sec) sec = None elif opts.action=='R': ensure_size_good(opts) if PITCHFORK: pitchfork.init() pitchfork.rng(int(opts.size), opts.outfile) else: random_stream_handler(opts.outfile, opts.size) elif opts.action=='h': hsum = hash_handler(opts.infile, k=load_key(opts.key), outlen=int(opts.size or '16')) if hsum: print ' '.join(split_by_n(binascii.hexlify(hsum),4)) def load_key(key): # asserts that self is specified if not key: return None if os.path.exists(key): with open(opts.key,'r') as fd: key = fd.read() return key def ensure_self_specified(opts): # asserts that self is specified if not opts.self: