Hi Jakub, On Wed, Jan 6, 2016 at 10:01 AM, Jakub Zelenka <bu...@php.net> wrote:
> Hi, > > I would like to propose an addition to the openssl ext - extending > openssl_encrypt and openssl_decrypt to support AEAD (Authenticated > Encryption with Additional Data - GCM and CCM modes support). There was > some discussion in past and people have been asking about that for some > time so I finally finished the implementation (it's more or less rewrite of > both functions) and created this RFC to discuss all concerns if there are > any... > > https://wiki.php.net/rfc/openssl_aead I think the API might need to be more generic so that any future cipher modes with different parameters could also be passed in. The reference model I'd suggest is the "context" parameter passed to stream related-functions. Userland creates a context, then passes the context to the encrypt/decrypt functions. The context is specific to the wrapper and drives specific behavior. Encrypt can add to the context any specific cipher state that needs to be passed along to decrypt. Using this model, the openssl API might look like: $context = openssl_context_create([ 'aead' => [ 'aad' => '...', 'tag_length' => '...' ]]); $ciphertext = openssl_encrypt( $data, $method, $password, $options, $iv, $context // here is the new parameter, encapsulating all cipher specifics ); echo $context['aead']['tag']; // populated by openssl_encrypt $plaintext = openssl_decrypt( $ciphertext, $method, $password, $options, $iv, $context // fully-reversible, because all necessary data are in context ); Might also want to check in with Scott Arciszewski (copied), as he's working on a new crypto API <https://github.com/paragonie/pco_prototype> proposal. Cheers, bishop