예제 #1
0
파일: bls.py 프로젝트: Hellblazer/core
def verify(SIG, m, W):
    HM = BLS_H(m)
    D = ECp()
    D.fromBytes(SIG)
    if D.isinf():
        return False
    if not (curve.r * D).isinf():
        return False
    D = -D

    PK = ECp2()
    PK.fromBytes(W)

    # Use new multi-pairing mechanism
    r = pair.initmp()
    pair.another_pc(r, G2_TAB, D)
    pair.another(r, PK, HM)
    v = pair.miller(r)

    #.. or alternatively
    #    G=ecp2.generator()
    #    if G.isinf() :
    #        return False
    #    v = pair.double_ate(G, D, PK, HM)

    v = pair.fexp(v)
    if v.isone():
        return True
    return False
예제 #2
0
파일: ecdh.py 프로젝트: stjordanis/core-8
def ECP_SvdpDH(S, W):
    s = big.from_bytes(S)
    WP = ECp()
    if not WP.fromBytes(W):
        return ECDH_ERROR

    r = curve.r
    s %= r
    WP = s * WP

    if WP.isinf():
        return ECDH_ERROR
    x = WP.getx()

    K = big.to_bytes(x)

    return K
예제 #3
0
파일: ecdh.py 프로젝트: stjordanis/core-8
def ECP_PublicKeyValidate(W):
    r = curve.r
    p = curve.p

    WP = ECp()
    if not WP.fromBytes(W):
        return ECDH_INVALID_PUBLIC_KEY

    nb = p.bit_length()
    k = 1
    k = k << (nb + 4) // 2
    k += p
    k //= r
    while k % 2 == 0:
        WP.dbl()
        k //= 2
    if k != 1:
        WP = k * WP
    if WP.isinf():
        return ECDH_INVALID_PUBLIC_KEY
    return 0