-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from GiacomoPope/sha_kat
- Loading branch information
Showing
18 changed files
with
16,738 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,32 @@ | ||
from hashlib import shake_128, shake_256 | ||
|
||
|
||
class ShakeStream: | ||
""" | ||
Written by David Buchanan | ||
""" | ||
Written by David Buchanan | ||
Taken from: | ||
https://github.com/pyca/cryptography/issues/9185#issuecomment-1868518432 | ||
""" | ||
def __init__(self, digestfn) -> None: | ||
# digestfn is anything we can call repeatedly with different lengths | ||
self.digest = digestfn | ||
self.buf = self.digest(32) # arbitrary starting length | ||
self.offset = 0 | ||
|
||
def read(self, n: int) -> bytes: | ||
# double the buffer size until we have enough | ||
while self.offset + n > len(self.buf): | ||
self.buf = self.digest(len(self.buf) * 2) | ||
res = self.buf[self.offset:self.offset + n] | ||
self.offset += n | ||
return res | ||
|
||
https://github.com/pyca/cryptography/issues/9185#issuecomment-1868518432 | ||
""" | ||
|
||
def __init__(self, digestfn) -> None: | ||
# digestfn is anything we can call repeatedly with different lengths | ||
self.digest = digestfn | ||
self.buf = self.digest(32) # arbitrary starting length | ||
self.offset = 0 | ||
|
||
def read(self, n: int) -> bytes: | ||
# double the buffer size until we have enough | ||
while self.offset + n > len(self.buf): | ||
self.buf = self.digest(len(self.buf) * 2) | ||
res = self.buf[self.offset : self.offset + n] | ||
self.offset += n | ||
return res | ||
|
||
|
||
def shake_128_hashlib(absorb): | ||
return ShakeStream(shake_128(absorb).digest) | ||
return ShakeStream(shake_128(absorb).digest) | ||
|
||
|
||
def shake_256_hashlib(absorb): | ||
return ShakeStream(shake_256(absorb).digest) | ||
return ShakeStream(shake_256(absorb).digest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Oops, something went wrong.