elif opts.action=='de': ensure_self_specified(opts) ensure_name_specified(opts) 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
clearmem(sec) sec = None # finish ECDH elif opts.action=='de': ensure_self_specified(opts) ensure_name_specified(opts) 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) random_stream_handler(opts.outfile, opts.size) def ensure_self_specified(opts): # asserts that self is specified if not opts.self: die("Error: need to specify your own key using the --self param") def ensure_name_specified(opts): # asserts that name is specified if not opts.name: die("Error: need to specify a key to operate on using the --name param") def ensure_recipient_specified(opts): # asserts that recipient is specified if not opts.recipient: die("Error: need to specify a recipient to "