Article View: news.software.nntp
Article #61289Re: [FNTP] verifying that part reposts belong to a file - solution
From: Curt Welch
Date: Thu, 10 Oct 2002 20:04
Date: Thu, 10 Oct 2002 20:04
149 lines
8813 bytes
8813 bytes
"Brian Truitt" <btruitt@rcn.com> wrote: > "Curt Welch" <curt@kcwc.com> wrote in message > news:20021010014047.034$XV@newsreader.com... > > 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. > > I think you wouldn't have a problem, as long as the hash function itself > was strong. If I take 2 hashes, put them together somehow, and put it > thru the hash function to get a new hash, if you have one original hash > and the final hash you would still have to brute force thru all the > possible values of the second hash and see if it results in the final > hash. If not, the hashing function is flawed to begin with for security > use and should be thrown away. Yeah, I think you are right. Some adcise from hash "experts" would be good still. > > I'm still thinking something in the 1K size is about right. > I disagree with this. Picking a small chunk size is going to create a > huge amount of calculation for each part you post. Simplist case, your > post size is 512K, your chunk size is 256K. You calculate hash A and B on > the 2 chunks, then calculate hash C from the somehow combined hashes A > and B. Hash C would be your top hash. Hash C is NOT the same as taking a > hash of the entire 512K part. So now we reduce the chunk size to 128K. > Now we do a hash on 4 chunks, then 2 combine hashes, then a final combine > hash. So now you have 7 hashes per post to work out. If you take this > down to 64 byte chunks, you now have to calculate 16383 hashes per 512k > post. At 1024 byte chunks, you still have 1023 hashes to grind thru > before you get the top hash for that post. I think you don't know much about how hash algorithms work. The amount of CPU time required is a linear function of the amount of data you have to hash, not the "number of hashes" you calculate. If you create a hash for each 1K block, you are adding 16 bytes of data which must be hashed for each 1K block. Extend that up though a full binary tree and it works out to be twice that. So for each 1K block of data, you have to hash 32 more bytes total. That a 3% increase in the amount of data which must be hashed. so if it takes 1 second to hash all the data, you have added .03 seconds of CPU time to the problem by using 1K blocks. To help you understand better... To calculate an MD5 hash of data, you divide the data up into blocks of 16 bytes each. You then start the 16 byte "hash context" at an initial state. You apply the MD5 algorthm to the context and the first 16 byte block. The algorithm produces as output, the next MD5 context. You repeat this for every 16 byte data block in your set. If you have a 1K block, you have to run the hash function 64 times. For a 512K block, you have to run the hash function 64*512 or 32,000 times. If you take two MD5 hashes, and hash them, you run the basic hash function 2 more times. For 512K of data, and a 1K block size, we end up with 1023 extra hash values which have to be hashed. So the total number of hashes that must be calculated is 32,1023 instead of just 32,000. If you use a block size of 256K, then the total number of hashes to be calucated drops to 32,003. Not a significant CPU savings for a problem which isn't CPU bound in the first place, it's disk IO bound. > I think that the chunk size should be the lowest part size you should > expect someone to post at. Make it 64K, binaries shouldn't ever be split > into pieces smaller than this, and at 512k part sizes, it only requires 8 > hash calculations per post. That's a point to consider. Like I said in my other post, I've already rasied it to 4KB in my test code. 64KB is a good number for a minimum post size. But, the number also becomes the granularity which will be used to try and adjust all posts in a set to the same size. To make articles move at about the same speed (and over the same feed links), you want all the articles in the set to be as close as possible to the same size. If you wanted to post a 3.1MB file say, that's works out to be 50 64KB chunks. If you want a part size of 432KB or less (9 chunks max per file), you get 5.6 articles (i.e. 6,), and you end up with some of the articles having 9 chunks and some with 8 like this: 9 9 8 8 8 8 So two files hold 576k of data and the rest hold 512K each. (the difference being your 64K chunk size). Are those file sizes close enough in size to help them move though usenet cleanly? I don't know. They don't seem as close as I'd like them, but maybe they are. I wouldn't want to go higher than 64K. There are so many hard cutoffs in the usenet feed system (like the Cidera 512K limit), that you want to get the articles as close in size as possible to minimize problems that some of the articles (like the last 3 in the set above) squeeze under a bar like the Cidera limit, where as the first 3 are blocked out. With a 1K granularity to work with, the odds are so much better that the article set won't get split up and have only some of the articles make it to a server instead of all or none. With 4K it gets worse. With 64K, it's a big difference. When we get farther with this we should experiment to see if this really makes much difference or not. If not, larger block sizes have an advantage even if the small sizes are not a CPU issue. > > The file is 2^37 bytes long. 1K is 2^10, so that gives us 2^27 P > > blocks > This would be 2^28-1 hashes you would have to calculate. If you can > calculate 10K hashes a second, this will take you 7 hours of math to > start posting. It'll solve the bandwidth problems nicely :D Well, to throw in some real numbers... The md5 Unix utility running on a 1GHz PIII machine of mine can do about 40MB of data per second when reading a file already cached in memory. That's over 2^32 bytes of data. So to calculate it for 2^37 bytes would take 2^5 seconds (that's 32 seconds to claculate a single hash for 128 GB of data). To calculate all the hashes for 1K blocks, that increases the work by 3%, so we are talking 33 seconds instead of 32. Not quite 7 hours is it? And how long do you think a typical disk drive will take to deliver 128 GB of data to you so you can do that 32 seconds of CPU work calculating the hash? 20MB per second is a typcial disk these days. At that rate, it would takes about 2 hours to read all that data. I don't think that 33 seconds of CPU work spread over 2 hours is going to be a problem. Someone wanting to post a 100GB file and not wanting to wait 2 hours before the posting can even start might be an issue. But my feelings on that is if they are putting that much data on Usenet they better be willing to wait because that 2 hours of delay will make it better for everyone on usenet trying to download the file or trying to transport the file for him. > > I think these ideas are just getting better and better. I'm beginning > > to feel the need to write proof of concept code.... > > I started playing around with this too, which is how I noticed how many > actual hashes you'd have to calculate per post. Yeah, but the time to calculate them shouldn't be a problem. Let us known if you find it is or think my logic above has some flaw in it. -- Curt Welch http://CurtWelch.Com/ curt@kcwc.com Webmaster for http://NewsReader.Com/
Technical Details
Message-ID:
<20021010160429.711$68@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!canoe.uoregon.edu!logbridge.uoregon.edu!news.stealth.net!news.stealth.net!66.250.146.10.MISMATCH!newshosting.com!news-xfer1.atl.newshosting.com!38.144.126.75.MISMATCH!feed1.newsreader.com!newsreader.com!news2.newsreader.com!ellis.newsreader.com!not-for-mailReferences:
<hpk9quk1cq0ti2reeu03epd0tgf4b8a8p0@4ax.com> <20021010014047.034$XV@newsreader.com> <ao4htp$rq1$1@bob.news.rcn.net>Show Full Headers
Complete Article Headers
Message-ID: <20021010160429.711$68@newsreader.com>
Subject: Re: [FNTP] verifying that part reposts belong to a file - solution
Date: Thu, 10 Oct 2002 20:04:29 +0000
From: curt@kcwc.com (Curt Welch)
References: <hpk9quk1cq0ti2reeu03epd0tgf4b8a8p0@4ax.com> <20021010014047.034$XV@newsreader.com> <ao4htp$rq1$1@bob.news.rcn.net>
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!news.stealth.net!news.stealth.net!66.250.146.10.MISMATCH!newshosting.com!news-xfer1.atl.newshosting.com!38.144.126.75.MISMATCH!feed1.newsreader.com!newsreader.com!news2.newsreader.com!ellis.newsreader.com!not-for-mail
Organization: NewsReader.Com
Newsgroups: news.software.nntp
X-Trace: NewsReader.Com vMQrDK3X/+Q012Cd+qUJnp0lW/x/Nqp5S@nI_VxSKfVlZRSf
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: 148