コード例 #1
0
def v2_verify(sm, pk, f=None):
    h = V2_PUBLIC
    sm, fi = _unpack_msg(h, sm, f)
    siglen = sodium.crypto_sign_BYTES
    m = sm[:-siglen]
    s = sm[-siglen:]
    m2 = pae([h, m, fi])
    with _translate_exc(
            naclexc.BadSignatureError,
            pexc.BadSignatureError,
            msg=BAD_SIGNATURE_ERR,
            truncate=True,
    ):
        sodium.crypto_sign_open(s + m2, pk)
    return m, fi
コード例 #2
0
def test_sign():
    seed = b"\x00" * c.crypto_sign_SEEDBYTES
    pubkey, secretkey = c.crypto_sign_seed_keypair(seed)
    assert len(pubkey) == c.crypto_sign_PUBLICKEYBYTES
    assert len(secretkey) == c.crypto_sign_SECRETKEYBYTES

    pubkey, secretkey = c.crypto_sign_keypair()
    assert len(pubkey) == c.crypto_sign_PUBLICKEYBYTES
    assert len(secretkey) == c.crypto_sign_SECRETKEYBYTES

    msg = b"message"
    sigmsg = c.crypto_sign(msg, secretkey)
    assert len(sigmsg) == len(msg) + c.crypto_sign_BYTES

    msg2 = c.crypto_sign_open(sigmsg, pubkey)
    assert msg2 == msg
コード例 #3
0
ファイル: test_bindings.py プロジェクト: xueyumusic/pynacl
def test_sign():
    seed = b"\x00" * c.crypto_sign_SEEDBYTES
    pubkey, secretkey = c.crypto_sign_seed_keypair(seed)
    assert len(pubkey) == c.crypto_sign_PUBLICKEYBYTES
    assert len(secretkey) == c.crypto_sign_SECRETKEYBYTES

    pubkey, secretkey = c.crypto_sign_keypair()
    assert len(pubkey) == c.crypto_sign_PUBLICKEYBYTES
    assert len(secretkey) == c.crypto_sign_SECRETKEYBYTES

    msg = b"message"
    sigmsg = c.crypto_sign(msg, secretkey)
    assert len(sigmsg) == len(msg) + c.crypto_sign_BYTES

    msg2 = c.crypto_sign_open(sigmsg, pubkey)
    assert msg2 == msg
コード例 #4
0
 def crypto_sign_open(self, sm, pk):
     try:
         return bindings.crypto_sign_open(sm, pk)
     except Exception as e:
         raise BadSignatureException(e)