2 * Argon2 reference source code package - reference C implementations
5 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
7 * You may use this work under the terms of a Creative Commons CC0 1.0
8 * License/Waiver or the Apache Public License 2.0, at your option. The terms of
9 * these licenses can be found at:
11 * - CC0 1.0 Universal : https://creativecommons.org/publicdomain/zero/1.0
12 * - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
14 * You should have received a copy of both of these licenses along with this
15 * software. If not, they may be obtained at the above URLs.
18 #ifndef ARGON2_THREAD_H
19 #define ARGON2_THREAD_H
21 #if !defined(ARGON2_NO_THREADS)
24 Here we implement an abstraction layer for the simpĺe requirements
25 of the Argon2 code. We only require 3 primitives---thread creation,
26 joining, and termination---so full emulation of the pthreads API
27 is unwarranted. Currently we wrap pthreads and Win32 threads.
29 The API defines 2 types: the function pointer type,
31 and the type of the thread handle---argon2_thread_handle_t.
35 typedef unsigned(__stdcall *argon2_thread_func_t)(void *);
36 typedef uintptr_t argon2_thread_handle_t;
39 typedef void *(*argon2_thread_func_t)(void *);
40 typedef pthread_t argon2_thread_handle_t;
44 * @param handle pointer to a thread handle, which is the output of this
45 * function. Must not be NULL.
46 * @param func A function pointer for the thread's entry point. Must not be
48 * @param args Pointer that is passed as an argument to @func. May be NULL.
49 * @return 0 if @handle and @func are valid pointers and a thread is successfully
52 int argon2_thread_create(argon2_thread_handle_t *handle,
53 argon2_thread_func_t func, void *args);
55 /* Waits for a thread to terminate
56 * @param handle Handle to a thread created with argon2_thread_create.
57 * @return 0 if @handle is a valid handle, and joining completed successfully.
59 int argon2_thread_join(argon2_thread_handle_t handle);
61 #endif /* ARGON2_NO_THREADS */