コード例 #1
0
    def test_sign_verify(self):
        for i in range(10):
            msg = utils.rand_bytes(1 + i * 512)
            key = ZilKey.generate_new()

            signature1 = schnorr.sign(msg, key.keypair_bytes.private)
            signature2 = schnorr.sign(msg, key.keypair_bytes.private)

            assert signature1 != signature2
            assert schnorr.verify(msg, signature1, key.keypair_bytes.public)
            assert schnorr.verify(msg, signature2, key.keypair_bytes.public)
コード例 #2
0
ファイル: TestDSESU.py プロジェクト: JHUISI/auto-tools
def verify(suPK, m, sig):
    sig1, sig2, spk = sig
    pk, ppk = suPK
    varM = (spk, m)
    varM1 = DeriveKey(varM)
    if ( ( (( (dse09sig.verify(pk, varM1, sig1)) == (True) )) and (( (schnorr.verify(ppk, spk, sig1, sig2)) == (True) )) ) ):
        output = True
        return output
    else:
        return False
コード例 #3
0
def verify(suPK, m, sig):
    sig1, sig2, spk = sig
    pk, ppk = suPK
    varM = (spk, m)
    varM1 = DeriveKey(varM)
    if (((((dse09sig.verify(pk, varM1, sig1)) == (True)))
         and (((schnorr.verify(ppk, spk, sig1, sig2)) == (True))))):
        output = True
        return output
    else:
        return False
コード例 #4
0
def small_test():
    # bank generates Schnorr key pair
    priv, Q = ec.nistp256.generate_key()

    # step 1: bank prepares a Schnorr nonce and commits to it
    # bank keeps: k 
    # bank -> user: R
    k, R = bank_init(ec.nistp256)

    # step 2: user prepares blinding factors
    # user keeps:  (a, rp) 
    # user -> bank: e
    msg = 'hello world'
    a, rp, ep, e = user_blind(ec.nistp256, H, Q, msg, R)

    # step 3: bank actually signs
    # bank -> user: s
    s = bank_sign(ec.nistp256, k, e, priv)

    # step 4: user computes, verifies and releases signature (rp, sp)
    sp = user_unblind(ec.nistp256, s, a)

    print "blinded sig (r,s) ", (rp, sp)
    verify(ec.nistp256, H, Q, msg, (rp, sp))
コード例 #5
0
    def test_vectors(self):
        vectors = json.load(open(os.path.join(cur_dir, "schnorr.fixtures.json")))
        for vector in random.choices(vectors, k=100):
            for key in vector:
                if isinstance(vector[key], bytes):
                    continue
                vector[key] = h2b(vector[key])

            sign = schnorr.sign_with_k(
                vector["msg"],
                vector["priv"],
                b2i(vector["k"])
            )
            assert not not sign

            r, s = schnorr.decode_signature(sign)
            assert r == b2i(vector["r"])
            assert s == b2i(vector["s"])

            sign = schnorr.encode_signature(r, s)

            assert schnorr.verify(vector["msg"], sign, vector["pub"])
コード例 #6
0
#!/usr/bin/env python3

from charm.toolbox.pairinggroup import PairingGroup, ZR, G1, G2, GT, pair

from schnorr import step_1 as verify
from utils import jencode, jdecode


if __name__ == "__main__":
    # Read {g, pk}
    v = jdecode(input("pub: "))
    v.update(jdecode(input("m: ")))
    v.update(jdecode(input("sign: ")))

    print(verify(v))