Example #1
0
 def test_retrieve(self):
     public_key, secret_key = generate_pair()
     index = 2
     enc_index = public_key.encrypt(binary(index, size=self.store.index_blength))
     enc_data = self.store.retrieve(enc_index, public_key)
     data = [secret_key.decrypt(bit) for bit in enc_data]
     assert_true(all(data == self.db[index]))
Example #2
0
 def test_retrieve(self):
     public_key, secret_key = generate_pair()
     index = 2
     enc_index = public_key.encrypt(
         binary(index, size=self.store.index_blength))
     enc_data = self.store.retrieve(enc_index, public_key)
     data = [secret_key.decrypt(bit) for bit in enc_data]
     assert_true(all(data == self.db[index]))
Example #3
0
    def test_retrieve(self):
        pk, sk = generate_pair()
        index = 2
        query = encrypt_index(pk, index, self.store.index_bits)

        response = self.store.retrieve(query, pk)
        data = sk.decrypt(response)
        assert_true(all(data == self.db[index]))
Example #4
0
    def test_set(self):
        index = 2
        new_value = [0, 0, 0, 0, 1, 1, 1, 1]
        self.store.set(index, new_value)

        public_key, secret_key = generate_pair()
        enc_index = public_key.encrypt(binary(index, size=self.store.index_blength))
        enc_data = self.store.retrieve(enc_index, public_key)
        data = [secret_key.decrypt(bit) for bit in enc_data]
        assert_equals(data, new_value)
Example #5
0
    def test_set(self):
        index = 2
        new_value = [0, 0, 0, 0, 1, 1, 1, 1]
        self.store.set(index, new_value)

        pk, sk = generate_pair()
        enc_index = encrypt_index(pk, index, self.store.index_bits)
        enc_data = self.store.retrieve(enc_index, pk)
        data = [sk.decrypt(bit) for bit in enc_data]
        assert_equals(data, new_value)
Example #6
0
    def test_set(self):
        index = 2
        new_value = [0, 0, 0, 0, 1, 1, 1, 1]
        self.store.set(index, new_value)

        public_key, secret_key = generate_pair()
        enc_index = public_key.encrypt(
            binary(index, size=self.store.index_blength))
        enc_data = self.store.retrieve(enc_index, public_key)
        data = [secret_key.decrypt(bit) for bit in enc_data]
        assert_equals(data, new_value)
Example #7
0
    def retrieve(self, index):
        """
        Retrieves a value from the Blindstore array.
        :param index: the index of the value to retrieve.
        :returns: the value stored at the given index, as a bit array.
        """
        public_key, secret_key = generate_pair()
        enc_index = public_key.encrypt(binary(index, size=self.index_length), secret_key)

        data = {'PUBLIC_KEY': str(public_key), 'ENC_INDEX': str(enc_index)}
        r = requests.post(self.url + 'retrieve', data=data)
        enc_data = [EncryptedBit(public_key, str(s)) for s in json.loads(r.text)]
        return [secret_key.decrypt(bit) for bit in enc_data]
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/..")

from benchmarks.benchmark import benchmark
from scarab import generate_pair
from common.utils import binary


pk, _ = generate_pair()
encrypted_one = pk.encrypt(0)
encrypted_zro = pk.encrypt(1)


def func():
    _ = encrypted_one & encrypted_zro


benchmark(func, 100, verbose=True, skip=10)
Example #9
0
def client_perform_query(i):
    pk, sk = generate_pair()
    response = server_generate_response(pk.encrypt(binary(i)), pk)
    result = [sk.decrypt(r) for r in response]
    return result
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/..")

from benchmarks.benchmark import benchmark
from scarab import generate_pair
from common.utils import binary
from server import Store


store = Store(record_size=20, record_count=20, fill='random')
index = 2
pk, sk = generate_pair()
eq = pk.encrypt(binary(index, size=store.index_bits), sk)


def func():
    list(store.retrieve(eq, pk))

benchmark(func, 10, verbose=True)
Example #11
0
        # TODO: make this parallel
        gammas = map(func, range(self.record_count))
        gammas = np.array(list(gammas))

        # TODO: make this parallel
        return map(lambda x: _R(gammas, self.database[:, x], public_key),
                   range(self.record_blength))

    def set(self, idx, value):
        """
        Set a value in the array.
        :param idx: the unencrypted index to set.
        :param value: the unencrypted value.
        """
        if len(value) < self.record_blength:
            padded_value = np.zeros(self.record_blength, dtype=np.int)
            padded_value[padded_value.size - len(value):] = value
        else:
            padded_value = value

        self.database[idx] = padded_value


if __name__ == '__main__':
    store = Store(record_count=8, record_blength=8)
    pk, sk = generate_pair()
    index = 2
    enc_data = store.retrieve(
        pk.encrypt(binary(index, size=store.index_blength)), pk)
    print([sk.decrypt(bit) for bit in enc_data])
Example #12
0
def test_encrypt_index():
    pk, sk = scarab.generate_pair()
    c = encrypt_index(pk, 1, 5)
    assert_true(len(c) == 5)