]> git.kaiwu.me - nginx.git/commitdiff
Chacha20 header protection support with BoringSSL.
authorSergey Kandaurov <pluknet@nginx.com>
Tue, 10 Mar 2020 16:15:12 +0000 (19:15 +0300)
committerSergey Kandaurov <pluknet@nginx.com>
Tue, 10 Mar 2020 16:15:12 +0000 (19:15 +0300)
BoringSSL lacks EVP for Chacha20.  Here we use CRYPTO_chacha_20() instead.

src/event/ngx_event_openssl.h
src/event/ngx_event_quic.c

index b562f0f177f9510e31c3ff8df17559ac942f6c0c..620a216efe5c373b40cf56b2b22ea232e8fbd926 100644 (file)
@@ -25,6 +25,7 @@
 #include <openssl/evp.h>
 #ifdef OPENSSL_IS_BORINGSSL
 #include <openssl/hkdf.h>
+#include <openssl/chacha.h>
 #else
 #include <openssl/kdf.h>
 #endif
index b7595e8bfd0d9faca04ed5a8c07949d3938f2030..c4012687e36527f85d2de4da468d7f491ed7b92e 100644 (file)
@@ -2053,6 +2053,17 @@ ngx_quic_tls_hp(ngx_connection_t *c, const EVP_CIPHER *cipher,
     EVP_CIPHER_CTX  *ctx;
     u_char           zero[5] = {0};
 
+#ifdef OPENSSL_IS_BORINGSSL
+    uint32_t counter;
+
+    ngx_memcpy(&counter, in, sizeof(uint32_t));
+
+    if (cipher == (const EVP_CIPHER *) EVP_aead_chacha20_poly1305()) {
+        CRYPTO_chacha_20(out, zero, 5, s->hp.data, &in[4], counter);
+        return NGX_OK;
+    }
+#endif
+
     ctx = EVP_CIPHER_CTX_new();
     if (ctx == NULL) {
         return NGX_ERROR;
@@ -2129,7 +2140,9 @@ ngx_quic_ciphers(ngx_connection_t *c, ngx_quic_ciphers_t *ciphers,
 #else
         ciphers->c = EVP_chacha20_poly1305();
 #endif
-#ifndef OPENSSL_IS_BORINGSSL
+#ifdef OPENSSL_IS_BORINGSSL
+        ciphers->hp = (const EVP_CIPHER *) EVP_aead_chacha20_poly1305();
+#else
         ciphers->hp = EVP_chacha20();
 #endif
         ciphers->d = EVP_sha256();