コード例 #1
0
ファイル: player.py プロジェクト: wszhang/nakasendo
    def polynomialPreCalculation(self, poly, mod, ordinal):

        self.transientData.reset()

        # evaluate polynomial for own ordinal
        # polynomial is set to Hex, so convert the ordinal to hex string
        self.transientData.f_x = poly(str(ordinal))
        bignum = Nakasendo.BigNum(self.transientData.f_x, mod)
        self.transientData.hiddenEvals[self.ordinal] = \
            str(Nakasendo.ECPoint().GetGeneratorPoint().multipleScalar(bignum))

        # evaluate polynomials for the group ordinals
        for ord in self.ordinalList:
            self.transientData.evals[ord[0]] = poly(str(ord[0]))
            bignum = Nakasendo.BigNum(self.transientData.evals[ord[0]], mod)
            self.transientData.hiddenEvals[ord[0]] = \
                str(Nakasendo.ECPoint().GetGeneratorPoint().multipleScalar(bignum))

        # hide own polynomial using generator point
        GEN = Nakasendo.ECPoint()
        GENPOINT = GEN.GetGeneratorPoint()

        for index in poly.coefficients:
            bignum = Nakasendo.BigNum(index, mod)
            res = GENPOINT.multipleScalar(bignum)
            self.transientData.hiddenPolynomial.append(res.value)
コード例 #2
0
def test_CheckOnCurveFromHexOnCurve():

    # Generating Random EC Points
    for x in range(10):
        # using the integer value of NID secp256k1, which is 714
        nID = 714

        # Generate a Random EC Point with default NID ==> NID_secp256k1
        hexValue = Nakasendo.ECPoint(nID)
        assert hexValue.IsPointOnCurve() is True, "Test failed"
コード例 #3
0
ファイル: player.py プロジェクト: wszhang/nakasendo
    def calculateShareOfVW(self, mod):

        # littleK * alpha
        v = self.littleK * self.alpha

        # alpha * Generator Point
        GEN = Nakasendo.ECPoint()
        GENPOINT = GEN.GetGeneratorPoint()
        w = GENPOINT.multipleScalar(self.alpha)

        return v.value, w.value
コード例 #4
0
def test_MultiplyScalarMNOnCurve():

    # Generating Random EC
    for x in range(10):
        # using the integer value of NID secp256k1, which is 714
        nID = 714

        # Generate a Random EC Point with default NID ==> NID_secp256k1
        mValue = Nakasendo.ECPoint(nID)
        nValue = Nakasendo.ECPoint(nID)

        # EC Point GetAffineCoOrdinates_GFp with default NID => NID_secp256k1
        x_axis, y_axis = mValue.GetAffineCoOrdinates()
        assert len(x_axis) == 62 or len(x_axis) == 64, "Test failed"

        # EC Point Scalar multiply with supplied curve ID
        actualValue = str(mValue.multipltScalarEx(mValue, nValue))

        # Verifying the the length of actual value as 66
        assert len(actualValue) == 66, "Test failed"
コード例 #5
0
def test_GetAffineCoOrdinates():

    # Generating Random EC
    for x in range(10):
        # using the integer value of NID secp256k1, which is 714
        nID = 714

        # Generate a Random EC Point with default NID ==> NID_secp256k1
        hexValue = Nakasendo.ECPoint(nID)

        # EC Point GetAffineCoOrdinates_GFp with default NID => NID_secp256k1
        x_axis, y_axis = hexValue.GetAffineCoOrdinates()
        assert len(x_axis) == 62 or len(x_axis) == 64, "Test failed"
コード例 #6
0
ファイル: player.py プロジェクト: wszhang/nakasendo
    def calculateEphemeralKey(self, groupId):

        group = self.groups[groupId]
        self.ptw("Calculating Ephemeral Key...")

        xfx_v = []
        xfx_w = []

        allOrdinals = group.allOrdinals()
        #allOrdinals = []
        #for i in group.ordinalList :
        #    allOrdinals.append( i[0] )
        #allOrdinals.append(group.ordinal)

        for ord in allOrdinals:
            vw = group.transientData.allVWshares[ord]
            xfx_v.append((ord, vw[0]))
            point = Nakasendo.ECPoint()
            point.SetValue(vw[1])
            w_points = point.GetAffineCoOrdinates()

            xfx_w.append((str(ord), w_points[0], w_points[1]))


        v_interpolator = Nakasendo.LGInterpolator \
            ( xfx_v, Player.modulo, decimal=False)
        w_interpolator = Nakasendo.LGECInterpolator \
            ( xfx_w, Player.modulo, decimal=False)

        vZeroVal = v_interpolator('0')
        wZeroVal = w_interpolator('0')

        vZeroValInv = vZeroVal.inverse()

        interpolated_r = wZeroVal.multipleScalar(vZeroValInv)
        if (interpolated_r.IsPointOnCurve() is not True):
            msg = ("Error in Player:calculateEphemeralKey: point not on curve")
            self.ptw(msg)
            raise PlayerError(msg)

        interpolated_r_points = interpolated_r.GetAffineCoOrdinates()

        r_bn = Nakasendo.BigNum(interpolated_r_points[0], Player.modulo)
        ephemeralKey = [group.littleK, r_bn]

        group.ephemeralKeyList.append(ephemeralKey)
