X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=gost_pmeth.c;h=ddbe1433ca6571f58e5853816e4edfea54d6e1f3;hb=be65ae82130e6908c88b975597d05f128057a287;hp=5c7352b338dd51d396f2ddf84ac01917db271913;hpb=37e242a6a246cbf51d0e7f16f11f122a8c2051eb;p=openssl-gost%2Fengine.git diff --git a/gost_pmeth.c b/gost_pmeth.c index 5c7352b..ddbe143 100644 --- a/gost_pmeth.c +++ b/gost_pmeth.c @@ -151,6 +151,10 @@ static int pkey_gost_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) return 0; } memcpy(pctx->shared_ukm, p2, (int)p1); + pctx->shared_ukm_size = p1; + return 1; + case EVP_PKEY_CTRL_CIPHER: + pctx->cipher_nid = p1; return 1; case EVP_PKEY_CTRL_PEER_KEY: if (p1 == 0 || p1 == 1) /* call from EVP_PKEY_derive_set_peer */ @@ -365,17 +369,17 @@ static int pkey_gost2012cp_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) /* ----------- sign callbacks --------------------------------------*/ /* * Packs signature according to Cryptopro rules - * and frees up DSA_SIG structure + * and frees up ECDSA_SIG structure */ -int pack_sign_cp(DSA_SIG *s, int order, unsigned char *sig, size_t *siglen) +int pack_sign_cp(ECDSA_SIG *s, int order, unsigned char *sig, size_t *siglen) { const BIGNUM *sig_r = NULL, *sig_s = NULL; - DSA_SIG_get0(s, &sig_r, &sig_s); + ECDSA_SIG_get0(s, &sig_r, &sig_s); *siglen = 2 * order; memset(sig, 0, *siglen); store_bignum(sig_s, sig, order); store_bignum(sig_r, sig + order, order); - DSA_SIG_free(s); + ECDSA_SIG_free(s); return 1; } @@ -383,7 +387,7 @@ 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; + ECDSA_SIG *unpacked_sig = NULL; EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx); int order = 0; @@ -417,19 +421,19 @@ static int pkey_gost_ec_cp_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, /* ------------------- verify callbacks ---------------------------*/ /* Unpack signature according to cryptopro rules */ -DSA_SIG *unpack_cp_signature(const unsigned char *sigbuf, size_t siglen) +ECDSA_SIG *unpack_cp_signature(const unsigned char *sigbuf, size_t siglen) { - DSA_SIG *sig; + ECDSA_SIG *sig; BIGNUM *r = NULL, *s = NULL; - sig = DSA_SIG_new(); + sig = ECDSA_SIG_new(); if (sig == NULL) { GOSTerr(GOST_F_UNPACK_CP_SIGNATURE, ERR_R_MALLOC_FAILURE); return NULL; } s = BN_bin2bn(sigbuf, siglen / 2, NULL); r = BN_bin2bn(sigbuf + siglen / 2, siglen / 2, NULL); - DSA_SIG_set0(sig, r, s); + ECDSA_SIG_set0(sig, r, s); return sig; } @@ -439,7 +443,7 @@ static int pkey_gost_ec_cp_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig, { int ok = 0; EVP_PKEY *pub_key = EVP_PKEY_CTX_get0_pkey(ctx); - DSA_SIG *s = (sig) ? unpack_cp_signature(sig, siglen) : NULL; + ECDSA_SIG *s = (sig) ? unpack_cp_signature(sig, siglen) : NULL; if (!s) return 0; #ifdef DEBUG_SIGN @@ -451,7 +455,7 @@ static int pkey_gost_ec_cp_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig, #endif if (pub_key) ok = gost_ec_verify(tbs, tbs_len, s, EVP_PKEY_get0(pub_key)); - DSA_SIG_free(s); + ECDSA_SIG_free(s); return ok; } @@ -614,7 +618,6 @@ static int pkey_gost_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) } case EVP_PKEY_CTRL_MAC_LEN: { - /*TODO*/ if (p1 < 1 || p1 > 8) { GOSTerr(GOST_F_PKEY_GOST_MAC_CTRL, GOST_R_INVALID_MAC_SIZE); @@ -746,8 +749,7 @@ static int pkey_gost_omac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2, si } case EVP_PKEY_CTRL_MAC_LEN: { - /*TODO*/ - if (p1 < 1 || p1 > 8) { + if (p1 < 1 || p1 > max_size) { GOSTerr(GOST_F_PKEY_GOST_OMAC_CTRL, GOST_R_INVALID_MAC_SIZE); return 0;