mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-03-22 03:35:16 +00:00
rename storage_index_chk_hash() to storage_index_hash() and add TODO about how our use of it now includes keys that are not CHKs
This commit is contained in:
parent
a2e1f13fd8
commit
1d1628e525
@ -77,7 +77,7 @@ class CLI(unittest.TestCase):
|
||||
|
||||
def test_dump_cap_chk(self):
|
||||
key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
|
||||
storage_index = hashutil.storage_index_chk_hash(key)
|
||||
storage_index = hashutil.storage_index_hash(key)
|
||||
uri_extension_hash = hashutil.uri_extension_hash("stuff")
|
||||
needed_shares = 25
|
||||
total_shares = 100
|
||||
|
@ -124,7 +124,7 @@ class AssistedUpload(unittest.TestCase):
|
||||
# populating the directory manually.
|
||||
key = hashutil.key_hash(DATA)[:16]
|
||||
encryptor = AES(key)
|
||||
SI = hashutil.storage_index_chk_hash(key)
|
||||
SI = hashutil.storage_index_hash(key)
|
||||
SI_s = idlib.b2a(SI)
|
||||
encfile = os.path.join(self.basedir, "CHK_encoding", SI_s)
|
||||
f = open(encfile, "wb")
|
||||
|
@ -57,7 +57,7 @@ class Compare(unittest.TestCase):
|
||||
class CHKFile(unittest.TestCase):
|
||||
def test_pack(self):
|
||||
key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
|
||||
storage_index = hashutil.storage_index_chk_hash(key)
|
||||
storage_index = hashutil.storage_index_hash(key)
|
||||
uri_extension_hash = hashutil.uri_extension_hash("stuff")
|
||||
needed_shares = 25
|
||||
total_shares = 100
|
||||
@ -116,7 +116,7 @@ class CHKFile(unittest.TestCase):
|
||||
|
||||
def test_pack_badly(self):
|
||||
key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
|
||||
storage_index = hashutil.storage_index_chk_hash(key)
|
||||
storage_index = hashutil.storage_index_hash(key)
|
||||
uri_extension_hash = hashutil.uri_extension_hash("stuff")
|
||||
needed_shares = 25
|
||||
total_shares = 100
|
||||
|
@ -11,7 +11,7 @@ from foolscap.logging import log
|
||||
from allmydata.util.hashutil import file_renewal_secret_hash, \
|
||||
file_cancel_secret_hash, bucket_renewal_secret_hash, \
|
||||
bucket_cancel_secret_hash, plaintext_hasher, \
|
||||
storage_index_chk_hash, plaintext_segment_hasher, key_hasher
|
||||
storage_index_hash, plaintext_segment_hasher, key_hasher
|
||||
from allmydata import encode, storage, hashtree, uri
|
||||
from allmydata.util import idlib, mathutil
|
||||
from allmydata.util.assertutil import precondition
|
||||
@ -404,7 +404,7 @@ class EncryptAnUploadable:
|
||||
e = AES(key)
|
||||
self._encryptor = e
|
||||
|
||||
storage_index = storage_index_chk_hash(key)
|
||||
storage_index = storage_index_hash(key)
|
||||
assert isinstance(storage_index, str)
|
||||
# There's no point to having the SI be longer than the key, so we
|
||||
# specify that it is truncated to the same 128 bits as the AES key.
|
||||
|
@ -50,9 +50,9 @@ class CHKFileURI(_BaseURI):
|
||||
self.needed_shares = needed_shares
|
||||
self.total_shares = total_shares
|
||||
self.size = size
|
||||
self.storage_index = hashutil.storage_index_chk_hash(self.key)
|
||||
self.storage_index = hashutil.storage_index_hash(self.key)
|
||||
assert len(self.storage_index) == 16
|
||||
self.storage_index = hashutil.storage_index_chk_hash(key)
|
||||
self.storage_index = hashutil.storage_index_hash(key)
|
||||
assert len(self.storage_index) == 16 # sha256 hash truncated to 128
|
||||
|
||||
@classmethod
|
||||
|
@ -32,10 +32,15 @@ def tagged_pair_hash(tag, val1, val2):
|
||||
def tagged_hasher(tag):
|
||||
return SHA256(netstring(tag))
|
||||
|
||||
def storage_index_chk_hash(data):
|
||||
def storage_index_hash(key):
|
||||
# storage index is truncated to 128 bits (16 bytes). We're only hashing a
|
||||
# 16-byte value to get it, so there's no point in using a larger value.
|
||||
return tagged_hash("allmydata_CHK_storage_index_v1", data)[:16]
|
||||
# TODO: remove the word "CHK" from this tag since we use this same tagged
|
||||
# hash for random-keyed immutable files, mutable files, content-hash-keyed
|
||||
# immutabie files. Or, define two other tagged hashes, one for each kind.
|
||||
# (Either way is fine -- we can never have collisions of storage indexes
|
||||
# anyway, since we can't have collisions of keys.)
|
||||
return tagged_hash("allmydata_CHK_storage_index_v1", key)[:16]
|
||||
|
||||
def block_hash(data):
|
||||
return tagged_hash("allmydata_encoded_subshare_v1", data)
|
||||
|
Loading…
x
Reference in New Issue
Block a user