예제 #1
0
def issuerHandler(issueparam):
    group = ECGroup(security_dict[issueparam.L])
    g = group.deserialize(str.encode(issueparam.sg))
    h = group.deserialize(str.encode(issueparam.sh))
    # print(issueparam.yt)

    #####!!!!!!!!!!!!!!!!!!!!!!!Danger!!!!!!!!!!!!!!#######
    # xt = group.random(ZR)
    # yt = g ** xt
    # print('xt: ----====>>>')
    # print(xt)
    yt = point2Obj(int(issueparam.yt), group)
    #####!!!!!!!!!!!!!!!!!!!!!!!Danger!!!!!!!!!!!!!!#######

    gamma = group.init(ZR, int(issueparam.gamma))
    z = group.deserialize(str.encode(issueparam.sz))

    zu = z**(gamma**-1)
    v, u, d, s1, s2 = (group.random(ZR) for i in range(5))
    t1, t2, t3, t4, t5 = (group.random(ZR) for i in range(5))
    z1 = yt**v
    z2 = zu / z1
    a = g**u
    b1 = (g**s1) * (z1**d)
    b2 = (h**s2) * (z2**d)

    ret = [zu, v, u, d, s1, s2, \
           t1, t2, t3, t4, t5, \
           z1, z2, a, b1, b2,\
           bytes.decode(group.serialize(zu)), bytes.decode(group.serialize(z1)), bytes.decode(group.serialize(z2)),\
           bytes.decode(group.serialize(a)), bytes.decode(group.serialize(b1)), bytes.decode(group.serialize(b2))]

    return (str(k) for k in ret)
예제 #2
0
def oneHandler(oneParameter):

    group = ECGroup(security_dict[oneParameter.L])
    t1 = group.init(ZR, int(oneParameter.t1))
    t2 = group.init(ZR, int(oneParameter.t2))
    t3 = group.init(ZR, int(oneParameter.t3))
    t4 = group.init(ZR, int(oneParameter.t4))
    t5 = group.init(ZR, int(oneParameter.t5))
    gamma = group.init(ZR, int(oneParameter.gamma))
    z1 = group.deserialize(str.encode(oneParameter.sz1))
    z = group.deserialize(str.encode(oneParameter.sz))
    a = group.deserialize(str.encode(oneParameter.sa))
    b1 = group.deserialize(str.encode(oneParameter.sb1))
    b2 = group.deserialize(str.encode(oneParameter.sb2))
    g = group.deserialize(str.encode(oneParameter.sg))
    h = group.deserialize(str.encode(oneParameter.sh))
    y = group.deserialize(str.encode(oneParameter.sy))
    message = oneParameter.M

    d = group.init(ZR, int(oneParameter.d))
    u = group.init(ZR, int(oneParameter.u))
    x = group.init(ZR, int(oneParameter.x))
    s1 = group.init(ZR, int(oneParameter.s1))
    s2 = group.init(ZR, int(oneParameter.s2))

    zeta1 = z1**gamma
    zeta2 = z / zeta1
    alpha = a * (g**t1) * (y**t2)
    beta1 = (b1**gamma) * (g**t3) * (zeta1**t5)
    beta2 = (b2**gamma) * (h**t4) * (zeta2**t5)
    epsilon = group.hash((zeta1, alpha, beta1, beta2, message), ZR)
    e = epsilon - t2 - t5

    ####---------------------------------------
    c = e - d
    r = u - c * x
    ####=======================================
    roi = r + t1
    omega = c + t2
    sigma1 = gamma * s1 + t3
    sigma2 = gamma * s2 + t4
    delta = d + t5
    ####----------------------------------------
    xi = group.deserialize(str.encode(oneParameter.sxi))
    v = group.init(ZR, int(oneParameter.v))
    xiv = xi**v

    ret = [
        zeta1, zeta2, alpha, beta1, beta2, epsilon, e, c, r, roi, omega,
        sigma1, sigma2, delta, xiv,
        bytes.decode(group.serialize(xiv)),
        bytes.decode(group.serialize(zeta1)),
        bytes.decode(group.serialize(zeta2))
    ]
    return (str(i) for i in ret)
예제 #3
0
def twoHandler(twoParameter):
    group = ECGroup(security_dict[twoParameter.L])
    omega = group.init(ZR, int(twoParameter.omega))
    delta = group.init(ZR, int(twoParameter.delta))
    g = group.deserialize(str.encode(twoParameter.sg))
    h = group.deserialize(str.encode(twoParameter.sh))
    y = group.deserialize(str.encode(twoParameter.sy))
    zeta1 = group.deserialize(str.encode(twoParameter.szeta1))
    zeta2 = group.deserialize(str.encode(twoParameter.szeta2))
    roi = group.init(ZR, int(twoParameter.roi))
    sigma1 = group.init(ZR, int(twoParameter.sigma1))
    sigma2 = group.init(ZR, int(twoParameter.sigma2))

    tmp1 = (g**roi) * (y**omega)
    tmp2 = (g**sigma1) * (zeta1**delta)
    tmp3 = (h**sigma2) * (zeta2**delta)
    m = twoParameter.m
    return (str(omega + delta),
            str(group.hash((zeta1, tmp1, tmp2, tmp3, m), ZR)))
