コード例 #1
0
ファイル: multiexp.py プロジェクト: ph4r05/research-lab
def boscoster_robust2(data):
    while True:
        index1 = 0
        for i in range(len(data)):
            if data[i][0] > data[index1][0]:
                index1 = i
        index2 = 0
        if index2 == index1:
            index2 = 1
        for i in range(len(data)):
            if i != index1:
                if data[i][0] > data[index2][0]:
                    index2 = i
        if data[index2][0] == 0:
            return ed25519.multiply(data[index1][0], data[index1][1])

        # handle pathological inputs where s1 > 2s2
        # replace (s1,P1) with (s1/2,2*P1)
        tail_point = ed25519.Z  # handles odd scalars
        while data[index1][0] > 2 * data[index2][0]:
            # if s1 is odd, add (1,P1) at the end of the heap
            if (data[index1][0] % 2) == 1:
                tail_point = ed25519.add(tail_point, data[index1][1])
            data[index1][0] = long(data[index1][0] / 2)
            data[index1][1] = ed25519.add(data[index1][1], data[index1][1])

        if tail_point != ed25519.Z:
            data.append([1, tail_point])
        data[index2][1] = ed25519.add(data[index2][1], data[index1][1])
        data[index1][0] = (data[index1][0] -
                           data[index2][0]) % ed25519.l  # scalar subtraction
コード例 #2
0
ファイル: multiexp.py プロジェクト: ph4r05/research-lab
def boscosterheap_robust2(data):
    data = [[-datum[0], datum[1]]
            for datum in data]  # to form a descending heap
    heapq.heapify(data)
    while len(data) > 1:
        item1 = heapq.heappop(data)
        item2 = heapq.heappop(data)
        s1, p1 = -item1[0], item1[1]
        s2, p2 = -item2[0], item2[1]

        # handle pathological inputs where s1 > 2s2
        # replace (s1,P1) with (s1/2,2*P1)
        tail_point = ed25519.Z  # handles odd scalars
        while s1 > 2 * s2:
            # if s1 is odd, add (1,P1) at the end of the heap
            if (s1 % 2) == 1:
                tail_point = ed25519.add(tail_point, p1)
            s1 = long(s1 / 2)
            p1 = ed25519.add(p1, p1)

        if tail_point != ed25519.Z:
            heapq.heappush(data, [-1, tail_point])
        p2 = ed25519.add(p1, p2)
        s1 = (s1 - s2) % ed25519.l  # scalar subtraction
        if s1 > 0L:
            heapq.heappush(data, [-s1, p1])
        heapq.heappush(data, [-s2, p2])
    result = heapq.heappop(data)
    return ed25519.multiply(-result[0], result[1])
コード例 #3
0
ファイル: multiexp.py プロジェクト: ph4r05/research-lab
def boscosterheap(data):
    data = [[-datum[0], datum[1]]
            for datum in data]  # to form a descending heap
    heapq.heapify(data)
    while len(data) > 1:
        item1 = heapq.heappop(data)
        item2 = heapq.heappop(data)
        s1, p1 = -item1[0], item1[1]
        s2, p2 = -item2[0], item2[1]
        p2 = ed25519.add(p1, p2)
        s1 = (s1 - s2) % ed25519.l  # scalar subtraction
        if s1 > 0L:
            heapq.heappush(data, [-s1, p1])
        heapq.heappush(data, [-s2, p2])
    result = heapq.heappop(data)
    return ed25519.multiply(-result[0], result[1])
コード例 #4
0
ファイル: multiexp.py プロジェクト: ph4r05/research-lab
def boscoster(data):
    while True:
        index1 = 0
        for i in range(len(data)):
            if data[i][0] > data[index1][0]:
                index1 = i
        index2 = 0
        if index2 == index1:
            index2 = 1
        for i in range(len(data)):
            if i != index1:
                if data[i][0] > data[index2][0]:
                    index2 = i
        if data[index2][0] == 0:
            return ed25519.multiply(data[index1][0], data[index1][1])
        data[index2][1] = ed25519.add(data[index2][1], data[index1][1])
        data[index1][0] = (data[index1][0] -
                           data[index2][0]) % ed25519.l  # scalar subtraction
コード例 #5
0
ファイル: multiexp.py プロジェクト: ph4r05/research-lab
def basic(data):
    result = ed25519.Z  # zero point
    for datum in data:
        result = ed25519.add(result, ed25519.multiply(datum[0], datum[1]))
    return result