diff --git a/Signature.cpp b/Signature.cpp index 9ea92309..a6d519a1 100644 --- a/Signature.cpp +++ b/Signature.cpp @@ -67,6 +67,14 @@ namespace crypto BN_CTX_free (ctx); } + Ed25519 (const Ed25519& other): q (BN_dup (other.q)), l (BN_dup (other.l)), + d (BN_dup (other.d)), I (BN_dup (other.I)), two_252_2 (BN_dup (other.two_252_2)) + { + for (int i = 0; i < 64; i++) + for (int j = 0; j < 15; j++) + Bi16[i][j] = other.Bi16[i][j]; + } + ~Ed25519 () { BN_free (q); @@ -387,7 +395,7 @@ namespace crypto // Bi16[0][0] = B, base point }; - static thread_local std::unique_ptr g_Ed25519; + static std::unique_ptr g_Ed25519; std::unique_ptr& GetEd25519 () { if (!g_Ed25519) diff --git a/Signature.h b/Signature.h index f46193aa..1e7ac2eb 100644 --- a/Signature.h +++ b/Signature.h @@ -373,6 +373,8 @@ namespace crypto BIGNUM * x, * y; BIGNUM * z, * t; // projective coordinates EDDSAPoint (): x(nullptr), y(nullptr), z(nullptr), t(nullptr) {}; + EDDSAPoint (const EDDSAPoint& other): x(nullptr), y(nullptr), z(nullptr), t(nullptr) + { *this = other; }; EDDSAPoint (EDDSAPoint&& other): x(nullptr), y(nullptr), z(nullptr), t(nullptr) { *this = std::move (other); }; EDDSAPoint (BIGNUM * x1, BIGNUM * y1, BIGNUM * z1 = nullptr, BIGNUM * t1 = nullptr): x(x1), y(y1), z(z1), t(t1) {}; @@ -380,17 +382,22 @@ namespace crypto EDDSAPoint& operator=(EDDSAPoint&& other) { - if (x) BN_free (x); - if (y) BN_free (y); - if (z) BN_free (z); - if (t) BN_free (t); - x = other.x; other.x = nullptr; - y = other.y; other.y = nullptr; - z = other.z; other.z = nullptr; - t = other.t; other.t = nullptr; + if (x) BN_free (x); x = other.x; other.x = nullptr; + if (y) BN_free (y); y = other.y; other.y = nullptr; + if (z) BN_free (z); z = other.z; other.z = nullptr; + if (t) BN_free (t); t = other.t; other.t = nullptr; return *this; } + EDDSAPoint& operator=(const EDDSAPoint& other) + { + if (x) BN_free (x); x = other.x ? BN_dup (other.x) : nullptr; + if (y) BN_free (y); y = other.y ? BN_dup (other.y) : nullptr; + if (z) BN_free (z); z = other.z ? BN_dup (other.z) : nullptr; + if (t) BN_free (t); t = other.t ? BN_dup (other.t) : nullptr; + return *this; + } + EDDSAPoint operator-() const { BIGNUM * x1 = NULL, * y1 = NULL, * z1 = NULL, * t1 = NULL;