Ejemplo n.º 1
0
def test_P521_sign_verify():
    # Try ECDSA on our own signature with P-521
    _sg = ("9ce982c91af08a21d405f96abd6204588bb0ef1c8b78305b06f36a12d1914cae9d"
           "ce6a1f1a0b4c42b067667c457c3e90e56f34cff0116bbd350d27882dd6e47997c9"
           "44dcead9cb945f7c691078c1b533960a55f93d241970a1fdf4441107d8bc8af5aa"
           "8e088ea3aa82c7f3286e815dbb85d5cfae0aeeeb093468cb55201eeffb")
    msg = msg = binascii.unhexlify(_sg)

    (priv, pub) = P521.key_pair()
    h = int(hashlib.new("SHA512", msg).hexdigest(), 16)
    sig = P521.sign(h, priv)
    assert P521.verify(h, sig, pub)
Ejemplo n.º 2
0
def test_P521_sign_verify():
    # Try ECDSA on our own signature with P-521
    _sg = ("9ce982c91af08a21d405f96abd6204588bb0ef1c8b78305b06f36a12d1914cae9d"
           "ce6a1f1a0b4c42b067667c457c3e90e56f34cff0116bbd350d27882dd6e47997c9"
           "44dcead9cb945f7c691078c1b533960a55f93d241970a1fdf4441107d8bc8af5aa"
           "8e088ea3aa82c7f3286e815dbb85d5cfae0aeeeb093468cb55201eeffb")
    msg = msg = binascii.unhexlify(_sg)

    (priv, pub) = P521.key_pair()
    h = int(hashlib.new("SHA512", msg).hexdigest(), 16)
    sig = P521.sign(h, priv)
    assert P521.verify(h, sig, pub)
Ejemplo n.º 3
0
def test_P521_verify_with_nist():
    # Try ECDSA with one of the NIST P-521 test vectors (should pass)
    _sg = ("f69417bead3b1e208c4c99236bf84474a00de7f0b9dd23f991b6b60ef0fb3c6207"
           "3a5a7abb1ef69dbbd8cf61e64200ca086dfd645b641e8d02397782da92d3542fbd"
           "df6349ac0b48b1b1d69fe462d1bb492f34dd40d137163843ac11bd099df719212c"
           "160cbebcb2ab6f3525e64846c887e1b52b52eced9447a3d31938593a87")
    msg = binascii.unhexlify(_sg)
    Qx = 0x153eb2be05438e5c1effb41b413efc2843b927cbf19f0bc9cc14b693eee26394a0d8880dc946a06656bcd09871544a5f15c7a1fa68e00cdc728c7cfb9c448034867
    Qy = 0x143ae8eecbce8fcf6b16e6159b2970a9ceb32c17c1d878c09317311b7519ed5ece3374e7929f338ddd0ec0522d81f2fa4fa47033ef0c0872dc049bb89233eef9bc1
    R = 0x0dd633947446d0d51a96a0173c01125858abb2bece670af922a92dedcec067136c1fa92e5fa73d7116ac9c1a42b9cb642e4ac19310b049e48c53011ffc6e7461c36
    S = 0x0efbdc6a414bb8d663bb5cdb7c586bccfe7589049076f98cee82cdb5d203fddb2e0ffb77954959dfa5ed0de850e42a86f5a63c5a6592e9b9b8bd1b40557b9cd0cc0

    h = int(hashlib.new("SHA512", msg).hexdigest(), 16)
    Q = (Qx, Qy)
    sig = P521.int2bytes(R) + P521.int2bytes(S)
    assert P521.verify(h, sig, Q)
Ejemplo n.º 4
0
def test_P521_negative_verify_with_nist():
    # Try ECDSA with one of the NIST P-521 test vectors (should fail)
    _sg = ("a0732a605c785a2cc9a3ff84cbaf29175040f7a0cc35f4ea8eeff267c1f92f06f4"
           "6d3b35437195185d322cbd775fd24741e86ee9236ba5b374a2ac29803554d715fa"
           "4656ac31778f103f88d68434dd2013d4c4e9848a11198b390c3d600d712893513e"
           "179cd3d31fb06c6e2a1016fb96ffd970b1489e36a556ab3b537eb29dff")
    msg = binascii.unhexlify(_sg)
    Qx = 0x12a593f568ca2571e543e00066ecd3a3272a57e1c94fe311e5df96afc1b792e5862720fc730e62052bbf3e118d3a078f0144fc00c9d8baaaa8298ff63981d09d911
    Qy = 0x17cea5ae75a74100ee03cdf2468393eef55ddabfe8fd5718e88903eb9fd241e8cbf9c68ae16f4a1db26c6352afcb1894a9812da6d32cb862021c86cd8aa483afc26
    R = 0x1aac7692baf3aa94a97907307010895efc1337cdd686f9ef2fd8404796a74701e55b03ceef41f3e6f50a0eeea11869c4789a3e8ab5b77324961d081e1a3377ccc91
    S = 0x009c1e7d93d056b5a97759458d58c49134a45071854b8a6b8272f9fe7e78e1f3d8097e8a6e731f7ab4851eb26d5aa4fdadba6296dc7af835fe3d1b6dba4b031d5f3

    h = int(hashlib.new("SHA512", msg).hexdigest(), 16)
    Q = (Qx, Qy)
    sig = P521.int2bytes(R) + P521.int2bytes(S)
    assert not P521.verify(h, sig, Q)
