On 2/26/15 11:12 AM, Leigh wrote:> On 26 February 2015 at 15:37, Tom
Worster fsb@thefsb.org wrote:
I've spoken with Anthony and a couple of others about something in the
same vein as the new csprng functions. I think core needs a pair of
functions that handles the needs of the 99%. Those functions are.aes_encrypt(string $data, string $key): string
aes_decrypt(string $data, string $key): string
I have discussed this briefly with Anthony and Nikita, and we haven't
reached a consensus on whether AES-n would be determined by key-length
(adding complexity for the user), or whether $key should be
$passphrase and should have key-stretching performed (this would avoid
the case where people pass in hex for a key), in which case we would
default to AES-128.The default mode would be CTR
An IV would be taken from the csprng random functions, and would be
prepended to the result.A strong MAC would be calculated and appended to the result.
This doesn't leave any room for interoperability where things are done
differently, but it also doesn't leave any room for people to mess it
up. I think it's important that when it comes to crypto, we give
people the ability to "just get it right", without having to know
about why something is right or wrong.I welcome any thoughts on this.
I agree with this direction and have a few comments.
- You say it "doesn't leave any room for interoperability" but I'm
not sure I agree. I invite you again to look at the Cryptography lib
for Python. The Fernet protocol is published. It implements basically
what you are describing above but with a couple of interesting extras:
-
protocol version number
-
timestamp, useful for receivers tracking for possible replay
I don't see why we couldn't sponsor an effort to encourage adoption
of this or some such interoperability protocol. Go to FIG, see if the
Rails, Node and Django people are interested, and so fourth...
-
At this stage I think PHP should be thinking beyond AES. There are
a number of arguments about phasing out AES that you can find online.
Regardless of the merits of these arguments, the demand for newer
ciphers is only going to increase. Meanwhile, it's going to be years
before anything we discuss here now is mainstream in PHP and more
years before that gets upgraded. So I think we may as well have a
pluggable backend for algorithm implementations and a means for users
to upgrade ciphers, perhaps by introducing new version numbers in the
above mentioned protocol from time to time. That said, I'm not in
favor of a function that lets users choose among lots of ciphers. I
just want an easier way to evolve than introducing new functions,
like, idk, threefish_encrypt(). -
When we did this in the yii\base\Security component we choose to
have separate methods for encryptByPassword() and encryptByKey(). The
main advantages are:
-
it makes the API simpler and easier to explain
-
it encourages the developer to think about the difference
-
it gives us a soapbox to encourage people to avoid passwords when
possible
And I encourage PHP to do the same if you want to allow users to do
either. Users will sometimes need to encrypt with a password so its
best to make it hard to screw up.
- We included a salt in the message for PBKDF2, and, just to keep
the message format the same both ways, used one also for key-based
encrypt.
Tom
Btw: owing to the volume on this list, I am not normally subscribed.
I occasionally check activity using nntp but cannot seem to reply
that way. In any case, if there's something you want me to see,
please send it to my email address.
- You say it "doesn't leave any room for interoperability" but I'm
not sure I agree. I invite you again to look at the Cryptography lib
for Python.
There are countless applications/services that will do things "their
own way", and the odds of them using the same structure as any generic
implementation is going to be hit and miss. I guess it would have been
better if I had said "doesn't give any room for flexibility"
I don't see why we couldn't sponsor an effort to encourage adoption
of this or some such interoperability protocol. Go to FIG, see if the
Rails, Node and Django people are interested, and so fourth...
Feeling pretty pessimistic on this one. Each camp is going to feel
that they know best and push for their own way. If we could get a
mandate from a group of established and respected cryptographers,
maybe :)
- At this stage I think PHP should be thinking beyond AES. There are
a number of arguments about phasing out AES that you can find online.
Regardless of the merits of these arguments, the demand for newer
ciphers is only going to increase. Meanwhile, it's going to be years
before anything we discuss here now is mainstream in PHP and more
years before that gets upgraded. So I think we may as well have a
pluggable backend for algorithm implementations and a means for users
to upgrade ciphers, perhaps by introducing new version numbers in the
above mentioned protocol from time to time. That said, I'm not in
favor of a function that lets users choose among lots of ciphers. I
just want an easier way to evolve than introducing new functions,
like, idk, threefish_encrypt().
I hear you.
http://marc.info/?l=php-internals&m=142365688004941&w=2
Count the number of replies :(
I don't see why we couldn't sponsor an effort to encourage adoption
of this or some such interoperability protocol. Go to FIG, see if the
Rails, Node and Django people are interested, and so fourth...Feeling pretty pessimistic on this one. Each camp is going to feel
that they know best and push for their own way. If we could get a
mandate from a group of established and respected cryptographers,
maybe :)
You're thinking on the right lines but you don't need actual
cryptographers to win this argument. You just need expert opinion in
the use of cryptography. And all the expert opinion needed is in fact
available from trusted sources.
Let's look at the objections. Say someone is reluctant, defending their
design. Two questions:
- Do you prefer NIH or interpretability?
Clearly the interest of your users means that interoperability is
the more important of these two.
- Should your design represent correct use of the crypto primitives
or not?
Clearly the answer is the former.
At this point the argument is won because there are few correct
designs and the differences between them are trivial in comparison to
interoperability.
Thus anyone really digging their heals in is demonstrably either
incompetent or not representing the interests of users.