コード例 #1
0
ファイル: newhope.py プロジェクト: scottwn/PyNewHope
def sharedb(received):
    global b_key
    (pka, seed) = received
    a_coeffs = gen_a(seed)
    s_coeffs = get_noise()
    e_coeffs = get_noise()
    b_coeffs = poly.pointwise(a_coeffs, s_coeffs)
    b_coeffs = poly.add(b_coeffs, e_coeffs)
    v_coeffs = poly.pointwise(pka, s_coeffs)
    v_coeffs = poly.invntt(v_coeffs)
    e_prime = poly.get_noise()
    v_coeffs = poly.add(v_coeffs, e_prime)
    c_coeffs = poly.helprec(v_coeffs)
    b_key = poly.rec(v_coeffs, c_coeffs)
    return (c_coeffs, b_coeffs)
コード例 #2
0
ファイル: newhope.py プロジェクト: scottwn/PyNewHope
def shareda(received):
    global a_key, s_hat
    (c_coeffs, b_coeffs) = received
    v_coeffs = poly.pointwise(s_hat, b_coeffs)
    v_coeffs = poly.invntt(v_coeffs)
    a_key = poly.rec(v_coeffs, c_coeffs)
    return
コード例 #3
0
ファイル: newhope.py プロジェクト: scottwn/PyNewHope
def keygen(verbose = False):
    global s_hat
    seed = os.urandom(params.NEWHOPE_SEEDBYTES)
    a_coeffs = gen_a(seed)
    s_coeffs = get_noise()
    s_hat = s_coeffs
    e_coeffs = get_noise()
    r_coeffs = poly.pointwise(s_coeffs, a_coeffs)
    p_coeffs = poly.add(e_coeffs, r_coeffs)
    return (p_coeffs, seed)
コード例 #4
0
def send_u(received):
    global b_key
    #getting s', e' and e'' with phi 16
    sprime_coeffs = get_noise()
    eprime_coeffs = get_noise()
    escndprime_coeffs = get_noise()

    #parse the seed to obtain a
    (pkb, seed) = received
    a_coeffs = parse(seed)

    #computing u<-as'+e'
    b_coeffs = poly.pointwise(a_coeffs, sprime_coeffs)
    u_coeffs = poly.add(b_coeffs, eprime_coeffs)

    #computing v<-bs'+e''
    v_coeffs = poly.pointwise(pkb, sprime_coeffs)
    v_coeffs = poly.add(v_coeffs, escndprime_coeffs)
    b_key = v_coeffs
    return u_coeffs
コード例 #5
0
def send_b_seed(verbose=False):
    global s_hat
    #generating the seed with 256 bits
    seed = os.urandom(params.NEWHOPE_SEEDBYTES)

    #parse the seed to obtain a
    a_coeffs = parse(seed)

    #getting s and e with phi 16
    s_coeffs = get_noise()
    s_hat = s_coeffs
    e_coeffs = get_noise()

    #computing b<- a.s + e
    r_coeffs = poly.pointwise(s_coeffs, a_coeffs)
    b_coeffs = poly.add(e_coeffs, r_coeffs)

    #b and seed are sent to Bob
    return (b_coeffs, seed)
コード例 #6
0
def compute_vprime(received):
    global a_key, s_hat
    u_coeffs = received
    vprime_coeffs = poly.pointwise(s_hat, u_coeffs)
    a_key = vprime_coeffs
    return