예제 #4
0
#192 bit group: g, h
decoded_g192 = b'\xab\xd0}\x86\xe1\x92,\xdd Ceael\x1a\xc3\xb9\xf5a\xe9K\xcd7\xa4'
decoded_h192 = b'\x00\xa3\x0brz\xea\xb0\xba\x005\t\xf9\xe9\xd2\x84\x0b\x18\x02\x18\xc2\xd7E\x13D'

group192 = ECGroup(prime192v1)
group256 = ECGroup(secp256k1)
group283 = ECGroup(sect283k1)
group571 = ECGroup(sect571k1)

g256 = group256.random(G)
h256 = group256.random(G)

#Cofactor is 4
#TODO: Just doing 8 change to 4
g283 = (group283.random(G))**(group283.init(ZR, int(4)))
h283 = (group283.random(G))**(group283.init(ZR, int(4)))

g571 = (group571.random(G))**(group571.init(ZR, int(4)))
h571 = (group571.random(G))**(group571.init(ZR, int(4)))

decoded_g256 = group256.decode(g256)
decoded_h256 = group256.decode(h256)

decoded_g283 = group283.decode(g283)
decoded_h283 = group283.decode(h283)

decoded_g571 = group571.decode(g571)
decoded_h571 = group571.decode(h571)
'''
print("decoded_g256:\n", decoded_g256)
예제 #5
0
파일: thresprf.py 프로젝트: fififish/beat
from charm.toolbox.ecgroup import ECGroup, ZR, G
from charm.toolbox.eccurve import prime256v1
from base64 import encodestring, decodestring
import random
import time

group = ECGroup(prime256v1)

g = group.random(G)
g1 = group.random(G)

ZERO = group.init(ZR, 0)
ONE = group.init(ZR, 1)


def serialize(g):
    # Only work in G1 here
    return decodestring(group.serialize(g)[2:])


def serialize1(g):
    return group.serialize(g)


def deserialize(g):
    return group.deserialize(g)


def deserialize2(g):
    # Only work in G1 here
    return group.deserialize('2:' + encodestring(g))
예제 #6
0
import time
import random
from collections import defaultdict
from honeybadgermpc.utils.misc import subscribe_recv, wrap_send

mpc_config = {
    MixinConstants.MultiplyShareArray: BeaverMultiplyArrays(),
    MixinConstants.MultiplyShare: BeaverMultiply(),
}
# public parameters
# sect571k1 = 0x020000000000000000000000000000000000000000000000000000000000000000000000131850E1F19A63E4B391A8DB917F4138B630D84BE5D639381E91DEB45CFE778F637C1001
# secp256k1 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F
p = 0x020000000000000000000000000000000000000000000000000000000000000000000000131850E1F19A63E4B391A8DB917F4138B630D84BE5D639381E91DEB45CFE778F637C1001
Field = GF(p)
group256 = ECGroup(sect571k1)
g = group256.init(G, 999999)
h = group256.init(G, 20)
KAPPA = 64  # security parameter
K = 256  # bit length of integer
random.seed(2020)


# excptions
class FieldsNotIdentical(Exception):
    pass


class DegreeNotIdentical(Exception):
    pass

예제 #7
0
    decoded_h = decoded_h256
    g = group.encode(decoded_g256)
    h = group.encode(decoded_h256)

elif bits == 283:
    group = group283
    decoded_g = decoded_g283
    decoded_h = decoded_h283
    g = group.encode(decoded_g283)**group.init(ZR, int(4))
    h = group.encode(decoded_h283)**group.init(ZR, int(4))

elif bits == 571:
    group = group571
    decoded_g = decoded_g571
    decoded_h = decoded_h571
    g = group.encode(decoded_g571)**group.init(ZR, int(4))
    h = group.encode(decoded_h571)**group.init(ZR, int(4))

g_rand = group.random(G)
zero = group.init(ZR, int(0))
unity = g_rand**zero

g256 = group256.encode(decoded_g256)
h256 = group256.encode(decoded_h256)

g283 = group283.encode(decoded_g283)**group283.init(ZR, int(4))
h283 = group283.encode(decoded_h283)**group283.init(ZR, int(4))

g571 = group571.encode(decoded_g571)**group571.init(ZR, int(4))
h571 = group571.encode(decoded_h571)**group571.init(ZR, int(4))