forked from chris-wood/keccak-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshake.py
More file actions
46 lines (38 loc) · 1.25 KB
/
shake.py
File metadata and controls
46 lines (38 loc) · 1.25 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
#! /usr/bin/python
"""
Extension of Keccak module to allow
XOF SHAKE-128 and SHAKE-256
"""
import Keccak
import sys
def shake128(msg, d):
"""
shake128 XOF returns a hexadecimal
digest of length d.
msg is the input hexadecimal message such as "90AB ..."
For more information refer to:
http://csrc.nist.gov/publications/drafts/fips-202/fips_202_draft.pdf
"""
mykeccak = Keccak.Keccak()
pad_msg = msg+"1111"
#msg is a hexadecimal string,
#size is the length of msg in bits
size = len(msg)*4
# r = 1344, c = 256, b = r+c = 1600
digest = mykeccak.Keccak((size,msg), 1344, 256, 0,d, False)
print digest, len(digest)*4
def shake256(msg, d):
"""
shake256 XOF returns a hexadecimal digest of length d.
msg is the input hexadecimal message such as "90AB ..."
For more information refer to:
http://csrc.nist.gov/publications/drafts/fips-202/fips_202_draft.pdf
"""
mykeccak = Keccak.Keccak()
pad_msg = msg+"1111"
#msg is a hexadecimal string,
#size is the length of msg in bits
size = len(msg)*4
# r = 1088, c = 512, b = r+c = 1600
digest = mykeccak.Keccak((size,msg), 1088, 512, 0, d, False)
print digest, len(digest)*4