static int pkey_gost_ec_cp_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbs_len) { DSA_SIG *unpacked_sig = NULL; EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx); int order = 0; if (!siglen) return 0; if (!pkey) return 0; switch (EVP_PKEY_base_id(pkey)) { case NID_id_GostR3410_2001: case NID_id_GostR3410_2012_256: order = 64; break; case NID_id_GostR3410_2012_512: order = 128; break; default: return 0; } if (!sig) { *siglen = order; return 1; } unpacked_sig = gost_ec_sign(tbs, tbs_len, EVP_PKEY_get0(pkey)); if (!unpacked_sig) { return 0; } return pack_sign_cp(unpacked_sig, order / 2, sig, siglen); }
static int pkey_gost01_cp_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbs_len) { DSA_SIG *unpacked_sig=NULL; EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx); if (!siglen) return 0; if (!sig) { *siglen= 64; /* better to check size of curve order*/ return 1; } unpacked_sig = gost2001_do_sign(tbs,tbs_len,EVP_PKEY_get0(pkey)); if (!unpacked_sig) { return 0; } return pack_sign_cp(unpacked_sig,32,sig,siglen); }