Mac OS X x86 assembler support.
[openssl.git] / crypto / evp / p_sign.c
index ad5bcd8..8df6d48 100644 (file)
@@ -1,5 +1,5 @@
 /* crypto/evp/p_sign.c */
 /* 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
  * All rights reserved.
  *
  * This package is an SSL implementation written
 
 #include <stdio.h>
 #include "cryptlib.h"
 
 #include <stdio.h>
 #include "cryptlib.h"
-#include "evp.h"
-#include "objects.h"
-#include "x509.h"
+#include <openssl/evp.h>
+#include <openssl/objects.h>
+#include <openssl/x509.h>
 
 #ifdef undef
 
 #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
 
        {
        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;
        {
        unsigned char m[EVP_MAX_MD_SIZE];
        unsigned int m_len;
        int i,ok=0,v;
+       MS_STATIC EVP_MD_CTX tmp_ctx;
 
        *siglen=0;
 
        *siglen=0;
-       EVP_DigestFinal(ctx,&(m[0]),&m_len);
+       EVP_MD_CTX_init(&tmp_ctx);
+       EVP_MD_CTX_copy_ex(&tmp_ctx,ctx);   
+       EVP_DigestFinal_ex(&tmp_ctx,&(m[0]),&m_len);
+       EVP_MD_CTX_cleanup(&tmp_ctx);
+
+       if (ctx->digest->flags & EVP_MD_FLAG_PKEY_METHOD_SIGNATURE)
+               {
+               EVP_PKEY_CTX *pkctx = NULL;
+               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];
        for (i=0; i<4; i++)
                {
                v=ctx->digest->required_pkey_type[i];
@@ -106,6 +125,7 @@ EVP_PKEY *pkey;
                EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE);
                return(0);
                }
                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);
        if (ctx->digest->sign == NULL)
                {
                EVPerr(EVP_F_EVP_SIGNFINAL,EVP_R_NO_SIGN_FUNCTION_CONFIGURED);