def test_k_upper_edge_case_succeeds(self): k = 512 chariot = Chariot(group, p, k) attribute_set = [i for i in range(6)] policy = [i for i in range(6)] threshold_policy = ThresholdPolicy(t, policy) message = "abcd" output = chariot.call(attribute_universe, attribute_set, threshold_policy, message, n) self.assertTrue(output)
def test_alternate_elliptic_curve_group(self): group = PairingGroup('SS1024') p = 36203638728584889925158415861634051131656232976339194924022065306723188923966451762160327870969638730567198058600508960697138006366861790409776528385407283664860565239295291314844246909284597617282274074224254733917313218308080644731349763985110821627195514711746037056425804819692632040479575042834043863089 chariot = Chariot(group, p, k) attribute_set = [i for i in range(3)] policy = [i for i in range(2)] t = 2 threshold_policy = ThresholdPolicy(t, policy) message = "abcd" output = chariot.call(attribute_universe, attribute_set, threshold_policy, message, n) self.assertTrue(output)
def perform_bencharks(repetitions, security_parameter, attribute_universe, attribute_set, threshold_policy): group = PairingGroup('SS512') p = 730750818665451621361119245571504901405976559617 chariot = Chariot(group, p, security_parameter) n = len(attribute_universe) # Upper bound of size of threshold policies avg_time, (public_params, master_secret_key) = benchmark(repetitions, chariot.setup, attribute_universe, n) print(f"Average Setup time: {avg_time}") avg_time, (osk, private_key, secret_key) = benchmark(repetitions, chariot.keygen, public_params, master_secret_key, attribute_set) print(f"Average Keygen time: {avg_time}") avg_time, HMAC_hashed_threshold_policy = benchmark(repetitions, chariot.request, threshold_policy, private_key) print(f"Average Request time: {avg_time}") avg_time, outsourced_signature = benchmark(repetitions, chariot.sign_out, public_params, osk, HMAC_hashed_threshold_policy) print(f"Average SignOut time: {avg_time}") message = "abcd" avg_time, signature = benchmark(repetitions, chariot.sign, public_params, private_key, message, outsourced_signature) print(f"Average Sign time: {avg_time}") avg_time, output = benchmark(repetitions, chariot.verify, public_params, secret_key, message, signature, threshold_policy) print(f"Average Verify time: {avg_time}")
import unittest import operator from functools import reduce from charm.schemes.CHARIOT.chariot import aggregate, Chariot from charm.toolbox.pairinggroup import ZR, G1, PairingGroup group = PairingGroup('SS512') p = 730750818665451621361119245571504901405976559617 k = 16 t = 6 attribute_universe = list([i for i in range(20)]) n = len(attribute_universe) chariot = Chariot(group, p, k) class TestAggregate(unittest.TestCase): def test_aggregate_calculates_correct_value(self): r = 5 g = group.random(G1) gamma = group.random(ZR) x_array = [group.random(ZR), group.random(ZR), group.random(ZR)] p_array = [g**(r / (gamma + i)) for i in x_array] output = aggregate(x_array, p_array) expected_output = g**( r / reduce(operator.mul, [gamma + i for i in x_array], 1)) self.assertEqual(output, expected_output)
def test_k_equal_0_throws_exception(self): with self.assertRaises(Exception): Chariot(group, p, 0)
def test_k_too_big_throws_exception(self): with self.assertRaises(Exception): Chariot(group, p, 513)
def test_k_non_divisible_by_8_throws_exception(self): with self.assertRaises(Exception): Chariot(group, p, 10)