def share_generation(k, m, n, l=None, pub_inf=None): #k degree, m members, n identities, n >=m, modulus is 2l bits long if l == None: s = safePrime() else: s = safePrime(l) mod = s.get_modulus() A = random_polynomial(k, randint(0, mod - 1), mod) #the second parameter means secret #A = [985, 254, 1957, 312] #print "f_i" + str(A) P = Polynomial(A, mod, n) ''' for i in range(1,n+1): print P.value(i) ''' S = [] if pub_inf == None: pub_inf = range(1, n + 1) inverseOfnminus1 = mod_inverse(n - 1, s.get_eular()) for i in range(n): c = s.sqaure_and_multiply(P.value(pub_inf[i]), inverseOfnminus1) S.append(share_Polynomial(P.get_mul_value(c), mod, n, i)) return A, S
def secret_int_to_points(secret_int, point_threshold, num_points, prime=None): """ Split a secret (integer) into shares (pair of integers / x,y coords). Sample the points of a random polynomial with the y intercept equal to the secret int. """ if point_threshold < 2: raise ValueError("Threshold must be >= 2.") if point_threshold > num_points: raise ValueError("Threshold must be < the total number of points.") if not prime: prime = get_large_enough_prime([secret_int, num_points]) if not prime: raise ValueError("Error! Secret is too long for share calculation!") coefficients = random_polynomial(point_threshold-1, secret_int, prime) points = get_polynomial_points(coefficients, num_points, prime) return points
def secret_int_to_points(secret_int, point_threshold, num_points): """ Split a secret (integer) into shares (pair of integers / x,y coords). Sample the points of a random polynomial with the y intercept equal to the secret int. """ if point_threshold < 2: raise ValueError("Threshold must be >= 2.") if point_threshold > num_points: raise ValueError("Threshold must be < the total number of points.") prime = get_large_enough_prime([secret_int, num_points]) if not prime: raise ValueError("Error! Secret is too long for share calculation!") print 'Selected Prime Number = ', prime coefficients = random_polynomial(point_threshold-1, secret_int, prime) points = get_polynomial_points(coefficients, num_points, prime) return points
def secret_int_to_points_given_prime(secret_int, point_threshold, num_points, prime): """ Split a secret (integer) into shares (pair of integers / x,y coords). The prime number chosen while constructing the polynomial is provided as an input to the function, rather than being chosen in the function. This is to ensure that the same prime is chosen for multiple shared secrets, allowing us to do homomorphic computations on the secrets. Sample the points of a random polynomial with the y intercept equal to the secret int. """ if point_threshold < 2: raise ValueError("Threshold must be >= 2.") if point_threshold > num_points: raise ValueError("Threshold must be < the total number of points.") if not prime: raise ValueError("Error! Secret is too long for share calculation!") print 'Selected Prime Number = ', prime coefficients = random_polynomial(point_threshold-1, secret_int, prime) points = get_polynomial_points(coefficients, num_points, prime) return points
def secret_int_to_points_given_prime(secret_int, point_threshold, num_points, prime): """ Split a secret (integer) into shares (pair of integers / x,y coords). The prime number chosen while constructing the polynomial is provided as an input to the function, rather than being chosen in the function. This is to ensure that the same prime is chosen for multiple shared secrets, allowing us to do homomorphic computations on the secrets. Sample the points of a random polynomial with the y intercept equal to the secret int. """ if point_threshold < 2: raise ValueError("Threshold must be >= 2.") if point_threshold > num_points: raise ValueError("Threshold must be < the total number of points.") if not prime: raise ValueError("Error! Secret is too long for share calculation!") print 'Selected Prime Number = ', prime coefficients = random_polynomial(point_threshold - 1, secret_int, prime) points = get_polynomial_points(coefficients, num_points, prime) return points
n = int(sys.argv[1]) rn = n/2 # 1024bit modulus p1 = 11514844562790516655282382339997901326205477956091910904703943499562165719386197597458797308772109262770530717689695340334206066966408416627740404681562663L q1 = 10423868126996985387214298003163473887816545231233184168499707786423333353741569421872579600137156466386073703548533187413949131260907402186949276882953347L n1 = 120029221225396603943216312047289862327499010103056102571360609037851894896802135599029426055406735973259252625983764193927877972873712575004271317839369300415405820754446598418407393743146043397841334533819748796599919740150430457027942915144241523764241525063139352964442411349882905130519757202210486083061L phi_1 = 120029221225396603943216312047289862327499010103056102571360609037851894896802135599029426055406735973259252625983764193927877972873712575004271317839369278476693130966944555921727050581770829375818147208724675592948633754651357329260923583767332614498512368458718114735914663194684677814700942512528921567052L # 2048bit modulus p2 = 146577968092877312553398069696998164521291778517747266285620770923741199895672989329883393034806862195786134935131447729635292436654606931321259940448635910284739497814443242901860431973473904516100420002377014760516087876319694046674932514757720182024711379435769206957579891080424488883021398865152668185847L q2 = 161185860087032198171591177899415457502154280429768268816998037977934434736927998922989563504350082388505854576461166890757554351306828172915196408722596424537550936512619197351577432179777058245856717154742653464973379928171789861715315739636999452888860044631026786739283446194194236313836676520593401112159L n2 = 23626295856859992265056730641465568551098718630084909446692697033225009031418301544480771860359655448664564181287192033292039242567946888484015603287220606316235151997738808126001142006753732243117524136214693962867755236545218137604793811858657384961745470253756673427655525701533591709750228473515744735089371318394149314335225824881013690795368106910575340795775903156498142994768069714898602269014705183848012394862675132316756664263850553979274626204746281189677294090916601447299267285290025687498569239951469483691647850557764983064367446907502177190801149385157844508468862171881233487337714983247906703413673L phi_2 = 23626295856859992265056730641465568551098718630084909446692697033225009031418301544480771860359655448664564181287192033292039242567946888484015603287220606316235151997738808126001142006753732243117524136214693962867755236545218137604793811858657384961745470253756673427655525701533591709750228473515744735089063554565969404824500835633417277173344660851627825260673284347596467360135468726645729312475548239263720405351082517696363817475889118875038169855575048854855003656589539007045829421136774724736612102794349815466158382753273499155977198653107457555887577961091048514771998834606614762140856907862160634115668L # degree of polynomial f11 is 10, and modulus is 1024 bits f11 = random_polynomial(10, randint(0, n1-1), n1) P11 = Polynomial(f11, n1, n) # degree of polynomial f12 is 10, and modulus is 2048 bits f12 = random_polynomial(10, randint(0, n2-1), n2) P12 = Polynomial(f12, n2, n) # degree of polynomial f11 is 20, and modulus is 1024 bits f21 = random_polynomial(20, randint(0, n1-1), n1) P21 = Polynomial(f21, n1, n) # degree of polynomial f12 is 20, and modulus is 2048 bits f22 = random_polynomial(20, randint(0, n2-1), n2) P22 = Polynomial(f22, n2, n) pub_inf = range(1,n+1) f = open('results.txt','a')