Ejemplo n.º 5
0
def test_P521_verify_with_nist():
    # Try ECDSA with one of the NIST P-521 test vectors (should pass)
    _sg = ("f69417bead3b1e208c4c99236bf84474a00de7f0b9dd23f991b6b60ef0fb3c6207"
           "3a5a7abb1ef69dbbd8cf61e64200ca086dfd645b641e8d02397782da92d3542fbd"
           "df6349ac0b48b1b1d69fe462d1bb492f34dd40d137163843ac11bd099df719212c"
           "160cbebcb2ab6f3525e64846c887e1b52b52eced9447a3d31938593a87")
    msg = binascii.unhexlify(_sg)
    Qx = 0x153eb2be05438e5c1effb41b413efc2843b927cbf19f0bc9cc14b693eee26394a0d8880dc946a06656bcd09871544a5f15c7a1fa68e00cdc728c7cfb9c448034867
    Qy = 0x143ae8eecbce8fcf6b16e6159b2970a9ceb32c17c1d878c09317311b7519ed5ece3374e7929f338ddd0ec0522d81f2fa4fa47033ef0c0872dc049bb89233eef9bc1
    R = 0x0dd633947446d0d51a96a0173c01125858abb2bece670af922a92dedcec067136c1fa92e5fa73d7116ac9c1a42b9cb642e4ac19310b049e48c53011ffc6e7461c36
    S = 0x0efbdc6a414bb8d663bb5cdb7c586bccfe7589049076f98cee82cdb5d203fddb2e0ffb77954959dfa5ed0de850e42a86f5a63c5a6592e9b9b8bd1b40557b9cd0cc0

    h = int(hashlib.new("SHA512", msg).hexdigest(), 16)
    Q = (Qx, Qy)
    sig = P521.int2bytes(R) + P521.int2bytes(S)
    assert P521.verify(h, sig, Q)
Ejemplo n.º 6
0
def test_P521_negative_verify_with_nist():
    # Try ECDSA with one of the NIST P-521 test vectors (should fail)
    _sg = ("a0732a605c785a2cc9a3ff84cbaf29175040f7a0cc35f4ea8eeff267c1f92f06f4"
           "6d3b35437195185d322cbd775fd24741e86ee9236ba5b374a2ac29803554d715fa"
           "4656ac31778f103f88d68434dd2013d4c4e9848a11198b390c3d600d712893513e"
           "179cd3d31fb06c6e2a1016fb96ffd970b1489e36a556ab3b537eb29dff")
    msg = binascii.unhexlify(_sg)
    Qx = 0x12a593f568ca2571e543e00066ecd3a3272a57e1c94fe311e5df96afc1b792e5862720fc730e62052bbf3e118d3a078f0144fc00c9d8baaaa8298ff63981d09d911
    Qy = 0x17cea5ae75a74100ee03cdf2468393eef55ddabfe8fd5718e88903eb9fd241e8cbf9c68ae16f4a1db26c6352afcb1894a9812da6d32cb862021c86cd8aa483afc26
    R = 0x1aac7692baf3aa94a97907307010895efc1337cdd686f9ef2fd8404796a74701e55b03ceef41f3e6f50a0eeea11869c4789a3e8ab5b77324961d081e1a3377ccc91
    S = 0x009c1e7d93d056b5a97759458d58c49134a45071854b8a6b8272f9fe7e78e1f3d8097e8a6e731f7ab4851eb26d5aa4fdadba6296dc7af835fe3d1b6dba4b031d5f3

    h = int(hashlib.new("SHA512", msg).hexdigest(), 16)
    Q = (Qx, Qy)
    sig = P521.int2bytes(R) + P521.int2bytes(S)
    assert not P521.verify(h, sig, Q)