-
Notifications
You must be signed in to change notification settings - Fork 7
/
fishwrap.py
executable file
·54 lines (49 loc) · 1.95 KB
/
fishwrap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
#################################################################################
# 20201123: wrapper for weechat fish.py
#################################################################################
# See original fish.py for Copyrights, license and info:
# https://github.com/weechat/scripts/blob/master/python/fish.py
# Does not call pack/unpack defs but re-uses relevant dh code directly:
# - vars: p_dh1080, q_dh1080
# - class: DH1080Ctx
# - defs: bytes2int, int2bytes dh_validate_public, dh1080_b64encode
#################################################################################
import sys
# dont load weechat module
sys.modules["weechat"] = ""
import fish as wcf
# output : my public and private key
if ((len(sys.argv) > 1) and (sys.argv[1] == "DH1080gen")):
fish_DH1080ctx = {}
targetl = "irc_nick"
fish_DH1080ctx[targetl] = wcf.DH1080Ctx()
try:
if not 1 < fish_DH1080ctx[targetl].public < wcf.p_dh1080:
sys.exit(1)
if not wcf.dh_validate_public(fish_DH1080ctx[targetl].public, wcf.q_dh1080, wcf.p_dh1080):
pass
b64_private=wcf.dh1080_b64encode(wcf.int2bytes(fish_DH1080ctx[targetl].private))
b64_public=wcf.dh1080_b64encode(wcf.int2bytes(fish_DH1080ctx[targetl].public))
print(b64_private, b64_public)
del fish_DH1080ctx[targetl]
del b64_private
except:
sys.exit(1)
# input : argv2 = my private key argv3 = someones public key
# output : shared secret
if ((len(sys.argv) > 3) and (sys.argv[1] == "DH1080comp")):
try:
private = wcf.bytes2int(wcf.dh1080_b64decode(sys.argv[2]))
public = wcf.bytes2int(wcf.dh1080_b64decode(sys.argv[3]))
if not 1 < public < wcf.p_dh1080:
sys.exit(1)
if not wcf.dh_validate_public(public, wcf.q_dh1080, wcf.p_dh1080):
pass
secret = pow(public, private, wcf.p_dh1080)
del private
print(wcf.dh1080_b64encode(wcf.sha256(wcf.int2bytes(secret))))
del secret
except:
sys.exit(1)
#print('DEBUG: globals')