Beispiel #1
0
def proveRange(amount):
    bb = d2b(amount, ATOMS)  #gives binary form of bb in "digits" binary digits
    print("amount, amount in binary", amount, bb)
    ai = [None] * len(bb)
    Ci = [None] * len(bb)
    CiH = [None] * len(bb)  #this is like Ci - 2^i H
    H2 = getH2ForCT()
    a = MiniNero.sc_0()
    ii = [None] * len(bb)
    indi = [None] * len(bb)
    for i in range(0, ATOMS):
        ai[i] = PaperWallet.skGen()
        a = MiniNero.addScalars(
            a, ai[i]
        )  #creating the total mask since you have to pass this to receiver...
        if bb[i] == 0:
            Ci[i] = MiniNero.scalarmultBase(ai[i])
        if bb[i] == 1:
            Ci[i] = MiniNero.addKeys(MiniNero.scalarmultBase(ai[i]), H2[i])
        CiH[i] = MiniNero.subKeys(Ci[i], H2[i])

    A = asnlSig()
    A.L1, A.s2, A.s = AggregateSchnorr.GenASNL(ai, Ci, CiH, bb)

    R = rangeSig()
    R.asig = A
    R.Ci = Ci

    mask = a
    C = sumCi(Ci)
    return C, mask, R
Beispiel #2
0
def proveRange(amount):
    bb = d2b(amount, ATOMS) #gives binary form of bb in "digits" binary digits
    print("amount, amount in binary", amount, bb)
    ai = [None] * len(bb)
    Ci = [None] * len(bb)
    CiH = [None] * len(bb) #this is like Ci - 2^i H
    H2 = getH2ForCT()
    a = MiniNero.sc_0()
    ii = [None] * len(bb)
    indi = [None] * len(bb)
    for i in range(0, ATOMS):
        ai[i] = PaperWallet.skGen()
        a = MiniNero.addScalars(a, ai[i]) #creating the total mask since you have to pass this to receiver...
        if bb[i] == 0:
            Ci[i] =  MiniNero.scalarmultBase(ai[i])
        if bb[i] == 1:
            Ci[i] = MiniNero.addKeys(MiniNero.scalarmultBase(ai[i]), H2[i])
        CiH[i] = MiniNero.subKeys(Ci[i], H2[i])
        
    A = asnlSig()
    A.L1, A.s2, A.s = AggregateSchnorr.GenASNL(ai, Ci, CiH, bb)
    
    R = rangeSig()
    R.asig = A
    R.Ci = Ci
    
    mask = a
    C = sumCi(Ci)
    return C, mask, R
Beispiel #3
0
def genRangeProof(b, digits):
    bb = binary(b, digits) #gives binary form of bb in "digits" binary digits
    print("b, b in binary", b, bb)
    ai = [None] * len(bb)
    Ci = [None] * len(bb)
    CiH = [None] * len(bb) #this is like Ci - 2^i H
    a = MiniNero.intToHex(0)
    ii = [None] * len(bb)
    indi = [None] * len(bb)
    for i in range(0, len(bb)):
        ai[i] = PaperWallet.skGen()
        a = MiniNero.addScalars(a, ai[i]) #creating the total mask since you have to pass this to receiver...
        Ci[i] = MiniNero.addKeys(MiniNero.scalarmultBase(ai[i]), MiniNero.scalarmultKey(getHForCT(), MiniNero.intToHex(bb[i] * 2 ** i)))
        CiH[i] = MiniNero.subKeys(Ci[i], MiniNero.scalarmultKey(getHForCT(), MiniNero.intToHex(2 ** i)))
    L1, s2, s = AggregateSchnorr.GenASNL(ai, Ci, CiH, bb)
    return sumCi(Ci), Ci, L1, s2, s, a
Beispiel #4
0
def genRangeProof(b, digits):
    bb = binary(b, digits)  #gives binary form of bb in "digits" binary digits
    print("b, b in binary", b, bb)
    ai = [None] * len(bb)
    Ci = [None] * len(bb)
    CiH = [None] * len(bb)  #this is like Ci - 2^i H
    a = MiniNero.intToHex(0)
    ii = [None] * len(bb)
    indi = [None] * len(bb)
    for i in range(0, len(bb)):
        ai[i] = PaperWallet.skGen()
        a = MiniNero.addScalars(
            a, ai[i]
        )  #creating the total mask since you have to pass this to receiver...
        Ci[i] = MiniNero.addKeys(
            MiniNero.scalarmultBase(ai[i]),
            MiniNero.scalarmultKey(getHForCT(),
                                   MiniNero.intToHex(bb[i] * 2**i)))
        CiH[i] = MiniNero.subKeys(
            Ci[i], MiniNero.scalarmultKey(getHForCT(),
                                          MiniNero.intToHex(2**i)))
    L1, s2, s = ASNL.GenASNL(ai, Ci, CiH, bb)
    return sumCi(Ci), Ci, L1, s2, s, a
