From 64a454df7e1d90e6c6de1009ee0dda2044899079 Mon Sep 17 00:00:00 2001
From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com>
Date: Thu, 5 Dec 2024 20:43:53 +0000
Subject: [PATCH 1/4] revert: stop tracking cmake dependency relic_conf.h.in
---
.../depends/relic/include/relic_conf.h.in | 717 ++++++++++++++++++
1 file changed, 717 insertions(+)
create mode 100644 src/dashbls/depends/relic/include/relic_conf.h.in
diff --git a/src/dashbls/depends/relic/include/relic_conf.h.in b/src/dashbls/depends/relic/include/relic_conf.h.in
new file mode 100644
index 0000000000..7db6f5b509
--- /dev/null
+++ b/src/dashbls/depends/relic/include/relic_conf.h.in
@@ -0,0 +1,717 @@
+/*
+ * RELIC is an Efficient LIbrary for Cryptography
+ * Copyright (c) 2009 RELIC Authors
+ *
+ * This file is part of RELIC. RELIC is legal property of its developers,
+ * whose names are not listed here. Please refer to the COPYRIGHT file
+ * for contact information.
+ *
+ * RELIC is free software; you can redistribute it and/or modify it under the
+ * terms of the version 2.1 (or later) of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; or version 2.0 of the Apache
+ * License as published by the Apache Software Foundation. See the LICENSE files
+ * for more details.
+ *
+ * RELIC is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the LICENSE files for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public or the
+ * Apache License along with RELIC. If not, see
+ * or .
+ */
+
+/**
+ * @file
+ *
+ * Project configuration.
+ *
+ * @version $Id: relic_conf.h.in 45 2009-07-04 23:45:48Z dfaranha $
+ * @ingroup relic
+ */
+
+#ifndef RLC_CONF_H
+#define RLC_CONF_H
+
+/** Project version. */
+#define RLC_VERSION "@VERSION@"
+
+/** Debugging support. */
+#cmakedefine DEBUG
+/** Profiling support. */
+#cmakedefine PROFL
+/** Error handling support. */
+#cmakedefine CHECK
+/** Verbose error messages. */
+#cmakedefine VERBS
+/** Build with overhead estimation. */
+#cmakedefine OVERH
+/** Build documentation. */
+#cmakedefine DOCUM
+/** Build only the selected algorithms. */
+#cmakedefine STRIP
+/** Build with printing disabled. */
+#cmakedefine QUIET
+/** Build with colored output. */
+#cmakedefine COLOR
+/** Build with big-endian support. */
+#cmakedefine BIGED
+/** Build shared library. */
+#cmakedefine SHLIB
+/** Build static library. */
+#cmakedefine STLIB
+
+/** Number of times each test is ran. */
+#define TESTS @TESTS@
+/** Number of times each benchmark is ran. */
+#define BENCH @BENCH@
+/** Number of available cores. */
+#define CORES @CORES@
+
+/** Atmel AVR ATMega128 8-bit architecture. */
+#define AVR 1
+/** MSP430 16-bit architecture. */
+#define MSP 2
+/** ARM 32-bit architecture. */
+#define ARM 3
+/** Intel x86-compatible 32-bit architecture. */
+#define X86 4
+/** AMD64-compatible 64-bit architecture. */
+#define X64 5
+/** Architecture. */
+#cmakedefine ARCH @ARCH@
+
+/** Size of word in this architecture. */
+#define WSIZE @WSIZE@
+
+/** Byte boundary to align digit vectors. */
+#define ALIGN @ALIGN@
+
+/** Build multiple precision integer module. */
+#cmakedefine WITH_BN
+/** Build prime field module. */
+#cmakedefine WITH_FP
+/** Build prime field extension module. */
+#cmakedefine WITH_FPX
+/** Build binary field module. */
+#cmakedefine WITH_FB
+/** Build prime elliptic curve module. */
+#cmakedefine WITH_EP
+/** Build prime field extension elliptic curve module. */
+#cmakedefine WITH_EPX
+/** Build binary elliptic curve module. */
+#cmakedefine WITH_EB
+/** Build elliptic Edwards curve module. */
+#cmakedefine WITH_ED
+/** Build elliptic curve cryptography module. */
+#cmakedefine WITH_EC
+/** Build pairings over prime curves module. */
+#cmakedefine WITH_PP
+/** Build pairing-based cryptography module. */
+#cmakedefine WITH_PC
+/** Build block ciphers. */
+#cmakedefine WITH_BC
+/** Build hash functions. */
+#cmakedefine WITH_MD
+/** Build cryptographic protocols. */
+#cmakedefine WITH_CP
+/** Build Multi-party computation primitives. */
+#cmakedefine WITH_MPC
+
+/** Easy C-only backend. */
+#define EASY 1
+/** GMP backend. */
+#define GMP 2
+/** GMP constant-time backend. */
+#define GMP_SEC 3
+/** Arithmetic backend. */
+#define ARITH @ARITH@
+
+/** Required precision in bits. */
+#define BN_PRECI @BN_PRECI@
+/** A multiple precision integer can store w words. */
+#define SINGLE 0
+/** A multiple precision integer can store the result of an addition. */
+#define CARRY 1
+/** A multiple precision integer can store the result of a multiplication. */
+#define DOUBLE 2
+/** Effective size of a multiple precision integer. */
+#define BN_MAGNI @BN_MAGNI@
+/** Number of Karatsuba steps. */
+#define BN_KARAT @BN_KARAT@
+
+/** Schoolbook multiplication. */
+#define BASIC 1
+/** Comba multiplication. */
+#define COMBA 2
+/** Chosen multiple precision multiplication method. */
+#define BN_MUL @BN_MUL@
+
+/** Schoolbook squaring. */
+#define BASIC 1
+/** Comba squaring. */
+#define COMBA 2
+/** Reuse multiplication for squaring. */
+#define MULTP 4
+/** Chosen multiple precision multiplication method. */
+#define BN_SQR @BN_SQR@
+
+/** Division modular reduction. */
+#define BASIC 1
+/** Barrett modular reduction. */
+#define BARRT 2
+/** Montgomery modular reduction. */
+#define MONTY 3
+/** Pseudo-Mersenne modular reduction. */
+#define PMERS 4
+/** Chosen multiple precision modular reduction method. */
+#define BN_MOD @BN_MOD@
+
+/** Binary modular exponentiation. */
+#define BASIC 1
+/** Sliding window modular exponentiation. */
+#define SLIDE 2
+/** Montgomery powering ladder. */
+#define MONTY 3
+/** Chosen multiple precision modular exponentiation method. */
+#define BN_MXP @BN_MXP@
+
+/** Basic Euclidean GCD Algorithm. */
+#define BASIC 1
+/** Lehmer's fast GCD Algorithm. */
+#define LEHME 2
+/** Stein's binary GCD Algorithm. */
+#define STEIN 3
+/** Chosen multiple precision greatest common divisor method. */
+#define BN_GCD @BN_GCD@
+
+/** Basic prime generation. */
+#define BASIC 1
+/** Safe prime generation. */
+#define SAFEP 2
+/** Strong prime generation. */
+#define STRON 3
+/** Chosen prime generation algorithm. */
+#define BN_GEN @BN_GEN@
+
+/** Multiple precision arithmetic method */
+#define BN_METHD "@BN_METHD@"
+
+/** Prime field size in bits. */
+#define FP_PRIME @FP_PRIME@
+/** Number of Karatsuba steps. */
+#define FP_KARAT @FP_KARAT@
+/** Prefer Pseudo-Mersenne primes over random primes. */
+#cmakedefine FP_PMERS
+/** Use -1 as quadratic non-residue. */
+#cmakedefine FP_QNRES
+/** Width of window processing for exponentiation methods. */
+#define FP_WIDTH @FP_WIDTH@
+
+/** Schoolbook addition. */
+#define BASIC 1
+/** Integrated modular addtion. */
+#define INTEG 3
+/** Chosen prime field multiplication method. */
+#define FP_ADD @FP_ADD@
+
+/** Schoolbook multiplication. */
+#define BASIC 1
+/** Comba multiplication. */
+#define COMBA 2
+/** Integrated modular multiplication. */
+#define INTEG 3
+/** Chosen prime field multiplication method. */
+#define FP_MUL @FP_MUL@
+
+/** Schoolbook squaring. */
+#define BASIC 1
+/** Comba squaring. */
+#define COMBA 2
+/** Integrated modular squaring. */
+#define INTEG 3
+/** Reuse multiplication for squaring. */
+#define MULTP 4
+/** Chosen prime field multiplication method. */
+#define FP_SQR @FP_SQR@
+
+/** Division-based reduction. */
+#define BASIC 1
+/** Fast reduction modulo special form prime. */
+#define QUICK 2
+/** Montgomery modular reduction. */
+#define MONTY 3
+/** Chosen prime field reduction method. */
+#define FP_RDC @FP_RDC@
+
+/** Inversion by Fermat's Little Theorem. */
+#define BASIC 1
+/** Binary inversion. */
+#define BINAR 2
+/** Integrated modular multiplication. */
+#define MONTY 3
+/** Extended Euclidean algorithm. */
+#define EXGCD 4
+/** Constant-time inversion by Bernstein-Yang division steps. */
+#define DIVST 5
+/** Use implementation provided by the lower layer. */
+#define LOWER 8
+/** Chosen prime field inversion method. */
+#define FP_INV @FP_INV@
+
+/** Binary modular exponentiation. */
+#define BASIC 1
+/** Sliding window modular exponentiation. */
+#define SLIDE 2
+/** Constant-time Montgomery powering ladder. */
+#define MONTY 3
+/** Chosen multiple precision modular exponentiation method. */
+#define FP_EXP @FP_EXP@
+
+/** Prime field arithmetic method */
+#define FP_METHD "@FP_METHD@"
+
+/** Basic quadratic extension field arithmetic. */
+#define BASIC 1
+/** Integrated extension field arithmetic. */
+#define INTEG 3
+/* Chosen extension field arithmetic method. */
+#define FPX_QDR @FPX_QDR@
+
+/** Basic cubic extension field arithmetic. */
+#define BASIC 1
+/** Integrated extension field arithmetic. */
+#define INTEG 3
+/* Chosen extension field arithmetic method. */
+#define FPX_CBC @FPX_CBC@
+
+/** Basic quadratic extension field arithmetic. */
+#define BASIC 1
+/** Lazy-reduced extension field arithmetic. */
+#define LAZYR 2
+/* Chosen extension field arithmetic method. */
+#define FPX_RDC @FPX_RDC@
+
+/** Prime extension field arithmetic method */
+#define FPX_METHD "@FPX_METHD@"
+
+/** Irreducible polynomial size in bits. */
+#define FB_POLYN @FB_POLYN@
+/** Number of Karatsuba steps. */
+#define FB_KARAT @FB_KARAT@
+/** Prefer trinomials over pentanomials. */
+#cmakedefine FB_TRINO
+/** Prefer square-root friendly polynomials. */
+#cmakedefine FB_SQRTF
+/** Precompute multiplication table for sqrt(z). */
+#cmakedefine FB_PRECO
+/** Width of window processing for exponentiation methods. */
+#define FB_WIDTH @FB_WIDTH@
+
+/** Shift-and-add multiplication. */
+#define BASIC 1
+/** Lopez-Dahab multiplication. */
+#define LODAH 2
+/** Integrated modular multiplication. */
+#define INTEG 3
+/** Chosen binary field multiplication method. */
+#define FB_MUL @FB_MUL@
+
+/** Basic squaring. */
+#define BASIC 1
+/** Table-based squaring. */
+#define QUICK 2
+/** Integrated modular squaring. */
+#define INTEG 3
+/** Chosen binary field squaring method. */
+#define FB_SQR @FB_SQR@
+
+/** Shift-and-add modular reduction. */
+#define BASIC 1
+/** Fast reduction modulo a trinomial or pentanomial. */
+#define QUICK 2
+/** Chosen binary field modular reduction method. */
+#define FB_RDC @FB_RDC@
+
+/** Square root by repeated squaring. */
+#define BASIC 1
+/** Fast square root extraction. */
+#define QUICK 2
+/** Chosen binary field modular reduction method. */
+#define FB_SRT @FB_SRT@
+
+/** Trace by repeated squaring. */
+#define BASIC 1
+/** Fast trace computation. */
+#define QUICK 2
+/** Chosen trace computation method. */
+#define FB_TRC @FB_TRC@
+
+/** Solve by half-trace computation. */
+#define BASIC 1
+/** Solve with precomputed half-traces. */
+#define QUICK 2
+/** Chosen method to solve a quadratic equation. */
+#define FB_SLV @FB_SLV@
+
+/** Inversion by Fermat's Little Theorem. */
+#define BASIC 1
+/** Binary inversion. */
+#define BINAR 2
+/** Almost inverse algorithm. */
+#define ALMOS 3
+/** Extended Euclidean algorithm. */
+#define EXGCD 4
+/** Itoh-Tsuji inversion. */
+#define ITOHT 5
+/** Hardware-friendly inversion by Brunner-Curiger-Hofstetter.*/
+#define BRUCH 6
+/** Constant-time version of almost inverse. */
+#define CTAIA 7
+/** Use implementation provided by the lower layer. */
+#define LOWER 8
+/** Chosen binary field inversion method. */
+#define FB_INV @FB_INV@
+
+/** Binary modular exponentiation. */
+#define BASIC 1
+/** Sliding window modular exponentiation. */
+#define SLIDE 2
+/** Constant-time Montgomery powering ladder. */
+#define MONTY 3
+/** Chosen multiple precision modular exponentiation method. */
+#define FB_EXP @FB_EXP@
+
+/** Iterated squaring/square-root by consecutive squaring/square-root. */
+#define BASIC 1
+/** Iterated squaring/square-root by table-based method. */
+#define QUICK 2
+/** Chosen method to solve a quadratic equation. */
+#define FB_ITR @FB_ITR@
+
+/** Binary field arithmetic method */
+#define FB_METHD "@FB_METHD@"
+
+/** Support for ordinary curves. */
+#cmakedefine EP_PLAIN
+/** Support for supersingular curves. */
+#cmakedefine EP_SUPER
+/** Support for prime curves with efficient endormorphisms. */
+#cmakedefine EP_ENDOM
+/** Use mixed coordinates. */
+#cmakedefine EP_MIXED
+/** Build precomputation table for generator. */
+#cmakedefine EP_PRECO
+/** Enable isogeny map for SSWU map-to-curve. */
+#cmakedefine EP_CTMAP
+/** Width of precomputation table for fixed point methods. */
+#define EP_DEPTH @EP_DEPTH@
+/** Width of window processing for unknown point methods. */
+#define EP_WIDTH @EP_WIDTH@
+
+/** Affine coordinates. */
+#define BASIC 1
+/** Projective coordinates. */
+#define PROJC 2
+/** Jacobian coordinates. */
+#define JACOB 3
+/** Chosen prime elliptic curve coordinate method. */
+#define EP_ADD @EP_ADD@
+
+/** Binary point multiplication. */
+#define BASIC 1
+/** Sliding window. */
+#define SLIDE 2
+/** Montgomery powering ladder. */
+#define MONTY 3
+/** Left-to-right Width-w NAF. */
+#define LWNAF 4
+/** Left-to-right Width-w NAF. */
+#define LWREG 5
+/** Chosen prime elliptic curve point multiplication method. */
+#define EP_MUL @EP_MUL@
+
+/** Binary point multiplication. */
+#define BASIC 1
+/** Single-table comb method. */
+#define COMBS 2
+/** Double-table comb method. */
+#define COMBD 3
+/** Left-to-right Width-w NAF. */
+#define LWNAF 4
+/** Chosen prime elliptic curve point multiplication method. */
+#define EP_FIX @EP_FIX@
+
+/** Basic simultaneouns point multiplication. */
+#define BASIC 1
+/** Shamir's trick. */
+#define TRICK 2
+/** Interleaving of w-(T)NAFs. */
+#define INTER 3
+/** Joint sparse form. */
+#define JOINT 4
+/** Chosen prime elliptic curve simulteanous point multiplication method. */
+#define EP_SIM @EP_SIM@
+
+/** Prime elliptic curve arithmetic method. */
+#define EP_METHD "@EP_METHD@"
+
+/** Support for ordinary curves without endormorphisms. */
+#cmakedefine EB_PLAIN
+/** Support for Koblitz anomalous binary curves. */
+#cmakedefine EB_KBLTZ
+/** Use mixed coordinates. */
+#cmakedefine EB_MIXED
+/** Build precomputation table for generator. */
+#cmakedefine EB_PRECO
+/** Width of precomputation table for fixed point methods. */
+#define EB_DEPTH @EB_DEPTH@
+/** Width of window processing for unknown point methods. */
+#define EB_WIDTH @EB_WIDTH@
+
+/** Binary elliptic curve arithmetic method. */
+#define EB_METHD "@EB_METHD@"
+
+/** Affine coordinates. */
+#define BASIC 1
+/** López-Dahab Projective coordinates. */
+#define PROJC 2
+/** Chosen binary elliptic curve coordinate method. */
+#define EB_ADD @EB_ADD@
+
+/** Binary point multiplication. */
+#define BASIC 1
+/** L�pez-Dahab point multiplication. */
+#define LODAH 2
+/** Halving. */
+#define HALVE 3
+/** Left-to-right width-w (T)NAF. */
+#define LWNAF 4
+/** Right-to-left width-w (T)NAF. */
+#define RWNAF 5
+/** Chosen binary elliptic curve point multiplication method. */
+#define EB_MUL @EB_MUL@
+
+/** Binary point multiplication. */
+#define BASIC 1
+/** Single-table comb method. */
+#define COMBS 2
+/** Double-table comb method. */
+#define COMBD 3
+/** Left-to-right Width-w NAF. */
+#define LWNAF 4
+/** Chosen binary elliptic curve point multiplication method. */
+#define EB_FIX @EB_FIX@
+
+/** Basic simultaneouns point multiplication. */
+#define BASIC 1
+/** Shamir's trick. */
+#define TRICK 2
+/** Interleaving of w-(T)NAFs. */
+#define INTER 3
+/** Joint sparse form. */
+#define JOINT 4
+/** Chosen binary elliptic curve simulteanous point multiplication method. */
+#define EB_SIM @EB_SIM@
+
+/** Build precomputation table for generator. */
+#cmakedefine ED_PRECO
+/** Width of precomputation table for fixed point methods. */
+#define ED_DEPTH @ED_DEPTH@
+/** Width of window processing for unknown point methods. */
+#define ED_WIDTH @ED_WIDTH@
+
+/** Edwards elliptic curve arithmetic method. */
+#define ED_METHD "@ED_METHD@"
+
+/** Affine coordinates. */
+#define BASIC 1
+/** Simple projective twisted Edwards coordinates */
+#define PROJC 2
+/** Extended projective twisted Edwards coordinates */
+#define EXTND 3
+/** Chosen binary elliptic curve coordinate method. */
+#define ED_ADD @ED_ADD@
+
+/** Binary point multiplication. */
+#define BASIC 1
+/** Sliding window. */
+#define SLIDE 2
+/** Montgomery powering ladder. */
+#define MONTY 3
+/** Left-to-right Width-w NAF. */
+#define LWNAF 4
+/** Left-to-right Width-w NAF. */
+#define LWREG 5
+/** Chosen prime elliptic twisted Edwards curve point multiplication method. */
+#define ED_MUL @ED_MUL@
+
+/** Binary point multiplication. */
+#define BASIC 1
+/** Single-table comb method. */
+#define COMBS 2
+/** Double-table comb method. */
+#define COMBD 3
+/** Left-to-right Width-w NAF. */
+#define LWNAF 4
+/** Chosen prime elliptic twisted Edwards curve point multiplication method. */
+#define ED_FIX @ED_FIX@
+
+/** Basic simultaneouns point multiplication. */
+#define BASIC 1
+/** Shamir's trick. */
+#define TRICK 2
+/** Interleaving of w-(T)NAFs. */
+#define INTER 3
+/** Joint sparse form. */
+#define JOINT 4
+/** Chosen prime elliptic curve simulteanous point multiplication method. */
+#define ED_SIM @ED_SIM@
+
+/** Prime curves. */
+#define PRIME 1
+/** Binary curves. */
+#define CHAR2 2
+/** Edwards curves */
+#define EDDIE 3
+/** Chosen elliptic curve type. */
+#define EC_CUR @EC_CUR@
+
+/** Chosen elliptic curve cryptography method. */
+#define EC_METHD "@EC_METHD@"
+/** Prefer curves with efficient endomorphisms. */
+#cmakedefine EC_ENDOM
+
+/** Basic quadratic extension field arithmetic. */
+#define BASIC 1
+/** Lazy-reduced extension field arithmetic. */
+#define LAZYR 2
+/* Chosen extension field arithmetic method. */
+#define PP_EXT @PP_EXT@
+
+/** Bilinear pairing method. */
+#define PP_METHD "@PP_METHD@"
+
+/** Tate pairing. */
+#define TATEP 1
+/** Weil pairing. */
+#define WEILP 2
+/** Optimal ate pairing. */
+#define OATEP 3
+/** Chosen pairing method over prime elliptic curves. */
+#define PP_MAP @PP_MAP@
+
+/** SHA-224 hash function. */
+#define SH224 2
+/** SHA-256 hash function. */
+#define SH256 3
+/** SHA-384 hash function. */
+#define SH384 4
+/** SHA-512 hash function. */
+#define SH512 5
+/** BLAKE2s-160 hash function. */
+#define B2S160 6
+/** BLAKE2s-256 hash function. */
+#define B2S256 7
+/** Chosen hash function. */
+#define MD_MAP @MD_MAP@
+
+/** Choice of hash function. */
+#define MD_METHD "@MD_METHD@"
+
+/** Chosen RSA method. */
+#cmakedefine CP_CRT
+/** RSA without padding. */
+#define BASIC 1
+/** RSA PKCS#1 v1.5 padding. */
+#define PKCS1 2
+/** RSA PKCS#1 v2.1 padding. */
+#define PKCS2 3
+/** Chosen RSA padding method. */
+#define CP_RSAPD @CP_RSAPD@
+
+/** Automatic memory allocation. */
+#define AUTO 1
+/** Dynamic memory allocation. */
+#define DYNAMIC 2
+/** Chosen memory allocation policy. */
+#define ALLOC @ALLOC@
+
+/** NIST HASH-DRBG generator. */
+#define HASHD 1
+/** Intel RdRand instruction. */
+#define RDRND 2
+/** Operating system underlying generator. */
+#define UDEV 3
+/** Override library generator with the callback. */
+#define CALL 4
+/** Chosen random generator. */
+#define RAND @RAND@
+
+/** Standard C library generator. */
+#define LIBC 1
+/** Intel RdRand instruction. */
+#define RDRND 2
+/** Device node generator. */
+#define UDEV 3
+/** Use Windows' CryptGenRandom. */
+#define WCGR 4
+/** Chosen random generator seeder. */
+#cmakedefine SEED @SEED@
+
+/** GNU/Linux operating system. */
+#define LINUX 1
+/** FreeBSD operating system. */
+#define FREEBSD 2
+/** Windows operating system. */
+#define MACOSX 3
+/** Windows operating system. */
+#define WINDOWS 4
+/** Android operating system. */
+#define DROID 5
+/** Arduino platform. */
+#define DUINO 6
+/** OpenBSD operating system. */
+#define OPENBSD 7
+/** Detected operation system. */
+#cmakedefine OPSYS @OPSYS@
+
+/** OpenMP multithreading support. */
+#define OPENMP 1
+/** POSIX multithreading support. */
+#define PTHREAD 2
+/** Chosen multithreading API. */
+#cmakedefine MULTI @MULTI@
+
+/** Per-process high-resolution timer. */
+#define HREAL 1
+/** Per-process high-resolution timer. */
+#define HPROC 2
+/** Per-thread high-resolution timer. */
+#define HTHRD 3
+/** POSIX-compatible timer. */
+#define POSIX 4
+/** ANSI-compatible timer. */
+#define ANSI 5
+/** Cycle-counting timer. */
+#define CYCLE 6
+/** Performance monitoring framework. */
+#define PERF 7
+/** Chosen timer. */
+#cmakedefine TIMER @TIMER@
+
+/** Prefix to identity this build of the library. */
+#cmakedefine LABEL @LABEL@
+
+#ifndef ASM
+
+#include "relic_label.h"
+
+/**
+ * Prints the project options selected at build time.
+ */
+void conf_print(void);
+
+#endif /* ASM */
+
+#endif /* !RLC_CONF_H */
From 3ac26192a9a234b56d47d39d627a8b1ea262b6ee Mon Sep 17 00:00:00 2001
From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com>
Date: Thu, 5 Dec 2024 20:44:38 +0000
Subject: [PATCH 2/4] Squashed 'src/dashbls/' changes from
7e747e8a07..30aa085b2b
30aa085b2b fixup: apply code review comments
a3afed8669 refactor: continued reduced duplication
0f3705b7db simplify G1Element::Serialize by using G1Element::SerializeToArray
677db58fc3 add SerializeToArray for PrivateKey
d1b3d244f0 fixup add const
09ac2e90d5 feat: implement std::array based serialization
REVERT: 7e747e8a07 Merge pull request #105 from kwvg/bump_1.3.4
REVERT: f8703c9971 chore: bump version to 1.3.4
git-subtree-dir: src/dashbls
git-subtree-split: 30aa085b2b8a169c157d3dfcba2caf604e8d3e54
---
configure.ac | 2 +-
include/dashbls/elements.hpp | 3 +++
include/dashbls/privatekey.hpp | 1 +
src/elements.cpp | 28 ++++++++++++++++++++++++----
src/privatekey.cpp | 7 +++++++
5 files changed, 36 insertions(+), 5 deletions(-)
diff --git a/configure.ac b/configure.ac
index df411ced0c..737e74eb05 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
AC_PREREQ([2.60])
-AC_INIT([libdashbls],[1.3.4])
+AC_INIT([libdashbls],[1.3.3])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([build-aux/m4])
diff --git a/include/dashbls/elements.hpp b/include/dashbls/elements.hpp
index 6832b31f3a..95937f62db 100644
--- a/include/dashbls/elements.hpp
+++ b/include/dashbls/elements.hpp
@@ -59,6 +59,7 @@ public:
GTElement Pair(const G2Element &b) const;
uint32_t GetFingerprint(bool fLegacy = false) const;
std::vector Serialize(bool fLegacy = false) const;
+ std::array SerializeToArray(bool fLegacy = false) const;
G1Element Copy();
friend bool operator==(const G1Element &a, const G1Element &b);
@@ -102,6 +103,7 @@ public:
G2Element Negate() const;
GTElement Pair(const G1Element &a) const;
std::vector Serialize(bool fLegacy = false) const;
+ std::array SerializeToArray(bool fLegacy = false) const;
G2Element Copy();
friend bool operator==(G2Element const &a, G2Element const &b);
@@ -127,6 +129,7 @@ public:
void Serialize(uint8_t *buffer) const;
std::vector Serialize() const;
+ std::array SerializeToArray() const;
friend bool operator==(GTElement const &a, GTElement const &b);
friend bool operator!=(GTElement const &a, GTElement const &b);
diff --git a/include/dashbls/privatekey.hpp b/include/dashbls/privatekey.hpp
index beebbb05ab..d02a7d292c 100644
--- a/include/dashbls/privatekey.hpp
+++ b/include/dashbls/privatekey.hpp
@@ -82,6 +82,7 @@ class PrivateKey {
// Serialize the key into bytes
void Serialize(uint8_t *buffer) const;
std::vector Serialize(bool fLegacy = false) const;
+ std::array SerializeToArray(bool fLegacy = false) const;
G2Element SignG2(
const uint8_t *msg,
diff --git a/src/elements.cpp b/src/elements.cpp
index 278af8cd8f..b0c747af82 100644
--- a/src/elements.cpp
+++ b/src/elements.cpp
@@ -171,11 +171,16 @@ uint32_t G1Element::GetFingerprint(const bool fLegacy) const
}
std::vector G1Element::Serialize(const bool fLegacy) const {
+ const auto arr = G1Element::SerializeToArray(fLegacy);
+ return std::vector{arr.begin(), arr.end()};
+}
+
+std::array G1Element::SerializeToArray(const bool fLegacy) const {
uint8_t buffer[G1Element::SIZE + 1];
g1_write_bin(buffer, G1Element::SIZE + 1, p, 1);
+ std::array result{};
if (buffer[0] == 0x00) { // infinity
- std::vector result(G1Element::SIZE, 0);
result[0] = 0xc0;
return result;
}
@@ -187,7 +192,9 @@ std::vector G1Element::Serialize(const bool fLegacy) const {
if (!fLegacy) {
buffer[1] |= 0x80; // indicate compression
}
- return std::vector(buffer + 1, buffer + 1 + G1Element::SIZE);
+
+ std::copy_n(buffer + 1, G1Element::SIZE, result.begin());
+ return result;
}
bool operator==(const G1Element & a, const G1Element &b)
@@ -386,11 +393,18 @@ G2Element G2Element::Negate() const
GTElement G2Element::Pair(const G1Element& a) const { return a & (*this); }
std::vector G2Element::Serialize(const bool fLegacy) const {
+ const auto arr = G2Element::SerializeToArray(fLegacy);
+ return std::vector{arr.begin(), arr.end()};
+}
+
+std::array G2Element::SerializeToArray(const bool fLegacy) const {
uint8_t buffer[G2Element::SIZE + 1];
g2_write_bin(buffer, G2Element::SIZE + 1, (g2_st*)q, 1);
+ std::array result{};
+
if (buffer[0] == 0x00) { // infinity
- std::vector result(G2Element::SIZE, 0);
+ result.fill(0);
result[0] = 0xc0;
return result;
}
@@ -410,7 +424,6 @@ std::vector G2Element::Serialize(const bool fLegacy) const {
}
}
- std::vector result(G2Element::SIZE, 0);
if (fLegacy) {
std::memcpy(result.data(), buffer + 1, G2Element::SIZE);
} else {
@@ -551,4 +564,11 @@ std::vector GTElement::Serialize() const
return data;
}
+std::array GTElement::SerializeToArray() const
+{
+ std::array data{};
+ Serialize(data.data());
+ return data;
+}
+
} // end namespace bls
diff --git a/src/privatekey.cpp b/src/privatekey.cpp
index 865507dfc7..d4dd32d116 100644
--- a/src/privatekey.cpp
+++ b/src/privatekey.cpp
@@ -284,6 +284,13 @@ std::vector PrivateKey::Serialize(const bool fLegacy) const
return data;
}
+std::array PrivateKey::SerializeToArray(bool fLegacy) const
+{
+ std::array data{};
+ Serialize(data.data());
+ return data;
+}
+
G2Element PrivateKey::SignG2(
const uint8_t *msg,
size_t len,
From cd115c29896fcee9f04b893d5c469f824c33afcd Mon Sep 17 00:00:00 2001
From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com>
Date: Wed, 28 Jun 2023 23:44:03 +0300
Subject: [PATCH 3/4] build: stop tracking cmake dependency relic_conf.h.in
---
.../depends/relic/include/relic_conf.h.in | 717 ------------------
1 file changed, 717 deletions(-)
delete mode 100644 src/dashbls/depends/relic/include/relic_conf.h.in
diff --git a/src/dashbls/depends/relic/include/relic_conf.h.in b/src/dashbls/depends/relic/include/relic_conf.h.in
deleted file mode 100644
index 7db6f5b509..0000000000
--- a/src/dashbls/depends/relic/include/relic_conf.h.in
+++ /dev/null
@@ -1,717 +0,0 @@
-/*
- * RELIC is an Efficient LIbrary for Cryptography
- * Copyright (c) 2009 RELIC Authors
- *
- * This file is part of RELIC. RELIC is legal property of its developers,
- * whose names are not listed here. Please refer to the COPYRIGHT file
- * for contact information.
- *
- * RELIC is free software; you can redistribute it and/or modify it under the
- * terms of the version 2.1 (or later) of the GNU Lesser General Public License
- * as published by the Free Software Foundation; or version 2.0 of the Apache
- * License as published by the Apache Software Foundation. See the LICENSE files
- * for more details.
- *
- * RELIC is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the LICENSE files for more details.
- *
- * You should have received a copy of the GNU Lesser General Public or the
- * Apache License along with RELIC. If not, see
- * or .
- */
-
-/**
- * @file
- *
- * Project configuration.
- *
- * @version $Id: relic_conf.h.in 45 2009-07-04 23:45:48Z dfaranha $
- * @ingroup relic
- */
-
-#ifndef RLC_CONF_H
-#define RLC_CONF_H
-
-/** Project version. */
-#define RLC_VERSION "@VERSION@"
-
-/** Debugging support. */
-#cmakedefine DEBUG
-/** Profiling support. */
-#cmakedefine PROFL
-/** Error handling support. */
-#cmakedefine CHECK
-/** Verbose error messages. */
-#cmakedefine VERBS
-/** Build with overhead estimation. */
-#cmakedefine OVERH
-/** Build documentation. */
-#cmakedefine DOCUM
-/** Build only the selected algorithms. */
-#cmakedefine STRIP
-/** Build with printing disabled. */
-#cmakedefine QUIET
-/** Build with colored output. */
-#cmakedefine COLOR
-/** Build with big-endian support. */
-#cmakedefine BIGED
-/** Build shared library. */
-#cmakedefine SHLIB
-/** Build static library. */
-#cmakedefine STLIB
-
-/** Number of times each test is ran. */
-#define TESTS @TESTS@
-/** Number of times each benchmark is ran. */
-#define BENCH @BENCH@
-/** Number of available cores. */
-#define CORES @CORES@
-
-/** Atmel AVR ATMega128 8-bit architecture. */
-#define AVR 1
-/** MSP430 16-bit architecture. */
-#define MSP 2
-/** ARM 32-bit architecture. */
-#define ARM 3
-/** Intel x86-compatible 32-bit architecture. */
-#define X86 4
-/** AMD64-compatible 64-bit architecture. */
-#define X64 5
-/** Architecture. */
-#cmakedefine ARCH @ARCH@
-
-/** Size of word in this architecture. */
-#define WSIZE @WSIZE@
-
-/** Byte boundary to align digit vectors. */
-#define ALIGN @ALIGN@
-
-/** Build multiple precision integer module. */
-#cmakedefine WITH_BN
-/** Build prime field module. */
-#cmakedefine WITH_FP
-/** Build prime field extension module. */
-#cmakedefine WITH_FPX
-/** Build binary field module. */
-#cmakedefine WITH_FB
-/** Build prime elliptic curve module. */
-#cmakedefine WITH_EP
-/** Build prime field extension elliptic curve module. */
-#cmakedefine WITH_EPX
-/** Build binary elliptic curve module. */
-#cmakedefine WITH_EB
-/** Build elliptic Edwards curve module. */
-#cmakedefine WITH_ED
-/** Build elliptic curve cryptography module. */
-#cmakedefine WITH_EC
-/** Build pairings over prime curves module. */
-#cmakedefine WITH_PP
-/** Build pairing-based cryptography module. */
-#cmakedefine WITH_PC
-/** Build block ciphers. */
-#cmakedefine WITH_BC
-/** Build hash functions. */
-#cmakedefine WITH_MD
-/** Build cryptographic protocols. */
-#cmakedefine WITH_CP
-/** Build Multi-party computation primitives. */
-#cmakedefine WITH_MPC
-
-/** Easy C-only backend. */
-#define EASY 1
-/** GMP backend. */
-#define GMP 2
-/** GMP constant-time backend. */
-#define GMP_SEC 3
-/** Arithmetic backend. */
-#define ARITH @ARITH@
-
-/** Required precision in bits. */
-#define BN_PRECI @BN_PRECI@
-/** A multiple precision integer can store w words. */
-#define SINGLE 0
-/** A multiple precision integer can store the result of an addition. */
-#define CARRY 1
-/** A multiple precision integer can store the result of a multiplication. */
-#define DOUBLE 2
-/** Effective size of a multiple precision integer. */
-#define BN_MAGNI @BN_MAGNI@
-/** Number of Karatsuba steps. */
-#define BN_KARAT @BN_KARAT@
-
-/** Schoolbook multiplication. */
-#define BASIC 1
-/** Comba multiplication. */
-#define COMBA 2
-/** Chosen multiple precision multiplication method. */
-#define BN_MUL @BN_MUL@
-
-/** Schoolbook squaring. */
-#define BASIC 1
-/** Comba squaring. */
-#define COMBA 2
-/** Reuse multiplication for squaring. */
-#define MULTP 4
-/** Chosen multiple precision multiplication method. */
-#define BN_SQR @BN_SQR@
-
-/** Division modular reduction. */
-#define BASIC 1
-/** Barrett modular reduction. */
-#define BARRT 2
-/** Montgomery modular reduction. */
-#define MONTY 3
-/** Pseudo-Mersenne modular reduction. */
-#define PMERS 4
-/** Chosen multiple precision modular reduction method. */
-#define BN_MOD @BN_MOD@
-
-/** Binary modular exponentiation. */
-#define BASIC 1
-/** Sliding window modular exponentiation. */
-#define SLIDE 2
-/** Montgomery powering ladder. */
-#define MONTY 3
-/** Chosen multiple precision modular exponentiation method. */
-#define BN_MXP @BN_MXP@
-
-/** Basic Euclidean GCD Algorithm. */
-#define BASIC 1
-/** Lehmer's fast GCD Algorithm. */
-#define LEHME 2
-/** Stein's binary GCD Algorithm. */
-#define STEIN 3
-/** Chosen multiple precision greatest common divisor method. */
-#define BN_GCD @BN_GCD@
-
-/** Basic prime generation. */
-#define BASIC 1
-/** Safe prime generation. */
-#define SAFEP 2
-/** Strong prime generation. */
-#define STRON 3
-/** Chosen prime generation algorithm. */
-#define BN_GEN @BN_GEN@
-
-/** Multiple precision arithmetic method */
-#define BN_METHD "@BN_METHD@"
-
-/** Prime field size in bits. */
-#define FP_PRIME @FP_PRIME@
-/** Number of Karatsuba steps. */
-#define FP_KARAT @FP_KARAT@
-/** Prefer Pseudo-Mersenne primes over random primes. */
-#cmakedefine FP_PMERS
-/** Use -1 as quadratic non-residue. */
-#cmakedefine FP_QNRES
-/** Width of window processing for exponentiation methods. */
-#define FP_WIDTH @FP_WIDTH@
-
-/** Schoolbook addition. */
-#define BASIC 1
-/** Integrated modular addtion. */
-#define INTEG 3
-/** Chosen prime field multiplication method. */
-#define FP_ADD @FP_ADD@
-
-/** Schoolbook multiplication. */
-#define BASIC 1
-/** Comba multiplication. */
-#define COMBA 2
-/** Integrated modular multiplication. */
-#define INTEG 3
-/** Chosen prime field multiplication method. */
-#define FP_MUL @FP_MUL@
-
-/** Schoolbook squaring. */
-#define BASIC 1
-/** Comba squaring. */
-#define COMBA 2
-/** Integrated modular squaring. */
-#define INTEG 3
-/** Reuse multiplication for squaring. */
-#define MULTP 4
-/** Chosen prime field multiplication method. */
-#define FP_SQR @FP_SQR@
-
-/** Division-based reduction. */
-#define BASIC 1
-/** Fast reduction modulo special form prime. */
-#define QUICK 2
-/** Montgomery modular reduction. */
-#define MONTY 3
-/** Chosen prime field reduction method. */
-#define FP_RDC @FP_RDC@
-
-/** Inversion by Fermat's Little Theorem. */
-#define BASIC 1
-/** Binary inversion. */
-#define BINAR 2
-/** Integrated modular multiplication. */
-#define MONTY 3
-/** Extended Euclidean algorithm. */
-#define EXGCD 4
-/** Constant-time inversion by Bernstein-Yang division steps. */
-#define DIVST 5
-/** Use implementation provided by the lower layer. */
-#define LOWER 8
-/** Chosen prime field inversion method. */
-#define FP_INV @FP_INV@
-
-/** Binary modular exponentiation. */
-#define BASIC 1
-/** Sliding window modular exponentiation. */
-#define SLIDE 2
-/** Constant-time Montgomery powering ladder. */
-#define MONTY 3
-/** Chosen multiple precision modular exponentiation method. */
-#define FP_EXP @FP_EXP@
-
-/** Prime field arithmetic method */
-#define FP_METHD "@FP_METHD@"
-
-/** Basic quadratic extension field arithmetic. */
-#define BASIC 1
-/** Integrated extension field arithmetic. */
-#define INTEG 3
-/* Chosen extension field arithmetic method. */
-#define FPX_QDR @FPX_QDR@
-
-/** Basic cubic extension field arithmetic. */
-#define BASIC 1
-/** Integrated extension field arithmetic. */
-#define INTEG 3
-/* Chosen extension field arithmetic method. */
-#define FPX_CBC @FPX_CBC@
-
-/** Basic quadratic extension field arithmetic. */
-#define BASIC 1
-/** Lazy-reduced extension field arithmetic. */
-#define LAZYR 2
-/* Chosen extension field arithmetic method. */
-#define FPX_RDC @FPX_RDC@
-
-/** Prime extension field arithmetic method */
-#define FPX_METHD "@FPX_METHD@"
-
-/** Irreducible polynomial size in bits. */
-#define FB_POLYN @FB_POLYN@
-/** Number of Karatsuba steps. */
-#define FB_KARAT @FB_KARAT@
-/** Prefer trinomials over pentanomials. */
-#cmakedefine FB_TRINO
-/** Prefer square-root friendly polynomials. */
-#cmakedefine FB_SQRTF
-/** Precompute multiplication table for sqrt(z). */
-#cmakedefine FB_PRECO
-/** Width of window processing for exponentiation methods. */
-#define FB_WIDTH @FB_WIDTH@
-
-/** Shift-and-add multiplication. */
-#define BASIC 1
-/** Lopez-Dahab multiplication. */
-#define LODAH 2
-/** Integrated modular multiplication. */
-#define INTEG 3
-/** Chosen binary field multiplication method. */
-#define FB_MUL @FB_MUL@
-
-/** Basic squaring. */
-#define BASIC 1
-/** Table-based squaring. */
-#define QUICK 2
-/** Integrated modular squaring. */
-#define INTEG 3
-/** Chosen binary field squaring method. */
-#define FB_SQR @FB_SQR@
-
-/** Shift-and-add modular reduction. */
-#define BASIC 1
-/** Fast reduction modulo a trinomial or pentanomial. */
-#define QUICK 2
-/** Chosen binary field modular reduction method. */
-#define FB_RDC @FB_RDC@
-
-/** Square root by repeated squaring. */
-#define BASIC 1
-/** Fast square root extraction. */
-#define QUICK 2
-/** Chosen binary field modular reduction method. */
-#define FB_SRT @FB_SRT@
-
-/** Trace by repeated squaring. */
-#define BASIC 1
-/** Fast trace computation. */
-#define QUICK 2
-/** Chosen trace computation method. */
-#define FB_TRC @FB_TRC@
-
-/** Solve by half-trace computation. */
-#define BASIC 1
-/** Solve with precomputed half-traces. */
-#define QUICK 2
-/** Chosen method to solve a quadratic equation. */
-#define FB_SLV @FB_SLV@
-
-/** Inversion by Fermat's Little Theorem. */
-#define BASIC 1
-/** Binary inversion. */
-#define BINAR 2
-/** Almost inverse algorithm. */
-#define ALMOS 3
-/** Extended Euclidean algorithm. */
-#define EXGCD 4
-/** Itoh-Tsuji inversion. */
-#define ITOHT 5
-/** Hardware-friendly inversion by Brunner-Curiger-Hofstetter.*/
-#define BRUCH 6
-/** Constant-time version of almost inverse. */
-#define CTAIA 7
-/** Use implementation provided by the lower layer. */
-#define LOWER 8
-/** Chosen binary field inversion method. */
-#define FB_INV @FB_INV@
-
-/** Binary modular exponentiation. */
-#define BASIC 1
-/** Sliding window modular exponentiation. */
-#define SLIDE 2
-/** Constant-time Montgomery powering ladder. */
-#define MONTY 3
-/** Chosen multiple precision modular exponentiation method. */
-#define FB_EXP @FB_EXP@
-
-/** Iterated squaring/square-root by consecutive squaring/square-root. */
-#define BASIC 1
-/** Iterated squaring/square-root by table-based method. */
-#define QUICK 2
-/** Chosen method to solve a quadratic equation. */
-#define FB_ITR @FB_ITR@
-
-/** Binary field arithmetic method */
-#define FB_METHD "@FB_METHD@"
-
-/** Support for ordinary curves. */
-#cmakedefine EP_PLAIN
-/** Support for supersingular curves. */
-#cmakedefine EP_SUPER
-/** Support for prime curves with efficient endormorphisms. */
-#cmakedefine EP_ENDOM
-/** Use mixed coordinates. */
-#cmakedefine EP_MIXED
-/** Build precomputation table for generator. */
-#cmakedefine EP_PRECO
-/** Enable isogeny map for SSWU map-to-curve. */
-#cmakedefine EP_CTMAP
-/** Width of precomputation table for fixed point methods. */
-#define EP_DEPTH @EP_DEPTH@
-/** Width of window processing for unknown point methods. */
-#define EP_WIDTH @EP_WIDTH@
-
-/** Affine coordinates. */
-#define BASIC 1
-/** Projective coordinates. */
-#define PROJC 2
-/** Jacobian coordinates. */
-#define JACOB 3
-/** Chosen prime elliptic curve coordinate method. */
-#define EP_ADD @EP_ADD@
-
-/** Binary point multiplication. */
-#define BASIC 1
-/** Sliding window. */
-#define SLIDE 2
-/** Montgomery powering ladder. */
-#define MONTY 3
-/** Left-to-right Width-w NAF. */
-#define LWNAF 4
-/** Left-to-right Width-w NAF. */
-#define LWREG 5
-/** Chosen prime elliptic curve point multiplication method. */
-#define EP_MUL @EP_MUL@
-
-/** Binary point multiplication. */
-#define BASIC 1
-/** Single-table comb method. */
-#define COMBS 2
-/** Double-table comb method. */
-#define COMBD 3
-/** Left-to-right Width-w NAF. */
-#define LWNAF 4
-/** Chosen prime elliptic curve point multiplication method. */
-#define EP_FIX @EP_FIX@
-
-/** Basic simultaneouns point multiplication. */
-#define BASIC 1
-/** Shamir's trick. */
-#define TRICK 2
-/** Interleaving of w-(T)NAFs. */
-#define INTER 3
-/** Joint sparse form. */
-#define JOINT 4
-/** Chosen prime elliptic curve simulteanous point multiplication method. */
-#define EP_SIM @EP_SIM@
-
-/** Prime elliptic curve arithmetic method. */
-#define EP_METHD "@EP_METHD@"
-
-/** Support for ordinary curves without endormorphisms. */
-#cmakedefine EB_PLAIN
-/** Support for Koblitz anomalous binary curves. */
-#cmakedefine EB_KBLTZ
-/** Use mixed coordinates. */
-#cmakedefine EB_MIXED
-/** Build precomputation table for generator. */
-#cmakedefine EB_PRECO
-/** Width of precomputation table for fixed point methods. */
-#define EB_DEPTH @EB_DEPTH@
-/** Width of window processing for unknown point methods. */
-#define EB_WIDTH @EB_WIDTH@
-
-/** Binary elliptic curve arithmetic method. */
-#define EB_METHD "@EB_METHD@"
-
-/** Affine coordinates. */
-#define BASIC 1
-/** López-Dahab Projective coordinates. */
-#define PROJC 2
-/** Chosen binary elliptic curve coordinate method. */
-#define EB_ADD @EB_ADD@
-
-/** Binary point multiplication. */
-#define BASIC 1
-/** L�pez-Dahab point multiplication. */
-#define LODAH 2
-/** Halving. */
-#define HALVE 3
-/** Left-to-right width-w (T)NAF. */
-#define LWNAF 4
-/** Right-to-left width-w (T)NAF. */
-#define RWNAF 5
-/** Chosen binary elliptic curve point multiplication method. */
-#define EB_MUL @EB_MUL@
-
-/** Binary point multiplication. */
-#define BASIC 1
-/** Single-table comb method. */
-#define COMBS 2
-/** Double-table comb method. */
-#define COMBD 3
-/** Left-to-right Width-w NAF. */
-#define LWNAF 4
-/** Chosen binary elliptic curve point multiplication method. */
-#define EB_FIX @EB_FIX@
-
-/** Basic simultaneouns point multiplication. */
-#define BASIC 1
-/** Shamir's trick. */
-#define TRICK 2
-/** Interleaving of w-(T)NAFs. */
-#define INTER 3
-/** Joint sparse form. */
-#define JOINT 4
-/** Chosen binary elliptic curve simulteanous point multiplication method. */
-#define EB_SIM @EB_SIM@
-
-/** Build precomputation table for generator. */
-#cmakedefine ED_PRECO
-/** Width of precomputation table for fixed point methods. */
-#define ED_DEPTH @ED_DEPTH@
-/** Width of window processing for unknown point methods. */
-#define ED_WIDTH @ED_WIDTH@
-
-/** Edwards elliptic curve arithmetic method. */
-#define ED_METHD "@ED_METHD@"
-
-/** Affine coordinates. */
-#define BASIC 1
-/** Simple projective twisted Edwards coordinates */
-#define PROJC 2
-/** Extended projective twisted Edwards coordinates */
-#define EXTND 3
-/** Chosen binary elliptic curve coordinate method. */
-#define ED_ADD @ED_ADD@
-
-/** Binary point multiplication. */
-#define BASIC 1
-/** Sliding window. */
-#define SLIDE 2
-/** Montgomery powering ladder. */
-#define MONTY 3
-/** Left-to-right Width-w NAF. */
-#define LWNAF 4
-/** Left-to-right Width-w NAF. */
-#define LWREG 5
-/** Chosen prime elliptic twisted Edwards curve point multiplication method. */
-#define ED_MUL @ED_MUL@
-
-/** Binary point multiplication. */
-#define BASIC 1
-/** Single-table comb method. */
-#define COMBS 2
-/** Double-table comb method. */
-#define COMBD 3
-/** Left-to-right Width-w NAF. */
-#define LWNAF 4
-/** Chosen prime elliptic twisted Edwards curve point multiplication method. */
-#define ED_FIX @ED_FIX@
-
-/** Basic simultaneouns point multiplication. */
-#define BASIC 1
-/** Shamir's trick. */
-#define TRICK 2
-/** Interleaving of w-(T)NAFs. */
-#define INTER 3
-/** Joint sparse form. */
-#define JOINT 4
-/** Chosen prime elliptic curve simulteanous point multiplication method. */
-#define ED_SIM @ED_SIM@
-
-/** Prime curves. */
-#define PRIME 1
-/** Binary curves. */
-#define CHAR2 2
-/** Edwards curves */
-#define EDDIE 3
-/** Chosen elliptic curve type. */
-#define EC_CUR @EC_CUR@
-
-/** Chosen elliptic curve cryptography method. */
-#define EC_METHD "@EC_METHD@"
-/** Prefer curves with efficient endomorphisms. */
-#cmakedefine EC_ENDOM
-
-/** Basic quadratic extension field arithmetic. */
-#define BASIC 1
-/** Lazy-reduced extension field arithmetic. */
-#define LAZYR 2
-/* Chosen extension field arithmetic method. */
-#define PP_EXT @PP_EXT@
-
-/** Bilinear pairing method. */
-#define PP_METHD "@PP_METHD@"
-
-/** Tate pairing. */
-#define TATEP 1
-/** Weil pairing. */
-#define WEILP 2
-/** Optimal ate pairing. */
-#define OATEP 3
-/** Chosen pairing method over prime elliptic curves. */
-#define PP_MAP @PP_MAP@
-
-/** SHA-224 hash function. */
-#define SH224 2
-/** SHA-256 hash function. */
-#define SH256 3
-/** SHA-384 hash function. */
-#define SH384 4
-/** SHA-512 hash function. */
-#define SH512 5
-/** BLAKE2s-160 hash function. */
-#define B2S160 6
-/** BLAKE2s-256 hash function. */
-#define B2S256 7
-/** Chosen hash function. */
-#define MD_MAP @MD_MAP@
-
-/** Choice of hash function. */
-#define MD_METHD "@MD_METHD@"
-
-/** Chosen RSA method. */
-#cmakedefine CP_CRT
-/** RSA without padding. */
-#define BASIC 1
-/** RSA PKCS#1 v1.5 padding. */
-#define PKCS1 2
-/** RSA PKCS#1 v2.1 padding. */
-#define PKCS2 3
-/** Chosen RSA padding method. */
-#define CP_RSAPD @CP_RSAPD@
-
-/** Automatic memory allocation. */
-#define AUTO 1
-/** Dynamic memory allocation. */
-#define DYNAMIC 2
-/** Chosen memory allocation policy. */
-#define ALLOC @ALLOC@
-
-/** NIST HASH-DRBG generator. */
-#define HASHD 1
-/** Intel RdRand instruction. */
-#define RDRND 2
-/** Operating system underlying generator. */
-#define UDEV 3
-/** Override library generator with the callback. */
-#define CALL 4
-/** Chosen random generator. */
-#define RAND @RAND@
-
-/** Standard C library generator. */
-#define LIBC 1
-/** Intel RdRand instruction. */
-#define RDRND 2
-/** Device node generator. */
-#define UDEV 3
-/** Use Windows' CryptGenRandom. */
-#define WCGR 4
-/** Chosen random generator seeder. */
-#cmakedefine SEED @SEED@
-
-/** GNU/Linux operating system. */
-#define LINUX 1
-/** FreeBSD operating system. */
-#define FREEBSD 2
-/** Windows operating system. */
-#define MACOSX 3
-/** Windows operating system. */
-#define WINDOWS 4
-/** Android operating system. */
-#define DROID 5
-/** Arduino platform. */
-#define DUINO 6
-/** OpenBSD operating system. */
-#define OPENBSD 7
-/** Detected operation system. */
-#cmakedefine OPSYS @OPSYS@
-
-/** OpenMP multithreading support. */
-#define OPENMP 1
-/** POSIX multithreading support. */
-#define PTHREAD 2
-/** Chosen multithreading API. */
-#cmakedefine MULTI @MULTI@
-
-/** Per-process high-resolution timer. */
-#define HREAL 1
-/** Per-process high-resolution timer. */
-#define HPROC 2
-/** Per-thread high-resolution timer. */
-#define HTHRD 3
-/** POSIX-compatible timer. */
-#define POSIX 4
-/** ANSI-compatible timer. */
-#define ANSI 5
-/** Cycle-counting timer. */
-#define CYCLE 6
-/** Performance monitoring framework. */
-#define PERF 7
-/** Chosen timer. */
-#cmakedefine TIMER @TIMER@
-
-/** Prefix to identity this build of the library. */
-#cmakedefine LABEL @LABEL@
-
-#ifndef ASM
-
-#include "relic_label.h"
-
-/**
- * Prints the project options selected at build time.
- */
-void conf_print(void);
-
-#endif /* ASM */
-
-#endif /* !RLC_CONF_H */
From 4d09138ff3e91b7dad20410d920f3cc80d3d16f8 Mon Sep 17 00:00:00 2001
From: pasta
Date: Fri, 6 Dec 2024 13:30:14 -0600
Subject: [PATCH 4/4] feat: serialize on the stack
---
src/bls/bls.h | 34 +++++++++++++++-----------
src/bls/bls_ies.cpp | 15 ++++--------
src/coinjoin/coinjoin.cpp | 4 +--
src/coinjoin/coinjoin.h | 5 ++--
src/governance/object.cpp | 2 +-
src/governance/vote.cpp | 2 +-
src/llmq/dkgsession.cpp | 4 +--
src/serialize.h | 51 +++++++++++++++++++++++++++++++++++++++
8 files changed, 85 insertions(+), 32 deletions(-)
diff --git a/src/bls/bls.h b/src/bls/bls.h
index e029b70ae5..71bbc25736 100644
--- a/src/bls/bls.h
+++ b/src/bls/bls.h
@@ -123,7 +123,15 @@ public:
cachedHash.SetNull();
}
- std::vector ToByteVector(const bool specificLegacyScheme) const
+ std::array ToBytes(const bool specificLegacyScheme) const
+ {
+ if (!fValid) {
+ return std::array{};
+ }
+ return impl.SerializeToArray(specificLegacyScheme);
+ }
+
+ std::vector ToActualByteVector(const bool specificLegacyScheme) const
{
if (!fValid) {
return std::vector(SerSize, 0);
@@ -131,9 +139,9 @@ public:
return impl.Serialize(specificLegacyScheme);
}
- std::vector ToByteVector() const
+ std::array ToBytes() const
{
- return ToByteVector(bls::bls_legacy_scheme.load());
+ return ToBytes(bls::bls_legacy_scheme.load());
}
const uint256& GetHash() const
@@ -167,7 +175,7 @@ public:
template
inline void Serialize(Stream& s, const bool specificLegacyScheme) const
{
- s.write(AsBytes(Span{ToByteVector(specificLegacyScheme).data(), SerSize}));
+ s.write(AsBytes(Span{ToBytes(specificLegacyScheme)}));
}
template
@@ -206,7 +214,7 @@ public:
inline bool CheckMalleable(Span vecBytes, const bool specificLegacyScheme) const
{
- if (memcmp(vecBytes.data(), ToByteVector(specificLegacyScheme).data(), SerSize)) {
+ if (memcmp(vecBytes.data(), ToBytes(specificLegacyScheme).data(), SerSize)) {
// TODO not sure if this is actually possible with the BLS libs. I'm assuming here that somewhere deep inside
// these libs masking might happen, so that 2 different binary representations could result in the same object
// representation
@@ -222,7 +230,7 @@ public:
inline std::string ToString(const bool specificLegacyScheme) const
{
- std::vector buf = ToByteVector(specificLegacyScheme);
+ auto buf = ToBytes(specificLegacyScheme);
return HexStr(buf);
}
@@ -245,10 +253,12 @@ struct CBLSIdImplicit : public uint256
memcpy(instance.begin(), buffer, sizeof(CBLSIdImplicit));
return instance;
}
- [[nodiscard]] std::vector Serialize(const bool fLegacy) const
+ [[nodiscard]] std::vector SerializeToVec(const bool fLegacy) const
{
return {begin(), end()};
}
+ [[nodiscard]] std::array Serialize(const bool fLegacy) const { return m_data; }
+ [[nodiscard]] std::array SerializeToArray(const bool fLegacy) const { return Serialize(fLegacy); }
};
class CBLSId : public CBLSWrapper
@@ -396,7 +406,7 @@ class CBLSLazyWrapper
private:
mutable std::mutex mutex;
- mutable std::vector vecBytes;
+ mutable std::array vecBytes{};
mutable bool bufValid{false};
mutable bool bufLegacyScheme{true};
@@ -407,7 +417,6 @@ private:
public:
CBLSLazyWrapper() :
- vecBytes(BLSObject::SerSize, 0),
bufLegacyScheme(bls::bls_legacy_scheme.load())
{}
@@ -425,7 +434,6 @@ public:
if (r.bufValid) {
vecBytes = r.vecBytes;
} else {
- vecBytes.resize(BLSObject::SerSize);
std::fill(vecBytes.begin(), vecBytes.end(), 0);
}
objInitialized = r.objInitialized;
@@ -448,10 +456,9 @@ public:
{
std::unique_lock l(mutex);
if (!objInitialized && !bufValid) {
- vecBytes.resize(BLSObject::SerSize);
std::fill(vecBytes.begin(), vecBytes.end(), 0);
} else if (!bufValid || (bufLegacyScheme != specificLegacyScheme)) {
- vecBytes = obj.ToByteVector(specificLegacyScheme);
+ vecBytes = obj.ToBytes(specificLegacyScheme);
bufValid = true;
bufLegacyScheme = specificLegacyScheme;
hash.SetNull();
@@ -533,11 +540,10 @@ public:
{
std::unique_lock l(mutex);
if (!objInitialized && !bufValid) {
- vecBytes.resize(BLSObject::SerSize);
std::fill(vecBytes.begin(), vecBytes.end(), 0);
hash.SetNull();
} else if (!bufValid) {
- vecBytes = obj.ToByteVector(bufLegacyScheme);
+ vecBytes = obj.ToBytes(bufLegacyScheme);
bufValid = true;
hash.SetNull();
}
diff --git a/src/bls/bls_ies.cpp b/src/bls/bls_ies.cpp
index 1068e078fc..640e820910 100644
--- a/src/bls/bls_ies.cpp
+++ b/src/bls/bls_ies.cpp
@@ -49,8 +49,7 @@ bool CBLSIESEncryptedBlob::Encrypt(size_t idx, const CBLSPublicKey& peerPubKey,
return false;
}
- std::vector symKey = pk.ToByteVector();
- symKey.resize(32);
+ auto symKey = pk.ToBytes();
uint256 iv = GetIV(idx);
return EncryptBlob(plainTextData, dataSize, data, symKey.data(), iv.begin());
@@ -63,10 +62,9 @@ bool CBLSIESEncryptedBlob::Decrypt(size_t idx, const CBLSSecretKey& secretKey, C
return false;
}
- std::vector symKey = pk.ToByteVector();
- symKey.resize(32);
-
uint256 iv = GetIV(idx);
+ auto symKey = pk.ToBytes();
+
return DecryptBlob(data.data(), data.size(), decryptedDataRet, symKey.data(), iv.begin());
}
@@ -117,8 +115,7 @@ bool CBLSIESMultiRecipientBlobs::Encrypt(size_t idx, const CBLSPublicKey& recipi
return false;
}
- std::vector symKey = pk.ToByteVector();
- symKey.resize(32);
+ auto symKey = pk.ToBytes();
return EncryptBlob(blob.data(), blob.size(), blobs[idx], symKey.data(), ivVector[idx].begin());
}
@@ -134,13 +131,11 @@ bool CBLSIESMultiRecipientBlobs::Decrypt(size_t idx, const CBLSSecretKey& sk, Bl
return false;
}
- std::vector symKey = pk.ToByteVector();
- symKey.resize(32);
-
uint256 iv = ivSeed;
for (size_t i = 0; i < idx; i++) {
iv = ::SerializeHash(iv);
}
+ auto symKey = pk.ToBytes();
return DecryptBlob(blobs[idx].data(), blobs[idx].size(), blobRet, symKey.data(), iv.begin());
}
diff --git a/src/coinjoin/coinjoin.cpp b/src/coinjoin/coinjoin.cpp
index 74fc644a70..2ac1b3d436 100644
--- a/src/coinjoin/coinjoin.cpp
+++ b/src/coinjoin/coinjoin.cpp
@@ -55,7 +55,7 @@ bool CCoinJoinQueue::Sign(const CActiveMasternodeManager& mn_activeman)
if (!sig.IsValid()) {
return false;
}
- vchSig = sig.ToByteVector(false);
+ vchSig = sig.ToBytes(false);
return true;
}
@@ -94,7 +94,7 @@ bool CCoinJoinBroadcastTx::Sign(const CActiveMasternodeManager& mn_activeman)
if (!sig.IsValid()) {
return false;
}
- vchSig = sig.ToByteVector(false);
+ vchSig = sig.ToBytes(false);
return true;
}
diff --git a/src/coinjoin/coinjoin.h b/src/coinjoin/coinjoin.h
index 68e2f40c05..18885a3284 100644
--- a/src/coinjoin/coinjoin.h
+++ b/src/coinjoin/coinjoin.h
@@ -7,6 +7,7 @@
#include
+#include
#include
#include
#include
@@ -183,7 +184,7 @@ public:
uint256 m_protxHash;
int64_t nTime{0};
bool fReady{false}; //ready for submit
- std::vector vchSig;
+ std::array vchSig;
// memory only
bool fTried{false};
@@ -243,7 +244,7 @@ public:
CTransactionRef tx;
COutPoint masternodeOutpoint;
uint256 m_protxHash;
- std::vector vchSig;
+ std::array vchSig;
int64_t sigTime{0};
CCoinJoinBroadcastTx() :
tx(MakeTransactionRef(CMutableTransaction{}))
diff --git a/src/governance/object.cpp b/src/governance/object.cpp
index 6ae0ed619b..eb571d23f6 100644
--- a/src/governance/object.cpp
+++ b/src/governance/object.cpp
@@ -258,7 +258,7 @@ bool CGovernanceObject::Sign(const CActiveMasternodeManager& mn_activeman)
if (!sig.IsValid()) {
return false;
}
- m_obj.vchSig = sig.ToByteVector(false);
+ m_obj.vchSig = sig.ToActualByteVector(false);
return true;
}
diff --git a/src/governance/vote.cpp b/src/governance/vote.cpp
index 5cfa2b1ac1..bf279d4f89 100644
--- a/src/governance/vote.cpp
+++ b/src/governance/vote.cpp
@@ -175,7 +175,7 @@ bool CGovernanceVote::Sign(const CActiveMasternodeManager& mn_activeman)
if (!sig.IsValid()) {
return false;
}
- vchSig = sig.ToByteVector(false);
+ vchSig = sig.ToActualByteVector(false);
return true;
}
diff --git a/src/llmq/dkgsession.cpp b/src/llmq/dkgsession.cpp
index 1c95881efe..850756d72f 100644
--- a/src/llmq/dkgsession.cpp
+++ b/src/llmq/dkgsession.cpp
@@ -1017,12 +1017,12 @@ void CDKGSession::SendCommitment(CDKGPendingMessages& pendingMessages)
if (lieType == 3) {
const bool is_bls_legacy = bls::bls_legacy_scheme.load();
- std::vector buf = qc.sig.ToByteVector(is_bls_legacy);
+ auto buf = qc.sig.ToBytes(is_bls_legacy);
buf[5]++;
qc.sig.SetByteVector(buf, is_bls_legacy);
} else if (lieType == 4) {
const bool is_bls_legacy = bls::bls_legacy_scheme.load();
- std::vector buf = qc.quorumSig.ToByteVector(is_bls_legacy);
+ auto buf = qc.quorumSig.ToBytes(is_bls_legacy);
buf[5]++;
qc.quorumSig.SetByteVector(buf, is_bls_legacy);
}
diff --git a/src/serialize.h b/src/serialize.h
index 14e56baef4..ea4c52b0b6 100644
--- a/src/serialize.h
+++ b/src/serialize.h
@@ -797,6 +797,9 @@ template inline void Unserialize(St
template inline void Serialize(Stream& os, const std::vector& v);
template inline void Unserialize(Stream& is, std::vector& v);
+template void Serialize(Stream& os, const std::array& a);
+template void Unserialize(Stream& is, std::array& a);
+
/**
* pair
*/
@@ -1028,6 +1031,54 @@ void Unserialize(Stream& is, std::vector& v)
}
}
+/**
+ * array
+ */
+template
+void Serialize(Stream& os, const std::array& a)
+{
+ if constexpr (std::is_same_v) {
+ // Directly write the byte data without writing the size
+ if (!a.empty()) {
+ os.write(MakeByteSpan(a));
+ }
+ }
+ else if constexpr (std::is_same_v) {
+ // Serialize each bool individually
+ for (const bool& elem : a) {
+ ::Serialize(os, elem);
+ }
+ }
+ else {
+ // Serialize each element using the default Serialize function
+ for (const T& elem : a) {
+ ::Serialize(os, elem);
+ }
+ }
+}
+
+template
+void Unserialize(Stream& is, std::array& a)
+{
+ if constexpr (std::is_same_v) {
+ // Directly read the byte data without reading the size
+ if (N > 0) {
+ is.read(AsWritableBytes(Span{a}));
+ }
+ }
+ else if constexpr (std::is_same_v) {
+ // Unserialize each bool individually
+ for (bool& elem : a) {
+ ::Unserialize(is, elem);
+ }
+ }
+ else {
+ // Unserialize each element using the default Unserialize function
+ for (T& elem : a) {
+ ::Unserialize(is, elem);
+ }
+ }
+}
/**
* pair