Initial Async notify code changes
[openssl.git] / engines / e_dasync.c
index 6c41f7522d611a943eb83269e9939631a1380e64..9e0ed1b492c95b03fea79911dd8dd3b3f04ec150 100644 (file)
@@ -82,6 +82,7 @@ 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);
@@ -234,6 +235,25 @@ 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
@@ -243,8 +263,7 @@ static int dasync_digests(ENGINE *e, const EVP_MD **digest,
 #define data(ctx) ((SHA_CTX *)(ctx)->md_data)
 static int digest_sha1_init(EVP_MD_CTX *ctx)
 {
-    /* Ignore errors - we carry on anyway */
-    ASYNC_pause_job();
+    dummy_pause_job();
 
     return SHA1_Init(data(ctx));
 }
@@ -252,16 +271,14 @@ static int digest_sha1_init(EVP_MD_CTX *ctx)
 static int digest_sha1_update(EVP_MD_CTX *ctx, const void *data,
                              unsigned long 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)
 {
-    /* Ignore errors - we carry on anyway */
-    ASYNC_pause_job();
+    dummy_pause_job();
 
     return SHA1_Final(md, data(ctx));
 }
@@ -273,14 +290,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 +305,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 +313,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);
 }