-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.py
76 lines (50 loc) · 1.55 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import logging
from binteger import Bin
from circkit.boolean import OptBooleanCircuit as BooleanCircuit
#from circkit.boolean import BooleanCircuit
from wbkit.ciphers.aes import BitAES
from wbkit.ciphers.aes.aes import encrypt
logging.basicConfig(level=logging.DEBUG)
C = BooleanCircuit(name="AES")
key = b"abcdefghABCDEFGH"
plaintext = b"0123456789abcdef"
pt = C.add_inputs(128)
ct, k10 = BitAES(pt, Bin(key).tuple, rounds=10)
C.add_output(ct)
C.in_place_remove_unused_nodes()
C.print_stats()
ct = C.evaluate(Bin(plaintext).tuple)
ct = Bin(ct).bytes
print(ct.hex())
ct2 = encrypt(plaintext, key, 10)
print(ct2.hex())
print()
assert ct == ct2
from wbkit.prng import NFSR, Pool
nfsr = NFSR(
taps=[[2, 77], [0], [7], [29], [50], [100]],
clocks_initial=128,
clocks_per_step=3,
)
prng = Pool(prng=nfsr, n=192)
from wbkit.masking import ISW, MINQ, DumShuf
# C = MINQ(prng=prng).transform(C)
# C.in_place_remove_unused_nodes()
# C.print_stats()
C = DumShuf(prng=prng, n_shares=3).transform(C)
C.in_place_remove_unused_nodes()
C.print_stats()
C = ISW(prng=prng, order=1).transform(C)
C.in_place_remove_unused_nodes()
C.print_stats()
ct = C.evaluate(Bin(plaintext).tuple)
ct = Bin(ct).bytes
print(ct.hex())
# from wbkit.serialize import RawSerializer
# RawSerializer().serialize_to_file(C, "circuits/aes10.bin")
# from wbkit.fastcircuit import FastCircuit
# C = FastCircuit("circuits/aes10.bin")
# ciphertext = C.compute_one(plaintext)
# print(ciphertext.hex())
# ciphertexts = C.compute_batch([b"my_plaintext_abc", b"anotherPlaintext"])
# print(ciphertexts)