def generate_public_key(private_key, security_level=SECURITY_LEVEL): public_key = [] modulus = 2 ** (security_level * 8) for count in range(32): chaff = [random_integer(security_level) for count in range(security_level / 2)] shares_tier0 = secret_split(0, security_level, 4, modulus) shares = [] for share in shares_tier0: shares.extend(secret_split(share, security_level, 4, modulus)) assert len(shares) == 16 combined = shares + chaff shuffle(combined, private_key) for chaff_share in chaff: if combined[0] == chaff_share: raise ValueError("Invalid private key") public_key.append(combined) return public_key
def generate_public_key(private_key, security_level=SECURITY_LEVEL): public_key = [] modulus = 2**(security_level * 8) for count in range(32): chaff = [ random_integer(security_level) for count in range(security_level / 2) ] shares_tier0 = secret_split(0, security_level, 4, modulus) shares = [] for share in shares_tier0: shares.extend(secret_split(share, security_level, 4, modulus)) assert len(shares) == 16 combined = shares + chaff shuffle(combined, private_key) for chaff_share in chaff: if combined[0] == chaff_share: raise ValueError("Invalid private key") public_key.append(combined) return public_key
def encrypt(m, key, security_level=SECURITY_LEVEL, modulus=MODULUS): ciphertext = [] weight = hamming_weight(key) shares = secret_split(m, security_level, weight, modulus) chaff = [random_integer(security_level) for count in range((security_level * 8) - weight)] for bit_number in range(security_level * 8): if (key >> bit_number) & 1 == 1: ciphertext.append(shares.pop(0)) else: ciphertext.append(chaff.pop(0)) return ciphertext
def encrypt(m, public_key, security_level=SECURITY_LEVEL): element_size = len(public_key[0]) modulus = 2 ** (security_level * 8) ciphertext = [0 for count in range(element_size)] m_shares = secret_split(m, security_level, security_level, modulus) for count in range(security_level): element = public_key[count] r_share = m_shares[count] for index in range(element_size): ciphertext[index] = (ciphertext[index] + (r_share * element[index])) % modulus return ciphertext
def encrypt(m, public_key, security_level=SECURITY_LEVEL): element_size = len(public_key[0]) modulus = 2**(security_level * 8) ciphertext = [0 for count in range(element_size)] m_shares = secret_split(m, security_level, security_level, modulus) for count in range(security_level): element = public_key[count] r_share = m_shares[count] for index in range(element_size): ciphertext[index] = (ciphertext[index] + (r_share * element[index])) % modulus return ciphertext
def encrypt(m, key, security_level=SECURITY_LEVEL, modulus=MODULUS): ciphertext = [] weight = hamming_weight(key) shares = secret_split(m, security_level, weight, modulus) chaff = [ random_integer(security_level) for count in range((security_level * 8) - weight) ] for bit_number in range(security_level * 8): if (key >> bit_number) & 1 == 1: ciphertext.append(shares.pop(0)) else: ciphertext.append(chaff.pop(0)) return ciphertext
def generate_public_key(private_key, security_level=SECURITY_LEVEL): public_key = [] modulus = 2 ** (security_level * 8) for public_key_element_number in range(security_level): element = [] shares = secret_split(1, security_level, hamming_weight(private_key), modulus) for counter in range(security_level * 8): if (private_key >> counter) & 1: element.append(shares.pop(0)) else: element.append(random_integer(security_level)) public_key.append(element) return public_key
def generate_public_key(private_key, security_level=SECURITY_LEVEL, dimensions=DIMENSIONS): public_key = [] modulus = 2 ** (security_level * 8) for public_key_element_number in range(dimensions): element = [] shares = secret_split(0, security_level, hamming_weight(private_key), modulus) for counter in range(security_level * 8): if (private_key >> counter) & 1: element.append(shares.pop(0)) else: element.append(random_integer(security_level)) public_key.append(element) return public_key
def public_key_operation(m, public_key, security_level=SECURITY_LEVEL, q=Q): x, y = secret_split(m, security_level, 2, q) a, b = public_key return add(scalar_multiplication(a, x, q), scalar_multiplication(b, y, q), q)
def secret_key_encrypt(m, key, security_level=SECURITY_LEVEL, q=Q): x, y = secret_split(m, security_level, 2, q) a, b = key return (a * x) % q, (b * y) % q
def encrypt(m, key, parameters=PARAMETERS, q=Q): message_vector = secret_split(m, parameters["x_size"], 2, parameters["x_modulus"]) ciphertext = dot_product(key.encryption_key, message_vector) % q return ciphertext
def encrypt(m, key, security_level=SECURITY_LEVEL, q=Q): x, y = secret_split(m, security_level, 2, q) a, b = key return (a * x) % q, (b * y) % q
def public_key_operation(m, public_key, security_level=SECURITY_LEVEL, q=Q): x, y = secret_split(m, security_level, 2, q) a, b = public_key return add(scalar_multiplication(a, x, q), scalar_multiplication(b, y, q), q)