Example #1
0
def main():
    print_dot()
    test_wots_kat(m1, pk1, sig1, adr1, seed1, adr1p)
    test_wots_kat(m2, pk2, sig2, adr2, seed2, adr2p)
    test_wots_self()
    test_wots_self()
    exit(0)
Example #2
0
def main():
    file = open('tests/test_vectors/kyber_test_vectors.json')
    kyber_test_vectors = json.load(file)
    print_dot()
    for i in range(len(kyber_test_vectors)):
        kyber_k = kyber_test_vectors[i]['kyber_k']
        kyber_eta = kyber_test_vectors[i]['kyber_eta']
        keypaircoins = bytes.from_hex(kyber_test_vectors[i]['keypaircoins'])
        coins = bytes.from_hex(kyber_test_vectors[i]['coins'])
        msgcoins = bytes.from_hex(kyber_test_vectors[i]['msgcoins'])
        pk_expected = bytes.from_hex(kyber_test_vectors[i]['pk_expected'])
        sk_expected = bytes.from_hex(kyber_test_vectors[i]['sk_expected'])
        ct_expected = bytes.from_hex(kyber_test_vectors[i]['ct_expected'])
        ss_expected = bytes.from_hex(kyber_test_vectors[i]['ss_expected'])

        (crypto_kem_keypair, crypto_kem_enc,
         crypto_kem_dec) = Kyber(kyber_k, kyber_eta)
        pk, sk = crypto_kem_keypair(keypaircoins, coins)
        ct, ss1 = crypto_kem_enc(pk, msgcoins)
        ss2 = crypto_kem_dec(ct, sk)

        #We do not check (sk == sk_expected) since we use an INV-NTT representation for sk
        if (ss1 == ss2 and ss1 == ss_expected and ct == ct_expected
                and pk == pk_expected):
            print("Kyber Test " + str(i) + " successful!")
        else:
            print("Kyber Test failed!")
            print("Computed shared secret 1: " + str(ss1))
            print("Computed shared secret 2: " + str(ss2))
            print("Expected shared secret: " + str(ss_expected))
            exit(1)
    exit(0)
Example #3
0
def test_wots_kat(m: digest_t, pk: pk_t, sig: sig_t, adr: address_t,
                  seed: seed_t, adrp: address_t):
    pk2, adr2 = wots_verify(pk, m, sig, adr, seed)
    if adr2 != adrp:
        print("adr is wrong after verification")
        print("got: " + str(adr2))
        print("expected: " + str(adrp))
        exit(1)
    verify_pk(pk, pk2)
Example #4
0
def verify_pk(pk1, pk2):
    verified = True
    if len(pk1) != len(pk2):
        print("pk2 has wrong length")
        verified = False
    if verified and pk1 != pk2:
        print("pks aren't equal: got " + str(pk1) + " expected " + str(pk2))
        verified = False
    if verified:
        print("Signature verified")
    else:
        print("Verification error :(")
        exit(1)
Example #5
0
def main():
    file = open('tests/test_vectors/frodo_test_vectors.json')
    frodo_test_vectors = json.load(file)
    print_dot()
    for i in range(len(frodo_test_vectors)):
        frodo_kem = frodo_test_vectors[i]['frodo_kem']
        gen_a = frodo_test_vectors[i]['gen_a']
        keypaircoins = bytes.from_hex(frodo_test_vectors[i]['keypaircoins'])
        enccoins = bytes.from_hex(frodo_test_vectors[i]['enccoins'])
        pk_expected = bytes.from_hex(frodo_test_vectors[i]['pk_expected'])
        ct_expected = bytes.from_hex(frodo_test_vectors[i]['ct_expected'])
        ss_expected = bytes.from_hex(frodo_test_vectors[i]['ss_expected'])

        (crypto_kem_keypair, crypto_kem_enc,
         crypto_kem_dec) = Frodo(frodo_kem, gen_a)
        pk, sk = crypto_kem_keypair(keypaircoins)
        ct, ss1 = crypto_kem_enc(enccoins, pk)
        ss2 = crypto_kem_dec(ct, sk)

        if (ss1 == ss2 and ss1 == ss_expected and pk == pk_expected
                and ct == ct_expected):
            print("Frodo Test " + str(i) + " successful!")
        else:
            print("Frodo Test failed!")
            if (ss1 != ss_expected or ss1 != ss2):
                print("Computed shared secret 1: " + str(ss1))
                print("Computed shared secret 2: " + str(ss2))
                print("Expected shared secret: " + str(ss_expected))
            if (pk != pk_expected):
                print("Computed public key: " + str(pk))
                print("Expected public key: " + str(pk_expected))
            if (ct != ct_expected):
                print("Computed cipher text: " + str(ct))
                print("Expected cipher text: " + str(ct_expected))
            exit(1)
    exit(0)
Example #6
0
def main():
    print_dot()
    test_xmss_self()
    exit(0)