Commit b697a0184f for openssl.org
commit b697a0184f65d8c8d7348f28856d17c998b90ab6
Author: Gleb Popov <6yearold@gmail.com>
Date: Mon Sep 1 20:54:47 2025 +0300
Add gf2m specialization for Elbrus2000
Reviewed-by: Andrew Dinh <andrewd@openssl.org>
Reviewed-by: Igor Ustinov <igus@openssl.foundation>
MergeDate: Fri Jul 31 16:49:36 2026
(Merged from https://github.com/openssl/openssl/pull/31269)
diff --git a/crypto/bn/asm/e2kv6-gf2m.c b/crypto/bn/asm/e2kv6-gf2m.c
new file mode 100644
index 0000000000..83c2729a0b
--- /dev/null
+++ b/crypto/bn/asm/e2kv6-gf2m.c
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2026 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License 2.0 (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+#include <e2kintrin.h>
+
+#include "../bn_local.h"
+
+void bn_GF2m_mul_2x2(BN_ULONG *r, const BN_ULONG a1, const BN_ULONG a0,
+ const BN_ULONG b1, const BN_ULONG b0)
+{
+ BN_ULONG m1, m0;
+
+ r[3] = __builtin_e2k_clmulh(a1, b1);
+ r[2] = __builtin_e2k_clmull(a1, b1);
+
+ r[1] = __builtin_e2k_clmulh(a0, b0);
+ r[0] = __builtin_e2k_clmull(a0, b0);
+
+ m1 = __builtin_e2k_clmulh(a0 ^ a1, b0 ^ b1);
+ m0 = __builtin_e2k_clmull(a0 ^ a1, b0 ^ b1);
+
+ r[2] ^= __builtin_e2k_plog(0x96, m1, r[1], r[3]);
+ r[1] = __builtin_e2k_plog(0x96, r[3], r[2], __builtin_e2k_plog(0x96, r[0], m1, m0));
+}
diff --git a/crypto/bn/build.info b/crypto/bn/build.info
index 01e98e4544..c895354346 100644
--- a/crypto/bn/build.info
+++ b/crypto/bn/build.info
@@ -90,6 +90,11 @@ IF[{- !$disabled{asm} -}]
$BNASM_c64xplus_ec2m=c64xplus-gf2m.s
$BNDEF_c64xplus_ec2m=OPENSSL_BN_ASM_GF2m
+ $BNASM_e2kv6=asm/e2kv6-gf2m.c
+ $BNDEF_e2kv6=OPENSSL_BN_ASM_GF2m
+ $BNASM_e2kv7=asm/e2kv6-gf2m.c
+ $BNDEF_e2kv7=OPENSSL_BN_ASM_GF2m
+
# Now that we have defined all the arch specific variables, use the
# appropriate ones, and define the appropriate macros
IF[$BNASM_{- $target{asm_arch} -}]