Browse Source

copy constructor for Ed22519

pull/306/head
orignal 9 years ago
parent
commit
d169471e8c
  1. 10
      Signature.cpp
  2. 23
      Signature.h

10
Signature.cpp

@ -67,6 +67,14 @@ namespace crypto
BN_CTX_free (ctx); 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 () ~Ed25519 ()
{ {
BN_free (q); BN_free (q);
@ -387,7 +395,7 @@ namespace crypto
// Bi16[0][0] = B, base point // Bi16[0][0] = B, base point
}; };
static thread_local std::unique_ptr<Ed25519> g_Ed25519; static std::unique_ptr<Ed25519> g_Ed25519;
std::unique_ptr<Ed25519>& GetEd25519 () std::unique_ptr<Ed25519>& GetEd25519 ()
{ {
if (!g_Ed25519) if (!g_Ed25519)

23
Signature.h

@ -373,6 +373,8 @@ namespace crypto
BIGNUM * x, * y; BIGNUM * x, * y;
BIGNUM * z, * t; // projective coordinates BIGNUM * z, * t; // projective coordinates
EDDSAPoint (): x(nullptr), y(nullptr), z(nullptr), t(nullptr) {}; 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) EDDSAPoint (EDDSAPoint&& other): x(nullptr), y(nullptr), z(nullptr), t(nullptr)
{ *this = std::move (other); }; { *this = std::move (other); };
EDDSAPoint (BIGNUM * x1, BIGNUM * y1, BIGNUM * z1 = nullptr, BIGNUM * t1 = nullptr): x(x1), y(y1), z(z1), t(t1) {}; EDDSAPoint (BIGNUM * x1, BIGNUM * y1, BIGNUM * z1 = nullptr, BIGNUM * t1 = nullptr): x(x1), y(y1), z(z1), t(t1) {};
@ -380,14 +382,19 @@ namespace crypto
EDDSAPoint& operator=(EDDSAPoint&& other) EDDSAPoint& operator=(EDDSAPoint&& other)
{ {
if (x) BN_free (x); if (x) BN_free (x); x = other.x; other.x = nullptr;
if (y) BN_free (y); if (y) BN_free (y); y = other.y; other.y = nullptr;
if (z) BN_free (z); if (z) BN_free (z); z = other.z; other.z = nullptr;
if (t) BN_free (t); if (t) BN_free (t); t = other.t; other.t = nullptr;
x = other.x; other.x = nullptr; return *this;
y = other.y; other.y = nullptr; }
z = other.z; other.z = nullptr;
t = other.t; other.t = nullptr; 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; return *this;
} }

Loading…
Cancel
Save