Exemplo n.º 1
0
def ec_pubkey_tweak_mul(ctx, pubkey, tweak):
    '''Tweak a public key by multiplying it by a tweak value.
    Args:
        ctx     (secp256k1_context*):   pointer to a context object
                                        initialized for validation (cannot be
                                        NULL)
        pubkey  (secp2561_pubkey*):     pointer to a public key object
        tweak   (bytes):                pointer to a 32-byte tweak
    Returns:
        (int, secp256k1_pubkey*):       (0 if the tweak was out of range
                                        (chance of around 1 in 2^128 for
                                        uniformly random 32-byte arrays, or
                                        equal to zero. 1 otherwise,
                                        pointer to a public key object)
    '''
    # Validate context
    utils.validate_context(ctx)

    # Validate public key
    utils.validate_public_key(pubkey)

    # Validate tweak
    utils.validate_tweak_ser(tweak)

    return (lib.secp256k1_ec_pubkey_tweak_mul(ctx, pubkey, tweak), pubkey)
Exemplo n.º 2
0
def ec_pubkey_tweak_add(ctx, pubkey, tweak):
    ''' Tweak a public key by adding tweak times the generator to it.
    Args:
        ctx     (secp256k1_context*):   pointer to a context object (cannot be
                                        NULL)
        pubkey  (secp256k1_pubkey*):    pointer to a public key object
        tweak   (bytes):                pointer to a 32-byte tweak
    Returns:
        (int, secp256k1_pubkey*):       (0 if the tweak was out of range
                                        (change of around 1 in 2^128 for
                                        uniformly random 32-byte arrays),
                                        or if the resulting public key
                                        would be invalid (only when the
                                        tweak is the complement of the
                                        corresponding private key). 1
                                        otherwise,
                                        a pointer to a secp256k1_pubkey
                                        containing tweaked public key)
    '''
    # Validate context
    utils.validate_context(ctx)

    # Validate public key
    utils.validate_public_key(pubkey)

    # Validate tweak
    utils.validate_tweak_ser(tweak)

    return (lib.secp256k1_ec_pubkey_tweak_add(ctx, pubkey, tweak), pubkey)
Exemplo n.º 3
0
def ec_privkey_tweak_mul(ctx, seckey, tweak):
    '''Tweak a private key by multiplying it by a tweak.
    Args:
        ctx     (secp256k1_context*):   pointer to a context object (cannot be
                                        NULL)
        seckey  (bytes):                pointer to a 32-byte private key
        tweak   (bytes):                pointer to a 32-byte tweak
    Returns:
        (int, seckey):                  (0 if the tweak was out of range
                                        (chance of around 1 in 2^128 for
                                        uniformly random 32-byte arrays, or
                                        equal to zero. 1 otherwise,
                                        pointer to a 32-byte private key)
    '''
    # Validate context
    utils.validate_context(ctx)

    # Validate secret key
    utils.validate_secret_key_ser(seckey)

    # Validate tweak
    utils.validate_tweak_ser(tweak)

    return (lib.secp256k1_ec_privkey_tweak_mul(ctx, seckey, tweak), seckey)