@@ -28,19 +28,24 @@ extern "C" {
2828
2929#include <stddef.h>
3030#include <emmintrin.h>
31+ #include <immintrin.h>
3132#include "../picotls.h"
3233
3334#define PTLS_FUSION_AES128_ROUNDS 10
3435#define PTLS_FUSION_AES256_ROUNDS 14
3536
3637typedef struct ptls_fusion_aesecb_context {
37- __m128i keys [PTLS_FUSION_AES256_ROUNDS + 1 ];
38+ union {
39+ __m128i m128 [PTLS_FUSION_AES256_ROUNDS + 1 ];
40+ __m256i m256 [PTLS_FUSION_AES256_ROUNDS + 1 ];
41+ } keys ;
3842 unsigned rounds ;
39- } ptls_fusion_aesecb_context_t ;
43+ uint8_t aesni256 ;
44+ } __attribute__((aligned (32 ))) ptls_fusion_aesecb_context_t ;
4045
4146typedef struct ptls_fusion_aesgcm_context ptls_fusion_aesgcm_context_t ;
4247
43- void ptls_fusion_aesecb_init (ptls_fusion_aesecb_context_t * ctx , int is_enc , const void * key , size_t key_size );
48+ void ptls_fusion_aesecb_init (ptls_fusion_aesecb_context_t * ctx , int is_enc , const void * key , size_t key_size , int avx256 );
4449void ptls_fusion_aesecb_dispose (ptls_fusion_aesecb_context_t * ctx );
4550void ptls_fusion_aesecb_encrypt (ptls_fusion_aesecb_context_t * ctx , void * dst , const void * src );
4651
@@ -84,8 +89,15 @@ void ptls_fusion_aesgcm_encrypt(ptls_fusion_aesgcm_context_t *ctx, void *output,
8489int ptls_fusion_aesgcm_decrypt (ptls_fusion_aesgcm_context_t * ctx , void * output , const void * input , size_t inlen , __m128i ctr ,
8590 const void * aad , size_t aadlen , const void * tag );
8691
92+ /**
93+ * A boolean flag indicating if vaes and vpclmulqdq (256-bit crypto instructions) should be used. This flag is set automatically
94+ * when `ptls_fusion_is_supported_by_cpu` is called. Users can update the flag to enforce behavior. Engines that do not have support
95+ * for these 256-bit instructions will continue using the 128-bit ones, even when this flag is set.
96+ */
97+ extern int ptls_fusion_can_aesni256 ;
8798extern ptls_cipher_algorithm_t ptls_fusion_aes128ctr , ptls_fusion_aes256ctr ;
8899extern ptls_aead_algorithm_t ptls_fusion_aes128gcm , ptls_fusion_aes256gcm ;
100+ extern ptls_aead_algorithm_t ptls_non_temporal_aes128gcm , ptls_non_temporal_aes256gcm ;
89101
90102/**
91103 * Returns a boolean indicating if fusion can be used.
0 commit comments