Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
ed661b1
it works! implement aes-gcm that uses non-temporal stores
kazuho Apr 30, 2022
42a4264
aligned
kazuho Apr 30, 2022
b854db9
on 9th-gen Core 9% slower than OpenSSL, on Zen 2 4%
kazuho Apr 30, 2022
7da0917
oops, use non-temporal
kazuho Apr 30, 2022
7fb163f
output buffers might not be aligned
kazuho May 1, 2022
791036a
9-th gen Core, slowdown is 6% compared to fusion, when mm256_store is…
kazuho May 2, 2022
59983e9
this helps on gcc
kazuho May 2, 2022
e0caecc
gcc 9.4 (ubuntu 20.04) cannot detect this transformation
kazuho May 4, 2022
7c0fc38
Merge branch 'master' into kazuho/fastls
kazuho May 4, 2022
8b9cd57
disable address sanitization of `fastly_encrypt_v`, as it overwrites …
kazuho May 4, 2022
122a334
wip
kazuho May 4, 2022
700beb9
more space, to suppress out-of-bounds read warning
kazuho May 4, 2022
7a0685d
no pointer arithmetic on `void *`
kazuho May 4, 2022
608b16e
Merge branch 'master' into kazuho/fastls
kazuho May 4, 2022
34037b9
Merge branch 'master' into kazuho/fastls
kazuho May 6, 2022
65f3b13
oops
kazuho May 7, 2022
86aa4f6
no need to check; bytes_copied + srclen is guaranteed to be less than…
kazuho May 8, 2022
fa3cd32
We need this - srclen can increase when switching to the next vector …
kazuho May 8, 2022
3b2ab61
make sure ek0 is encrypted in the main loop
kazuho May 8, 2022
9430f84
oops
kazuho May 8, 2022
4f6bcae
remove needless if
kazuho May 8, 2022
204e765
add compile options for 256-bit-wide aesgcm
kazuho May 9, 2022
680ce18
aes-gcm using 256-bit insns
kazuho May 9, 2022
d1a0912
update copyright
kazuho May 9, 2022
34e9b2d
less sexy name
kazuho May 9, 2022
0a8330b
oops again
kazuho May 9, 2022
a7006dc
refactor
kazuho May 9, 2022
fd7d5c1
reduce register usage
kazuho May 9, 2022
93b04e1
quick hack for GCC on Intel
kazuho May 9, 2022
224fa36
don't forget the union
kazuho May 9, 2022
7f165e0
win32/64 fixes
kazuho May 9, 2022
eb3ebf4
use _aligned_malloc on windows
kazuho May 9, 2022
6144b4f
windows does not like `= {}`
kazuho May 9, 2022
07f37c2
Use dedicated types, as ASAN does not understand flexibly arrays insi…
kazuho May 10, 2022
196e477
we do out-of-bounds access within the same page directly, which asan …
kazuho May 10, 2022
13ced82
extract "unsafe" logic
kazuho May 10, 2022
4543982
retain the attribute, as we write to `output` adjusted to out-of-bounds
kazuho May 10, 2022
2344f27
turn fusion off on platform that does not have GCC with support for v…
kazuho May 10, 2022
2094f78
decoder works
kazuho May 10, 2022
5f76ffc
use avx256 instructions for load, store, xor
kazuho May 10, 2022
b93d856
full matrix testing
kazuho May 10, 2022
9f8e12a
teach GCC that xor should not be delayed across multiple steps of gfm…
kazuho May 10, 2022
908f00a
revert to the simple method; previous method (using 256-bit registers…
kazuho May 10, 2022
688d70c
expansion should retain 32-byte alignment
kazuho May 11, 2022
6e6d72b
for non-temporal aesgcm, buffer allocation should be cache-line-aware
kazuho Jun 5, 2022
f9c85cb
on windows, use _aligned_malloc / _aligned_free
kazuho Jun 6, 2022
9dc6982
add flag indicating if the AEAD engine uses non-temporal store instru…
kazuho Jun 8, 2022
7ada03c
Merge branch 'master' into kazuho/fastls
kazuho Jun 27, 2022
d155972
add multivec test
kazuho Jun 29, 2022
78e6c3a
fix handling of zero-length vec
kazuho Jun 29, 2022
629b800
ditto for aesni256-side
kazuho Jun 29, 2022
65d3e79
s/avx256/aesni256/, as we use avx256 instructions even when not using…
kazuho Jun 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
matrix:
include:
- name: "Linux / OpenSSL 1.1.0"
command: make -f misc/docker-ci.mk CMAKE_ARGS='-DOPENSSL_ROOT_DIR=-DOPENSSL_ROOT_DIR=/opt/openssl-1.1.0' CONTAINER_NAME='h2oserver/h2o-ci:ubuntu1604'
command: make -f misc/docker-ci.mk CMAKE_ARGS='-DOPENSSL_ROOT_DIR=-DOPENSSL_ROOT_DIR=/opt/openssl-1.1.0 -DWITH_FUSION=OFF' CONTAINER_NAME='h2oserver/h2o-ci:ubuntu1604'
- name: "Linux / OpenSSL 1.1.1"
command: make -f misc/docker-ci.mk
- name: "Linux / OpenSSL 1.1.1 + ASan & UBSan"
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ ENDIF ()

IF (WITH_FUSION)
ADD_LIBRARY(picotls-fusion lib/fusion.c)
SET_TARGET_PROPERTIES(picotls-fusion PROPERTIES COMPILE_FLAGS "-mavx2 -maes -mpclmul")
SET_TARGET_PROPERTIES(picotls-fusion PROPERTIES COMPILE_FLAGS "-mavx2 -maes -mpclmul -mvaes -mvpclmulqdq")
TARGET_LINK_LIBRARIES(picotls-fusion picotls-core)
ADD_EXECUTABLE(test-fusion.t
deps/picotest/picotest.c
lib/picotls.c
t/fusion.c)
TARGET_LINK_LIBRARIES(test-fusion.t picotls-minicrypto)
SET_TARGET_PROPERTIES(test-fusion.t PROPERTIES COMPILE_FLAGS "-mavx2 -maes -mpclmul")
SET_TARGET_PROPERTIES(test-fusion.t PROPERTIES COMPILE_FLAGS "-mavx2 -maes -mpclmul -mvaes -mvpclmulqdq")
IF (WITH_DTRACE)
ADD_DEPENDENCIES(test-fusion.t generate-picotls-probes)
ENDIF ()
Expand Down
8 changes: 8 additions & 0 deletions include/picotls.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ extern "C" {
#define PTLS_FUZZ_HANDSHAKE 0
#endif

#ifndef PTLS_SIZEOF_CACHE_LINE
#define PTLS_SIZEOF_CACHE_LINE 64
#endif

#define PTLS_HELLO_RANDOM_SIZE 32

#define PTLS_AES128_KEY_SIZE 16
Expand Down Expand Up @@ -392,6 +396,10 @@ typedef const struct st_ptls_aead_algorithm_t {
* size of the tag
*/
size_t tag_size;
/**
* if encrypted bytes are going to be written using non-temporal store instructions (i.e., skip cache)
*/
unsigned non_temporal : 1;
/**
* size of memory allocated for ptls_aead_context_t. AEAD implementations can set this value to something greater than
* sizeof(ptls_aead_context_t) and stuff additional data at the bottom of the struct.
Expand Down
18 changes: 15 additions & 3 deletions include/picotls/fusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,24 @@ extern "C" {

#include <stddef.h>
#include <emmintrin.h>
#include <immintrin.h>
#include "../picotls.h"

#define PTLS_FUSION_AES128_ROUNDS 10
#define PTLS_FUSION_AES256_ROUNDS 14

typedef struct ptls_fusion_aesecb_context {
__m128i keys[PTLS_FUSION_AES256_ROUNDS + 1];
union {
__m128i m128[PTLS_FUSION_AES256_ROUNDS + 1];
__m256i m256[PTLS_FUSION_AES256_ROUNDS + 1];
} keys;
unsigned rounds;
} ptls_fusion_aesecb_context_t;
uint8_t aesni256;
} __attribute__((aligned(32))) ptls_fusion_aesecb_context_t;

typedef struct ptls_fusion_aesgcm_context ptls_fusion_aesgcm_context_t;

void ptls_fusion_aesecb_init(ptls_fusion_aesecb_context_t *ctx, int is_enc, const void *key, size_t key_size);
void ptls_fusion_aesecb_init(ptls_fusion_aesecb_context_t *ctx, int is_enc, const void *key, size_t key_size, int avx256);
void ptls_fusion_aesecb_dispose(ptls_fusion_aesecb_context_t *ctx);
void ptls_fusion_aesecb_encrypt(ptls_fusion_aesecb_context_t *ctx, void *dst, const void *src);

Expand Down Expand Up @@ -84,8 +89,15 @@ void ptls_fusion_aesgcm_encrypt(ptls_fusion_aesgcm_context_t *ctx, void *output,
int ptls_fusion_aesgcm_decrypt(ptls_fusion_aesgcm_context_t *ctx, void *output, const void *input, size_t inlen, __m128i ctr,
const void *aad, size_t aadlen, const void *tag);

/**
* A boolean flag indicating if vaes and vpclmulqdq (256-bit crypto instructions) should be used. This flag is set automatically
* when `ptls_fusion_is_supported_by_cpu` is called. Users can update the flag to enforce behavior. Engines that do not have support
* for these 256-bit instructions will continue using the 128-bit ones, even when this flag is set.
*/
extern int ptls_fusion_can_aesni256;
extern ptls_cipher_algorithm_t ptls_fusion_aes128ctr, ptls_fusion_aes256ctr;
extern ptls_aead_algorithm_t ptls_fusion_aes128gcm, ptls_fusion_aes256gcm;
extern ptls_aead_algorithm_t ptls_non_temporal_aes128gcm, ptls_non_temporal_aes256gcm;

/**
* Returns a boolean indicating if fusion can be used.
Expand Down
1 change: 1 addition & 0 deletions lib/cifra/aes128.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ ptls_aead_algorithm_t ptls_minicrypto_aes128gcm = {"AES128-GCM",
PTLS_AES128_KEY_SIZE,
PTLS_AESGCM_IV_SIZE,
PTLS_AESGCM_TAG_SIZE,
0,
sizeof(struct aesgcm_context_t),
aead_aes128gcm_setup_crypto};
ptls_cipher_suite_t ptls_minicrypto_aes128gcmsha256 = {.id = PTLS_CIPHER_SUITE_AES_128_GCM_SHA256,
Expand Down
1 change: 1 addition & 0 deletions lib/cifra/aes256.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ ptls_aead_algorithm_t ptls_minicrypto_aes256gcm = {"AES256-GCM",
PTLS_AES256_KEY_SIZE,
PTLS_AESGCM_IV_SIZE,
PTLS_AESGCM_TAG_SIZE,
0,
sizeof(struct aesgcm_context_t),
aead_aes256gcm_setup_crypto};
ptls_cipher_suite_t ptls_minicrypto_aes256gcmsha384 = {.id = PTLS_CIPHER_SUITE_AES_256_GCM_SHA384,
Expand Down
1 change: 1 addition & 0 deletions lib/cifra/chacha20.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ ptls_aead_algorithm_t ptls_minicrypto_chacha20poly1305 = {"CHACHA20-POLY1305",
PTLS_CHACHA20_KEY_SIZE,
PTLS_CHACHA20POLY1305_IV_SIZE,
PTLS_CHACHA20POLY1305_TAG_SIZE,
0,
sizeof(struct chacha20poly1305_context_t),
aead_chacha20poly1305_setup_crypto};
ptls_cipher_suite_t ptls_minicrypto_chacha20poly1305sha256 = {.id = PTLS_CIPHER_SUITE_CHACHA20_POLY1305_SHA256,
Expand Down
Loading