+
+int ossltest_aes128_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
+ const unsigned char *iv, int enc)
+{
+ return EVP_CIPHER_meth_get_init(EVP_aes_128_gcm()) (ctx, key, iv, enc);
+}
+
+
+int ossltest_aes128_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
+ const unsigned char *in, size_t inl)
+{
+ unsigned char *tmpbuf;
+ const size_t datalen = inl - EVP_GCM_TLS_EXPLICIT_IV_LEN
+ - EVP_GCM_TLS_TAG_LEN;
+
+ tmpbuf = OPENSSL_malloc(datalen);
+ if (tmpbuf == NULL)
+ return -1;
+
+ /* Remember what we were asked to encrypt */
+ memcpy(tmpbuf, in + EVP_GCM_TLS_EXPLICIT_IV_LEN, datalen);
+
+ /* Go through the motions of encrypting it */
+ EVP_CIPHER_meth_get_do_cipher(EVP_aes_128_gcm())(ctx, out, in, inl);
+
+ /*
+ * Throw it all away and just use the plaintext as the output with empty
+ * IV and tag
+ */
+ memset(out, 0, inl);
+ memcpy(out + EVP_GCM_TLS_EXPLICIT_IV_LEN, tmpbuf, datalen);
+ OPENSSL_free(tmpbuf);
+
+ return 1;
+}
+
+static int ossltest_aes128_gcm_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,
+ void *ptr)
+{
+ int ret;
+
+ /* Pass the ctrl down */
+ ret = EVP_CIPHER_meth_get_ctrl(EVP_aes_128_gcm())(ctx, type, arg, ptr);
+
+ return ret;
+}