mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-19 19:26:25 +00:00
hashutil: convenience methods for tagged and encoded hashes
In various cases, including Merkle Trees, it is useful to tag and encode the inputs to your secure hashes to prevent security flaws due to ambiguous meanings of hash values.
This commit is contained in:
parent
4b4f5bbcba
commit
99a046ab51
18
src/allmydata/util/hashutil.py
Normal file
18
src/allmydata/util/hashutil.py
Normal file
@ -0,0 +1,18 @@
|
||||
from allmydata.Crypto.Hash import SHA256
|
||||
|
||||
def netstring(s):
|
||||
return "%d:%s," % (len(s), s,)
|
||||
|
||||
def tagged_hash(tag, val):
|
||||
s = SHA256.new()
|
||||
s.update(netstring(tag))
|
||||
s.update(val)
|
||||
return s.digest()
|
||||
|
||||
def tagged_pair_hash(tag, val1, val2):
|
||||
s = SHA256.new()
|
||||
s.update(netstring(tag))
|
||||
s.update(netstring(val1))
|
||||
s.update(netstring(val2))
|
||||
return s.digest()
|
||||
|
Loading…
Reference in New Issue
Block a user