コード例 #1
0
ファイル: mirage.py プロジェクト: HarryR/active-oasis
fake_g = rands()
fake_G = sbmul(fake_g)
fake_sbmul = lambda x: multiply(fake_G, x)

expr_funcs = dict(
    TypeScalar=lambda x: x,
    TypePoint=lambda x: x,
    Opaque=lambda x: x,
    G=fake_sbmul,
    GDL=lambda: fake_g,
    Point=lambda x: x if isinstance(x, tuple) else fake_sbmul(x),
    PointDouble=lambda x: double(x),
    Sub=lambda x, y: (x - y) % curve_order,
    Neg=lambda x: -x % curve_order,
    Inv=lambda x: inv(x, curve_order),
    #InvMul=lambda x, y: (x * pow(y, field_modulus-2, field_modulus)),
    Add=lambda x, y: (x + y) % curve_order,
    Mul=lambda x, y: (x * y) % curve_order,
    ScalarMult=multiply,
    PointNeg=lambda x: (x[0], -x[1]),
    PointInv=lambda x: x.inv(),
    PointAdd=add,
    Hs=hashs,
    Hp=hashp,
    Equal=lambda x, y: x == y,
)


def extract_vars(term):
    return {str(x): rands() for x in T.variables(term)}
コード例 #2
0
asint = lambda x: x.n if isinstance(x, FQ) else x

randsn = lambda: randint(1, curve_order - 1)
randsp = lambda: randint(1, field_modulus - 1)
sbmul = lambda s: multiply(G1, asint(s))
hashsn = lambda *x: hashs(*x) % curve_order
hashpn = lambda *x: hashsn(*[item.n for sublist in x for item in sublist])
hashp = lambda *x: hashs(*[item.n for sublist in x for item in sublist])
addmodn = lambda x, y: (x + y) % curve_order
addmodp = lambda x, y: (x + y) % field_modulus
mulmodn = lambda x, y: (x * y) % curve_order
expmodn = lambda x, y: (x ** y) % curve_order
mulmodp = lambda x, y: (x * y) % field_modulus
submodn = lambda x, y: (x - y) % curve_order
submodp = lambda x, y: (x - y) % field_modulus
invmodn = lambda x: inv(x, curve_order)
invmodp = lambda x: inv(x, field_modulus)
negp = lambda x: (x[0], -x[1])

pasint = lambda p: (asint(p[0]), asint(p[1]))
mpasint = lambda *mp: [list(pasint(p)) for p in mp]
serring = lambda *x: [mpasint(*sublist) for sublist in x]

def evalcurve(x):
	a = 5472060717959818805561601436314318772174077789324455915672259473661306552146
	beta = addmodp(mulmodp(mulmodp(x, x), x), 3)
	y = powmod(beta, a, field_modulus)
	return (beta, y)


def isoncurve(x, y):
コード例 #3
0
def invmodp(x):
    return inv(x, P)
コード例 #4
0
from py_ecc.bn128 import add, multiply, curve_order, G1
from py_ecc.bn128.bn128_field_elements import inv, field_modulus, FQ

from .utils import hashs, bytes_to_int, powmod

randsn = lambda: randint(1, curve_order - 1)
sbmul = lambda s: multiply(G1, s)
hashsn = lambda *x: hashs(*x) % curve_order
hashpn = lambda *x: hashsn(*[item.n for sublist in x for item in sublist])
hashp = lambda *x: hashs(*[item.n for sublist in x for item in sublist])
addmodn = lambda x, y: (x + y) % curve_order
addmodp = lambda x, y: (x + y) % field_modulus
mulmodn = lambda x, y: (x * y) % curve_order
mulmodp = lambda x, y: (x * y) % field_modulus
submodn = lambda x, y: (x - y) % curve_order
invmodn = lambda x: inv(x, curve_order)
negp = lambda x: (x[0], -x[1])


def evalcurve(x):
    a = 5472060717959818805561601436314318772174077789324455915672259473661306552146
    beta = addmodp(mulmodp(mulmodp(x, x), x), 3)
    y = powmod(beta, a, field_modulus)
    return (beta, y)


def isoncurve(x, y):
    beta = addmodp(mulmodp(mulmodp(x, x), x), 3)
    return beta == mulmodp(y, y)

コード例 #5
0
def invmodn(x):
    return inv(x, N)