Exemplo n.º 1
0
def test_not_enabled():
    # TODO: test broken as the compiled lib determines which algorithms are supported and enabled
    for alg_name in oqs.get_supported_KEM_mechanisms():
        if alg_name not in oqs.get_enabled_KEM_mechanisms():
            # found a non-enabled but supported alg
            try:
                kem = oqs.KeyEncapsulation(alg_name)
                raise AssertionError(
                    "oqs.MechanismNotEnabledError was not raised.")
            except oqs.MechanismNotEnabledError:
                pass
            except E:
                raise AssertionError("An unexpected exception was raised. " +
                                     E)
Exemplo n.º 2
0
# key encapsulation Python example

from pprint import pprint
import oqs

#######################################################################
# KEM example
#######################################################################

kems = oqs.get_enabled_KEM_mechanisms()

print("Enabled KEM mechanisms:")
pprint(kems, compact="True")

# create client and server with default KEM mechanisms
kemalg = "DEFAULT"
with oqs.KeyEncapsulation(kemalg) as client:
    with oqs.KeyEncapsulation(kemalg) as server:
        print("\nKey encapsulation details:")
        pprint(client.details)

        # client generates its keypair
        public_key = client.generate_keypair()
        # optionally, the secret key can be obtained by calling export_secret_key()
        # and the client can later be re-instantiated with the key pair:
        # secret_key = client.export_secret_key()
        # store key pair, wait... (session resumption):
        # client = oqs.KeyEncapsulation(kemalg, secret_key)

        # the server encapsulates its secret using the client's public key
        ciphertext, shared_secret_server = server.encap_secret(public_key)
Exemplo n.º 3
0
def test_correctness():
    for alg_name in oqs.get_enabled_KEM_mechanisms():
        yield (check_correctness, alg_name)
Exemplo n.º 4
0
def test_wrong_secret_key():
    for alg_name in oqs.get_enabled_KEM_mechanisms():
        yield (check_wrong_secret_key, alg_name)
Exemplo n.º 5
0
def test_wrong_ciphertext():
    for alg_name in oqs.get_enabled_KEM_mechanisms():
        yield (check_wrong_ciphertext, alg_name)
Exemplo n.º 6
0
def test_wrong_ciphertext():
    for alg_name in oqs.get_enabled_KEM_mechanisms():
        if any(item in alg_name for item in disabled_KEM_patterns):
            continue
        yield check_wrong_ciphertext, alg_name
Exemplo n.º 7
0
def test_correctness():
    for alg_name in oqs.get_enabled_KEM_mechanisms():
        if any(item in alg_name for item in disabled_KEM_patterns):
            continue
        yield check_correctness, alg_name