aboutsummaryrefslogtreecommitdiffstats
path: root/python3/sha3sum.py
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2013-08-10 07:24:48 +0200
committerMattias Andrée <maandree@operamail.com>2013-08-10 07:24:48 +0200
commitc4ff173c5150b7ef3e9359fc05e3e715401eb1a4 (patch)
tree1de5f2f2475c51604b9d5e090fe299668b0c98e1 /python3/sha3sum.py
parentsplit python2 version into two files (diff)
downloadsha3sum-c4ff173c5150b7ef3e9359fc05e3e715401eb1a4.tar.gz
sha3sum-c4ff173c5150b7ef3e9359fc05e3e715401eb1a4.tar.bz2
sha3sum-c4ff173c5150b7ef3e9359fc05e3e715401eb1a4.tar.xz
add support for concurrent threads in python3 version
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'python3/sha3sum.py')
-rwxr-xr-xpython3/sha3sum.py29
1 files changed, 15 insertions, 14 deletions
diff --git a/python3/sha3sum.py b/python3/sha3sum.py
index 32a96a7..4143652 100755
--- a/python3/sha3sum.py
+++ b/python3/sha3sum.py
@@ -275,13 +275,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
sys.exit(3)
stdin = None
fail = False
+ sha = SHA3()
for filename in files:
rc = ''
fn = '/dev/stdin' if filename is None else filename
with open(fn, 'rb') as file:
try:
if (filename is not None) or (stdin is None):
- SHA3.initialise(r, c, o)
+ sha.initialise(r, c, o)
blksize = 4096
try:
blksize = os.stat(os.path.realpath(fn)).st_blksize
@@ -294,7 +295,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
if len(chunk) == 0:
break
if not hex:
- SHA3.update(chunk)
+ sha.update(chunk)
else:
chunk = list(chunk)
n = len(chunk) >> 1
@@ -303,24 +304,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
a = ((a & 15) + (0 if a <= '9' else 9)) << 4
b = (b & 15) + (0 if b <= '9' else 0)
chunk[_] = a | b
- SHA3.update(bytes(chunk), n)
- bs = SHA3.digest(j == 1)
+ sha.update(bytes(chunk), n)
+ bs = sha.digest(j == 1)
if j > 2:
- SHA3.fastSqueeze(j - 2)
+ sha.fastSqueeze(j - 2)
if j > 1:
- bs = SHA3.squeeze();
+ bs = sha.squeeze();
if filename is None:
stdin = bs
else:
bs = stdin
if multi == 0:
for _ in range(i - 1):
- SHA3.initialise(r, c, o)
- bs = SHA3.digest(bs, j == 1)
+ sha.initialise(r, c, o)
+ bs = sha.digest(bs, j == 1)
if j > 2:
- SHA3.fastSqueeze(j - 2)
+ sha.fastSqueeze(j - 2)
if j > 1:
- bs = SHA3.squeeze();
+ bs = sha.squeeze();
if binary:
sys.stdout.buffer.write(bs)
else:
@@ -339,12 +340,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
rc += '\n'
sys.stdout.buffer.write(rc.encode('UTF-8'))
for _ in range(i - 1):
- SHA3.initialise(r, c, o)
- bs = SHA3.digest(bs, j == 1)
+ sha.initialise(r, c, o)
+ bs = sha.digest(bs, j == 1)
if j > 2:
- SHA3.fastSqueeze(j - 2)
+ sha.fastSqueeze(j - 2)
if j > 1:
- bs = SHA3.squeeze();
+ bs = sha.squeeze();
if binary:
sys.stdout.buffer.write(bs);
else: