2007-03-30 01:11:30 +00:00
|
|
|
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()
|
|
|
|
|
2007-06-08 04:47:21 +00:00
|
|
|
# specific hash tags that we use
|
|
|
|
|
|
|
|
def tagged_hasher(tag):
|
|
|
|
return SHA256.new(netstring(tag))
|
|
|
|
|
|
|
|
def block_hash(data):
|
|
|
|
return tagged_hash("allmydata_encoded_subshare_v1", data)
|
|
|
|
def block_hasher():
|
|
|
|
return tagged_hasher("allmydata_encoded_subshare_v1")
|
|
|
|
|
2007-06-08 22:59:16 +00:00
|
|
|
def uri_extension_hash(data):
|
|
|
|
return tagged_hash("allmydata_uri_extension_v1", data)
|
|
|
|
def uri_extension_hasher():
|
|
|
|
return tagged_hasher("allmydata_uri_extension_v1")
|
2007-06-08 04:47:21 +00:00
|
|
|
|
2007-06-10 03:46:04 +00:00
|
|
|
def plaintext_hash(data):
|
|
|
|
return tagged_hash("allmydata_plaintext_hash_v1", data)
|
|
|
|
def plaintext_hasher():
|
|
|
|
return tagged_hasher("allmydata_plaintext_hash_v1")
|
|
|
|
|
|
|
|
def crypttext_hash(data):
|
|
|
|
return tagged_hash("allmydata_crypttext_hash_v1", data)
|
|
|
|
def crypttext_hasher():
|
|
|
|
return tagged_hasher("allmydata_crypttext_hash_v1")
|
2007-06-08 04:47:21 +00:00
|
|
|
|
|
|
|
def crypttext_segment_hash(data):
|
|
|
|
return tagged_hash("allmydata_crypttext_segment_v1", data)
|
|
|
|
def crypttext_segment_hasher():
|
|
|
|
return tagged_hasher("allmydata_crypttext_segment_v1")
|
|
|
|
|
|
|
|
def plaintext_segment_hash(data):
|
|
|
|
return tagged_hash("allmydata_plaintext_segment_v1", data)
|
|
|
|
def plaintext_segment_hasher():
|
|
|
|
return tagged_hasher("allmydata_plaintext_segment_v1")
|
|
|
|
|
|
|
|
def key_hash(data):
|
|
|
|
return tagged_hash("allmydata_encryption_key_v1", data)
|
|
|
|
def key_hasher():
|
|
|
|
return tagged_hasher("allmydata_encryption_key_v1")
|
|
|
|
|