Пример #1
0
def MLSAG_Gen(pk, xx, index ):
    rows = len(xx)
    cols = len(pk[0])
    print("Generating MG sig of size ", rows, "x", cols)
    c= [None] * cols
    alpha = skvGen(rows)
    I = keyImageV(xx)
    L = keyMatrix(rows, cols)
    R = keyMatrix(rows, cols)
    s = keyMatrix(rows, cols)
    m = ''.join(pk[0])
    for i in range(1, cols):
        m = m + ''.join(pk[i])
    L[index] = [MiniNero.scalarmultBase(aa) for aa in alpha] #L = aG
    Hi = hashKeyVector(pk[index])
    R[index] = [MiniNero.scalarmultKey(Hi[ii], alpha[ii]) for ii in range(0, rows)] #R = aI
    oldi = index
    i = (index + 1) % cols
    c[i] = MiniNero.cn_fast_hash(m+''.join(L[oldi]) + ''.join(R[oldi]))
    
    while i != index:
        s[i] = skvGen(rows)
        L[i] = [MiniNero.addKeys1(s[i][j], c[i], pk[i][j]) for j in range(0, rows)]

        Hi = hashKeyVector(pk[i])
        R[i] = [MiniNero.addKeys2( s[i][j], Hi[j], c[i], I[j]) for j in range(0, rows)]
        oldi = i
        i = (i + 1) % cols
        c[i] = MiniNero.cn_fast_hash(m+''.join(L[oldi]) + ''.join(R[oldi]))
    print("L", L)
    print("R", R)
    s[index] = [MiniNero.sc_mulsub_keys(alpha[j], c[index], xx[j]) for j in range(0, rows)] #alpha - c * x
    return I, c[0], s
Пример #2
0
def LLW_Sig(pk, xx, index):
    n = len(pk)
    print("Generating LLW sig of length ", n)
    L = [None] * n
    R = [None] * n
    c = [None] * n
    s = [PaperWallet.skGen() for i in range(0, n)]
    HP = [MiniNero.hashToPoint_ct(i) for i in pk]
    pj = ''.join(pk)
    keyimage = keyImage(xx)  #ok
    s[index] = MiniNero.mul_8(s[index])
    L[index] = MiniNero.scalarmultBase(s[index])
    R[index] = MiniNero.scalarmultKey(HP[index], s[index])  #aH
    j = (index + 1) % n
    c[j] = MiniNero.cn_fast_hash(pj + L[index] + R[index])
    while j != index:
        L[j] = MiniNero.addKeys(MiniNero.scalarmultBase(s[j]),
                                MiniNero.scalarmultKey(pk[j],
                                                       c[j]))  #Lj = sG + cxG
        R[j] = MiniNero.addKeys(MiniNero.scalarmultKey(HP[j], s[j]),
                                MiniNero.scalarmultKey(keyimage,
                                                       c[j]))  #Rj = sH + cxH
        cj = (j + 1) % n
        c[cj] = MiniNero.cn_fast_hash(pj + L[j] +
                                      R[j])  #c j+1 = H(pk + Lj + Rj
        j = cj  #increment j
    s[index] = MiniNero.sc_mulsub_keys(s[index], c[index],
                                       xx)  #si = a - c x so a = s + c x
    print("sigma = ", keyimage, c[0], s[:])
    return keyimage, c[0], s[:]
Пример #3
0
def GenSchnorrNonLinkable(x, P1, P2, index):
    if index == 0:
        a = PaperWallet.skGen()
        L1 = MiniNero.scalarmultBase(a)
        s2 = PaperWallet.skGen()
        c2 = MiniNero.cn_fast_hash(L1)
        L2 = MiniNero.addKeys(MiniNero.scalarmultBase(s2), MiniNero.scalarmultKey(P2, c2))
        c1 = MiniNero.cn_fast_hash(L2)
        s1 = MiniNero.sc_mulsub_keys(a,  x, c1)
    if index == 1:
        a = PaperWallet.skGen()
        L2 = MiniNero.scalarmultBase(a)
        s1 = PaperWallet.skGen()
        c1 = MiniNero.cn_fast_hash(L2)
        L1 = MiniNero.addKeys(MiniNero.scalarmultBase(s1), MiniNero.scalarmultKey(P1, c1))
        c2 = MiniNero.cn_fast_hash(L1)
        s2 = MiniNero.sc_mulsub_keys(a,  x, c2)
    return L1, s1, s2,
Пример #4
0
def GenSchnorrNonLinkable(x, P1, P2, index):
    if index == 0:
        a = PaperWallet.skGen()
        L1 = MiniNero.scalarmultBase(a)
        s2 = PaperWallet.skGen()
        c2 = MiniNero.cn_fast_hash(L1)
        L2 = MiniNero.addKeys(MiniNero.scalarmultBase(s2),
                              MiniNero.scalarmultKey(P2, c2))
        c1 = MiniNero.cn_fast_hash(L2)
        s1 = MiniNero.sc_mulsub_keys(a, x, c1)
    if index == 1:
        a = PaperWallet.skGen()
        L2 = MiniNero.scalarmultBase(a)
        s1 = PaperWallet.skGen()
        c1 = MiniNero.cn_fast_hash(L2)
        L1 = MiniNero.addKeys(MiniNero.scalarmultBase(s1),
                              MiniNero.scalarmultKey(P1, c1))
        c2 = MiniNero.cn_fast_hash(L1)
        s2 = MiniNero.sc_mulsub_keys(a, x, c2)
    return L1, s1, s2,
