Re: Was Using OpenSSL and RSA - Blowfish in ObjC and Cocoa
Re: Was Using OpenSSL and RSA - Blowfish in ObjC and Cocoa
- Subject: Re: Was Using OpenSSL and RSA - Blowfish in ObjC and Cocoa
- From: Andy Lee <email@hidden>
- Date: Fri, 29 Mar 2002 20:37:29 -0500
At 8:41 PM +0100 3/29/02, Nat! wrote:
(1) The encryption logic in MulleCipherBlowfish pads the source
data with zeros, because Blowfish operates on 8-byte chunks. This
means that after decryption, you will get 0-7 extra bytes at the
end that were not part of your original data. This may not matter,
depending on your app, but if it does matter to you, you'll have to
chop those bytes off yourself.
Yes this is a property of the blowfish algorithm. There is no good
way around it AFAIK. Putting the length of the data in front of the
plaintext data is not a good idea though, because that would make
cracking easier. [Mental note: Gotta document this property]
How about this: put the size of the padding at the end of the data
before encrypting it. Instead of padding by 0-7 null bytes, pad by
1-8 random bytes, and put the pad size in the last three bits of the
last byte. Then after decrypting, you can read those three bits to
tell how many bytes to chop off the end.
Today I wrote code that does almost this, but pads with zeros, which
after reading your comment I realized is bad. I will change my code
shortly to use random bits in the padding (except for the last three,
of course). Seems like this should solve the problem -- or am I
mistaken?
(4) It will be obvious from the code, but I'll just mention that
MulleCipherBlowfish is not threadsafe. It would be up to you, the
caller, to wrap it with threadsafe logic if it matters.
Fortunately, this is not necessary for my simple needs.
Apart from the sharedInstance call, which leaves a small troubled
window of time, I would at the moment boldly contest that statement.
Couldn't another thread muck with the NSMutableData that is being
encrypted, during the encryption process? That was what I was
thinking.
(5) The MulleCipher code dates back to late 2000. I couldn't find
a newer version, but if there is one, my points (1)-(4) may be
irrelevant. ;)
But that's in my eyes a positive thing. When I use a reasonably
popular routine that has f.e. "Copyright 1992" on it, I get that
warm comfortable feeling of trust, that this thing is going to work.
Oh, I didn't mean to pass judgment either way. There's a lot to be
said for code that is tried and true. That's why CVS gives me such a
warm and fuzzy feeling, for example. I was just afraid I might be
making a fool of myself by commenting on code that had been updated
already. ;)
Thanks, Nat!
--Andy
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.