コード例 #7
0
def test_GetGeneratorPoint():

    # Generating Random EC
    for x in range(10):
        # using the integer value of NID secp256k1, which is 714
        nID = 714

        # Generate a Random EC Point with default NID ==> NID_secp256k1
        hexValue = Nakasendo.ECPoint(nID)

        # EC Point GetAffineCoOrdinates_GFp with default NID => NID_secp256k1
        x_axis, y_axis = hexValue.GetAffineCoOrdinates()
        assert len(x_axis) == 62 or len(x_axis) == 64, "Test failed"
        assert hexValue.IsPointOnCurve() is True, "Test failed"
        # Generate a Elliptic curve point
        xPoint = str(hexValue.GetGeneratorPoint())
        assert len(xPoint) == 66, "Test failed"
コード例 #8
0
def test_MultiplyByGenerator():

    # Generating Random EC
    for x in range(10):
        # using the integer value of NID secp256k1, which is 714
        nID = 714

        # Generate a Random EC Point with default NID ==> NID_secp256k1
        hexValue = Nakasendo.ECPoint(nID)
        bigNumB = Nakasendo.BigNum()
        # EC Point GetAffineCoOrdinates_GFp with default NID => NID_secp256k1
        x_axis, y_axis = hexValue.GetAffineCoOrdinates()
        assert len(x_axis) == 62 or len(x_axis) == 64, "Test failed"

        # EC Point Scalar multiply on curve with supplied ID
        actualValue = str(
            Nakasendo.MultiplyByGenerator(bigNumB, compressed=True))
        assert len(actualValue) == 66, "Test failed"
コード例 #9
0
def test_MultiplyScalarMOnCurve():

    # Generating Random EC
    for x in range(10):
        # using the integer value of NID secp256k1, which is 714
        nID = 714

        # Generate a Random EC Point with default NID ==> NID_secp256k1
        hexValue = Nakasendo.ECPoint(nID)

        # EC Point GetAffineCoOrdinates_GFp with default NID => NID_secp256k1
        x_axis, y_axis = hexValue.GetAffineCoOrdinates()
        assert len(x_axis) == 62 or len(x_axis) == 64, "Test failed"

        # EC Point Scalar multiply on curve with supplied ID
        actualValue = str(hexValue.multipleScalar(hexValue))

        # Verifying the actual value with expected value
        assert len(actualValue) == 66, "Test failed"
コード例 #10
0
def test_LGECInterpolatorFull():

    modulo = PyBigNumbers.GenerateRandPrimeHex(1000)
    xValue = PyBigNumbers.GenerateRandHex(1000)
    listTupleObj = []
    dec = False

    # Generating Random EC
    for x in range(10, 50):
        # Generate a Random EC Point with default NID ==> NID_secp256k1
        hexValue = Nakasendo.ECPoint()

        # Check if the point is on the curve with the supplied NID default NID ==> NID_secp256k1
        assert hexValue.IsPointOnCurve(), "Test failed"

        x_Axis, y_axis = hexValue.GetAffineCoOrdinates()
        # EC Point GetAffineCoOrdinates_GFp with default NID => NID_secp256k1
        listTupleObj.append((str(x), x_Axis, y_axis))

    lgInterpolatorX = PyPolynomial.LGECInterpolatorFull(
        listTupleObj, modulo, xValue, dec)
    assert type(lgInterpolatorX) == str, "Test failed"
コード例 #11
0
def test_LGECInterpolatorFull():

    # modulo = PyBigNumbers.GenerateRandPrimeHex(1000)
    modulo = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"
    xValue = Nakasendo.BigNum().value
    listTupleObj = []
    hex_value = False
    # Generating Random EC
    for x in range(10, 50):
        # Generate a Random EC Point with default NID ==> NID_secp256k1
        hexValue = Nakasendo.ECPoint()
        print(hexValue.value)
        # Check if the point is on the curve with the supplied NID default NID ==> NID_secp256k1
        assert hexValue.IsPointOnCurve(), "Test failed"

        x_Axis, y_axis = hexValue.GetAffineCoOrdinates()
        # EC Point GetAffineCoOrdinates_GFp with default NID => NID_secp256k1
        listTupleObj.append((str(x), x_Axis, y_axis))

    lgInterpolatorX = Nakasendo.LGECInterpolator(listTupleObj, modulo,
                                                 hex_value)
    lgInterpolatorX = lgInterpolatorX(xValue)
    assert type(lgInterpolatorX) == Nakasendo.ECPoint, "Test failed"
コード例 #12
0
    import PyECPoint
    import PySymEncDec
    import PyMessageHash
    import PyAsymKey
    import PyPolynomial
    import Nakasendo
except ImportError as e:
    print('Error while loading SDKLibraries python modules {}'.format(e.message))
    print('Try to define environment variable SDKLIBRARIES_ROOT pointing to the location of installed SDKLibraries or add this to PYTHONPATH')
    raise ImportError('Unable to load SDKLibraries python modules')


