Article View: news.software.nntp
Article #63017Content-SHA1-Tree
From: Kjetil Torgrim Homme
Date: Sat, 11 Jan 2003 03:28
Date: Sat, 11 Jan 2003 03:28
113 lines
6285 bytes
6285 bytes
I thought I'd try my hand at writing a specification of
Content-SHA1-Tree, but before foisting it on the MIME people, I guess
it's best that people here (at least Curt) has a look at it and sees
that it is right.
----- begins -----
Content-SHA1-Tree is a header which is used to verify the correct
transfer of a file. It differs from most other hashes in that it can
verify individual fragments of a file, with only the information
included in this header and the fragment itself.
The basic principle is to create an identifying hash which builds on a
tree of hashes. The file is split into blocks and the data in each
block is hashed, using SHA1 as the hashing algorithm.
+--------+--------+--------+--------+-- - - --+--------+
| block1 | block2 | block3 | block4 | | block8 |
+--------+--------+--------+--------+-- - - --+--------+
| | | | |
v v v v v
hash1 hash2 hash3 hash4 ... hash8
Each hashN is a 160 bits value. Concatenate hash1 and hash2, and run
SHA1 on those 320 bits. Let's call the resulting hash value hash12.
Do the same for hash3 and hash4, etc. Now move up a level, and run
SHA1 on the concatenation of hash12 and hash34, etc. Finally,
concatenate hash1234 and hash5678, run SHA1 on it. The result is the
hash used to identify the file.
hash1 hash2 hash3 hash4 hash5 hash6 hash7 hash8
| | | | | | | |
+---+---+ +---+---+ +---+---+ +---+---+
| | | |
hash12 hash34 hash56 hash78
| | | |
+-------+-------+ +-------+-------+
| |
hash1234 hash5678
| |
+---------------+---------------+
|
identifying hash
If we have all the data and the identifying hash, it is easy to verify
that the hash matches. If we only have some of the data (and the
identifying hash), we need either more data, or more hashes. Let's
say the file in question was split in three, with the first fragment
containing three blocks. It is easy to calculate hash1, hash2, hash3
and hash12 from the data, but then we're stuck. To continue the
calculation, we need hash4. Now we can calculate hash34 and hash1234.
If we're supplied with hash5678 as well, the identifying hash can be
verified. Hence, the first fragment only needs the hashes hash4 and
hash5678 to verify that the first three blocks are a genuine part of
the complete file.
To complete the example: Fragment 2, containing blocks 4, 5 and 6,
needs hashes hash12, hash3 and hash78. The last fragment needs hashes
hash1234 and hash56.
In order to fool this algorithm into verifying false data, you would
have to find a (false) value for hash5678, which, when hashed with the
hash1234 calculated from the false data, gives the identifying hash as
its answer. SHA1 is considered a cryptographically secure hash, that
is, there is no known way to create data which produces a given hash.
With current technology, this requires a brute force attack in a 160
bits namespace, and there isn't even any guarantee that the wanted
value can be found.
Content-SHA1-Tree contains the hashes needed to verify a fragment. In
the above example, the header of the first fragment is:
Content-SHA1-Tree: id-hash hash4 hash5678
The first hash in the list is always the identifying hash, but notice
that there is nothing to identify hash4 as hash4. This must be
deduced from the total size of the file and which blocks are included
in the fragment. Given that information, the above tree can be
constructed, and it is easy to spot which hashes are needed. The
order of the hashes is from the root and up, left to right, depth
first.
The total size of the file and the offset of the fragment into the
complete file is information which must be available from other
headers, e.g., Content-Disposition.
For completeness, here are the headers for fragment 2 and 3:
Content-SHA1-Tree: id-hash hash12 hash3 hash78
Content-SHA1-Tree: id-hash hash1234 hash56
Each hash is a 160-bit number presented in BASE64. It will generally
require 27 characters to encode, but with many leading zero bits, it
can be less. When used with large files, the number of hashes can
become quite large. It is suggested that the header is folded on
whitespace to keep line length down.
The size of a block must be constant across implementations. The
chosen value is 22500 octets. The last block may be less than that,
but there is no need to zero-pad the data (it will actually give the
wrong result if you do), SHA1 accepts blocks of data of arbitrary
size.
----- ends -----
did I miss anything an implementer needs to know? can the
presentation be improved (of course it can! please help! :-)
--
Kjetil T. | read and make up your own mind
| http://www.cactus48.com/truth.html
Technical Details
Message-ID:
<1r3co0fjr2.fsf@vingodur.ifi.uio.no>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!logbridge.uoregon.edu!uio.no!nntp.uio.no!ifi.uio.no!not-for-mailShow Full Headers
Complete Article Headers
Message-ID: <1r3co0fjr2.fsf@vingodur.ifi.uio.no> Subject: Content-SHA1-Tree Date: Sat, 11 Jan 2003 03:28:01 +0000 From: Kjetil Torgrim Homme <kjetilho@haey.ifi.uio.no> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!logbridge.uoregon.edu!uio.no!nntp.uio.no!ifi.uio.no!not-for-mail Newsgroups: news.software.nntp Organization: Dept. of Informatics, Univ. of Oslo, Norway Lines: 112 NNTP-Posting-Host: vingodur.ifi.uio.no Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: maud.ifi.uio.no 1042255682 2054 129.240.68.200 (11 Jan 2003 03:28:02 GMT) X-Complaints-To: abuse@ifi.uio.no NNTP-Posting-Date: 11 Jan 2003 03:28:02 GMT User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7