Adjust all accesses to EVP_MD_CTX to use accessor functions.
[openssl.git] / engines / e_dasync.c
index 6c41f7522d611a943eb83269e9939631a1380e64..7f6aa7568d7de1349268727859e8c425b5a401d3 100644 (file)
@@ -82,24 +82,24 @@ static int dasync_digests(ENGINE *e, const EVP_MD **digest,
 
 static int dasync_digest_nids[] = { NID_sha1, 0 };
 
+static void dummy_pause_job(void);
 
 /* SHA1 */
-static int digest_sha1_init(EVP_MD_CTX *ctx);
-static int digest_sha1_update(EVP_MD_CTX *ctx, const void *data,
-                             unsigned long count);
-static int digest_sha1_final(EVP_MD_CTX *ctx, unsigned char *md);
+static int dasync_sha1_init(EVP_MD_CTX *ctx);
+static int dasync_sha1_update(EVP_MD_CTX *ctx, const void *data,
+                             size_t count);
+static int dasync_sha1_final(EVP_MD_CTX *ctx, unsigned char *md);
 
-static const EVP_MD digest_sha1 = {
+static const EVP_MD dasync_sha1 = {
     NID_sha1,
     NID_sha1WithRSAEncryption,
     SHA_DIGEST_LENGTH,
-    EVP_MD_FLAG_PKEY_METHOD_SIGNATURE | EVP_MD_FLAG_DIGALGID_ABSENT,
-    digest_sha1_init,
-    digest_sha1_update,
-    digest_sha1_final,
+    EVP_MD_FLAG_DIGALGID_ABSENT,
+    dasync_sha1_init,
+    dasync_sha1_update,
+    dasync_sha1_final,
     NULL,
     NULL,
-    EVP_PKEY_NULL_method,
     SHA_CBLOCK,
     sizeof(EVP_MD *) + sizeof(SHA_CTX),
 };
@@ -224,7 +224,7 @@ static int dasync_digests(ENGINE *e, const EVP_MD **digest,
     /* We are being asked for a specific digest */
     switch (nid) {
     case NID_sha1:
-        *digest = &digest_sha1;
+        *digest = &dasync_sha1;
         break;
     default:
         ok = 0;
@@ -234,34 +234,50 @@ static int dasync_digests(ENGINE *e, const EVP_MD **digest,
     return ok;
 }
 
+static void dummy_pause_job(void) {
+    ASYNC_JOB *job;
+
+    if ((job = ASYNC_get_current_job()) == NULL)
+        return;
+
+    /*
+     * In the Dummy async engine we are cheating. We signal that the job
+     * is complete by waking it before the call to ASYNC_pause_job(). A real
+     * async engine would only wake when the job was actually complete
+     */
+    ASYNC_wake(job);
+
+    /* Ignore errors - we carry on anyway */
+    ASYNC_pause_job();
+
+    ASYNC_clear_wake(job);
+}
+
 
 /*
  * SHA1 implementation. At the moment we just defer to the standard
  * implementation
  */
 #undef data
-#define data(ctx) ((SHA_CTX *)(ctx)->md_data)
-static int digest_sha1_init(EVP_MD_CTX *ctx)
+#define data(ctx) ((SHA_CTX *)EVP_MD_CTX_md_data(ctx))
+static int dasync_sha1_init(EVP_MD_CTX *ctx)
 {
-    /* Ignore errors - we carry on anyway */
-    ASYNC_pause_job();
+    dummy_pause_job();
 
     return SHA1_Init(data(ctx));
 }
 
-static int digest_sha1_update(EVP_MD_CTX *ctx, const void *data,
-                             unsigned long count)
+static int dasync_sha1_update(EVP_MD_CTX *ctx, const void *data,
+                             size_t count)
 {
-    /* Ignore errors - we carry on anyway */
-    ASYNC_pause_job();
+    dummy_pause_job();
 
     return SHA1_Update(data(ctx), data, (size_t)count);
 }
 
-static int digest_sha1_final(EVP_MD_CTX *ctx, unsigned char *md)
+static int dasync_sha1_final(EVP_MD_CTX *ctx, unsigned char *md)
 {
-    /* Ignore errors - we carry on anyway */
-    ASYNC_pause_job();
+    dummy_pause_job();
 
     return SHA1_Final(md, data(ctx));
 }
@@ -273,14 +289,14 @@ static int digest_sha1_final(EVP_MD_CTX *ctx, unsigned char *md)
 static int dasync_pub_enc(int flen, const unsigned char *from,
                     unsigned char *to, RSA *rsa, int padding) {
     /* Ignore errors - we carry on anyway */
-    ASYNC_pause_job();
+    dummy_pause_job();
     return RSA_PKCS1_OpenSSL()->rsa_pub_enc(flen, from, to, rsa, padding);
 }
 
 static int dasync_pub_dec(int flen, const unsigned char *from,
                     unsigned char *to, RSA *rsa, int padding) {
     /* Ignore errors - we carry on anyway */
-    ASYNC_pause_job();
+    dummy_pause_job();
     return RSA_PKCS1_OpenSSL()->rsa_pub_dec(flen, from, to, rsa, padding);
 }
 
@@ -288,7 +304,7 @@ static int dasync_rsa_priv_enc(int flen, const unsigned char *from,
                       unsigned char *to, RSA *rsa, int padding)
 {
     /* Ignore errors - we carry on anyway */
-    ASYNC_pause_job();
+    dummy_pause_job();
     return RSA_PKCS1_OpenSSL()->rsa_priv_enc(flen, from, to, rsa, padding);
 }
 
@@ -296,14 +312,14 @@ static int dasync_rsa_priv_dec(int flen, const unsigned char *from,
                       unsigned char *to, RSA *rsa, int padding)
 {
     /* Ignore errors - we carry on anyway */
-    ASYNC_pause_job();
+    dummy_pause_job();
     return RSA_PKCS1_OpenSSL()->rsa_priv_dec(flen, from, to, rsa, padding);
 }
 
 static int dasync_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
 {
     /* Ignore errors - we carry on anyway */
-    ASYNC_pause_job();
+    dummy_pause_job();
     return RSA_PKCS1_OpenSSL()->rsa_mod_exp(r0, I, rsa, ctx);
 }