🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #62448

Re: xBin (Power-Post 2003 - requesting input from authorities..)

#62448
From: Rene
Date: Wed, 25 Dec 2002 16:35
431 lines
22693 bytes
curt@kcwc.com (Curt Welch) wrote:
> > Yes you can do that. Since CPU time is however much more cheaper than
> > bandwith it makes sense to pre-compute the header data. Its cheap to
> > get them and as an additional bonus, the newsreader can tell its user
> > "I currently see X valid parts of Y".
> Are you talking about downloading all the headers and collecting all the
> Signature information first?  That won't tell you if the article is
> valid. The data could be bogus or corrupted still.  You have to download
> the entire article to know if you have a valid part.

Yes that's right. But I need to download only ONE valid block. After that,
I have a partially hash tree in memory and can compare the headers with my
hash tree.

Let's take my N=8 tree example again. Suppose each article contains only
one block.

      root
     /     \
    e       f
  /  \    /  \
 a   b   c   d
/ \ / \ / \ / \
1 2 3 4 5 6 7 8

The root is known anyway. I download one article, lets say nr4. The
article's header contains the hashes 3, a, f. I decode the article,
calculate hash 4. Now I check hashes 3 and 4 result in b. a + b = e, e + f
= root. The block is accepted and validated. But as a side effect I now
have the validated hashes 3, 4, a, b, e, f.
Posts 1 and 2 will include hashes b and f in their header. I can check
these. Post 3 will include hashes 4, a, f in its header, I can check these.
Posts 5 to 8 will include hash e in its header.

The more valid parts I download, the more validated hashes I will have in
my tree.

Now this simply means that if an attacker wants to fake headers, he must
know the hashes in the tree nodes. But he can't do that unless he downloads
parts and calculates the valid tree by himself. So there can't be a
pro-active spamming a ng with bogus articles, because those can be spotted
from afar.

If there is a file being reposted later, a prospective attacker might have
a tree ready to create "good looking" headers. So this is just an added
"small" bonus.

If xBin becomes accepted and widely used, then an attacker creating
additional messages knows, that the only thing he can do is force a user to
download his parts and reject them. He can't cause file corruption any
longer. If then servers start to perform the checks themselves and discard
faulty messages, that attack becomes utterly useless.

Best way to stop xBin files is imho trying to kill the messages. And that,
to my understanding, will only be possible if you can get all server
operators to do that.

> Also, given only the signature data from one article, you don't have
> enough information to calculate the hash, so you have no way of knowning
> if the data from that article is valid.  If you have enough articles, you

If I have limited knowledge of the tree, by having at least one valid
block, I can decide if the header is fundamentally wrong or not.

> to solve.  Just start downloading the aticles, thrown them away if you
> find they are bogus, or else keep the data if you find they are good.

Its a small addition to that basic method. It is completely superfluous
until attackers start sending bogus articles for xBin files and your
newsreader doesn't want to download 5 bogus articles for every valid one.
Unless the attacker learns how to recreate the header-data, of course.

> Now the one thing we could do is add a few more hash values in the
> signature so it includes the hash values for the data in the article as
> well, then you would be able to verify that the signature hash values are

I don't think that's neccessary. In fact, that drops some of the security
of the system. If the current block's hash is included in the header, I can
malicously create a block of junk data. Hash it, and create hashes up just
to the root. (using my picture above, lets say I have made a bogus part 1
plus all hashes up to e) Now all that's left for me to do, is to find one
single hash f' so that my bogus e + f' are resulting in the root hash.

Only one hash collision to find. Since the hashes are 20bytes, thats 320
bits input giving one SHA-1 round (actually 512bits, but the padding is
known) yielding 160bits hash. Probably easy to find / create a collision.

Now *if* thats possible, then I can create articles with bogus blocks and
valid looking headers, even with hashes that add up correctly to the root,
but which are utterly corrupt.

If a newsreader picks up such a bogus-xBin part first, he won't be able to
complete the file because the bogus/real parts won't fit somewhen later due
to the newsreader having built up a fake tree.

