This repository has been archived by the owner on Mar 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathprover.rs
2361 lines (2142 loc) · 85.6 KB
/
prover.rs
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
use crate::cl::prover::*;
use crate::cl::*;
use crate::errors::prelude::*;
use crate::ffi::ErrorCode;
use crate::utils::ctypes::*;
use serde_json;
use std::os::raw::{c_char, c_void};
/// Creates a master secret.
///
/// Note that master secret deallocation must be performed by
/// calling ursa_cl_master_secret_free.
///
/// # Arguments
/// * `master_secret_p` - Reference that will contain master secret instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_prover_new_master_secret(
master_secret_p: *mut *const c_void,
) -> ErrorCode {
trace!(
"ursa_cl_prover_new_master_secret: >>> {:?}",
master_secret_p
);
check_useful_c_ptr!(master_secret_p, ErrorCode::CommonInvalidParam1);
let res = match Prover::new_master_secret() {
Ok(master_secret) => {
trace!(
"ursa_cl_prover_new_master_secret: master_secret: {:?}",
master_secret
);
unsafe {
*master_secret_p = Box::into_raw(Box::new(master_secret)) as *const c_void;
trace!(
"ursa_cl_prover_new_master_secret: *master_secret_p: {:?}",
*master_secret_p
);
}
ErrorCode::Success
}
Err(err) => err.into(),
};
trace!("ursa_cl_prover_new_master_secret: <<< res: {:?}", res);
res
}
/// Returns json representation of master secret.
///
/// # Arguments
/// * `master_secret` - Reference that contains master secret instance pointer.
/// * `master_secret_json_p` - Reference that will contain master secret json.
#[no_mangle]
pub extern "C" fn ursa_cl_master_secret_to_json(
master_secret: *const c_void,
master_secret_json_p: *mut *const c_char,
) -> ErrorCode {
trace!(
"ursa_cl_master_secret_to_json: >>> master_secret: {:?}, master_secret_json_p: {:?}",
master_secret,
master_secret_json_p
);
check_useful_c_reference!(master_secret, MasterSecret, ErrorCode::CommonInvalidParam1);
check_useful_c_ptr!(master_secret_json_p, ErrorCode::CommonInvalidParam2);
trace!(
"ursa_cl_master_secret_to_json: entity >>> master_secret: {:?}",
master_secret
);
let res = match serde_json::to_string(master_secret) {
Ok(master_secret_json) => {
trace!(
"ursa_cl_master_secret_to_json: master_secret_json: {:?}",
master_secret_json
);
unsafe {
let master_secret_json = string_to_cstring(master_secret_json);
*master_secret_json_p = master_secret_json.into_raw();
trace!(
"ursa_cl_master_secret_to_json: master_secret_json_p: {:?}",
*master_secret_json_p
);
}
ErrorCode::Success
}
Err(err) => err
.to_ursa(
UrsaCryptoErrorKind::InvalidState,
"Unable to serialize master secret as json",
)
.into(),
};
trace!("ursa_cl_master_secret_to_json: <<< res: {:?}", res);
res
}
/// Creates and returns master secret from json.
///
/// Note: Master secret instance deallocation must be performed
/// by calling ursa_cl_master_secret_free.
///
/// # Arguments
/// * `master_secret_json` - Reference that contains master secret json.
/// * `master_secret_p` - Reference that will contain master secret instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_master_secret_from_json(
master_secret_json: *const c_char,
master_secret_p: *mut *const c_void,
) -> ErrorCode {
trace!(
"ursa_cl_master_secret_from_json: >>> master_secret_json: {:?}, master_secret_p: {:?}",
master_secret_json,
master_secret_p
);
check_useful_c_str!(master_secret_json, ErrorCode::CommonInvalidParam1);
check_useful_c_ptr!(master_secret_p, ErrorCode::CommonInvalidParam2);
trace!(
"ursa_cl_master_secret_from_json: entity: master_secret_json: {:?}",
master_secret_json
);
let res = match serde_json::from_str::<MasterSecret>(&master_secret_json) {
Ok(master_secret) => {
trace!(
"ursa_cl_master_secret_from_json: master_secret: {:?}",
master_secret
);
unsafe {
*master_secret_p = Box::into_raw(Box::new(master_secret)) as *const c_void;
trace!(
"ursa_cl_master_secret_from_json: *master_secret_p: {:?}",
*master_secret_p
);
}
ErrorCode::Success
}
Err(err) => err
.to_ursa(
UrsaCryptoErrorKind::InvalidStructure,
"Unable to deserialize master secret from json",
)
.into(),
};
trace!("ursa_cl_master_secret_from_json: <<< res: {:?}", res);
res
}
/// Deallocates master secret instance.
///
/// # Arguments
/// * `master_secret` - Reference that contains master secret instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_master_secret_free(master_secret: *const c_void) -> ErrorCode {
trace!(
"ursa_cl_master_secret_free: >>> master_secret: {:?}",
master_secret
);
check_useful_c_ptr!(master_secret, ErrorCode::CommonInvalidParam1);
let master_secret = unsafe { Box::from_raw(master_secret as *mut MasterSecret) };
trace!(
"ursa_cl_master_secret_free: entity: master_secret: {:?}",
master_secret
);
let res = ErrorCode::Success;
trace!("ursa_cl_master_secret_free: <<< res: {:?}", res);
res
}
/// Creates blinded credential secrets for given issuer key and master secret.
///
/// Note that blinded credential secrets deallocation must be performed by
/// calling ursa_cl_blinded_credential_secrets_free.
///
/// Note that credential secrets blinding factors deallocation must be performed by
/// calling ursa_cl_credential_secrets_blinding_factors_free.
///
/// Note that blinded credential secrets correctness proof deallocation must be performed by
/// calling ursa_cl_blinded_credential_secrets_correctness_proof_free.
///
/// # Arguments
/// * `credential_pub_key` - Reference that contains credential public key instance pointer.
/// * `credential_key_correctness_proof` - Reference that contains credential key correctness proof instance pointer.
/// * `credential_values` - Reference that contains credential values pointer.
/// * `credential_nonce` - Reference that contains nonce instance pointer.
/// * `blinded_credential_secrets_p` - Reference that will contain blinded credential secrets instance pointer.
/// * `credential_secrets_blinding_factors_p` - Reference that will contain credential secrets blinding factors instance pointer.
/// * `blinded_credential_secrets_correctness_proof_p` - Reference that will contain blinded credential secrets correctness proof instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_prover_blind_credential_secrets(
credential_pub_key: *const c_void,
credential_key_correctness_proof: *const c_void,
credential_values: *const c_void,
credential_nonce: *const c_void,
blinded_credential_secrets_p: *mut *const c_void,
credential_secrets_blinding_factors_p: *mut *const c_void,
blinded_credential_secrets_correctness_proof_p: *mut *const c_void,
) -> ErrorCode {
trace!(
"ursa_cl_prover_blind_credential_secrets: >>> credential_pub_key: {:?}, \
credential_key_correctness_proof: {:?}, \
credential_values: {:?}, \
credential_nonce: {:?}, \
blinded_credential_secrets_p: {:?}, \
credential_secrets_blinding_factors_p: {:?}, \
blinded_credential_secrets_correctness_proof_p: {:?}",
credential_pub_key,
credential_key_correctness_proof,
credential_values,
credential_nonce,
blinded_credential_secrets_p,
credential_secrets_blinding_factors_p,
blinded_credential_secrets_correctness_proof_p
);
check_useful_c_reference!(
credential_pub_key,
CredentialPublicKey,
ErrorCode::CommonInvalidParam1
);
check_useful_c_reference!(
credential_key_correctness_proof,
CredentialKeyCorrectnessProof,
ErrorCode::CommonInvalidParam2
);
check_useful_c_reference!(
credential_values,
CredentialValues,
ErrorCode::CommonInvalidParam3
);
check_useful_c_reference!(credential_nonce, Nonce, ErrorCode::CommonInvalidParam4);
check_useful_c_ptr!(blinded_credential_secrets_p, ErrorCode::CommonInvalidParam5);
check_useful_c_ptr!(
credential_secrets_blinding_factors_p,
ErrorCode::CommonInvalidParam6
);
check_useful_c_ptr!(
blinded_credential_secrets_correctness_proof_p,
ErrorCode::CommonInvalidParam7
);
trace!(
"ursa_cl_prover_blind_credential_secrets: inputs: credential_pub_key: {:?}, \
credential_key_correctness_proof: {:?}, \
credential_values: {:?}, \
credential_nonce: {:?}",
credential_pub_key,
credential_key_correctness_proof,
credential_values,
credential_nonce
);
let res = match Prover::blind_credential_secrets(
credential_pub_key,
credential_key_correctness_proof,
credential_values,
credential_nonce,
) {
Ok((
blinded_credential_secrets,
credential_secrets_blinding_factors,
blinded_credential_secrets_correctness_proof,
)) => {
trace!(
"ursa_cl_prover_blind_credential_secrets: blinded_credential_secrets: {:?}, \
credential_secrets_blinding_factors: {:?}, \
blinded_credential_secrets_correctness_proof: {:?}",
blinded_credential_secrets,
credential_secrets_blinding_factors,
blinded_credential_secrets_correctness_proof
);
unsafe {
*blinded_credential_secrets_p =
Box::into_raw(Box::new(blinded_credential_secrets)) as *const c_void;
*credential_secrets_blinding_factors_p =
Box::into_raw(Box::new(credential_secrets_blinding_factors)) as *const c_void;
*blinded_credential_secrets_correctness_proof_p =
Box::into_raw(Box::new(blinded_credential_secrets_correctness_proof))
as *const c_void;
trace!("ursa_cl_prover_blind_credential_secrets: *blinded_credential_secrets_p: {:?}, \
*credential_secrets_blinding_factors_p: {:?}, \
*blinded_credential_secrets_correctness_proof_p: {:?}",
*blinded_credential_secrets_p,
*credential_secrets_blinding_factors_p,
*blinded_credential_secrets_correctness_proof_p);
}
ErrorCode::Success
}
Err(err) => err.into(),
};
trace!(
"ursa_cl_prover_blind_credential_secrets: <<< res: {:?}",
res
);
res
}
/// Returns json representation of blinded credential secrets.
///
/// # Arguments
/// * `blinded_credential_secrets` - Reference that contains Blinded credential secrets pointer.
/// * `blinded_credential_secrets_json_p` - Reference that will contain blinded credential secrets json.
#[no_mangle]
pub extern "C" fn ursa_cl_blinded_credential_secrets_to_json(
blinded_credential_secrets: *const c_void,
blinded_credential_secrets_json_p: *mut *const c_char,
) -> ErrorCode {
trace!(
"ursa_cl_blinded_credential_secrets_to_json: >>> blinded_credential_secrets: {:?}\n\
blinded_credential_secrets_json_p: {:?}",
blinded_credential_secrets,
blinded_credential_secrets_json_p
);
check_useful_c_reference!(
blinded_credential_secrets,
BlindedCredentialSecrets,
ErrorCode::CommonInvalidParam1
);
check_useful_c_ptr!(
blinded_credential_secrets_json_p,
ErrorCode::CommonInvalidParam2
);
trace!(
"ursa_cl_blinded_credential_secrets_to_json: entity >>> blinded_credential_secrets: {:?}",
blinded_credential_secrets
);
let res = match serde_json::to_string(blinded_credential_secrets) {
Ok(blinded_credential_secrets_json) => {
trace!(
"ursa_cl_blinded_credential_secrets_to_json: blinded_credential_secrets_json: {:?}",
blinded_credential_secrets_json
);
unsafe {
let blinded_credential_secrets_json =
string_to_cstring(blinded_credential_secrets_json);
*blinded_credential_secrets_json_p = blinded_credential_secrets_json.into_raw();
trace!("ursa_cl_blinded_credential_secrets_to_json: blinded_credential_secrets_json_p: {:?}", *blinded_credential_secrets_json_p);
}
ErrorCode::Success
}
Err(err) => err
.to_ursa(
UrsaCryptoErrorKind::InvalidState,
"Unable to serialize blinded credential secret as json",
)
.into(),
};
trace!(
"ursa_cl_blinded_credential_secrets_to_json: <<< res: {:?}",
res
);
res
}
/// Creates and returns blinded credential secrets from json.
///
/// Note: Blinded credential secrets instance deallocation must be performed
/// by calling ursa_cl_blinded_credential_secrets_free
///
/// # Arguments
/// * `blinded_credential_secrets_json` - Reference that contains blinded credential secret json.
/// * `blinded_credential_secrets_p` - Reference that will contain blinded credential secret instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_blinded_credential_secrets_from_json(
blinded_credential_secrets_json: *const c_char,
blinded_credential_secrets_p: *mut *const c_void,
) -> ErrorCode {
trace!("ursa_cl_blinded_credential_secrets_from_json: >>> blinded_credential_secrets_json: {:?}, blinded_credential_secrets_p: {:?}", blinded_credential_secrets_json, blinded_credential_secrets_p);
check_useful_c_str!(
blinded_credential_secrets_json,
ErrorCode::CommonInvalidParam1
);
check_useful_c_ptr!(blinded_credential_secrets_p, ErrorCode::CommonInvalidParam2);
trace!("ursa_cl_blinded_credential_secrets_from_json: entity: blinded_credential_secrets_json: {:?}", blinded_credential_secrets_json);
let res = match serde_json::from_str::<BlindedCredentialSecrets>(
&blinded_credential_secrets_json,
) {
Ok(blinded_credential_secrets) => {
trace!(
"ursa_cl_blinded_credential_secrets_from_json: blinded_credential_secrets: {:?}",
blinded_credential_secrets
);
unsafe {
*blinded_credential_secrets_p =
Box::into_raw(Box::new(blinded_credential_secrets)) as *const c_void;
trace!("ursa_cl_blinded_credential_secrets_from_json: *blinded_credential_secrets_p: {:?}", *blinded_credential_secrets_p);
}
ErrorCode::Success
}
Err(err) => err
.to_ursa(
UrsaCryptoErrorKind::InvalidStructure,
"Unable to deserialize blinded credential secret from json",
)
.into(),
};
trace!(
"ursa_cl_blinded_credential_secrets_from_json: <<< res: {:?}",
res
);
res
}
/// Deallocates blinded credential secrets instance.
///
/// # Arguments
/// * `blinded_credential_secrets` - Reference that contains blinded credential secrets instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_blinded_credential_secrets_free(
blinded_credential_secrets: *const c_void,
) -> ErrorCode {
trace!(
"ursa_cl_blinded_credential_secrets_free: >>> blinded_credential_secrets: {:?}",
blinded_credential_secrets
);
check_useful_c_ptr!(blinded_credential_secrets, ErrorCode::CommonInvalidParam1);
let blinded_credential_secrets =
unsafe { Box::from_raw(blinded_credential_secrets as *mut BlindedCredentialSecrets) };
trace!(
"ursa_cl_blinded_credential_secrets_free: entity: blinded_credential_secrets: {:?}",
blinded_credential_secrets
);
let res = ErrorCode::Success;
trace!(
"ursa_cl_blinded_credential_secrets_free: <<< res: {:?}",
res
);
res
}
/// Returns json representation of credential secrets blinding factors.
///
/// # Arguments
/// * `credential_secrets_blinding_factors` - Reference that contains credential secrets blinding factors pointer.
/// * `credential_secrets_blinding_factors_json_p` - Reference that will contain credential secrets blinding factors json.
#[no_mangle]
pub extern "C" fn ursa_cl_credential_secrets_blinding_factors_to_json(
credential_secrets_blinding_factors: *const c_void,
credential_secrets_blinding_factors_json_p: *mut *const c_char,
) -> ErrorCode {
trace!("ursa_cl_credential_secret_blinding_factors_to_json: >>> credential_secrets_blinding_factors: {:?}\n\
credential_secrets_blinding_factors_json_p: {:?}", credential_secrets_blinding_factors, credential_secrets_blinding_factors_json_p);
check_useful_c_reference!(
credential_secrets_blinding_factors,
CredentialSecretsBlindingFactors,
ErrorCode::CommonInvalidParam1
);
check_useful_c_ptr!(
credential_secrets_blinding_factors_json_p,
ErrorCode::CommonInvalidParam2
);
trace!("ursa_cl_credential_secret_blinding_factors_to_json: entity >>> credential_secrets_blinding_factors: {:?}", credential_secrets_blinding_factors);
let res = match serde_json::to_string(credential_secrets_blinding_factors) {
Ok(credential_secrets_blinding_factors_json) => {
trace!("ursa_cl_credential_secret_blinding_factors_to_json: credential_secrets_blinding_factors_json: {:?}", credential_secrets_blinding_factors_json);
unsafe {
let credential_secrets_blinding_factors_json =
string_to_cstring(credential_secrets_blinding_factors_json);
*credential_secrets_blinding_factors_json_p =
credential_secrets_blinding_factors_json.into_raw();
trace!("ursa_cl_credential_secret_blinding_factors_to_json: credential_secrets_blinding_factors_json_p: {:?}", *credential_secrets_blinding_factors_json_p);
}
ErrorCode::Success
}
Err(err) => err
.to_ursa(
UrsaCryptoErrorKind::InvalidState,
"Unable to serialize blinded credential secret factors as json",
)
.into(),
};
trace!(
"ursa_cl_credential_secret_blinding_factors_to_json: <<< res: {:?}",
res
);
res
}
/// Creates and returns credential secrets blinding factors json.
///
/// Note: Credential secrets blinding factors instance deallocation must be performed
/// by calling ursa_cl_credential_secrets_blinding_factors_free.
///
/// # Arguments
/// * `credential_secrets_blinding_factors_json` - Reference that contains credential secrets blinding factors json.
/// * `credential_secrets_blinding_factors_p` - Reference that will contain credential secrets blinding factors instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_credential_secrets_blinding_factors_from_json(
credential_secrets_blinding_factors_json: *const c_char,
credential_secrets_blinding_factors_p: *mut *const c_void,
) -> ErrorCode {
trace!("ursa_cl_credential_secrets_blinding_factors_from_json: >>> credential_secrets_blinding_factors_json: {:?}\n\
credential_secrets_blinding_factors_p: {:?}", credential_secrets_blinding_factors_json, credential_secrets_blinding_factors_p);
check_useful_c_str!(
credential_secrets_blinding_factors_json,
ErrorCode::CommonInvalidParam1
);
check_useful_c_ptr!(
credential_secrets_blinding_factors_p,
ErrorCode::CommonInvalidParam2
);
trace!("ursa_cl_credential_secrets_blinding_factors_from_json: entity: credential_secrets_blinding_factors_json: {:?}", credential_secrets_blinding_factors_json);
let res = match serde_json::from_str::<CredentialSecretsBlindingFactors>(
&credential_secrets_blinding_factors_json,
) {
Ok(credential_secrets_blinding_factors) => {
trace!("ursa_cl_credential_secrets_blinding_factors_from_json: credential_secrets_blinding_factors: {:?}", credential_secrets_blinding_factors);
unsafe {
*credential_secrets_blinding_factors_p =
Box::into_raw(Box::new(credential_secrets_blinding_factors)) as *const c_void;
trace!("ursa_cl_credential_secrets_blinding_factors_from_json: *credential_secrets_blinding_factors_p: {:?}", *credential_secrets_blinding_factors_p);
}
ErrorCode::Success
}
Err(err) => err
.to_ursa(
UrsaCryptoErrorKind::InvalidStructure,
"Unable to deserialize blinded credential secret factors from json",
)
.into(),
};
trace!(
"ursa_cl_credential_secrets_blinding_factors_from_json: <<< res: {:?}",
res
);
res
}
/// Deallocates credential secrets blinding factors instance.
///
/// # Arguments
/// * `credential_secrets_blinding_factors` - Reference that contains credential secrets blinding factors instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_credential_secrets_blinding_factors_free(
credential_secrets_blinding_factors: *const c_void,
) -> ErrorCode {
trace!("ursa_cl_credential_secrets_blinding_factors_free: >>> credential_secrets_blinding_factors: {:?}", credential_secrets_blinding_factors);
check_useful_c_ptr!(
credential_secrets_blinding_factors,
ErrorCode::CommonInvalidParam1
);
let credential_secrets_blinding_factors = unsafe {
Box::from_raw(credential_secrets_blinding_factors as *mut CredentialSecretsBlindingFactors)
};
trace!("ursa_cl_credential_secrets_blinding_factors_free: entity: credential_secrets_blinding_factors: {:?}", credential_secrets_blinding_factors);
let res = ErrorCode::Success;
trace!(
"ursa_cl_credential_secrets_blinding_factors_free: <<< res: {:?}",
res
);
res
}
/// Returns json representation of blinded credential secrets correctness proof.
///
/// # Arguments
/// * `blinded_credential_secrets_correctness_proof` - Reference that contains blinded credential secrets correctness proof pointer.
/// * `blinded_credential_secrets_correctness_proof_json_p` - Reference that will contain blinded credential secrets correctness proof json.
#[no_mangle]
pub extern "C" fn ursa_cl_blinded_credential_secrets_correctness_proof_to_json(
blinded_credential_secrets_correctness_proof: *const c_void,
blinded_credential_secrets_correctness_proof_json_p: *mut *const c_char,
) -> ErrorCode {
trace!("ursa_cl_blinded_credential_secrets_correctness_proof_to_json: >>> blinded_credential_secrets_correctness_proof: {:?}\n\
blinded_credential_secrets_correctness_proof_json_p: {:?}", blinded_credential_secrets_correctness_proof, blinded_credential_secrets_correctness_proof_json_p);
check_useful_c_reference!(
blinded_credential_secrets_correctness_proof,
BlindedCredentialSecretsCorrectnessProof,
ErrorCode::CommonInvalidParam1
);
check_useful_c_ptr!(
blinded_credential_secrets_correctness_proof_json_p,
ErrorCode::CommonInvalidParam2
);
trace!("ursa_cl_blinded_credential_secrets_correctness_proof_to_json: entity >>> blinded_credential_secrets_correctness_proof: {:?}",
blinded_credential_secrets_correctness_proof);
let res = match serde_json::to_string(blinded_credential_secrets_correctness_proof) {
Ok(blinded_credential_secrets_correctness_proof_json) => {
trace!("ursa_cl_blinded_credential_secrets_correctness_proof_to_json: blinded_credential_secrets_correctness_proof: {:?}",
blinded_credential_secrets_correctness_proof_json);
unsafe {
let blinded_credential_secrets_correctness_proof_json =
string_to_cstring(blinded_credential_secrets_correctness_proof_json);
*blinded_credential_secrets_correctness_proof_json_p =
blinded_credential_secrets_correctness_proof_json.into_raw();
trace!("ursa_cl_blinded_credential_secrets_correctness_proof_to_json: blinded_credential_secrets_correctness_proof_json_p: {:?}",
*blinded_credential_secrets_correctness_proof_json_p);
}
ErrorCode::Success
}
Err(err) => err
.to_ursa(
UrsaCryptoErrorKind::InvalidState,
"Unable to serialize blinded credential secrets correctness proof as json",
)
.into(),
};
trace!(
"ursa_cl_blinded_credential_secrets_correctness_proof_to_json: <<< res: {:?}",
res
);
res
}
/// Creates and returns blinded credential secrets correctness proof json.
///
/// Note: Blinded credential secrets correctness proof instance deallocation must be performed
/// by calling ursa_cl_blinded_credential_secrets_correctness_proof_free.
///
/// # Arguments
/// * `blinded_credential_secrets_correctness_proof_json` - Reference that contains blinded credential secrets correctness proof json.
/// * `blinded_credential_secrets_correctness_proof_p` - Reference that will contain blinded credential secret correctness proof instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_blinded_credential_secrets_correctness_proof_from_json(
blinded_credential_secrets_correctness_proof_json: *const c_char,
blinded_credential_secrets_correctness_proof_p: *mut *const c_void,
) -> ErrorCode {
trace!("ursa_cl_blinded_credential_secrets_correctness_proof_from_json: >>> blinded_credential_secrets_correctness_proof_json: {:?},\
blinded_credential_secrets_correctness_proof_p: {:?}", blinded_credential_secrets_correctness_proof_json, blinded_credential_secrets_correctness_proof_p);
check_useful_c_str!(
blinded_credential_secrets_correctness_proof_json,
ErrorCode::CommonInvalidParam1
);
check_useful_c_ptr!(
blinded_credential_secrets_correctness_proof_p,
ErrorCode::CommonInvalidParam2
);
trace!("ursa_cl_blinded_credential_secrets_correctness_proof_from_json: entity: blinded_credential_secrets_correctness_proof_json: {:?}",
blinded_credential_secrets_correctness_proof_json);
let res = match serde_json::from_str::<BlindedCredentialSecretsCorrectnessProof>(
&blinded_credential_secrets_correctness_proof_json,
) {
Ok(blinded_credential_secrets_correctness_proof) => {
trace!("ursa_cl_blinded_credential_secrets_correctness_proof_from_json: blinded_credential_secrets_correctness_proof: {:?}",
blinded_credential_secrets_correctness_proof);
unsafe {
*blinded_credential_secrets_correctness_proof_p =
Box::into_raw(Box::new(blinded_credential_secrets_correctness_proof))
as *const c_void;
trace!("ursa_cl_blinded_credential_secrets_correctness_proof_from_json: *blinded_credential_secrets_correctness_proof_p: {:?}",
*blinded_credential_secrets_correctness_proof_p);
}
ErrorCode::Success
}
Err(err) => err
.to_ursa(
UrsaCryptoErrorKind::InvalidStructure,
"Unable to deserialize blinded credential secret correctness proof from json",
)
.into(),
};
trace!(
"ursa_cl_blinded_credential_secrets_correctness_proof_from_json: <<< res: {:?}",
res
);
res
}
/// Deallocates blinded credential secrets correctness proof instance.
///
/// # Arguments
/// * `blinded_credential_secrets_correctness_proof` - Reference that contains blinded credential secrets correctness proof instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_blinded_credential_secrets_correctness_proof_free(
blinded_credential_secrets_correctness_proof: *const c_void,
) -> ErrorCode {
trace!("ursa_cl_blinded_credential_secrets_correctness_proof_free: >>> blinded_credential_secrets_correctness_proof: {:?}",
blinded_credential_secrets_correctness_proof);
check_useful_c_ptr!(
blinded_credential_secrets_correctness_proof,
ErrorCode::CommonInvalidParam1
);
let blinded_credential_secrets_correctness_proof = unsafe {
Box::from_raw(
blinded_credential_secrets_correctness_proof
as *mut BlindedCredentialSecretsCorrectnessProof,
)
};
trace!("ursa_cl_blinded_credential_secrets_correctness_proof_free: entity: blinded_credential_secrets_correctness_proof: {:?}", blinded_credential_secrets_correctness_proof);
let res = ErrorCode::Success;
trace!(
"ursa_cl_blinded_credential_secrets_correctness_proof_free: <<< res: {:?}",
res
);
res
}
/// Updates the credential signature by a credential secrets blinding factors.
///
/// # Arguments
/// * `credential_signature` - Credential signature instance pointer generated by Issuer.
/// * `credential_values` - Credential values instance pointer.
/// * `signature_correctness_proof` - Credential signature correctness proof instance pointer.
/// * `credential_secrets_blinding_factors` - Credential secrets blinding factors instance pointer.
/// * `credential_pub_key` - Credential public key instance pointer.
/// * `nonce` - Nonce instance pointer was used by Issuer for the creation of signature_correctness_proof.
/// * `rev_key_pub` - (Optional) Revocation registry public key instance pointer.
/// * `rev_reg` - (Optional) Revocation registry instance pointer.
/// * `witness` - (Optional) Witness instance pointer.
#[no_mangle]
#[allow(unused_variables)]
pub extern "C" fn ursa_cl_prover_process_credential_signature(
credential_signature: *const c_void,
credential_values: *const c_void,
signature_correctness_proof: *const c_void,
credential_secrets_blinding_factors: *const c_void,
credential_pub_key: *const c_void,
credential_issuance_nonce: *const c_void,
rev_key_pub: *const c_void,
rev_reg: *const c_void,
witness: *const c_void,
) -> ErrorCode {
trace!(
"ursa_cl_prover_process_credential_signature: >>> credential_signature: {:?}\n\
signature_correctness_proof: {:?}\n\
credential_secrets_blinding_factors: {:?}\n\
credential_pub_key: {:?}\n\
credential_issuance_nonce: {:?}\n\
rev_key_pub: {:?}\n\
rev_reg {:?}\n\
witness {:?}",
credential_signature,
signature_correctness_proof,
credential_secrets_blinding_factors,
credential_pub_key,
credential_issuance_nonce,
rev_key_pub,
rev_reg,
witness
);
check_useful_mut_c_reference!(
credential_signature,
CredentialSignature,
ErrorCode::CommonInvalidParam1
);
check_useful_c_reference!(
credential_values,
CredentialValues,
ErrorCode::CommonInvalidParam2
);
check_useful_c_reference!(
signature_correctness_proof,
SignatureCorrectnessProof,
ErrorCode::CommonInvalidParam3
);
check_useful_c_reference!(
credential_secrets_blinding_factors,
CredentialSecretsBlindingFactors,
ErrorCode::CommonInvalidParam4
);
check_useful_c_reference!(
credential_pub_key,
CredentialPublicKey,
ErrorCode::CommonInvalidParam5
);
check_useful_c_reference!(
credential_issuance_nonce,
Nonce,
ErrorCode::CommonInvalidParam6
);
check_useful_opt_c_reference!(rev_key_pub, RevocationKeyPublic);
check_useful_opt_c_reference!(rev_reg, RevocationRegistry);
check_useful_opt_c_reference!(witness, Witness);
trace!(
"ursa_cl_prover_process_credential_signature: >>> credential_signature: {:?}\n\
credential_values: {:?}\n\
signature_correctness_proof: {:?}\n\
credential_secrets_blinding_factors: {:?}\n\
credential_pub_key: {:?}\n\
credential_issuance_nonce: {:?}\n\
rev_key_pub: {:?}\n\
rev_reg {:?}, witness {:?}",
credential_signature,
credential_values,
signature_correctness_proof,
credential_secrets_blinding_factors,
credential_pub_key,
credential_issuance_nonce,
rev_key_pub,
rev_reg,
witness
);
let res = match Prover::process_credential_signature(
credential_signature,
credential_values,
signature_correctness_proof,
credential_secrets_blinding_factors,
credential_pub_key,
credential_issuance_nonce,
rev_key_pub,
rev_reg,
witness,
) {
Ok(()) => ErrorCode::Success,
Err(err) => err.into(),
};
trace!(
"ursa_cl_prover_process_credential_signature: <<< res: {:?}",
res
);
res
}
#[no_mangle]
#[allow(unused_variables)]
pub extern "C" fn ursa_cl_prover_get_credential_revocation_index(
credential_signature: *const c_void,
cred_rev_indx: *mut u32,
) -> ErrorCode {
trace!("ursa_cl_prover_get_credential_revocation_index: >>> credential_signature: {:?}, cred_rev_indx: {:?}",
credential_signature, cred_rev_indx);
check_useful_c_reference!(
credential_signature,
CredentialSignature,
ErrorCode::CommonInvalidParam1
);
trace!(
"ursa_cl_prover_get_credential_revocation_index: >>> credential_signature: {:?}",
credential_signature
);
let res = match credential_signature.extract_index() {
Some(index) => {
trace!(
"ursa_cl_prover_get_credential_revocation_index: index: {:?}",
index
);
unsafe {
*cred_rev_indx = index;
}
trace!(
"ursa_cl_prover_get_credential_revocation_index: *cred_rev_indx: {:?}",
cred_rev_indx
);
ErrorCode::Success
}
None => err_msg(
UrsaCryptoErrorKind::InvalidState,
"Unable to extract credential revocation index",
)
.into(),
};
trace!(
"ursa_cl_prover_get_credential_revocation_index: <<< res: {:?}",
res
);
res
}
/// Creates and returns proof builder.
///
/// The purpose of proof builder is building of proof entity according to the given request .
///
/// Note that proof builder deallocation must be performed by
/// calling ursa_cl_proof_builder_finalize.
///
/// # Arguments
/// * `proof_builder_p` - Reference that will contain proof builder instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_prover_new_proof_builder(
proof_builder_p: *mut *const c_void,
) -> ErrorCode {
trace!(
"ursa_cl_prover_new_proof_builder: >>> {:?}",
proof_builder_p
);
check_useful_c_ptr!(proof_builder_p, ErrorCode::CommonInvalidParam1);
let res = match Prover::new_proof_builder() {
Ok(proof_builder) => {
trace!(
"ursa_cl_prover_new_proof_builder: proof_builder: {:?}",
proof_builder
);
unsafe {
*proof_builder_p = Box::into_raw(Box::new(proof_builder)) as *const c_void;
trace!(
"ursa_cl_prover_new_proof_builder: *proof_builder_p: {:?}",
*proof_builder_p
);
}
ErrorCode::Success
}
Err(err) => err.into(),
};
trace!("ursa_cl_prover_new_proof_builder: <<< res: {:?}", res);
res
}
/// Add a common attribute to the proof builder
///
/// # Arguments
/// * `proof_builder` - Reference that contain proof builder instance pointer.
/// * `attribute_name` - Common attribute's name
#[no_mangle]
pub extern "C" fn ursa_cl_proof_builder_add_common_attribute(
proof_builder: *const c_void,
attribute_name: *const c_char,
) -> ErrorCode {
trace!(
"ursa_cl_proof_builder_add_common_attribute: >>> proof_builder: {:?}, attribute_name: {:?}",
proof_builder,
attribute_name
);
check_useful_mut_c_reference!(proof_builder, ProofBuilder, ErrorCode::CommonInvalidParam1);
check_useful_c_str!(attribute_name, ErrorCode::CommonInvalidParam2);
trace!(
"ursa_cl_proof_builder_add_common_attribute: entities: proof_builder: {:?}, attribute_name: {:?}",
proof_builder,
attribute_name
);
match proof_builder.add_common_attribute(&attribute_name) {
Ok(()) => ErrorCode::Success,
Err(err) => err.into(),
}
}
/// Add a sub proof request to the proof builder
///
/// # Arguments
/// * `proof_builder` - Reference that contain proof builder instance pointer.
/// * `sub_proof_request` - Reference that contain sub proof request instance pointer.
/// * `credential_schema` - Reference that contains credential schema instance pointer.
/// * `non_credential_schema` - Reference that contains non credential schema instance pointer.
/// * `credential_signature` - Reference that contains the credential signature pointer.
/// * `credential_values` - Reference that contains credential values instance pointer.
/// * `credential_pub_key` - Reference that contains credential public key instance pointer.
/// * `rev_reg` - (Optional) Reference that will contain revocation registry public instance pointer.
/// * `witness` - (Optional) Reference that will contain witness instance pointer.
#[no_mangle]
pub extern "C" fn ursa_cl_proof_builder_add_sub_proof_request(
proof_builder: *const c_void,
sub_proof_request: *const c_void,
credential_schema: *const c_void,
non_credential_schema: *const c_void,
credential_signature: *const c_void,
credential_values: *const c_void,
credential_pub_key: *const c_void,