Пример #5
0
def MLSAG_Gen(pk, xx, index):
    rows = len(xx)
    cols = len(pk)
    print("Generating MG sig of size ", rows, "x", cols)
    print("index is:", index)
    print("checking if I can actually sign")
    print(pk[index])
    print([MiniNero.scalarmultBase(x) for x in xx])
    c = [None] * cols
    alpha = skvGen(rows)
    I = keyImageV(xx)
    L = keyMatrix(rows, cols)
    R = keyMatrix(rows, cols)
    s = keyMatrix(rows, cols)
    m = ''.join(pk[0])
    for i in range(1, cols):
        m = m + ''.join(pk[i])
    L[index] = [MiniNero.scalarmultBase(aa) for aa in alpha]  #L = aG
    Hi = hashKeyVector(pk[index])
    R[index] = [
        MiniNero.scalarmultKey(Hi[ii], alpha[ii]) for ii in range(0, rows)
    ]  #R = aI
    oldi = index
    i = (index + 1) % cols
    c[i] = MiniNero.cn_fast_hash(m + ''.join(L[oldi]) + ''.join(R[oldi]))

    while i != index:
        s[i] = skvGen(rows)
        L[i] = [
            MiniNero.addKeys1(s[i][j], c[i], pk[i][j]) for j in range(0, rows)
        ]

        Hi = hashKeyVector(pk[i])
        R[i] = [
            MiniNero.addKeys2(s[i][j], Hi[j], c[i], I[j])
            for j in range(0, rows)
        ]
        oldi = i
        i = (i + 1) % cols
        c[i] = MiniNero.cn_fast_hash(m + ''.join(L[oldi]) + ''.join(R[oldi]))
    print("L", L)
    print("R", R)
    s[index] = [
        MiniNero.sc_mulsub_keys(alpha[j], c[index], xx[j])
        for j in range(0, rows)
    ]  #alpha - c * x
    return I, c[0], s
Пример #6
0
def MLSAG_Sign(pk, xx, index):
    rows = len(xx)
    cols = len(pk[0])
    print("Generating MLSAG sig of dimensions ",rows ,"x ", cols)
    L = [[None] * cols] #list of keyvectors? except it's indexed by cols... it's kind of internal actually
    R = [[None] * cols]
    s = [[PaperWallet.skGen() for i in range(0, cols)] ] #first index is rows, second is cols, wonder if I should switch that..
    HP = [[MiniNero.hashToPoint_cn(i) for i in pk[0]]]

    pj = ''.join(pk[0])  
    for i in range(1, rows):
      L.append([None] * cols)
      R.append([None] * cols)
      s.append([PaperWallet.skGen() for j in range(0, cols)])
      HP.append([MiniNero.hashToPoint_cn(j) for j in pk[i]]) 
      pj = pj + ''.join(pk[i])

    c= [None] * cols #1-dimensional
    keyimage = keyImage(xx, rows) #ok
    for i in range(0, rows):
      L[i][index] = MiniNero.scalarmultBase(s[i][index]) #aG
      R[i][index] = MiniNero.scalarmultKey(HP[i][index], s[i][index]) #aH
    j = (index + 1) % cols
    tohash = pj
    for i in range(0, rows):
      tohash = tohash + L[i][index] + R[i][index]
    c[j] = MiniNero.cn_fast_hash(tohash)
    while j != index:
      tohash = pj
      for i in range(0, rows):
        L[i][j] = MiniNero.addKeys(MiniNero.scalarmultBase(s[i][j]), MiniNero.scalarmultKey(pk[i][j], c[j])) #Lj = sG + cxG
        R[i][j] = MiniNero.addKeys(MiniNero.scalarmultKey(HP[i][j], s[i][j]), MiniNero.scalarmultKey(keyimage[i], c[j])) #Rj = sH + cxH
        tohash = tohash + L[i][j] + R[i][j]
      j = (j + 1) % cols
      c[j] = MiniNero.cn_fast_hash(tohash)
    for i in range(0, rows):
      s[i][index] = MiniNero.sc_mulsub_keys(s[i][index], c[index], xx[i]) #si = a - c x so a = s + c x
    return keyimage, c[0], s
Пример #7
0
def LLW_Sig(pk, xx, index ):
    n = len(pk)
    print("Generating LLW sig of length ", n)
    L = [None] * n
    R = [None] * n
    c= [None] * n
    s = [PaperWallet.skGen() for i in range(0, n)] 
    HP = [MiniNero.hashToPoint_ct(i) for i in pk]
    pj = ''.join(pk)
    keyimage = keyImage(xx) #ok
    s[index] = MiniNero.mul_8(s[index])
    L[index] = MiniNero.scalarmultBase(s[index])
    R[index] = MiniNero.scalarmultKey(HP[index], s[index]) #aH
    j = (index + 1) % n
    c[j] = MiniNero.cn_fast_hash(pj+L[index]+R[index])
    while j != index:
        L[j] = MiniNero.addKeys(MiniNero.scalarmultBase(s[j]), MiniNero.scalarmultKey(pk[j], c[j])) #Lj = sG + cxG
        R[j] = MiniNero.addKeys(MiniNero.scalarmultKey(HP[j], s[j]), MiniNero.scalarmultKey(keyimage, c[j])) #Rj = sH + cxH
        cj = (j + 1) % n
        c[cj] = MiniNero.cn_fast_hash(pj + L[j] + R[j]) #c j+1 = H(pk + Lj + Rj
        j = cj #increment j
    s[index] = MiniNero.sc_mulsub_keys(s[index], c[index], xx) #si = a - c x so a = s + c x
    print("sigma = ", keyimage, c[0], s[:])
    return keyimage, c[0], s[:]