> The nice thing about adding the extra hash values to the signature is
> that looking at the Signature: header alone, you would be able to verify
> all those values were valid without the help of any other data.  But for
> part sizes around 1MB, you might have to add as many as 7 additional hash
> values to a header which I fear might already be too large for very large
> posts.

Its no good idea either.

Oh just had a minor revelation. My pseudocode is more severly broken than I
thought first. Suppose the n=8 tree above. I one article spans blocks 1-4,
then the only hash in the header is f (and root). This means it is not
possible to process and validate the blocks within one article
sequencially. You need to decode all blocks first, then start validating
the tree hashes. In the example with 1-4, if one block has a bit error
(from decoding or whatever) then it can't be decided which is faulty and
which not, and all must be dropped. Again: Depending on position if some
blocks span the left-half of the tree and some the right-half, then not all
blocks need to be dropped. Some can still be validated.

Hm I can adapt to that, need to rework the pseudocode though...

> > If the tree is non-power of two, then you still create a tree the size
> > of the next larger power-of-two value and insert some "nonexistent"
> > nodes there. I've yet to formalize the rules of the creation of the
> > tree. Target is, to be able to create exactly one, well defined tree by
> > use of only one parameter: "number of blocks".
> It's very easy to write code to construct it.  Coming up with a formula
> to calcaute things like the number of hash values in the signature is
> what I have not seen a solution for yet.  Writing code to calcuate that
> is easy as well.

Yes writing the code for that is easy, but I'm not seeing an easy formula
either.

> > Depth of the tree will be log2(N), whereas N either is already a power
> > of two, or is being rounded up to be one.
> int(log2(N-1))) + 1 should do it where int() takes the interger value of
> the number and throws away the fractional part.

Right. Is int() used as a typecast here? Usually the function's called
trunc() or truncate()

> > Actually thinking about it: The worstcase is one article containing all
> > blocks, since that article will need to contain 2*N-1 hashes. (all of
> > them)
> Ah.  You are confused.  Or just not thinking like I am.  The signature
> does not include the hash values for the blocks in the current article.
> It only includes the hash values for the data not in the current
> articles.

You're right I was confused there or to be more exact, I forgot about that
"detail". The basic rule is: "Don't send any hash that can be computed,
only send the complement(s) needed to be able to reach the root."

> One post that includes all the data is the best case.  It has no hash
> values in the signature.

Well it has one, the root hash. Actually, is that necessary? I understand
it is there for a newsreader to search on using a "XHDR X-Bin-Signature"
however a newsreader could just as well skim through the message-id's no?

> > > Ah, I'm beginning to see it.  This is the same problem as counting
> > > the number of bits turned on in a binary number.
> > >Ah, but it's not even that simple because that gives you the correct
> > >value for the left side (which starts at the beginning of the file and
> > >is correctly aligned with the binary tree), but the number required
> > >for the right side depends on the alignment of the block with the
> > >binary tree for the entire file.
[..]
> Well if you have 8 in the article, then you need hash values which cover
> blocks 1 to 7.  That's less than 8, so the first hash value will cover
> only 4 blocks, leaving 3 more blocks to cover, so the next hash value
> will cover 2 blocks, the last hash value will cover 1.
> So those hash values are e, c, 7.  4+2+1 == 7 blocks covered by those 3
> hash values.  Binary for 7 is 111 which has 3 bits turned on which the
> number of hash values you need for the blocks to the left of the segment
> included in the file.

I think I have that solved now. Still it is no formula which gives the
worst case but it is a formula which gives you the number of hashes for any
given sequence of blocks.

To be given:
 N = number of blocks
 a,b = start and end of block sequence (inclusive)

calculate:
 P = next greater power-of-two from N (P = trunc(log2(N-1))) + 1 )
 X = 2*N-2 (number of total hashes in the tree minus the root)

First, check to see if sequence spans the middle:
IF(P/2 in (a,b) AND P/2+1 in (a,b)) THEN
// ok it does span the middle
  temp = a-1; // get value left of sequence
  r1 = bitcount(temp); // count number of 1 bits in temp
  temp = hashcover(b); // calculate hashcover of b (see below)
  temp = X - temp;     // subtract hashcover from total
  r2 = bitcount(temp); // count number of 1 bits
  RETURN r1+r2;  // result if sequence spans middle
