Make the tool nicer
This commit is contained in:
parent
2abf5ccf6f
commit
cb5b9e6561
12
tool.py
12
tool.py
|
@ -16,7 +16,6 @@ def enc_pk(pk, plaintext):
|
||||||
raw_shared_secret = compact_ecdh_curve25519.ecdh(pk, ephemeral_sk)
|
raw_shared_secret = compact_ecdh_curve25519.ecdh(pk, ephemeral_sk)
|
||||||
shared_secret = compact_xchapoly.hchacha20(raw_shared_secret, b'\x00'*24)
|
shared_secret = compact_xchapoly.hchacha20(raw_shared_secret, b'\x00'*24)
|
||||||
nonce = os.urandom(24)
|
nonce = os.urandom(24)
|
||||||
print(shared_secret, nonce, plaintext)#debg
|
|
||||||
return ephemeral_pk + nonce + compact_xchapoly.enc(b'', shared_secret, nonce, plaintext)
|
return ephemeral_pk + nonce + compact_xchapoly.enc(b'', shared_secret, nonce, plaintext)
|
||||||
|
|
||||||
def dec_sk(sk, ciphertext):
|
def dec_sk(sk, ciphertext):
|
||||||
|
@ -43,10 +42,17 @@ if __name__ == '__main__':
|
||||||
print('pubkey:', pk.hex())
|
print('pubkey:', pk.hex())
|
||||||
elif sys.argv[1] == '-E':
|
elif sys.argv[1] == '-E':
|
||||||
pk = bytes.fromhex(sys.argv[2])
|
pk = bytes.fromhex(sys.argv[2])
|
||||||
print(enc_pk(pk, input().encode('utf-8')).hex())
|
plaintext = sys.stdin.buffer.read()
|
||||||
|
sys.stdout.buffer.write(enc_pk(pk, plaintext))
|
||||||
elif sys.argv[1] == '-D':
|
elif sys.argv[1] == '-D':
|
||||||
with open(sys.argv[2], 'rb') as f:
|
with open(sys.argv[2], 'rb') as f:
|
||||||
sk = f.read()
|
sk = f.read()
|
||||||
print(dec_sk(sk, bytes.fromhex(input())))
|
ciphertext = sys.stdin.buffer.read()
|
||||||
|
plaintext = dec_sk(sk, ciphertext)
|
||||||
|
if plaintext is None:
|
||||||
|
print('%s: Error: Ciphertext authentication failure' % os.path.basename(sys.argv[0]), file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
sys.stdout.buffer.write(plaintext)
|
||||||
else:
|
else:
|
||||||
usage()
|
usage()
|
||||||
|
|
Loading…
Reference in New Issue