├── README.md └── ore.py /README.md: -------------------------------------------------------------------------------- 1 | This is a simple implementation in Python of the Order Revealing scheme of Chenette et al. For more details refer to the original work: 2 | 3 | Chenette, N., Lewi, K., Weis, S. A., & Wu, D. J. (2016). Practical order-revealing encryption with limited leakage. In Proceedings of the 23rd International Conference on Fast Software Encryption (IACR-FSE). 4 | -------------------------------------------------------------------------------- /ore.py: -------------------------------------------------------------------------------- 1 | import hashlib 2 | import random 3 | from string import ascii_uppercase, digits 4 | LEN = 16 5 | 6 | 7 | def rnd_word(n): 8 | return ''.join(random.choice(ascii_uppercase + digits) for _ in range(n)) 9 | 10 | 11 | def prf(msg, k): 12 | pad = "0" * (LEN - len(msg)) 13 | return int(hashlib.sha224(str(msg) + pad + str(k)).hexdigest(), 16) 14 | 15 | 16 | def ore_enc(m, k): 17 | tmp_m = "" 18 | tmpres = "" 19 | for i in m: 20 | tmp_m += i 21 | tmpres += str((prf(tmp_m[:-1], k) + int(tmp_m[-1])) % 3) 22 | return tmpres 23 | 24 | 25 | def ore_comp(u, v): 26 | if u == v: 27 | return 0 28 | L = len(u) 29 | cnt = 0 30 | while u[cnt] == v[cnt]: 31 | cnt += 1 32 | if (int(u[cnt]) + 1) % 3 == int(v[cnt]): 33 | return -1 34 | else: 35 | return 1 36 | 37 | 38 | def int_comp(u, v): 39 | if u == v: 40 | return 0 41 | elif u > v: 42 | return 1 43 | else: 44 | return -1 45 | 46 | cnt = 0 47 | tests = 100 48 | for i in range(tests): 49 | passwd = rnd_word(10) 50 | num1 = random.randrange(2**63, 2**64) 51 | num2 = random.randrange(2**63, 2**64) 52 | 53 | a = ore_enc(bin(num1)[2:], passwd) 54 | b = ore_enc(bin(num2)[2:], passwd) 55 | if ore_comp(a, b) == int_comp(num1, num2): 56 | cnt += 1 57 | print "Succeded in: %d out of %d tests." % (cnt, tests) 58 | --------------------------------------------------------------------------------