コード例 #1
0
ファイル: test_jacobian_field.py プロジェクト: marchon/gec
def test_jacobian_multi():
    ret = JacobianGroupBTC(
        (
            FiniteFieldBTC(5),
            FiniteFieldBTC(8),
            FiniteFieldBTC(1)
        )
    ) @ EllipticCurveCyclicSubgroupBTC(2)

    ans = jacobian_multiply((5, 8, 1), 2)
    assert (
        ret.value[0].value,
        ret.value[1].value,
        ret.value[2].value
    ) == ans

    ans = jacobian_multiply((5, 8, 1), 3)
    ret = JacobianGroupBTC(
        EllipticCurveGroupBTC(
            (
                FiniteFieldBTC(5),
                FiniteFieldBTC(8),
            )
        )
    ) @ EllipticCurveCyclicSubgroupBTC(3)
    assert (
        ret.value[0].value,
        ret.value[1].value,
        ret.value[2].value
    ) == ans
    ret = EllipticCurveGroupBTC(ret)
    assert (
        ret.value[0].value,
        ret.value[1].value,
    ) == from_jacobian(ans)
コード例 #2
0
def ecrecover_substitute(z, v, r, s):
    P, A, B, N, Gx, Gy = b.P, b.A, b.B, b.N, b.Gx, b.Gy
    x = r
    beta = pow(x * x * x + A * x + B, (P + 1) // 4, P)
    y = beta if v % 2 ^ beta % 2 else (P - beta)
    Gz = b.jacobian_multiply((Gx, Gy, 1), (N - z) % N)
    XY = b.jacobian_multiply((x, y, 1), s)
    Qr = b.jacobian_add(Gz, XY)
    Q = b.jacobian_multiply(Qr, pow(r, N - 2, N))
    Q = b.from_jacobian(Q)
    return signed(Q)
コード例 #3
0
ファイル: substitutes.py プロジェクト: ethereum/serpent
def ecrecover_substitute(z, v, r, s):
    P, A, B, N, Gx, Gy = b.P, b.A, b.B, b.N, b.Gx, b.Gy
    x = r
    beta = pow(x*x*x+A*x+B, (P + 1) / 4, P)
    y = beta if v % 2 ^ beta % 2 else (P - beta)
    Gz = b.jacobian_multiply((Gx, Gy, 1), (N - z) % N)
    XY = b.jacobian_multiply((x, y, 1), s)
    Qr = b.jacobian_add(Gz, XY)
    Q = b.jacobian_multiply(Qr, pow(r, N - 2, N))
    Q = b.from_jacobian(Q)
    return signed(Q)
コード例 #4
0
import bitcoin as b
import random
import sys
import math
from ethereum.tools import tester as t
from ethereum import utils
import substitutes
import time

vals = [random.randrange(2**256) for i in range(12)]

test_points = [b.jacobian_multiply((b.Gx, b.Gy, 1), r) for r in vals]

G = [b.Gx, b.Gy, 1]
Z = [0, 0, 1]


def neg_point(p):
    return [p[0], b.P - p[1], p[2]]


s = t.Chain()
s.head_state.gas_limit = 10**9

tests = sys.argv[1:]

if '--log' in tests:
    t.set_logging_level(int((tests + [1])[tests.index('--log') + 1]))

if '--modexp' in tests or not len(tests):
    c = s.contract('jacobian_arith.se', language='serpent')
コード例 #5
0
def jacobian_mul_substitute(A, B, C, N):
    output = b.jacobian_multiply((A, B, C), N)
    return signed(output)
コード例 #6
0
ファイル: substitutes.py プロジェクト: ethereum/serpent
def jacobian_mul_substitute(A, B, C, N):
    output = b.jacobian_multiply((A, B, C), N)
    return signed(output)