check CPU features
diff --git a/include/picotls/fusion.h b/include/picotls/fusion.h
index fede03d..d7da45e 100644
--- a/include/picotls/fusion.h
+++ b/include/picotls/fusion.h
@@ -80,6 +80,11 @@
extern ptls_cipher_algorithm_t ptls_fusion_aes128ctr;
extern ptls_aead_algorithm_t ptls_fusion_aes128gcm;
+/**
+ * Returns a boolean indicating if fusion can be used.
+ */
+int ptls_fusion_is_supported_by_cpu(void);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/fusion.c b/lib/fusion.c
index 979469b..d1f074a 100644
--- a/lib/fusion.c
+++ b/lib/fusion.c
@@ -848,3 +848,15 @@
PTLS_AESGCM_TAG_SIZE,
sizeof(struct aesgcm_context),
aes128gcm_setup};
+
+int ptls_fusion_is_supported_by_cpu(void)
+{
+#define REQUIRE(s) \
+ if (!__builtin_cpu_supports(s)) \
+ return 0;
+ REQUIRE("avx2");
+ REQUIRE("aes");
+ REQUIRE("pclmul");
+#undef REQUIRE
+ return 1;
+}
diff --git a/t/fusion.c b/t/fusion.c
index dbe0b6e..a804e83 100644
--- a/t/fusion.c
+++ b/t/fusion.c
@@ -48,6 +48,11 @@
int main(int argc, char **argv)
{
+ if (!ptls_fusion_is_supported_by_cpu()) {
+ note("CPU does have the necessary features (avx2, aes, pclmul)\n");
+ return done_testing();
+ }
+
static const uint8_t zero[16384] = {}, one[16] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
{