Re: Fw: [PEAR-DEV] Re: [RFC] Horde_Cipher -> Crypt_Cipher
| From: | Davey | Date: | Sun, 27 Jul 2003 18:13:20 +0000 |
| Subject: | Re: Fw: [PEAR-DEV] Re: [RFC] Horde_Cipher -> Crypt_Cipher | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-18814@lists.php.net to get a copy of this message | ||
Colin Viebrock wrote:
Thanks. Please forward this to whomever needs to see it. I'll try and catch up on the PEAR-DEV mailing list shortly, so I should be able to read any responses. ---- I'm sort of jumping in at the end here, but here's the answers I think you need from me:If this relies on mcrypt, then it really isn't the best idea to put it in Crypt_Cipher/Hash, Perhaps you can take a look at the Horde_Cipher blocking code and see if a) it fullfils your needs or b) can lead you to create a full PHP Userland implementation (but use mcrypt if its there).Colin: What does CBC do? if it is blocking, can I use it how I'd like? Does it have a place in an all-in-one Crypt_Cipher/Hash package?Crypt_CBC is basically a translation from Perl into PHP of CPAN's Crypt::CBC. I needed it because I was writing a PHP client that spoke encrypted to a Perl server, and the way that the mcrypt functions handled CBC wasn't compatible with Perl. That said, it was a really quick hack, and basically uses mcrypt to do ECB encryption, and handles the chaining itself. It also uses a standard IV that Crypt::CBC uses so as to be compatible. I would not call this class a good candidate for a general CBC encryption class. Like I said, it's a quick hack and exists solely (for me anyway) to talk to Perl.
That said, if you want my opinion on the structuring of a generic cipher/hash class, may I suggest doing something like DB.php or Log.php do? i.e. have one singleton-type class/method that includes the required "driver" class. Each driver class would then have identical methods. You could even split the cipher stuff and hash stuff and have:This is pretty much exactly what I am thinking of doing, not sure about the DSN stuff though, I would prefer an array of options instead. Maybe both?
These sound pretty good, will, finish checking out the Horde_Cipher API, would be nice to make it somewhat compatibleCipher.php Cipher_CBC.php Cipher_ECB.php etc. Hash.php Hash_MD5.php Hash_HMAC.php etc.And the code might look like:<? require 'Crypt.php'; $C = Crypt::singleton( 'CBC://Blowfish/RandomIV' ); $C->encrypt('secret message');?>That 'CBC://Blowfish/RandomIV' would be some parseable DSN or whatever to let the class know the cipher, algorithm, IV, and any other data needed. The Cipher_* classes would have initialize(), encrypt() and decrypt() methods. The Hash_* classes would (I guess) only have initialize() and hash() methods.
Anyway, that's all just IMHO. I'm not a encryption guru by any means, and I really only use Crypt_CBC for one thing right now. I wouldn't be offended if it was removed from PEAR, or renamed or whatever. I'll try and follow along in the newsgroup for the rest of this discussion.Cool :)
- Colin- Davey