forked from joshjdevl/libsodium-jni
-
Notifications
You must be signed in to change notification settings - Fork 2
/
sodium.i
1655 lines (1354 loc) · 67.6 KB
/
sodium.i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* sodium.i */
%module Sodium
%include "typemaps.i"
%include "stdint.i"
%include "arrays_java.i"
%include "carrays.i"
%include "various.i"
%include "java.swg"
%include "typemaps.i"
/* Basic mappings */
%apply int {unsigned long long};
%apply long[] {unsigned long long *};
%apply int {size_t};
%apply int {uint32_t};
%apply long {uint64_t};
/* unsigned char */
%typemap(jni) unsigned char * "jbyteArray"
%typemap(jtype) unsigned char * "byte[]"
%typemap(jstype) unsigned char * "byte[]"
%typemap(in) unsigned char *{
$1 = (unsigned char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(argout) unsigned char *{
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
}
%typemap(javain) unsigned char *"$javainput"
/* Prevent default freearg typemap from being used */
%typemap(freearg) unsigned char *""
/* uint8_t */
%typemap(jni) uint8_t *"jbyteArray"
%typemap(jtype) uint8_t *"byte[]"
%typemap(jstype) uint8_t *"byte[]"
%typemap(in) uint8_t *{
$1 = (uint8_t *) JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(argout) uint8_t *{
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
}
%typemap(javain) uint8_t *"$javainput"
%typemap(freearg) uint8_t *""
/* Strings */
%typemap(jni) char *"jbyteArray"
%typemap(jtype) char *"byte[]"
%typemap(jstype) char *"byte[]"
%typemap(in) char *{
$1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(argout) char *{
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
}
%typemap(javain) char *"$javainput"
%typemap(freearg) char *""
/* char types */
%typemap(jni) char *BYTE "jbyteArray"
%typemap(jtype) char *BYTE "byte[]"
%typemap(jstype) char *BYTE "byte[]"
%typemap(in) char *BYTE {
$1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(argout) char *BYTE {
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
}
%typemap(javain) char *BYTE "$javainput"
/* Prevent default freearg typemap from being used */
%typemap(freearg) char *BYTE ""
/* Fixed size strings/char arrays */
%typemap(jni) char [ANY]"jbyteArray"
%typemap(jtype) char [ANY]"byte[]"
%typemap(jstype) char [ANY]"byte[]"
%typemap(in) char [ANY]{
$1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(argout) char [ANY]{
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
}
%typemap(javain) char [ANY]"$javainput"
%typemap(freearg) char [ANY]""
/* =============================================================================
TYPEMAPS FOR CRYPTO_*_STATE DATATYPES
============================================================================= */
/*
crypto_generichash_state
*/
%typemap(jni) crypto_generichash_state *"jbyteArray"
%typemap(jtype) crypto_generichash_state *"byte[]"
%typemap(jstype) crypto_generichash_state *"byte[]"
%typemap(in) crypto_generichash_state *{
$1 = (crypto_generichash_state *) JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(argout) crypto_generichash_state *{
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
}
%typemap(javain) crypto_generichash_state *"$javainput"
%typemap(freearg) crypto_generichash_state *""
/*
crypto_generichash_blake2b_state
*/
%typemap(jni) crypto_generichash_blake2b_state*"jbyteArray"
%typemap(jtype) crypto_generichash_blake2b_state *"byte[]"
%typemap(jstype) crypto_generichash_blake2b_state *"byte[]"
%typemap(in) crypto_generichash_blake2b_state *{
$1 = (crypto_generichash_blake2b_state *) JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(argout) crypto_generichash_blake2b_state *{
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
}
%typemap(javain) crypto_generichash_blake2b_state *"$javainput"
%typemap(freearg) crypto_generichash_blake2b_state *""
/*
crypto_hash_sha256_state
*/
%typemap(jni) crypto_hash_sha256_state *"jbyteArray"
%typemap(jtype) crypto_hash_sha256_state *"byte[]"
%typemap(jstype) crypto_hash_sha256_state *"byte[]"
%typemap(in) crypto_hash_sha256_state *{
$1 = (crypto_hash_sha256_state *) JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(argout) crypto_hash_sha256_state *{
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
}
%typemap(javain) crypto_hash_sha256_state *"$javainput"
%typemap(freearg) crypto_hash_sha256_state *""
/*
crypto_hash_sha512_state
*/
%typemap(jni) crypto_hash_sha512_state *"jbyteArray"
%typemap(jtype) crypto_hash_sha512_state *"byte[]"
%typemap(jstype) crypto_hash_sha512_state *"byte[]"
%typemap(in) crypto_hash_sha512_state *{
$1 = (crypto_hash_sha512_state *) JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(argout) crypto_hash_sha512_state *{
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
}
%typemap(javain) crypto_hash_sha512_state *"$javainput"
%typemap(freearg) crypto_hash_sha512_state *""
/*
crypto_onetimeauth_state
*/
%typemap(jni) crypto_onetimeauth_state *"jbyteArray"
%typemap(jtype) crypto_onetimeauth_state *"byte[]"
%typemap(jstype) crypto_onetimeauth_state *"byte[]"
%typemap(in) crypto_onetimeauth_state *{
$1 = (crypto_onetimeauth_state *) JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(argout) crypto_onetimeauth_state *{
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
}
%typemap(javain) crypto_onetimeauth_state *"$javainput"
%typemap(freearg) crypto_onetimeauth_state *""
/*
crypto_onetimeauth_poly1305_state
*/
%typemap(jni) crypto_onetimeauth_poly1305_state *"jbyteArray"
%typemap(jtype) crypto_onetimeauth_poly1305_state *"byte[]"
%typemap(jstype) crypto_onetimeauth_poly1305_state *"byte[]"
%typemap(in) crypto_onetimeauth_poly1305_state *{
$1 = (crypto_onetimeauth_poly1305_state *) JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(argout) crypto_onetimeauth_poly1305_state *{
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
}
%typemap(javain) crypto_onetimeauth_poly1305_state *"$javainput"
%typemap(freearg) crypto_onetimeauth_poly1305_state *""
/*
crypto_auth_hmacsha256_state
*/
%typemap(jni) crypto_auth_hmacsha256_state *"jbyteArray"
%typemap(jtype) crypto_auth_hmacsha256_state *"byte[]"
%typemap(jstype) crypto_auth_hmacsha256_state *"byte[]"
%typemap(in) crypto_auth_hmacsha256_state *{
$1 = (crypto_auth_hmacsha256_state *) JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(argout) crypto_auth_hmacsha256_state *{
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
}
%typemap(javain) crypto_auth_hmacsha256_state *"$javainput"
%typemap(freearg) crypto_auth_hmacsha256_state *""
/*
crypto_auth_hmacsha512_state
*/
%typemap(jni) crypto_auth_hmacsha512_state *"jbyteArray"
%typemap(jtype) crypto_auth_hmacsha512_state *"byte[]"
%typemap(jstype) crypto_auth_hmacsha512_state *"byte[]"
%typemap(in) crypto_auth_hmacsha512_state *{
$1 = (crypto_auth_hmacsha512_state *) JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(argout) crypto_auth_hmacsha512_state *{
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
}
%typemap(javain) crypto_auth_hmacsha512_state *"$javainput"
%typemap(freearg) crypto_auth_hmacsha512_state *""
/*
crypto_auth_hmacsha512_state
*/
%typemap(jni) crypto_auth_hmacsha512256_state *"jbyteArray"
%typemap(jtype) crypto_auth_hmacsha512256_state *"byte[]"
%typemap(jstype) crypto_auth_hmacsha512256_state *"byte[]"
%typemap(in) crypto_auth_hmacsha512256_state *{
$1 = (crypto_auth_hmacsha512256_state *) JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(argout) crypto_auth_hmacsha512256_state *{
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
}
%typemap(javain) crypto_auth_hmacsha512256_state *"$javainput"
%typemap(freearg) crypto_auth_hmacsha512256_state *""
/*
crypto_secretstream_xchacha20poly1305_state
*/
%typemap(jni) crypto_secretstream_xchacha20poly1305_state *"jbyteArray"
%typemap(jtype) crypto_secretstream_xchacha20poly1305_state *"byte[]"
%typemap(jstype) crypto_secretstream_xchacha20poly1305_state *"byte[]"
%typemap(in) crypto_secretstream_xchacha20poly1305_state *{
$1 = (crypto_secretstream_xchacha20poly1305_state *) JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(argout) crypto_secretstream_xchacha20poly1305_state *{
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
}
%typemap(javain) crypto_secretstream_xchacha20poly1305_state *"$javainput"
%typemap(freearg) crypto_secretstream_xchacha20poly1305_state *""
/* *****************************************************************************
HIGH-LEVEL LIBSODIUM API'S
***************************************************************************** */
%{
/* Put header files here or function declarations like below */
#include "sodium.h"
%}
/*
Runtime API
*/
int sodium_init(void);
const char *sodium_version_string(void);
/* void randombytes(unsigned char * const buf, const unsigned long long buf_len); */
void randombytes(unsigned char *dst_buf,
unsigned long long buf_len);
/*
randombytes API
*/
uint32_t randombytes_random(void);
uint32_t randombytes_uniform(const uint32_t upper_bound);
/*void randombytes_buf(void * const buf, const size_t size);*/
void randombytes_buf(unsigned char * const buff,
const unsigned long long buff_len);
int randombytes_close(void);
void randombytes_stir(void);
void randombytes_buf_deterministic(unsigned char * const buff, const unsigned long long buff_len, const unsigned char *seed);
size_t randombytes_seedbytes(void);
/*
helpers API
*/
/*int sodium_memcmp(const void * const b1_,
const void * const b2_,
size_t len);*/
void sodium_increment(unsigned char *src_dst_number,
const size_t number_len);
/*
crypto_secretbox API
*/
size_t crypto_secretbox_keybytes(void);
size_t crypto_secretbox_noncebytes(void);
size_t crypto_secretbox_macbytes(void);
size_t crypto_secretbox_zerobytes(void);
size_t crypto_secretbox_boxzerobytes(void);
const char *crypto_secretbox_primitive(void);
int crypto_secretbox_easy(unsigned char *dst_cipher,
const unsigned char *src_plain,
unsigned long long plain_len,
const unsigned char *nonce,
const unsigned char *secret_key);
int crypto_secretbox_open_easy(unsigned char *dst_plain,
const unsigned char *src_cipher,
unsigned long long cipher_len,
const unsigned char *nonce,
const unsigned char *secret_key);
/*
crypto_secretbox_detached API
*/
int crypto_secretbox_detached(unsigned char *dst_cipher,
unsigned char *mac,
const unsigned char *src_plain,
unsigned long long plain_len,
const unsigned char *nonce,
const unsigned char *secretkey);
int crypto_secretbox_open_detached(unsigned char *dst_plain,
const unsigned char *src_cipher,
const unsigned char *mac,
unsigned long long cipher_len,
const unsigned char *nonce,
const unsigned char *secretkey);
/*
crypto_scalarmult API, for crypto_box keys
*/
size_t crypto_scalarmult_bytes(void);
size_t crypto_scalarmult_scalarbytes(void);
const char *crypto_scalarmult_primitive(void);
int crypto_scalarmult_base(unsigned char *q,
const unsigned char *n);
int crypto_scalarmult(unsigned char *q,
const unsigned char *n,
const unsigned char *p);
/*
crypto_box API
*/
size_t crypto_box_seedbytes(void);
size_t crypto_box_publickeybytes(void);
size_t crypto_box_secretkeybytes(void);
size_t crypto_box_noncebytes(void);
size_t crypto_box_macbytes(void);
const char *crypto_box_primitive(void);
int crypto_box_keypair(unsigned char *dst_public_Key,
unsigned char *dst_private_key);
int crypto_box_seed_keypair(unsigned char *dst_public_key,
unsigned char *dst_private_key,
const unsigned char *src_seed);
int crypto_scalarmult_base(unsigned char *dst_group_element,
const unsigned char *src_n_multiplier);
int crypto_box_easy(unsigned char *dst_cipher,
const unsigned char *src_plain,
unsigned long long plain_len,
const unsigned char *nonce,
const unsigned char *remote_public_key,
const unsigned char *local_private_key);
int crypto_box_open_easy(unsigned char *dst_plain,
const unsigned char *src_cipher,
unsigned long long cipher_len,
const unsigned char *nonce,
const unsigned char *remote_public_key,
const unsigned char *local_private_key);
int crypto_box_detached(unsigned char *dst_cipher,
unsigned char *dst_mac,
const unsigned char *src_plain,
unsigned long long plain_len,
const unsigned char *nonces,
const unsigned char *remote_public_key,
const unsigned char *local_private_key);
int crypto_box_open_detached(unsigned char *dst_plain,
const unsigned char *src_cipher,
const unsigned char *src_mac,
unsigned long long cipher_len,
const unsigned char *nonce,
const unsigned char *remote_public_key,
const unsigned char *local_private_key);
/*
crypto_box*nm* API
*/
size_t crypto_box_beforenmbytes(void);
int crypto_box_beforenm(unsigned char *dst_shared_key,
const unsigned char *remote_public_key,
const unsigned char *local_private_key);
int crypto_box_easy_afternm(unsigned char *dst_cipher,
const unsigned char *src_plain,
unsigned long long plain_len,
const unsigned char *nonce,
const unsigned char *shared_key);
int crypto_box_open_easy_afternm(unsigned char *dst_plain,
const unsigned char *src_cipher,
unsigned long long cipher_len,
const unsigned char *nonce,
const unsigned char *shared_key);
int crypto_box_detached_afternm(unsigned char *dst_cipher,
unsigned char *dst_mac,
const unsigned char *src_plain,
unsigned long long plain_len,
const unsigned char *nonce,
const unsigned char *shared_key);
int crypto_box_open_detached_afternm(unsigned char *dst_plain,
const unsigned char *src_cipher,
const unsigned char *src_mac,
unsigned long long cipher_len,
const unsigned char *nonce,
const unsigned char *shared_key);
/*
crypto_box_seal API
*/
size_t crypto_box_sealbytes(void);
int crypto_box_seal(unsigned char *dst_cipher,
const unsigned char *src_plain,
unsigned long long plain_len,
const unsigned char *remote_public_key);
int crypto_box_seal_open(unsigned char *dst_plain,
const unsigned char *src_cipher,
unsigned long long cipher_len,
const unsigned char *local_public_key,
const unsigned char *local_private_key);
/*
crypto_box NaCl-compatible API
*/
size_t crypto_box_zerobytes(void);
size_t crypto_box_boxzerobytes(void);
int crypto_box(unsigned char *dst_cipher,
const unsigned char *src_msg,
unsigned long long msg_len,
const unsigned char *src_nonce,
const unsigned char *src_pub,
const unsigned char *src_secret);
int crypto_box_open(unsigned char *dst_msg,
const unsigned char *src_cipher,
unsigned long long cipher_len,
const unsigned char *src_nonce,
const unsigned char *src_pub,
const unsigned char *src_secret);
int crypto_box_afternm(unsigned char *dst_cipher,
const unsigned char *src_msg,
unsigned long long msg_len,
const unsigned char *src_nonce,
const unsigned char *src_key);
int crypto_box_open_afternm(unsigned char *dst_msg,
const unsigned char *src_cipher,
unsigned long long cipher_len,
const unsigned char *src_nonce,
const unsigned char *src_key);
/*
crypto_sign API
*/
size_t crypto_sign_bytes(void);
size_t crypto_sign_seedbytes(void);
size_t crypto_sign_publickeybytes(void);
size_t crypto_sign_secretkeybytes(void);
const char *crypto_sign_primitive(void);
int crypto_sign_keypair(unsigned char *dst_public_Key,
unsigned char *dst_private_key);
int crypto_sign_seed_keypair(unsigned char *dst_public_Key,
unsigned char *dst_private_key,
const unsigned char *src_seed);
int crypto_sign(unsigned char *dst_signed_msg,
unsigned long long *signed_msg_len,
const unsigned char *src_msg,
unsigned long long msg_len,
const unsigned char *local_private_key);
int crypto_sign_open(unsigned char *dst_msg,
unsigned long long *msg_len,
const unsigned char *src_signed_msg,
unsigned long long signed_msg_len,
const unsigned char *remote_public_key);
int crypto_sign_detached(unsigned char *dst_signature,
unsigned long long *signature_len,
const unsigned char *src_msg,
unsigned long long msg_len,
const unsigned char *local_private_key);
int crypto_sign_verify_detached(const unsigned char *src_signature,
const unsigned char *src_msg,
unsigned long long msg_len,
const unsigned char *remote_public_key);
int crypto_sign_ed25519_sk_to_seed(unsigned char *dst_seed,
const unsigned char *src_private_key);
int crypto_sign_ed25519_sk_to_pk(unsigned char *dst_public_key,
const unsigned char *src_private_key);
/*
crypto_hash API
*/
size_t crypto_generichash_bytes(void);
size_t crypto_generichash_bytes_min(void);
size_t crypto_generichash_bytes_max(void);
size_t crypto_generichash_keybytes(void);
size_t crypto_generichash_keybytes_min(void);
size_t crypto_generichash_keybytes_max(void);
const char *crypto_generichash_primitive(void);
int crypto_generichash(unsigned char *dst_hash,
unsigned long long dst_len,
const unsigned char *src_input,
unsigned long long input_len,
const unsigned char *src_key,
unsigned long long key_len);
/* TODO NOTE EXPERIMENTAL CODE FOLLOWS */
size_t crypto_generichash_statebytes(void);
int crypto_generichash_init(crypto_generichash_state *state,
const unsigned char *src_key,
const unsigned long long key_len,
const unsigned long long out_len);
int crypto_generichash_update(crypto_generichash_state *state,
const unsigned char *src_input,
unsigned long long input_len);
int crypto_generichash_final(crypto_generichash_state *state,
unsigned char *dst_out,
const unsigned long long out_len);
/* TODO END OF DANGER ZONE */
/*
crypto_shorthash API
*/
size_t crypto_shorthash_bytes(void);
size_t crypto_shorthash_keybytes(void);
const char *crypto_shorthash_primitive(void);
int crypto_shorthash(unsigned char *dst_out,
const unsigned char *src_input,
unsigned long long input_len,
const unsigned char *src_key);
/*
crypto_auth API
*/
size_t crypto_auth_bytes(void);
size_t crypto_auth_keybytes(void);
const char *crypto_auth_primitive(void);
int crypto_auth(unsigned char *dst_mac,
const unsigned char *src_input,
unsigned long long input_len,
const unsigned char *src_key);
int crypto_auth_verify(const unsigned char *src_mac,
const unsigned char *src_input,
unsigned long long input_len,
const unsigned char *src_key);
/*
crypto_onetimeauth API
TODO streaming interface
*/
size_t crypto_onetimeauth_bytes(void);
size_t crypto_onetimeauth_keybytes(void);
const char *crypto_onetimeauth_primitive(void);
int crypto_onetimeauth(unsigned char *dst_out,
const unsigned char *src_input,
unsigned long long input_len,
const unsigned char *src_key);
int crypto_onetimeauth_verify(const unsigned char *src_mac,
const unsigned char *src_input,
unsigned long long input_len,
const unsigned char *src_key);
size_t crypto_onetimeauth_statebytes(void);
int crypto_onetimeauth_init(crypto_onetimeauth_state *dst_state,
const unsigned char *src_key);
int crypto_onetimeauth_update(crypto_onetimeauth_state *dst_state,
const unsigned char *src_input,
unsigned long long input_len);
int crypto_onetimeauth_final(crypto_onetimeauth_state *final_state,
unsigned char *dst_out);
/*
Key exchange
*/
int crypto_kx_keypair(unsigned char *pk,
unsigned char *sk);
int crypto_kx_seed_keypair(unsigned char *pk,
unsigned char *sk,
const unsigned char *seed);
int crypto_kx_client_session_keys(unsigned char *rx,
unsigned char *tx,
const unsigned char *client_pk,
const unsigned char *client_sk,
const unsigned char *server_pk);
int crypto_kx_server_session_keys(unsigned char *rx,
unsigned char *tx,
const unsigned char *server_pk,
const unsigned char *server_sk,
const unsigned char *client_pk);
/*
Key Derivation
*/
size_t crypto_kdf_bytes_min(void);
size_t crypto_kdf_bytes_max(void);
size_t crypto_kdf_keybytes(void);
size_t crypto_kdf_contextbytes(void);
const char * crypto_kdf_primitive(void);
int crypto_kdf_derive_from_key(unsigned char *subkey,
const size_t subkey_len,
unsigned long long subkey_id,
const char *ctx,
const unsigned char *key);
void crypto_kdf_keygen(unsigned char *key);
/* *****************************************************************************
LOW LEVEL API'S
Low level API;s expose the functions for the specific primitives, and
support some functions that are only included for legacy reasons.
Some functions are aliased by the higher-level API calls, and should produce
the exact same result when called. For compatibility reasons, the primitive-
specific function calls are implemented and wrapped seperately, so when a
primitive changes in the official Sodium library, it automatically changes
in libstodium as well.
The Low-level implementations are exported for the sake of completeness, as
well as the primitive-specific implementations of the Java standard
interfaces for cryptographic operations.
i***************************************************************************** */
/*
AEAD aes256gcm is not (yet) implemented
TODO decide if this should be included
*/
/*
AEAD chacha20poly1305
*/
size_t crypto_aead_chacha20poly1305_keybytes(void);
size_t crypto_aead_chacha20poly1305_nsecbytes(void);
size_t crypto_aead_chacha20poly1305_npubbytes(void);
size_t crypto_aead_chacha20poly1305_abytes(void);
size_t crypto_aead_chacha20poly1305_messagebytes_max(void);
void crypto_aead_chacha20poly1305_keygen(unsigned char *k);
int crypto_aead_chacha20poly1305_encrypt(unsigned char *c,
unsigned long long *clen_p,
const unsigned char *m,
unsigned long long mlen,
const unsigned char *ad,
unsigned long long adlen,
const unsigned char *nsec,
const unsigned char *npub,
const unsigned char *k);
int crypto_aead_chacha20poly1305_encrypt_detached(unsigned char *c,
unsigned char *mac,
unsigned long long *maclen_p,
const unsigned char *m,
unsigned long long mlen,
const unsigned char *ad,
unsigned long long adlen,
const unsigned char *nsec,
const unsigned char *npub,
const unsigned char *k);
int crypto_aead_chacha20poly1305_decrypt(unsigned char *m,
unsigned long long *mlen_p,
unsigned char *nsec,
const unsigned char *c,
unsigned long long clen,
const unsigned char *ad,
unsigned long long adlen,
const unsigned char *npub,
const unsigned char *k);
int crypto_aead_chacha20poly1305_decrypt_detached(unsigned char *m,
unsigned char *nsec,
const unsigned char *c,
unsigned long long clen,
const unsigned char *mac,
const unsigned char *ad,
unsigned long long adlen,
const unsigned char *npub,
const unsigned char *k);
size_t crypto_aead_chacha20poly1305_ietf_keybytes(void);
size_t crypto_aead_chacha20poly1305_ietf_nsecbytes(void);
size_t crypto_aead_chacha20poly1305_ietf_abytes(void);
size_t crypto_aead_chacha20poly1305_ietf_messagebytes_max(void);
size_t crypto_aead_chacha20poly1305_ietf_npubbytes(void);
void crypto_aead_chacha20poly1305_ietf_keygen(unsigned char *k);
int crypto_aead_chacha20poly1305_ietf_encrypt(unsigned char *c,
unsigned long long *clen_p,
const unsigned char *m,
unsigned long long mlen,
const unsigned char *ad,
unsigned long long adlen,
const unsigned char *nsec,
const unsigned char *npub,
const unsigned char *k);
int crypto_aead_chacha20poly1305_ietf_encrypt_detached(unsigned char *c,
unsigned char *mac,
unsigned long long *maclen_p,
const unsigned char *m,
unsigned long long mlen,
const unsigned char *ad,
unsigned long long adlen,
const unsigned char *nsec,
const unsigned char *npub,
const unsigned char *k);
int crypto_aead_chacha20poly1305_ietf_decrypt(unsigned char *m,
unsigned long long *mlen_p,
unsigned char *nsec,
const unsigned char *c,
unsigned long long clen,
const unsigned char *ad,
unsigned long long adlen,
const unsigned char *npub,
const unsigned char *k);
int crypto_aead_chacha20poly1305_ietf_decrypt_detached(unsigned char *m,
unsigned char *nsec,
const unsigned char *c,
unsigned long long clen,
const unsigned char *mac,
const unsigned char *ad,
unsigned long long adlen,
const unsigned char *npub,
const unsigned char *k);
/*
AEAD xchacha20poly1305
*/
size_t crypto_aead_xchacha20poly1305_ietf_keybytes(void);
size_t crypto_aead_xchacha20poly1305_ietf_npubbytes(void);
size_t crypto_aead_xchacha20poly1305_ietf_nsecbytes(void);
size_t crypto_aead_xchacha20poly1305_ietf_abytes(void);
size_t crypto_aead_xchacha20poly1305_ietf_messagebytes_max(void);
void crypto_aead_xchacha20poly1305_ietf_keygen(unsigned char *k);
int crypto_aead_xchacha20poly1305_ietf_encrypt_detached(unsigned char *c,
unsigned char *mac,
unsigned long long *maclen_p,
const unsigned char *m,
unsigned long long mlen,
const unsigned char *ad,
unsigned long long adlen,
const unsigned char *nsec,
const unsigned char *npub,
const unsigned char *k);
int crypto_aead_xchacha20poly1305_ietf_encrypt(unsigned char *c,
unsigned long long *clen_p,
const unsigned char *m,
unsigned long long mlen,
const unsigned char *ad,
unsigned long long adlen,
const unsigned char *nsec,
const unsigned char *npub,
const unsigned char *k);
int crypto_aead_xchacha20poly1305_ietf_decrypt_detached(unsigned char *m,
unsigned char *nsec,
const unsigned char *c,
unsigned long long clen,
const unsigned char *mac,
const unsigned char *ad,
unsigned long long adlen,
const unsigned char *npub,
const unsigned char *k);
int crypto_aead_xchacha20poly1305_ietf_decrypt(unsigned char *m,
unsigned long long *mlen_p,
unsigned char *nsec,
const unsigned char *c,
unsigned long long clen,
const unsigned char *ad,
unsigned long long adlen,
const unsigned char *npub,
const unsigned char *k);
/*
Auth HMAC-SHA-256
*/
size_t crypto_auth_hmacsha256_bytes(void);
size_t crypto_auth_hmacsha256_keybytes(void);
int crypto_auth_hmacsha256(unsigned char *out,
const unsigned char *in,
unsigned long long inlen,
const unsigned char *k);
int crypto_auth_hmacsha256_verify(const unsigned char *h,
const unsigned char *in,
unsigned long long inlen,
const unsigned char *k);
size_t crypto_auth_hmacsha256_statebytes(void);
int crypto_auth_hmacsha256_init(crypto_auth_hmacsha256_state *state,
const unsigned char *key,
size_t keylen);
int crypto_auth_hmacsha256_update(crypto_auth_hmacsha256_state *state,
const unsigned char *in,
unsigned long long inlen);
int crypto_auth_hmacsha256_final(crypto_auth_hmacsha256_state *state,
unsigned char *out);
/*
Auth HMAC-SHA-512
*/
size_t crypto_auth_hmacsha512_bytes(void);
size_t crypto_auth_hmacsha512_keybytes(void);
int crypto_auth_hmacsha512(unsigned char *out,
const unsigned char *in,
unsigned long long inlen,
const unsigned char *k);
int crypto_auth_hmacsha512_verify(const unsigned char *h,
const unsigned char *in,
unsigned long long inlen,
const unsigned char *k);
size_t crypto_auth_hmacsha512_statebytes(void);
int crypto_auth_hmacsha512_init(crypto_auth_hmacsha512_state *state,
const unsigned char *key,
size_t keylen);
int crypto_auth_hmacsha512_update(crypto_auth_hmacsha512_state *state,
const unsigned char *in,
unsigned long long inlen);
int crypto_auth_hmacsha512_final(crypto_auth_hmacsha512_state *state,
unsigned char *out);
/*
Auth HMAC-SHA-512/256
*/
size_t crypto_auth_hmacsha512256_bytes(void);
size_t crypto_auth_hmacsha512256_keybytes(void);
int crypto_auth_hmacsha512256(unsigned char *out,
const unsigned char *in,
unsigned long long inlen,
const unsigned char *k);
int crypto_auth_hmacsha512256_verify(const unsigned char *h,
const unsigned char *in,
unsigned long long inlen,
const unsigned char *k);
size_t crypto_auth_hmacsha512256_statebytes(void);
int crypto_auth_hmacsha512256_init(crypto_auth_hmacsha512256_state *state,
const unsigned char *key,
size_t keylen);
int crypto_auth_hmacsha512256_update(crypto_auth_hmacsha512256_state *state,
const unsigned char *in,
unsigned long long inlen);
int crypto_auth_hmacsha512256_final(crypto_auth_hmacsha512256_state *state,
unsigned char *out);
/*
Box Curve25519XSalsa20Poly1305
*/
size_t crypto_box_curve25519xsalsa20poly1305_seedbytes(void);
size_t crypto_box_curve25519xsalsa20poly1305_publickeybytes(void);
size_t crypto_box_curve25519xsalsa20poly1305_secretkeybytes(void);
size_t crypto_box_curve25519xsalsa20poly1305_beforenmbytes(void);
size_t crypto_box_curve25519xsalsa20poly1305_noncebytes(void);
size_t crypto_box_curve25519xsalsa20poly1305_zerobytes(void);
size_t crypto_box_curve25519xsalsa20poly1305_boxzerobytes(void);
size_t crypto_box_curve25519xsalsa20poly1305_macbytes(void);
int crypto_box_curve25519xsalsa20poly1305(unsigned char *c,
const unsigned char *m,
unsigned long long mlen,
const unsigned char *n,
const unsigned char *pk,
const unsigned char *sk);
int crypto_box_curve25519xsalsa20poly1305_open(unsigned char *m,
const unsigned char *c,
unsigned long long clen,
const unsigned char *n,
const unsigned char *pk,
const unsigned char *sk);
int crypto_box_curve25519xsalsa20poly1305_seed_keypair(unsigned char *pk,
unsigned char *sk,
const unsigned char *seed);
int crypto_box_curve25519xsalsa20poly1305_keypair(unsigned char *pk,
unsigned char *sk);
int crypto_box_curve25519xsalsa20poly1305_beforenm(unsigned char *k,
const unsigned char *pk,
const unsigned char *sk);
int crypto_box_curve25519xsalsa20poly1305_afternm(unsigned char *c,
const unsigned char *m,
unsigned long long mlen,
const unsigned char *n,
const unsigned char *k);
int crypto_box_curve25519xsalsa20poly1305_open_afternm(unsigned char *m,
const unsigned char *c,
unsigned long long clen,
const unsigned char *n,
const unsigned char *k);
/*
Core HSalsa20
*/
size_t crypto_core_hsalsa20_outputbytes(void);
size_t crypto_core_hsalsa20_inputbytes(void);