Initial Async notify code changes

Initial API implemented for notifying applications that an ASYNC_JOB
has completed. Currently only s_server is using this. The Dummy Async
engine "cheats" in that it notifies that it has completed *before* it
pauses the job. A normal async engine would not do that.

Only the posix version of this has been implemented so far, so it will
probably fail to compile on Windows at the moment.

Reviewed-by: Rich Salz <rsalz@openssl.org>
This commit is contained in:
Matt Caswell
2015-07-24 08:15:31 +01:00
parent 252d6d3aa6
commit f4da39d200
9 changed files with 140 additions and 12 deletions

View 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);
}