#!/usr/bin/env python3

import binascii
import hashlib
import socket
import sys
import os

l = 1152
lev=2
pos=0

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('127.0.0.1', 584))

datalist = [
    int.to_bytes(lev, 1, "little"),   # level
    int.to_bytes(pos, 2, "little"),   # position
    l * b'\x00'
]

packet = b''
packet += b'\xf0\x00' # static key
for data in datalist:
    packet += int.to_bytes(len(data), 2, "big")
    packet += data


# receive packet
s.send(packet)
data = s.recv(4096)
data = binascii.hexlify(data[11:43]).decode()

# compute hash
content = open('/etc/pqconnect/keys/mceliece_pk', 'rb').read()[0:1152]
h = hashlib.shake_256(content).hexdigest(32)

assert(h == data)
