From 439c2d445ce0672460f8c22696bf2fa86dffead2 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 9 Mar 2017 20:13:21 -0500 Subject: [PATCH] GOST R 34.10 sign --- Signature.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Signature.cpp b/Signature.cpp index 2e83e91c..72826aa9 100644 --- a/Signature.cpp +++ b/Signature.cpp @@ -531,6 +531,26 @@ namespace crypto { return EC_POINT_get_affine_coordinates_GFp (m_Group, p, x, y, nullptr); } + + void Sign (const BIGNUM * priv, const BIGNUM * digest, BIGNUM * r, BIGNUM * s) + { + BN_CTX * ctx = BN_CTX_new (); + BN_CTX_start (ctx); + BIGNUM * q = BN_CTX_get (ctx); + EC_GROUP_get_order(m_Group, q, ctx); + BIGNUM * k = BN_CTX_get (ctx); + BN_rand_range (k, q); // 0 < k < q + EC_POINT * C = MulP (k); // C = k*P + GetXY (C, r, nullptr); // r = Cx + EC_POINT_free (C); + BN_mod_mul (s, r, priv, q, ctx); // (r*priv)%q + BIGNUM * tmp = BN_CTX_get (ctx); + BN_mod_mul (tmp, k, digest, q, ctx); // (k*digest)%q + BN_mod_add (s, s, tmp, q, ctx); // (r*priv+k*digest)%q + BN_CTX_end (ctx); + BN_CTX_free (ctx); + } + private: