[PATCH 2/4] Rename KDF job functions and function types

Jussi Kivilinna jussi.kivilinna at iki.fi
Fri Jan 28 20:06:14 CET 2022


* src/gcrypt.h.in (gcry_kdf_job_fn_t): New.
(gcry_kdf_dispatch_job_fn_t): Renamed from 'gcry_kdf_lauch_job_t'; Use
'gcry_kdf_job_fn_t' for function pointer parameter.
(gcry_kdf_wait_all_jobs_fn_t): Renamed from
'gcry_kdf_wait_all_jobs_completion_t'.
(gcry_kdf_thread_ops_t): Rename functions to 'dispatch_job' and
'wait_all_jobs'.
* cipher/kdf.c (argon2_compute): Change to use 'dispatch_job' and
'wait_all_jobs'.
* tests/t-kdf.c (job_thread_param, pthread_jobs_launch_job): Use
'gcry_kdf_job_fn_t' type for 'job'.
--

Rename 'launch_job' to 'dispatch_job', dispatch feels better
word to describe the action here. Also remove '_completion'
from wait_all function name as it makes name unnecessary long.

Signed-off-by: Jussi Kivilinna <jussi.kivilinna at iki.fi>
---
 cipher/kdf.c    |  6 +++---
 src/gcrypt.h.in | 14 +++++++-------
 tests/t-kdf.c   |  8 ++++----
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/cipher/kdf.c b/cipher/kdf.c
index 94cd064f..d426b608 100644
--- a/cipher/kdf.c
+++ b/cipher/kdf.c
@@ -719,14 +719,14 @@ argon2_compute (argon2_ctx_t a, const struct gcry_kdf_thread_ops *ops)
             thread_data->lane = l;
 
             if (ops)
-              ops->launch_job (ops->jobs_context,
-                               argon2_compute_segment, thread_data);
+              ops->dispatch_job (ops->jobs_context,
+                                 argon2_compute_segment, thread_data);
             else
               argon2_compute_segment (thread_data);
           }
 
         if (ops)
-          ops->wait_all_jobs_completion (ops->jobs_context);
+          ops->wait_all_jobs (ops->jobs_context);
       }
 
   return 0;
diff --git a/src/gcrypt.h.in b/src/gcrypt.h.in
index 680f634f..2fd47292 100644
--- a/src/gcrypt.h.in
+++ b/src/gcrypt.h.in
@@ -1613,18 +1613,18 @@ gpg_error_t gcry_kdf_derive (const void *passphrase, size_t passphraselen,
 /* Another API to derive a key from a passphrase.  */
 typedef struct gcry_kdf_handle *gcry_kdf_hd_t;
 
-
-typedef int (*gcry_kdf_lauch_job_t) (void *jobs_context,
-                                     void (*job) (void *work_priv),
-                                     void *work_priv);
-typedef int (*gcry_kdf_wait_all_jobs_completion_t) (void *jobs_context);
+typedef void (*gcry_kdf_job_fn_t) (void *priv);
+typedef int (*gcry_kdf_dispatch_job_fn_t) (void *jobs_context,
+                                           gcry_kdf_job_fn_t job_fn,
+                                           void *job_priv);
+typedef int (*gcry_kdf_wait_all_jobs_fn_t) (void *jobs_context);
 
 /* Exposed structure for KDF computation to decouple thread functionality.  */
 typedef struct gcry_kdf_thread_ops
 {
   void *jobs_context;
-  gcry_kdf_lauch_job_t launch_job;
-  gcry_kdf_wait_all_jobs_completion_t wait_all_jobs_completion;
+  gcry_kdf_dispatch_job_fn_t dispatch_job;
+  gcry_kdf_wait_all_jobs_fn_t wait_all_jobs;
 } gcry_kdf_thread_ops_t;
 
 gcry_error_t gcry_kdf_open (gcry_kdf_hd_t *hd, int algo, int subalgo,
diff --git a/tests/t-kdf.c b/tests/t-kdf.c
index d61159e3..8844e111 100644
--- a/tests/t-kdf.c
+++ b/tests/t-kdf.c
@@ -1257,7 +1257,7 @@ struct user_defined_threads_ctx
   pthread_t thread[MAX_THREADS];
   struct job_thread_param
   {
-    void (*job) (void *work_priv);
+    gcry_kdf_job_fn_t job;
     void *priv;
   } work[MAX_THREADS];
 };
@@ -1271,8 +1271,8 @@ job_thread (void *p)
 }
 
 static int
-pthread_jobs_launch_job (void *jobs_context,
-                         void (*job) (void *work_priv), void *work_priv)
+pthread_jobs_launch_job (void *jobs_context, gcry_kdf_job_fn_t job,
+			 void *job_priv)
 {
   struct user_defined_threads_ctx *ctx = jobs_context;
 
@@ -1286,7 +1286,7 @@ pthread_jobs_launch_job (void *jobs_context,
     }
 
   ctx->work[ctx->next_thread_idx].job = job;
-  ctx->work[ctx->next_thread_idx].priv = work_priv;
+  ctx->work[ctx->next_thread_idx].priv = job_priv;
   pthread_create (&ctx->thread[ctx->next_thread_idx], &ctx->attr,
                   job_thread, &ctx->work[ctx->next_thread_idx]);
   if (ctx->oldest_thread_idx < 0)
-- 
2.32.0




More information about the Gcrypt-devel mailing list