Exemplo n.º 1
0
from pycryptopp import _import_my_names

# These initializations to None are just to pacify pyflakes, which
# doesn't understand that we have to do some funky import trickery
# below in _import_my_names() in order to get sensible namespaces.
AES = None
Error = None

_import_my_names(globals(), "aes_")

del _import_my_names


def start_up_self_test():
    """
    This is a quick test intended to detect major errors such as the library being
    miscompiled and segfaulting or returning incorrect answers.  We've had problems
    of that kind many times, thus justifying running this self-test on import.
    This idea was suggested to me by the second edition of "Practical
    Cryptography" by Ferguson, Schneier, and Kohno.
    These tests were copied from pycryptopp/test/test_aes.py on 2009-10-30.
    """
    enc0 = "dc95c078a2408989ad48a21492842087530f8afbc74536b9a963b4f1c4cb738b"
    from binascii import a2b_hex, b2a_hex

    cryptor = AES(key="\x00" * 32)
    ct = cryptor.process("\x00" * 32)
    if enc0 != b2a_hex(ct):
        raise Error("pycryptopp failed startup self-test. Please run pycryptopp unit tests.")

    cryptor = AES(key="\x00" * 32)
Exemplo n.º 2
0
from pycryptopp import _import_my_names

_import_my_names(globals(), "rsa_")

del _import_my_names
Exemplo n.º 3
0
from pycryptopp import _import_my_names

# These initializations to None are just to pacify pyflakes, which
# doesn't understand that we have to do some funky import trickery
# below in _import_my_names() in order to get sensible namespaces.
SHA256=None
Error=None

_import_my_names(globals(), "sha256_")

del _import_my_names

def start_up_self_test():
    """
    This is a quick test intended to detect major errors such as the library being
    miscompiled and segfaulting or returning incorrect answers.  We've had problems
    of that kind many times, thus justifying running this self-test on import.
    This idea was suggested to me by the second edition of "Practical
    Cryptography" by Ferguson, Schneier, and Kohno.
    This test was copied from pycryptopp/test/test_sha256.py on 2010-09-04.

    This test takes up to 1.5 milliseconds on a VirtualBox instance on
    my Macbook Pro (fast 64-bit Intel dual-core).

    Test that updating a hasher with various sized inputs yields
    the expected answer. This is somewhat redundant with
    test_chunksize(), but that's okay. This one exercises some
    slightly different situations (such as finalizing a hash after
    different length inputs.) This one is recursive so that there
    is a single fixed result that we expect.
    """
Exemplo n.º 4
0
from pycryptopp import _import_my_names

# These initializations to None are just to pacify pyflakes, which
# doesn't understand that we have to do some funky import trickery
# below in _import_my_names() in order to get sensible namespaces.
AES = None
Error = None

_import_my_names(globals(), "aes_")

del _import_my_names


def start_up_self_test():
    """
    This is a quick test intended to detect major errors such as the library being
    miscompiled and segfaulting or returning incorrect answers.  We've had problems
    of that kind many times, thus justifying running this self-test on import.
    This idea was suggested to me by the second edition of "Practical
    Cryptography" by Ferguson, Schneier, and Kohno.
    These tests were copied from pycryptopp/test/test_aes.py on 2009-10-30.
    """
    enc0 = "dc95c078a2408989ad48a21492842087530f8afbc74536b9a963b4f1c4cb738b"
    from binascii import a2b_hex, b2a_hex

    cryptor = AES(key="\x00" * 32)
    ct = cryptor.process("\x00" * 32)
    if enc0 != b2a_hex(ct):
        raise Error(
            "pycryptopp failed startup self-test. Please run pycryptopp unit tests."
        )
Exemplo n.º 5
0
from pycryptopp import _import_my_names

_import_my_names(globals(), "xsalsa20_")

del _import_my_names


def selftest():
    # pyflakes doesn't know that XSalsa20 is made available above
    XSalsa20 = globals()["XSalsa20"]
    from binascii import unhexlify

    key = unhexlify("ad5eadf7163b0d36e44c126037a03419" "fcda2b3a1bb4ab064b6070e61b0fa5ca")
    iv = unhexlify("6a059adb8c7d4acb1c537767d541506f" "c5ef0ace9a2a65bd")
    encrypted = unhexlify(
        "23a8ed0475150e988c545b11e3660de7"
        "8bf88e6628c4c99ba36330c05cb919e7"
        "901295db479c9a8a0401d5e040b8919b"
        "7d64b2f728c59703c3"
    )
    p = XSalsa20(key, iv)
    decrypted = p.process(encrypted)
    expected = "crypto libraries should always test themselves at powerup"
    assert decrypted == expected

    p = XSalsa20(key, iv)
    decrypted = ""
    offset = 0
    for chunksize in [13, 11, 1, 2, 3, 20, 999]:
        decrypted += p.process(encrypted[offset : offset + chunksize])
        offset += chunksize
Exemplo n.º 6
0
from pycryptopp import _import_my_names

_import_my_names(globals(), "ecdsa_")

del _import_my_names
Exemplo n.º 7
0
from pycryptopp import _import_my_names

_import_my_names(globals(), "xsalsa20_")

del _import_my_names


def selftest():
    # pyflakes doesn't know that XSalsa20 is made available above
    XSalsa20 = globals()["XSalsa20"]
    from binascii import unhexlify
    key = unhexlify("ad5eadf7163b0d36e44c126037a03419"
                    "fcda2b3a1bb4ab064b6070e61b0fa5ca")
    iv = unhexlify("6a059adb8c7d4acb1c537767d541506f" "c5ef0ace9a2a65bd")
    encrypted = unhexlify("23a8ed0475150e988c545b11e3660de7"
                          "8bf88e6628c4c99ba36330c05cb919e7"
                          "901295db479c9a8a0401d5e040b8919b"
                          "7d64b2f728c59703c3")
    p = XSalsa20(key, iv)
    decrypted = p.process(encrypted)
    expected = "crypto libraries should always test themselves at powerup"
    assert decrypted == expected

    p = XSalsa20(key, iv)
    decrypted = ""
    offset = 0
    for chunksize in [13, 11, 1, 2, 3, 20, 999]:
        decrypted += p.process(encrypted[offset:offset + chunksize])
        offset += chunksize
    assert decrypted == expected
Exemplo n.º 8
0
from pycryptopp import _import_my_names

# These initializations to None are just to pacify pyflakes, which
# doesn't understand that we have to do some funky import trickery
# below in _import_my_names() in order to get sensible namespaces.
SHA256 = None
Error = None

_import_my_names(globals(), "sha256_")

del _import_my_names


def start_up_self_test():
    """
    This is a quick test intended to detect major errors such as the library being
    miscompiled and segfaulting or returning incorrect answers.  We've had problems
    of that kind many times, thus justifying running this self-test on import.
    This idea was suggested to me by the second edition of "Practical
    Cryptography" by Ferguson, Schneier, and Kohno.
    This test was copied from pycryptopp/test/test_sha256.py on 2010-09-04.

    This test takes up to 1.5 milliseconds on a VirtualBox instance on
    my Macbook Pro (fast 64-bit Intel dual-core).

    Test that updating a hasher with various sized inputs yields
    the expected answer. This is somewhat redundant with
    test_chunksize(), but that's okay. This one exercises some
    slightly different situations (such as finalizing a hash after
    different length inputs.) This one is recursive so that there
    is a single fixed result that we expect.