🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #61267

Re: [FNTP] verifying that part reposts belong to a file - solution

#61267
From: Curt Welch
Date: Thu, 10 Oct 2002 05:40
207 lines
11302 bytes
Bas Ruiter <lordsnow@home.nl> wrote:

[quote moved from below]
> I think someone else mentioned binary trees in the previous discussion?

Not binary trees, but hash trees.  It is bascially the exact same concept
as what you posted below just done slightly differently.  I thought it up
as a solution to matching the hash to the data and preventing forging.  It
seems others have seen the same solution.

> To quote:

So who are you quoting and from where?  Is this your work or someone else?

> > To save space in the 0/N file, you can use hash trees.

Yes, the use of hash trees is the same idea I came to for the same reason,
you can greatly reduce the number of hash values you send.

And I propose putting the final hash (the one at the top of the tree) into
the Message-ID.  We will use that as the unique identifier for all files
posted to Usenet in the format.

Doing it like this means that you can take any single article, and veryify
that the data in the article is not forged, and that it is part of the file
which produces the hash in the Message-Id.  When you have it all bundled
like that, news servers can check these files when they are posted, or (if
you have the CPU ressources) even in transit, and reject them if they are
invalid or corrupted.  This is a wonderful thing to be able to do and I
think it justifies the amount of extra data you will have to send in every
article.

> > This means the 0/N file requires only one hash.  This is at a cost of a
> > including a signature of up to 2lg(L/C) hashes on sequence of parts you
> > post, in order to be able to verify any sequence of parts as it comes
> > in without having to verify the whole file.