ELSE
  IF(a < P/2) THEN   // is sequence in left half?
    left = a-1;
    right = P/2 - b);
  ELSE // sequence is in right half
    left = a - P/2+1;
    right = N - b;
  END;
  r1 = bitcount(left);
  r2 = bitcount(right);
  RETURN = r1+r2+1;
END

Hashcoverfunction (input integer N)
r = 0;
c = 0;
bitmask = 0x1;
REPEAT
 IF(N & bitmask != 0) THEN
   r = r + (2*bitmask-1);
   c = c + bitmask;
 END;
 bitmask << 1;
UNTIL(c = N);
RETURN r;

Discussion of this algorithm:

First what does Hashcover do? It calculates, how many hashes a sequence
from 1 to n are completely defined by those n leaves. What the algorithm
does: it breaks N into its power of two components and for each of those
(p) components it adds 2*p-1. Its actually just calculating the number of
hashes within each subtree according to the rule 2*num_of_nodes - 1 =
number of hashes total. However each power of two spans its own subtree.

Now how does the main algorithm work? Well we have to differ 2 situations.
(a) a sequence remains in one half of the tree or (b) the sequence spans
the middle.

For situation a, I must simply know how many hashes I need to be able to go
up to the child of the root node. Then I need to add 1 (this is the other
child of the root node) so I can calculate the root itself.

But how do I know how many hashes I will need ? Well we look first at the
left side of our sequence. As Curt has already stated, just take the number
of the block left of the sequence and count the number of 1 bits in that
value. That many hashes are needed. Now get the number of how many blocks
are to the right of our sequence up to the middle and do the very same. Add
those two values together and you have the number of hashes needed to reach
the child of the root. As already stated, add one to be able to calculate
the root itself.

Now the real beauty is, this even works for a incomplete tree (ie the right
side) Test it ! I had to do this several times until I was sure it works.

So basically : leftvalue is the number of blocks left of my sequence downto
1 or downto the middle and rightvalue is the number of blocks right of my
sequence up to N or the middle. Then just add bitcount of left- and
right-value plus one and you have it.

This leaves situation b, where the sequence crosses the middle. The left
side again is easy: Get the number of blocks from 1 to (a-1), which is just
a-1. Perform bitcount on a-1 and you know the number of hashes needed for
the left side. Now calculate the hashcover of our rightmost block (b)in the
sequence. This value now is simply the number of hashes we cover, when we
have the nodes 1 to b. And we truly have those, because the bitcount from 1
to (a-1) gives us the left hashes and the sequence (a,b) gives us the rest.
So what do we need to know from the right subtree past block b? Well
calculate how many hashes are left in total. Thats exactly X minus the
hashcount we just calculated. And now we're set, because you just take the
bitcount of that value...

