X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=crypto%2Fevp%2Fp_sign.c;h=dfa48c157cf5b6db223cfdc0e4c5abb42d208c4e;hb=a99ce1f5b12a72285aa1bd05db61912cd0f925bf;hp=ad5bcd8ba861186daf26e24f1f5f00ee2377d818;hpb=b7896b3cb86d80206af14a14d69b0717786f2729;p=oweals%2Fopenssl.git diff --git a/crypto/evp/p_sign.c b/crypto/evp/p_sign.c index ad5bcd8ba8..dfa48c157c 100644 --- a/crypto/evp/p_sign.c +++ b/crypto/evp/p_sign.c @@ -1,5 +1,5 @@ /* crypto/evp/p_sign.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written @@ -58,39 +58,60 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include #ifdef undef -void EVP_SignInit(ctx,type) -EVP_MD_CTX *ctx; -EVP_MD *type; +void EVP_SignInit(EVP_MD_CTX *ctx, EVP_MD *type) { - EVP_DigestInit(ctx,type); + EVP_DigestInit_ex(ctx,type); } -void EVP_SignUpdate(ctx,data,count) -EVP_MD_CTX *ctx; -unsigned char *data; -unsigned int count; +void EVP_SignUpdate(EVP_MD_CTX *ctx, unsigned char *data, + unsigned int count) { EVP_DigestUpdate(ctx,data,count); } #endif -int EVP_SignFinal(ctx,sigret,siglen,pkey) -EVP_MD_CTX *ctx; -unsigned char *sigret; -unsigned int *siglen; -EVP_PKEY *pkey; +int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen, + EVP_PKEY *pkey) { unsigned char m[EVP_MAX_MD_SIZE]; unsigned int m_len; - int i,ok=0,v; + int i=0,ok=0,v; + EVP_MD_CTX tmp_ctx; + EVP_PKEY_CTX *pkctx = NULL; *siglen=0; - EVP_DigestFinal(ctx,&(m[0]),&m_len); + EVP_MD_CTX_init(&tmp_ctx); + if (!EVP_MD_CTX_copy_ex(&tmp_ctx,ctx)) + goto err; + if (!EVP_DigestFinal_ex(&tmp_ctx,&(m[0]),&m_len)) + goto err; + EVP_MD_CTX_cleanup(&tmp_ctx); + + if (ctx->digest->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE) + { + size_t sltmp = (size_t)EVP_PKEY_size(pkey); + i = 0; + pkctx = EVP_PKEY_CTX_new(pkey, NULL); + if (!pkctx) + goto err; + if (EVP_PKEY_sign_init(pkctx) <= 0) + goto err; + if (EVP_PKEY_CTX_set_signature_md(pkctx, ctx->digest) <= 0) + goto err; + if (EVP_PKEY_sign(pkctx, sigret, &sltmp, m, m_len) <= 0) + goto err; + *siglen = sltmp; + i = 1; + err: + EVP_PKEY_CTX_free(pkctx); + return i; + } + for (i=0; i<4; i++) { v=ctx->digest->required_pkey_type[i]; @@ -106,6 +127,7 @@ EVP_PKEY *pkey; EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE); return(0); } + if (ctx->digest->sign == NULL) { EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_NO_SIGN_FUNCTION_CONFIGURED);