tfhe 1.7.0

TFHE-rs is a fully homomorphic encryption (FHE) library that implements Zama's variant of TFHE.
Documentation
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
use std::borrow::Borrow;
use std::num::NonZeroU64;

use crate::core_crypto::gpu::CudaStreams;
use crate::integer::ciphertext::{PrfReRandomizationContext, ReRandomizationSeed};
use crate::integer::gpu::ciphertext::re_randomization::CudaReRandomizationKey;
use crate::integer::gpu::ciphertext::{
    CudaIntegerRadixCiphertext, CudaRadixCiphertext, CudaSignedRadixCiphertext,
    CudaUnsignedRadixCiphertext,
};
use crate::integer::gpu::server_key::{
    CudaBootstrappingKey, CudaDynamicKeyswitchingKey, CudaServerKey,
};
use itertools::Itertools;

use crate::shortint::oprf::{
    create_random_from_seed_modulus_switched, raw_seeded_msed_to_lwe, RandomBitsRleLeBytes,
};
use crate::shortint::OprfSeed;

use crate::core_crypto::gpu::lwe_compact_ciphertext_list::CudaLweCompactCiphertextList;
use crate::core_crypto::gpu::lwe_keyswitch_key::CudaLweKeyswitchKey;
use crate::core_crypto::gpu::vec::CudaVec;
use crate::core_crypto::prelude::LweCiphertextCount;
use crate::integer::block_decomposition::BlockDecomposer;
use crate::integer::gpu::{
    cuda_backend_get_grouped_oprf_size_on_gpu, cuda_backend_grouped_oprf,
    cuda_backend_grouped_oprf_custom_range,
};
use crate::shortint::PBSOrder;

pub struct GenericCudaOprfServerKey<K> {
    bootstrapping_key: K,
}

pub type CudaOprfServerKey = GenericCudaOprfServerKey<CudaBootstrappingKey<u64>>;
pub type CudaOprfServerKeyView<'a> = GenericCudaOprfServerKey<&'a CudaBootstrappingKey<u64>>;

impl CudaOprfServerKey {
    pub fn as_view(&self) -> CudaOprfServerKeyView<'_> {
        GenericCudaOprfServerKey {
            bootstrapping_key: &self.bootstrapping_key,
        }
    }

    pub fn decompress_from_cpu(
        cpu_key: &crate::integer::oprf::CompressedOprfServerKey,
        streams: &CudaStreams,
    ) -> Self {
        let expanded = cpu_key.expand();
        Self::from_expanded_cpu(&expanded, streams)
    }

    pub fn from_expanded_cpu(
        expanded: &crate::integer::oprf::ExpandedOprfServerKey,
        streams: &CudaStreams,
    ) -> Self {
        let bsk = &expanded.0 .0;
        let bootstrapping_key = CudaBootstrappingKey::from_expanded_oprf_server_key(bsk, streams);
        Self { bootstrapping_key }
    }
}

impl<'a> CudaOprfServerKeyView<'a> {
    pub fn from_borrowed_bsk(bsk: &'a CudaBootstrappingKey<u64>) -> Self {
        Self {
            bootstrapping_key: bsk,
        }
    }
}

