From: Zooko O'Whielacronx Date: Fri, 1 Feb 2008 19:27:37 +0000 (-0700) Subject: rename storage_index_chk_hash() to storage_index_hash() and add TODO about how our... X-Git-Url: https://git.rkrishnan.org/components/%22news.html/about.html?a=commitdiff_plain;h=1d1628e52573ad44b7b3325f47d3e093200ca424;p=tahoe-lafs%2Ftahoe-lafs.git 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 --- diff --git a/src/allmydata/test/test_cli.py b/src/allmydata/test/test_cli.py index bb1d704b..7d941985 100644 --- a/src/allmydata/test/test_cli.py +++ b/src/allmydata/test/test_cli.py @@ -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 diff --git a/src/allmydata/test/test_helper.py b/src/allmydata/test/test_helper.py index 6fa96585..85995124 100644 --- a/src/allmydata/test/test_helper.py +++ b/src/allmydata/test/test_helper.py @@ -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") diff --git a/src/allmydata/test/test_uri.py b/src/allmydata/test/test_uri.py index 6b3cee0c..7ccd3278 100644 --- a/src/allmydata/test/test_uri.py +++ b/src/allmydata/test/test_uri.py @@ -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 diff --git a/src/allmydata/upload.py b/src/allmydata/upload.py index 7a9d0b34..ed147f16 100644 --- a/src/allmydata/upload.py +++ b/src/allmydata/upload.py @@ -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. diff --git a/src/allmydata/uri.py b/src/allmydata/uri.py index 51ebec87..44df1f48 100644 --- a/src/allmydata/uri.py +++ b/src/allmydata/uri.py @@ -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 diff --git a/src/allmydata/util/hashutil.py b/src/allmydata/util/hashutil.py index 218be2ed..1dfcb2a4 100644 --- a/src/allmydata/util/hashutil.py +++ b/src/allmydata/util/hashutil.py @@ -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)