xref: /trunk/ns_server/deps/enacl/c_src/enacl_nif.c (revision e35c584a)
1 #include <sodium.h>
2 #include <string.h>
3 
4 #include <erl_nif.h>
5 
6 #include "aead.h"
7 #include "enacl.h"
8 #include "enacl_ext.h"
9 #include "generichash.h"
10 #include "hash.h"
11 #include "kdf.h"
12 #include "kx.h"
13 #include "public.h"
14 #include "pwhash.h"
15 #include "randombytes.h"
16 #include "secret.h"
17 #include "secretstream.h"
18 #include "sign.h"
19 
20 #ifdef ERL_NIF_DIRTY_JOB_CPU_BOUND
21 #define erl_nif_dirty_job_cpu_bound_macro(a, b, c)                             \
22   { a, b, c, ERL_NIF_DIRTY_JOB_CPU_BOUND }
23 #else
24 #define erl_nif_dirty_job_cpu_bound_macro(a, b, c)                             \
25   { a, b, c }
26 #endif
27 
28 /* Initialization */
enacl_crypto_load(ErlNifEnv * env,void ** priv_data,ERL_NIF_TERM load_info)29 static int enacl_crypto_load(ErlNifEnv *env, void **priv_data,
30                              ERL_NIF_TERM load_info) {
31   // Create a new resource type for crypto_generichash_state
32   if (!enacl_init_generic_hash_ctx(env)) {
33     return -1;
34   }
35 
36   if (!enacl_init_sign_ctx(env)) {
37     return -1;
38   }
39 
40   if (!enacl_init_secretstream_ctx(env)) {
41     return -1;
42   }
43 
44   if (sodium_init() == -1) {
45     return -1;
46   }
47 
48   return 0;
49 }
50 
enacl_crypto_upgrade(ErlNifEnv * env,void ** priv_data,void ** old_priv_data,ERL_NIF_TERM load_info)51 static int enacl_crypto_upgrade(ErlNifEnv* env, void **priv_data,
52                                 void **old_priv_data,
53                                 ERL_NIF_TERM load_info) {
54     return 0;
55 }
56 
enacl_crypto_unload(ErlNifEnv * env,void ** priv_data,ERL_NIF_TERM load_info)57 static int enacl_crypto_unload(ErlNifEnv* env, void **priv_data,
58                                 ERL_NIF_TERM load_info) {
59     return 0;
60 }
61 
62 /* GENERAL ROUTINES
63  *
64  * These don't generally fit somewhere else nicely, so we keep them in the main
65  * file
66  *
67  */
enacl_crypto_verify_16(ErlNifEnv * env,int argc,ERL_NIF_TERM const argv[])68 static ERL_NIF_TERM enacl_crypto_verify_16(ErlNifEnv *env, int argc,
69                                            ERL_NIF_TERM const argv[]) {
70   ErlNifBinary x, y;
71 
72   if ((argc != 2) || (!enif_inspect_binary(env, argv[0], &x)) ||
73       (!enif_inspect_binary(env, argv[1], &y))) {
74     return enif_make_badarg(env);
75   }
76 
77   if (x.size != 16 || y.size != 16) {
78     return enif_make_badarg(env);
79   }
80 
81   if (0 == crypto_verify_16(x.data, y.data)) {
82     return enif_make_atom(env, "true");
83   } else {
84     return enif_make_atom(env, "false");
85   }
86 }
87 
enacl_crypto_verify_32(ErlNifEnv * env,int argc,ERL_NIF_TERM const argv[])88 static ERL_NIF_TERM enacl_crypto_verify_32(ErlNifEnv *env, int argc,
89                                            ERL_NIF_TERM const argv[]) {
90   ErlNifBinary x, y;
91 
92   if ((argc != 2) || (!enif_inspect_binary(env, argv[0], &x)) ||
93       (!enif_inspect_binary(env, argv[1], &y))) {
94     return enif_make_badarg(env);
95   }
96 
97   if (x.size != 32 || y.size != 32) {
98     return enif_make_badarg(env);
99   }
100 
101   if (0 == crypto_verify_32(x.data, y.data)) {
102     return enif_make_atom(env, "true");
103   } else {
104     return enif_make_atom(env, "false");
105   }
106 }
107 
108 /* This is very unsafe. It will not affect things that have been
109   binary_copy()'ed Use this for destroying key material from ram but nothing
110   more. Be careful! */
enif_sodium_memzero(ErlNifEnv * env,int argc,ERL_NIF_TERM const argv[])111 static ERL_NIF_TERM enif_sodium_memzero(ErlNifEnv *env, int argc,
112                                         ERL_NIF_TERM const argv[]) {
113   ErlNifBinary x;
114 
115   if ((argc != 1) || (!enif_inspect_binary(env, argv[0], &x))) {
116     return enif_make_badarg(env);
117   }
118 
119   sodium_memzero(x.data, x.size);
120 
121   return enif_make_atom(env, "ok");
122 }
123 
124 /* Curve 25519 */
125 static ERL_NIF_TERM
enacl_crypto_curve25519_scalarmult(ErlNifEnv * env,int argc,ERL_NIF_TERM const argv[])126 enacl_crypto_curve25519_scalarmult(ErlNifEnv *env, int argc,
127                                    ERL_NIF_TERM const argv[]) {
128   ERL_NIF_TERM result;
129   ErlNifBinary secret, basepoint, output;
130   uint8_t bp[crypto_scalarmult_curve25519_BYTES];
131 
132   if ((argc != 2) || (!enif_inspect_binary(env, argv[0], &secret)) ||
133       (!enif_inspect_binary(env, argv[1], &basepoint)) ||
134       (secret.size != crypto_scalarmult_curve25519_BYTES) ||
135       (basepoint.size != crypto_scalarmult_curve25519_BYTES)) {
136     return enif_make_badarg(env);
137   }
138 
139   memcpy(bp, basepoint.data, crypto_scalarmult_curve25519_BYTES);
140 
141   /* Clear the high-bit. Better safe than sorry. */
142   bp[crypto_scalarmult_curve25519_BYTES - 1] &= 0x7f;
143 
144   do {
145     if (!enif_alloc_binary(crypto_scalarmult_curve25519_BYTES, &output)) {
146       result = enacl_internal_error(env);
147       continue;
148     }
149 
150     if (crypto_scalarmult_curve25519(output.data, secret.data, bp) != 0) {
151       enif_release_binary(&output);
152       result = enacl_error_tuple(env, "scalarmult_curve25519_failed");
153       continue;
154     }
155 
156     result = enif_make_binary(env, &output);
157   } while (0);
158 
159   sodium_memzero(bp, crypto_scalarmult_curve25519_BYTES);
160 
161   return result;
162 }
163 
164 static ERL_NIF_TERM
enacl_crypto_curve25519_scalarmult_base(ErlNifEnv * env,int argc,ERL_NIF_TERM const argv[])165 enacl_crypto_curve25519_scalarmult_base(ErlNifEnv *env, int argc,
166                                         ERL_NIF_TERM const argv[]) {
167   ERL_NIF_TERM result;
168   ErlNifBinary secret, output;
169 
170   if ((argc != 1) || (!enif_inspect_binary(env, argv[0], &secret)) ||
171       (secret.size != crypto_scalarmult_curve25519_BYTES)) {
172     return enif_make_badarg(env);
173   }
174 
175   do {
176     if (!enif_alloc_binary(crypto_scalarmult_curve25519_BYTES, &output)) {
177       result = enacl_internal_error(env);
178       continue;
179     }
180 
181     if (crypto_scalarmult_curve25519_base(output.data, secret.data) != 0) {
182       enif_release_binary(&output);
183       result = enacl_error_tuple(env, "scalarmult_curve25519_base_failed");
184       continue;
185     }
186 
187     result = enif_make_binary(env, &output);
188   } while (0);
189 
190   return result;
191 }
192 
193 /* Tie the knot to the Erlang world */
194 static ErlNifFunc nif_funcs[] = {
195     {"crypto_box_NONCEBYTES", 0, enacl_crypto_box_NONCEBYTES},
196     {"crypto_box_ZEROBYTES", 0, enacl_crypto_box_ZEROBYTES},
197     {"crypto_box_BOXZEROBYTES", 0, enacl_crypto_box_BOXZEROBYTES},
198     {"crypto_box_PUBLICKEYBYTES", 0, enacl_crypto_box_PUBLICKEYBYTES},
199     {"crypto_box_SECRETKEYBYTES", 0, enacl_crypto_box_SECRETKEYBYTES},
200     {"crypto_box_BEFORENMBYTES", 0, enacl_crypto_box_BEFORENMBYTES},
201 
202     erl_nif_dirty_job_cpu_bound_macro("crypto_box_keypair", 0,
203                                       enacl_crypto_box_keypair),
204 
205     erl_nif_dirty_job_cpu_bound_macro("crypto_box", 4, enacl_crypto_box),
206     erl_nif_dirty_job_cpu_bound_macro("crypto_box_open", 4,
207                                       enacl_crypto_box_open),
208 
209     {"crypto_box_beforenm", 2, enacl_crypto_box_beforenm},
210     {"crypto_box_afternm_b", 3, enacl_crypto_box_afternm},
211     erl_nif_dirty_job_cpu_bound_macro("crypto_box_afternm", 3,
212                                       enacl_crypto_box_afternm),
213     {"crypto_box_open_afternm_b", 3, enacl_crypto_box_open_afternm},
214     erl_nif_dirty_job_cpu_bound_macro("crypto_box_open_afternm", 3,
215                                       enacl_crypto_box_open_afternm),
216 
217     {"crypto_sign_PUBLICKEYBYTES", 0, enacl_crypto_sign_PUBLICKEYBYTES},
218     {"crypto_sign_SECRETKEYBYTES", 0, enacl_crypto_sign_SECRETKEYBYTES},
219     erl_nif_dirty_job_cpu_bound_macro("crypto_sign_keypair", 0,
220                                       enacl_crypto_sign_keypair),
221     erl_nif_dirty_job_cpu_bound_macro("crypto_sign_seed_keypair", 1,
222                                       enacl_crypto_sign_seed_keypair),
223 
224     erl_nif_dirty_job_cpu_bound_macro("crypto_sign", 2, enacl_crypto_sign),
225     erl_nif_dirty_job_cpu_bound_macro("crypto_sign_open", 2,
226                                       enacl_crypto_sign_open),
227 
228     erl_nif_dirty_job_cpu_bound_macro("crypto_sign_detached", 2,
229                                       enacl_crypto_sign_detached),
230     erl_nif_dirty_job_cpu_bound_macro("crypto_sign_verify_detached", 3,
231                                       enacl_crypto_sign_verify_detached),
232     {"crypto_sign_init", 0, enacl_crypto_sign_init},
233     erl_nif_dirty_job_cpu_bound_macro("crypto_sign_update", 2,
234                                       enacl_crypto_sign_update),
235     erl_nif_dirty_job_cpu_bound_macro("crypto_sign_final_create", 2,
236                                       enacl_crypto_sign_final_create),
237     erl_nif_dirty_job_cpu_bound_macro("crypto_sign_final_verify", 3,
238                                       enacl_crypto_sign_final_verify),
239 
240     {"crypto_sign_ed25519_sk_to_pk", 1, enacl_crypto_sign_ed25519_sk_to_pk},
241 
242     {"crypto_box_SEALBYTES", 0, enacl_crypto_box_SEALBYTES},
243 
244     erl_nif_dirty_job_cpu_bound_macro("crypto_box_seal", 2,
245                                       enacl_crypto_box_seal),
246     erl_nif_dirty_job_cpu_bound_macro("crypto_box_seal_open", 3,
247                                       enacl_crypto_box_seal_open),
248 
249     {"crypto_secretbox_NONCEBYTES", 0, enacl_crypto_secretbox_NONCEBYTES},
250     {"crypto_secretbox_ZEROBYTES", 0, enacl_crypto_secretbox_ZEROBYTES},
251     {"crypto_secretbox_BOXZEROBYTES", 0, enacl_crypto_secretbox_BOXZEROBYTES},
252     {"crypto_secretbox_KEYBYTES", 0, enacl_crypto_secretbox_KEYBYTES},
253     {"crypto_secretbox_b", 3, enacl_crypto_secretbox},
254     erl_nif_dirty_job_cpu_bound_macro("crypto_secretbox", 3,
255                                       enacl_crypto_secretbox),
256     {"crypto_secretbox_open_b", 3, enacl_crypto_secretbox_open},
257     erl_nif_dirty_job_cpu_bound_macro("crypto_secretbox_open", 3,
258                                       enacl_crypto_secretbox_open),
259 
260     {"crypto_stream_chacha20_KEYBYTES", 0,
261      enacl_crypto_stream_chacha20_KEYBYTES},
262     {"crypto_stream_chacha20_NONCEBYTES", 0,
263      enacl_crypto_stream_chacha20_NONCEBYTES},
264     {"crypto_stream_chacha20_b", 3, enacl_crypto_stream_chacha20},
265     erl_nif_dirty_job_cpu_bound_macro("crypto_stream_chacha20", 3,
266                                       enacl_crypto_stream_chacha20),
267     {"crypto_stream_chacha20_xor_b", 3, enacl_crypto_stream_chacha20_xor},
268     erl_nif_dirty_job_cpu_bound_macro("crypto_stream_chacha20_xor", 3,
269                                       enacl_crypto_stream_chacha20_xor),
270 
271     {"crypto_stream_KEYBYTES", 0, enacl_crypto_stream_KEYBYTES},
272     {"crypto_stream_NONCEBYTES", 0, enacl_crypto_stream_NONCEBYTES},
273     {"crypto_stream_b", 3, enacl_crypto_stream},
274     erl_nif_dirty_job_cpu_bound_macro("crypto_stream", 3, enacl_crypto_stream),
275     {"crypto_stream_xor_b", 3, enacl_crypto_stream_xor},
276     erl_nif_dirty_job_cpu_bound_macro("crypto_stream_xor", 3,
277                                       enacl_crypto_stream_xor),
278 
279     {"crypto_auth_BYTES", 0, enacl_crypto_auth_BYTES},
280     {"crypto_auth_KEYBYTES", 0, enacl_crypto_auth_KEYBYTES},
281     {"crypto_auth_b", 2, enacl_crypto_auth},
282     erl_nif_dirty_job_cpu_bound_macro("crypto_auth", 2, enacl_crypto_auth),
283     {"crypto_auth_verify_b", 3, enacl_crypto_auth_verify},
284     erl_nif_dirty_job_cpu_bound_macro("crypto_auth_verify", 3,
285                                       enacl_crypto_auth_verify),
286 
287     {"crypto_shorthash_BYTES", 0, enacl_crypto_shorthash_BYTES},
288     {"crypto_shorthash_KEYBYTES", 0, enacl_crypto_shorthash_KEYBYTES},
289     {"crypto_shorthash", 2, enacl_crypto_shorthash},
290 
291     {"crypto_onetimeauth_BYTES", 0, enacl_crypto_onetimeauth_BYTES},
292     {"crypto_onetimeauth_KEYBYTES", 0, enacl_crypto_onetimeauth_KEYBYTES},
293     {"crypto_onetimeauth_b", 2, enacl_crypto_onetimeauth},
294     erl_nif_dirty_job_cpu_bound_macro("crypto_onetimeauth", 2,
295                                       enacl_crypto_onetimeauth),
296     {"crypto_onetimeauth_verify_b", 3, enacl_crypto_onetimeauth_verify},
297     erl_nif_dirty_job_cpu_bound_macro("crypto_onetimeauth_verify", 3,
298                                       enacl_crypto_onetimeauth_verify),
299 
300     {"crypto_hash_b", 1, enacl_crypto_hash},
301     erl_nif_dirty_job_cpu_bound_macro("crypto_hash", 1, enacl_crypto_hash),
302     {"crypto_verify_16", 2, enacl_crypto_verify_16},
303     {"crypto_verify_32", 2, enacl_crypto_verify_32},
304     {"sodium_memzero", 1, enif_sodium_memzero},
305 
306     {"crypto_pwhash_SALTBYTES", 0, enacl_crypto_pwhash_SALTBYTES},
307     erl_nif_dirty_job_cpu_bound_macro("crypto_pwhash", 5, enacl_crypto_pwhash),
308     erl_nif_dirty_job_cpu_bound_macro("crypto_pwhash_str", 3,
309                                       enacl_crypto_pwhash_str),
310     erl_nif_dirty_job_cpu_bound_macro("crypto_pwhash_str_verify", 2,
311                                       enacl_crypto_pwhash_str_verify),
312 
313     {"crypto_kdf_KEYBYTES", 0, enacl_crypto_kdf_KEYBYTES},
314     {"crypto_kdf_CONTEXTBYTES", 0, enacl_crypto_kdf_CONTEXTBYTES},
315     erl_nif_dirty_job_cpu_bound_macro("crypto_kdf_derive_from_key", 3,
316                                       enacl_crypto_kdf_derive_from_key),
317 
318     erl_nif_dirty_job_cpu_bound_macro("crypto_curve25519_scalarmult", 2,
319                                       enacl_crypto_curve25519_scalarmult),
320     erl_nif_dirty_job_cpu_bound_macro("crypto_curve25519_scalarmult_base", 1,
321                                       enacl_crypto_curve25519_scalarmult_base),
322 
323     erl_nif_dirty_job_cpu_bound_macro("crypto_sign_ed25519_keypair", 0,
324                                       enacl_crypto_sign_ed25519_keypair),
325     {"crypto_sign_ed25519_public_to_curve25519", 1,
326      enacl_crypto_sign_ed25519_public_to_curve25519},
327     {"crypto_sign_ed25519_secret_to_curve25519", 1,
328      enacl_crypto_sign_ed25519_secret_to_curve25519},
329     {"crypto_sign_ed25519_PUBLICKEYBYTES", 0,
330      enacl_crypto_sign_ed25519_PUBLICKEYBYTES},
331     {"crypto_sign_ed25519_SECRETKEYBYTES", 0,
332      enacl_crypto_sign_ed25519_SECRETKEYBYTES},
333 
334     // Linux might block here if early in the boot sequence, so get it off the
335     // main scheduler. Otherwise, it it would probably be fine to run on the
336     // main scheduler. This plays it safe, albeit with a performance hit.
337     //
338     // However: you shouldn't use a CSPRNG unless you need one. So it is
339     // probably fine to do the dirty-scheduler dance. Using the random
340     // material should dwarf the extraction of random material.
341     erl_nif_dirty_job_cpu_bound_macro("randombytes", 1, enif_randombytes),
342     erl_nif_dirty_job_cpu_bound_macro("randombytes_uint32", 0,
343                                       enif_randombytes_uint32),
344     erl_nif_dirty_job_cpu_bound_macro("randombytes_uniform", 1,
345                                       enif_randombytes_uniform),
346 
347     erl_nif_dirty_job_cpu_bound_macro("crypto_kx_keypair", 0,
348                                       enacl_crypto_kx_keypair),
349     erl_nif_dirty_job_cpu_bound_macro("crypto_kx_client_session_keys", 3,
350                                       enacl_crypto_kx_client_session_keys),
351     erl_nif_dirty_job_cpu_bound_macro("crypto_kx_server_session_keys", 3,
352                                       enacl_crypto_kx_server_session_keys),
353     {"crypto_kx_PUBLICKEYBYTES", 0, enacl_crypto_kx_PUBLICKEYBYTES},
354     {"crypto_kx_SECRETKEYBYTES", 0, enacl_crypto_kx_SECRETKEYBYTES},
355     {"crypto_kx_SESSIONKEYBYTES", 0, enacl_crypto_kx_SESSIONKEYBYTES},
356 
357     {"scramble_block_16", 2, enif_scramble_block_16},
358 
359     {"crypto_aead_chacha20poly1305_ietf_KEYBYTES", 0,
360      enacl_crypto_aead_chacha20poly1305_ietf_KEYBYTES},
361     {"crypto_aead_chacha20poly1305_ietf_NPUBBYTES", 0,
362      enacl_crypto_aead_chacha20poly1305_ietf_NPUBBYTES},
363     {"crypto_aead_chacha20poly1305_ietf_ABYTES", 0,
364      enacl_crypto_aead_chacha20poly1305_ietf_ABYTES},
365     {"crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX", 0,
366      enacl_crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX},
367     erl_nif_dirty_job_cpu_bound_macro(
368         "crypto_aead_chacha20poly1305_ietf_encrypt", 4,
369         enacl_crypto_aead_chacha20poly1305_ietf_encrypt),
370     erl_nif_dirty_job_cpu_bound_macro(
371         "crypto_aead_chacha20poly1305_ietf_decrypt", 4,
372         enacl_crypto_aead_chacha20poly1305_ietf_decrypt),
373 
374     {"crypto_aead_xchacha20poly1305_ietf_KEYBYTES", 0,
375      enacl_crypto_aead_xchacha20poly1305_ietf_KEYBYTES},
376     {"crypto_aead_xchacha20poly1305_ietf_NPUBBYTES", 0,
377      enacl_crypto_aead_xchacha20poly1305_ietf_NPUBBYTES},
378     {"crypto_aead_xchacha20poly1305_ietf_ABYTES", 0,
379      enacl_crypto_aead_xchacha20poly1305_ietf_ABYTES},
380     {"crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX", 0,
381      enacl_crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX},
382     erl_nif_dirty_job_cpu_bound_macro(
383         "crypto_aead_xchacha20poly1305_ietf_encrypt", 4,
384         enacl_crypto_aead_xchacha20poly1305_ietf_encrypt),
385     erl_nif_dirty_job_cpu_bound_macro(
386         "crypto_aead_xchacha20poly1305_ietf_decrypt", 4,
387         enacl_crypto_aead_xchacha20poly1305_ietf_decrypt),
388 
389     {"crypto_generichash_BYTES", 0, enacl_crypto_generichash_BYTES},
390     {"crypto_generichash_BYTES_MIN", 0, enacl_crypto_generichash_BYTES_MIN},
391     {"crypto_generichash_BYTES_MAX", 0, enacl_crypto_generichash_BYTES_MAX},
392     {"crypto_generichash_KEYBYTES", 0, enacl_crypto_generichash_KEYBYTES},
393     {"crypto_generichash_KEYBYTES_MIN", 0,
394      enacl_crypto_generichash_KEYBYTES_MIN},
395     {"crypto_generichash_KEYBYTES_MAX", 0,
396      enacl_crypto_generichash_KEYBYTES_MAX},
397     {"crypto_generichash", 3, enacl_crypto_generichash},
398     {"crypto_generichash_init", 2, enacl_crypto_generichash_init},
399     erl_nif_dirty_job_cpu_bound_macro("crypto_generichash_update", 2,
400                                       enacl_crypto_generichash_update),
401     erl_nif_dirty_job_cpu_bound_macro("crypto_generichash_final", 1,
402                                       enacl_crypto_generichash_final),
403 
404     {"crypto_secretstream_xchacha20poly1305_ABYTES", 0,
405      enacl_crypto_secretstream_xchacha20poly1305_ABYTES},
406     {"crypto_secretstream_xchacha20poly1305_HEADERBYTES", 0,
407      enacl_crypto_secretstream_xchacha20poly1305_HEADERBYTES},
408     {"crypto_secretstream_xchacha20poly1305_KEYBYTES", 0,
409      enacl_crypto_secretstream_xchacha20poly1305_KEYBYTES},
410     {"crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX", 0,
411      enacl_crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX},
412     {"crypto_secretstream_xchacha20poly1305_TAG_MESSAGE", 0,
413      enacl_crypto_secretstream_xchacha20poly1305_TAG_MESSAGE},
414     {"crypto_secretstream_xchacha20poly1305_TAG_PUSH", 0,
415      enacl_crypto_secretstream_xchacha20poly1305_TAG_PUSH},
416     {"crypto_secretstream_xchacha20poly1305_TAG_REKEY", 0,
417      enacl_crypto_secretstream_xchacha20poly1305_TAG_REKEY},
418     {"crypto_secretstream_xchacha20poly1305_TAG_FINAL", 0,
419      enacl_crypto_secretstream_xchacha20poly1305_TAG_FINAL},
420     {"crypto_secretstream_xchacha20poly1305_keygen", 0,
421      enacl_crypto_secretstream_xchacha20poly1305_keygen},
422     {"crypto_secretstream_xchacha20poly1305_init_push", 1,
423      enacl_crypto_secretstream_xchacha20poly1305_init_push},
424     {"crypto_secretstream_xchacha20poly1305_init_pull", 2,
425      enacl_crypto_secretstream_xchacha20poly1305_init_pull},
426     {"crypto_secretstream_xchacha20poly1305_rekey", 1,
427      enacl_crypto_secretstream_xchacha20poly1305_rekey},
428     erl_nif_dirty_job_cpu_bound_macro(
429         "crypto_secretstream_xchacha20poly1305_push", 4,
430         enacl_crypto_secretstream_xchacha20poly1305_push),
431     erl_nif_dirty_job_cpu_bound_macro(
432         "crypto_secretstream_xchacha20poly1305_pull", 3,
433         enacl_crypto_secretstream_xchacha20poly1305_pull)};
434 
435 ERL_NIF_INIT(enacl_nif, nif_funcs, enacl_crypto_load, NULL, enacl_crypto_upgrade, enacl_crypto_unload);
436