AEAD support in ssl/
[oweals/openssl.git] / ssl / ssl_ciph.c
index 22047c3e4191893687e7cd80377762637dcdb212..4eb86fbcfab3146e3077b6c3e12cfaae1003cbaa 100644 (file)
@@ -484,32 +484,72 @@ static void load_builtin_compressions(void)
        }
 #endif
 
+/* ssl_cipher_get_comp sets |comp| to the correct SSL_COMP for the given
+ * session and returns 1. On error it returns 0. */
+int ssl_cipher_get_comp(const SSL_SESSION *s, SSL_COMP **comp)
+       {
+       int i;
+
+       SSL_COMP ctmp;
+#ifndef OPENSSL_NO_COMP
+       load_builtin_compressions();
+#endif
+
+       *comp=NULL;
+       ctmp.id=s->compress_meth;
+       if (ssl_comp_methods != NULL)
+               {
+               i=sk_SSL_COMP_find(ssl_comp_methods,&ctmp);
+               if (i >= 0)
+                       *comp=sk_SSL_COMP_value(ssl_comp_methods,i);
+               else
+                       *comp=NULL;
+               }
+
+       return 1;
+       }
+
+/* ssl_cipher_get_evp_aead sets |*aead| to point to the correct EVP_AEAD object
+ * for |s->cipher|. It returns 1 on success and 0 on error. */
+int ssl_cipher_get_evp_aead(const SSL_SESSION *s, const EVP_AEAD **aead)
+       {
+       const SSL_CIPHER *c = s->cipher;
+
+       *aead = NULL;
+
+       if (c == NULL)
+               return 0;
+       if ((c->algorithm2 & SSL_CIPHER_ALGORITHM2_AEAD) == 0)
+               return 0;
+
+       switch (c->algorithm_enc)
+               {
+#ifndef OPENSSL_NO_AES
+       case SSL_AES128GCM:
+               *aead = EVP_aead_aes_128_gcm();
+               return 1;
+       case SSL_AES256GCM:
+               *aead = EVP_aead_aes_256_gcm();
+               return 1;
+#endif
+               }
+
+       return 0;
+       }
+
 int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc,
-            const EVP_MD **md, int *mac_pkey_type, int *mac_secret_size,SSL_COMP **comp)
+            const EVP_MD **md, int *mac_pkey_type, int *mac_secret_size)
        {
        int i;
        const SSL_CIPHER *c;
 
        c=s->cipher;
        if (c == NULL) return(0);
-       if (comp != NULL)
-               {
-               SSL_COMP ctmp;
-#ifndef OPENSSL_NO_COMP
-               load_builtin_compressions();
-#endif
 
-               *comp=NULL;
-               ctmp.id=s->compress_meth;
-               if (ssl_comp_methods != NULL)
-                       {
-                       i=sk_SSL_COMP_find(ssl_comp_methods,&ctmp);
-                       if (i >= 0)
-                               *comp=sk_SSL_COMP_value(ssl_comp_methods,i);
-                       else
-                               *comp=NULL;
-                       }
-               }
+       /* This function doesn't deal with EVP_AEAD. See
+        * |ssl_cipher_get_aead_evp|. */
+       if (c->algorithm2 & SSL_CIPHER_ALGORITHM2_AEAD)
+               return(0);
 
        if ((enc == NULL) || (md == NULL)) return(0);