Example #1
0
def crypto_sign_ed25519ph_final_create(edph, sk):
    """
    Create a signature for the data hashed in edph
    using the secret key sk

    :param edph: the ed25519ph state for the data
                 being signed
    :type edph: crypto_sign_ed25519ph_state
    :param sk: the ed25519 secret part of the signing key
    :type sk: bytes
    :return: ed25519ph signature
    :rtype: bytes
    """
    ensure(isinstance(edph, crypto_sign_ed25519ph_state),
           'edph parameter must be a ed25519ph_state object',
           raising=exc.TypeError)
    ensure(isinstance(sk, bytes),
           'secret key parameter must be a bytes object',
           raising=exc.TypeError)
    ensure(len(sk) == crypto_sign_SECRETKEYBYTES,
           ('secret key must be {0} '
            'bytes long').format(crypto_sign_SECRETKEYBYTES),
           raising=exc.TypeError)
    signature = ffi.new("unsigned char[]", crypto_sign_BYTES)
    rc = lib.crypto_sign_ed25519ph_final_create(edph.state, signature,
                                                ffi.NULL, sk)
    ensure(rc == 0, 'Unexpected library error', raising=exc.RuntimeError)

    return ffi.buffer(signature, crypto_sign_BYTES)[:]
Example #2
0
def crypto_sign_ed25519ph_final_create(edph,
                                       sk):
    """
    Create a signature for the data hashed in edph
    using the secret key sk

    :param edph: the ed25519ph state for the data
                 being signed
    :type edph: crypto_sign_ed25519ph_state
    :param sk: the ed25519 secret part of the signing key
    :type sk: bytes
    :return: ed25519ph signature
    :rtype: bytes
    """
    ensure(isinstance(edph, crypto_sign_ed25519ph_state),
           'edph parameter must be a ed25519ph_state object',
           raising=exc.TypeError)
    ensure(isinstance(sk, bytes),
           'secret key parameter must be a bytes object',
           raising=exc.TypeError)
    ensure(len(sk) == crypto_sign_SECRETKEYBYTES,
           ('secret key must be {0} '
            'bytes long').format(crypto_sign_SECRETKEYBYTES),
           raising=exc.TypeError)
    signature = ffi.new("unsigned char[]", crypto_sign_BYTES)
    rc = lib.crypto_sign_ed25519ph_final_create(edph.state,
                                                signature,
                                                ffi.NULL,
                                                sk)
    ensure(rc == 0,
           'Unexpected library error',
           raising=exc.RuntimeError)

    return ffi.buffer(signature, crypto_sign_BYTES)[:]