> > The hash is 160 bits large, that's 20 bytes (yielding 40 chars, not 20
> > like I wrote before). So we best take those 20 bytes and encode them
> > somewhat (you use uuencode, as I've seen)
> It's Mime Base64 actaully.  The hash is 27 bytes in base64.

Ok my fault, you even wrote this in your first message. I can't distinguish
base64 from uuencode from sight.

> > Could we yEnc the 20 hash bytes in the header? Or not yEnc, because
> > yEnc rotates the byte-value, assuming there are less "00" that way. A
> > hash value byte though has an equal probability on every single of the
> > 256 values.
> You could, but it would get weird.  I think if there are news servers
> that have problems with headers that long, the better option is to look
> at multiple header solution than trying to compress the data into one
> header and make it that much more unreadable.

Yes that's a possibility. If an article contains blocks 7-12, then it
simply would have headers x-Bin-Signature[7-12] or something like this,
additionally to the Signature which defines what blocks are in this
article. Its way less slick but its a possibility, if header length is a
problem.

> I guess the other issue is that the only thing keeping it from growing is
> the header size issue, and if this became a wide spread standard and
> needed 2KB headers to work for the huge posts, then the servers that
> couldn't deal with it would be under a lot of pressure to change.  So if
> the servers can deal with the heaaders for the size files people are
> positing today, then it might be ok to push the problem off onto the
> servers.  That would be even more justifable if "most" servers today
> didn't have a problem with 2KB header lines.  My server doesn't for
> example.  So that's one.

Yes, if the majority of servers handle this, its ok to force the rest to
adapt. Though it is not very nice to those that need to change, of course.
There might even be mixed cases, ie where a server transports such articles
with long headers very easily, however if you do a XHDR X-Bin-Signature
over it, it returns the header truncated or not at all.

> > Don't know, you are the server guy :) I suspect however that headers
> > get indexed at servers. If I issue a XHEAD command in a newsgroup with
> > 1'000'000 articles, I really doubt the server opens every single
> > file/article and gathers the headers toghether. I think headers are
> > indexed in a special database in advance, and if so, they probably DO
> > have a size constraint.
> Most servers special cate the XOVER headers, but none that I'm aware of
> special case all the headers.  Some servers only allow you do do an XHDR
> on headers in the special XOVER database.  Some allow you to do it on any
> header, but if it's a non xover header, yes, it fetches the data from
> each article.
>
> But the articles are stored in special spools which are designed to be
> fast to access so you don't have to do something like open a file for
> each article.  You do have to seek an read at least one block for every
> header however.

Could put quite a stress on servers if the access pattern of half of its
users change. A server which does not allow XHDR X-Bin-Signature however
will be a nuisance to a newsreader, since then the newsreader needs to fall
back to reg-exping the message-id's to retrieve all the articles.

> yes.  The only minor catch is that a few too many servers have "broken"
> history files which are used to look up articles by Message-ID.  They
> have problems of beeing to shourt for the server and Message-IDs will
> expire from the history before the article expires from the server.
> After that, you can't find it by Message-ID even though you can find it
> by group and article number still.

Well, that's a broken server in that case. If that's quite common though,
then a newsreader does need to implement the "fallback" methode I wrote
above.

> Right, if you try to equalize the size of the articles, and do it right,
> the last N will be 1 block shorter than the others (where N is a function
> of the filesize and the article size you pick).  So the block size
> defines how close in size the articles in a multipart post can be.

So you are saying, from a server perspective, it is better to have 95 parts
of the same size and 5 parts slightly smaller than having 99 parts of the
same size and 1 part a lot smaller?

In any case, that's the job of the posting software to achieve. I'm
personally interested in writing a decoder. The encoder I leave to others.

> > Before I start some real coding, some things need to be defined first:
> > - The exact building rule for the tree
> What is in question?  Using SHA-1, you get a 20 byte hash.  To combine
> the two hashes together, you put them in a 40 byte array with the first
> 20 bytes filled in with the hash for the lower block numbers.  You then
> hash that 40 byte chunk of data.

No, the filling of the tree is clear to me. What is not clear is how skewed
trees are exactly built. That is, I know how I would do it, but that does
not necesarily comply with your idea.

> For files which don't have a number of blocks which is a power of 2, you
> will end up with hash values in the tree where it's matching pair doesn't
> exist.  For those, you just take the hash value unchanged to the next
> higher level.

Let me rephrase this: We start by "lining" up the block nodes. Any space
between the last node and the next power of two is filled by a
"nonexistant" node. Then the tree is build by creating parents of the
leaves until we have a root. Whenever a parent has only one real child (ie
a right side "nonexistant"-node) then the hash-value of the left node is
promoted up to this parent.

So having a tree with 9 nodes means that block 9's hash is actually saved
in the right child of the root node. Correct?

> > If I understand you correctly, you're saying that will create "virtual
> > segements" ie segments that do not really exist, because the file will
> > be sent as one not segmented. But for the generation of PAR files, the
> > newsreader/poster looks at it as if it were. Is that right?
> Right.  The PAR file is specified as if large file had been split up
> somehow.
>
> The problem is that this might make it too hard for someone trying to
> find and download PAR files by to figure out which PAR files they need.
> But mayne not.  If you generate them for the articles as they were
> posted, then the subject just needs to point out that this is PAR1 for
> articles 0256-0512 etc.

Well since using virtual segments, this throws out any manual intervention
anyhow. The newsreader getting blocks must implement this functionality. So
its the newsreaders job to localize the par's. Which means there must be a
machine-readable indicator.

I guess that means: Either par-technology (actually RS-coding) is part of
the xBin standard or it is taken care now that it can be implemented later.

> > > But 8 bit Reed-Solomon coding is limited in the number of "files" it
> > > can protect.  It think that number is 128 or 256.  Or maybe it's
> > > actually that the number of data files + the number of par files you
> > > want post has to <= 256??
> > From your posted link, the m + n values (number of segments plus all
> > part files ever) may not be >= 2^wordsize. Using a wordsize of 16 bits,
> > that's already a safe value of 65535...
>
> Well, to calcuate the missing data, you have to read all the other files
> in the set.  If you have a 1,000 article set with 1 part missing and you
> downloaded 1 par file, for the algorithm to figure out the missing data
> it has to scan all 1000 articles.  And when you generate the par files,
> you also have to scan the entire file and do the math.  It's probably
> better to limit the range of the par files to something like 100 articles
> just to prevent having to read so much data to calcuate the missing
> blocks.

You need to scan the entire file anyway (even if it has missing blocks)!
Well a newsreader downloading an xBin file should only create one file with
the final size (the size is in the Signature-header, so that's possible)
and fill in data as it recieves and validates them. If a newsreader wants
to create as many files as there are blocks, then that's their business. It
will have 1000 fopen's then, yes.

> > Happy chritsmas !
> Same to you!

Thanks, already over now though :)

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB
Technical Details
Message-ID: <20021225113500.563$i1@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!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!38.144.126.70.MISMATCH!feed3.newsreader.com!newsreader.com!news2.newsreader.com!ellis.newsreader.com!not-for-mail
References: <cdda0v4h6t52ov7abf1j0qkpo843itf4se@4ax.com> <cfka0vsbjdlbdmtv2gg8qnehok033qh5f1@4ax.com> <20021223041127.986$6M_-_@newsreader.com> <1rfzsoaacf.fsf@vingodur.ifi.uio.no> <20021223180543.105$Wn@newsreader.com> <20021223185652.700$BS@newsreader.com> <20021223203608.351$Qp@newsreader.com> <20021223223311.286$Mx@newsreader.com> <20021224034919.081$PY@newsreader.com> <20021224151028.847$pv@newsreader.com> <20021225035755.305$XK@newsreader.com>

Show Full Headers
Complete Article Headers
Message-ID: <20021225113500.563$i1@newsreader.com>
Subject: Re: xBin (Power-Post 2003 - requesting input from authorities..)
Date: Wed, 25 Dec 2002 16:35:00 +0000
From: Rene <invalid@email.addr>
References: <cdda0v4h6t52ov7abf1j0qkpo843itf4se@4ax.com> <cfka0vsbjdlbdmtv2gg8qnehok033qh5f1@4ax.com> <20021223041127.986$6M_-_@newsreader.com> <1rfzsoaacf.fsf@vingodur.ifi.uio.no> <20021223180543.105$Wn@newsreader.com> <20021223185652.700$BS@newsreader.com> <20021223203608.351$Qp@newsreader.com> <20021223223311.286$Mx@newsreader.com> <20021224034919.081$PY@newsreader.com> <20021224151028.847$pv@newsreader.com> <20021225035755.305$XK@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!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!38.144.126.70.MISMATCH!feed3.newsreader.com!newsreader.com!news2.newsreader.com!ellis.newsreader.com!not-for-mail
Organization: NewsReader.Com Subscriber
Newsgroups: news.software.nntp
X-Trace: NewsReader.Com S6k8A-5lOx321jEYVH+MQWoCv8pSgCemE48c0RLiF_@n1o9PHG
Lines: 430