Skip to content

Commit

Permalink
copy constructor for Ed22519
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Nov 26, 2015
1 parent 56453f6 commit d169471
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
10 changes: 9 additions & 1 deletion Signature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -387,7 +395,7 @@ namespace crypto
// 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 ()
{
if (!g_Ed25519)
Expand Down
23 changes: 15 additions & 8 deletions Signature.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,24 +373,31 @@ 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) {};
~EDDSAPoint () { BN_free (x); BN_free (y); BN_free(z); BN_free(t); };

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;
Expand Down

0 comments on commit d169471

Please sign in to comment.