Beispiel #5
0
        print("verifying range proofs of outputs")
        RingCT.verRangeProof(Cib, L1b, s2b, sb)
        RingCT.verRangeProof(Cic, L1c, s2c, sc)
        x, P1 = PaperWallet.skpkGen()
        P2 = PaperWallet.pkGen()
        C2 = PaperWallet.pkGen() #some random commitment grabbed from the blockchain
        ind = 0
        Ca = RingCT.sumCi(Cia)
        Cb = RingCT.sumCi(Cib)
        Cc = RingCT.sumCi(Cic)
        sk = [x, MiniNero.sc_sub_keys(ska, MiniNero.sc_add_keys(skb, skc))]
        pk = [[P1, P2], [MiniNero.subKeys(Ca, MiniNero.addKeys(Cb, Cc)), MiniNero.subKeys(C2, MiniNero.addKeys(Cb, Cc)) ] ]
        II, cc, ssVal = MLSAG.MLSAG_Sign(pk, sk, ind)
        print("Sig verified?", MLSAG.MLSAG_Ver(pk, II, cc, ssVal) )
        print("Finding received amount corresponding to Cib")
        RingCT.ComputeReceivedAmount(pe, sr, MiniNero.addScalars(ss1, skb),MiniNero.addScalars(ss2, MiniNero.intToHex(b)), Cib, 9)
        print("Finding received amount corresponding to Cic")
        RingCT.ComputeReceivedAmount(pe, sr, MiniNero.addScalars(ss1, skc), MiniNero.addScalars(ss2, MiniNero.intToHex(c)), Cic, 9)
    if sys.argv[1] == "MLSAG":
        #below is example usage. Uncomment each line for testing
        N = 3 #cols
        R = 3 #rows
        x = [[None]*N] #just used to generate test public keys
        sk = [None] * R #vector of secret keys
        P = [[None]*N] #stores the public keys

        ind = 2
        for j in range(0, R):
            if j > 0:
                x.append([None]*N)
                P.append([None]*N)
Beispiel #6
0
        )  #some random commitment grabbed from the blockchain
        ind = 0
        Ca = RingCT.sumCi(Cia)
        Cb = RingCT.sumCi(Cib)
        Cc = RingCT.sumCi(Cic)
        sk = [x, MiniNero.sc_sub_keys(ska, MiniNero.sc_add_keys(skb, skc))]
        pk = [[P1, P2],
              [
                  MiniNero.subKeys(Ca, MiniNero.addKeys(Cb, Cc)),
                  MiniNero.subKeys(C2, MiniNero.addKeys(Cb, Cc))
              ]]
        II, cc, ssVal = MLSAG.MLSAG_Sign(pk, sk, ind)
        print("Sig verified?", MLSAG.MLSAG_Ver(pk, II, cc, ssVal))
        print("Finding received amount corresponding to Cib")
        RingCT.ComputeReceivedAmount(
            pe, sr, MiniNero.addScalars(ss1, skb),
            MiniNero.addScalars(ss2, MiniNero.intToHex(b)), Cib, 9)
        print("Finding received amount corresponding to Cic")
        RingCT.ComputeReceivedAmount(
            pe, sr, MiniNero.addScalars(ss1, skc),
            MiniNero.addScalars(ss2, MiniNero.intToHex(c)), Cic, 9)
    if sys.argv[1] == "MLSAG":
        #below is example usage. Uncomment each line for testing
        N = 3  #cols
        R = 3  #rows
        x = [[None] * N]  #just used to generate test public keys
        sk = [None] * R  #vector of secret keys
        P = [[None] * N]  #stores the public keys

        ind = 2
        for j in range(0, R):
Beispiel #7
0
        print("verifying range proofs of outputs")
        RingCT.verRangeProof(Cib, L1b, s2b, sb)
        RingCT.verRangeProof(Cic, L1c, s2c, sc)
        x, P1 = PaperWallet.skpkGen()
        P2 = PaperWallet.pkGen()
        C2 = PaperWallet.pkGen() #some random commitment grabbed from the blockchain
        ind = 0
        Ca = RingCT.sumCi(Cia)
        Cb = RingCT.sumCi(Cib)
        Cc = RingCT.sumCi(Cic)
        sk = [x, MiniNero.sc_sub_keys(ska, MiniNero.sc_add_keys(skb, skc))]
        pk = [[P1, P2], [MiniNero.subKeys(Ca, MiniNero.addKeys(Cb, Cc)), MiniNero.subKeys(C2, MiniNero.addKeys(Cb, Cc)) ] ]
        II, cc, ssVal = MLSAG.MLSAG_Sign(pk, sk, ind)
        print("Sig verified?", MLSAG.MLSAG_Ver(pk, II, cc, ssVal) )
        print("Finding received amount corresponding to Cib")
        RingCT.ComputeReceivedAmount(pe, sr, MiniNero.addScalars(ss1, skb),MiniNero.addScalars(ss2, MiniNero.intToHex(b)), Cib, 9)
        print("Finding received amount corresponding to Cic")
        RingCT.ComputeReceivedAmount(pe, sr, MiniNero.addScalars(ss1, skc), MiniNero.addScalars(ss2, MiniNero.intToHex(c)), Cic, 9)
    if sys.argv[1] == "MLSAG":
        #below is example usage. Uncomment each line for testing
        N = 3 #cols
        R = 3 #rows
        x = [[None]*N] #just used to generate test public keys
        sk = [None] * R #vector of secret keys
        P = [[None]*N] #stores the public keys

        ind = 2
        for j in range(0, R):
            if j > 0:
                x.append([None]*N)
                P.append([None]*N)