Yeah, same iade, but drop the 0/N file because the hash is also in every
post in the Message-ID. (you can send a 0/N file for other reasons if you
like but it's not needed or desired for the file hash).

> > I will try to explain trees by an example: imagine a 512-byte file
> > divided into 8 parts of 64 bytes, called P1, P2, P3, P4, P5, P6, P7,
> > P8.
> >
> > Let W1 = H(P1), W2 = H(P2), ... , W8 = H(P8). H is your hash function.
> > Let X1 = H(W1|W2), X2 = H(W3|W4), X3 = H(W5|W6), X4 = H(W7|W8).
> > Let Y1 = H(X1|X2), Y2 = H(X3|X4).
> > Let Z = H(Y1|Y2).
> >
> > Put Z in the 0/N file.

What is the | function in the above notation?  It's not an OR is it like it
is in C?  You would never want to use OR.  But XOR might work ok.

If it is concatenat, then that was my plan as well.  I talked about doing
it not with only 2 hashs, but with the same size block you used at the
first level.  I had picked 1K blocks out of thin air.  With a 128 bit (16
byte) hash like MD5, that gives you 64 hashes to combine together into a 1K
block, and hash down to one hash at each node of the tree.

But, to minimize the number of hashes you need to include in the hash tree
of each post, you should use a binary tree like you used, not a 64-way tree
like I built.  I binary tree will have more levels, but less hash values
total.

I'm only a bit concernted that if you only hash two values to get one, that
it won't be as secure as if you were to hash more at each level of the
tree.

> > Suppose I wanted to send bytes 320-383 (P6). I'd post P6 and as a
> > signature W5, X4, and Y1. The receiver calculates W6 from P6, then from
> > W5 and W6 gets X3, then from X3 and X4 gets Y2, then from Y1 and Y2
> > gets Z. By comparing this Z with the Z in the 0/N file he knows he's
> > got the right P6, without needing to know any other part of the file.
> > But W5, X4, Y1 and Z do not allow an attacker to forge any part of the
> > file, assuming H is a cryptographically strong hash function.

And assuming that taking the hash of the hash values does not weaken the
security which it very well may.  I'd like to get advice on that from
people that know more about it than I do.

> > Now suppose instead I wanted to send bytes 256-447 (P5-P7). I post P5,
> > P6, P7; and as a signature on these three parts I post W8 and Y1. From
> > this the receiver can compute Z and match against the 0/N file. As you
> > see, I don't have to sign each 64-byte part separately, I can sign a
> > sequence of 64-byte parts and I just have to provide enough to complete
> > the tree down to Z. In no case will I need to post more than 4 hashes
> > to sign any sequence (for a 64MB file divided into 64 byte parts, this
> > figure goes up to only 40).

> I been kinda busy the last few days so not completely reading the posts
> - just skimming to keep up.
>
> But the above solution looks nice.
>
> It has the following implications:
>
> 1. a chunk size would have to be agreed upon (P above)

Yes.

> 2. reposts would always start at a boundary that's a multiple of P

> 3. an article can contain a repost that's a multiple of P.

I don't know why you say "repost".  I'm thinking of this for all binary
posts on usenet, not just "reposts".  And yes, all the segments would
have to begin and end on these hash chunk boundries.  So the amount
of data in each file will have to be an integer multiple of the
chunk size.

This means the chunk size should not be very large so when you split a
file up, you can still attempt to make all the parts somewhat close to
each other.  I'm still thinking something in the 1K size is about
right.

> 4. It probably means more data than needed is posted for a fill.
>    The waste would at most be 0.5 x P per article.

0.5 * P what?  I don't get what you are saying.  Oh, wait, I do get
what you are saying.  If you want to post some byte range, but are forced
to post more to make it align to the chunk size of P then you waste data,
but the waste can be up to 2P-2 bytes, not .5 P right?  But you don't need
to waste anything.  You just split it on the P boundries to start with.

This systems should be used for all posts, not just "reposts".  When
someone posts data and markes it with hash value X, you need a way to know
that they are telling the truth and that data really did come from a file
with that hash value and that it's not a fake, or an accidential
corruption.  So you make everyone label all files posted with this hash
value system, and they sign each post with the hash tree values as required
to prove to the rest of Usenet that the hash label they put on the post is
valid.

> The trick is to find a good size for P, so hash calculations
> are kept to a minimum, and so waste is also kept to a minimum.
> (read, minimum = acceptable levels)

There will be no waste to worry about if all posts are done like this.  But
you want the granularity low enough so all the posts come out to be about
the same size when the article size is chosen (which helps the articles
move at the same speed though usenet so they show up closer to the same
time and expire closer to the same time on servers).

The larger the P size, the smaller the hash tree, but doubling the size of
P only cuts the number of hash values by 1, so I suspect it's not going to
make much difference.

Ok, so to test a value, if P is 1KB, and we want to post a 128GB file in
chunks of 128KB each (trying to create a worse case example of a huge file
and small part size)... (this is a 1 million part post - that would be fun
to see).

The file is 2^37 bytes long.  1K is 2^10, so that gives us 2^27 P blocks in
the entire file so the hash tree is 27 hashes deep.  But 128KB articles
span 128 P blocks, which is 2^7 so that removes 7 levels of hash values
from what you need to include in each article, so that means you only need
to add a 20 hash values to each file to serve as the signature (well 19 I
guess because #20 is the file hash which you find in the message-id).  And
for MD5, that's only 300 bytes of extra signature data needed to for each
128K post (or 600 bytes if it's done in ascii hex).  Hell, you can get away
with putting that in the header.  That's very very workable from my point
of view.

For a more typical example, if you posted a 32MB file in 512K chunks (64
parts), the hash tree would be 15 deep for the file, but each post spans 8
levels of the tree so you only need 6 hash values included in each post
which is only 192 bytes of hex data to add to each header as the digital
signature for each post.  Cool.

Plus, if you can put the hash signature in the header, then the body can be
straight yEnc or uuencode and it becomes completely backward compatibale
with current yEnc multipart posts.  I was concerned because when I thought
the signature would be too large to fit in the header, there was no easy
way to put it in the body without breaking current decoding tools. ... But
now that I think about it, if the body was yEnc, and the signature was
something custom that just looked like text to all other decoders, then it
wouldn't cause problems adding it to the end of the post.  Yenc has an end
of data marker even for multpart posts so you can have text at the end of
each part (or article footers/signatures) without causing problems for yEnc
decoders.

But, with the hash signature system, we have something much better than the
crc used by yEnc so we can in the end just throw out yEnc, put all the file
info into the header, and make the body pure binary or something close to
it (like Content-Transfer-Encoding: X-UnidataEncoding which is a much
simpler and beter system than yEnc from my point of view).

And, since this hash system forces all file segments to be aligned on
blocks of size P (1K in my example), if we put the offset and segment size
in the message-Id like we have talked about, we can now do it in units of
size P - i.e. 1K blocks - which cuts out 10 bits from each of those numbers
to help (a little bit) make up for how large the Message-Id is going to get
for these things.

I think these ideas are just getting better and better.  I'm beginning to
feel the need to write proof of concept code....

>  Bas Ruiter

Cool stuff.

-- 
Curt Welch                                            http://CurtWelch.Com/
curt@kcwc.com                          Webmaster for http://NewsReader.Com/
Technical Details
Message-ID: <20021010014047.034$XV@newsreader.com>
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!news.uchicago.edu!newsswitch.lcs.mit.edu!newsfeed.cwix.com!newsfeed1.cidera.com!Cidera!feed2.newsreader.com!newsreader.com!news2.newsreader.com!ellis.newsreader.com!not-for-mail
References: <hpk9quk1cq0ti2reeu03epd0tgf4b8a8p0@4ax.com>

Show Full Headers
Complete Article Headers
Message-ID: <20021010014047.034$XV@newsreader.com>
Subject: Re: [FNTP] verifying that part reposts belong to a file - solution
Date: Thu, 10 Oct 2002 05:40:47 +0000
From: curt@kcwc.com (Curt Welch)
References: <hpk9quk1cq0ti2reeu03epd0tgf4b8a8p0@4ax.com>
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!news.uchicago.edu!newsswitch.lcs.mit.edu!newsfeed.cwix.com!newsfeed1.cidera.com!Cidera!feed2.newsreader.com!newsreader.com!news2.newsreader.com!ellis.newsreader.com!not-for-mail
Organization: NewsReader.Com
Newsgroups: news.software.nntp
X-Trace: NewsReader.Com xNk7P/RGjFf1F4Fn0q3NT48sc3JVlmvvY9Z9fMtYe,iXOx
X-Face: "p}G*1KH{+F7EYGKLb>ogDguabZ+%,?^epeFB!nzu`)`$=QcvL1KF6<0GH!Tbc!Sqo[|tV5
  %IW48mQf3K=Ci&gZ7]]aazx@]Y-nq!r5{yH/#,?@lDdUDvOfByB2hVW0.@OM%{l/{cT'{w
X-Url: http://CurtWelch.Com/
User-Agent: NewsReader.Com
Lines: 206