mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2024-11-17 21:26:04 +00:00
GOST R 34.10 sign
This commit is contained in:
parent
7f71d5dbd8
commit
439c2d445c
@ -532,6 +532,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:
|
||||
|
||||
EC_GROUP * m_Group;
|
||||
|
Loading…
Reference in New Issue
Block a user