impl<K> GenericCudaOprfServerKey<K>
where
    K: Borrow<CudaBootstrappingKey<u64>>,
{
    pub(crate) fn assert_compatible_with_target_bsk(&self, target_bsk: &CudaBootstrappingKey<u64>) {
        assert_eq!(
            target_bsk.input_lwe_dimension(),
            self.bootstrapping_key.borrow().input_lwe_dimension()
        );
        assert_eq!(
            target_bsk.output_lwe_dimension(),
            self.bootstrapping_key.borrow().output_lwe_dimension()
        );
        assert_eq!(
            target_bsk.polynomial_size(),
            self.bootstrapping_key.borrow().polynomial_size()
        );
        assert_eq!(
            target_bsk.glwe_size(),
            self.bootstrapping_key.borrow().glwe_size()
        );
    }

    /// Generates an encrypted `num_block` blocks unsigned integer
    /// taken uniformly in its full range using the given seed.
    /// The encrypted value is oblivious to the server.
    /// It can be useful to make server random generation deterministic.
    ///
    /// ```rust
    /// use tfhe::core_crypto::gpu::CudaStreams;
    /// use tfhe::core_crypto::gpu::vec::GpuIndex;
    /// use tfhe::integer::gpu::gen_keys_gpu;
    /// use tfhe::integer::gpu::CudaOprfServerKey;
    /// use tfhe::integer::oprf::{CompressedOprfServerKey, OprfPrivateKey};
    /// use tfhe::shortint::parameters::PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
    /// use tfhe::Seed;
    ///
    /// let size = 4;
    /// let gpu_index = 0;
    /// let streams = CudaStreams::new_single_gpu(GpuIndex::new(gpu_index));
    ///
    /// // Generate the client key and the server key:
    /// let (cks, sks) = gen_keys_gpu(PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128, &streams);
    ///
    /// // Generate the OPRF key:
    /// let oprf_pk = OprfPrivateKey::new(&cks);
    /// let compressed_oprf_sk = CompressedOprfServerKey::new(&oprf_pk, &cks).unwrap();
    /// let cuda_oprf_sk = CudaOprfServerKey::decompress_from_cpu(&compressed_oprf_sk, &streams);
    ///
    /// // DANGER: Using a fixed seed is insecure and only done here to show API usage.
    /// // The proper way of generating a seed depends on your application.
    /// let d_ct_res = cuda_oprf_sk.par_generate_oblivious_pseudo_random_unsigned_integer(Seed(0), size as u64, &sks, &streams);
    /// let ct_res = d_ct_res.to_radix_ciphertext(&streams);
    /// // Decrypt:
    /// let dec_result: u64 = cks.decrypt_radix(&ct_res);
    ///
    /// assert!(dec_result < 1 << (2 * size));
    /// ```
    pub fn par_generate_oblivious_pseudo_random_unsigned_integer(
        &self,
        seed: impl OprfSeed,
        num_blocks: u64,
        target_sks: &CudaServerKey,
        streams: &CudaStreams,
    ) -> CudaUnsignedRadixCiphertext {
        self.generate_oblivious_pseudo_random_unbounded_integer(
            seed, num_blocks, target_sks, streams,
        )
    }

    pub fn par_generate_oblivious_pseudo_random_unsigned_integer_and_re_randomize(
        &self,
        seed: impl OprfSeed,
        num_blocks: u64,
        target_sks: &CudaServerKey,
        re_randomization_key: &CudaReRandomizationKey<'_>,
        prf_re_randomization_context: &PrfReRandomizationContext,
        streams: &CudaStreams,
    ) -> crate::Result<CudaUnsignedRadixCiphertext> {
        self.generate_oblivious_pseudo_random_unbounded_integer_and_re_randomize(
            seed,
            num_blocks,
            target_sks,
            re_randomization_key,
            prf_re_randomization_context,
            streams,
        )
    }

    /// Generates an encrypted `num_block` blocks unsigned integer
    /// taken uniformly in `[0, 2^random_bits_count[` using the given seed.
    /// The encrypted value is oblivious to the server.
    /// It can be useful to make server random generation deterministic.
    ///
    /// ```rust
    /// use tfhe::core_crypto::gpu::CudaStreams;
    /// use tfhe::core_crypto::gpu::vec::GpuIndex;
    /// use tfhe::integer::gpu::gen_keys_gpu;
    /// use tfhe::integer::gpu::CudaOprfServerKey;
    /// use tfhe::integer::oprf::{CompressedOprfServerKey, OprfPrivateKey};
    /// use tfhe::shortint::parameters::PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
    /// use tfhe::Seed;
    ///
    /// let gpu_index = 0;
    /// let streams = CudaStreams::new_single_gpu(GpuIndex::new(gpu_index));
    /// let size = 4;
    ///
    /// // Generate the client key and the server key:
    /// let (cks, sks) = gen_keys_gpu(PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128, &streams);
    ///
    /// // Generate the OPRF key:
    /// let oprf_pk = OprfPrivateKey::new(&cks);
    /// let compressed_oprf_sk = CompressedOprfServerKey::new(&oprf_pk, &cks).unwrap();
    /// let cuda_oprf_sk = CudaOprfServerKey::decompress_from_cpu(&compressed_oprf_sk, &streams);
    ///
    /// let random_bits_count = 3;
    ///
    /// // DANGER: Using a fixed seed is insecure and only done here to show API usage.
    /// // The proper way of generating a seed depends on your application.
    /// let d_ct_res = cuda_oprf_sk.par_generate_oblivious_pseudo_random_unsigned_integer_bounded(
    ///     Seed(0),
    ///     random_bits_count,
    ///     size as u64,
    ///     &sks,
    ///     &streams,
    /// );
    /// let ct_res = d_ct_res.to_radix_ciphertext(&streams);
    /// // Decrypt:
    /// let dec_result: u64 = cks.decrypt_radix(&ct_res);
    /// assert!(dec_result < (1 << random_bits_count));
    /// ```
    pub fn par_generate_oblivious_pseudo_random_unsigned_integer_bounded(
        &self,
        seed: impl OprfSeed,
        random_bits_count: u64,
        num_blocks: u64,
        target_sks: &CudaServerKey,
        streams: &CudaStreams,
    ) -> CudaUnsignedRadixCiphertext {
        assert!(target_sks.message_modulus.0.is_power_of_two());
        let message_bits_count = target_sks.message_modulus.0.ilog2() as u64;
        let range_bits_count = message_bits_count * num_blocks;
        assert!(range_bits_count > 0);

        assert!(
            random_bits_count <= range_bits_count,
            "The range asked for a random value (=[0, 2^{random_bits_count}[) \
            does not fit in the available range [0, 2^{range_bits_count}[",
        );

        self.generate_oblivious_pseudo_random_bounded_integer(
            seed,
            random_bits_count,
            num_blocks,
            target_sks,
            streams,
        )
    }

    #[allow(clippy::too_many_arguments)]
    pub fn par_generate_oblivious_pseudo_random_unsigned_integer_bounded_and_re_randomize(
        &self,
        seed: impl OprfSeed,
        random_bits_count: u64,
        num_blocks: u64,
        target_sks: &CudaServerKey,
        re_randomization_key: &CudaReRandomizationKey<'_>,
        prf_re_randomization_context: &PrfReRandomizationContext,
        streams: &CudaStreams,
    ) -> crate::Result<CudaUnsignedRadixCiphertext> {
        assert!(target_sks.message_modulus.0.is_power_of_two());
        let message_bits_count = target_sks.message_modulus.0.ilog2() as u64;
        let range_bits_count = message_bits_count * num_blocks;
        assert!(range_bits_count > 0);

        assert!(
            random_bits_count <= range_bits_count,
            "The range asked for a random value (=[0, 2^{random_bits_count}[) \
            does not fit in the available range [0, 2^{range_bits_count}[",
        );

        self.generate_oblivious_pseudo_random_bounded_integer_and_re_randomize(
            seed,
            random_bits_count,
            num_blocks,
            target_sks,
            re_randomization_key,
            prf_re_randomization_context,
            streams,
        )
    }

    /// Generates an encrypted `num_block` blocks signed integer
    /// taken uniformly in its full range using the given seed.
    /// The encrypted value is oblivious to the server.
    /// It can be useful to make server random generation deterministic.
    ///
    /// ```rust
    /// use tfhe::core_crypto::gpu::CudaStreams;
    /// use tfhe::core_crypto::gpu::vec::GpuIndex;
    /// use tfhe::integer::gpu::gen_keys_gpu;
    /// use tfhe::integer::gpu::CudaOprfServerKey;
    /// use tfhe::integer::oprf::{CompressedOprfServerKey, OprfPrivateKey};
    /// use tfhe::shortint::parameters::PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
    /// use tfhe::Seed;
    ///
    /// let gpu_index = 0;
    /// let streams = CudaStreams::new_single_gpu(GpuIndex::new(gpu_index));
    /// let size = 4;
    ///
    /// // Generate the client key and the server key:
    /// let (cks, sks) = gen_keys_gpu(PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128, &streams);
    ///
    /// // Generate the OPRF key:
    /// let oprf_pk = OprfPrivateKey::new(&cks);
    /// let compressed_oprf_sk = CompressedOprfServerKey::new(&oprf_pk, &cks).unwrap();
    /// let cuda_oprf_sk = CudaOprfServerKey::decompress_from_cpu(&compressed_oprf_sk, &streams);
    ///
    /// // DANGER: Using a fixed seed is insecure and only done here to show API usage.
    /// // The proper way of generating a seed depends on your application.
    /// let d_ct_res = cuda_oprf_sk.par_generate_oblivious_pseudo_random_signed_integer(Seed(0), size as u64, &sks, &streams);
    /// let ct_res = d_ct_res.to_signed_radix_ciphertext(&streams);
    ///
    /// // Decrypt:
    /// let dec_result: i64 = cks.decrypt_signed_radix(&ct_res);
    /// assert!(dec_result < 1 << (2 * size - 1));
    /// assert!(dec_result >= -(1 << (2 * size - 1)));
    /// ```
    pub fn par_generate_oblivious_pseudo_random_signed_integer(
        &self,
        seed: impl OprfSeed,
        num_blocks: u64,
        target_sks: &CudaServerKey,
        streams: &CudaStreams,
    ) -> CudaSignedRadixCiphertext {
        self.generate_oblivious_pseudo_random_unbounded_integer(
            seed, num_blocks, target_sks, streams,
        )
    }

    pub fn par_generate_oblivious_pseudo_random_signed_integer_and_re_randomize(
        &self,
        seed: impl OprfSeed,
        num_blocks: u64,
        target_sks: &CudaServerKey,
        re_randomization_key: &CudaReRandomizationKey<'_>,
        prf_re_randomization_context: &PrfReRandomizationContext,
        streams: &CudaStreams,
    ) -> crate::Result<CudaSignedRadixCiphertext> {
        self.generate_oblivious_pseudo_random_unbounded_integer_and_re_randomize(
            seed,
            num_blocks,
            target_sks,
            re_randomization_key,
            prf_re_randomization_context,
            streams,
        )
    }

    /// Generates an encrypted `num_block` blocks signed integer
    /// taken uniformly in `[0, 2^random_bits_count[` using the given seed.
    /// The encrypted value is oblivious to the server.
    /// It can be useful to make server random generation deterministic.
    ///
    /// ```rust
    /// use tfhe::core_crypto::gpu::CudaStreams;
    /// use tfhe::core_crypto::gpu::vec::GpuIndex;
    /// use tfhe::integer::gpu::gen_keys_gpu;
    /// use tfhe::integer::gpu::CudaOprfServerKey;
    /// use tfhe::integer::oprf::{CompressedOprfServerKey, OprfPrivateKey};
    /// use tfhe::shortint::parameters::PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
    /// use tfhe::Seed;
    ///
    /// let gpu_index = 0;
    /// let streams = CudaStreams::new_single_gpu(GpuIndex::new(gpu_index));
    /// let size = 4;
    ///
    /// // Generate the client key and the server key:
    /// let (cks, sks) = gen_keys_gpu(PARAM_GPU_MULTI_BIT_GROUP_4_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128, &streams);
    ///
    /// // Generate the OPRF key:
    /// let oprf_pk = OprfPrivateKey::new(&cks);
    /// let compressed_oprf_sk = CompressedOprfServerKey::new(&oprf_pk, &cks).unwrap();
    /// let cuda_oprf_sk = CudaOprfServerKey::decompress_from_cpu(&compressed_oprf_sk, &streams);
    ///
    /// let random_bits_count = 3;
    ///
    /// // DANGER: Using a fixed seed is insecure and only done here to show API usage.
    /// // The proper way of generating a seed depends on your application.
    /// let d_ct_res = cuda_oprf_sk.par_generate_oblivious_pseudo_random_signed_integer_bounded(
    ///     Seed(0),
    ///     random_bits_count,
    ///     size as u64,
    ///     &sks,
    ///     &streams,
    /// );
    /// let ct_res = d_ct_res.to_signed_radix_ciphertext(&streams);
    ///
    /// // Decrypt:
    /// let dec_result: i64 = cks.decrypt_signed_radix(&ct_res);
    /// assert!(dec_result >= 0);
    /// assert!(dec_result < (1 << random_bits_count));
    /// ```
    pub fn par_generate_oblivious_pseudo_random_signed_integer_bounded(
        &self,
        seed: impl OprfSeed,
        random_bits_count: u64,
        num_blocks: u64,
        target_sks: &CudaServerKey,
        streams: &CudaStreams,
    ) -> CudaSignedRadixCiphertext {
        assert!(target_sks.message_modulus.0.is_power_of_two());
        let message_bits_count = target_sks.message_modulus.0.ilog2() as u64;
        let range_bits_count = message_bits_count * num_blocks;
        assert!(range_bits_count > 0);

        {
            let signed_range_bits_count = range_bits_count.saturating_sub(1);
            assert!(
                random_bits_count <= signed_range_bits_count,
                "The range asked for a random value (=[0, 2^{random_bits_count}[) \
                which does not fit in the available range \
                [-2^{signed_range_bits_count}, 2^{signed_range_bits_count}[",
            );
        }

        self.generate_oblivious_pseudo_random_bounded_integer(
            seed,
            random_bits_count,
            num_blocks,
            target_sks,
            streams,
        )
    }

    #[allow(clippy::too_many_arguments)]
    pub fn par_generate_oblivious_pseudo_random_signed_integer_bounded_and_re_randomize(
        &self,
        seed: impl OprfSeed,
        random_bits_count: u64,
        num_blocks: u64,
        target_sks: &CudaServerKey,
        re_randomization_key: &CudaReRandomizationKey<'_>,
        prf_re_randomization_context: &PrfReRandomizationContext,
        streams: &CudaStreams,
    ) -> crate::Result<CudaSignedRadixCiphertext> {
        assert!(target_sks.message_modulus.0.is_power_of_two());
        let message_bits_count = target_sks.message_modulus.0.ilog2() as u64;
        let range_bits_count = message_bits_count * num_blocks;
        assert!(range_bits_count > 0);

        {
            let signed_range_bits_count = range_bits_count.saturating_sub(1);
            assert!(
                random_bits_count <= signed_range_bits_count,
                "The range asked for a random value (=[0, 2^{random_bits_count}[) \
                which does not fit in the available range \
                [-2^{signed_range_bits_count}, 2^{signed_range_bits_count}[",
            );
        }

        self.generate_oblivious_pseudo_random_bounded_integer_and_re_randomize(
            seed,
            random_bits_count,
            num_blocks,
            target_sks,
            re_randomization_key,
            prf_re_randomization_context,
            streams,
        )
    }

    /// Generic internal implementation for unbounded pseudo-random generation.
    /// It calls the core implementation with parameters for the unbounded case.
    fn generate_oblivious_pseudo_random_unbounded_integer<T>(
        &self,
        seed: impl OprfSeed,
        num_blocks: u64,
        target_sks: &CudaServerKey,
        streams: &CudaStreams,
    ) -> T
    where
        T: CudaIntegerRadixCiphertext,
    {
        assert!(target_sks.message_modulus.0.is_power_of_two());

        let message_bits_count = target_sks.message_modulus.0.ilog2() as u64;

        let mut result = target_sks.create_trivial_zero_radix(num_blocks as usize, streams);

        if num_blocks == 0 {
            return result;
        }

        let _random_bits_rle_bytes = self.generate_multiblocks_oblivious_pseudo_random(
            result.as_mut(),
            seed,
            num_blocks,
            num_blocks * message_bits_count,
            target_sks,
            streams,
        );

        result
    }

    /// Same as [`Self::generate_oblivious_pseudo_random_unbounded_integer`] with additional
    /// re-randomization of the output.
    fn generate_oblivious_pseudo_random_unbounded_integer_and_re_randomize<T>(
        &self,
        prf_seed: impl OprfSeed,
        num_blocks: u64,
        target_sks: &CudaServerKey,
        re_randomization_key: &CudaReRandomizationKey<'_>,
        prf_re_randomization_context: &PrfReRandomizationContext,
        streams: &CudaStreams,
    ) -> crate::Result<T>
    where
        T: CudaIntegerRadixCiphertext,
    {
        assert!(target_sks.message_modulus.0.is_power_of_two());

        let message_bits_count = target_sks.message_modulus.0.ilog2() as u64;

        let mut result = target_sks.create_trivial_zero_radix(num_blocks as usize, streams);

        if num_blocks == 0 {
            return Ok(result);
        }

        self.generate_multiblocks_oblivious_pseudo_random_and_re_randomize(
            result.as_mut(),
            prf_seed,
            num_blocks * message_bits_count,
            target_sks,
            re_randomization_key,
            prf_re_randomization_context,
            streams,
        )?;

        Ok(result)
    }

    /// Generic internal implementation for bounded pseudo-random generation.
    /// It calls the core implementation with parameters for the bounded case.
    fn generate_oblivious_pseudo_random_bounded_integer<T>(
        &self,
        seed: impl OprfSeed,
        random_bits_count: u64,
        num_blocks: u64,
        target_sks: &CudaServerKey,
        streams: &CudaStreams,
    ) -> T
    where
        T: CudaIntegerRadixCiphertext,
    {
        assert!(target_sks.message_modulus.0.is_power_of_two());
        let message_bits_count = target_sks.message_modulus.0.ilog2() as u64;
        let num_active_blocks = random_bits_count.div_ceil(message_bits_count);

        let mut result = target_sks.create_trivial_zero_radix(num_blocks as usize, streams);

        assert!(
            num_blocks >= num_active_blocks,
            "Cuda error: num_blocks should be greater than num_blocks_to_process"
        );
        if num_active_blocks == 0 {
            return result;
        }

        let _random_bits_rle_bytes = self.generate_multiblocks_oblivious_pseudo_random(
            result.as_mut(),
            seed,
            num_active_blocks,
            random_bits_count,
            target_sks,
            streams,
        );
        result
    }

    /// Same as [`Self::generate_oblivious_pseudo_random_bounded_integer`] with additional
    /// re-randomization of the output.
    #[allow(clippy::too_many_arguments)]
    fn generate_oblivious_pseudo_random_bounded_integer_and_re_randomize<T>(
        &self,
        seed: impl OprfSeed,
        random_bits_count: u64,
        num_blocks: u64,
        target_sks: &CudaServerKey,
        re_randomization_key: &CudaReRandomizationKey<'_>,
        prf_re_randomization_context: &PrfReRandomizationContext,
        streams: &CudaStreams,
    ) -> crate::Result<T>
    where
        T: CudaIntegerRadixCiphertext,
    {
        assert!(target_sks.message_modulus.0.is_power_of_two());
        let message_bits_count = target_sks.message_modulus.0.ilog2() as u64;
        let num_active_blocks = random_bits_count.div_ceil(message_bits_count);

        // We need the PRF + ReRand to be applied only on the num_active_blocks and later extend
        // with trivial 0s (so that the padding is not re-randed)
        //
        // The multiblocks primitive applies the rerand to all the blocks (there is no
        // "active blocks" rerand primitive currently)
        let mut result = target_sks.create_trivial_zero_radix(num_active_blocks as usize, streams);

        assert!(
            num_blocks >= num_active_blocks,
            "Cuda error: num_blocks should be greater than num_blocks_to_process"
        );
        if num_active_blocks == 0 {
            return Ok(result);
        }

        self.generate_multiblocks_oblivious_pseudo_random_and_re_randomize(
            result.as_mut(),
            seed,
            random_bits_count,
            target_sks,
            re_randomization_key,
            prf_re_randomization_context,
            streams,
        )?;

        if num_blocks == num_active_blocks {
            Ok(result)
        } else {
            // We manually cast to unsigned to be able to extend the ciphertext after PRF +
            // ReRand without sign issues
            let inner_radix = result.into_inner();
            let unsigned_radix =
                <CudaUnsignedRadixCiphertext as CudaIntegerRadixCiphertext>::from(inner_radix);
            let result = target_sks.cast_to_unsigned(unsigned_radix, num_blocks as usize, streams);
            Ok(T::from(result.into_inner()))
        }
    }

    /// Core private implementation that calls the OPRF backend.
    /// This function contains the main logic for both bounded and unbounded generation.
    ///
    /// Caller must ensure total_random_bits is non 0 otherwise this function will panic.
    fn generate_multiblocks_oblivious_pseudo_random(
        &self,
        result: &mut CudaRadixCiphertext,
        seed: impl OprfSeed,
        num_active_blocks: u64,
        total_random_bits: u64,
        target_sks: &CudaServerKey,
        streams: &CudaStreams,
    ) -> RandomBitsRleLeBytes {
        let CudaDynamicKeyswitchingKey::Standard(computing_ks_key) = &target_sks.key_switching_key
        else {
            panic!("Only the standard atomic pattern is supported");
        };

        self.assert_compatible_with_target_bsk(&target_sks.bootstrapping_key);

        let bootstrapping_key = self.bootstrapping_key.borrow();
        let input_lwe_dimension = bootstrapping_key.input_lwe_dimension();
        let polynomial_size = bootstrapping_key.polynomial_size();
        let in_lwe_size = input_lwe_dimension.to_lwe_size();
        let message_bits_count = target_sks.message_modulus.0.ilog2();
        let carry_bits_count = target_sks.carry_modulus.0.ilog2();
        let bits_per_block = message_bits_count + carry_bits_count + 1;

        let (seeded, rle_info) = create_random_from_seed_modulus_switched(
            seed,
            in_lwe_size,
            polynomial_size,
            &[total_random_bits],
            message_bits_count.into(),
            bits_per_block.into(),
        );

        let h_seeded_lwe_list: Vec<u64> = seeded
            .into_iter()
            .flat_map(|(seeded, _bits)| {
                raw_seeded_msed_to_lwe(&seeded, target_sks.ciphertext_modulus).into_container()
            })
            .collect();

        let mut d_seeded_lwe_input =
            unsafe { CudaVec::<u64>::new_async(h_seeded_lwe_list.len(), streams, 0) };
        unsafe {
            d_seeded_lwe_input.copy_from_cpu_async(&h_seeded_lwe_list, streams, 0);
        }

        unsafe {
            match bootstrapping_key {
                CudaBootstrappingKey::Classic(d_bsk) => {
                    cuda_backend_grouped_oprf(
                        streams,
                        result,
                        &d_seeded_lwe_input,
                        num_active_blocks as u32,
                        &d_bsk.d_vec,
                        d_bsk,
                        computing_ks_key.params_ffi(),
                        target_sks.message_modulus,
                        target_sks.carry_modulus,
                        total_random_bits as u32,
                        d_bsk.ms_noise_reduction_configuration.as_ref(),
                    );
                }
                CudaBootstrappingKey::MultiBit(d_bsk) => {
                    cuda_backend_grouped_oprf(
                        streams,
                        result,
                        &d_seeded_lwe_input,
                        num_active_blocks as u32,
                        &d_bsk.d_vec,
                        d_bsk,
                        computing_ks_key.params_ffi(),
                        target_sks.message_modulus,
                        target_sks.carry_modulus,
                        total_random_bits as u32,
                        None,
                    );
                }
            }
        }

        rle_info
    }

    #[allow(clippy::too_many_arguments)]
    fn generate_multiblocks_oblivious_pseudo_random_and_re_randomize(
        &self,
        result: &mut CudaRadixCiphertext,
        prf_seed: impl OprfSeed,
        total_random_bits: u64,
        target_sks: &CudaServerKey,
        re_randomization_key: &CudaReRandomizationKey<'_>,
        prf_re_randomization_context: &PrfReRandomizationContext,
        streams: &CudaStreams,
    ) -> crate::Result<()> {
        let prf_seed = prf_seed.into_bytes();
        let prf_seed = prf_seed.as_ref();

        let num_blocks = result.d_blocks.lwe_ciphertext_count().0 as u64;

        let prf_random_bits_rle_bytes = self.generate_multiblocks_oblivious_pseudo_random(
            result,
            prf_seed,
            num_blocks,
            total_random_bits,
            target_sks,
            streams,
        );

        let rerand_seed = ReRandomizationSeed::new_prf_rerand_seed(
            prf_re_randomization_context.inner(),
            prf_seed,
            &prf_random_bits_rle_bytes,
        );

        result.re_randomize(*re_randomization_key, rerand_seed, streams)
    }

    pub(crate) fn bootstrapping_key(&self) -> &CudaBootstrappingKey<u64> {
        self.bootstrapping_key.borrow()
    }

    /// # Panics
    ///
    /// Panics if:
    /// - `target_sks.message_modulus` is not a power of 2
    /// - `excluded_upper_bound` is a power of 2 use
    ///   [`Self::par_generate_oblivious_pseudo_random_unsigned_integer_bounded`] instead
    /// - `excluded_upper_bound.ilog2() + 1` is greater than the output bit count
    pub fn par_generate_oblivious_pseudo_random_unsigned_custom_range(
        &self,
        seed: impl OprfSeed,
        num_input_random_bits: u64,
        excluded_upper_bound: NonZeroU64,
        num_blocks_output: u64,
        target_sks: &CudaServerKey,
        streams: &CudaStreams,
    ) -> CudaUnsignedRadixCiphertext {
        self.par_generate_oblivious_pseudo_random_unsigned_custom_range_impl(
            seed,
            num_input_random_bits,
            excluded_upper_bound,
            num_blocks_output,
            target_sks,
            streams,
            |result,
             num_blocks_intermediate,
             d_seeded_lwe_input,
             decomposed_scalar,
             has_at_least_one_set,
             shift,
             computing_ks_key,
             _prf_seed,
             _rle_info| {
                // SAFETY: all device buffers referenced below outlive the backend call, and this
                // closure holds exclusive access to `result`.
                unsafe {
                    self.dispatch_custom_range_oprf(
                        streams,
                        result,
                        num_blocks_intermediate,
                        d_seeded_lwe_input,
                        decomposed_scalar,
                        has_at_least_one_set,
                        shift,
                        computing_ks_key,
                        target_sks,
                        false,
                        None,
                        None,
                    );
                }
                Ok(())
            },
        )
        .unwrap()
    }

    #[allow(clippy::too_many_arguments)]
    pub fn par_generate_oblivious_pseudo_random_unsigned_custom_range_and_re_randomize(
        &self,
        seed: impl OprfSeed,
        num_input_random_bits: u64,
        excluded_upper_bound: NonZeroU64,
        num_blocks_output: u64,
        target_sks: &CudaServerKey,
        re_randomization_key: &CudaReRandomizationKey<'_>,
        prf_re_randomization_context: &PrfReRandomizationContext,
        streams: &CudaStreams,
    ) -> crate::Result<CudaUnsignedRadixCiphertext> {
        let message_bits_count: u64 = target_sks.message_modulus.0.ilog2().into();
        self.par_generate_oblivious_pseudo_random_unsigned_custom_range_impl(
            seed,
            num_input_random_bits,
            excluded_upper_bound,
            num_blocks_output,
            target_sks,
            streams,
            |result,
             num_blocks_intermediate,
             d_seeded_lwe_input,
             decomposed_scalar,
             has_at_least_one_set,
             shift,
             computing_ks_key,
             prf_seed,
             rle_info| {
                let radix_block_lwe_size = result.d_blocks.lwe_dimension().to_lwe_size();
                let (compact_public_key, rerand_keyswitch_key) = match *re_randomization_key {
                    CudaReRandomizationKey::LegacyDedicatedCPK { cpk, ksk } => {
                        let lwe_keyswitch_key = &ksk.lwe_keyswitch_key;
                        if lwe_keyswitch_key.output_key_lwe_size() != radix_block_lwe_size {
                            return Err(crate::error!(
                                "Mismatched LweSize between the ciphertext being re-randomized \
                                and the provided re-randomization keyswitch key output."
                            ));
                        }
                        if lwe_keyswitch_key.input_key_lwe_size()
                            != cpk.parameters().encryption_lwe_dimension.to_lwe_size()
                        {
                            return Err(crate::error!(
                                "Mismatched LweDimension between the provided CompactPublicKey \
                                and the re-randomization keyswitch key input."
                            ));
                        }
                        if ksk.destination_key.into_pbs_order() != PBSOrder::KeyswitchBootstrap {
                            return Err(crate::error!(
                                "Tried to re-randomize with a re-randomization keyswitch key \
                                whose destination key uses an unsupported PBSOrder. Required \
                                PBSOrder::KeyswitchBootstrap."
                            ));
                        }
                        if ksk.cast_rshift != 0 {
                            return Err(crate::error!(
                                "Tried to re-randomize with a re-randomization keyswitch key that \
                                has a non-zero cast_rshift, this is unsupported."
                            ));
                        }
                        (cpk, Some(lwe_keyswitch_key))
                    }
                    CudaReRandomizationKey::DerivedCPKWithoutKeySwitch { cpk } => {
                        if cpk.key.key.lwe_dimension().to_lwe_size() != radix_block_lwe_size {
                            return Err(crate::error!(
                                "Mismatched LweSize between the ciphertext being re-randomized \
                                and the provided CompactPublicKey."
                            ));
                        }
                        (cpk, None)
                    }
                };

                let num_random_input_blocks = (shift as u64).div_ceil(message_bits_count);
                let rerand_seed = ReRandomizationSeed::new_prf_rerand_seed(
                    prf_re_randomization_context.inner(),
                    prf_seed,
                    rle_info,
                );
                let encryption_of_zero = compact_public_key.key.prepare_cpk_zero_for_rerand(
                    rerand_seed,
                    LweCiphertextCount(num_random_input_blocks as usize),
                );
                let d_zero_lwes = CudaLweCompactCiphertextList::from_lwe_compact_ciphertext_list(
                    &encryption_of_zero,
                    streams,
                );

                // SAFETY: all device buffers referenced below outlive the backend call, and this
                // closure holds exclusive access to `result`.
                unsafe {
                    self.dispatch_custom_range_oprf(
                        streams,
                        result,
                        num_blocks_intermediate,
                        d_seeded_lwe_input,
                        decomposed_scalar,
                        has_at_least_one_set,
                        shift,
                        computing_ks_key,
                        target_sks,
                        true,
                        Some(&d_zero_lwes),
                        rerand_keyswitch_key,
                    );
                }
                Ok(())
            },
        )
    }

    #[allow(clippy::too_many_arguments)]
    fn par_generate_oblivious_pseudo_random_unsigned_custom_range_impl(
        &self,
        seed: impl OprfSeed,
        num_input_random_bits: u64,
        excluded_upper_bound: NonZeroU64,
        num_blocks_output: u64,
        target_sks: &CudaServerKey,
        streams: &CudaStreams,
        prf_dispatch: impl FnOnce(
            &mut CudaRadixCiphertext,
            u32,
            &CudaVec<u64>,
            &[u64],
            &[u64],
            u32,
            &CudaLweKeyswitchKey<u64>,
            &[u8],
            &RandomBitsRleLeBytes,
        ) -> crate::Result<()>,
    ) -> crate::Result<CudaUnsignedRadixCiphertext> {
        assert!(
            target_sks.message_modulus.0.is_power_of_two(),
            "Message modulus must be a power of two"
        );
        assert!(
            target_sks.carry_modulus.0.is_power_of_two(),
            "Carry modulus must be a power of two"
        );
        let message_bits_count: u64 = target_sks.message_modulus.0.ilog2().into();
        let carry_bits_count: u64 = target_sks.carry_modulus.0.ilog2().into();
        let bits_per_block = message_bits_count + carry_bits_count + 1;

        assert!(
            !excluded_upper_bound.is_power_of_two(),
            "Use the cheaper par_generate_oblivious_pseudo_random_unsigned_integer_bounded \
            function instead"
        );

        let num_bits_output = num_blocks_output * message_bits_count;
        let excluded_upper_bound_ceil_log2 = u64::BITS - excluded_upper_bound.leading_zeros();
        assert!(
            u64::from(excluded_upper_bound_ceil_log2) <= num_bits_output,
            "num_blocks_output(={num_blocks_output}) is too small to hold an integer \
            up to excluded_upper_bound(={excluded_upper_bound})"
        );

        let CudaDynamicKeyswitchingKey::Standard(computing_ks_key) = &target_sks.key_switching_key
        else {
            panic!("Only the standard atomic pattern is supported");
        };

        self.assert_compatible_with_target_bsk(&target_sks.bootstrapping_key);

        let bootstrapping_key = self.bootstrapping_key.borrow();
        let input_lwe_dimension = bootstrapping_key.input_lwe_dimension();
        let polynomial_size = bootstrapping_key.polynomial_size();
        let in_lwe_size = input_lwe_dimension.to_lwe_size();

        let post_mul_num_bits = num_input_random_bits + u64::from(excluded_upper_bound.ilog2()) + 1;
        let num_blocks_intermediate = post_mul_num_bits.div_ceil(message_bits_count);

        let decomposer =
            BlockDecomposer::with_early_stop_at_zero(excluded_upper_bound.get(), 1).iter_as::<u8>();
        let mut has_at_least_one_set = vec![0u64; message_bits_count as usize];
        for (i, bit) in decomposer.collect_vec().iter().copied().enumerate() {
            if bit == 1 {
                has_at_least_one_set[i % message_bits_count as usize] = 1;
            }
        }
        let decomposed_scalar =
            BlockDecomposer::with_early_stop_at_zero(excluded_upper_bound.get(), 1)
                .iter_as::<u64>()
                .collect::<Vec<_>>();

        let seed_bytes = seed.into_bytes();
        let prf_seed: &[u8] = seed_bytes.as_ref();

        let (seeded, rle_info) = create_random_from_seed_modulus_switched(
            prf_seed,
            in_lwe_size,
            polynomial_size,
            &[num_input_random_bits],
            message_bits_count,
            bits_per_block,
        );

        let h_seeded_lwe_list: Vec<u64> = seeded
            .into_iter()
            .flat_map(|(seeded, _bits)| {
                raw_seeded_msed_to_lwe(&seeded, target_sks.ciphertext_modulus).into_container()
            })
            .collect();

        let mut d_seeded_lwe_input =
            unsafe { CudaVec::<u64>::new_async(h_seeded_lwe_list.len(), streams, 0) };
        unsafe { d_seeded_lwe_input.copy_from_cpu_async(&h_seeded_lwe_list, streams, 0) };
        streams.synchronize();

        let mut result: CudaUnsignedRadixCiphertext =
            target_sks.create_trivial_zero_radix(num_blocks_output as usize, streams);

        prf_dispatch(
            result.as_mut(),
            num_blocks_intermediate as u32,
            &d_seeded_lwe_input,
            decomposed_scalar.as_slice(),
            has_at_least_one_set.as_slice(),
            num_input_random_bits as u32,
            computing_ks_key,
            prf_seed,
            &rle_info,
        )?;

        Ok(result)
    }

    /// # Safety
    ///
    /// All device buffers referenced by `self`, `target_sks`, `computing_ks_key`, the input
    /// arguments, and `zero_lwes`/`rerand_keyswitch_key` must remain alive and unmodified for the
    /// duration of the backend call.
    #[allow(clippy::too_many_arguments)]
    unsafe fn dispatch_custom_range_oprf(
        &self,
        streams: &CudaStreams,
        result: &mut CudaRadixCiphertext,
        num_blocks_intermediate: u32,
        d_seeded_lwe_input: &CudaVec<u64>,
        decomposed_scalar: &[u64],
        has_at_least_one_set: &[u64],
        num_input_random_bits: u32,
        computing_ks_key: &CudaLweKeyswitchKey<u64>,
        target_sks: &CudaServerKey,
        apply_rerand: bool,
        zero_lwes: Option<&CudaLweCompactCiphertextList<u64>>,
        rerand_keyswitch_key: Option<&CudaLweKeyswitchKey<u64>>,
    ) {
        match (
            self.bootstrapping_key.borrow(),
            &target_sks.bootstrapping_key,
        ) {
            (
                CudaBootstrappingKey::Classic(d_bsk),
                CudaBootstrappingKey::Classic(compute_d_bsk),
            ) => {
                cuda_backend_grouped_oprf_custom_range(
                    streams,
                    result,
                    num_blocks_intermediate,
                    d_seeded_lwe_input,
                    decomposed_scalar,
                    has_at_least_one_set,
                    num_input_random_bits,
                    &d_bsk.d_vec,
                    &compute_d_bsk.d_vec,
                    &computing_ks_key.d_vec,
                    d_bsk,
                    computing_ks_key.params_ffi(),
                    target_sks.message_modulus,
                    target_sks.carry_modulus,
                    d_bsk.ms_noise_reduction_configuration.as_ref(),
                    apply_rerand,
                    zero_lwes,
                    rerand_keyswitch_key,
                );
            }
            (
                CudaBootstrappingKey::MultiBit(d_bsk),
                CudaBootstrappingKey::MultiBit(compute_d_bsk),
            ) => {
                cuda_backend_grouped_oprf_custom_range(
                    streams,
                    result,
                    num_blocks_intermediate,
                    d_seeded_lwe_input,
                    decomposed_scalar,
                    has_at_least_one_set,
                    num_input_random_bits,
                    &d_bsk.d_vec,
                    &compute_d_bsk.d_vec,
                    &computing_ks_key.d_vec,
                    d_bsk,
                    computing_ks_key.params_ffi(),
                    target_sks.message_modulus,
                    target_sks.carry_modulus,
                    None,
                    apply_rerand,
                    zero_lwes,
                    rerand_keyswitch_key,
                );
            }
            (_, _) => {
                panic!("OPRF and compute bootstrapping keys must have matching types");
            }
        }
    }

    /// Getter for the GPU memory usage of OPRF.
    pub fn get_par_generate_oblivious_pseudo_random_unsigned_integer_size_on_gpu(
        &self,
        target_sks: &CudaServerKey,
        streams: &CudaStreams,
    ) -> u64 {
        let message_bits = target_sks.message_modulus.0.ilog2();
        let CudaDynamicKeyswitchingKey::Standard(computing_ks_key) = &target_sks.key_switching_key
        else {
            panic!("Only the standard atomic pattern is supported");
        };

        match &self.bootstrapping_key.borrow() {
            CudaBootstrappingKey::Classic(d_bsk) => cuda_backend_get_grouped_oprf_size_on_gpu(
                streams,
                1,
                d_bsk,
                computing_ks_key.params_ffi(),
                target_sks.message_modulus,
                target_sks.carry_modulus,
                message_bits,
                d_bsk.ms_noise_reduction_configuration.as_ref(),
            ),
            CudaBootstrappingKey::MultiBit(d_bsk) => cuda_backend_get_grouped_oprf_size_on_gpu(
                streams,
                1,
                d_bsk,
                computing_ks_key.params_ffi(),
                target_sks.message_modulus,
                target_sks.carry_modulus,
                message_bits,
                None,
            ),
        }
    }

    pub fn get_par_generate_oblivious_pseudo_random_unsigned_integer_bounded_size_on_gpu(
        &self,
        target_sks: &CudaServerKey,
        streams: &CudaStreams,
    ) -> u64 {
        self.get_par_generate_oblivious_pseudo_random_unsigned_integer_size_on_gpu(
            target_sks, streams,
        )
    }

    pub fn get_par_generate_oblivious_pseudo_random_signed_integer_size_on_gpu(
        &self,
        target_sks: &CudaServerKey,
        streams: &CudaStreams,
    ) -> u64 {
        self.get_par_generate_oblivious_pseudo_random_unsigned_integer_size_on_gpu(
            target_sks, streams,
        )
    }

    pub fn get_par_generate_oblivious_pseudo_random_signed_integer_bounded_size_on_gpu(
        &self,
        target_sks: &CudaServerKey,
        streams: &CudaStreams,
    ) -> u64 {
        self.get_par_generate_oblivious_pseudo_random_unsigned_integer_size_on_gpu(
            target_sks, streams,
        )
    }
}