Added ChaCha20+Poly1305 support (stand-alone, cipher suites).
[BearSSL] / src / ssl / ssl_client_full.c
index 64f9327..7480de8 100644 (file)
@@ -36,17 +36,20 @@ br_ssl_client_init_full(br_ssl_client_context *cc,
         * Rationale for suite order, from most important to least
         * important rule:
         *
-        * -- Don't use 3DES if AES is available.
+        * -- Don't use 3DES if AES or ChaCha20 is available.
         * -- Try to have Forward Secrecy (ECDHE suite) if possible.
         * -- When not using Forward Secrecy, ECDH key exchange is
         *    better than RSA key exchange (slightly more expensive on the
         *    client, but much cheaper on the server, and it implies smaller
         *    messages).
+        * -- ChaCha20+Poly1305 is better than AES/GCM (faster, smaller code).
         * -- GCM is better than CBC.
         * -- AES-128 is preferred over AES-256 (AES-128 is already
         *    strong enough, and AES-256 is 40% more expensive).
         */
        static const uint16_t suites[] = {
+               BR_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
+               BR_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
                BR_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
                BR_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
                BR_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
@@ -181,6 +184,10 @@ br_ssl_client_init_full(br_ssl_client_context *cc,
        br_ssl_engine_set_des_cbc(&cc->eng,
                &br_des_ct_cbcenc_vtable,
                &br_des_ct_cbcdec_vtable);
+       br_ssl_engine_set_chacha20(&cc->eng,
+               &br_chacha20_ct_run);
+       br_ssl_engine_set_poly1305(&cc->eng,
+               &br_poly1305_ctmul_run);
 
        /*
         * Set the SSL record engines (CBC, GCM).
@@ -191,4 +198,7 @@ br_ssl_client_init_full(br_ssl_client_context *cc,
        br_ssl_engine_set_gcm(&cc->eng,
                &br_sslrec_in_gcm_vtable,
                &br_sslrec_out_gcm_vtable);
+       br_ssl_engine_set_chapol(&cc->eng,
+               &br_sslrec_in_chapol_vtable,
+               &br_sslrec_out_chapol_vtable);
 }