forked from chris-wood/keccak-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadMe.txt
More file actions
executable file
·110 lines (82 loc) · 5.84 KB
/
ReadMe.txt
File metadata and controls
executable file
·110 lines (82 loc) · 5.84 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
Content
-------
List of files:
- Keccak.py : the Keccak and KeccakError classes
- shake.py : implements extendable output functions SHAKE-128 and SHAKE-256
- demo_KeccakF.py : example of use of Keccak_f function on a 0-filled 5×5 matrix
- demo_TestVectors.py : verification of Short/Long test vectors. The test vectors must be copied in the same location as the Python files
Few words of explanation
------------------------
The Keccak module is stateless. It takes your inputs, performs the computation and returns the result.
Typical uses
------------
1) Compute a hash using Keccak[r=1152, c=448, d=28] (224 bits of output) on '00112233445566778899AABBCCDDEEFF' (8*16bits=128 bits)
>>> import Keccak
>>> myKeccak=Keccak.Keccak()
>>> myKeccak.Keccak((128,'00112233445566778899AABBCCDDEEFF'),1152,448,28,224,True)
Create a Keccak function with (r=1152, c=448, d=28 (i.e. w=64))
String ready to be absorbed: 00112233445566778899AABBCCDDEEFF011C90010000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000 (will be completed by 56 x '00')
Current value of state: Before first round
['0x7766554433221100L', '0xffeeddccbbaa9988L', '0x1901c01', '0x0', '0x0']
['0x0', '0x0', '0x0', '0x0', '0x0']
['0x0', '0x0', '0x0', '0x0', '0x0']
['0x0', '0x0', '0x0', '0x0', '0x0']
['0x0', '0x0', '0x0', '0x0', '0x0']
Current value of state: Satus end of round #1/24
['0xdcf7ae5456dd06cdL', '0x22901776e5544300L', '0x7e6e4e6f7e6e5e6eL', '0x8019d44fc4570000L', '0x8a218b329807ab3L']
['0x567099498aa11005L', '0xa9866666600eeacaL', '0xe4304ddaaffcc9beL', '0x45204eaccaa88600L', '0xb77bbfbbb77bbffbL']
['0x1111110117516115L', '0x371ffb68ae8462d1L', '0x224675288a45ff10L', '0xddba8867573200efL', '0x4c3bf7a24e1fd5cL']
['0xcb3621d00752651cL', '0x13f17c0ab99bcfb5L', '0x985510c008a589d5L', '0x2cd47cc54bb21ab7L', '0x3541100ff888089fL']
['0x5deab70448dba553L', '0x88e623889922fac2L', '0x77885477265dc032L', '0x8804819c95f1338cL', '0xdd995510c008ec05L']
<...>
Current value of state: Satus end of round #24/24
['0x39ff0529da2f89f0L', '0x75288cb96c2dd5e9L', '0x98534de599eff2a2L', '0xea94bda8d3e9387cL', '0x220779e8cb82b41cL']
['0x506d59a9b6439571L', '0xcc245627703d61a6L', '0x7130e0926ec89e4L', '0xdde96db68bc6fe96L', '0xcdf10c08b69c63f1L']
['0x17263b71ff50b825L', '0x624621dcf40fbadL', '0xf832f9debeed67e6L', '0xbfacbb515102948L', '0x95e7f953edbc171bL']
['0x47674cd342495774L', '0x387edb9045d2bde4L', '0x956529cea8859f3cL', '0x2f834e8a8584e7e4L', '0xa3b4d17a2b9fb5f2L']
['0x60fe21fea35e6553L', '0x9d4188dc79aa5db2L', '0xad3cea397748254dL', '0x523bfabdccf20597L', '0xe358001d8e70846L']
Value after absorption : F0892FDA2905FF39E9D52D6CB98C2875A2F2EF99E54D53987C38E9D3A8BD94EA1CB482CBE8790722719543B6A9596D50A6613D702
75624CCE489EC26090E130796FEC68BB66DE9DDF1639CB6080CF1CD25B850FF713B2617ADFB40CF1D622406E667EDBEDEF932F848291015B5CBFA0B1B17BCED53F
9E79574574942D34C6747E4BDD24590DB7E383C9F85A8CE296595E4E784858A4E832FF2B59F2B7AD1B4A353655EA3FE21FE60B25DAA79DC88419D4D25487739EA3
CAD9705F2CCBDFA3B524608E7D80180350E
Value after squeezing : F0892FDA2905FF39E9D52D6CB98C2875A2F2EF99E54D53987C38E9D3A8BD94EA1CB482CBE8790722719543B6A9596D50A6613D7027
5624CCE489EC26090E130796FEC68BB66DE9DDF1639CB6080CF1CD25B850FF713B2617ADFB40CF1D622406E667EDBEDEF932F848291015B5CBFA0B1B17BCED53F9
E79574574942D34C6747E4BDD24590DB7E383C9F85A8CE296595E4E784858A4E832FF2B59F2B7AD1B4A353655EA3FE21FE60B25DAA79DC88419D4D25487739EA3C
AD9705F2CCBDFA3B524608E7D80180350E
'F0892FDA2905FF39E9D52D6CB98C2875A2F2EF99E54D53987C38E9D3'
2) Computation of the Keccak-f function on an all-zero state
>>> import Keccak
>>> A=[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]
>>> myKeccak=Keccak.Keccak(1600)
>>> myKeccak.Keccakf(A, True)
>>> myKeccak.printState(A,'Final result')
Current value of state: Before first round
['0x0', '0x0', '0x0', '0x0', '0x0']
['0x0', '0x0', '0x0', '0x0', '0x0']
['0x0', '0x0', '0x0', '0x0', '0x0']
['0x0', '0x0', '0x0', '0x0', '0x0']
['0x0', '0x0', '0x0', '0x0', '0x0']
Current value of state: Satus end of round #1/24
['0x1L', '0x0L', '0x0L', '0x0L', '0x0L']
['0x0L', '0x0L', '0x0L', '0x0L', '0x0L']
['0x0L', '0x0L', '0x0L', '0x0L', '0x0L']
['0x0L', '0x0L', '0x0L', '0x0L', '0x0L']
['0x0L', '0x0L', '0x0L', '0x0L', '0x0L']
<...>
Current value of state: Satus end of round #24/24
['0xf1258f7940e1dde7L', '0x84d5ccf933c0478aL', '0xd598261ea65aa9eeL', '0xbd1547306f80494dL', '0x8b284e056253d057L']
['0xff97a42d7f8e6fd4L', '0x90fee5a0a44647c4L', '0x8c5bda0cd6192e76L', '0xad30a6f71b19059cL', '0x30935ab7d08ffc64L']
['0xeb5aa93f2317d635L', '0xa9a6e6260d712103L', '0x81a57c16dbcf555fL', '0x43b831cd0347c826L', '0x1f22f1a11a5569fL']
['0x5e5635a21d9ae61L', '0x64befef28cc970f2L', '0x613670957bc46611L', '0xb87c5a554fd00ecbL', '0x8c3ee88a1ccf32c8L']
['0x940c7922ae3a2614L', '0x1841f924a2c509e4L', '0x16f53526e70465c2L', '0x75f644e97f30a13bL', '0xeaf1ff7b5ceca249L']
[[17376452488221285863L, 18417369716475457492L, 16959053435453822517L, 424854978622500449L, 10668034807192757780L], [9571781953733
019530L, 10448040663659726788L, 12224711289652453635L, 7259519967065370866L, 1747952066141424100L], [15391093639620504046L, 101139
17136857017974L, 9342009439668884831L, 7004910057750291985L, 1654286879329379778L], [13624874521033984333L, 12479658147685402012L,
4879704952849025062L, 13293599522548616907L, 8500057116360352059L], [10027350355371872343L, 3500241080921619556L, 140226327413610
143L, 10105770293752443592L, 16929593379567477321L]]
3) SHAKE
>>> from shake import *
>>> shake128("001122", 1024)
>>> shake256("001122", 1024)