if __name__ == "__main__":
    print ("starting.....")
    
    ECPointA  = Nakasendo.ECPoint ()
    print ("ECPointA output %s" % ECPointA ) 

    ECPointB = Nakasendo.ECPoint ()
    print ("ECPointB output %s " % ECPointB)


    coordsA = ECPointA.GetAffineCoOrdinates()
    print ("Random Elliptic Curve Point A:\n x = %s \ny= %s" % (coordsA[0], coordsA[1]))
    
    coordsB = ECPointB.GetAffineCoOrdinates()
    print ("Random Elliptic Curve Point B:\n x = %s \ny= %s" % (coordsB[0], coordsB[1]))
    
    
    bigNumA = Nakasendo.BigNum()
    bigNumB = Nakasendo.BigNum(ECPointA.value)
コード例 #13
0
ファイル: player.py プロジェクト: wszhang/nakasendo
 def getECPoint(value, isDecimal=False):
     ecpoint = Nakasendo.ECPoint()
     ecpoint.SetValue(value)
     return ecpoint
コード例 #14
0
ファイル: TSLiveDemo.py プロジェクト: hilzlee/nakasendo-1
        index = random.randint(0, len(Players) - 1)
        if (index not in subGroupPlayersIndex):
            subGroupPlayersIndex.append(index)

    subGroupSigningIndex = []
    while (len(subGroupSigningIndex)) < (2 * tt + 1):
        index = random.randint(0, len(Players) - 1)
        if (index not in subGroupSigningIndex):
            subGroupSigningIndex.append(index)
    #print('Players SubGroup')

    vect_d = CalculateSecret(Players, modulo_n.value, isDec=False)
    print(vect_d)
    secret = DerivePubKey(Players, modulo_n.value, isDec=False)

    GEN = Nakasendo.ECPoint(isDec=False)
    GENPOINT = GEN.GetGeneratorPoint()

    HiddenPoint = GENPOINT.multipleScalar(secret)
    PubKeyPoints = HiddenPoint.GetAffineCoOrdinates()
    print('Public Key %s %s' % (PubKeyPoints[0], PubKeyPoints[1]))
    print('public key in compressed form %s' % HiddenPoint)
    print('private key %s' % secret.value)
    #can we recover the key from a subgroup with interpolation

    #Recover the public key from a t+1 group.
    print('Recover the public/private key pair from a group size of t+1 = %s' %
          (tt + 1))
    private_d_points = []
    for i in subGroupPlayersIndex:
        label_j = Players[i].getOrdinal()
コード例 #15
0
ファイル: TestNakasendo.py プロジェクト: hilzlee/nakasendo-1
        e.message))
    print(
        'Try to define environment variable SDKLIBRARIES_ROOT pointing to the location of installed SDKLibraries or add this to PYTHONPATH'
    )
    raise ImportError('Unable to load SDKLibraries python modules')

if __name__ == "__main__":
    print("starting.....")
    bigNumA = Nakasendo.BigNum()
    bigNumB = Nakasendo.BigNum()

    c = bigNumA + bigNumB
    print("operator A ->  %s, ..... operator B-> %s" % (bigNumA, bigNumB))
    print("...result of addition %s", c)

    ECPointA = Nakasendo.ECPoint()
    print("ECPointA output %s" % ECPointA)

    ECPointB = Nakasendo.ECPoint()
    print("ECPointB output %s " % ECPointB)

    ECPointC = ECPointA + ECPointB
    print("ECPointC (ECPointA + ECPointB) output %s " % ECPointC)

    print("Testing multiplication (2 parameters)... ")
    BigNumScalerA = Nakasendo.BigNum()
    ECPointG = Nakasendo.ECPoint()

    ECPointRes = ECPointG.multipleScalar(BigNumScalerA)
    print("Multiplication res: %s " % ECPointRes)
コード例 #16
0
ファイル: verifyTest.py プロジェクト: hilzlee/nakasendo-1
if __name__ == "__main__":
    print("...starting....")
    #print (sys.argv)
    sigRStr = sys.argv[1]
    sigSStr = sys.argv[2]
    pubKeyStr = sys.argv[3]
    message = sys.argv[4]

    dersigStr = None
    if (len(sys.argv) == 6):
        dersigStr = sys.argv[5]

    print('[%s, %s] \n pubkey %s \nmessage = %s' %
          (sigRStr, sigSStr, pubKeyStr, message))
    # create an ECPoint
    pt = Nakasendo.ECPoint()
    pt.value = pubKeyStr
    #print(pt.GetAffineCoOrdinates())

    coords = pt.GetAffineCoOrdinates()

    pempubkey = Nakasendo.pubKeyHexPtasPem(coords[0], coords[1])
    print(pempubkey)
    print('verify the pem format')
    pubKeyStrValidate = Nakasendo.pubKeyPEMasHex(pempubkey, True)
    #print(pubKeyStrValidate)
    # get the affine co-ordinates
    # get pem format

    valPem = Nakasendo.verify(message, pempubkey, sigRStr, sigSStr)
    if (valPem == True):