Added ChaCha20+Poly1305 support (stand-alone, cipher suites).
[BearSSL] / src / ssl / ssl_engine.c
index 32bc406..1f095f0 100644 (file)
@@ -1474,3 +1474,44 @@ br_ssl_engine_switch_gcm_out(br_ssl_engine_context *cc,
        cc->igcm_out->init(&cc->out.gcm.vtable.out,
                bc_impl, cipher_key, cipher_key_len, cc->ighash, iv);
 }
+
+/* see inner.h */
+void
+br_ssl_engine_switch_chapol_in(br_ssl_engine_context *cc,
+       int is_client, int prf_id)
+{
+       unsigned char kb[88];
+       unsigned char *cipher_key, *iv;
+
+       compute_key_block(cc, prf_id, 44, kb);
+       if (is_client) {
+               cipher_key = &kb[32];
+               iv = &kb[76];
+       } else {
+               cipher_key = &kb[0];
+               iv = &kb[64];
+       }
+       cc->ichapol_in->init(&cc->in.chapol.vtable.in,
+               cc->ichacha, cc->ipoly, cipher_key, iv);
+       cc->incrypt = 1;
+}
+
+/* see inner.h */
+void
+br_ssl_engine_switch_chapol_out(br_ssl_engine_context *cc,
+       int is_client, int prf_id)
+{
+       unsigned char kb[88];
+       unsigned char *cipher_key, *iv;
+
+       compute_key_block(cc, prf_id, 44, kb);
+       if (is_client) {
+               cipher_key = &kb[0];
+               iv = &kb[64];
+       } else {
+               cipher_key = &kb[32];
+               iv = &kb[76];
+       }
+       cc->ichapol_out->init(&cc->out.chapol.vtable.out,
+               cc->ichacha, cc->ipoly, cipher_key, iv);
+}