示例#1
0
    def sign(self, groupId, message, signatureData):

        group = self.groups[groupId]
        self.ptw(
            "Player.sign: groupId = {0}, message = {1}, signatureData = {2}\n".
            format(groupId, message, signatureData))

        # convert dictionary to list of points
        points = list(signatureData.items())
        interpolator = Nakasendo.LGInterpolator \
            ( points, Player.modulo, decimal=False)

        s_at_zero = interpolator('0')

        #DER format
        mod_bn = Nakasendo.BigNum(Player.modulo, Player.modulo)

        TWO = Nakasendo.BigNum('2', Player.modulo, isDec=False)
        modDivByTwo = mod_bn / TWO
        canonizedInteropolated_s = s_at_zero

        if (s_at_zero > modDivByTwo):

            canonizedInteropolated_s = mod_bn - s_at_zero

        DerFormatSig = Nakasendo.createDERFormat(group.signer_r,
                                                 canonizedInteropolated_s)

        mySignature = [group.signer_r, s_at_zero]

        self.ptw("DER formatted signature = {0}, signature = {1}"\
            .format(DerFormatSig,mySignature ))
        return mySignature
示例#2
0
    print(s_points)
    s_interpolator = Nakasendo.LGInterpolator(s_points,
                                              modulo_n.value,
                                              decimal=False)
    interpolated_s = s_interpolator('0')

    #DER FORMAT (move this into the Nakasendo
    TWO = Nakasendo.BigNum('2', modulo_n, isDec=False)
    modDivByTwo = modulo_n / TWO
    canonizedInteropolated_s = interpolated_s

    if (interpolated_s > modDivByTwo):
        canonizedInteropolated_s = modulo_n - interpolated_s

    DerFormatSig = Nakasendo.createDERFormat(interpR, canonizedInteropolated_s)
    #print('Signature -> %s' % DerFormatSig)

    if (userTXInput):
        #41 is hex for 65 and is the sighash flag for ALL and FORKID
        #21 is the length of the compressed public key.
        #These values are hard coded for testing purpose.
        SigBytes = bytes.fromhex(DerFormatSig.value)
        HexSigBytes = binascii.hexlify(SigBytes)
        signature_length = len(
            SigBytes) + 1  # 1 byte will be added later for sighash flag
        signature_length = signature_length.to_bytes(
            (signature_length.bit_length() + 7) // 8, 'big')
        scriptSig_final = binascii.hexlify(
            signature_length) + HexSigBytes + b'4121' + binascii.hexlify(
                binascii.unhexlify(HiddenPoint.value))
示例#3
0
        print(
            "SUCESS WITH TS via ECDSA library .. point constructed from public key parameter"
        )
    else:
        print("FAILURE WITH TS via ECDSA library")

    if (dersigStr is not None):
        orderlen = (1 + len("%x" % N)) // 2
        print(orderlen)
        print(len(dersigStr))
        print(len(bytes(dersigStr, 'utf-8')))

        rBN = Nakasendo.BigNum(
            value=sigRStr,
            mod=
            "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141")
        sBN = Nakasendo.BigNum(
            value=sigSStr,
            mod=
            "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141")
        derSigInputBN = Nakasendo.BigNum(
            value=dersigStr,
            mod=
            "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141")
        DerFormatSigTest = Nakasendo.createDERFormat(rBN, sBN)
        assert (DerFormatSigTest == DerFormatSigTest)

        val = Nakasendo.verifyDER(message, pempubkey, dersigStr, False)
        if (val == True):
            print('TS DER format verified')