Article View: news.software.nntp
Article #62429Re: xBin (Power-Post 2003 - requesting input from authorities..)
From: Rene
Date: Tue, 24 Dec 2002 03:33
Date: Tue, 24 Dec 2002 03:33
130 lines
7556 bytes
7556 bytes
Lucky me, can't find some sleep... *sigh* curt@kcwc.com (Curt Welch) wrote: > I could easilly be wrong about SHA-1. I don't think I've ever looked > into it. I just made the assumption it worked on 20 byte blocks in a > similar way to how MD5 works. > > MD5 however is a block hash which works on 16 byte blocks. It is > structured to run though it's algorithm once for each 16 byte block. If > you give it 17 bytes to hash, it pads the last block and runs the hash > algortihm twice making it take twice as long as for 16 bytes. Nope, sorry. That's wrong too. MD5's internal state is 4 times 4 bytes, that much is correct, however it too processes data in intervals of 512bit / 64 bytes. See http://www.ietf.org/rfc/rfc1321.txt either section 3.1 where the padding is explained or the sample code on page 8 where you see that the struct MD5_CTX uses a buffer of size 64. An optimal input size would be 447 bits, because 1 bit at least is always added for padding, followed by the lenght (which is 64 bits, not 32) and thus result in a full 512 bit buffer. However, don't do that ! This results in only one round and is probably far more easier to reverse. (That's 447 bits input producing a 128bit hash in MD5). > If you selected a 17 byte "tree hash" vs 16 bytes, it would take close to > 2X the CPU time to clacuate the hash. But that's a worse case issue > which is not at all significant when you are talking about blocks sizes > 1K and up. Nope you can enter full 55 bytes to still fit in one round (on MD4, MD5 and SHA-1 which all use a 512 bit buffer) Second round would be 64+55 bytes and so on. So chosing a size based on hash-rounds, you'd need n*64+55 bytes as an optimal input size. > If SHA-1 does use 64 byte blocks internally, then a 4500 byte hash block > would be mis-alligned for its blocks. But like we both said, that's not > going to make a notable difference in CPU usage. 4500 bytes would end up in 70 rounds of full 64 bytes, leaving 20 where 55 could fit. We can't get 35 more bytes since the file limit is 45 as you say. This is a uuencode limit as you say. May the last line be shorter? If so you could increase the blocksize to 4535. > > Well as I said, I'd make it a multiple of the OS' file io system. > Write the code, set the block size to 4096 and time it. Change the block > size to 4500 and see if you can measure _any_ difference. You won't be > able to. Probably not. Then again I don't know on what blocksizes the OS performs one read call. Its probably 512 bytes or 1024 bytes. So does it make a difference ? Probably nothing measurable. If the blocksize of the OS is 1024, then I've issued a command that caused 4 reads instead of 5. It might not be measurable, in fact I'm quite sure it isn't worth a long debate. Its a minor optimisation, causing one less syscall, one less memory access on a block which by then is in the cache anyway, so winning about 5usec latency at most. You say your chosen size is adapted to uuencode, so that's in a field where I have no clue what you need to do and what you must not. I trust your judgment in that area. > Here are three runs of my code calculating the tree hash of a 50MB file > (where the file is all in the memory cache of the server so no disk IO > happened): Well actually loading and processing the file would have been more interesting... The slowest part of all this WILL be the disk i/o. Memory access is always fast. > Looking at the user time (u), the 4500 block code seemed to run faster > than the 4096 byte code. But more important, the difference is so small Yes the difference is too small. It probably will still be small with actual disk i/o but you already seem to have your test-program around, so can you repeat this test with a non-cached file? > is. How long will it take to just read that from the disk when the > blocks are pre-cached in memory like this example? How long will it take 0 - if the data is pre-cached, then the disk will not be asked for blocks. > to post it? How long will it take to download it? Far longer. However, you need to assume that a multithreading newsreader will be processing the posts. So there are concurrent downloading / decoding / memory updates. You can't be too sure your block will be in the cache when you are going to feed it to the hash-algorithm (especially considering that this will probably be after the write to disk, so the cache-blocks holding that part are already marked as "written and reclaimable") Its but a little optimisation trying to minimize disk i/o. If conforming to uuencode line length is more important, then forget it, its not worth trying to find something that satisfies both things. If it can easily be done though, then I'd do it, it doesn't really cost anything. > The users will never ever notice a difference in performance if the block > size is 4500 vs 4096. If we pick a block size which is not a multiple of > the uuencode 45 bytes per line, this forces the last line in most > uuencoded articles to be short. If there is only one poorly written > uudecode utility in the world which is unable to correctly deal with that > (for example it falsely assums a short line means "end of file"), and one > user has to spend hours trying to undersand why the files he is > downloading "don't work", how much CPU time will you have to "save" for > the other millions of users to make up for the problems you caused that 1 > user? That's one of the things I didn't knew about. If it is potentially that critical, then by all means, make it a multiple of 45. However it was my intention that the last line could be made shorter - so assuming that this is the eof would be correct. You probably meant to write that this uudecode cannot handle that correctly and adds junk (which subsequently will get that block marked corrupt by the hash-algorithm) > I know a block size which is not a power of two seems "wrong". But I > think it's more than justified for this application. It seems so, yes. Coming from the pure programmer's side with no binary news experience I would have taken a multiply of 1024 because it is "natural". I didn't see the problems with uudecode. Damn, not a bit more tired now... -- -------------------- http://NewsReader.Com/ -------------------- Usenet Newsgroup Service New Rate! $9.95/Month 50GB
Technical Details
Message-ID:
<20021223223311.286$Mx@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-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed1.newsreader.com!newsreader.com!news2.newsreader.com!ellis.newsreader.com!not-for-mailReferences:
<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>Show Full Headers
Complete Article Headers
Message-ID: <20021223223311.286$Mx@newsreader.com> Subject: Re: xBin (Power-Post 2003 - requesting input from authorities..) Date: Tue, 24 Dec 2002 03:33:11 +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> 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-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed1.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 elqOh9o4_/Clg_SHy6PFl/CohBCk-Z8c0RLiF_@nd8WzQx Lines: 129