test/functional/test_framework/key.py
def verify_ecdsa(self, sig, msg, low_s=True):
        """Verify a strictly DER-encoded ECDSA signature against this pubkey."""
        assert(self.valid)
        if (sig[1] + 2 != len(sig)):
            return False
        if (len(sig) < 4):
            return False
        if (sig[0] != 0x30):
            return False
        if (sig[2] != 0x02):
            return False
        rlen = sig[3]
        if (len(sig) < 6 + rlen):
            return False
        if rlen < 1 or rlen > 33:
            return False
        if sig[4] >= 0x80:
            return False
        if (rlen > 1 and (sig[4] == 0) and not (sig[5] & 0x80)):
            return False
        r = int.from_bytes(sig[4:4 + rlen], 'big')
        if (sig[4 + rlen] != 0x02):
            return False
        slen = sig[5 + rlen]
        if slen < 1 or slen > 33:
            return False
        if (len(sig) != 6 + rlen + slen):
            return False
        if sig[6 + rlen] >= 0x80:
            return False
        if (slen > 1 and (sig[6 + rlen] == 0) and not (sig[7 + rlen] & 0x80)):
            return False
        s = int.from_bytes(sig[6 + rlen:6 + rlen + slen], 'big')
        if r < 1 or s < 1 or r >= SECP256K1_ORDER or s >= SECP256K1_ORDER:
            return False
        if low_s and s >= SECP256K1_ORDER_HALF:
            return False
        z = int.from_bytes(msg, 'big')
        w = modinv(s, SECP256K1_ORDER)
        u1 = z * w % SECP256K1_ORDER
        u2 = r * w % SECP256K1_ORDER
        R = SECP256K1.affine(SECP256K1.mul([(SECP256K1_G, u1), (self.p, u2)]))
        if R is None or R[0] != r:
            return False
        return True
Verify a strictly DER-encoded ECDSA signature against this pubkey.
Verify a strictly DER-encoded ECDSA signature against this pubkey.
Verify a strictly DER - encoded ECDSA signature against this pubkey .
def verify_ecdsa(self, sig, msg, low_s=True):
        assert(self.valid)
        if (sig[1] + 2 != len(sig)):
            return False
        if (len(sig) < 4):
            return False
        if (sig[0] != 0x30):
            return False
        if (sig[2] != 0x02):
            return False
        rlen = sig[3]
        if (len(sig) < 6 + rlen):
            return False
        if rlen < 1 or rlen > 33:
            return False
        if sig[4] >= 0x80:
            return False
        if (rlen > 1 and (sig[4] == 0) and not (sig[5] & 0x80)):
            return False
        r = int.from_bytes(sig[4:4 + rlen], 'big')
        if (sig[4 + rlen] != 0x02):
            return False
        slen = sig[5 + rlen]
        if slen < 1 or slen > 33:
            return False
        if (len(sig) != 6 + rlen + slen):
            return False
        if sig[6 + rlen] >= 0x80:
            return False
        if (slen > 1 and (sig[6 + rlen] == 0) and not (sig[7 + rlen] & 0x80)):
            return False
        s = int.from_bytes(sig[6 + rlen:6 + rlen + slen], 'big')
        if r < 1 or s < 1 or r >= SECP256K1_ORDER or s >= SECP256K1_ORDER:
            return False
        if low_s and s >= SECP256K1_ORDER_HALF:
            return False
        z = int.from_bytes(msg, 'big')
        w = modinv(s, SECP256K1_ORDER)
        u1 = z * w % SECP256K1_ORDER
        u2 = r * w % SECP256K1_ORDER
        R = SECP256K1.affine(SECP256K1.mul([(SECP256K1_G, u1), (self.p, u2)]))
        if R is None or R[0] != r:
            return False
        return True
def verify_ecdsa ( self , sig , msg , low_s = True ) : assert ( self . valid ) if ( sig [ 1 ] + 2 != len ( sig ) ) : return False if ( len ( sig ) < 4 ) : return False if ( sig [ 0 ] != 0x30 ) : return False if ( sig [ 2 ] != 0x02 ) : return False rlen = sig [ 3 ] if ( len ( sig ) < 6 + rlen ) : return False if rlen < 1 or rlen > 33 : return False if sig [ 4 ] >= 0x80 : return False if ( rlen > 1 and ( sig [ 4 ] == 0 ) and not ( sig [ 5 ] & 0x80 ) ) : return False r = int . from_bytes ( sig [ 4 : 4 + rlen ] , 'big' ) if ( sig [ 4 + rlen ] != 0x02 ) : return False slen = sig [ 5 + rlen ] if slen < 1 or slen > 33 : return False if ( len ( sig ) != 6 + rlen + slen ) : return False if sig [ 6 + rlen ] >= 0x80 : return False if ( slen > 1 and ( sig [ 6 + rlen ] == 0 ) and not ( sig [ 7 + rlen ] & 0x80 ) ) : return False s = int . from_bytes ( sig [ 6 + rlen : 6 + rlen + slen ] , 'big' ) if r < 1 or s < 1 or r >= SECP256K1_ORDER or s >= SECP256K1_ORDER : return False if low_s and s >= SECP256K1_ORDER_HALF : return False z = int . from_bytes ( msg , 'big' ) w = modinv ( s , SECP256K1_ORDER ) u1 = z * w % SECP256K1_ORDER u2 = r * w % SECP256K1_ORDER R = SECP256K1 . affine ( SECP256K1 . mul ( [ ( SECP256K1_G , u1 ) , ( self . p , u2 ) ] ) ) if R is None or R [ 0 ] != r : return False return True
Verify a strictly DER-encoded ECDSA signature against this pubkey.
Verify a strictly DER - encoded ECDSA signature against this pubkey .
"""Verify a strictly DER-encoded ECDSA signature against this pubkey."""
self
sig
msg
low_s