From 89f9ee229ff908463fe0b35f7ef03aa32839f9fc Mon Sep 17 00:00:00 2001 From: dsuponitskiy <28961198+dsuponitskiy@users.noreply.github.com> Date: Mon, 20 Apr 2026 11:15:10 -0400 Subject: [PATCH 1/3] Replaced usint with uint32_t, usshort with uint16_t and uschar with uint8_t and removed their aliases from inttypes.h (#1168) * Remove usshort and uschar from inttypes.h and replaced their usage with uint16_t and uint8_t * Removed usint from inttypes.h and replaced its usage with uint32_t * Pass integer parameter by value to function instead of by constant reference --------- Co-authored-by: Dmitriy Suponitskiy --- benchmark/src/IntegerMath.cpp | 12 +- benchmark/src/NbTheory.cpp | 24 +- benchmark/src/bfv-mult-method-benchmark.cpp | 8 +- .../src/ckks-functional-bootstrapping.cpp | 2 +- .../src/compare-bfv-hps-leveled-vs-behz.cpp | 26 +- benchmark/src/compare-bfvrns-vs-bgvrns.cpp | 14 +- benchmark/src/lib-benchmark.cpp | 56 ++-- benchmark/src/mult-vs-square.cpp | 66 ++-- src/binfhe/lib/rgsw-acc-lmkcdey.cpp | 8 +- src/core/extras/math.cpp | 12 +- src/core/extras/ntt1.cpp | 8 +- src/core/extras/ntt2.cpp | 14 +- src/core/include/lattice/dgsampling-impl.h | 4 +- src/core/include/lattice/field2n.h | 2 +- .../include/lattice/hal/dcrtpoly-interface.h | 38 +-- .../lattice/hal/default/dcrtpoly-impl.h | 4 +- .../include/lattice/hal/default/dcrtpoly.h | 14 +- .../include/lattice/hal/default/poly-impl.h | 32 +- src/core/include/lattice/hal/default/poly.h | 20 +- src/core/include/lattice/hal/poly-interface.h | 18 +- src/core/include/lattice/ilelement.h | 16 +- src/core/include/lattice/stdlatticeparms.h | 22 +- src/core/include/lattice/trapdoorparameters.h | 4 +- .../math/binaryuniformgenerator-impl.h | 4 +- .../include/math/binaryuniformgenerator.h | 2 +- .../include/math/hal/bigintdyn/mubintvecdyn.h | 28 +- .../math/hal/bigintdyn/transformdyn-impl.h | 232 ++++++------- .../include/math/hal/bigintdyn/transformdyn.h | 48 +-- .../include/math/hal/bigintdyn/ubintdyn.h | 44 +-- .../include/math/hal/bigintfxd/mubintvecfxd.h | 22 +- .../math/hal/bigintfxd/transformfxd-impl.h | 232 ++++++------- .../include/math/hal/bigintfxd/transformfxd.h | 48 +-- .../include/math/hal/bigintfxd/ubintfxd.h | 72 ++-- .../include/math/hal/bigintntl/mubintvecntl.h | 24 +- .../math/hal/bigintntl/transformntl-impl.h | 232 ++++++------- .../include/math/hal/bigintntl/transformntl.h | 48 +-- .../include/math/hal/bigintntl/ubintntl.h | 34 +- src/core/include/math/hal/integer.h | 22 +- .../include/math/hal/intnat/mubintvecnat.h | 16 +- .../include/math/hal/intnat/transformnat.h | 48 +-- src/core/include/math/hal/intnat/ubintnat.h | 40 +-- src/core/include/math/hal/transform.h | 28 +- src/core/include/math/hal/vector.h | 8 +- src/core/include/math/matrix.h | 2 +- src/core/include/math/nbtheory-impl.h | 60 ++-- src/core/include/math/nbtheory.h | 22 +- .../include/utils/blockAllocator/xvector.h | 4 +- src/core/include/utils/inttypes.h | 15 - src/core/lib/lattice/stdlatticeparms.cpp | 4 +- src/core/lib/math/dftransform.cpp | 26 +- .../math/discretegaussiangeneratorgeneric.cpp | 4 +- .../lib/math/hal/bigintdyn/be4-math-impl.cpp | 10 +- .../lib/math/hal/bigintdyn/mubintvecdyn.cpp | 6 +- src/core/lib/math/hal/bigintdyn/ubintdyn.cpp | 56 ++-- .../lib/math/hal/bigintfxd/be2-math-impl.cpp | 10 +- .../lib/math/hal/bigintfxd/mubintvecfxd.cpp | 56 ++-- src/core/lib/math/hal/bigintfxd/ubintfxd.cpp | 308 +++++++++--------- .../lib/math/hal/bigintntl/be6-math-impl.cpp | 10 +- .../lib/math/hal/bigintntl/mubintvecntl.cpp | 14 +- src/core/lib/math/hal/bigintntl/ubintntl.cpp | 42 +-- .../math/hal/intnat/benative-math-impl.cpp | 12 +- src/core/lib/math/nbtheory2.cpp | 52 +-- src/core/unittest/UnitTest128.cpp | 4 +- src/core/unittest/UnitTestBinInt.cpp | 16 +- src/core/unittest/UnitTestBinVect.cpp | 38 +-- src/core/unittest/UnitTestDistrGen.cpp | 68 ++-- src/core/unittest/UnitTestMatrix.cpp | 6 +- src/core/unittest/UnitTestMubintvec.cpp | 28 +- src/core/unittest/UnitTestNTT.cpp | 10 +- src/core/unittest/UnitTestNbTheory.cpp | 28 +- src/core/unittest/UnitTestTransform.cpp | 46 +-- src/core/unittest/UnitTestTrapdoor.cpp | 72 ++-- src/core/unittest/UnitTestUtils.cpp | 4 +- .../examples/advanced-ckks-bootstrapping.cpp | 12 +- src/pke/examples/ckks-noise-flooding.cpp | 6 +- src/pke/examples/function-evaluation.cpp | 16 +- .../functional-bootstrapping-ckks.cpp | 16 +- .../examples/interactive-bootstrapping.cpp | 2 +- ...e-ckks-bootstrapping-composite-scaling.cpp | 12 +- src/pke/examples/linearwsum-evaluation.cpp | 6 +- src/pke/examples/rotation.cpp | 2 +- src/pke/examples/scheme-switching.cpp | 4 +- .../examples/simple-real-numbers-serial.cpp | 2 +- ...interactive-mp-bootstrapping-Chebyshev.cpp | 14 +- .../tckks-interactive-mp-bootstrapping.cpp | 22 +- src/pke/examples/threshold-fhe-5p.cpp | 12 +- src/pke/examples/threshold-fhe.cpp | 8 +- .../bfv-encode-vs-ptxt-ctxt-benchmark.cpp.cpp | 2 +- src/pke/extras/bfv-mult-bug.cpp | 6 +- src/pke/extras/ckks-bootstrap.cpp | 20 +- .../scheme/bfvrns/bfvrns-cryptoparameters.h | 4 +- .../scheme/bgvrns/bgvrns-cryptoparameters.h | 4 +- .../gen-cryptocontext-ckksrns-internal.h | 4 +- src/pke/include/schemebase/base-multiparty.h | 26 +- .../lib/scheme/bfvrns/bfvrns-multiparty.cpp | 4 +- src/pke/lib/scheme/bfvrns/bfvrns-pke.cpp | 4 +- .../scheme/bgvrns/bgvrns-cryptoparameters.cpp | 16 +- src/pke/lib/scheme/bgvrns/bgvrns-pke.cpp | 2 +- .../ckksrns/ckksrns-cryptoparameters.cpp | 2 +- .../scheme/gen-cryptocontext-params-impl.cpp | 32 +- .../gen-cryptocontext-params-validation.cpp | 2 +- src/pke/lib/schemebase/base-advancedshe.cpp | 62 ++-- .../lib/schemerns/rns-cryptoparameters.cpp | 12 +- src/pke/lib/schemerns/rns-multiparty.cpp | 24 +- src/pke/unittest/UnitTestENCRYPT.cpp | 4 +- src/pke/unittest/UnitTestEvalMult.cpp | 12 +- src/pke/unittest/UnitTestPRE.cpp | 8 +- src/pke/unittest/UnitTestSHE.cpp | 12 +- src/pke/unittest/utbfvrns/UnitTestBFVrns.cpp | 4 +- .../utbfvrns/UnitTestBFVrnsAutomorphism.cpp | 10 +- .../utbfvrns/UnitTestBFVrnsCRTOperations.cpp | 16 +- .../utbfvrns/UnitTestBFVrnsDecrypt.cpp | 18 +- src/pke/unittest/utbgvrns/UnitTestBGVrns.cpp | 34 +- .../utbgvrns/UnitTestBGVrnsAdvancedSHE.cpp | 6 +- .../utbgvrns/UnitTestBGVrnsAutomorphism.cpp | 6 +- .../utbgvrns/UnitTestBGVrnsSerialize.cpp | 14 +- .../unittest/utckksrns/UnitTestCKKSrns.cpp | 22 +- .../utckksrns/UnitTestCKKSrnsAutomorphism.cpp | 10 +- .../UnitTestCKKSrnsCompositeScaling.cpp | 22 +- ...itTestCKKSrnsCompositeScalingBootstrap.cpp | 4 +- .../utckksrns/UnitTestCKKSrnsSerialize.cpp | 10 +- src/pke/unittest/utckksrns/UnitTestFBT.cpp | 24 +- 122 files changed, 1635 insertions(+), 1650 deletions(-) diff --git a/benchmark/src/IntegerMath.cpp b/benchmark/src/IntegerMath.cpp index eeeb5ba45..ecf7f8e65 100644 --- a/benchmark/src/IntegerMath.cpp +++ b/benchmark/src/IntegerMath.cpp @@ -187,7 +187,7 @@ static void BM_BigInt_DividedByEq(benchmark::State& state) { } template -static void exp_BigInt(const I& a, const usint& b) { +static void exp_BigInt(const I& a, uint32_t b) { __attribute__((unused)) I c1 = a.Exp(b); } @@ -199,7 +199,7 @@ static void BM_BigInt_Exp(benchmark::State& state) { } template -static void expeq_BigInt(I a, const usint& b) { +static void expeq_BigInt(I a, uint32_t b) { a.ExpEq(b); } @@ -239,7 +239,7 @@ static void BM_BigInt_MultiplyAndRoundEq(benchmark::State& state) { } template -static void lshift_BigInt(const I& a, const usshort& b) { +static void lshift_BigInt(const I& a, uint16_t b) { __attribute__((unused)) I c1 = a.LShift(b); } @@ -251,7 +251,7 @@ static void BM_BigInt_LShift(benchmark::State& state) { } template -static void lshifteq_BigInt(I a, const usshort& b) { +static void lshifteq_BigInt(I a, uint16_t b) { a.LShiftEq(b); } @@ -263,7 +263,7 @@ static void BM_BigInt_LShiftEq(benchmark::State& state) { } template -static void rshift_BigInt(const I& a, const usshort& b) { +static void rshift_BigInt(const I& a, uint16_t b) { __attribute__((unused)) I c1 = a.RShift(b); } @@ -275,7 +275,7 @@ static void BM_BigInt_RShift(benchmark::State& state) { } template -static void rshifteq_BigInt(I a, const usshort& b) { +static void rshifteq_BigInt(I a, uint16_t b) { a.RShiftEq(b); } diff --git a/benchmark/src/NbTheory.cpp b/benchmark/src/NbTheory.cpp index bafd72bdc..51514fc30 100644 --- a/benchmark/src/NbTheory.cpp +++ b/benchmark/src/NbTheory.cpp @@ -191,8 +191,8 @@ BENCHMARK(BM_FACT1); // register benchmark // Prime Modulus tests // static BigInteger PM_foundPrimeModulus(void) { - const usint m = 2048; - const usint nBits = 30; + const uint32_t m = 2048; + const uint32_t nBits = 30; return lbcrypto::FirstPrime(nBits, m); } @@ -215,8 +215,8 @@ BENCHMARK(BM_PM1); // register benchmark // note this returns a refrence to BBI static BigInteger& PM_returns_higher_bit_length(void) { - usint m = 4096; - usint nBits = 49; + uint32_t m = 4096; + uint32_t nBits = 49; BigInteger primeModulus = lbcrypto::FirstPrime(nBits, m); return primeModulus; @@ -240,8 +240,8 @@ BENCHMARK(BM_PM2); // register benchmark // Note this benchmark returns two BBIs so we return a string and suffer // some overhead static std::string PROU_equals_m_not_equals_mbytwo(void) { - usint m = 4096; - usint nBits = 33; + uint32_t m = 4096; + uint32_t nBits = 33; BigInteger primeModulus = lbcrypto::FirstPrime(nBits, m); BigInteger primitiveRootOfUnity = lbcrypto::RootOfUnity(m, primeModulus); @@ -268,9 +268,9 @@ BENCHMARK(BM_PROU1); // register benchmark #if 0 // this takes a long time to run so comment out for quick check // similarly this outputs 3 values with a string static std::string PROU_equals_m_not_equals_mbytwo_mbyfour_single_input(void) { - const usint n = 2048; - const usint m = 2*n; - const usint nBits = 43; + const uint32_t n = 2048; + const uint32_t m = 2*n; + const uint32_t nBits = 43; const int ITERATIONS = m*2; BigInteger M(std::to_string(m)), @@ -312,7 +312,7 @@ BENCHMARK(BM_PROU2); // similarly this outputs 3 values with a string static std::string PROU_equals_m_not_equals_mbytwo_mbyfour_multiple_inputs(void) { - usint nqBitsArray[] = { + uint32_t nqBitsArray[] = { 1, 1, 2, @@ -329,7 +329,7 @@ static std::string PROU_equals_m_not_equals_mbytwo_mbyfour_multiple_inputs(void) 40, 2048, 41 - // const usint BIT_LENGTH = 200 and const usint FRAGMENTATION_FACTOR = 27 + // const uint32_t BIT_LENGTH = 200 and const uint32_t FRAGMENTATION_FACTOR = 27 // ,2048, 51 , 4096, @@ -358,7 +358,7 @@ static std::string PROU_equals_m_not_equals_mbytwo_mbyfour_multiple_inputs(void) }; int length = sizeof(nqBitsArray) / sizeof(nqBitsArray[0]); - usint n, qBits, m; + uint32_t n, qBits, m; BigInteger wpowerm("0"); BigInteger wpowermbytwo("0"); BigInteger wpowermbyfour("0"); diff --git a/benchmark/src/bfv-mult-method-benchmark.cpp b/benchmark/src/bfv-mult-method-benchmark.cpp index 488af35a4..187daa1f4 100644 --- a/benchmark/src/bfv-mult-method-benchmark.cpp +++ b/benchmark/src/bfv-mult-method-benchmark.cpp @@ -50,10 +50,10 @@ using namespace lbcrypto; -constexpr usint RING_DIM = 16384; -constexpr usint MULT_DEPTH = 7; -constexpr usint PTM = 2; -constexpr usint DCRT_BITS = 60; +constexpr uint32_t RING_DIM = 16384; +constexpr uint32_t MULT_DEPTH = 7; +constexpr uint32_t PTM = 2; +constexpr uint32_t DCRT_BITS = 60; constexpr KeySwitchTechnique KS_TECH = BV; static std::vector MULT_METHOD_ARGS = {BEHZ, HPS, HPSPOVERQ, HPSPOVERQLEVELED}; diff --git a/benchmark/src/ckks-functional-bootstrapping.cpp b/benchmark/src/ckks-functional-bootstrapping.cpp index 3fd584863..b9f2a4bce 100644 --- a/benchmark/src/ckks-functional-bootstrapping.cpp +++ b/benchmark/src/ckks-functional-bootstrapping.cpp @@ -338,7 +338,7 @@ struct fbt_config { auto exact(x); std::transform(x.begin(), x.end(), exact.begin(), - [&](const int64_t& elem) { return (elem >= t.PInput.ConvertToDouble() / 2.); }); + [&](int64_t elem) { return (elem >= t.PInput.ConvertToDouble() / 2.); }); std::vector coeffintMod; std::vector> coeffcompMod; diff --git a/benchmark/src/compare-bfv-hps-leveled-vs-behz.cpp b/benchmark/src/compare-bfv-hps-leveled-vs-behz.cpp index 118f9c5f4..63e86e7aa 100644 --- a/benchmark/src/compare-bfv-hps-leveled-vs-behz.cpp +++ b/benchmark/src/compare-bfv-hps-leveled-vs-behz.cpp @@ -50,23 +50,23 @@ using namespace lbcrypto; -usint mult_depth = 3; -static std::vector ptm_args{2, 65537}; -static std::vector dcrtbit_args{30, 60}; -static std::vector logn_args{12, 14}; +uint32_t mult_depth = 3; +static std::vector ptm_args{2, 65537}; +static std::vector dcrtbit_args{30, 60}; +static std::vector logn_args{12, 14}; static void MultBFVArguments(benchmark::internal::Benchmark* b) { - for (usint ptm : ptm_args) { - for (usint dcrtbit : dcrtbit_args) { + for (uint32_t ptm : ptm_args) { + for (uint32_t dcrtbit : dcrtbit_args) { b->ArgNames({"ptm", "dcrtbit"})->Args({ptm, dcrtbit})->MinTime(10.0); } } } static void DecBFVArguments(benchmark::internal::Benchmark* b) { - for (usint ptm : ptm_args) { - for (usint dcrtbit : dcrtbit_args) { - for (usint logn : logn_args) { + for (uint32_t ptm : ptm_args) { + for (uint32_t dcrtbit : dcrtbit_args) { + for (uint32_t logn : logn_args) { b->ArgNames({"ptm", "dcrtbit", "logn"})->Args({ptm, dcrtbit, logn}); } } @@ -77,7 +77,7 @@ static void DecBFVArguments(benchmark::internal::Benchmark* b) { * Context setup utility methods */ -CryptoContext GenerateBFVrnsContext(usint ptm, usint dcrtBits) { +CryptoContext GenerateBFVrnsContext(uint32_t ptm, uint32_t dcrtBits) { CCParams parameters; parameters.SetPlaintextModulus(ptm); parameters.SetMultiplicativeDepth(mult_depth); @@ -93,7 +93,7 @@ CryptoContext GenerateBFVrnsContext(usint ptm, usint dcrtBits) { return cc; } -CryptoContext GenerateBEHZContext(usint ptm, usint dcrtBits) { +CryptoContext GenerateBEHZContext(uint32_t ptm, uint32_t dcrtBits) { CCParams parameters; parameters.SetPlaintextModulus(ptm); parameters.SetMultiplicativeDepth(mult_depth); @@ -109,7 +109,7 @@ CryptoContext GenerateBEHZContext(usint ptm, usint dcrtBits) { return cc; } -CryptoContext GenerateFlatBFVrnsContext(usint ptm, usint dcrtBits, usint n) { +CryptoContext GenerateFlatBFVrnsContext(uint32_t ptm, uint32_t dcrtBits, uint32_t n) { CCParams parameters; parameters.SetPlaintextModulus(ptm); parameters.SetMaxRelinSkDeg(0); @@ -124,7 +124,7 @@ CryptoContext GenerateFlatBFVrnsContext(usint ptm, usint dcrtBits, usi return cc; } -CryptoContext GenerateFlatBEHZContext(usint ptm, usint dcrtBits, usint n) { +CryptoContext GenerateFlatBEHZContext(uint32_t ptm, uint32_t dcrtBits, uint32_t n) { CCParams parameters; parameters.SetPlaintextModulus(ptm); parameters.SetMaxRelinSkDeg(0); diff --git a/benchmark/src/compare-bfvrns-vs-bgvrns.cpp b/benchmark/src/compare-bfvrns-vs-bgvrns.cpp index e2ee2dfa8..c2a5a0e93 100644 --- a/benchmark/src/compare-bfvrns-vs-bgvrns.cpp +++ b/benchmark/src/compare-bfvrns-vs-bgvrns.cpp @@ -51,12 +51,12 @@ using namespace lbcrypto; -usint mult_depth = 3; +uint32_t mult_depth = 3; /* * Context setup utility methods */ -CryptoContext GenerateBFVrnsContext(usint ptm) { +CryptoContext GenerateBFVrnsContext(uint32_t ptm) { CCParams parameters; parameters.SetPlaintextModulus(ptm); parameters.SetMultiplicativeDepth(mult_depth); @@ -73,7 +73,7 @@ CryptoContext GenerateBFVrnsContext(usint ptm) { return cc; } -CryptoContext GenerateBGVrnsContext(usint ptm) { +CryptoContext GenerateBGVrnsContext(uint32_t ptm) { CCParams parameters; parameters.SetMultiplicativeDepth(mult_depth); parameters.SetPlaintextModulus(ptm); @@ -93,7 +93,7 @@ CryptoContext GenerateBGVrnsContext(usint ptm) { * BFVrns benchmarks */ void BFVrns_EvalMultManyP2(benchmark::State& state) { - usint ptm = 2; + uint32_t ptm = 2; CryptoContext cc = GenerateBFVrnsContext(ptm); @@ -126,7 +126,7 @@ void BFVrns_EvalMultManyP2(benchmark::State& state) { BENCHMARK(BFVrns_EvalMultManyP2)->Unit(benchmark::kMicrosecond)->MinTime(10.0); void BGVrns_EvalMultManyP2(benchmark::State& state) { - usint ptm = 2; + uint32_t ptm = 2; CryptoContext cc = GenerateBGVrnsContext(ptm); @@ -163,7 +163,7 @@ BENCHMARK(BGVrns_EvalMultManyP2)->Unit(benchmark::kMicrosecond)->MinTime(10.0); */ void BFVrns_EvalMultManyP65537(benchmark::State& state) { - usint ptm = 65537; + uint32_t ptm = 65537; CryptoContext cc = GenerateBFVrnsContext(ptm); @@ -196,7 +196,7 @@ void BFVrns_EvalMultManyP65537(benchmark::State& state) { BENCHMARK(BFVrns_EvalMultManyP65537)->Unit(benchmark::kMicrosecond)->MinTime(10.0); void BGVrns_EvalMultManyP65537(benchmark::State& state) { - usint ptm = 65537; + uint32_t ptm = 65537; CryptoContext cc = GenerateBGVrnsContext(ptm); diff --git a/benchmark/src/lib-benchmark.cpp b/benchmark/src/lib-benchmark.cpp index b92dda15b..461686357 100644 --- a/benchmark/src/lib-benchmark.cpp +++ b/benchmark/src/lib-benchmark.cpp @@ -229,7 +229,7 @@ void BFVrns_EvalAtIndexKeyGen(benchmark::State& state) { keyPair = cc->KeyGen(); std::vector indexList(1); - for (usint i = 0; i < 1; i++) { + for (uint32_t i = 0; i < 1; i++) { indexList[i] = 1; } @@ -369,7 +369,7 @@ void BFVrns_EvalAtIndex(benchmark::State& state) { cc->EvalMultKeyGen(keyPair.secretKey); std::vector indexList(1); - for (usint i = 0; i < 1; i++) { + for (uint32_t i = 0; i < 1; i++) { indexList[i] = 1; } @@ -429,7 +429,7 @@ void CKKSrns_EvalAtIndexKeyGen(benchmark::State& state) { keyPair = cc->KeyGen(); std::vector indexList(1); - for (usint i = 0; i < 1; i++) { + for (uint32_t i = 0; i < 1; i++) { indexList[i] = 1; } @@ -445,9 +445,9 @@ void CKKSrns_Encryption(benchmark::State& state) { KeyPair keyPair = cc->KeyGen(); - usint slots = cc->GetEncodingParams()->GetBatchSize(); + uint32_t slots = cc->GetEncodingParams()->GetBatchSize(); std::vector> vectorOfInts(slots); - for (usint i = 0; i < slots; i++) { + for (uint32_t i = 0; i < slots; i++) { vectorOfInts[i] = 1.001 * i; } @@ -465,9 +465,9 @@ void CKKSrns_Decryption(benchmark::State& state) { KeyPair keyPair = cc->KeyGen(); - usint slots = cc->GetEncodingParams()->GetBatchSize(); + uint32_t slots = cc->GetEncodingParams()->GetBatchSize(); std::vector> vectorOfInts1(slots); - for (usint i = 0; i < slots; i++) { + for (uint32_t i = 0; i < slots; i++) { vectorOfInts1[i] = 1.001 * i; } @@ -489,9 +489,9 @@ void CKKSrns_Add(benchmark::State& state) { KeyPair keyPair = cc->KeyGen(); - usint slots = cc->GetEncodingParams()->GetBatchSize(); + uint32_t slots = cc->GetEncodingParams()->GetBatchSize(); std::vector> vectorOfInts1(slots); - for (usint i = 0; i < slots; i++) { + for (uint32_t i = 0; i < slots; i++) { vectorOfInts1[i] = 1.001 * i; } std::vector> vectorOfInts2(vectorOfInts1); @@ -514,9 +514,9 @@ void CKKSrns_AddInPlace(benchmark::State& state) { KeyPair keyPair = cc->KeyGen(); - usint slots = cc->GetEncodingParams()->GetBatchSize(); + uint32_t slots = cc->GetEncodingParams()->GetBatchSize(); std::vector> vectorOfInts1(slots); - for (usint i = 0; i < slots; i++) { + for (uint32_t i = 0; i < slots; i++) { vectorOfInts1[i] = 1.001 * i; } std::vector> vectorOfInts2(vectorOfInts1); @@ -539,9 +539,9 @@ void CKKSrns_MultNoRelin(benchmark::State& state) { KeyPair keyPair = cc->KeyGen(); - usint slots = cc->GetEncodingParams()->GetBatchSize(); + uint32_t slots = cc->GetEncodingParams()->GetBatchSize(); std::vector> vectorOfInts1(slots); - for (usint i = 0; i < slots; i++) { + for (uint32_t i = 0; i < slots; i++) { vectorOfInts1[i] = 1.001 * i; } std::vector> vectorOfInts2(vectorOfInts1); @@ -567,9 +567,9 @@ void CKKSrns_MultRelin(benchmark::State& state) { KeyPair keyPair = cc->KeyGen(); cc->EvalMultKeyGen(keyPair.secretKey); - usint slots = cc->GetEncodingParams()->GetBatchSize(); + uint32_t slots = cc->GetEncodingParams()->GetBatchSize(); std::vector> vectorOfInts1(slots); - for (usint i = 0; i < slots; i++) { + for (uint32_t i = 0; i < slots; i++) { vectorOfInts1[i] = 1.001 * i; } std::vector> vectorOfInts2(vectorOfInts1); @@ -595,9 +595,9 @@ void CKKSrns_Relin(benchmark::State& state) { KeyPair keyPair = cc->KeyGen(); cc->EvalMultKeyGen(keyPair.secretKey); - usint slots = cc->GetEncodingParams()->GetBatchSize(); + uint32_t slots = cc->GetEncodingParams()->GetBatchSize(); std::vector> vectorOfInts1(slots); - for (usint i = 0; i < slots; i++) { + for (uint32_t i = 0; i < slots; i++) { vectorOfInts1[i] = 1.001 * i; } std::vector> vectorOfInts2(vectorOfInts1); @@ -623,9 +623,9 @@ void CKKSrns_RelinInPlace(benchmark::State& state) { KeyPair keyPair = cc->KeyGen(); cc->EvalMultKeyGen(keyPair.secretKey); - usint slots = cc->GetEncodingParams()->GetBatchSize(); + uint32_t slots = cc->GetEncodingParams()->GetBatchSize(); std::vector> vectorOfInts1(slots); - for (usint i = 0; i < slots; i++) { + for (uint32_t i = 0; i < slots; i++) { vectorOfInts1[i] = 1.001 * i; } std::vector> vectorOfInts2(vectorOfInts1); @@ -655,9 +655,9 @@ void CKKSrns_Rescale(benchmark::State& state) { KeyPair keyPair = cc->KeyGen(); cc->EvalMultKeyGen(keyPair.secretKey); - usint slots = cc->GetEncodingParams()->GetBatchSize(); + uint32_t slots = cc->GetEncodingParams()->GetBatchSize(); std::vector> vectorOfInts1(slots); - for (usint i = 0; i < slots; i++) { + for (uint32_t i = 0; i < slots; i++) { vectorOfInts1[i] = 1.001 * i; } std::vector> vectorOfInts2(vectorOfInts1); @@ -683,9 +683,9 @@ void CKKSrns_RescaleInPlace(benchmark::State& state) { KeyPair keyPair = cc->KeyGen(); cc->EvalMultKeyGen(keyPair.secretKey); - usint slots = cc->GetEncodingParams()->GetBatchSize(); + uint32_t slots = cc->GetEncodingParams()->GetBatchSize(); std::vector> vectorOfInts(slots); - for (usint i = 0; i < slots; i++) { + for (uint32_t i = 0; i < slots; i++) { vectorOfInts[i] = 1.001 * i; } @@ -711,15 +711,15 @@ void CKKSrns_EvalAtIndex(benchmark::State& state) { cc->EvalMultKeyGen(keyPair.secretKey); std::vector indexList(1); - for (usint i = 0; i < 1; i++) { + for (uint32_t i = 0; i < 1; i++) { indexList[i] = 1; } cc->EvalAtIndexKeyGen(keyPair.secretKey, indexList); - usint slots = cc->GetEncodingParams()->GetBatchSize(); + uint32_t slots = cc->GetEncodingParams()->GetBatchSize(); std::vector> vectorOfInts1(slots); - for (usint i = 0; i < slots; i++) { + for (uint32_t i = 0; i < slots; i++) { vectorOfInts1[i] = 1.001 * i; } std::vector> vectorOfInts2(vectorOfInts1); @@ -775,7 +775,7 @@ void BGVrns_EvalAtIndexKeyGen(benchmark::State& state) { keyPair = cc->KeyGen(); std::vector indexList(1); - for (usint i = 0; i < 1; i++) { + for (uint32_t i = 0; i < 1; i++) { indexList[i] = 1; } @@ -1016,7 +1016,7 @@ void BGVrns_EvalAtIndex(benchmark::State& state) { cc->EvalMultKeyGen(keyPair.secretKey); std::vector indexList(1); - for (usint i = 0; i < 1; i++) { + for (uint32_t i = 0; i < 1; i++) { indexList[i] = 1; } diff --git a/benchmark/src/mult-vs-square.cpp b/benchmark/src/mult-vs-square.cpp index 8fb94d94b..d2b260eab 100644 --- a/benchmark/src/mult-vs-square.cpp +++ b/benchmark/src/mult-vs-square.cpp @@ -50,12 +50,12 @@ using namespace lbcrypto; -static std::vector depths({1, 2, 4, 8, 12}); +static std::vector depths({1, 2, 4, 8, 12}); /* * Context setup utility methods */ -CryptoContext GenerateBGVrnsContext(usint ptm, usint multDepth) { +CryptoContext GenerateBGVrnsContext(uint32_t ptm, uint32_t multDepth) { CCParams parameters; parameters.SetPlaintextModulus(ptm); parameters.SetMultiplicativeDepth(multDepth); @@ -70,7 +70,7 @@ CryptoContext GenerateBGVrnsContext(usint ptm, usint multDepth) { return cc; } -CryptoContext GenerateBFVrnsContext(usint ptm, usint multDepth) { +CryptoContext GenerateBFVrnsContext(uint32_t ptm, uint32_t multDepth) { CCParams parameters; parameters.SetPlaintextModulus(ptm); parameters.SetMultiplicativeDepth(multDepth); @@ -86,7 +86,7 @@ CryptoContext GenerateBFVrnsContext(usint ptm, usint multDepth) { return cc; } -CryptoContext GenerateCKKSContext(usint multDepth) { +CryptoContext GenerateCKKSContext(uint32_t multDepth) { CCParams parameters; parameters.SetScalingModSize(48); parameters.SetBatchSize(8); @@ -101,7 +101,7 @@ CryptoContext GenerateCKKSContext(usint multDepth) { } static void DepthArguments(benchmark::internal::Benchmark* b) { - for (usint t : depths) { + for (uint32_t t : depths) { b->ArgName("depths")->Arg(t); } } @@ -110,8 +110,8 @@ static void DepthArguments(benchmark::internal::Benchmark* b) { * EvalMult benchmarks for Power of 2 */ void BGVrns_EvalPo2WithMult_P2(benchmark::State& state) { - usint ptm = 2; - usint depth = state.range(0); + uint32_t ptm = 2; + uint32_t depth = state.range(0); CryptoContext cc = GenerateBGVrnsContext(ptm, depth); // KeyGen @@ -126,7 +126,7 @@ void BGVrns_EvalPo2WithMult_P2(benchmark::State& state) { while (state.KeepRunning()) { ciphertextPo2 = cc->EvalMult(ciphertext, ciphertext); - for (usint i = 2; i < depth; ++i) { + for (uint32_t i = 2; i < depth; ++i) { ciphertextPo2 = cc->EvalMult(ciphertextPo2, ciphertextPo2); } } @@ -148,8 +148,8 @@ BENCHMARK(BGVrns_EvalPo2WithMult_P2)->Unit(benchmark::kMicrosecond)->Apply(Depth * EvalSquare benchmarks for Power of 2 */ void BGVrns_EvalPo2WithSquare_P2(benchmark::State& state) { - usint ptm = 2; - usint depth = state.range(0); + uint32_t ptm = 2; + uint32_t depth = state.range(0); CryptoContext cc = GenerateBGVrnsContext(ptm, depth); // KeyGen @@ -164,7 +164,7 @@ void BGVrns_EvalPo2WithSquare_P2(benchmark::State& state) { while (state.KeepRunning()) { ciphertextPo2 = cc->EvalSquare(ciphertext); - for (usint i = 2; i < depth; ++i) { + for (uint32_t i = 2; i < depth; ++i) { ciphertextPo2 = cc->EvalSquare(ciphertextPo2); } } @@ -186,8 +186,8 @@ BENCHMARK(BGVrns_EvalPo2WithSquare_P2)->Unit(benchmark::kMicrosecond)->Apply(Dep * EvalMult benchmarks for Power of 2 */ void BFVrns_EvalPo2WithMult_P2(benchmark::State& state) { - usint ptm = 2; - usint depth = state.range(0); + uint32_t ptm = 2; + uint32_t depth = state.range(0); CryptoContext cc = GenerateBFVrnsContext(ptm, depth); // KeyGen @@ -202,7 +202,7 @@ void BFVrns_EvalPo2WithMult_P2(benchmark::State& state) { while (state.KeepRunning()) { ciphertextPo2 = cc->EvalMult(ciphertext, ciphertext); - for (usint i = 2; i < depth; ++i) { + for (uint32_t i = 2; i < depth; ++i) { ciphertextPo2 = cc->EvalMult(ciphertextPo2, ciphertextPo2); } } @@ -224,8 +224,8 @@ BENCHMARK(BFVrns_EvalPo2WithMult_P2)->Unit(benchmark::kMicrosecond)->Apply(Depth * EvalSquare benchmarks for Power of 2 */ void BFVrns_EvalPo2WithSquare_P2(benchmark::State& state) { - usint ptm = 2; - usint depth = state.range(0); + uint32_t ptm = 2; + uint32_t depth = state.range(0); CryptoContext cc = GenerateBFVrnsContext(ptm, depth); // KeyGen @@ -240,7 +240,7 @@ void BFVrns_EvalPo2WithSquare_P2(benchmark::State& state) { while (state.KeepRunning()) { ciphertextPo2 = cc->EvalSquare(ciphertext); - for (usint i = 2; i < depth; ++i) { + for (uint32_t i = 2; i < depth; ++i) { ciphertextPo2 = cc->EvalSquare(ciphertextPo2); } } @@ -262,8 +262,8 @@ BENCHMARK(BFVrns_EvalPo2WithSquare_P2)->Unit(benchmark::kMicrosecond)->Apply(Dep * EvalMult benchmarks for Power of 2 */ void BGVrns_EvalPo2WithMult_P65537(benchmark::State& state) { - usint ptm = 65537; - usint depth = state.range(0); + uint32_t ptm = 65537; + uint32_t depth = state.range(0); CryptoContext cc = GenerateBGVrnsContext(ptm, depth); // KeyGen @@ -278,7 +278,7 @@ void BGVrns_EvalPo2WithMult_P65537(benchmark::State& state) { while (state.KeepRunning()) { ciphertextPo2 = cc->EvalMult(ciphertext, ciphertext); - for (usint i = 2; i < depth; ++i) { + for (uint32_t i = 2; i < depth; ++i) { ciphertextPo2 = cc->EvalMult(ciphertextPo2, ciphertextPo2); } } @@ -300,8 +300,8 @@ BENCHMARK(BGVrns_EvalPo2WithMult_P65537)->Unit(benchmark::kMicrosecond)->Apply(D * EvalSquare benchmarks for Power of 2 */ void BGVrns_EvalPo2WithSquare_P65537(benchmark::State& state) { - usint ptm = 65537; - usint depth = state.range(0); + uint32_t ptm = 65537; + uint32_t depth = state.range(0); CryptoContext cc = GenerateBGVrnsContext(ptm, depth); // KeyGen @@ -316,7 +316,7 @@ void BGVrns_EvalPo2WithSquare_P65537(benchmark::State& state) { while (state.KeepRunning()) { ciphertextPo2 = cc->EvalSquare(ciphertext); - for (usint i = 2; i < depth; ++i) { + for (uint32_t i = 2; i < depth; ++i) { cc->EvalSquareInPlace(ciphertextPo2); } } @@ -338,8 +338,8 @@ BENCHMARK(BGVrns_EvalPo2WithSquare_P65537)->Unit(benchmark::kMicrosecond)->Apply * EvalMult benchmarks for Power of 2 */ void BFVrns_EvalPo2WithMult_P65537(benchmark::State& state) { - usint ptm = 65537; - usint depth = state.range(0); + uint32_t ptm = 65537; + uint32_t depth = state.range(0); CryptoContext cc = GenerateBFVrnsContext(ptm, depth); // KeyGen @@ -354,7 +354,7 @@ void BFVrns_EvalPo2WithMult_P65537(benchmark::State& state) { while (state.KeepRunning()) { ciphertextPo2 = cc->EvalMult(ciphertext, ciphertext); - for (usint i = 2; i < depth; ++i) { + for (uint32_t i = 2; i < depth; ++i) { ciphertextPo2 = cc->EvalMult(ciphertextPo2, ciphertextPo2); } } @@ -376,8 +376,8 @@ BENCHMARK(BFVrns_EvalPo2WithMult_P65537)->Unit(benchmark::kMicrosecond)->Apply(D * EvalSquare benchmarks for Power of 2 */ void BFVrns_EvalPo2WithSquare_P65537(benchmark::State& state) { - usint ptm = 65537; - usint depth = state.range(0); + uint32_t ptm = 65537; + uint32_t depth = state.range(0); CryptoContext cc = GenerateBFVrnsContext(ptm, depth); // KeyGen @@ -392,7 +392,7 @@ void BFVrns_EvalPo2WithSquare_P65537(benchmark::State& state) { while (state.KeepRunning()) { ciphertextPo2 = cc->EvalSquare(ciphertext); - for (usint i = 2; i < depth; ++i) { + for (uint32_t i = 2; i < depth; ++i) { ciphertextPo2 = cc->EvalSquare(ciphertextPo2); } } @@ -414,7 +414,7 @@ BENCHMARK(BFVrns_EvalPo2WithSquare_P65537)->Unit(benchmark::kMicrosecond)->Apply * EvalMult benchmarks for Power of 2 */ void CKKSrns_EvalPo2WithMult(benchmark::State& state) { - usint depth = state.range(0); + uint32_t depth = state.range(0); CryptoContext cc = GenerateCKKSContext(depth); // KeyGen @@ -429,7 +429,7 @@ void CKKSrns_EvalPo2WithMult(benchmark::State& state) { while (state.KeepRunning()) { ciphertextPo2 = cc->EvalMult(ciphertext, ciphertext); - for (usint i = 2; i < depth; ++i) { + for (uint32_t i = 2; i < depth; ++i) { ciphertextPo2 = cc->EvalMult(ciphertextPo2, ciphertextPo2); } } @@ -456,7 +456,7 @@ BENCHMARK(CKKSrns_EvalPo2WithMult)->Unit(benchmark::kMicrosecond)->Apply(DepthAr * EvalSquare benchmarks for Power of 2 */ void CKKSrns_EvalPo2WithSquare(benchmark::State& state) { - usint depth = state.range(0); + uint32_t depth = state.range(0); CryptoContext cc = GenerateCKKSContext(depth); // KeyGen @@ -471,7 +471,7 @@ void CKKSrns_EvalPo2WithSquare(benchmark::State& state) { while (state.KeepRunning()) { ciphertextPo2 = cc->EvalSquare(ciphertext); - for (usint i = 2; i < depth; ++i) { + for (uint32_t i = 2; i < depth; ++i) { ciphertextPo2 = cc->EvalSquare(ciphertextPo2); } } diff --git a/src/binfhe/lib/rgsw-acc-lmkcdey.cpp b/src/binfhe/lib/rgsw-acc-lmkcdey.cpp index 64f47de3c..6cbeebaa9 100644 --- a/src/binfhe/lib/rgsw-acc-lmkcdey.cpp +++ b/src/binfhe/lib/rgsw-acc-lmkcdey.cpp @@ -250,14 +250,14 @@ void RingGSWAccumulatorLMKCDEY::Automorphism(const std::shared_ptrGetN()}; - std::vector vec(N); - PrecomputeAutoMap(N, a.ConvertToInt(), &vec); + std::vector vec(N); + PrecomputeAutoMap(N, a.ConvertToInt(), &vec); - acc->GetElements()[1] = acc->GetElements()[1].AutomorphismTransform(a.ConvertToInt(), vec); + acc->GetElements()[1] = acc->GetElements()[1].AutomorphismTransform(a.ConvertToInt(), vec); NativePoly cta(acc->GetElements()[0]); acc->GetElements()[0].SetValuesToZero(); - cta = cta.AutomorphismTransform(a.ConvertToInt(), vec); + cta = cta.AutomorphismTransform(a.ConvertToInt(), vec); cta.SetFormat(COEFFICIENT); // approximate gadget decomposition is used; the first digit is ignored diff --git a/src/core/extras/math.cpp b/src/core/extras/math.cpp index 0a183ad47..263c04163 100644 --- a/src/core/extras/math.cpp +++ b/src/core/extras/math.cpp @@ -47,11 +47,11 @@ using namespace lbcrypto; // define the main sections of the test -void test_BigVector(usint nloop); // test old version of big int vector +void test_BigVector(uint32_t nloop); // test old version of big int vector // main() need this for Kurts' makefile to ignore this. int main(int argc, char* argv[]) { - usint nloop = 10; + uint32_t nloop = 10; if (argc > 1) nloop = atoi(argv[1]); @@ -71,7 +71,7 @@ int main(int argc, char* argv[]) { do { \ try { \ TIC(t); \ - for (usint j = 0; j < nloop; j++) { \ + for (uint32_t j = 0; j < nloop; j++) { \ res = (fn); \ } \ time2 = TOC(t); \ @@ -90,7 +90,7 @@ int main(int argc, char* argv[]) { // helper function that bulds BigVector from a vector of strings BigVector BBVfromStrvec(std::vector& s) { BigVector a(s.size()); - for (usint i = 0; i < s.size(); i++) { + for (uint32_t i = 0; i < s.size(); i++) { a.at(i) = s[i]; } return a; @@ -98,7 +98,7 @@ BigVector BBVfromStrvec(std::vector& s) { // function to compare two BigVectors and print differing indicies void vec_diff(BigVector& a, BigVector& b) { - for (usint i = 0; i < a.GetLength(); ++i) { + for (uint32_t i = 0; i < a.GetLength(); ++i) { if (a.at(i) != b.at(i)) { std::cout << "i: " << i << std::endl; std::cout << "first vector " << std::endl; @@ -112,7 +112,7 @@ void vec_diff(BigVector& a, BigVector& b) { } // main BigVector test suite. tests math -void test_BigVector(usint nloop) { +void test_BigVector(uint32_t nloop) { std::cout << "testing BigVector" << std::endl; TimeVar t1, t2, t3; // timers for TIC() TOC() diff --git a/src/core/extras/ntt1.cpp b/src/core/extras/ntt1.cpp index 4ad57a375..5ad8b9a1b 100644 --- a/src/core/extras/ntt1.cpp +++ b/src/core/extras/ntt1.cpp @@ -66,7 +66,7 @@ int main(int argc, char* argv[]) { do { \ try { \ TIC(t); \ - for (usint j = 0; j < nloop; j++) { \ + for (uint32_t j = 0; j < nloop; j++) { \ res = (fn); \ } \ time2 = TOC(t); \ @@ -85,7 +85,7 @@ int main(int argc, char* argv[]) { // helper function that bulds BigVector from a vector of strings BigVector BBVfromStrvec(std::vector& s) { BigVector a(s.size()); - for (usint i = 0; i < s.size(); i++) { + for (uint32_t i = 0; i < s.size(); i++) { a[i] = s[i]; } return a; @@ -93,7 +93,7 @@ BigVector BBVfromStrvec(std::vector& s) { // function to compare two BigVectors and print differing indicies void vec_diff(BigVector& a, BigVector& b) { - for (usint i = 0; i < a.GetLength(); ++i) { + for (uint32_t i = 0; i < a.GetLength(); ++i) { if (a.at(i) != b.at(i)) { std::cout << "i: " << i << std::endl; std::cout << "first vector " << std::endl; @@ -254,7 +254,7 @@ void test_NTT() { b3.SetModulus(q3); #if 1 - usint m = 32; + uint32_t m = 32; // BigInteger modulus(q1); diff --git a/src/core/extras/ntt2.cpp b/src/core/extras/ntt2.cpp index 77bb5a63c..efb772f59 100644 --- a/src/core/extras/ntt2.cpp +++ b/src/core/extras/ntt2.cpp @@ -48,15 +48,15 @@ using namespace lbcrypto; // define the main sections of the test -void test_NTT(const usint level, const usint nloop); // test code +void test_NTT(const uint32_t level, const uint32_t nloop); // test code // main() need this for Kurts' makefile to ignore this. int main(int argc, char* argv[]) { if (argc < 2) // argc should be 2 for correct execution // We print argv[0] assuming it is the program name std::cout << "usage: " << argv[0] << " 1|2|3(default 1) nloop (default 10)" << std::endl; - usint level = 1; - usint nloop = 10; + uint32_t level = 1; + uint32_t nloop = 10; if (argc > 1) level = atoi(argv[1]); if (argc > 2) @@ -77,7 +77,7 @@ int main(int argc, char* argv[]) { // function to compare two BigVectors and print differing indicies void vec_diff(BigVector& a, BigVector& b) { - for (usint i = 0; i < a.GetLength(); ++i) { + for (uint32_t i = 0; i < a.GetLength(); ++i) { if (a.at(i) != b.at(i)) { std::cout << "i: " << i << std::endl; std::cout << "first vector " << std::endl; @@ -102,7 +102,7 @@ bool clonetest(Poly& a, Poly& b, std::string name) { } // main NTT test suite. -void test_NTT(const usint level, const usint nloop) { +void test_NTT(const uint32_t level, const uint32_t nloop) { // Code to test NTT at three different numbers of limbs. TimeVar t1, t_setup, t_total; // timers for TIC() TOC() @@ -123,7 +123,7 @@ void test_NTT(const usint level, const usint nloop) { BigInteger q1("270337"); // test case 1 smaller than 32 bits - usint m = 2048; + uint32_t m = 2048; std::cout << "m=" << m << std::endl; BigInteger rootOfUnity1(RootOfUnity(m, q1)); @@ -230,7 +230,7 @@ void test_NTT(const usint level, const usint nloop) { time3br = 0.0; bool failed = false; - usint ix; + uint32_t ix; std::cout << "Starting timing" << std::endl; for (ix = 0; ix < nloop; ix++) { diff --git a/src/core/include/lattice/dgsampling-impl.h b/src/core/include/lattice/dgsampling-impl.h index 3cde67937..2fbd54432 100644 --- a/src/core/include/lattice/dgsampling-impl.h +++ b/src/core/include/lattice/dgsampling-impl.h @@ -455,7 +455,7 @@ std::shared_ptr> LatticeGaussSampUtility::ZSampleF(cons f0.SetFormat(Format::EVALUATION); f1.SetFormat(Format::EVALUATION); - usint f0_size = f0.Size(); + uint32_t f0_size = f0.Size(); auto qZVector = std::make_shared>([]() { return 0; }, f0_size * 2, 1); @@ -477,7 +477,7 @@ Matrix LatticeGaussSampUtility::Permute(Matrix* p) { int evenPtr = 0; int oddPtr = p->GetRows() / 2; Matrix permuted([]() { return 0; }, p->GetRows(), 1); - for (usint i = 0; i < p->GetRows(); i++) { + for (uint32_t i = 0; i < p->GetRows(); i++) { if (i % 2 == 0) { permuted(evenPtr, 0) = (*p)(i, 0); evenPtr++; diff --git a/src/core/include/lattice/field2n.h b/src/core/include/lattice/field2n.h index 8d567616c..5a90277d2 100644 --- a/src/core/include/lattice/field2n.h +++ b/src/core/include/lattice/field2n.h @@ -75,7 +75,7 @@ class Field2n : public std::vector>, public Serializable { * @param initializeElementToZero flag for initializing values to zero. It is * set to false by default. */ - Field2n(usint size, Format f = Format::EVALUATION, bool initializeElementToZero = false) // NOLINT + Field2n(uint32_t size, Format f = Format::EVALUATION, bool initializeElementToZero = false) // NOLINT : std::vector>(size, initializeElementToZero ? 0 : -std::numeric_limits::max()), format(f) {} diff --git a/src/core/include/lattice/hal/dcrtpoly-interface.h b/src/core/include/lattice/hal/dcrtpoly-interface.h index 5991119ad..020e10b4e 100644 --- a/src/core/include/lattice/hal/dcrtpoly-interface.h +++ b/src/core/include/lattice/hal/dcrtpoly-interface.h @@ -215,7 +215,7 @@ class DCRTPolyInterface : public ILElement { * @brief returns the element's cyclotomic order * @return returns the cyclotomic order of the element. */ - usint GetCyclotomicOrder() const final { + uint32_t GetCyclotomicOrder() const final { return this->GetDerived().GetParams()->GetCyclotomicOrder(); } @@ -223,7 +223,7 @@ class DCRTPolyInterface : public ILElement { * @brief returns the element's ring dimension * @return returns the ring dimension of the element. */ - usint GetRingDimension() const { + uint32_t GetRingDimension() const { return this->GetDerived().GetParams()->GetRingDimension(); } @@ -251,7 +251,7 @@ class DCRTPolyInterface : public ILElement { * * @return length of the component element */ - usint GetLength() const final { + uint32_t GetLength() const final { return this->GetDerived().GetParams()->GetRingDimension(); } @@ -260,10 +260,10 @@ class DCRTPolyInterface : public ILElement { * Note this operation is computationally intense. Does bound checking * @return interpolated value at index i. */ - BigIntType& at(usint i) final { + BigIntType& at(uint32_t i) final { OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } - const BigIntType& at(usint i) const final { + const BigIntType& at(uint32_t i) const final { OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } @@ -272,10 +272,10 @@ class DCRTPolyInterface : public ILElement { * Note this operation is computationally intense. No bound checking * @return interpolated value at index i. */ - BigIntType& operator[](usint i) final { + BigIntType& operator[](uint32_t i) final { OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } - const BigIntType& operator[](usint i) const final { + const BigIntType& operator[](uint32_t i) const final { OPENFHE_THROW(NOT_IMPLEMENTED_ERROR); } @@ -297,7 +297,7 @@ class DCRTPolyInterface : public ILElement { * * @return the number of component elements. */ - usint GetNumOfElements() const { + uint32_t GetNumOfElements() const { return this->GetDerived().GetAllElements().size(); } @@ -307,7 +307,7 @@ class DCRTPolyInterface : public ILElement { * @param i index of tower to be returned. * @returns a reference to the returned tower */ - const TowerType& GetElementAtIndex(usint i) const { + const TowerType& GetElementAtIndex(uint32_t i) const { return this->GetDerived().GetAllElements()[i]; } @@ -317,7 +317,7 @@ class DCRTPolyInterface : public ILElement { * @param index where the element should be set * @param element The element to store */ - void SetElementAtIndex(usint index, const TowerType& element) { + void SetElementAtIndex(uint32_t index, const TowerType& element) { return this->GetDerived().SetElementAtIndex(index, element); } @@ -327,7 +327,7 @@ class DCRTPolyInterface : public ILElement { * @param index where the element should be set * @param element The element to store */ - void SetElementAtIndex(usint index, TowerType&& element) { + void SetElementAtIndex(uint32_t index, TowerType&& element) { return this->GetDerived().SetElementAtIndex(index, std::move(element)); } @@ -349,7 +349,7 @@ class DCRTPolyInterface : public ILElement { * @warning not efficient and not fast, uses multiprecision arithmetic and * will be removed in future. Use @see DCRTPolyInterface::CRTDecompose instead. */ - std::vector BaseDecompose(usint baseBits, bool evalModeAnswer) const override = 0; + std::vector BaseDecompose(uint32_t baseBits, bool evalModeAnswer) const override = 0; /** * @brief Generate a vector of PolyImpl's as \f$ \left\{x, {base}*x, @@ -365,7 +365,7 @@ class DCRTPolyInterface : public ILElement { * @warning not efficient and not fast, uses multiprecision arithmetic and * will be removed in future. Use @see DCRTPolyInterface::CRTDecompose instead. */ - std::vector PowersOfBase(usint baseBits) const override = 0; + std::vector PowersOfBase(uint32_t baseBits) const override = 0; /** * CRT basis decomposition of c as [c qi/q]_qi @@ -407,10 +407,10 @@ class DCRTPolyInterface : public ILElement { DerivedType& operator=(std::initializer_list rhs) override = 0; /** - * @brief Assignment Operator. The usint val will be set at index zero and all + * @brief Assignment Operator. The uint32_t val will be set at index zero and all * other indices will be set to zero. * - * @param val is the usint to assign to index zero. + * @param val is the uint32_t to assign to index zero. * @return the resulting vector. */ DerivedType& operator=(uint64_t val) { @@ -876,7 +876,7 @@ class DCRTPolyInterface : public ILElement { * * @return the interpolated ring element as a Poly object. */ - virtual PolyLargeType CRTInterpolateIndex(usint i) const = 0; + virtual PolyLargeType CRTInterpolateIndex(uint32_t i) const = 0; /** * @brief Computes and returns the product of primes in the current moduli @@ -1128,7 +1128,7 @@ class DCRTPolyInterface : public ILElement { virtual void ExpandCRTBasisQlHat(const std::shared_ptr& paramsQ, const std::vector& QlHatModq, - const std::vector& QlHatModqPrecon, const usint sizeQ) = 0; + const std::vector& QlHatModqPrecon, const uint32_t sizeQ) = 0; /** * @brief Performs scale and round: @@ -1299,7 +1299,7 @@ class DCRTPolyInterface : public ILElement { const std::vector& mtildeQHatInvModq, const std::vector& mtildeQHatInvModqPrecon, const std::vector>& QHatModbsk, const std::vector& QHatModmtilde, const std::vector& QModbsk, const std::vector& QModbskPrecon, - const uint64_t& negQInvModmtilde, const std::vector& mtildeInvModbsk, + uint64_t negQInvModmtilde, const std::vector& mtildeInvModbsk, const std::vector& mtildeInvModbskPrecon) = 0; /** @@ -1440,7 +1440,7 @@ class DCRTPolyInterface : public ILElement { */ friend inline std::ostream& operator<<(std::ostream& os, const DerivedType& vec) { // os << (vec.m_format == EVALUATION ? "EVAL: " : "COEF: "); - for (usint i = 0; i < vec.GetAllElements().size(); i++) { + for (uint32_t i = 0; i < vec.GetAllElements().size(); i++) { if (i != 0) os << std::endl; os << i << ": "; diff --git a/src/core/include/lattice/hal/default/dcrtpoly-impl.h b/src/core/include/lattice/hal/default/dcrtpoly-impl.h index bd0255336..2bb592d77 100644 --- a/src/core/include/lattice/hal/default/dcrtpoly-impl.h +++ b/src/core/include/lattice/hal/default/dcrtpoly-impl.h @@ -1517,7 +1517,7 @@ DCRTPolyImpl DCRTPolyImpl::ScaleAndRound( OPENFHE_THROW("Use of ScaleAndRound with NATIVEINT == 32 may lead to overflow"); DCRTPolyImpl ans(paramsOutput, m_format, true); - uint32_t ringDim = m_params->GetRingDimension(); + uint32_t ringDim = m_params->GetRingDimension(); uint32_t sizeQP = m_vectors.size(); uint32_t sizeO = ans.m_vectors.size(); uint32_t sizeI = sizeQP - sizeO; @@ -1697,7 +1697,7 @@ void DCRTPolyImpl::FastBaseConvqToBskMontgomery( const std::vector& mtildeQHatInvModq, const std::vector& mtildeQHatInvModqPrecon, const std::vector>& QHatModbsk, const std::vector& QHatModmtilde, const std::vector& QModbsk, const std::vector& QModbskPrecon, - const uint64_t& negQInvModmtilde, const std::vector& mtildeInvModbsk, + uint64_t negQInvModmtilde, const std::vector& mtildeInvModbsk, const std::vector& mtildeInvModbskPrecon) { constexpr uint64_t mtilde = (uint64_t)1 << 16; constexpr uint64_t mtilde_half = mtilde >> 1; diff --git a/src/core/include/lattice/hal/default/dcrtpoly.h b/src/core/include/lattice/hal/default/dcrtpoly.h index 2c5229fc6..ca8138a16 100644 --- a/src/core/include/lattice/hal/default/dcrtpoly.h +++ b/src/core/include/lattice/hal/default/dcrtpoly.h @@ -141,8 +141,8 @@ class DCRTPolyImpl final : public DCRTPolyInterface, VecTy DCRTPolyType Negate() const override; DCRTPolyType operator-() const override; - std::vector BaseDecompose(usint baseBits, bool evalModeAnswer) const override; - std::vector PowersOfBase(usint baseBits) const override; + std::vector BaseDecompose(uint32_t baseBits, bool evalModeAnswer) const override; + std::vector PowersOfBase(uint32_t baseBits) const override; std::vector CRTDecompose(uint32_t baseBits) const; DCRTPolyType AutomorphismTransform(uint32_t i) const override; @@ -217,7 +217,7 @@ class DCRTPolyImpl final : public DCRTPolyInterface, VecTy PolyLargeType CRTInterpolate() const override; PolyType DecryptionCRTInterpolate(PlaintextModulus ptm) const override; PolyType ToNativePoly() const override; - PolyLargeType CRTInterpolateIndex(usint i) const override; + PolyLargeType CRTInterpolateIndex(uint32_t i) const override; Integer GetWorkingModulus() const override; void SetValuesModSwitch(const DCRTPolyType& element, const NativeInteger& modulus) override; @@ -274,7 +274,7 @@ class DCRTPolyImpl final : public DCRTPolyInterface, VecTy void FastExpandCRTBasisPloverQ(const Precomputations& precomputed) override; void ExpandCRTBasisQlHat(const std::shared_ptr& paramsQ, const std::vector& QlHatModq, - const std::vector& QlHatModqPrecon, const usint sizeQ) override; + const std::vector& QlHatModqPrecon, const uint32_t sizeQ) override; PolyType ScaleAndRound(const NativeInteger& t, const std::vector& tQHatInvModqDivqModt, const std::vector& tQHatInvModqDivqModtPrecon, @@ -307,7 +307,7 @@ class DCRTPolyImpl final : public DCRTPolyInterface, VecTy const std::vector& mtildeQHatInvModq, const std::vector& mtildeQHatInvModqPrecon, const std::vector>& QHatModbsk, const std::vector& QHatModmtilde, const std::vector& QModbsk, const std::vector& QModbskPrecon, - const uint64_t& negQInvModmtilde, const std::vector& mtildeInvModbsk, + uint64_t negQInvModmtilde, const std::vector& mtildeInvModbsk, const std::vector& mtildeInvModbskPrecon) override; void FastRNSFloorq(const NativeInteger& t, const std::vector& moduliQ, @@ -383,11 +383,11 @@ class DCRTPolyImpl final : public DCRTPolyInterface, VecTy return m_vectors; } - void SetElementAtIndex(usint index, const PolyType& element) { + void SetElementAtIndex(uint32_t index, const PolyType& element) { m_vectors[index] = element; } - void SetElementAtIndex(usint index, PolyType&& element) { + void SetElementAtIndex(uint32_t index, PolyType&& element) { m_vectors[index] = std::move(element); } diff --git a/src/core/include/lattice/hal/default/poly-impl.h b/src/core/include/lattice/hal/default/poly-impl.h index 909c252b5..ac4f828e2 100644 --- a/src/core/include/lattice/hal/default/poly-impl.h +++ b/src/core/include/lattice/hal/default/poly-impl.h @@ -300,9 +300,9 @@ PolyImpl& PolyImpl::operator-=(const PolyImpl& element) { template void PolyImpl::AddILElementOne() { static const Integer ONE(1); - usint vlen{m_params->GetRingDimension()}; + uint32_t vlen{m_params->GetRingDimension()}; const auto& m{m_params->GetModulus()}; - for (usint i = 0; i < vlen; ++i) + for (uint32_t i = 0; i < vlen; ++i) (*m_values)[i].ModAddFastEq(ONE, m); } @@ -488,8 +488,8 @@ void PolyImpl::MakeSparse(uint32_t wFactor) { template bool PolyImpl::InverseExists() const { static const Integer ZERO(0); - usint vlen{m_params->GetRingDimension()}; - for (usint i = 0; i < vlen; ++i) { + uint32_t vlen{m_params->GetRingDimension()}; + for (uint32_t i = 0; i < vlen; ++i) { if ((*m_values)[i] == ZERO) return false; } @@ -498,11 +498,11 @@ bool PolyImpl::InverseExists() const { template double PolyImpl::Norm() const { - usint vlen{m_params->GetRingDimension()}; + uint32_t vlen{m_params->GetRingDimension()}; const auto& q{m_params->GetModulus()}; const auto& half{q >> 1}; Integer maxVal{}, minVal{q}; - for (usint i = 0; i < vlen; i++) { + for (uint32_t i = 0; i < vlen; i++) { auto& val = (*m_values)[i]; if (val > half) minVal = val < minVal ? val : minVal; @@ -521,10 +521,10 @@ double PolyImpl::Norm() const { // TODO: optimize this template -std::vector> PolyImpl::BaseDecompose(usint baseBits, bool evalModeAnswer) const { - usint nBits = m_params->GetModulus().GetLengthForBase(2); +std::vector> PolyImpl::BaseDecompose(uint32_t baseBits, bool evalModeAnswer) const { + uint32_t nBits = m_params->GetModulus().GetLengthForBase(2); - usint nWindows = nBits / baseBits; + uint32_t nWindows = nBits / baseBits; if (nBits % baseBits > 0) nWindows++; @@ -537,7 +537,7 @@ std::vector> PolyImpl::BaseDecompose(usint baseBits, x.SetFormat(Format::COEFFICIENT); // TP: x is same for BACKEND 2 and 6 - for (usint i = 0; i < nWindows; ++i) { + for (uint32_t i = 0; i < nWindows; ++i) { xDigit.SetValues(x.GetValues().GetDigitAtIndexForBase(i + 1, 1 << baseBits), x.GetFormat()); // TP: xDigit is all zeros for BACKEND=6, but not for BACKEND-2 @@ -556,16 +556,16 @@ std::vector> PolyImpl::BaseDecompose(usint baseBits, // base = 2^baseBits template -std::vector> PolyImpl::PowersOfBase(usint baseBits) const { +std::vector> PolyImpl::PowersOfBase(uint32_t baseBits) const { static const Integer TWO(2); const auto& m{m_params->GetModulus()}; - usint nBits{m.GetLengthForBase(2)}; - usint nWindows{nBits / baseBits}; + uint32_t nBits{m.GetLengthForBase(2)}; + uint32_t nWindows{nBits / baseBits}; if (nBits % baseBits > 0) ++nWindows; std::vector> result(nWindows); Integer shift{0}, bbits{baseBits}; - for (usint i = 0; i < nWindows; ++i, shift += bbits) + for (uint32_t i = 0; i < nWindows; ++i, shift += bbits) result[i] = (*this) * TWO.ModExp(shift, m); return result; } @@ -573,11 +573,11 @@ std::vector> PolyImpl::PowersOfBase(usint baseBits) c template typename PolyImpl::PolyNative PolyImpl::DecryptionCRTInterpolate(PlaintextModulus ptm) const { const PolyImpl smaller(PolyImpl::Mod(ptm)); - usint vlen{m_params->GetRingDimension()}; + uint32_t vlen{m_params->GetRingDimension()}; auto c{m_params->GetCyclotomicOrder()}; auto params{std::make_shared(c, NativeInteger(ptm), 1)}; typename PolyImpl::PolyNative tmp(params, m_format, true); - for (usint i = 0; i < vlen; ++i) + for (uint32_t i = 0; i < vlen; ++i) tmp[i] = NativeInteger((*smaller.m_values)[i]); return tmp; } diff --git a/src/core/include/lattice/hal/default/poly.h b/src/core/include/lattice/hal/default/poly.h index 4a62ebc7a..629481b29 100644 --- a/src/core/include/lattice/hal/default/poly.h +++ b/src/core/include/lattice/hal/default/poly.h @@ -153,12 +153,12 @@ class PolyImpl final : public PolyInterface, VecType, PolyImpl PolyNative DecryptionCRTInterpolate(PlaintextModulus ptm) const override; PolyNative ToNativePoly() const final { - usint vlen{m_params->GetRingDimension()}; + uint32_t vlen{m_params->GetRingDimension()}; auto c{m_params->GetCyclotomicOrder()}; NativeInteger m{std::numeric_limits::max()}; auto params{std::make_shared>(c, m, 1)}; typename PolyImpl::PolyNative tmp(params, m_format, true); - for (usint i = 0; i < vlen; ++i) + for (uint32_t i = 0; i < vlen; ++i) tmp[i] = NativeInteger((*m_values)[i]); return tmp; } @@ -167,12 +167,12 @@ class PolyImpl final : public PolyInterface, VecType, PolyImpl void SetValues(VecType&& values, Format format) override; void SetValuesToZero() override { - usint r{m_params->GetRingDimension()}; + uint32_t r{m_params->GetRingDimension()}; m_values = std::make_unique(r, m_params->GetModulus()); } void SetValuesToMax() override { - usint r{m_params->GetRingDimension()}; + uint32_t r{m_params->GetRingDimension()}; auto max{m_params->GetModulus() - Integer(1)}; m_values = std::make_unique(r, m_params->GetModulus(), max); } @@ -199,23 +199,23 @@ class PolyImpl final : public PolyInterface, VecType, PolyImpl return m_values == nullptr; } - inline Integer& at(usint i) final { + inline Integer& at(uint32_t i) final { if (m_values == nullptr) OPENFHE_THROW("No values in PolyImpl"); return m_values->at(i); } - inline const Integer& at(usint i) const final { + inline const Integer& at(uint32_t i) const final { if (m_values == nullptr) OPENFHE_THROW("No values in PolyImpl"); return m_values->at(i); } - inline Integer& operator[](usint i) final { + inline Integer& operator[](uint32_t i) final { return (*m_values)[i]; } - inline const Integer& operator[](usint i) const final { + inline const Integer& operator[](uint32_t i) const final { return (*m_values)[i]; } @@ -329,8 +329,8 @@ class PolyImpl final : public PolyInterface, VecType, PolyImpl void MakeSparse(uint32_t wFactor) override; bool InverseExists() const override; double Norm() const override; - std::vector BaseDecompose(usint baseBits, bool evalModeAnswer) const override; - std::vector PowersOfBase(usint baseBits) const override; + std::vector BaseDecompose(uint32_t baseBits, bool evalModeAnswer) const override; + std::vector PowersOfBase(uint32_t baseBits) const override; template void save(Archive& ar, std::uint32_t const version) const { diff --git a/src/core/include/lattice/hal/poly-interface.h b/src/core/include/lattice/hal/poly-interface.h index c96215a71..02c243e26 100644 --- a/src/core/include/lattice/hal/poly-interface.h +++ b/src/core/include/lattice/hal/poly-interface.h @@ -164,7 +164,7 @@ class PolyInterface : public ILElement { * @brief returns the element's ring dimension * @return returns the ring dimension of the element. */ - usint GetRingDimension() const { + uint32_t GetRingDimension() const { return this->GetDerived().GetParams()->GetRingDimension(); } @@ -188,7 +188,7 @@ class PolyInterface : public ILElement { * @brief returns the element's cyclotomic order * @return returns the cyclotomic order of the element. */ - usint GetCyclotomicOrder() const final { + uint32_t GetCyclotomicOrder() const final { return this->GetDerived().GetParams()->GetCyclotomicOrder(); } @@ -198,7 +198,7 @@ class PolyInterface : public ILElement { * * @return length of the component element */ - usint GetLength() const final { + uint32_t GetLength() const final { // if (this->GetDerived().IsEmpty()) // OPENFHE_THROW("No values in PolyImpl"); return this->GetDerived().GetValues().GetLength(); @@ -218,19 +218,19 @@ class PolyInterface : public ILElement { * Note this operation is computationally intense. Does bound checking * @return interpolated value at index i. */ - Integer& at(usint i) override = 0; - const Integer& at(usint i) const override = 0; + Integer& at(uint32_t i) override = 0; + const Integer& at(uint32_t i) const override = 0; /** * @brief Get interpolated value of element at index i. * Note this operation is computationally intense. No bound checking * @return interpolated value at index i. */ - Integer& operator[](usint i) override { + Integer& operator[](uint32_t i) override { return this->GetDerived()[i]; } - const Integer& operator[](usint i) const override { + const Integer& operator[](uint32_t i) const override { return this->GetDerived()[i]; } @@ -546,7 +546,7 @@ class PolyInterface : public ILElement { * will be removed in future. Use @see DCRTPolyInterface::CRTDecompose instead. */ - std::vector BaseDecompose(usint baseBits, bool evalModeAnswer) const override = 0; + std::vector BaseDecompose(uint32_t baseBits, bool evalModeAnswer) const override = 0; /** * @brief Generate a vector of PolyImpl's as \f$ \left\{x, {base}*x, @@ -562,7 +562,7 @@ class PolyInterface : public ILElement { * @warning not efficient and not fast, uses multiprecision arithmetic and * will be removed in future. Use @see DCRTPolyInterface::CRTDecompose instead. */ - std::vector PowersOfBase(usint baseBits) const override = 0; + std::vector PowersOfBase(uint32_t baseBits) const override = 0; /** * @brief Set method that should not be used, will throw an error. diff --git a/src/core/include/lattice/ilelement.h b/src/core/include/lattice/ilelement.h index 7d4367681..f7485f702 100644 --- a/src/core/include/lattice/ilelement.h +++ b/src/core/include/lattice/ilelement.h @@ -121,7 +121,7 @@ class ILElement : public Serializable { * * @return length */ - virtual usint GetLength() const = 0; + virtual uint32_t GetLength() const = 0; /** * @brief Get modulus of the element @@ -142,7 +142,7 @@ class ILElement : public Serializable { * * @return order */ - virtual usint GetCyclotomicOrder() const = 0; + virtual uint32_t GetCyclotomicOrder() const = 0; /** * @brief Gets the Value in the Element that is At Index and returns it. @@ -152,16 +152,16 @@ class ILElement : public Serializable { * @param i is the index. * @return will throw an error. */ - virtual IntType& at(usint i) { + virtual IntType& at(uint32_t i) { OPENFHE_THROW("at() not implemented"); } - virtual const IntType& at(usint i) const { + virtual const IntType& at(uint32_t i) const { OPENFHE_THROW("const at() not implemented"); } - virtual IntType& operator[](usint i) { + virtual IntType& operator[](uint32_t i) { OPENFHE_THROW("[] not implemented"); } - virtual const IntType& operator[](usint i) const { + virtual const IntType& operator[](uint32_t i) const { OPENFHE_THROW("const [] not implemented"); } @@ -337,7 +337,7 @@ class ILElement : public Serializable { * evaluation mode * @result is the pointer where the base decomposition vector is stored */ - virtual std::vector BaseDecompose(usint baseBits, bool evalModeAnswer) const = 0; + virtual std::vector BaseDecompose(uint32_t baseBits, bool evalModeAnswer) const = 0; /** * @brief Scalar division followed by rounding operation - operation on all @@ -411,7 +411,7 @@ class ILElement : public Serializable { * @param baseBits * @return */ - virtual std::vector PowersOfBase(usint baseBits) const = 0; + virtual std::vector PowersOfBase(uint32_t baseBits) const = 0; /** * @brief Mod - perform a modulus operation. diff --git a/src/core/include/lattice/stdlatticeparms.h b/src/core/include/lattice/stdlatticeparms.h index 7d54c5e61..b5b1af50b 100644 --- a/src/core/include/lattice/stdlatticeparms.h +++ b/src/core/include/lattice/stdlatticeparms.h @@ -81,9 +81,9 @@ std::ostream& operator<<(std::ostream& s, SecurityLevel sl); class StdLatticeParm { DistributionType distType; - usint ringDim; + uint32_t ringDim; SecurityLevel minSecLev; - usint maxLogQ; + uint32_t maxLogQ; // NOTE!!! the declaration below relies upon there being three possible values // for the first index (the distribution type), and six possible values for @@ -96,14 +96,14 @@ class StdLatticeParm { // will suffer MAKE SURE that the number of entries in the DistributionType // enum is == the first index, and MAKE SURE that the number of entries in the // SecurityLevel enum is == the second index - static std::map byRing[3][6]; - static std::map byLogQ[3][6]; + static std::map byRing[3][6]; + static std::map byLogQ[3][6]; static std::vector StandardLatticeParmSets; static bool initialized; public: - StdLatticeParm(DistributionType distType, usint ringDim, SecurityLevel minSecLev, usint maxLogQ) + StdLatticeParm(DistributionType distType, uint32_t ringDim, SecurityLevel minSecLev, uint32_t maxLogQ) : distType(distType), ringDim(ringDim), minSecLev(minSecLev), maxLogQ(maxLogQ) {} static void initializeLookups() { @@ -115,7 +115,7 @@ class StdLatticeParm { initialized = true; } - static usint FindMaxQ(DistributionType distType, SecurityLevel minSecLev, usint ringDim) { + static uint32_t FindMaxQ(DistributionType distType, SecurityLevel minSecLev, uint32_t ringDim) { int distTypeIdx = static_cast(distType); int minSecLevIdx = static_cast(minSecLev); if (!initialized) @@ -126,14 +126,14 @@ class StdLatticeParm { return it->second->getMaxLogQ(); } - static usint FindRingDim(DistributionType distType, SecurityLevel minSecLev, usint curLogQ) { + static uint32_t FindRingDim(DistributionType distType, SecurityLevel minSecLev, uint32_t curLogQ) { if (!initialized) initializeLookups(); - usint prev = 0; + uint32_t prev = 0; int distTypeIdx = static_cast(distType); int minSecLevIdx = static_cast(minSecLev); - usint n = 0; + uint32_t n = 0; for (std::pair& it : byLogQ[distTypeIdx][minSecLevIdx]) { if ((curLogQ <= it.second->getMaxLogQ()) && (curLogQ > prev)) return it.second->getRingDim(); @@ -146,13 +146,13 @@ class StdLatticeParm { DistributionType getDistType() const { return distType; } - usint getRingDim() const { + uint32_t getRingDim() const { return ringDim; } SecurityLevel getMinSecLev() const { return minSecLev; } - usint getMaxLogQ() const { + uint32_t getMaxLogQ() const { return maxLogQ; } }; diff --git a/src/core/include/lattice/trapdoorparameters.h b/src/core/include/lattice/trapdoorparameters.h index 7b41a7c42..c189c148c 100644 --- a/src/core/include/lattice/trapdoorparameters.h +++ b/src/core/include/lattice/trapdoorparameters.h @@ -201,7 +201,7 @@ class RLWETrapdoorParams : public TrapdoorParams { *@brief Accessor function for ring size *@return Ring size */ - usint GetN() { + uint32_t GetN() { return m_n; } /* @@ -225,7 +225,7 @@ class RLWETrapdoorParams : public TrapdoorParams { int64_t m_base; size_t m_k; bool m_bal; - usint m_n; + uint32_t m_n; DggType m_dggLargeSigma; // DggType m_dggLargeSigma = DggType(0); }; diff --git a/src/core/include/math/binaryuniformgenerator-impl.h b/src/core/include/math/binaryuniformgenerator-impl.h index d9080b915..005936eed 100644 --- a/src/core/include/math/binaryuniformgenerator-impl.h +++ b/src/core/include/math/binaryuniformgenerator-impl.h @@ -54,10 +54,10 @@ typename VecType::Integer BinaryUniformGeneratorImpl::GenerateInteger() } template -VecType BinaryUniformGeneratorImpl::GenerateVector(const usint size, +VecType BinaryUniformGeneratorImpl::GenerateVector(const uint32_t size, const typename VecType::Integer& modulus) const { VecType v(size, modulus); - for (usint i = 0; i < size; i++) + for (uint32_t i = 0; i < size; i++) v[i] = GenerateInteger(); return v; } diff --git a/src/core/include/math/binaryuniformgenerator.h b/src/core/include/math/binaryuniformgenerator.h index e254cab1b..3697f52d1 100644 --- a/src/core/include/math/binaryuniformgenerator.h +++ b/src/core/include/math/binaryuniformgenerator.h @@ -69,7 +69,7 @@ class BinaryUniformGeneratorImpl { * Distribution. * @return A vector of random values within this Binary Uniform Distribution. */ - VecType GenerateVector(const usint size, const typename VecType::Integer& modulus) const; + VecType GenerateVector(const uint32_t size, const typename VecType::Integer& modulus) const; private: static std::bernoulli_distribution m_distribution; diff --git a/src/core/include/math/hal/bigintdyn/mubintvecdyn.h b/src/core/include/math/hal/bigintdyn/mubintvecdyn.h index 554f2bbcc..ee3a7fbb2 100644 --- a/src/core/include/math/hal/bigintdyn/mubintvecdyn.h +++ b/src/core/include/math/hal/bigintdyn/mubintvecdyn.h @@ -87,16 +87,16 @@ class mubintvec final : public lbcrypto::BigVectorInterface rhs) noexcept; + explicit mubintvec(uint32_t length, const ubint_el_t& modulus, std::initializer_list rhs) noexcept; /** * Basic constructor for specifying the length of the vector with @@ -154,7 +154,7 @@ class mubintvec final : public lbcrypto::BigVectorInterface rhs) noexcept; + explicit mubintvec(uint32_t length, const ubint_el_t& modulus, std::initializer_list rhs) noexcept; // constructor specifying the mubintvec as a vector of strings and modulus explicit mubintvec(const std::vector& s, const ubint_el_t& modulus) noexcept; @@ -204,7 +204,7 @@ class mubintvec final : public lbcrypto::BigVectorInterface rhs) noexcept; /** - * @param &&rhs is the usint value to assign to the zeroth entry + * @param &&rhs is the uint32_t value to assign to the zeroth entry * @return resulting mubintvec * note that modulus remains untouched. */ @@ -269,7 +269,7 @@ class mubintvec final : public lbcrypto::BigVectorInterface ChineseRemainderTransformArbDyn::m_DivisionNTTRootOfUnity; template -std::map ChineseRemainderTransformArbDyn::m_nttDivisionDim; +std::map ChineseRemainderTransformArbDyn::m_nttDivisionDim; template void NumberTheoreticTransformDyn::ForwardTransformIterative(const VecType& element, const VecType& rootOfUnityTable, VecType* result) { - usint n = element.GetLength(); + uint32_t n = element.GetLength(); if (result->GetLength() != n) { OPENFHE_THROW("size of input element and size of output element not of same size"); } @@ -129,24 +129,24 @@ void NumberTheoreticTransformDyn::ForwardTransformIterative(const VecTy IntType mu = modulus.ComputeMu(); result->SetModulus(modulus); - usint msb = GetMSB64(n - 1); + uint32_t msb = GetMSB64(n - 1); for (size_t i = 0; i < n; i++) { (*result)[i] = element[ReverseBits(i, msb)]; } IntType omega, omegaFactor, oddVal, evenVal; - usint logm, i, j, indexEven, indexOdd; + uint32_t logm, i, j, indexEven, indexOdd; - usint logn = GetMSB64(n - 1); + uint32_t logn = GetMSB64(n - 1); for (logm = 1; logm <= logn; logm++) { // calculate the i indexes into the root table one time per loop - std::vector indexes(1 << (logm - 1)); - for (i = 0; i < (usint)(1 << (logm - 1)); i++) { + std::vector indexes(1 << (logm - 1)); + for (i = 0; i < (uint32_t)(1 << (logm - 1)); i++) { indexes[i] = (i << (logn - logm)); } for (j = 0; j < n; j = j + (1 << logm)) { - for (i = 0; i < (usint)(1 << (logm - 1)); i++) { + for (i = 0; i < (uint32_t)(1 << (logm - 1)); i++) { omega = rootOfUnityTable[indexes[i]]; indexEven = j + i; indexOdd = indexEven + (1 << (logm - 1)); @@ -177,14 +177,14 @@ template void NumberTheoreticTransformDyn::InverseTransformIterative(const VecType& element, const VecType& rootOfUnityInverseTable, VecType* result) { - usint n = element.GetLength(); + uint32_t n = element.GetLength(); IntType modulus = element.GetModulus(); IntType mu = modulus.ComputeMu(); NumberTheoreticTransformDyn().ForwardTransformIterative(element, rootOfUnityInverseTable, result); IntType cycloOrderInv(IntType(n).ModInverse(modulus)); - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { (*result)[i].ModMulEq(cycloOrderInv, modulus, mu); } return; @@ -193,15 +193,15 @@ void NumberTheoreticTransformDyn::InverseTransformIterative(const VecTy template void NumberTheoreticTransformDyn::ForwardTransformToBitReverseInPlace(const VecType& rootOfUnityTable, VecType* element) { - usint n = element->GetLength(); + uint32_t n = element->GetLength(); IntType modulus = element->GetModulus(); IntType mu = modulus.ComputeMu(); - usint i, m, j1, j2, indexOmega, indexLo, indexHi; + uint32_t i, m, j1, j2, indexOmega, indexLo, indexHi; IntType omega, omegaFactor, loVal, hiVal, zero(0); - usint t = (n >> 1); - usint logt1 = GetMSB64(t); + uint32_t t = (n >> 1); + uint32_t logt1 = GetMSB64(t); for (m = 1; m < n; m <<= 1) { for (i = 0; i < m; ++i) { j1 = i << logt1; @@ -238,7 +238,7 @@ template void NumberTheoreticTransformDyn::ForwardTransformToBitReverse(const VecType& element, const VecType& rootOfUnityTable, VecType* result) { - usint n = element.GetLength(); + uint32_t n = element.GetLength(); if (result->GetLength() != n) { OPENFHE_THROW("size of input element and size of output element not of same size"); } @@ -247,15 +247,15 @@ void NumberTheoreticTransformDyn::ForwardTransformToBitReverse(const Ve IntType mu = modulus.ComputeMu(); result->SetModulus(modulus); - usint i, m, j1, j2, indexOmega, indexLo, indexHi; + uint32_t i, m, j1, j2, indexOmega, indexLo, indexHi; IntType omega, omegaFactor, loVal, hiVal, zero(0); for (i = 0; i < n; ++i) { (*result)[i] = element[i]; } - usint t = (n >> 1); - usint logt1 = GetMSB64(t); + uint32_t t = (n >> 1); + uint32_t logt1 = GetMSB64(t); for (m = 1; m < n; m <<= 1) { for (i = 0; i < m; ++i) { j1 = i << logt1; @@ -297,15 +297,15 @@ template void NumberTheoreticTransformDyn::ForwardTransformToBitReverseInPlace(const VecType& rootOfUnityTable, const VecType& preconRootOfUnityTable, VecType* element) { - usint n = element->GetLength(); + uint32_t n = element->GetLength(); IntType modulus = element->GetModulus(); uint32_t indexOmega, indexHi; IntType preconOmega; IntType omega, omegaFactor, loVal, hiVal, zero(0); - usint t = (n >> 1); - usint logt1 = GetMSB64(t); + uint32_t t = (n >> 1); + uint32_t logt1 = GetMSB64(t); for (uint32_t m = 1; m < n; m <<= 1, t >>= 1, --logt1) { uint32_t j1, j2; for (uint32_t i = 0; i < m; ++i) { @@ -343,7 +343,7 @@ void NumberTheoreticTransformDyn::ForwardTransformToBitReverse(const Ve const VecType& rootOfUnityTable, const VecType& preconRootOfUnityTable, VecType* result) { - usint n = element.GetLength(); + uint32_t n = element.GetLength(); if (result->GetLength() != n) { OPENFHE_THROW("size of input element and size of output element not of same size"); @@ -361,8 +361,8 @@ void NumberTheoreticTransformDyn::ForwardTransformToBitReverse(const Ve IntType preconOmega; IntType omega, omegaFactor, loVal, hiVal, zero(0); - usint t = (n >> 1); - usint logt1 = GetMSB64(t); + uint32_t t = (n >> 1); + uint32_t logt1 = GetMSB64(t); for (uint32_t m = 1; m < n; m <<= 1, t >>= 1, --logt1) { uint32_t j1, j2; for (uint32_t i = 0; i < m; ++i) { @@ -404,15 +404,15 @@ template void NumberTheoreticTransformDyn::InverseTransformFromBitReverseInPlace(const VecType& rootOfUnityInverseTable, const IntType& cycloOrderInv, VecType* element) { - usint n = element->GetLength(); + uint32_t n = element->GetLength(); IntType modulus = element->GetModulus(); IntType mu = modulus.ComputeMu(); IntType loVal, hiVal, omega, omegaFactor; - usint i, m, j1, j2, indexOmega, indexLo, indexHi; + uint32_t i, m, j1, j2, indexOmega, indexLo, indexHi; - usint t = 1; - usint logt1 = 1; + uint32_t t = 1; + uint32_t logt1 = 1; for (m = (n >> 1); m >= 1; m >>= 1) { for (i = 0; i < m; ++i) { j1 = i << logt1; @@ -459,7 +459,7 @@ void NumberTheoreticTransformDyn::InverseTransformFromBitReverse(const const VecType& rootOfUnityInverseTable, const IntType& cycloOrderInv, VecType* result) { - usint n = element.GetLength(); + uint32_t n = element.GetLength(); if (result->GetLength() != n) { OPENFHE_THROW("size of input element and size of output element not of same size"); @@ -467,7 +467,7 @@ void NumberTheoreticTransformDyn::InverseTransformFromBitReverse(const result->SetModulus(element.GetModulus()); - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { (*result)[i] = element[i]; } InverseTransformFromBitReverseInPlace(rootOfUnityInverseTable, cycloOrderInv, result); @@ -477,16 +477,16 @@ template void NumberTheoreticTransformDyn::InverseTransformFromBitReverseInPlace( const VecType& rootOfUnityInverseTable, const VecType& preconRootOfUnityInverseTable, const IntType& cycloOrderInv, const IntType& preconCycloOrderInv, VecType* element) { - usint n = element->GetLength(); + uint32_t n = element->GetLength(); IntType modulus = element->GetModulus(); IntType loVal, hiVal, omega, omegaFactor; IntType preconOmega; - usint i, m, j1, j2, indexOmega, indexLo, indexHi; + uint32_t i, m, j1, j2, indexOmega, indexLo, indexHi; - usint t = 1; - usint logt1 = 1; + uint32_t t = 1; + uint32_t logt1 = 1; for (m = (n >> 1); m >= 1; m >>= 1) { for (i = 0; i < m; ++i) { j1 = i << logt1; @@ -532,14 +532,14 @@ template void NumberTheoreticTransformDyn::InverseTransformFromBitReverse( const VecType& element, const VecType& rootOfUnityInverseTable, const VecType& preconRootOfUnityInverseTable, const IntType& cycloOrderInv, const IntType& preconCycloOrderInv, VecType* result) { - usint n = element.GetLength(); + uint32_t n = element.GetLength(); if (result->GetLength() != n) { OPENFHE_THROW("size of input element and size of output element not of same size"); } result->SetModulus(element.GetModulus()); - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { (*result)[i] = element[i]; } InverseTransformFromBitReverseInPlace(rootOfUnityInverseTable, preconRootOfUnityInverseTable, cycloOrderInv, @@ -550,7 +550,7 @@ void NumberTheoreticTransformDyn::InverseTransformFromBitReverse( template void ChineseRemainderTransformFTTDyn::ForwardTransformToBitReverseInPlace(const IntType& rootOfUnity, - const usint CycloOrder, + const uint32_t CycloOrder, VecType* element) { if (rootOfUnity == IntType(1) || rootOfUnity == IntType(0)) { return; @@ -560,7 +560,7 @@ void ChineseRemainderTransformFTTDyn::ForwardTransformToBitReverseInPla OPENFHE_THROW("CyclotomicOrder is not a power of two"); } - usint CycloOrderHf = (CycloOrder >> 1); + uint32_t CycloOrderHf = (CycloOrder >> 1); if (element->GetLength() != CycloOrderHf) { OPENFHE_THROW("element size must be equal to CyclotomicOrder / 2"); } @@ -585,7 +585,7 @@ void ChineseRemainderTransformFTTDyn::ForwardTransformToBitReverseInPla template void ChineseRemainderTransformFTTDyn::ForwardTransformToBitReverse(const VecType& element, const IntType& rootOfUnity, - const usint CycloOrder, VecType* result) { + const uint32_t CycloOrder, VecType* result) { if (rootOfUnity == IntType(1) || rootOfUnity == IntType(0)) { *result = element; return; @@ -595,7 +595,7 @@ void ChineseRemainderTransformFTTDyn::ForwardTransformToBitReverse(cons OPENFHE_THROW("CyclotomicOrder is not a power of two"); } - usint CycloOrderHf = (CycloOrder >> 1); + uint32_t CycloOrderHf = (CycloOrder >> 1); if (result->GetLength() != CycloOrderHf) { OPENFHE_THROW("result size must be equal to CyclotomicOrder / 2"); } @@ -621,7 +621,7 @@ void ChineseRemainderTransformFTTDyn::ForwardTransformToBitReverse(cons template void ChineseRemainderTransformFTTDyn::InverseTransformFromBitReverseInPlace(const IntType& rootOfUnity, - const usint CycloOrder, + const uint32_t CycloOrder, VecType* element) { if (rootOfUnity == IntType(1) || rootOfUnity == IntType(0)) { return; @@ -631,7 +631,7 @@ void ChineseRemainderTransformFTTDyn::InverseTransformFromBitReverseInP OPENFHE_THROW("CyclotomicOrder is not a power of two"); } - usint CycloOrderHf = (CycloOrder >> 1); + uint32_t CycloOrderHf = (CycloOrder >> 1); if (element->GetLength() != CycloOrderHf) { OPENFHE_THROW("element size must be equal to CyclotomicOrder / 2"); } @@ -643,7 +643,7 @@ void ChineseRemainderTransformFTTDyn::InverseTransformFromBitReverseInP PreCompute(rootOfUnity, CycloOrder, modulus); } - usint msb = GetMSB64(CycloOrderHf - 1); + uint32_t msb = GetMSB64(CycloOrderHf - 1); // if (typeid(IntType) == typeid(NativeInteger)) { // NumberTheoreticTransformDyn().InverseTransformFromBitReverseInPlace( // m_rootOfUnityInverseReverseTableByModulus[modulus], @@ -659,7 +659,7 @@ void ChineseRemainderTransformFTTDyn::InverseTransformFromBitReverseInP template void ChineseRemainderTransformFTTDyn::InverseTransformFromBitReverse(const VecType& element, const IntType& rootOfUnity, - const usint CycloOrder, VecType* result) { + const uint32_t CycloOrder, VecType* result) { if (rootOfUnity == IntType(1) || rootOfUnity == IntType(0)) { *result = element; return; @@ -669,7 +669,7 @@ void ChineseRemainderTransformFTTDyn::InverseTransformFromBitReverse(co OPENFHE_THROW("CyclotomicOrder is not a power of two"); } - usint CycloOrderHf = (CycloOrder >> 1); + uint32_t CycloOrderHf = (CycloOrder >> 1); if (result->GetLength() != CycloOrderHf) { OPENFHE_THROW("result size must be equal to CyclotomicOrder / 2"); } @@ -681,13 +681,13 @@ void ChineseRemainderTransformFTTDyn::InverseTransformFromBitReverse(co PreCompute(rootOfUnity, CycloOrder, modulus); } - usint n = element.GetLength(); + uint32_t n = element.GetLength(); result->SetModulus(element.GetModulus()); - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { (*result)[i] = element[i]; } - usint msb = GetMSB64(CycloOrderHf - 1); + uint32_t msb = GetMSB64(CycloOrderHf - 1); // if (typeid(IntType) == typeid(NativeInteger)) { // NumberTheoreticTransformDyn().InverseTransformFromBitReverseInPlace( // m_rootOfUnityInverseReverseTableByModulus[modulus], @@ -704,23 +704,23 @@ void ChineseRemainderTransformFTTDyn::InverseTransformFromBitReverse(co } template -void ChineseRemainderTransformFTTDyn::PreCompute(const IntType& rootOfUnity, const usint CycloOrder, +void ChineseRemainderTransformFTTDyn::PreCompute(const IntType& rootOfUnity, const uint32_t CycloOrder, const IntType& modulus) { // Half of cyclo order - usint CycloOrderHf = (CycloOrder >> 1); + uint32_t CycloOrderHf = (CycloOrder >> 1); auto mapSearch = m_rootOfUnityReverseTableByModulus.find(modulus); if (mapSearch == m_rootOfUnityReverseTableByModulus.end() || mapSearch->second.GetLength() != CycloOrderHf) { #pragma omp critical { IntType x(1), xinv(1); - usint msb = GetMSB64(CycloOrderHf - 1); + uint32_t msb = GetMSB64(CycloOrderHf - 1); IntType mu = modulus.ComputeMu(); VecType Table(CycloOrderHf, modulus); VecType TableI(CycloOrderHf, modulus); IntType rootOfUnityInverse = rootOfUnity.ModInverse(modulus); - usint iinv; - for (usint i = 0; i < CycloOrderHf; i++) { + uint32_t iinv; + for (uint32_t i = 0; i < CycloOrderHf; i++) { iinv = ReverseBits(i, msb); Table[iinv] = x; TableI[iinv] = xinv; @@ -731,7 +731,7 @@ void ChineseRemainderTransformFTTDyn::PreCompute(const IntType& rootOfU m_rootOfUnityInverseReverseTableByModulus[modulus] = TableI; VecType TableCOI(msb + 1, modulus); - for (usint i = 0; i < msb + 1; i++) { + for (uint32_t i = 0; i < msb + 1; i++) { IntType coInv(IntType(1 << i).ModInverse(modulus)); TableCOI[i] = coInv; } @@ -742,7 +742,7 @@ void ChineseRemainderTransformFTTDyn::PreCompute(const IntType& rootOfU // VecType preconTable(CycloOrderHf, nativeModulus); // VecType preconTableI(CycloOrderHf, nativeModulus); - // for (usint i = 0; i < CycloOrderHf; i++) { + // for (uint32_t i = 0; i < CycloOrderHf; i++) { // preconTable[i] = // NativeInteger( // m_rootOfUnityReverseTableByModulus[modulus][i].ConvertToInt()) @@ -755,7 +755,7 @@ void ChineseRemainderTransformFTTDyn::PreCompute(const IntType& rootOfU // } // VecType preconTableCOI(msb + 1, nativeModulus); - // for (usint i = 0; i < msb + 1; i++) { + // for (uint32_t i = 0; i < msb + 1; i++) { // preconTableCOI[i] = // NativeInteger( // m_cycloOrderInverseTableByModulus[modulus][i].ConvertToInt()) @@ -771,16 +771,16 @@ void ChineseRemainderTransformFTTDyn::PreCompute(const IntType& rootOfU } template -void ChineseRemainderTransformFTTDyn::PreCompute(std::vector& rootOfUnity, const usint CycloOrder, +void ChineseRemainderTransformFTTDyn::PreCompute(std::vector& rootOfUnity, const uint32_t CycloOrder, std::vector& moduliiChain) { - usint numOfRootU = rootOfUnity.size(); - usint numModulii = moduliiChain.size(); + uint32_t numOfRootU = rootOfUnity.size(); + uint32_t numModulii = moduliiChain.size(); if (numOfRootU != numModulii) { OPENFHE_THROW("size of root of unity and size of moduli chain not of same size"); } - for (usint i = 0; i < numOfRootU; ++i) { + for (uint32_t i = 0; i < numOfRootU; ++i) { IntType currentRoot(rootOfUnity[i]); IntType currentMod(moduliiChain[i]); PreCompute(currentRoot, CycloOrder, currentMod); @@ -798,8 +798,8 @@ void ChineseRemainderTransformFTTDyn::Reset() { } template -void BluesteinFFTDyn::PreComputeDefaultNTTModulusRoot(usint cycloOrder, const IntType& modulus) { - usint nttDim = std::pow(2, std::ceil(std::log2(2 * cycloOrder - 1))); +void BluesteinFFTDyn::PreComputeDefaultNTTModulusRoot(uint32_t cycloOrder, const IntType& modulus) { + uint32_t nttDim = std::pow(2, std::ceil(std::log2(2 * cycloOrder - 1))); const auto nttModulus = LastPrime(std::log2(nttDim) + 2 * modulus.GetMSB(), nttDim); const auto nttRoot = RootOfUnity(nttDim, nttModulus); const ModulusRoot nttModulusRoot = {nttModulus, nttRoot}; @@ -809,9 +809,9 @@ void BluesteinFFTDyn::PreComputeDefaultNTTModulusRoot(usint cycloOrder, } template -void BluesteinFFTDyn::PreComputeRootTableForNTT(usint cyclotoOrder, +void BluesteinFFTDyn::PreComputeRootTableForNTT(uint32_t cyclotoOrder, const ModulusRoot& nttModulusRoot) { - usint nttDim = std::pow(2, std::ceil(std::log2(2 * cyclotoOrder - 1))); + uint32_t nttDim = std::pow(2, std::ceil(std::log2(2 * cyclotoOrder - 1))); const auto& nttModulus = nttModulusRoot.first; const auto& nttRoot = nttModulusRoot.second; @@ -819,18 +819,18 @@ void BluesteinFFTDyn::PreComputeRootTableForNTT(usint cyclotoOrder, auto rootInv = root.ModInverse(nttModulus); - usint nttDimHf = (nttDim >> 1); + uint32_t nttDimHf = (nttDim >> 1); VecType rootTable(nttDimHf, nttModulus); VecType rootTableInverse(nttDimHf, nttModulus); IntType x(1); - for (usint i = 0; i < nttDimHf; i++) { + for (uint32_t i = 0; i < nttDimHf; i++) { rootTable[i] = x; x = x.ModMul(root, nttModulus); } x = 1; - for (usint i = 0; i < nttDimHf; i++) { + for (uint32_t i = 0; i < nttDimHf; i++) { rootTableInverse[i] = x; x = x.ModMul(rootInv, nttModulus); } @@ -840,13 +840,13 @@ void BluesteinFFTDyn::PreComputeRootTableForNTT(usint cyclotoOrder, } template -void BluesteinFFTDyn::PreComputePowers(usint cycloOrder, const ModulusRoot& modulusRoot) { +void BluesteinFFTDyn::PreComputePowers(uint32_t cycloOrder, const ModulusRoot& modulusRoot) { const auto& modulus = modulusRoot.first; const auto& root = modulusRoot.second; VecType powers(cycloOrder, modulus); powers[0] = 1; - for (usint i = 1; i < cycloOrder; i++) { + for (uint32_t i = 1; i < cycloOrder; i++) { auto iSqr = (i * i) % (2 * cycloOrder); auto val = root.ModExp(IntType(iSqr), modulus); powers[i] = val; @@ -855,7 +855,7 @@ void BluesteinFFTDyn::PreComputePowers(usint cycloOrder, const ModulusR } template -void BluesteinFFTDyn::PreComputeRBTable(usint cycloOrder, const ModulusRootPair& modulusRootPair) { +void BluesteinFFTDyn::PreComputeRBTable(uint32_t cycloOrder, const ModulusRootPair& modulusRootPair) { const auto& modulusRoot = modulusRootPair.first; const auto& modulus = modulusRoot.first; const auto& root = modulusRoot.second; @@ -866,11 +866,11 @@ void BluesteinFFTDyn::PreComputeRBTable(usint cycloOrder, const Modulus // const auto &nttRoot = nttModulusRoot.second; // assumes rootTable is precomputed const auto& rootTable = m_rootOfUnityTableByModulusRoot[nttModulusRoot]; - usint nttDim = std::pow(2, std::ceil(std::log2(2 * cycloOrder - 1))); + uint32_t nttDim = std::pow(2, std::ceil(std::log2(2 * cycloOrder - 1))); VecType b(2 * cycloOrder - 1, modulus); b[cycloOrder - 1] = 1; - for (usint i = 1; i < cycloOrder; i++) { + for (uint32_t i = 1; i < cycloOrder; i++) { auto iSqr = (i * i) % (2 * cycloOrder); auto val = rootInv.ModExp(IntType(iSqr), modulus); b[cycloOrder - 1 + i] = val; @@ -887,7 +887,7 @@ void BluesteinFFTDyn::PreComputeRBTable(usint cycloOrder, const Modulus template VecType BluesteinFFTDyn::ForwardTransform(const VecType& element, const IntType& root, - const usint cycloOrder) { + const uint32_t cycloOrder) { const auto& modulus = element.GetModulus(); const auto& nttModulusRoot = m_defaultNTTModulusRoot[modulus]; @@ -895,7 +895,7 @@ VecType BluesteinFFTDyn::ForwardTransform(const VecType& element, const } template -VecType BluesteinFFTDyn::ForwardTransform(const VecType& element, const IntType& root, const usint cycloOrder, +VecType BluesteinFFTDyn::ForwardTransform(const VecType& element, const IntType& root, const uint32_t cycloOrder, const ModulusRoot& nttModulusRoot) { if (element.GetLength() != cycloOrder) { OPENFHE_THROW("expected size of element vector should be equal to cyclotomic order"); @@ -912,7 +912,7 @@ VecType BluesteinFFTDyn::ForwardTransform(const VecType& element, const m_rootOfUnityInverseTableByModulusRoot[nttModulusRoot]; // assumes rootTableInverse is precomputed VecType x = element.ModMul(powers); - usint nttDim = std::pow(2, std::ceil(std::log2(2 * cycloOrder - 1))); + uint32_t nttDim = std::pow(2, std::ceil(std::log2(2 * cycloOrder - 1))); auto Ra = PadZeros(x, nttDim); Ra.SetModulus(nttModulus); VecType RA(nttDim); @@ -933,15 +933,15 @@ VecType BluesteinFFTDyn::ForwardTransform(const VecType& element, const } template -VecType BluesteinFFTDyn::PadZeros(const VecType& a, const usint finalSize) { - usint s = a.GetLength(); +VecType BluesteinFFTDyn::PadZeros(const VecType& a, const uint32_t finalSize) { + uint32_t s = a.GetLength(); VecType result(finalSize, a.GetModulus()); - for (usint i = 0; i < s; i++) { + for (uint32_t i = 0; i < s; i++) { result[i] = a[i]; } - for (usint i = a.GetLength(); i < finalSize; i++) { + for (uint32_t i = a.GetLength(); i < finalSize; i++) { result[i] = IntType(0); } @@ -949,10 +949,10 @@ VecType BluesteinFFTDyn::PadZeros(const VecType& a, const usint finalSi } template -VecType BluesteinFFTDyn::Resize(const VecType& a, usint lo, usint hi) { +VecType BluesteinFFTDyn::Resize(const VecType& a, uint32_t lo, uint32_t hi) { VecType result(hi - lo + 1, a.GetModulus()); - for (usint i = lo, j = 0; i <= hi; i++, j++) { + for (uint32_t i = lo, j = 0; i <= hi; i++, j++) { result[j] = a[i]; } @@ -974,12 +974,12 @@ void ChineseRemainderTransformArbDyn::SetCylotomicPolynomial(const VecT } template -void ChineseRemainderTransformArbDyn::PreCompute(const usint cyclotoOrder, const IntType& modulus) { +void ChineseRemainderTransformArbDyn::PreCompute(const uint32_t cyclotoOrder, const IntType& modulus) { BluesteinFFTDyn().PreComputeDefaultNTTModulusRoot(cyclotoOrder, modulus); } template -void ChineseRemainderTransformArbDyn::SetPreComputedNTTModulus(usint cyclotoOrder, const IntType& modulus, +void ChineseRemainderTransformArbDyn::SetPreComputedNTTModulus(uint32_t cyclotoOrder, const IntType& modulus, const IntType& nttModulus, const IntType& nttRoot) { const ModulusRoot nttModulusRoot = {nttModulus, nttRoot}; @@ -988,15 +988,15 @@ void ChineseRemainderTransformArbDyn::SetPreComputedNTTModulus(usint cy } template -void ChineseRemainderTransformArbDyn::SetPreComputedNTTDivisionModulus(usint cyclotoOrder, +void ChineseRemainderTransformArbDyn::SetPreComputedNTTDivisionModulus(uint32_t cyclotoOrder, const IntType& modulus, const IntType& nttMod, const IntType& nttRootBig) { - usint n = GetTotient(cyclotoOrder); - usint power = cyclotoOrder - n; + uint32_t n = GetTotient(cyclotoOrder); + uint32_t power = cyclotoOrder - n; m_nttDivisionDim[cyclotoOrder] = 2 * std::pow(2, std::ceil(std::log2(power))); - usint nttDimBig = std::pow(2, std::ceil(std::log2(2 * cyclotoOrder - 1))); + uint32_t nttDimBig = std::pow(2, std::ceil(std::log2(2 * cyclotoOrder - 1))); // Computes the root of unity for the division NTT based on the root of unity // for regular NTT @@ -1005,22 +1005,22 @@ void ChineseRemainderTransformArbDyn::SetPreComputedNTTDivisionModulus( m_DivisionNTTModulus[modulus] = nttMod; m_DivisionNTTRootOfUnity[modulus] = nttRoot; // part0 setting of rootTable and inverse rootTable - usint nttDim = m_nttDivisionDim[cyclotoOrder]; + uint32_t nttDim = m_nttDivisionDim[cyclotoOrder]; IntType root(nttRoot); auto rootInv = root.ModInverse(nttMod); - usint nttDimHf = (nttDim >> 1); + uint32_t nttDimHf = (nttDim >> 1); VecType rootTable(nttDimHf, nttMod); VecType rootTableInverse(nttDimHf, nttMod); IntType x(1); - for (usint i = 0; i < nttDimHf; i++) { + for (uint32_t i = 0; i < nttDimHf; i++) { rootTable[i] = x; x = x.ModMul(root, nttMod); } x = 1; - for (usint i = 0; i < nttDimHf; i++) { + for (uint32_t i = 0; i < nttDimHf; i++) { rootTableInverse[i] = x; x = x.ModMul(rootInv, nttMod); } @@ -1042,7 +1042,7 @@ void ChineseRemainderTransformArbDyn::SetPreComputedNTTDivisionModulus( const auto& cycloPoly = m_cyclotomicPolyMap[modulus]; VecType QForwardTransform(nttDim, nttMod); - for (usint i = 0; i < cycloPoly.GetLength(); i++) { + for (uint32_t i = 0; i < cycloPoly.GetLength(); i++) { QForwardTransform[i] = cycloPoly[i]; } @@ -1054,17 +1054,17 @@ void ChineseRemainderTransformArbDyn::SetPreComputedNTTDivisionModulus( template VecType ChineseRemainderTransformArbDyn::InversePolyMod(const VecType& cycloPoly, const IntType& modulus, - usint power) { + uint32_t power) { VecType result(power, modulus); - usint r = std::ceil(std::log2(power)); + uint32_t r = std::ceil(std::log2(power)); VecType h(1, modulus); // h is a unit polynomial h[0] = 1; // Precompute the Barrett mu parameter IntType mu = modulus.ComputeMu(); - for (usint i = 0; i < r; i++) { - usint qDegree = std::pow(2, i + 1); + for (uint32_t i = 0; i < r; i++) { + uint32_t qDegree = std::pow(2, i + 1); VecType q(qDegree + 1, modulus); // q = x^(2^i+1) q[qDegree] = 1; auto hSquare = PolynomialMultiplication(h, h); @@ -1072,7 +1072,7 @@ VecType ChineseRemainderTransformArbDyn::InversePolyMod(const VecType& auto a = h * IntType(2); auto b = PolynomialMultiplication(hSquare, cycloPoly); // b = 2h - gh^2 - for (usint j = 0; j < b.GetLength(); j++) { + for (uint32_t j = 0; j < b.GetLength(); j++) { if (j < a.GetLength()) { b[j] = a[j].ModSub(b[j], modulus, mu); } @@ -1083,7 +1083,7 @@ VecType ChineseRemainderTransformArbDyn::InversePolyMod(const VecType& h = PolyMod(b, q, modulus); } // take modulo x^power - for (usint i = 0; i < power; i++) { + for (uint32_t i = 0; i < power; i++) { result[i] = h[i]; } @@ -1093,8 +1093,8 @@ VecType ChineseRemainderTransformArbDyn::InversePolyMod(const VecType& template VecType ChineseRemainderTransformArbDyn::ForwardTransform(const VecType& element, const IntType& root, const IntType& nttModulus, const IntType& nttRoot, - const usint cycloOrder) { - usint phim = GetTotient(cycloOrder); + const uint32_t cycloOrder) { + uint32_t phim = GetTotient(cycloOrder); if (element.GetLength() != phim) { OPENFHE_THROW("element size should be equal to phim"); } @@ -1131,8 +1131,8 @@ VecType ChineseRemainderTransformArbDyn::ForwardTransform(const VecType template VecType ChineseRemainderTransformArbDyn::InverseTransform(const VecType& element, const IntType& root, const IntType& nttModulus, const IntType& nttRoot, - const usint cycloOrder) { - usint phim = GetTotient(cycloOrder); + const uint32_t cycloOrder) { + uint32_t phim = GetTotient(cycloOrder); if (element.GetLength() != phim) { OPENFHE_THROW("element size should be equal to phim"); } @@ -1168,20 +1168,20 @@ VecType ChineseRemainderTransformArbDyn::InverseTransform(const VecType } template -VecType ChineseRemainderTransformArbDyn::Pad(const VecType& element, const usint cycloOrder, bool forward) { - usint n = GetTotient(cycloOrder); +VecType ChineseRemainderTransformArbDyn::Pad(const VecType& element, const uint32_t cycloOrder, bool forward) { + uint32_t n = GetTotient(cycloOrder); const auto& modulus = element.GetModulus(); VecType inputToBluestein(cycloOrder, modulus); if (forward) { // Forward transform padding - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { inputToBluestein[i] = element[i]; } } else { // Inverse transform padding auto tList = GetTotientList(cycloOrder); - usint i = 0; + uint32_t i = 0; for (auto& coprime : tList) { inputToBluestein[coprime] = element[i++]; } @@ -1191,16 +1191,16 @@ VecType ChineseRemainderTransformArbDyn::Pad(const VecType& element, co } template -VecType ChineseRemainderTransformArbDyn::Drop(const VecType& element, const usint cycloOrder, bool forward, +VecType ChineseRemainderTransformArbDyn::Drop(const VecType& element, const uint32_t cycloOrder, bool forward, const IntType& bigMod, const IntType& bigRoot) { - usint n = GetTotient(cycloOrder); + uint32_t n = GetTotient(cycloOrder); const auto& modulus = element.GetModulus(); VecType output(n, modulus); if (forward) { // Forward transform drop auto tList = GetTotientList(cycloOrder); - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { output[i] = element[tList[i]]; } } @@ -1210,7 +1210,7 @@ VecType ChineseRemainderTransformArbDyn::Drop(const VecType& element, c // cycloOrder is prime: Reduce mod Phi_{n+1}(x) // Reduction involves subtracting the coeff of x^n from all terms auto coeff_n = element[n]; - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { output[i] = element[i].ModSub(coeff_n, modulus, mu); } } @@ -1219,7 +1219,7 @@ VecType ChineseRemainderTransformArbDyn::Drop(const VecType& element, c // cycloOrder is 2*prime: 2 Step reduction // First reduce mod x^(n+1)+1 (=(x+1)*Phi_{2*(n+1)}(x)) // Subtract co-efficient of x^(i+n+1) from x^(i) - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { auto coeff_i = element[i]; auto coeff_ip = element[i + n + 1]; output[i] = coeff_i.ModSub(coeff_ip, modulus, mu); @@ -1227,7 +1227,7 @@ VecType ChineseRemainderTransformArbDyn::Drop(const VecType& element, c auto coeff_n = element[n].ModSub(element[2 * n + 1], modulus, mu); // Now reduce mod Phi_{2*(n+1)}(x) // Similar to the prime case but with alternating signs - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { if (i % 2 == 0) { output[i].ModSubEq(coeff_n, modulus, mu); } @@ -1251,8 +1251,8 @@ VecType ChineseRemainderTransformArbDyn::Drop(const VecType& element, c const auto& rootTable = m_rootOfUnityDivisionTableByModulus[nttMod]; VecType aPadded2(m_nttDivisionDim[cycloOrder], nttMod); // perform mod operation - usint power = cycloOrder - n; - for (usint i = n; i < element.GetLength(); i++) { + uint32_t power = cycloOrder - n; + for (uint32_t i = n; i < element.GetLength(); i++) { aPadded2[power - (i - n) - 1] = element[i]; } VecType A(m_nttDivisionDim[cycloOrder]); @@ -1263,7 +1263,7 @@ VecType ChineseRemainderTransformArbDyn::Drop(const VecType& element, c NumberTheoreticTransformDyn().InverseTransformIterative(AB, rootTableInverse, &a); VecType quotient(m_nttDivisionDim[cycloOrder], modulus); - for (usint i = 0; i < power; i++) { + for (uint32_t i = 0; i < power; i++) { quotient[i] = a[i]; } quotient.ModEq(modulus); @@ -1281,7 +1281,7 @@ VecType ChineseRemainderTransformArbDyn::Drop(const VecType& element, c IntType mu = modulus.ComputeMu(); // Precompute the Barrett mu parameter - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { output[i] = element[i].ModSub(newQuotient2[cycloOrder - 1 - i], modulus, mu); } } diff --git a/src/core/include/math/hal/bigintdyn/transformdyn.h b/src/core/include/math/hal/bigintdyn/transformdyn.h index 2167a3c64..df2eb8a09 100644 --- a/src/core/include/math/hal/bigintdyn/transformdyn.h +++ b/src/core/include/math/hal/bigintdyn/transformdyn.h @@ -254,7 +254,7 @@ class ChineseRemainderTransformFTTDyn final : public lbcrypto::ChineseRemainderT * size as input or a throw of error occurs. * @see NumberTheoreticTransform::ForwardTransformToBitReverseInPlace() */ - void ForwardTransformToBitReverse(const VecType& element, const IntType& rootOfUnity, const usint CycloOrder, + void ForwardTransformToBitReverse(const VecType& element, const IntType& rootOfUnity, const uint32_t CycloOrder, VecType* result); /** @@ -270,7 +270,7 @@ class ChineseRemainderTransformFTTDyn final : public lbcrypto::ChineseRemainderT * @return none * @see NumberTheoreticTransform::ForwardTransformToBitReverseInPlace() */ - void ForwardTransformToBitReverseInPlace(const IntType& rootOfUnity, const usint CycloOrder, VecType* element); + void ForwardTransformToBitReverseInPlace(const IntType& rootOfUnity, const uint32_t CycloOrder, VecType* element); /** * Copies \p element into \p result and calls NumberTheoreticTransform::InverseTransformFromBitReverseInPlace() @@ -289,7 +289,7 @@ class ChineseRemainderTransformFTTDyn final : public lbcrypto::ChineseRemainderT * @return none * @see NumberTheoreticTransform::InverseTransformFromBitReverseInPlace() */ - void InverseTransformFromBitReverse(const VecType& element, const IntType& rootOfUnity, const usint CycloOrder, + void InverseTransformFromBitReverse(const VecType& element, const IntType& rootOfUnity, const uint32_t CycloOrder, VecType* result); /** @@ -305,7 +305,7 @@ class ChineseRemainderTransformFTTDyn final : public lbcrypto::ChineseRemainderT * @return none * @see NumberTheoreticTransform::InverseTransformFromBitReverseInPlace() */ - void InverseTransformFromBitReverseInPlace(const IntType& rootOfUnity, const usint CycloOrder, VecType* element); + void InverseTransformFromBitReverseInPlace(const IntType& rootOfUnity, const uint32_t CycloOrder, VecType* element); /** * Precomputation of root of unity tables for transforms in the ring @@ -317,7 +317,7 @@ class ChineseRemainderTransformFTTDyn final : public lbcrypto::ChineseRemainderT * @param CycloOrder is a power-of-two, equal to 2n. * @param modulus is q, the prime modulus */ - void PreCompute(const IntType& rootOfUnity, const usint CycloOrder, const IntType& modulus); + void PreCompute(const IntType& rootOfUnity, const uint32_t CycloOrder, const IntType& modulus); /** * Precomputation of root of unity tables for transforms in the ring @@ -329,7 +329,7 @@ class ChineseRemainderTransformFTTDyn final : public lbcrypto::ChineseRemainderT * @param CycloOrder is a power-of-two, equal to 2n. * @param &moduliChain is the vector of prime moduli qi such that 2n|qi-1 */ - void PreCompute(std::vector& rootOfUnity, const usint CycloOrder, std::vector& moduliChain); + void PreCompute(std::vector& rootOfUnity, const uint32_t CycloOrder, std::vector& moduliChain); /** * Reset cached values for the root of unity tables to empty. @@ -380,8 +380,8 @@ class BluesteinFFTDyn { * @param cycloOrder is the cyclotomic order. * @return is the output result of the transform. */ - VecType ForwardTransform(const VecType& element, const IntType& root, const usint cycloOrder); - VecType ForwardTransform(const VecType& element, const IntType& root, const usint cycloOrder, + VecType ForwardTransform(const VecType& element, const IntType& root, const uint32_t cycloOrder); + VecType ForwardTransform(const VecType& element, const IntType& root, const uint32_t cycloOrder, const ModulusRoot& nttModulusRoot); /** @@ -391,7 +391,7 @@ class BluesteinFFTDyn { * @return output vector padded with (finalSize - initial size)additional * zeros. */ - VecType PadZeros(const VecType& a, const usint finalSize); + VecType PadZeros(const VecType& a, const uint32_t finalSize); /** * @@ -400,9 +400,9 @@ class BluesteinFFTDyn { * @param hi is higher coefficient index. * @return output vector s.t output vector = a[lo]...a[hi]. */ - VecType Resize(const VecType& a, usint lo, usint hi); + VecType Resize(const VecType& a, uint32_t lo, uint32_t hi); - // void PreComputeNTTModulus(usint cycloOrder, const std::vector + // void PreComputeNTTModulus(uint32_t cycloOrder, const std::vector // &modulii); /** @@ -411,7 +411,7 @@ class BluesteinFFTDyn { * @param cycloOrder is the cyclotomic order of the polynomial. * @param modulus is the modulus of the polynomial. */ - void PreComputeDefaultNTTModulusRoot(usint cycloOrder, const IntType& modulus); + void PreComputeDefaultNTTModulusRoot(uint32_t cycloOrder, const IntType& modulus); /** * @brief Precomputes the root of unity table needed for NTT operation in @@ -419,7 +419,7 @@ class BluesteinFFTDyn { * @param cycloOrder is the cyclotomic order of the polynomial ring. * @param modulus is the modulus of the polynomial. */ - void PreComputeRootTableForNTT(usint cycloOrder, const ModulusRoot& nttModulusRoot); + void PreComputeRootTableForNTT(uint32_t cycloOrder, const ModulusRoot& nttModulusRoot); /** * @brief precomputes the powers of root used in forward Bluestein transform. @@ -427,7 +427,7 @@ class BluesteinFFTDyn { * @param modulus is the modulus of the polynomial ring. * @param root is the root of unity s.t. root^2m = 1. */ - void PreComputePowers(usint cycloOrder, const ModulusRoot& modulusRoot); + void PreComputePowers(uint32_t cycloOrder, const ModulusRoot& modulusRoot); /** * @brief precomputes the NTT transform of the power of root of unity used in @@ -438,7 +438,7 @@ class BluesteinFFTDyn { * @param bigMod is the modulus required for the NTT transform. * @param bigRoot is the root of unity required for the NTT transform. */ - void PreComputeRBTable(usint cycloOrder, const ModulusRootPair& modulusRootPair); + void PreComputeRBTable(uint32_t cycloOrder, const ModulusRootPair& modulusRootPair); /** * Reset cached values for the transform to empty. @@ -490,7 +490,7 @@ class ChineseRemainderTransformArbDyn final : public lbcrypto::ChineseRemainderT * @return is the output result of the transform. */ VecType ForwardTransform(const VecType& element, const IntType& root, const IntType& bigMod, const IntType& bigRoot, - const usint cycloOrder); + const uint32_t cycloOrder); /** * Inverse transform. @@ -504,7 +504,7 @@ class ChineseRemainderTransformArbDyn final : public lbcrypto::ChineseRemainderT * @return is the output result of the transform. */ VecType InverseTransform(const VecType& element, const IntType& root, const IntType& bigMod, const IntType& bigRoot, - const usint cycloOrder); + const uint32_t cycloOrder); /** * Reset cached values for the transform to empty. @@ -517,7 +517,7 @@ class ChineseRemainderTransformArbDyn final : public lbcrypto::ChineseRemainderT * @param cycloOrder is the cyclotomic order of the polynomial ring. * @param modulus is the modulus of the polynomial ring. */ - void PreCompute(const usint cyclotoOrder, const IntType& modulus); + void PreCompute(const uint32_t cyclotoOrder, const IntType& modulus); /** * @brief Sets the precomputed root of unity and modulus needed for NTT @@ -529,7 +529,7 @@ class ChineseRemainderTransformArbDyn final : public lbcrypto::ChineseRemainderT * @param nttRoot is the root of unity needed for the NTT operation in forward * Bluestein transform. */ - void SetPreComputedNTTModulus(usint cyclotoOrder, const IntType& modulus, const IntType& nttMod, + void SetPreComputedNTTModulus(uint32_t cyclotoOrder, const IntType& modulus, const IntType& nttMod, const IntType& nttRoot); /** @@ -543,7 +543,7 @@ class ChineseRemainderTransformArbDyn final : public lbcrypto::ChineseRemainderT * @param nttRoot is the root of unity needed for the NTT operation in forward * Bluestein transform. */ - void SetPreComputedNTTDivisionModulus(usint cyclotoOrder, const IntType& modulus, const IntType& nttMod, + void SetPreComputedNTTDivisionModulus(uint32_t cyclotoOrder, const IntType& modulus, const IntType& nttMod, const IntType& nttRoot); /** @@ -553,7 +553,7 @@ class ChineseRemainderTransformArbDyn final : public lbcrypto::ChineseRemainderT * @param modulus is the modulus of the polynomial ring. * @return inverse polynomial. */ - VecType InversePolyMod(const VecType& cycloPoly, const IntType& modulus, usint power); + VecType InversePolyMod(const VecType& cycloPoly, const IntType& modulus, uint32_t power); private: /** @@ -563,7 +563,7 @@ class ChineseRemainderTransformArbDyn final : public lbcrypto::ChineseRemainderT * @param forward is a flag for forward/inverse transform padding. * @return is result vector with &element values with padded zeros to it */ - VecType Pad(const VecType& element, const usint cycloOrder, bool forward); + VecType Pad(const VecType& element, const uint32_t cycloOrder, bool forward); /** * @brief Dropping elements from a vector @@ -576,7 +576,7 @@ class ChineseRemainderTransformArbDyn final : public lbcrypto::ChineseRemainderT * tables if needed. The tables are used in the inverse dropping computations * @return is result vector with &element values with dropped elements from it */ - VecType Drop(const VecType& element, const usint cycloOrder, bool forward, const IntType& bigMod, + VecType Drop(const VecType& element, const uint32_t cycloOrder, bool forward, const IntType& bigMod, const IntType& bigRoot); // map to store the cyclotomic polynomial with polynomial ring's modulus as @@ -605,7 +605,7 @@ class ChineseRemainderTransformArbDyn final : public lbcrypto::ChineseRemainderT static std::map m_DivisionNTTRootOfUnity; // dimension of the NTT transform in NTT based polynomial division. - static std::map m_nttDivisionDim; + static std::map m_nttDivisionDim; }; } // namespace bigintdyn diff --git a/src/core/include/math/hal/bigintdyn/ubintdyn.h b/src/core/include/math/hal/bigintdyn/ubintdyn.h index d6c96a9d3..47f61cea2 100644 --- a/src/core/include/math/hal/bigintdyn/ubintdyn.h +++ b/src/core/include/math/hal/bigintdyn/ubintdyn.h @@ -87,13 +87,13 @@ class mubintvec; * @brief Struct to find log 2 value of N. * Used in preprocessing of ubint to determine bitwidth. */ -template +template struct Log2 { - static constexpr usint value = 1 + Log2::value; + static constexpr uint32_t value = 1 + Log2::value; }; template <> struct Log2<2> { - static constexpr usint value = 1; + static constexpr uint32_t value = 1; }; // @brief A pre-computed constant of Log base 2 of 10. @@ -139,15 +139,15 @@ template class ubint final : public lbcrypto::BigIntegerInterface> { private: // variable that stores the MOST SIGNIFICANT BIT position in the - usint m_MSB{0}; + uint32_t m_MSB{0}; // vector storing the native integers. stored little endian std::vector m_value{0}; // variable to store the maximum value of the limb data type static constexpr limb_t m_MaxLimb{std::numeric_limits::max()}; // variable to store the bitlength of the limb data type - static constexpr usint m_limbBitLength{sizeof(limb_t) * 8}; + static constexpr uint32_t m_limbBitLength{sizeof(limb_t) * 8}; // variable to store the log2 of the number of bits in the limb data type - static constexpr usint m_log2LimbBitLength{Log2::value}; + static constexpr uint32_t m_log2LimbBitLength{Log2::value}; friend class mubintvec>; @@ -326,8 +326,8 @@ class ubint final : public lbcrypto::BigIntegerInterface> { * @param p the exponent. * @return is the result of the exponentiation operation. */ - ubint Exp(usint p) const; - ubint& ExpEq(usint p) { + ubint Exp(uint32_t p) const; + ubint& ExpEq(uint32_t p) { return *this = this->ubint::Exp(p); } @@ -679,8 +679,8 @@ class ubint final : public lbcrypto::BigIntegerInterface> { * @param shift # of bits. * @return result of the shift operation. */ - ubint LShift(usshort shift) const; - ubint& LShiftEq(usshort shift); + ubint LShift(uint16_t shift) const; + ubint& LShiftEq(uint16_t shift); /** * Right shift operation. @@ -688,8 +688,8 @@ class ubint final : public lbcrypto::BigIntegerInterface> { * @param shift # of bits. * @return result of the shift operation. */ - ubint RShift(usshort shift) const; - ubint& RShiftEq(usshort shift); + ubint RShift(uint16_t shift) const; + ubint& RShiftEq(uint16_t shift); /** * Compares the current ubint to ubint a. @@ -714,14 +714,14 @@ class ubint final : public lbcrypto::BigIntegerInterface> { template T ConvertToInt() const noexcept { - constexpr usint limblen{sizeof(T) * 8}; + constexpr uint32_t limblen{sizeof(T) * 8}; if constexpr (m_limbBitLength >= limblen) { return static_cast(m_value[0]); } if constexpr (m_limbBitLength < limblen) { auto ceilInt = MSBToLimbs(limblen > m_MSB ? m_MSB : limblen); auto result = static_cast(m_value[0]); - for (usint i{1}; i < ceilInt; ++i) + for (uint32_t i{1}; i < ceilInt; ++i) result |= static_cast(m_value[i]) << (i * m_limbBitLength); return result; } @@ -748,7 +748,7 @@ class ubint final : public lbcrypto::BigIntegerInterface> { * Returns the MSB location of the value. * @return the index of the most significant bit. */ - usint GetMSB() const { + uint32_t GetMSB() const { return m_MSB; } @@ -790,7 +790,7 @@ class ubint final : public lbcrypto::BigIntegerInterface> { */ // TODO hardcoded for base 2? - usint GetLengthForBase(usint base) const { + uint32_t GetLengthForBase(uint32_t base) const { return GetMSB(); } @@ -808,7 +808,7 @@ class ubint final : public lbcrypto::BigIntegerInterface> { * @param base is the base with which to determine length in. * @return the length of the representation in a specific base. */ - usint GetDigitAtIndexForBase(usint index, usint base) const; + uint32_t GetDigitAtIndexForBase(uint32_t index, uint32_t base) const; /** * Gets the bit at the specified index. @@ -816,7 +816,7 @@ class ubint final : public lbcrypto::BigIntegerInterface> { * @param index is the index of the bit to get. * @return resulting bit. */ - uschar GetBitAtIndex(usint index) const; + uint8_t GetBitAtIndex(uint32_t index) const; /** * A zero allocator that is called by the Matrix class. It is used to @@ -910,7 +910,7 @@ class ubint final : public lbcrypto::BigIntegerInterface> { * Sets the MSB to the correct value as computed from the internal value. */ void SetMSB() { - m_MSB = m_limbBitLength * static_cast(m_value.size() - 1); + m_MSB = m_limbBitLength * static_cast(m_value.size() - 1); m_MSB += lbcrypto::GetMSB(m_value.back()); } @@ -925,7 +925,7 @@ class ubint final : public lbcrypto::BigIntegerInterface> { auto size = m_value.size() - 1; while (size > 0 && m_value[size--] == 0) m_value.pop_back(); - m_MSB = m_limbBitLength * static_cast(m_value.size() - 1); + m_MSB = m_limbBitLength * static_cast(m_value.size() - 1); m_MSB += lbcrypto::GetMSB(m_value.back()); } @@ -944,8 +944,8 @@ class ubint final : public lbcrypto::BigIntegerInterface> { * @param Number is the number to be divided. * @return the ceiling of Number/(bits in the limb data type) */ - static constexpr usint MSBToLimbs(usint msb) noexcept { - constexpr usint mask{m_limbBitLength - 1}; + static constexpr uint32_t MSBToLimbs(uint32_t msb) noexcept { + constexpr uint32_t mask{m_limbBitLength - 1}; if (msb == 0) return 1; return (msb >> m_log2LimbBitLength) + ((msb & mask) != 0); diff --git a/src/core/include/math/hal/bigintfxd/mubintvecfxd.h b/src/core/include/math/hal/bigintfxd/mubintvecfxd.h index 968c80b5f..ab69b7a55 100644 --- a/src/core/include/math/hal/bigintfxd/mubintvecfxd.h +++ b/src/core/include/math/hal/bigintfxd/mubintvecfxd.h @@ -88,9 +88,9 @@ class BigVectorFixedT final : public lbcrypto::BigVectorInterface rhs); + BigVectorFixedT(uint32_t length, const IntegerType& modulus, std::initializer_list rhs); /** * Basic constructor for specifying the length of the vector @@ -128,9 +128,9 @@ class BigVectorFixedT final : public lbcrypto::BigVectorInterface rhs); + BigVectorFixedT(uint32_t length, const IntegerType& modulus, std::initializer_list rhs); /** * Assignment operator to assign value from rhs @@ -297,7 +297,7 @@ class BigVectorFixedT final : public lbcrypto::BigVectorInterface& ptr_obj) { auto len = ptr_obj.m_length; os << "["; - for (usint i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++) { os << ptr_obj.m_data[i]; os << ((i == (len - 1)) ? "]" : " "); } @@ -597,12 +597,12 @@ class BigVectorFixedT final : public lbcrypto::BigVectorInterface ChineseRemainderTransformArbFxd::m_DivisionNTTRootOfUnity; template -std::map ChineseRemainderTransformArbFxd::m_nttDivisionDim; +std::map ChineseRemainderTransformArbFxd::m_nttDivisionDim; template void NumberTheoreticTransformFxd::ForwardTransformIterative(const VecType& element, const VecType& rootOfUnityTable, VecType* result) { - usint n = element.GetLength(); + uint32_t n = element.GetLength(); if (result->GetLength() != n) { OPENFHE_THROW("size of input element and size of output element not of same size"); } @@ -129,24 +129,24 @@ void NumberTheoreticTransformFxd::ForwardTransformIterative(const VecTy IntType mu = modulus.ComputeMu(); result->SetModulus(modulus); - usint msb = GetMSB64(n - 1); + uint32_t msb = GetMSB64(n - 1); for (size_t i = 0; i < n; i++) { (*result)[i] = element[ReverseBits(i, msb)]; } IntType omega, omegaFactor, oddVal, evenVal; - usint logm, i, j, indexEven, indexOdd; + uint32_t logm, i, j, indexEven, indexOdd; - usint logn = GetMSB64(n - 1); + uint32_t logn = GetMSB64(n - 1); for (logm = 1; logm <= logn; logm++) { // calculate the i indexes into the root table one time per loop - std::vector indexes(1 << (logm - 1)); - for (i = 0; i < (usint)(1 << (logm - 1)); i++) { + std::vector indexes(1 << (logm - 1)); + for (i = 0; i < (uint32_t)(1 << (logm - 1)); i++) { indexes[i] = (i << (logn - logm)); } for (j = 0; j < n; j = j + (1 << logm)) { - for (i = 0; i < (usint)(1 << (logm - 1)); i++) { + for (i = 0; i < (uint32_t)(1 << (logm - 1)); i++) { omega = rootOfUnityTable[indexes[i]]; indexEven = j + i; indexOdd = indexEven + (1 << (logm - 1)); @@ -177,14 +177,14 @@ template void NumberTheoreticTransformFxd::InverseTransformIterative(const VecType& element, const VecType& rootOfUnityInverseTable, VecType* result) { - usint n = element.GetLength(); + uint32_t n = element.GetLength(); IntType modulus = element.GetModulus(); IntType mu = modulus.ComputeMu(); NumberTheoreticTransformFxd().ForwardTransformIterative(element, rootOfUnityInverseTable, result); IntType cycloOrderInv(IntType(n).ModInverse(modulus)); - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { (*result)[i].ModMulEq(cycloOrderInv, modulus, mu); } return; @@ -193,15 +193,15 @@ void NumberTheoreticTransformFxd::InverseTransformIterative(const VecTy template void NumberTheoreticTransformFxd::ForwardTransformToBitReverseInPlace(const VecType& rootOfUnityTable, VecType* element) { - usint n = element->GetLength(); + uint32_t n = element->GetLength(); IntType modulus = element->GetModulus(); IntType mu = modulus.ComputeMu(); - usint i, m, j1, j2, indexOmega, indexLo, indexHi; + uint32_t i, m, j1, j2, indexOmega, indexLo, indexHi; IntType omega, omegaFactor, loVal, hiVal, zero(0); - usint t = (n >> 1); - usint logt1 = GetMSB64(t); + uint32_t t = (n >> 1); + uint32_t logt1 = GetMSB64(t); for (m = 1; m < n; m <<= 1) { for (i = 0; i < m; ++i) { j1 = i << logt1; @@ -238,7 +238,7 @@ template void NumberTheoreticTransformFxd::ForwardTransformToBitReverse(const VecType& element, const VecType& rootOfUnityTable, VecType* result) { - usint n = element.GetLength(); + uint32_t n = element.GetLength(); if (result->GetLength() != n) { OPENFHE_THROW("size of input element and size of output element not of same size"); } @@ -247,15 +247,15 @@ void NumberTheoreticTransformFxd::ForwardTransformToBitReverse(const Ve IntType mu = modulus.ComputeMu(); result->SetModulus(modulus); - usint i, m, j1, j2, indexOmega, indexLo, indexHi; + uint32_t i, m, j1, j2, indexOmega, indexLo, indexHi; IntType omega, omegaFactor, loVal, hiVal, zero(0); for (i = 0; i < n; ++i) { (*result)[i] = element[i]; } - usint t = (n >> 1); - usint logt1 = GetMSB64(t); + uint32_t t = (n >> 1); + uint32_t logt1 = GetMSB64(t); for (m = 1; m < n; m <<= 1) { for (i = 0; i < m; ++i) { j1 = i << logt1; @@ -297,15 +297,15 @@ template void NumberTheoreticTransformFxd::ForwardTransformToBitReverseInPlace(const VecType& rootOfUnityTable, const VecType& preconRootOfUnityTable, VecType* element) { - usint n = element->GetLength(); + uint32_t n = element->GetLength(); IntType modulus = element->GetModulus(); uint32_t indexOmega, indexHi; IntType preconOmega; IntType omega, omegaFactor, loVal, hiVal, zero(0); - usint t = (n >> 1); - usint logt1 = GetMSB64(t); + uint32_t t = (n >> 1); + uint32_t logt1 = GetMSB64(t); for (uint32_t m = 1; m < n; m <<= 1, t >>= 1, --logt1) { uint32_t j1, j2; for (uint32_t i = 0; i < m; ++i) { @@ -343,7 +343,7 @@ void NumberTheoreticTransformFxd::ForwardTransformToBitReverse(const Ve const VecType& rootOfUnityTable, const VecType& preconRootOfUnityTable, VecType* result) { - usint n = element.GetLength(); + uint32_t n = element.GetLength(); if (result->GetLength() != n) { OPENFHE_THROW("size of input element and size of output element not of same size"); @@ -361,8 +361,8 @@ void NumberTheoreticTransformFxd::ForwardTransformToBitReverse(const Ve IntType preconOmega; IntType omega, omegaFactor, loVal, hiVal, zero(0); - usint t = (n >> 1); - usint logt1 = GetMSB64(t); + uint32_t t = (n >> 1); + uint32_t logt1 = GetMSB64(t); for (uint32_t m = 1; m < n; m <<= 1, t >>= 1, --logt1) { uint32_t j1, j2; for (uint32_t i = 0; i < m; ++i) { @@ -404,15 +404,15 @@ template void NumberTheoreticTransformFxd::InverseTransformFromBitReverseInPlace(const VecType& rootOfUnityInverseTable, const IntType& cycloOrderInv, VecType* element) { - usint n = element->GetLength(); + uint32_t n = element->GetLength(); IntType modulus = element->GetModulus(); IntType mu = modulus.ComputeMu(); IntType loVal, hiVal, omega, omegaFactor; - usint i, m, j1, j2, indexOmega, indexLo, indexHi; + uint32_t i, m, j1, j2, indexOmega, indexLo, indexHi; - usint t = 1; - usint logt1 = 1; + uint32_t t = 1; + uint32_t logt1 = 1; for (m = (n >> 1); m >= 1; m >>= 1) { for (i = 0; i < m; ++i) { j1 = i << logt1; @@ -459,7 +459,7 @@ void NumberTheoreticTransformFxd::InverseTransformFromBitReverse(const const VecType& rootOfUnityInverseTable, const IntType& cycloOrderInv, VecType* result) { - usint n = element.GetLength(); + uint32_t n = element.GetLength(); if (result->GetLength() != n) { OPENFHE_THROW("size of input element and size of output element not of same size"); @@ -467,7 +467,7 @@ void NumberTheoreticTransformFxd::InverseTransformFromBitReverse(const result->SetModulus(element.GetModulus()); - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { (*result)[i] = element[i]; } InverseTransformFromBitReverseInPlace(rootOfUnityInverseTable, cycloOrderInv, result); @@ -477,16 +477,16 @@ template void NumberTheoreticTransformFxd::InverseTransformFromBitReverseInPlace( const VecType& rootOfUnityInverseTable, const VecType& preconRootOfUnityInverseTable, const IntType& cycloOrderInv, const IntType& preconCycloOrderInv, VecType* element) { - usint n = element->GetLength(); + uint32_t n = element->GetLength(); IntType modulus = element->GetModulus(); IntType loVal, hiVal, omega, omegaFactor; IntType preconOmega; - usint i, m, j1, j2, indexOmega, indexLo, indexHi; + uint32_t i, m, j1, j2, indexOmega, indexLo, indexHi; - usint t = 1; - usint logt1 = 1; + uint32_t t = 1; + uint32_t logt1 = 1; for (m = (n >> 1); m >= 1; m >>= 1) { for (i = 0; i < m; ++i) { j1 = i << logt1; @@ -532,14 +532,14 @@ template void NumberTheoreticTransformFxd::InverseTransformFromBitReverse( const VecType& element, const VecType& rootOfUnityInverseTable, const VecType& preconRootOfUnityInverseTable, const IntType& cycloOrderInv, const IntType& preconCycloOrderInv, VecType* result) { - usint n = element.GetLength(); + uint32_t n = element.GetLength(); if (result->GetLength() != n) { OPENFHE_THROW("size of input element and size of output element not of same size"); } result->SetModulus(element.GetModulus()); - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { (*result)[i] = element[i]; } InverseTransformFromBitReverseInPlace(rootOfUnityInverseTable, preconRootOfUnityInverseTable, cycloOrderInv, @@ -550,7 +550,7 @@ void NumberTheoreticTransformFxd::InverseTransformFromBitReverse( template void ChineseRemainderTransformFTTFxd::ForwardTransformToBitReverseInPlace(const IntType& rootOfUnity, - const usint CycloOrder, + const uint32_t CycloOrder, VecType* element) { if (rootOfUnity == IntType(1) || rootOfUnity == IntType(0)) { return; @@ -560,7 +560,7 @@ void ChineseRemainderTransformFTTFxd::ForwardTransformToBitReverseInPla OPENFHE_THROW("CyclotomicOrder is not a power of two"); } - usint CycloOrderHf = (CycloOrder >> 1); + uint32_t CycloOrderHf = (CycloOrder >> 1); if (element->GetLength() != CycloOrderHf) { OPENFHE_THROW("element size must be equal to CyclotomicOrder / 2"); } @@ -585,7 +585,7 @@ void ChineseRemainderTransformFTTFxd::ForwardTransformToBitReverseInPla template void ChineseRemainderTransformFTTFxd::ForwardTransformToBitReverse(const VecType& element, const IntType& rootOfUnity, - const usint CycloOrder, VecType* result) { + const uint32_t CycloOrder, VecType* result) { if (rootOfUnity == IntType(1) || rootOfUnity == IntType(0)) { *result = element; return; @@ -595,7 +595,7 @@ void ChineseRemainderTransformFTTFxd::ForwardTransformToBitReverse(cons OPENFHE_THROW("CyclotomicOrder is not a power of two"); } - usint CycloOrderHf = (CycloOrder >> 1); + uint32_t CycloOrderHf = (CycloOrder >> 1); if (result->GetLength() != CycloOrderHf) { OPENFHE_THROW("result size must be equal to CyclotomicOrder / 2"); } @@ -621,7 +621,7 @@ void ChineseRemainderTransformFTTFxd::ForwardTransformToBitReverse(cons template void ChineseRemainderTransformFTTFxd::InverseTransformFromBitReverseInPlace(const IntType& rootOfUnity, - const usint CycloOrder, + const uint32_t CycloOrder, VecType* element) { if (rootOfUnity == IntType(1) || rootOfUnity == IntType(0)) { return; @@ -631,7 +631,7 @@ void ChineseRemainderTransformFTTFxd::InverseTransformFromBitReverseInP OPENFHE_THROW("CyclotomicOrder is not a power of two"); } - usint CycloOrderHf = (CycloOrder >> 1); + uint32_t CycloOrderHf = (CycloOrder >> 1); if (element->GetLength() != CycloOrderHf) { OPENFHE_THROW("element size must be equal to CyclotomicOrder / 2"); } @@ -643,7 +643,7 @@ void ChineseRemainderTransformFTTFxd::InverseTransformFromBitReverseInP PreCompute(rootOfUnity, CycloOrder, modulus); } - usint msb = GetMSB64(CycloOrderHf - 1); + uint32_t msb = GetMSB64(CycloOrderHf - 1); // if (typeid(IntType) == typeid(NativeInteger)) { // NumberTheoreticTransformFxd().InverseTransformFromBitReverseInPlace( // m_rootOfUnityInverseReverseTableByModulus[modulus], @@ -659,7 +659,7 @@ void ChineseRemainderTransformFTTFxd::InverseTransformFromBitReverseInP template void ChineseRemainderTransformFTTFxd::InverseTransformFromBitReverse(const VecType& element, const IntType& rootOfUnity, - const usint CycloOrder, VecType* result) { + const uint32_t CycloOrder, VecType* result) { if (rootOfUnity == IntType(1) || rootOfUnity == IntType(0)) { *result = element; return; @@ -669,7 +669,7 @@ void ChineseRemainderTransformFTTFxd::InverseTransformFromBitReverse(co OPENFHE_THROW("CyclotomicOrder is not a power of two"); } - usint CycloOrderHf = (CycloOrder >> 1); + uint32_t CycloOrderHf = (CycloOrder >> 1); if (result->GetLength() != CycloOrderHf) { OPENFHE_THROW("result size must be equal to CyclotomicOrder / 2"); } @@ -681,13 +681,13 @@ void ChineseRemainderTransformFTTFxd::InverseTransformFromBitReverse(co PreCompute(rootOfUnity, CycloOrder, modulus); } - usint n = element.GetLength(); + uint32_t n = element.GetLength(); result->SetModulus(element.GetModulus()); - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { (*result)[i] = element[i]; } - usint msb = lbcrypto::GetMSB64(CycloOrderHf - 1); + uint32_t msb = lbcrypto::GetMSB64(CycloOrderHf - 1); // if (typeid(IntType) == typeid(NativeInteger)) { // NumberTheoreticTransformFxd().InverseTransformFromBitReverseInPlace( // m_rootOfUnityInverseReverseTableByModulus[modulus], @@ -703,23 +703,23 @@ void ChineseRemainderTransformFTTFxd::InverseTransformFromBitReverse(co } template -void ChineseRemainderTransformFTTFxd::PreCompute(const IntType& rootOfUnity, const usint CycloOrder, +void ChineseRemainderTransformFTTFxd::PreCompute(const IntType& rootOfUnity, const uint32_t CycloOrder, const IntType& modulus) { // Half of cyclo order - usint CycloOrderHf = (CycloOrder >> 1); + uint32_t CycloOrderHf = (CycloOrder >> 1); auto mapSearch = m_rootOfUnityReverseTableByModulus.find(modulus); if (mapSearch == m_rootOfUnityReverseTableByModulus.end() || mapSearch->second.GetLength() != CycloOrderHf) { #pragma omp critical { IntType x(1), xinv(1); - usint msb = lbcrypto::GetMSB64(CycloOrderHf - 1); + uint32_t msb = lbcrypto::GetMSB64(CycloOrderHf - 1); IntType mu = modulus.ComputeMu(); VecType Table(CycloOrderHf, modulus); VecType TableI(CycloOrderHf, modulus); IntType rootOfUnityInverse = rootOfUnity.ModInverse(modulus); - usint iinv; - for (usint i = 0; i < CycloOrderHf; i++) { + uint32_t iinv; + for (uint32_t i = 0; i < CycloOrderHf; i++) { iinv = lbcrypto::ReverseBits(i, msb); Table[iinv] = x; TableI[iinv] = xinv; @@ -730,7 +730,7 @@ void ChineseRemainderTransformFTTFxd::PreCompute(const IntType& rootOfU m_rootOfUnityInverseReverseTableByModulus[modulus] = TableI; VecType TableCOI(msb + 1, modulus); - for (usint i = 0; i < msb + 1; i++) { + for (uint32_t i = 0; i < msb + 1; i++) { IntType coInv(IntType(1 << i).ModInverse(modulus)); TableCOI[i] = coInv; } @@ -741,7 +741,7 @@ void ChineseRemainderTransformFTTFxd::PreCompute(const IntType& rootOfU // VecType preconTable(CycloOrderHf, nativeModulus); // VecType preconTableI(CycloOrderHf, nativeModulus); - // for (usint i = 0; i < CycloOrderHf; i++) { + // for (uint32_t i = 0; i < CycloOrderHf; i++) { // preconTable[i] = // NativeInteger( // m_rootOfUnityReverseTableByModulus[modulus][i].ConvertToInt()) @@ -754,7 +754,7 @@ void ChineseRemainderTransformFTTFxd::PreCompute(const IntType& rootOfU // } // VecType preconTableCOI(msb + 1, nativeModulus); - // for (usint i = 0; i < msb + 1; i++) { + // for (uint32_t i = 0; i < msb + 1; i++) { // preconTableCOI[i] = // NativeInteger( // m_cycloOrderInverseTableByModulus[modulus][i].ConvertToInt()) @@ -770,16 +770,16 @@ void ChineseRemainderTransformFTTFxd::PreCompute(const IntType& rootOfU } template -void ChineseRemainderTransformFTTFxd::PreCompute(std::vector& rootOfUnity, const usint CycloOrder, +void ChineseRemainderTransformFTTFxd::PreCompute(std::vector& rootOfUnity, const uint32_t CycloOrder, std::vector& moduliiChain) { - usint numOfRootU = rootOfUnity.size(); - usint numModulii = moduliiChain.size(); + uint32_t numOfRootU = rootOfUnity.size(); + uint32_t numModulii = moduliiChain.size(); if (numOfRootU != numModulii) { OPENFHE_THROW("size of root of unity and size of moduli chain not of same size"); } - for (usint i = 0; i < numOfRootU; ++i) { + for (uint32_t i = 0; i < numOfRootU; ++i) { IntType currentRoot(rootOfUnity[i]); IntType currentMod(moduliiChain[i]); PreCompute(currentRoot, CycloOrder, currentMod); @@ -797,8 +797,8 @@ void ChineseRemainderTransformFTTFxd::Reset() { } template -void BluesteinFFTFxd::PreComputeDefaultNTTModulusRoot(usint cycloOrder, const IntType& modulus) { - usint nttDim = std::pow(2, std::ceil(std::log2(2 * cycloOrder - 1))); +void BluesteinFFTFxd::PreComputeDefaultNTTModulusRoot(uint32_t cycloOrder, const IntType& modulus) { + uint32_t nttDim = std::pow(2, std::ceil(std::log2(2 * cycloOrder - 1))); const auto nttModulus = LastPrime(std::log2(nttDim) + 2 * modulus.GetMSB(), nttDim); const auto nttRoot = RootOfUnity(nttDim, nttModulus); const ModulusRoot nttModulusRoot = {nttModulus, nttRoot}; @@ -808,9 +808,9 @@ void BluesteinFFTFxd::PreComputeDefaultNTTModulusRoot(usint cycloOrder, } template -void BluesteinFFTFxd::PreComputeRootTableForNTT(usint cyclotoOrder, +void BluesteinFFTFxd::PreComputeRootTableForNTT(uint32_t cyclotoOrder, const ModulusRoot& nttModulusRoot) { - usint nttDim = std::pow(2, std::ceil(std::log2(2 * cyclotoOrder - 1))); + uint32_t nttDim = std::pow(2, std::ceil(std::log2(2 * cyclotoOrder - 1))); const auto& nttModulus = nttModulusRoot.first; const auto& nttRoot = nttModulusRoot.second; @@ -818,18 +818,18 @@ void BluesteinFFTFxd::PreComputeRootTableForNTT(usint cyclotoOrder, auto rootInv = root.ModInverse(nttModulus); - usint nttDimHf = (nttDim >> 1); + uint32_t nttDimHf = (nttDim >> 1); VecType rootTable(nttDimHf, nttModulus); VecType rootTableInverse(nttDimHf, nttModulus); IntType x(1); - for (usint i = 0; i < nttDimHf; i++) { + for (uint32_t i = 0; i < nttDimHf; i++) { rootTable[i] = x; x = x.ModMul(root, nttModulus); } x = 1; - for (usint i = 0; i < nttDimHf; i++) { + for (uint32_t i = 0; i < nttDimHf; i++) { rootTableInverse[i] = x; x = x.ModMul(rootInv, nttModulus); } @@ -839,13 +839,13 @@ void BluesteinFFTFxd::PreComputeRootTableForNTT(usint cyclotoOrder, } template -void BluesteinFFTFxd::PreComputePowers(usint cycloOrder, const ModulusRoot& modulusRoot) { +void BluesteinFFTFxd::PreComputePowers(uint32_t cycloOrder, const ModulusRoot& modulusRoot) { const auto& modulus = modulusRoot.first; const auto& root = modulusRoot.second; VecType powers(cycloOrder, modulus); powers[0] = 1; - for (usint i = 1; i < cycloOrder; i++) { + for (uint32_t i = 1; i < cycloOrder; i++) { auto iSqr = (i * i) % (2 * cycloOrder); auto val = root.ModExp(IntType(iSqr), modulus); powers[i] = val; @@ -854,7 +854,7 @@ void BluesteinFFTFxd::PreComputePowers(usint cycloOrder, const ModulusR } template -void BluesteinFFTFxd::PreComputeRBTable(usint cycloOrder, const ModulusRootPair& modulusRootPair) { +void BluesteinFFTFxd::PreComputeRBTable(uint32_t cycloOrder, const ModulusRootPair& modulusRootPair) { const auto& modulusRoot = modulusRootPair.first; const auto& modulus = modulusRoot.first; const auto& root = modulusRoot.second; @@ -865,11 +865,11 @@ void BluesteinFFTFxd::PreComputeRBTable(usint cycloOrder, const Modulus // const auto &nttRoot = nttModulusRoot.second; // assumes rootTable is precomputed const auto& rootTable = m_rootOfUnityTableByModulusRoot[nttModulusRoot]; - usint nttDim = std::pow(2, std::ceil(std::log2(2 * cycloOrder - 1))); + uint32_t nttDim = std::pow(2, std::ceil(std::log2(2 * cycloOrder - 1))); VecType b(2 * cycloOrder - 1, modulus); b[cycloOrder - 1] = 1; - for (usint i = 1; i < cycloOrder; i++) { + for (uint32_t i = 1; i < cycloOrder; i++) { auto iSqr = (i * i) % (2 * cycloOrder); auto val = rootInv.ModExp(IntType(iSqr), modulus); b[cycloOrder - 1 + i] = val; @@ -886,7 +886,7 @@ void BluesteinFFTFxd::PreComputeRBTable(usint cycloOrder, const Modulus template VecType BluesteinFFTFxd::ForwardTransform(const VecType& element, const IntType& root, - const usint cycloOrder) { + const uint32_t cycloOrder) { const auto& modulus = element.GetModulus(); const auto& nttModulusRoot = m_defaultNTTModulusRoot[modulus]; @@ -894,7 +894,7 @@ VecType BluesteinFFTFxd::ForwardTransform(const VecType& element, const } template -VecType BluesteinFFTFxd::ForwardTransform(const VecType& element, const IntType& root, const usint cycloOrder, +VecType BluesteinFFTFxd::ForwardTransform(const VecType& element, const IntType& root, const uint32_t cycloOrder, const ModulusRoot& nttModulusRoot) { if (element.GetLength() != cycloOrder) { OPENFHE_THROW("expected size of element vector should be equal to cyclotomic order"); @@ -911,7 +911,7 @@ VecType BluesteinFFTFxd::ForwardTransform(const VecType& element, const m_rootOfUnityInverseTableByModulusRoot[nttModulusRoot]; // assumes rootTableInverse is precomputed VecType x = element.ModMul(powers); - usint nttDim = std::pow(2, std::ceil(std::log2(2 * cycloOrder - 1))); + uint32_t nttDim = std::pow(2, std::ceil(std::log2(2 * cycloOrder - 1))); auto Ra = PadZeros(x, nttDim); Ra.SetModulus(nttModulus); VecType RA(nttDim); @@ -932,15 +932,15 @@ VecType BluesteinFFTFxd::ForwardTransform(const VecType& element, const } template -VecType BluesteinFFTFxd::PadZeros(const VecType& a, const usint finalSize) { - usint s = a.GetLength(); +VecType BluesteinFFTFxd::PadZeros(const VecType& a, const uint32_t finalSize) { + uint32_t s = a.GetLength(); VecType result(finalSize, a.GetModulus()); - for (usint i = 0; i < s; i++) { + for (uint32_t i = 0; i < s; i++) { result[i] = a[i]; } - for (usint i = a.GetLength(); i < finalSize; i++) { + for (uint32_t i = a.GetLength(); i < finalSize; i++) { result[i] = IntType(0); } @@ -948,10 +948,10 @@ VecType BluesteinFFTFxd::PadZeros(const VecType& a, const usint finalSi } template -VecType BluesteinFFTFxd::Resize(const VecType& a, usint lo, usint hi) { +VecType BluesteinFFTFxd::Resize(const VecType& a, uint32_t lo, uint32_t hi) { VecType result(hi - lo + 1, a.GetModulus()); - for (usint i = lo, j = 0; i <= hi; i++, j++) { + for (uint32_t i = lo, j = 0; i <= hi; i++, j++) { result[j] = a[i]; } @@ -973,12 +973,12 @@ void ChineseRemainderTransformArbFxd::SetCylotomicPolynomial(const VecT } template -void ChineseRemainderTransformArbFxd::PreCompute(const usint cyclotoOrder, const IntType& modulus) { +void ChineseRemainderTransformArbFxd::PreCompute(const uint32_t cyclotoOrder, const IntType& modulus) { BluesteinFFTFxd().PreComputeDefaultNTTModulusRoot(cyclotoOrder, modulus); } template -void ChineseRemainderTransformArbFxd::SetPreComputedNTTModulus(usint cyclotoOrder, const IntType& modulus, +void ChineseRemainderTransformArbFxd::SetPreComputedNTTModulus(uint32_t cyclotoOrder, const IntType& modulus, const IntType& nttModulus, const IntType& nttRoot) { const ModulusRoot nttModulusRoot = {nttModulus, nttRoot}; @@ -986,15 +986,15 @@ void ChineseRemainderTransformArbFxd::SetPreComputedNTTModulus(usint cy } template -void ChineseRemainderTransformArbFxd::SetPreComputedNTTDivisionModulus(usint cyclotoOrder, +void ChineseRemainderTransformArbFxd::SetPreComputedNTTDivisionModulus(uint32_t cyclotoOrder, const IntType& modulus, const IntType& nttMod, const IntType& nttRootBig) { - usint n = GetTotient(cyclotoOrder); - usint power = cyclotoOrder - n; + uint32_t n = GetTotient(cyclotoOrder); + uint32_t power = cyclotoOrder - n; m_nttDivisionDim[cyclotoOrder] = 2 * std::pow(2, std::ceil(std::log2(power))); - usint nttDimBig = std::pow(2, std::ceil(std::log2(2 * cyclotoOrder - 1))); + uint32_t nttDimBig = std::pow(2, std::ceil(std::log2(2 * cyclotoOrder - 1))); // Computes the root of unity for the division NTT based on the root of unity // for regular NTT @@ -1003,22 +1003,22 @@ void ChineseRemainderTransformArbFxd::SetPreComputedNTTDivisionModulus( m_DivisionNTTModulus[modulus] = nttMod; m_DivisionNTTRootOfUnity[modulus] = nttRoot; // part0 setting of rootTable and inverse rootTable - usint nttDim = m_nttDivisionDim[cyclotoOrder]; + uint32_t nttDim = m_nttDivisionDim[cyclotoOrder]; IntType root(nttRoot); auto rootInv = root.ModInverse(nttMod); - usint nttDimHf = (nttDim >> 1); + uint32_t nttDimHf = (nttDim >> 1); VecType rootTable(nttDimHf, nttMod); VecType rootTableInverse(nttDimHf, nttMod); IntType x(1); - for (usint i = 0; i < nttDimHf; i++) { + for (uint32_t i = 0; i < nttDimHf; i++) { rootTable[i] = x; x = x.ModMul(root, nttMod); } x = 1; - for (usint i = 0; i < nttDimHf; i++) { + for (uint32_t i = 0; i < nttDimHf; i++) { rootTableInverse[i] = x; x = x.ModMul(rootInv, nttMod); } @@ -1040,7 +1040,7 @@ void ChineseRemainderTransformArbFxd::SetPreComputedNTTDivisionModulus( const auto& cycloPoly = m_cyclotomicPolyMap[modulus]; VecType QForwardTransform(nttDim, nttMod); - for (usint i = 0; i < cycloPoly.GetLength(); i++) { + for (uint32_t i = 0; i < cycloPoly.GetLength(); i++) { QForwardTransform[i] = cycloPoly[i]; } @@ -1052,17 +1052,17 @@ void ChineseRemainderTransformArbFxd::SetPreComputedNTTDivisionModulus( template VecType ChineseRemainderTransformArbFxd::InversePolyMod(const VecType& cycloPoly, const IntType& modulus, - usint power) { + uint32_t power) { VecType result(power, modulus); - usint r = std::ceil(std::log2(power)); + uint32_t r = std::ceil(std::log2(power)); VecType h(1, modulus); // h is a unit polynomial h[0] = 1; // Precompute the Barrett mu parameter IntType mu = modulus.ComputeMu(); - for (usint i = 0; i < r; i++) { - usint qDegree = std::pow(2, i + 1); + for (uint32_t i = 0; i < r; i++) { + uint32_t qDegree = std::pow(2, i + 1); VecType q(qDegree + 1, modulus); // q = x^(2^i+1) q[qDegree] = 1; auto hSquare = PolynomialMultiplication(h, h); @@ -1070,7 +1070,7 @@ VecType ChineseRemainderTransformArbFxd::InversePolyMod(const VecType& auto a = h * IntType(2); auto b = PolynomialMultiplication(hSquare, cycloPoly); // b = 2h - gh^2 - for (usint j = 0; j < b.GetLength(); j++) { + for (uint32_t j = 0; j < b.GetLength(); j++) { if (j < a.GetLength()) { b[j] = a[j].ModSub(b[j], modulus, mu); } @@ -1081,7 +1081,7 @@ VecType ChineseRemainderTransformArbFxd::InversePolyMod(const VecType& h = PolyMod(b, q, modulus); } // take modulo x^power - for (usint i = 0; i < power; i++) { + for (uint32_t i = 0; i < power; i++) { result[i] = h[i]; } @@ -1091,8 +1091,8 @@ VecType ChineseRemainderTransformArbFxd::InversePolyMod(const VecType& template VecType ChineseRemainderTransformArbFxd::ForwardTransform(const VecType& element, const IntType& root, const IntType& nttModulus, const IntType& nttRoot, - const usint cycloOrder) { - usint phim = GetTotient(cycloOrder); + const uint32_t cycloOrder) { + uint32_t phim = GetTotient(cycloOrder); if (element.GetLength() != phim) { OPENFHE_THROW("element size should be equal to phim"); } @@ -1130,8 +1130,8 @@ VecType ChineseRemainderTransformArbFxd::ForwardTransform(const VecType template VecType ChineseRemainderTransformArbFxd::InverseTransform(const VecType& element, const IntType& root, const IntType& nttModulus, const IntType& nttRoot, - const usint cycloOrder) { - usint phim = GetTotient(cycloOrder); + const uint32_t cycloOrder) { + uint32_t phim = GetTotient(cycloOrder); if (element.GetLength() != phim) { OPENFHE_THROW("element size should be equal to phim"); } @@ -1168,20 +1168,20 @@ VecType ChineseRemainderTransformArbFxd::InverseTransform(const VecType } template -VecType ChineseRemainderTransformArbFxd::Pad(const VecType& element, const usint cycloOrder, bool forward) { - usint n = GetTotient(cycloOrder); +VecType ChineseRemainderTransformArbFxd::Pad(const VecType& element, const uint32_t cycloOrder, bool forward) { + uint32_t n = GetTotient(cycloOrder); const auto& modulus = element.GetModulus(); VecType inputToBluestein(cycloOrder, modulus); if (forward) { // Forward transform padding - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { inputToBluestein[i] = element[i]; } } else { // Inverse transform padding auto tList = GetTotientList(cycloOrder); - usint i = 0; + uint32_t i = 0; for (auto& coprime : tList) { inputToBluestein[coprime] = element[i++]; } @@ -1191,16 +1191,16 @@ VecType ChineseRemainderTransformArbFxd::Pad(const VecType& element, co } template -VecType ChineseRemainderTransformArbFxd::Drop(const VecType& element, const usint cycloOrder, bool forward, +VecType ChineseRemainderTransformArbFxd::Drop(const VecType& element, const uint32_t cycloOrder, bool forward, const IntType& bigMod, const IntType& bigRoot) { - usint n = GetTotient(cycloOrder); + uint32_t n = GetTotient(cycloOrder); const auto& modulus = element.GetModulus(); VecType output(n, modulus); if (forward) { // Forward transform drop auto tList = GetTotientList(cycloOrder); - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { output[i] = element[tList[i]]; } } @@ -1210,7 +1210,7 @@ VecType ChineseRemainderTransformArbFxd::Drop(const VecType& element, c // cycloOrder is prime: Reduce mod Phi_{n+1}(x) // Reduction involves subtracting the coeff of x^n from all terms auto coeff_n = element[n]; - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { output[i] = element[i].ModSub(coeff_n, modulus, mu); } } @@ -1219,7 +1219,7 @@ VecType ChineseRemainderTransformArbFxd::Drop(const VecType& element, c // cycloOrder is 2*prime: 2 Step reduction // First reduce mod x^(n+1)+1 (=(x+1)*Phi_{2*(n+1)}(x)) // Subtract co-efficient of x^(i+n+1) from x^(i) - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { auto coeff_i = element[i]; auto coeff_ip = element[i + n + 1]; output[i] = coeff_i.ModSub(coeff_ip, modulus, mu); @@ -1227,7 +1227,7 @@ VecType ChineseRemainderTransformArbFxd::Drop(const VecType& element, c auto coeff_n = element[n].ModSub(element[2 * n + 1], modulus, mu); // Now reduce mod Phi_{2*(n+1)}(x) // Similar to the prime case but with alternating signs - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { if (i % 2 == 0) { output[i].ModSubEq(coeff_n, modulus, mu); } @@ -1251,8 +1251,8 @@ VecType ChineseRemainderTransformArbFxd::Drop(const VecType& element, c const auto& rootTable = m_rootOfUnityDivisionTableByModulus[nttMod]; VecType aPadded2(m_nttDivisionDim[cycloOrder], nttMod); // perform mod operation - usint power = cycloOrder - n; - for (usint i = n; i < element.GetLength(); i++) { + uint32_t power = cycloOrder - n; + for (uint32_t i = n; i < element.GetLength(); i++) { aPadded2[power - (i - n) - 1] = element[i]; } VecType A(m_nttDivisionDim[cycloOrder]); @@ -1263,7 +1263,7 @@ VecType ChineseRemainderTransformArbFxd::Drop(const VecType& element, c NumberTheoreticTransformFxd().InverseTransformIterative(AB, rootTableInverse, &a); VecType quotient(m_nttDivisionDim[cycloOrder], modulus); - for (usint i = 0; i < power; i++) { + for (uint32_t i = 0; i < power; i++) { quotient[i] = a[i]; } quotient.ModEq(modulus); @@ -1281,7 +1281,7 @@ VecType ChineseRemainderTransformArbFxd::Drop(const VecType& element, c IntType mu = modulus.ComputeMu(); // Precompute the Barrett mu parameter - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { output[i] = element[i].ModSub(newQuotient2[cycloOrder - 1 - i], modulus, mu); } } diff --git a/src/core/include/math/hal/bigintfxd/transformfxd.h b/src/core/include/math/hal/bigintfxd/transformfxd.h index 69b028015..2c17f447d 100644 --- a/src/core/include/math/hal/bigintfxd/transformfxd.h +++ b/src/core/include/math/hal/bigintfxd/transformfxd.h @@ -255,7 +255,7 @@ class ChineseRemainderTransformFTTFxd : public lbcrypto::ChineseRemainderTransfo * size as input or a throw of error occurs. * @see NumberTheoreticTransform::ForwardTransformToBitReverseInPlace() */ - void ForwardTransformToBitReverse(const VecType& element, const IntType& rootOfUnity, const usint CycloOrder, + void ForwardTransformToBitReverse(const VecType& element, const IntType& rootOfUnity, const uint32_t CycloOrder, VecType* result); /** @@ -271,7 +271,7 @@ class ChineseRemainderTransformFTTFxd : public lbcrypto::ChineseRemainderTransfo * @return none * @see NumberTheoreticTransform::ForwardTransformToBitReverseInPlace() */ - void ForwardTransformToBitReverseInPlace(const IntType& rootOfUnity, const usint CycloOrder, VecType* element); + void ForwardTransformToBitReverseInPlace(const IntType& rootOfUnity, const uint32_t CycloOrder, VecType* element); /** * Copies \p element into \p result and calls NumberTheoreticTransform::InverseTransformFromBitReverseInPlace() @@ -290,7 +290,7 @@ class ChineseRemainderTransformFTTFxd : public lbcrypto::ChineseRemainderTransfo * @return none * @see NumberTheoreticTransform::InverseTransformFromBitReverseInPlace() */ - void InverseTransformFromBitReverse(const VecType& element, const IntType& rootOfUnity, const usint CycloOrder, + void InverseTransformFromBitReverse(const VecType& element, const IntType& rootOfUnity, const uint32_t CycloOrder, VecType* result); /** @@ -306,7 +306,7 @@ class ChineseRemainderTransformFTTFxd : public lbcrypto::ChineseRemainderTransfo * @return none * @see NumberTheoreticTransform::InverseTransformFromBitReverseInPlace() */ - void InverseTransformFromBitReverseInPlace(const IntType& rootOfUnity, const usint CycloOrder, VecType* element); + void InverseTransformFromBitReverseInPlace(const IntType& rootOfUnity, const uint32_t CycloOrder, VecType* element); /** * Precomputation of root of unity tables for transforms in the ring @@ -318,7 +318,7 @@ class ChineseRemainderTransformFTTFxd : public lbcrypto::ChineseRemainderTransfo * @param CycloOrder is a power-of-two, equal to 2n. * @param modulus is q, the prime modulus */ - void PreCompute(const IntType& rootOfUnity, const usint CycloOrder, const IntType& modulus); + void PreCompute(const IntType& rootOfUnity, const uint32_t CycloOrder, const IntType& modulus); /** * Precomputation of root of unity tables for transforms in the ring @@ -330,7 +330,7 @@ class ChineseRemainderTransformFTTFxd : public lbcrypto::ChineseRemainderTransfo * @param CycloOrder is a power-of-two, equal to 2n. * @param &moduliChain is the vector of prime moduli qi such that 2n|qi-1 */ - void PreCompute(std::vector& rootOfUnity, const usint CycloOrder, std::vector& moduliChain); + void PreCompute(std::vector& rootOfUnity, const uint32_t CycloOrder, std::vector& moduliChain); /** * Reset cached values for the root of unity tables to empty. @@ -381,8 +381,8 @@ class BluesteinFFTFxd { * @param cycloOrder is the cyclotomic order. * @return is the output result of the transform. */ - VecType ForwardTransform(const VecType& element, const IntType& root, const usint cycloOrder); - VecType ForwardTransform(const VecType& element, const IntType& root, const usint cycloOrder, + VecType ForwardTransform(const VecType& element, const IntType& root, const uint32_t cycloOrder); + VecType ForwardTransform(const VecType& element, const IntType& root, const uint32_t cycloOrder, const ModulusRoot& nttModulusRoot); /** @@ -392,7 +392,7 @@ class BluesteinFFTFxd { * @return output vector padded with (finalSize - initial size)additional * zeros. */ - VecType PadZeros(const VecType& a, const usint finalSize); + VecType PadZeros(const VecType& a, const uint32_t finalSize); /** * @@ -401,9 +401,9 @@ class BluesteinFFTFxd { * @param hi is higher coefficient index. * @return output vector s.t output vector = a[lo]...a[hi]. */ - VecType Resize(const VecType& a, usint lo, usint hi); + VecType Resize(const VecType& a, uint32_t lo, uint32_t hi); - // void PreComputeNTTModulus(usint cycloOrder, const std::vector + // void PreComputeNTTModulus(uint32_t cycloOrder, const std::vector // &modulii); /** @@ -412,7 +412,7 @@ class BluesteinFFTFxd { * @param cycloOrder is the cyclotomic order of the polynomial. * @param modulus is the modulus of the polynomial. */ - void PreComputeDefaultNTTModulusRoot(usint cycloOrder, const IntType& modulus); + void PreComputeDefaultNTTModulusRoot(uint32_t cycloOrder, const IntType& modulus); /** * @brief Precomputes the root of unity table needed for NTT operation in @@ -420,7 +420,7 @@ class BluesteinFFTFxd { * @param cycloOrder is the cyclotomic order of the polynomial ring. * @param modulus is the modulus of the polynomial. */ - void PreComputeRootTableForNTT(usint cycloOrder, const ModulusRoot& nttModulusRoot); + void PreComputeRootTableForNTT(uint32_t cycloOrder, const ModulusRoot& nttModulusRoot); /** * @brief precomputes the powers of root used in forward Bluestein transform. @@ -428,7 +428,7 @@ class BluesteinFFTFxd { * @param modulus is the modulus of the polynomial ring. * @param root is the root of unity s.t. root^2m = 1. */ - void PreComputePowers(usint cycloOrder, const ModulusRoot& modulusRoot); + void PreComputePowers(uint32_t cycloOrder, const ModulusRoot& modulusRoot); /** * @brief precomputes the NTT transform of the power of root of unity used in @@ -439,7 +439,7 @@ class BluesteinFFTFxd { * @param bigMod is the modulus required for the NTT transform. * @param bigRoot is the root of unity required for the NTT transform. */ - void PreComputeRBTable(usint cycloOrder, const ModulusRootPair& modulusRootPair); + void PreComputeRBTable(uint32_t cycloOrder, const ModulusRootPair& modulusRootPair); /** * Reset cached values for the transform to empty. @@ -491,7 +491,7 @@ class ChineseRemainderTransformArbFxd : public lbcrypto::ChineseRemainderTransfo * @return is the output result of the transform. */ VecType ForwardTransform(const VecType& element, const IntType& root, const IntType& bigMod, const IntType& bigRoot, - const usint cycloOrder); + const uint32_t cycloOrder); /** * Inverse transform. @@ -505,7 +505,7 @@ class ChineseRemainderTransformArbFxd : public lbcrypto::ChineseRemainderTransfo * @return is the output result of the transform. */ VecType InverseTransform(const VecType& element, const IntType& root, const IntType& bigMod, const IntType& bigRoot, - const usint cycloOrder); + const uint32_t cycloOrder); /** * Reset cached values for the transform to empty. @@ -518,7 +518,7 @@ class ChineseRemainderTransformArbFxd : public lbcrypto::ChineseRemainderTransfo * @param cycloOrder is the cyclotomic order of the polynomial ring. * @param modulus is the modulus of the polynomial ring. */ - void PreCompute(const usint cyclotoOrder, const IntType& modulus); + void PreCompute(const uint32_t cyclotoOrder, const IntType& modulus); /** * @brief Sets the precomputed root of unity and modulus needed for NTT @@ -530,7 +530,7 @@ class ChineseRemainderTransformArbFxd : public lbcrypto::ChineseRemainderTransfo * @param nttRoot is the root of unity needed for the NTT operation in forward * Bluestein transform. */ - void SetPreComputedNTTModulus(usint cyclotoOrder, const IntType& modulus, const IntType& nttMod, + void SetPreComputedNTTModulus(uint32_t cyclotoOrder, const IntType& modulus, const IntType& nttMod, const IntType& nttRoot); /** @@ -544,7 +544,7 @@ class ChineseRemainderTransformArbFxd : public lbcrypto::ChineseRemainderTransfo * @param nttRoot is the root of unity needed for the NTT operation in forward * Bluestein transform. */ - void SetPreComputedNTTDivisionModulus(usint cyclotoOrder, const IntType& modulus, const IntType& nttMod, + void SetPreComputedNTTDivisionModulus(uint32_t cyclotoOrder, const IntType& modulus, const IntType& nttMod, const IntType& nttRoot); /** @@ -554,7 +554,7 @@ class ChineseRemainderTransformArbFxd : public lbcrypto::ChineseRemainderTransfo * @param modulus is the modulus of the polynomial ring. * @return inverse polynomial. */ - VecType InversePolyMod(const VecType& cycloPoly, const IntType& modulus, usint power); + VecType InversePolyMod(const VecType& cycloPoly, const IntType& modulus, uint32_t power); private: /** @@ -564,7 +564,7 @@ class ChineseRemainderTransformArbFxd : public lbcrypto::ChineseRemainderTransfo * @param forward is a flag for forward/inverse transform padding. * @return is result vector with &element values with padded zeros to it */ - VecType Pad(const VecType& element, const usint cycloOrder, bool forward); + VecType Pad(const VecType& element, const uint32_t cycloOrder, bool forward); /** * @brief Dropping elements from a vector @@ -577,7 +577,7 @@ class ChineseRemainderTransformArbFxd : public lbcrypto::ChineseRemainderTransfo * tables if needed. The tables are used in the inverse dropping computations * @return is result vector with &element values with dropped elements from it */ - VecType Drop(const VecType& element, const usint cycloOrder, bool forward, const IntType& bigMod, + VecType Drop(const VecType& element, const uint32_t cycloOrder, bool forward, const IntType& bigMod, const IntType& bigRoot); // map to store the cyclotomic polynomial with polynomial ring's modulus as @@ -606,7 +606,7 @@ class ChineseRemainderTransformArbFxd : public lbcrypto::ChineseRemainderTransfo static std::map m_DivisionNTTRootOfUnity; // dimension of the NTT transform in NTT based polynomial division. - static std::map m_nttDivisionDim; + static std::map m_nttDivisionDim; }; } // namespace bigintfxd diff --git a/src/core/include/math/hal/bigintfxd/ubintfxd.h b/src/core/include/math/hal/bigintfxd/ubintfxd.h index d49272532..2cdb3218c 100644 --- a/src/core/include/math/hal/bigintfxd/ubintfxd.h +++ b/src/core/include/math/hal/bigintfxd/ubintfxd.h @@ -97,7 +97,7 @@ using U128BITS = uint128_t; #endif // forward declaration for aliases -template +template class BigIntegerFixedT; // Create default type for the MATHBACKEND 2 integer @@ -114,9 +114,9 @@ using BigInteger = BigIntegerFixedT; * * @tparam N bitwidth. */ -template +template struct Log2 { - static const usint value = 1 + Log2::value; + static const uint32_t value = 1 + Log2::value; }; /** @@ -126,7 +126,7 @@ struct Log2 { */ template <> struct Log2<2> { - static const usint value = 1; + static const uint32_t value = 1; }; /** @@ -137,7 +137,7 @@ struct Log2<2> { */ template struct LogDtype { - static const usint value = Log2<8 * sizeof(U)>::value; + static const uint32_t value = Log2<8 * sizeof(U)>::value; }; /** @@ -257,7 +257,7 @@ constexpr double LOG2_10 = 3.32192809; //!< @brief A pre-computed constant of L * @tparam uint_type native unsigned integer type * @tparam BITLENGTH maximum bitwidth supported for big integers */ -template +template class BigIntegerFixedT : public lbcrypto::BigIntegerInterface> { public: // CONSTRUCTORS @@ -405,7 +405,7 @@ class BigIntegerFixedT : public lbcrypto::BigIntegerInterface || std::is_same_v || std::is_same_v, bool> = true> T ConvertToInt() const { - constexpr usint bits = sizeof(T) * CHAR_BIT; + constexpr uint32_t bits = sizeof(T) * CHAR_BIT; T result = 0; // set num to number of equisized chunks - usint num = bits / m_uintBitLength; - usint ceilInt = m_nSize - ceilIntByUInt(m_MSB); + uint32_t num = bits / m_uintBitLength; + uint32_t ceilInt = m_nSize - ceilIntByUInt(m_MSB); // copy the values by shift and add - for (usint i = 0; i < num && (m_nSize - i - 1) >= ceilInt; i++) { + for (uint32_t i = 0; i < num && (m_nSize - i - 1) >= ceilInt; i++) { result += ((T)this->m_value[m_nSize - i - 1] << (m_uintBitLength * i)); } if (this->m_MSB > bits) { @@ -908,7 +908,7 @@ class BigIntegerFixedT : public lbcrypto::BigIntegerInterface + template friend std::ostream& operator<<(std::ostream& os, const BigIntegerFixedT& ptr_obj) { - usint counter; + uint32_t counter; // initiate to object to be printed auto print_obj = new BigIntegerFixedT(ptr_obj); // print_VALUE array stores the decimal value in the array - uschar* print_VALUE = new uschar[ptr_obj.m_numDigitInPrintval]; + uint8_t* print_VALUE = new uint8_t[ptr_obj.m_numDigitInPrintval]; for (size_t i = 0; i < ptr_obj.m_numDigitInPrintval; i++) { // reset to zero *(print_VALUE + i) = 0; @@ -1115,7 +1115,7 @@ class BigIntegerFixedT : public lbcrypto::BigIntegerInterface, myVecP(myVecP&& a); myVecP(const long n, const myT& q); // NOLINT - myVecP(usint n, const myT& q, const myT& v) : Vec(INIT_SIZE, n) { + myVecP(uint32_t n, const myT& q, const myT& v) : Vec(INIT_SIZE, n) { this->SetModulus(q); - for (usint i{0}; i < n; ++i) + for (uint32_t i{0}; i < n; ++i) (*this)[i] = v; } @@ -195,7 +195,7 @@ class myVecP : public NTL::Vec, } // sets modulus and the NTL init function uint64_t argument - inline void SetModulus(const uint64_t& value) { + inline void SetModulus(uint64_t value) { if (value == 0) { OPENFHE_THROW("SetModulus(uint64_t) cannot be zero"); } @@ -299,7 +299,7 @@ class myVecP : public NTL::Vec, */ myVecP& ModAddEq(const myT& b) { ModulusCheck("Warning: myVecP::ModAdd"); - for (usint i = 0; i < this->GetLength(); i++) { + for (uint32_t i = 0; i < this->GetLength(); i++) { this->operator[](i).ModAddEq(b, this->m_modulus); } return *this; @@ -344,14 +344,14 @@ class myVecP : public NTL::Vec, */ myVecP& ModAddEq(const myVecP& b) { ArgCheckVector(b, "myVecP ModAddEq()"); - for (usint i = 0; i < this->GetLength(); i++) { + for (uint32_t i = 0; i < this->GetLength(); i++) { this->operator[](i).ModAddEq(b[i], this->m_modulus); } return *this; } myVecP& ModAddNoCheckEq(const myVecP& b) { - for (usint i = 0; i < this->GetLength(); i++) + for (uint32_t i = 0; i < this->GetLength(); i++) this->operator[](i).ModAddEq(b[i], this->m_modulus); return *this; } @@ -381,7 +381,7 @@ class myVecP : public NTL::Vec, */ myVecP& ModSubEq(const myT& b) { ModulusCheck("Warning: myVecP::ModSubEq"); - for (usint i = 0; i < this->GetLength(); i++) { + for (uint32_t i = 0; i < this->GetLength(); i++) { this->operator[](i).ModSubEq(b, this->m_modulus); } return (*this); @@ -408,7 +408,7 @@ class myVecP : public NTL::Vec, */ myVecP& ModSubEq(const myVecP& b) { ArgCheckVector(b, "myVecP ModSubEq()"); - for (usint i = 0; i < this->GetLength(); i++) { + for (uint32_t i = 0; i < this->GetLength(); i++) { this->operator[](i).ModSubEq(b[i], this->m_modulus); } return (*this); @@ -439,7 +439,7 @@ class myVecP : public NTL::Vec, */ myVecP& ModMulEq(const myT& b) { ModulusCheck("Warning: myVecP::ModMul"); - for (usint i = 0; i < this->GetLength(); i++) { + for (uint32_t i = 0; i < this->GetLength(); i++) { this->operator[](i).ModMulEq(b, this->m_modulus); } return (*this); @@ -468,14 +468,14 @@ class myVecP : public NTL::Vec, */ myVecP& ModMulEq(const myVecP& b) { ArgCheckVector(b, "myVecP Mul()"); - for (usint i = 0; i < this->GetLength(); i++) { + for (uint32_t i = 0; i < this->GetLength(); i++) { this->operator[](i).ModMulEq(b[i], this->m_modulus); } return (*this); } myVecP& ModMulNoCheckEq(const myVecP& b) { - for (usint i = 0; i < this->GetLength(); i++) + for (uint32_t i = 0; i < this->GetLength(); i++) this->operator[](i).ModMulEq(b[i], this->m_modulus); return (*this); } @@ -587,7 +587,7 @@ class myVecP : public NTL::Vec, * @return is the digit at a specific index for all entries for a given number * base */ - myVecP GetDigitAtIndexForBase(size_t index, usint base) const; + myVecP GetDigitAtIndexForBase(size_t index, uint32_t base) const; // STRINGS & STREAMS diff --git a/src/core/include/math/hal/bigintntl/transformntl-impl.h b/src/core/include/math/hal/bigintntl/transformntl-impl.h index b43b3a0fc..1c6db1442 100644 --- a/src/core/include/math/hal/bigintntl/transformntl-impl.h +++ b/src/core/include/math/hal/bigintntl/transformntl-impl.h @@ -116,12 +116,12 @@ std::map ChineseRemainderTransformArbNtl::m_DivisionNTTRootOfUnity; template -std::map ChineseRemainderTransformArbNtl::m_nttDivisionDim; +std::map ChineseRemainderTransformArbNtl::m_nttDivisionDim; template void NumberTheoreticTransformNtl::ForwardTransformIterative(const VecType& element, const VecType& rootOfUnityTable, VecType* result) { - usint n = element.GetLength(); + uint32_t n = element.GetLength(); if (result->GetLength() != n) { OPENFHE_THROW("size of input element and size of output element not of same size"); } @@ -130,24 +130,24 @@ void NumberTheoreticTransformNtl::ForwardTransformIterative(const VecTy IntType mu = modulus.ComputeMu(); result->SetModulus(modulus); - usint msb = GetMSB64(n - 1); + uint32_t msb = GetMSB64(n - 1); for (size_t i = 0; i < n; i++) { (*result)[i] = element[ReverseBits(i, msb)]; } IntType omega, omegaFactor, oddVal, evenVal; - usint logm, i, j, indexEven, indexOdd; + uint32_t logm, i, j, indexEven, indexOdd; - usint logn = GetMSB64(n - 1); + uint32_t logn = GetMSB64(n - 1); for (logm = 1; logm <= logn; logm++) { // calculate the i indexes into the root table one time per loop - std::vector indexes(1 << (logm - 1)); - for (i = 0; i < (usint)(1 << (logm - 1)); i++) { + std::vector indexes(1 << (logm - 1)); + for (i = 0; i < (uint32_t)(1 << (logm - 1)); i++) { indexes[i] = (i << (logn - logm)); } for (j = 0; j < n; j = j + (1 << logm)) { - for (i = 0; i < (usint)(1 << (logm - 1)); i++) { + for (i = 0; i < (uint32_t)(1 << (logm - 1)); i++) { omega = rootOfUnityTable[indexes[i]]; indexEven = j + i; indexOdd = indexEven + (1 << (logm - 1)); @@ -178,14 +178,14 @@ template void NumberTheoreticTransformNtl::InverseTransformIterative(const VecType& element, const VecType& rootOfUnityInverseTable, VecType* result) { - usint n = element.GetLength(); + uint32_t n = element.GetLength(); IntType modulus = element.GetModulus(); IntType mu = modulus.ComputeMu(); NumberTheoreticTransformNtl().ForwardTransformIterative(element, rootOfUnityInverseTable, result); IntType cycloOrderInv(IntType(n).ModInverse(modulus)); - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { (*result)[i].ModMulEq(cycloOrderInv, modulus, mu); } return; @@ -194,15 +194,15 @@ void NumberTheoreticTransformNtl::InverseTransformIterative(const VecTy template void NumberTheoreticTransformNtl::ForwardTransformToBitReverseInPlace(const VecType& rootOfUnityTable, VecType* element) { - usint n = element->GetLength(); + uint32_t n = element->GetLength(); IntType modulus = element->GetModulus(); IntType mu = modulus.ComputeMu(); - usint i, m, j1, j2, indexOmega, indexLo, indexHi; + uint32_t i, m, j1, j2, indexOmega, indexLo, indexHi; IntType omega, omegaFactor, loVal, hiVal, zero(0); - usint t = (n >> 1); - usint logt1 = GetMSB64(t); + uint32_t t = (n >> 1); + uint32_t logt1 = GetMSB64(t); for (m = 1; m < n; m <<= 1) { for (i = 0; i < m; ++i) { j1 = i << logt1; @@ -239,7 +239,7 @@ template void NumberTheoreticTransformNtl::ForwardTransformToBitReverse(const VecType& element, const VecType& rootOfUnityTable, VecType* result) { - usint n = element.GetLength(); + uint32_t n = element.GetLength(); if (result->GetLength() != n) { OPENFHE_THROW("size of input element and size of output element not of same size"); } @@ -248,15 +248,15 @@ void NumberTheoreticTransformNtl::ForwardTransformToBitReverse(const Ve IntType mu = modulus.ComputeMu(); result->SetModulus(modulus); - usint i, m, j1, j2, indexOmega, indexLo, indexHi; + uint32_t i, m, j1, j2, indexOmega, indexLo, indexHi; IntType omega, omegaFactor, loVal, hiVal, zero(0); for (i = 0; i < n; ++i) { (*result)[i] = element[i]; } - usint t = (n >> 1); - usint logt1 = GetMSB64(t); + uint32_t t = (n >> 1); + uint32_t logt1 = GetMSB64(t); for (m = 1; m < n; m <<= 1) { for (i = 0; i < m; ++i) { j1 = i << logt1; @@ -298,15 +298,15 @@ template void NumberTheoreticTransformNtl::ForwardTransformToBitReverseInPlace(const VecType& rootOfUnityTable, const VecType& preconRootOfUnityTable, VecType* element) { - usint n = element->GetLength(); + uint32_t n = element->GetLength(); IntType modulus = element->GetModulus(); uint32_t indexOmega, indexHi; IntType preconOmega; IntType omega, omegaFactor, loVal, hiVal, zero(0); - usint t = (n >> 1); - usint logt1 = GetMSB64(t); + uint32_t t = (n >> 1); + uint32_t logt1 = GetMSB64(t); for (uint32_t m = 1; m < n; m <<= 1, t >>= 1, --logt1) { uint32_t j1, j2; for (uint32_t i = 0; i < m; ++i) { @@ -344,7 +344,7 @@ void NumberTheoreticTransformNtl::ForwardTransformToBitReverse(const Ve const VecType& rootOfUnityTable, const VecType& preconRootOfUnityTable, VecType* result) { - usint n = element.GetLength(); + uint32_t n = element.GetLength(); if (result->GetLength() != n) { OPENFHE_THROW("size of input element and size of output element not of same size"); @@ -362,8 +362,8 @@ void NumberTheoreticTransformNtl::ForwardTransformToBitReverse(const Ve IntType preconOmega; IntType omega, omegaFactor, loVal, hiVal, zero(0); - usint t = (n >> 1); - usint logt1 = GetMSB64(t); + uint32_t t = (n >> 1); + uint32_t logt1 = GetMSB64(t); for (uint32_t m = 1; m < n; m <<= 1, t >>= 1, --logt1) { uint32_t j1, j2; for (uint32_t i = 0; i < m; ++i) { @@ -405,15 +405,15 @@ template void NumberTheoreticTransformNtl::InverseTransformFromBitReverseInPlace(const VecType& rootOfUnityInverseTable, const IntType& cycloOrderInv, VecType* element) { - usint n = element->GetLength(); + uint32_t n = element->GetLength(); IntType modulus = element->GetModulus(); IntType mu = modulus.ComputeMu(); IntType loVal, hiVal, omega, omegaFactor; - usint i, m, j1, j2, indexOmega, indexLo, indexHi; + uint32_t i, m, j1, j2, indexOmega, indexLo, indexHi; - usint t = 1; - usint logt1 = 1; + uint32_t t = 1; + uint32_t logt1 = 1; for (m = (n >> 1); m >= 1; m >>= 1) { for (i = 0; i < m; ++i) { j1 = i << logt1; @@ -460,7 +460,7 @@ void NumberTheoreticTransformNtl::InverseTransformFromBitReverse(const const VecType& rootOfUnityInverseTable, const IntType& cycloOrderInv, VecType* result) { - usint n = element.GetLength(); + uint32_t n = element.GetLength(); if (result->GetLength() != n) { OPENFHE_THROW("size of input element and size of output element not of same size"); @@ -468,7 +468,7 @@ void NumberTheoreticTransformNtl::InverseTransformFromBitReverse(const result->SetModulus(element.GetModulus()); - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { (*result)[i] = element[i]; } InverseTransformFromBitReverseInPlace(rootOfUnityInverseTable, cycloOrderInv, result); @@ -478,16 +478,16 @@ template void NumberTheoreticTransformNtl::InverseTransformFromBitReverseInPlace( const VecType& rootOfUnityInverseTable, const VecType& preconRootOfUnityInverseTable, const IntType& cycloOrderInv, const IntType& preconCycloOrderInv, VecType* element) { - usint n = element->GetLength(); + uint32_t n = element->GetLength(); IntType modulus = element->GetModulus(); IntType loVal, hiVal, omega, omegaFactor; IntType preconOmega; - usint i, m, j1, j2, indexOmega, indexLo, indexHi; + uint32_t i, m, j1, j2, indexOmega, indexLo, indexHi; - usint t = 1; - usint logt1 = 1; + uint32_t t = 1; + uint32_t logt1 = 1; for (m = (n >> 1); m >= 1; m >>= 1) { for (i = 0; i < m; ++i) { j1 = i << logt1; @@ -533,14 +533,14 @@ template void NumberTheoreticTransformNtl::InverseTransformFromBitReverse( const VecType& element, const VecType& rootOfUnityInverseTable, const VecType& preconRootOfUnityInverseTable, const IntType& cycloOrderInv, const IntType& preconCycloOrderInv, VecType* result) { - usint n = element.GetLength(); + uint32_t n = element.GetLength(); if (result->GetLength() != n) { OPENFHE_THROW("size of input element and size of output element not of same size"); } result->SetModulus(element.GetModulus()); - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { (*result)[i] = element[i]; } InverseTransformFromBitReverseInPlace(rootOfUnityInverseTable, preconRootOfUnityInverseTable, cycloOrderInv, @@ -551,7 +551,7 @@ void NumberTheoreticTransformNtl::InverseTransformFromBitReverse( template void ChineseRemainderTransformFTTNtl::ForwardTransformToBitReverseInPlace(const IntType& rootOfUnity, - const usint CycloOrder, + const uint32_t CycloOrder, VecType* element) { if (rootOfUnity == IntType(1) || rootOfUnity == IntType(0)) { return; @@ -561,7 +561,7 @@ void ChineseRemainderTransformFTTNtl::ForwardTransformToBitReverseInPla OPENFHE_THROW("CyclotomicOrder is not a power of two"); } - usint CycloOrderHf = (CycloOrder >> 1); + uint32_t CycloOrderHf = (CycloOrder >> 1); if (element->GetLength() != CycloOrderHf) { OPENFHE_THROW("element size must be equal to CyclotomicOrder / 2"); } @@ -586,7 +586,7 @@ void ChineseRemainderTransformFTTNtl::ForwardTransformToBitReverseInPla template void ChineseRemainderTransformFTTNtl::ForwardTransformToBitReverse(const VecType& element, const IntType& rootOfUnity, - const usint CycloOrder, VecType* result) { + const uint32_t CycloOrder, VecType* result) { if (rootOfUnity == IntType(1) || rootOfUnity == IntType(0)) { *result = element; return; @@ -596,7 +596,7 @@ void ChineseRemainderTransformFTTNtl::ForwardTransformToBitReverse(cons OPENFHE_THROW("CyclotomicOrder is not a power of two"); } - usint CycloOrderHf = (CycloOrder >> 1); + uint32_t CycloOrderHf = (CycloOrder >> 1); if (result->GetLength() != CycloOrderHf) { OPENFHE_THROW("result size must be equal to CyclotomicOrder / 2"); } @@ -622,7 +622,7 @@ void ChineseRemainderTransformFTTNtl::ForwardTransformToBitReverse(cons template void ChineseRemainderTransformFTTNtl::InverseTransformFromBitReverseInPlace(const IntType& rootOfUnity, - const usint CycloOrder, + const uint32_t CycloOrder, VecType* element) { if (rootOfUnity == IntType(1) || rootOfUnity == IntType(0)) { return; @@ -632,7 +632,7 @@ void ChineseRemainderTransformFTTNtl::InverseTransformFromBitReverseInP OPENFHE_THROW("CyclotomicOrder is not a power of two"); } - usint CycloOrderHf = (CycloOrder >> 1); + uint32_t CycloOrderHf = (CycloOrder >> 1); if (element->GetLength() != CycloOrderHf) { OPENFHE_THROW("element size must be equal to CyclotomicOrder / 2"); } @@ -644,7 +644,7 @@ void ChineseRemainderTransformFTTNtl::InverseTransformFromBitReverseInP PreCompute(rootOfUnity, CycloOrder, modulus); } - usint msb = GetMSB64(CycloOrderHf - 1); + uint32_t msb = GetMSB64(CycloOrderHf - 1); // if (typeid(IntType) == typeid(NativeInteger)) { // NumberTheoreticTransformNtl().InverseTransformFromBitReverseInPlace( // m_rootOfUnityInverseReverseTableByModulus[modulus], @@ -660,7 +660,7 @@ void ChineseRemainderTransformFTTNtl::InverseTransformFromBitReverseInP template void ChineseRemainderTransformFTTNtl::InverseTransformFromBitReverse(const VecType& element, const IntType& rootOfUnity, - const usint CycloOrder, VecType* result) { + const uint32_t CycloOrder, VecType* result) { if (rootOfUnity == IntType(1) || rootOfUnity == IntType(0)) { *result = element; return; @@ -670,7 +670,7 @@ void ChineseRemainderTransformFTTNtl::InverseTransformFromBitReverse(co OPENFHE_THROW("CyclotomicOrder is not a power of two"); } - usint CycloOrderHf = (CycloOrder >> 1); + uint32_t CycloOrderHf = (CycloOrder >> 1); if (result->GetLength() != CycloOrderHf) { OPENFHE_THROW("result size must be equal to CyclotomicOrder / 2"); } @@ -682,13 +682,13 @@ void ChineseRemainderTransformFTTNtl::InverseTransformFromBitReverse(co PreCompute(rootOfUnity, CycloOrder, modulus); } - usint n = element.GetLength(); + uint32_t n = element.GetLength(); result->SetModulus(element.GetModulus()); - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { (*result)[i] = element[i]; } - usint msb = GetMSB64(CycloOrderHf - 1); + uint32_t msb = GetMSB64(CycloOrderHf - 1); // if (typeid(IntType) == typeid(NativeInteger)) { // NumberTheoreticTransformNtl().InverseTransformFromBitReverseInPlace( // m_rootOfUnityInverseReverseTableByModulus[modulus], @@ -704,23 +704,23 @@ void ChineseRemainderTransformFTTNtl::InverseTransformFromBitReverse(co } template -void ChineseRemainderTransformFTTNtl::PreCompute(const IntType& rootOfUnity, const usint CycloOrder, +void ChineseRemainderTransformFTTNtl::PreCompute(const IntType& rootOfUnity, const uint32_t CycloOrder, const IntType& modulus) { // Half of cyclo order - usint CycloOrderHf = (CycloOrder >> 1); + uint32_t CycloOrderHf = (CycloOrder >> 1); auto mapSearch = m_rootOfUnityReverseTableByModulus.find(modulus); if (mapSearch == m_rootOfUnityReverseTableByModulus.end() || mapSearch->second.GetLength() != CycloOrderHf) { #pragma omp critical { IntType x(1), xinv(1); - usint msb = GetMSB64(CycloOrderHf - 1); + uint32_t msb = GetMSB64(CycloOrderHf - 1); IntType mu = modulus.ComputeMu(); VecType Table(CycloOrderHf, modulus); VecType TableI(CycloOrderHf, modulus); IntType rootOfUnityInverse = rootOfUnity.ModInverse(modulus); - usint iinv; - for (usint i = 0; i < CycloOrderHf; i++) { + uint32_t iinv; + for (uint32_t i = 0; i < CycloOrderHf; i++) { iinv = ReverseBits(i, msb); Table[iinv] = x; TableI[iinv] = xinv; @@ -731,7 +731,7 @@ void ChineseRemainderTransformFTTNtl::PreCompute(const IntType& rootOfU m_rootOfUnityInverseReverseTableByModulus[modulus] = TableI; VecType TableCOI(msb + 1, modulus); - for (usint i = 0; i < msb + 1; i++) { + for (uint32_t i = 0; i < msb + 1; i++) { IntType coInv(IntType(1 << i).ModInverse(modulus)); TableCOI[i] = coInv; } @@ -742,7 +742,7 @@ void ChineseRemainderTransformFTTNtl::PreCompute(const IntType& rootOfU // VecType preconTable(CycloOrderHf, nativeModulus); // VecType preconTableI(CycloOrderHf, nativeModulus); - // for (usint i = 0; i < CycloOrderHf; i++) { + // for (uint32_t i = 0; i < CycloOrderHf; i++) { // preconTable[i] = NativeInteger( m_rootOfUnityReverseTableByModulus[modulus][i] // .ConvertToInt()).PrepModMulConst(nativeModulus); // preconTableI[i] = NativeInteger( m_rootOfUnityInverseReverseTableByModulus[modulus][i] @@ -750,7 +750,7 @@ void ChineseRemainderTransformFTTNtl::PreCompute(const IntType& rootOfU // } // VecType preconTableCOI(msb + 1, nativeModulus); - // for (usint i = 0; i < msb + 1; i++) { + // for (uint32_t i = 0; i < msb + 1; i++) { // preconTableCOI[i] = NativeInteger( m_cycloOrderInverseTableByModulus[modulus][i] // .ConvertToInt()).PrepModMulConst(nativeModulus); // } @@ -764,16 +764,16 @@ void ChineseRemainderTransformFTTNtl::PreCompute(const IntType& rootOfU } template -void ChineseRemainderTransformFTTNtl::PreCompute(std::vector& rootOfUnity, const usint CycloOrder, +void ChineseRemainderTransformFTTNtl::PreCompute(std::vector& rootOfUnity, const uint32_t CycloOrder, std::vector& moduliiChain) { - usint numOfRootU = rootOfUnity.size(); - usint numModulii = moduliiChain.size(); + uint32_t numOfRootU = rootOfUnity.size(); + uint32_t numModulii = moduliiChain.size(); if (numOfRootU != numModulii) { OPENFHE_THROW("size of root of unity and size of moduli chain not of same size"); } - for (usint i = 0; i < numOfRootU; ++i) { + for (uint32_t i = 0; i < numOfRootU; ++i) { IntType currentRoot(rootOfUnity[i]); IntType currentMod(moduliiChain[i]); PreCompute(currentRoot, CycloOrder, currentMod); @@ -791,8 +791,8 @@ void ChineseRemainderTransformFTTNtl::Reset() { } template -void BluesteinFFTNtl::PreComputeDefaultNTTModulusRoot(usint cycloOrder, const IntType& modulus) { - usint nttDim = std::pow(2, std::ceil(std::log2(2 * cycloOrder - 1))); +void BluesteinFFTNtl::PreComputeDefaultNTTModulusRoot(uint32_t cycloOrder, const IntType& modulus) { + uint32_t nttDim = std::pow(2, std::ceil(std::log2(2 * cycloOrder - 1))); const auto nttModulus = LastPrime(std::log2(nttDim) + 2 * modulus.GetMSB(), nttDim); const auto nttRoot = RootOfUnity(nttDim, nttModulus); const ModulusRoot nttModulusRoot = {nttModulus, nttRoot}; @@ -802,9 +802,9 @@ void BluesteinFFTNtl::PreComputeDefaultNTTModulusRoot(usint cycloOrder, } template -void BluesteinFFTNtl::PreComputeRootTableForNTT(usint cyclotoOrder, +void BluesteinFFTNtl::PreComputeRootTableForNTT(uint32_t cyclotoOrder, const ModulusRoot& nttModulusRoot) { - usint nttDim = std::pow(2, std::ceil(std::log2(2 * cyclotoOrder - 1))); + uint32_t nttDim = std::pow(2, std::ceil(std::log2(2 * cyclotoOrder - 1))); const auto& nttModulus = nttModulusRoot.first; const auto& nttRoot = nttModulusRoot.second; @@ -812,18 +812,18 @@ void BluesteinFFTNtl::PreComputeRootTableForNTT(usint cyclotoOrder, auto rootInv = root.ModInverse(nttModulus); - usint nttDimHf = (nttDim >> 1); + uint32_t nttDimHf = (nttDim >> 1); VecType rootTable(nttDimHf, nttModulus); VecType rootTableInverse(nttDimHf, nttModulus); IntType x(1); - for (usint i = 0; i < nttDimHf; i++) { + for (uint32_t i = 0; i < nttDimHf; i++) { rootTable[i] = x; x = x.ModMul(root, nttModulus); } x = 1; - for (usint i = 0; i < nttDimHf; i++) { + for (uint32_t i = 0; i < nttDimHf; i++) { rootTableInverse[i] = x; x = x.ModMul(rootInv, nttModulus); } @@ -833,13 +833,13 @@ void BluesteinFFTNtl::PreComputeRootTableForNTT(usint cyclotoOrder, } template -void BluesteinFFTNtl::PreComputePowers(usint cycloOrder, const ModulusRoot& modulusRoot) { +void BluesteinFFTNtl::PreComputePowers(uint32_t cycloOrder, const ModulusRoot& modulusRoot) { const auto& modulus = modulusRoot.first; const auto& root = modulusRoot.second; VecType powers(cycloOrder, modulus); powers[0] = 1; - for (usint i = 1; i < cycloOrder; i++) { + for (uint32_t i = 1; i < cycloOrder; i++) { auto iSqr = (i * i) % (2 * cycloOrder); auto val = root.ModExp(IntType(iSqr), modulus); powers[i] = val; @@ -848,7 +848,7 @@ void BluesteinFFTNtl::PreComputePowers(usint cycloOrder, const ModulusR } template -void BluesteinFFTNtl::PreComputeRBTable(usint cycloOrder, const ModulusRootPair& modulusRootPair) { +void BluesteinFFTNtl::PreComputeRBTable(uint32_t cycloOrder, const ModulusRootPair& modulusRootPair) { const auto& modulusRoot = modulusRootPair.first; const auto& modulus = modulusRoot.first; const auto& root = modulusRoot.second; @@ -859,11 +859,11 @@ void BluesteinFFTNtl::PreComputeRBTable(usint cycloOrder, const Modulus // const auto &nttRoot = nttModulusRoot.second; // assumes rootTable is precomputed const auto& rootTable = m_rootOfUnityTableByModulusRoot[nttModulusRoot]; - usint nttDim = std::pow(2, std::ceil(std::log2(2 * cycloOrder - 1))); + uint32_t nttDim = std::pow(2, std::ceil(std::log2(2 * cycloOrder - 1))); VecType b(2 * cycloOrder - 1, modulus); b[cycloOrder - 1] = 1; - for (usint i = 1; i < cycloOrder; i++) { + for (uint32_t i = 1; i < cycloOrder; i++) { auto iSqr = (i * i) % (2 * cycloOrder); auto val = rootInv.ModExp(IntType(iSqr), modulus); b[cycloOrder - 1 + i] = val; @@ -880,7 +880,7 @@ void BluesteinFFTNtl::PreComputeRBTable(usint cycloOrder, const Modulus template VecType BluesteinFFTNtl::ForwardTransform(const VecType& element, const IntType& root, - const usint cycloOrder) { + const uint32_t cycloOrder) { const auto& modulus = element.GetModulus(); const auto& nttModulusRoot = m_defaultNTTModulusRoot[modulus]; @@ -888,7 +888,7 @@ VecType BluesteinFFTNtl::ForwardTransform(const VecType& element, const } template -VecType BluesteinFFTNtl::ForwardTransform(const VecType& element, const IntType& root, const usint cycloOrder, +VecType BluesteinFFTNtl::ForwardTransform(const VecType& element, const IntType& root, const uint32_t cycloOrder, const ModulusRoot& nttModulusRoot) { if (element.GetLength() != cycloOrder) { OPENFHE_THROW("expected size of element vector should be equal to cyclotomic order"); @@ -905,7 +905,7 @@ VecType BluesteinFFTNtl::ForwardTransform(const VecType& element, const m_rootOfUnityInverseTableByModulusRoot[nttModulusRoot]; // assumes rootTableInverse is precomputed VecType x = element.ModMul(powers); - usint nttDim = std::pow(2, std::ceil(std::log2(2 * cycloOrder - 1))); + uint32_t nttDim = std::pow(2, std::ceil(std::log2(2 * cycloOrder - 1))); auto Ra = PadZeros(x, nttDim); Ra.SetModulus(nttModulus); VecType RA(nttDim); @@ -926,15 +926,15 @@ VecType BluesteinFFTNtl::ForwardTransform(const VecType& element, const } template -VecType BluesteinFFTNtl::PadZeros(const VecType& a, const usint finalSize) { - usint s = a.GetLength(); +VecType BluesteinFFTNtl::PadZeros(const VecType& a, const uint32_t finalSize) { + uint32_t s = a.GetLength(); VecType result(finalSize, a.GetModulus()); - for (usint i = 0; i < s; i++) { + for (uint32_t i = 0; i < s; i++) { result[i] = a[i]; } - for (usint i = a.GetLength(); i < finalSize; i++) { + for (uint32_t i = a.GetLength(); i < finalSize; i++) { result[i] = IntType(0); } @@ -942,10 +942,10 @@ VecType BluesteinFFTNtl::PadZeros(const VecType& a, const usint finalSi } template -VecType BluesteinFFTNtl::Resize(const VecType& a, usint lo, usint hi) { +VecType BluesteinFFTNtl::Resize(const VecType& a, uint32_t lo, uint32_t hi) { VecType result(hi - lo + 1, a.GetModulus()); - for (usint i = lo, j = 0; i <= hi; i++, j++) { + for (uint32_t i = lo, j = 0; i <= hi; i++, j++) { result[j] = a[i]; } @@ -967,12 +967,12 @@ void ChineseRemainderTransformArbNtl::SetCylotomicPolynomial(const VecT } template -void ChineseRemainderTransformArbNtl::PreCompute(const usint cyclotoOrder, const IntType& modulus) { +void ChineseRemainderTransformArbNtl::PreCompute(const uint32_t cyclotoOrder, const IntType& modulus) { BluesteinFFTNtl().PreComputeDefaultNTTModulusRoot(cyclotoOrder, modulus); } template -void ChineseRemainderTransformArbNtl::SetPreComputedNTTModulus(usint cyclotoOrder, const IntType& modulus, +void ChineseRemainderTransformArbNtl::SetPreComputedNTTModulus(uint32_t cyclotoOrder, const IntType& modulus, const IntType& nttModulus, const IntType& nttRoot) { const ModulusRoot nttModulusRoot = {nttModulus, nttRoot}; @@ -980,15 +980,15 @@ void ChineseRemainderTransformArbNtl::SetPreComputedNTTModulus(usint cy } template -void ChineseRemainderTransformArbNtl::SetPreComputedNTTDivisionModulus(usint cyclotoOrder, +void ChineseRemainderTransformArbNtl::SetPreComputedNTTDivisionModulus(uint32_t cyclotoOrder, const IntType& modulus, const IntType& nttMod, const IntType& nttRootBig) { - usint n = GetTotient(cyclotoOrder); - usint power = cyclotoOrder - n; + uint32_t n = GetTotient(cyclotoOrder); + uint32_t power = cyclotoOrder - n; m_nttDivisionDim[cyclotoOrder] = 2 * std::pow(2, std::ceil(std::log2(power))); - usint nttDimBig = std::pow(2, std::ceil(std::log2(2 * cyclotoOrder - 1))); + uint32_t nttDimBig = std::pow(2, std::ceil(std::log2(2 * cyclotoOrder - 1))); // Computes the root of unity for the division NTT based on the root of unity // for regular NTT @@ -997,22 +997,22 @@ void ChineseRemainderTransformArbNtl::SetPreComputedNTTDivisionModulus( m_DivisionNTTModulus[modulus] = nttMod; m_DivisionNTTRootOfUnity[modulus] = nttRoot; // part0 setting of rootTable and inverse rootTable - usint nttDim = m_nttDivisionDim[cyclotoOrder]; + uint32_t nttDim = m_nttDivisionDim[cyclotoOrder]; IntType root(nttRoot); auto rootInv = root.ModInverse(nttMod); - usint nttDimHf = (nttDim >> 1); + uint32_t nttDimHf = (nttDim >> 1); VecType rootTable(nttDimHf, nttMod); VecType rootTableInverse(nttDimHf, nttMod); IntType x(1); - for (usint i = 0; i < nttDimHf; i++) { + for (uint32_t i = 0; i < nttDimHf; i++) { rootTable[i] = x; x = x.ModMul(root, nttMod); } x = 1; - for (usint i = 0; i < nttDimHf; i++) { + for (uint32_t i = 0; i < nttDimHf; i++) { rootTableInverse[i] = x; x = x.ModMul(rootInv, nttMod); } @@ -1034,7 +1034,7 @@ void ChineseRemainderTransformArbNtl::SetPreComputedNTTDivisionModulus( const auto& cycloPoly = m_cyclotomicPolyMap[modulus]; VecType QForwardTransform(nttDim, nttMod); - for (usint i = 0; i < cycloPoly.GetLength(); i++) { + for (uint32_t i = 0; i < cycloPoly.GetLength(); i++) { QForwardTransform[i] = cycloPoly[i]; } @@ -1046,17 +1046,17 @@ void ChineseRemainderTransformArbNtl::SetPreComputedNTTDivisionModulus( template VecType ChineseRemainderTransformArbNtl::InversePolyMod(const VecType& cycloPoly, const IntType& modulus, - usint power) { + uint32_t power) { VecType result(power, modulus); - usint r = std::ceil(std::log2(power)); + uint32_t r = std::ceil(std::log2(power)); VecType h(1, modulus); // h is a unit polynomial h[0] = 1; // Precompute the Barrett mu parameter IntType mu = modulus.ComputeMu(); - for (usint i = 0; i < r; i++) { - usint qDegree = std::pow(2, i + 1); + for (uint32_t i = 0; i < r; i++) { + uint32_t qDegree = std::pow(2, i + 1); VecType q(qDegree + 1, modulus); // q = x^(2^i+1) q[qDegree] = 1; auto hSquare = PolynomialMultiplication(h, h); @@ -1064,7 +1064,7 @@ VecType ChineseRemainderTransformArbNtl::InversePolyMod(const VecType& auto a = h * IntType(2); auto b = PolynomialMultiplication(hSquare, cycloPoly); // b = 2h - gh^2 - for (usint j = 0; j < b.GetLength(); j++) { + for (uint32_t j = 0; j < b.GetLength(); j++) { if (j < a.GetLength()) { b[j] = a[j].ModSub(b[j], modulus, mu); } @@ -1075,7 +1075,7 @@ VecType ChineseRemainderTransformArbNtl::InversePolyMod(const VecType& h = PolyMod(b, q, modulus); } // take modulo x^power - for (usint i = 0; i < power; i++) { + for (uint32_t i = 0; i < power; i++) { result[i] = h[i]; } @@ -1085,8 +1085,8 @@ VecType ChineseRemainderTransformArbNtl::InversePolyMod(const VecType& template VecType ChineseRemainderTransformArbNtl::ForwardTransform(const VecType& element, const IntType& root, const IntType& nttModulus, const IntType& nttRoot, - const usint cycloOrder) { - usint phim = GetTotient(cycloOrder); + const uint32_t cycloOrder) { + uint32_t phim = GetTotient(cycloOrder); if (element.GetLength() != phim) { OPENFHE_THROW("element size should be equal to phim"); } @@ -1123,8 +1123,8 @@ VecType ChineseRemainderTransformArbNtl::ForwardTransform(const VecType template VecType ChineseRemainderTransformArbNtl::InverseTransform(const VecType& element, const IntType& root, const IntType& nttModulus, const IntType& nttRoot, - const usint cycloOrder) { - usint phim = GetTotient(cycloOrder); + const uint32_t cycloOrder) { + uint32_t phim = GetTotient(cycloOrder); if (element.GetLength() != phim) { OPENFHE_THROW("element size should be equal to phim"); } @@ -1160,20 +1160,20 @@ VecType ChineseRemainderTransformArbNtl::InverseTransform(const VecType } template -VecType ChineseRemainderTransformArbNtl::Pad(const VecType& element, const usint cycloOrder, bool forward) { - usint n = GetTotient(cycloOrder); +VecType ChineseRemainderTransformArbNtl::Pad(const VecType& element, const uint32_t cycloOrder, bool forward) { + uint32_t n = GetTotient(cycloOrder); const auto& modulus = element.GetModulus(); VecType inputToBluestein(cycloOrder, modulus); if (forward) { // Forward transform padding - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { inputToBluestein[i] = element[i]; } } else { // Inverse transform padding auto tList = GetTotientList(cycloOrder); - usint i = 0; + uint32_t i = 0; for (auto& coprime : tList) { inputToBluestein[coprime] = element[i++]; } @@ -1183,16 +1183,16 @@ VecType ChineseRemainderTransformArbNtl::Pad(const VecType& element, co } template -VecType ChineseRemainderTransformArbNtl::Drop(const VecType& element, const usint cycloOrder, bool forward, +VecType ChineseRemainderTransformArbNtl::Drop(const VecType& element, const uint32_t cycloOrder, bool forward, const IntType& bigMod, const IntType& bigRoot) { - usint n = GetTotient(cycloOrder); + uint32_t n = GetTotient(cycloOrder); const auto& modulus = element.GetModulus(); VecType output(n, modulus); if (forward) { // Forward transform drop auto tList = GetTotientList(cycloOrder); - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { output[i] = element[tList[i]]; } } @@ -1202,7 +1202,7 @@ VecType ChineseRemainderTransformArbNtl::Drop(const VecType& element, c // cycloOrder is prime: Reduce mod Phi_{n+1}(x) // Reduction involves subtracting the coeff of x^n from all terms auto coeff_n = element[n]; - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { output[i] = element[i].ModSub(coeff_n, modulus, mu); } } @@ -1211,7 +1211,7 @@ VecType ChineseRemainderTransformArbNtl::Drop(const VecType& element, c // cycloOrder is 2*prime: 2 Step reduction // First reduce mod x^(n+1)+1 (=(x+1)*Phi_{2*(n+1)}(x)) // Subtract co-efficient of x^(i+n+1) from x^(i) - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { auto coeff_i = element[i]; auto coeff_ip = element[i + n + 1]; output[i] = coeff_i.ModSub(coeff_ip, modulus, mu); @@ -1219,7 +1219,7 @@ VecType ChineseRemainderTransformArbNtl::Drop(const VecType& element, c auto coeff_n = element[n].ModSub(element[2 * n + 1], modulus, mu); // Now reduce mod Phi_{2*(n+1)}(x) // Similar to the prime case but with alternating signs - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { if (i % 2 == 0) { output[i].ModSubEq(coeff_n, modulus, mu); } @@ -1243,8 +1243,8 @@ VecType ChineseRemainderTransformArbNtl::Drop(const VecType& element, c const auto& rootTable = m_rootOfUnityDivisionTableByModulus[nttMod]; VecType aPadded2(m_nttDivisionDim[cycloOrder], nttMod); // perform mod operation - usint power = cycloOrder - n; - for (usint i = n; i < element.GetLength(); i++) { + uint32_t power = cycloOrder - n; + for (uint32_t i = n; i < element.GetLength(); i++) { aPadded2[power - (i - n) - 1] = element[i]; } VecType A(m_nttDivisionDim[cycloOrder]); @@ -1255,7 +1255,7 @@ VecType ChineseRemainderTransformArbNtl::Drop(const VecType& element, c NumberTheoreticTransformNtl().InverseTransformIterative(AB, rootTableInverse, &a); VecType quotient(m_nttDivisionDim[cycloOrder], modulus); - for (usint i = 0; i < power; i++) { + for (uint32_t i = 0; i < power; i++) { quotient[i] = a[i]; } quotient.ModEq(modulus); @@ -1273,7 +1273,7 @@ VecType ChineseRemainderTransformArbNtl::Drop(const VecType& element, c IntType mu = modulus.ComputeMu(); // Precompute the Barrett mu parameter - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { output[i] = element[i].ModSub(newQuotient2[cycloOrder - 1 - i], modulus, mu); } } diff --git a/src/core/include/math/hal/bigintntl/transformntl.h b/src/core/include/math/hal/bigintntl/transformntl.h index c551efe1f..b7fdd29e2 100644 --- a/src/core/include/math/hal/bigintntl/transformntl.h +++ b/src/core/include/math/hal/bigintntl/transformntl.h @@ -257,7 +257,7 @@ class ChineseRemainderTransformFTTNtl : public lbcrypto::ChineseRemainderTransfo * size as input or a throw of error occurs. * @see NumberTheoreticTransform::ForwardTransformToBitReverseInPlace() */ - void ForwardTransformToBitReverse(const VecType& element, const IntType& rootOfUnity, const usint CycloOrder, + void ForwardTransformToBitReverse(const VecType& element, const IntType& rootOfUnity, const uint32_t CycloOrder, VecType* result); /** @@ -273,7 +273,7 @@ class ChineseRemainderTransformFTTNtl : public lbcrypto::ChineseRemainderTransfo * @return none * @see NumberTheoreticTransform::ForwardTransformToBitReverseInPlace() */ - void ForwardTransformToBitReverseInPlace(const IntType& rootOfUnity, const usint CycloOrder, VecType* element); + void ForwardTransformToBitReverseInPlace(const IntType& rootOfUnity, const uint32_t CycloOrder, VecType* element); /** * Copies \p element into \p result and calls NumberTheoreticTransform::InverseTransformFromBitReverseInPlace() @@ -292,7 +292,7 @@ class ChineseRemainderTransformFTTNtl : public lbcrypto::ChineseRemainderTransfo * @return none * @see NumberTheoreticTransform::InverseTransformFromBitReverseInPlace() */ - void InverseTransformFromBitReverse(const VecType& element, const IntType& rootOfUnity, const usint CycloOrder, + void InverseTransformFromBitReverse(const VecType& element, const IntType& rootOfUnity, const uint32_t CycloOrder, VecType* result); /** @@ -308,7 +308,7 @@ class ChineseRemainderTransformFTTNtl : public lbcrypto::ChineseRemainderTransfo * @return none * @see NumberTheoreticTransform::InverseTransformFromBitReverseInPlace() */ - void InverseTransformFromBitReverseInPlace(const IntType& rootOfUnity, const usint CycloOrder, VecType* element); + void InverseTransformFromBitReverseInPlace(const IntType& rootOfUnity, const uint32_t CycloOrder, VecType* element); /** * Precomputation of root of unity tables for transforms in the ring @@ -320,7 +320,7 @@ class ChineseRemainderTransformFTTNtl : public lbcrypto::ChineseRemainderTransfo * @param CycloOrder is a power-of-two, equal to 2n. * @param modulus is q, the prime modulus */ - void PreCompute(const IntType& rootOfUnity, const usint CycloOrder, const IntType& modulus); + void PreCompute(const IntType& rootOfUnity, const uint32_t CycloOrder, const IntType& modulus); /** * Precomputation of root of unity tables for transforms in the ring @@ -332,7 +332,7 @@ class ChineseRemainderTransformFTTNtl : public lbcrypto::ChineseRemainderTransfo * @param CycloOrder is a power-of-two, equal to 2n. * @param &moduliChain is the vector of prime moduli qi such that 2n|qi-1 */ - void PreCompute(std::vector& rootOfUnity, const usint CycloOrder, std::vector& moduliChain); + void PreCompute(std::vector& rootOfUnity, const uint32_t CycloOrder, std::vector& moduliChain); /** * Reset cached values for the root of unity tables to empty. @@ -383,8 +383,8 @@ class BluesteinFFTNtl { * @param cycloOrder is the cyclotomic order. * @return is the output result of the transform. */ - VecType ForwardTransform(const VecType& element, const IntType& root, const usint cycloOrder); - VecType ForwardTransform(const VecType& element, const IntType& root, const usint cycloOrder, + VecType ForwardTransform(const VecType& element, const IntType& root, const uint32_t cycloOrder); + VecType ForwardTransform(const VecType& element, const IntType& root, const uint32_t cycloOrder, const ModulusRoot& nttModulusRoot); /** @@ -394,7 +394,7 @@ class BluesteinFFTNtl { * @return output vector padded with (finalSize - initial size)additional * zeros. */ - VecType PadZeros(const VecType& a, const usint finalSize); + VecType PadZeros(const VecType& a, const uint32_t finalSize); /** * @@ -403,9 +403,9 @@ class BluesteinFFTNtl { * @param hi is higher coefficient index. * @return output vector s.t output vector = a[lo]...a[hi]. */ - VecType Resize(const VecType& a, usint lo, usint hi); + VecType Resize(const VecType& a, uint32_t lo, uint32_t hi); - // void PreComputeNTTModulus(usint cycloOrder, const std::vector + // void PreComputeNTTModulus(uint32_t cycloOrder, const std::vector // &modulii); /** @@ -414,7 +414,7 @@ class BluesteinFFTNtl { * @param cycloOrder is the cyclotomic order of the polynomial. * @param modulus is the modulus of the polynomial. */ - void PreComputeDefaultNTTModulusRoot(usint cycloOrder, const IntType& modulus); + void PreComputeDefaultNTTModulusRoot(uint32_t cycloOrder, const IntType& modulus); /** * @brief Precomputes the root of unity table needed for NTT operation in @@ -422,7 +422,7 @@ class BluesteinFFTNtl { * @param cycloOrder is the cyclotomic order of the polynomial ring. * @param modulus is the modulus of the polynomial. */ - void PreComputeRootTableForNTT(usint cycloOrder, const ModulusRoot& nttModulusRoot); + void PreComputeRootTableForNTT(uint32_t cycloOrder, const ModulusRoot& nttModulusRoot); /** * @brief precomputes the powers of root used in forward Bluestein transform. @@ -430,7 +430,7 @@ class BluesteinFFTNtl { * @param modulus is the modulus of the polynomial ring. * @param root is the root of unity s.t. root^2m = 1. */ - void PreComputePowers(usint cycloOrder, const ModulusRoot& modulusRoot); + void PreComputePowers(uint32_t cycloOrder, const ModulusRoot& modulusRoot); /** * @brief precomputes the NTT transform of the power of root of unity used in @@ -441,7 +441,7 @@ class BluesteinFFTNtl { * @param bigMod is the modulus required for the NTT transform. * @param bigRoot is the root of unity required for the NTT transform. */ - void PreComputeRBTable(usint cycloOrder, const ModulusRootPair& modulusRootPair); + void PreComputeRBTable(uint32_t cycloOrder, const ModulusRootPair& modulusRootPair); /** * Reset cached values for the transform to empty. @@ -493,7 +493,7 @@ class ChineseRemainderTransformArbNtl : public lbcrypto::ChineseRemainderTransfo * @return is the output result of the transform. */ VecType ForwardTransform(const VecType& element, const IntType& root, const IntType& bigMod, const IntType& bigRoot, - const usint cycloOrder); + const uint32_t cycloOrder); /** * Inverse transform. @@ -507,7 +507,7 @@ class ChineseRemainderTransformArbNtl : public lbcrypto::ChineseRemainderTransfo * @return is the output result of the transform. */ VecType InverseTransform(const VecType& element, const IntType& root, const IntType& bigMod, const IntType& bigRoot, - const usint cycloOrder); + const uint32_t cycloOrder); /** * Reset cached values for the transform to empty. @@ -520,7 +520,7 @@ class ChineseRemainderTransformArbNtl : public lbcrypto::ChineseRemainderTransfo * @param cycloOrder is the cyclotomic order of the polynomial ring. * @param modulus is the modulus of the polynomial ring. */ - void PreCompute(const usint cyclotoOrder, const IntType& modulus); + void PreCompute(const uint32_t cyclotoOrder, const IntType& modulus); /** * @brief Sets the precomputed root of unity and modulus needed for NTT @@ -532,7 +532,7 @@ class ChineseRemainderTransformArbNtl : public lbcrypto::ChineseRemainderTransfo * @param nttRoot is the root of unity needed for the NTT operation in forward * Bluestein transform. */ - void SetPreComputedNTTModulus(usint cyclotoOrder, const IntType& modulus, const IntType& nttMod, + void SetPreComputedNTTModulus(uint32_t cyclotoOrder, const IntType& modulus, const IntType& nttMod, const IntType& nttRoot); /** @@ -546,7 +546,7 @@ class ChineseRemainderTransformArbNtl : public lbcrypto::ChineseRemainderTransfo * @param nttRoot is the root of unity needed for the NTT operation in forward * Bluestein transform. */ - void SetPreComputedNTTDivisionModulus(usint cyclotoOrder, const IntType& modulus, const IntType& nttMod, + void SetPreComputedNTTDivisionModulus(uint32_t cyclotoOrder, const IntType& modulus, const IntType& nttMod, const IntType& nttRoot); /** @@ -556,7 +556,7 @@ class ChineseRemainderTransformArbNtl : public lbcrypto::ChineseRemainderTransfo * @param modulus is the modulus of the polynomial ring. * @return inverse polynomial. */ - VecType InversePolyMod(const VecType& cycloPoly, const IntType& modulus, usint power); + VecType InversePolyMod(const VecType& cycloPoly, const IntType& modulus, uint32_t power); private: /** @@ -566,7 +566,7 @@ class ChineseRemainderTransformArbNtl : public lbcrypto::ChineseRemainderTransfo * @param forward is a flag for forward/inverse transform padding. * @return is result vector with &element values with padded zeros to it */ - VecType Pad(const VecType& element, const usint cycloOrder, bool forward); + VecType Pad(const VecType& element, const uint32_t cycloOrder, bool forward); /** * @brief Dropping elements from a vector @@ -579,7 +579,7 @@ class ChineseRemainderTransformArbNtl : public lbcrypto::ChineseRemainderTransfo * tables if needed. The tables are used in the inverse dropping computations * @return is result vector with &element values with dropped elements from it */ - VecType Drop(const VecType& element, const usint cycloOrder, bool forward, const IntType& bigMod, + VecType Drop(const VecType& element, const uint32_t cycloOrder, bool forward, const IntType& bigMod, const IntType& bigRoot); // map to store the cyclotomic polynomial with polynomial ring's modulus as @@ -608,7 +608,7 @@ class ChineseRemainderTransformArbNtl : public lbcrypto::ChineseRemainderTransfo static std::map m_DivisionNTTRootOfUnity; // dimension of the NTT transform in NTT based polynomial division. - static std::map m_nttDivisionDim; + static std::map m_nttDivisionDim; }; } // namespace NTL diff --git a/src/core/include/math/hal/bigintntl/ubintntl.h b/src/core/include/math/hal/bigintntl/ubintntl.h index e98f1e447..b072e08c7 100644 --- a/src/core/include/math/hal/bigintntl/ubintntl.h +++ b/src/core/include/math/hal/bigintntl/ubintntl.h @@ -88,9 +88,9 @@ using BigInteger = myZZ; * * @tparam N bitwidth. */ -template +template struct Log2 { - static const usint value = 1 + Log2::value; + static const uint32_t value = 1 + Log2::value; }; /** @@ -100,7 +100,7 @@ struct Log2 { */ template <> struct Log2<2> { - static const usint value = 1; + static const uint32_t value = 1; }; class myZZ : public NTL::ZZ, public lbcrypto::BigIntegerInterface { @@ -332,7 +332,7 @@ class myZZ : public NTL::ZZ, public lbcrypto::BigIntegerInterface { * @param p the exponent. * @return is the result of the exponentiation operation. */ - myZZ Exp(const usint p) const { + myZZ Exp(const uint32_t p) const { return power(*this, p); } @@ -342,7 +342,7 @@ class myZZ : public NTL::ZZ, public lbcrypto::BigIntegerInterface { * @param p the exponent. * @return is the result of the exponentiation operation. */ - myZZ& ExpEq(const usint p) { + myZZ& ExpEq(const uint32_t p) { *this = power(*this, p); return *this; } @@ -824,7 +824,7 @@ class myZZ : public NTL::ZZ, public lbcrypto::BigIntegerInterface { * @param shift # of bits. * @return result of the shift operation. */ - myZZ LShift(usshort shift) const { + myZZ LShift(uint16_t shift) const { return *static_cast(this) << shift; } @@ -834,7 +834,7 @@ class myZZ : public NTL::ZZ, public lbcrypto::BigIntegerInterface { * @param shift # of bits. * @return result of the shift operation. */ - myZZ& LShiftEq(usshort shift) { + myZZ& LShiftEq(uint16_t shift) { *static_cast(this) <<= shift; return *this; } @@ -845,7 +845,7 @@ class myZZ : public NTL::ZZ, public lbcrypto::BigIntegerInterface { * @param shift # of bits. * @return result of the shift operation. */ - myZZ RShift(usshort shift) const { + myZZ RShift(uint16_t shift) const { return *static_cast(this) >> shift; } @@ -855,7 +855,7 @@ class myZZ : public NTL::ZZ, public lbcrypto::BigIntegerInterface { * @param shift # of bits. * @return result of the shift operation. */ - myZZ& RShiftEq(usshort shift) { + myZZ& RShiftEq(uint16_t shift) { *static_cast(this) >>= shift; return *this; } @@ -912,7 +912,7 @@ class myZZ : public NTL::ZZ, public lbcrypto::BigIntegerInterface { static const myZZ& zero(); - usint GetMSB() const; + uint32_t GetMSB() const; /** * Get the number of digits using a specific base - support for @@ -921,7 +921,7 @@ class myZZ : public NTL::ZZ, public lbcrypto::BigIntegerInterface { * @param base is the base with which to determine length in. * @return the length of the representation in a specific base. */ - usint GetLengthForBase(usint base) const { + uint32_t GetLengthForBase(uint32_t base) const { return GetMSB(); } @@ -940,11 +940,11 @@ class myZZ : public NTL::ZZ, public lbcrypto::BigIntegerInterface { * @param base such that log2(base)+1 is the bitwidth of the subfield * @return the unsigned integer value of the subfield */ - usint GetDigitAtIndexForBase(usint index, usint base) const; + uint32_t GetDigitAtIndexForBase(uint32_t index, uint32_t base) const; // variable to store the log(base 2) of the number of bits in the // limb data type. - static const usint m_log2LimbBitLength; + static const uint32_t m_log2LimbBitLength; /** * Gets a subset of bits of a given length with LSB at specified index. @@ -953,7 +953,7 @@ class myZZ : public NTL::ZZ, public lbcrypto::BigIntegerInterface { * @param length of the set of bits to get. LSB=1 * @return resulting unsigned in formed by set of bits. */ - usint GetBitRangeAtIndex(usint index, usint length) const; + uint32_t GetBitRangeAtIndex(uint32_t index, uint32_t length) const; /** * Gets the bit at the specified index. @@ -961,7 +961,7 @@ class myZZ : public NTL::ZZ, public lbcrypto::BigIntegerInterface { * @param index of the bit to get. LSB=1 * @return resulting bit. */ - uschar GetBitAtIndex(usint index) const; + uint8_t GetBitAtIndex(uint32_t index) const; /** * A zero allocator that is called by the Matrix class. It is used to @@ -1081,10 +1081,10 @@ class myZZ : public NTL::ZZ, public lbcrypto::BigIntegerInterface { * @return the ceiling of Number/(bits in the limb data type) */ // todo: rename to MSB2NLimbs() - static usint ceilIntByUInt(const ZZ_limb_t Number); + static uint32_t ceilIntByUInt(const ZZ_limb_t Number); mutable ::cereal::size_type m_MSB; - usint GetMSBLimb_t(ZZ_limb_t x) const; + uint32_t GetMSBLimb_t(ZZ_limb_t x) const; }; // class ends diff --git a/src/core/include/math/hal/integer.h b/src/core/include/math/hal/integer.h index e92ba9623..8483d21c1 100644 --- a/src/core/include/math/hal/integer.h +++ b/src/core/include/math/hal/integer.h @@ -347,14 +347,14 @@ class BigIntegerInterface { * @param shift # of bits. * @return result of the shift operation. */ - T LShift(usshort shift) const; - T& LShiftEq(usshort shift); + T LShift(uint16_t shift) const; + T& LShiftEq(uint16_t shift); /// inline operators for the left shift operations. - friend T operator<<(const T& a, usshort shift) { + friend T operator<<(const T& a, uint16_t shift) { return a.LShift(shift); } - friend T& operator<<=(T& a, usshort shift) { + friend T& operator<<=(T& a, uint16_t shift) { return a.LShiftEq(shift); } @@ -364,14 +364,14 @@ class BigIntegerInterface { * @param shift # of bits. * @return result of the shift operation. */ - T RShift(usshort shift) const; - T& RShiftEq(usshort shift); + T RShift(uint16_t shift) const; + T& RShiftEq(uint16_t shift); /// inline operators for the right shift operations. - friend T operator>>(const T& a, usshort shift) { + friend T operator>>(const T& a, uint16_t shift) { return a.RShift(shift); } - friend T& operator>>=(T& a, usshort shift) { + friend T& operator>>=(T& a, uint16_t shift) { return a.RShiftEq(shift); } @@ -418,7 +418,7 @@ class BigIntegerInterface { * * @return the index of the most significant bit. */ - usint GetMSB() const; + uint32_t GetMSB() const; /** * Get the number of digits using a specific base - support for arbitrary base @@ -427,7 +427,7 @@ class BigIntegerInterface { * @param base is the base with which to determine length in. * @return the length of the representation in a specific base. */ - usint GetLengthForBase(usint base) const; + uint32_t GetLengthForBase(uint32_t base) const; /** * Get the number of digits using a specific base - support for arbitrary base @@ -442,7 +442,7 @@ class BigIntegerInterface { * @param base is the base with which to determine length in. * @return the length of the representation in a specific base. */ - usint GetDigitAtIndexForBase(usint index, usint base) const; + uint32_t GetDigitAtIndexForBase(uint32_t index, uint32_t base) const; // STRINGS diff --git a/src/core/include/math/hal/intnat/mubintvecnat.h b/src/core/include/math/hal/intnat/mubintvecnat.h index 173023302..b7fa84ae8 100644 --- a/src/core/include/math/hal/intnat/mubintvecnat.h +++ b/src/core/include/math/hal/intnat/mubintvecnat.h @@ -149,7 +149,7 @@ class NativeVectorT final : public lbcrypto::BigVectorInterface MAX_MODULUS_SIZE) // OPENFHE_THROW(std::to_string(modulus.GetMSB()) + // " bits larger than max modulus bits " + std::to_string(MAX_MODULUS_SIZE)); } - constexpr NativeVectorT(usint length, const IntegerType& modulus, const IntegerType& val) noexcept + constexpr NativeVectorT(uint32_t length, const IntegerType& modulus, const IntegerType& val) noexcept : m_modulus{modulus}, m_data(length, val.Mod(modulus)) { // TODO: better performance if this check is done at poly level // if (modulus.GetMSB() > MAX_MODULUS_SIZE) @@ -198,7 +198,7 @@ class NativeVectorT final : public lbcrypto::BigVectorInterface rhs) noexcept; + NativeVectorT(uint32_t length, const IntegerType& modulus, std::initializer_list rhs) noexcept; /** * Basic constructor for specifying the length of the vector @@ -207,9 +207,9 @@ class NativeVectorT final : public lbcrypto::BigVectorInterface rhs) noexcept; + NativeVectorT(uint32_t length, const IntegerType& modulus, std::initializer_list rhs) noexcept; /** * Assignment operator to assign value from rhs @@ -630,7 +630,7 @@ class NativeVectorT final : public lbcrypto::BigVectorInterface& ptr_obj) { auto len = ptr_obj.m_data.size(); os << "["; - for (usint i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++) { os << ptr_obj.m_data[i]; os << ((i == (len - 1)) ? "]" : " "); } diff --git a/src/core/include/math/hal/intnat/transformnat.h b/src/core/include/math/hal/intnat/transformnat.h index 4370165d6..43debe900 100644 --- a/src/core/include/math/hal/intnat/transformnat.h +++ b/src/core/include/math/hal/intnat/transformnat.h @@ -265,7 +265,7 @@ class ChineseRemainderTransformFTTNat final : public lbcrypto::ChineseRemainderT * size as input or a throw of error occurs. * @see NumberTheoreticTransform::ForwardTransformToBitReverseInPlace() */ - void ForwardTransformToBitReverse(const VecType& element, const IntType& rootOfUnity, const usint CycloOrder, + void ForwardTransformToBitReverse(const VecType& element, const IntType& rootOfUnity, const uint32_t CycloOrder, VecType* result); /** @@ -281,7 +281,7 @@ class ChineseRemainderTransformFTTNat final : public lbcrypto::ChineseRemainderT * @return none * @see NumberTheoreticTransform::ForwardTransformToBitReverseInPlace() */ - void ForwardTransformToBitReverseInPlace(const IntType& rootOfUnity, const usint CycloOrder, VecType* element); + void ForwardTransformToBitReverseInPlace(const IntType& rootOfUnity, const uint32_t CycloOrder, VecType* element); /** * Copies \p element into \p result and calls NumberTheoreticTransform::InverseTransformFromBitReverseInPlace() @@ -300,7 +300,7 @@ class ChineseRemainderTransformFTTNat final : public lbcrypto::ChineseRemainderT * @return none * @see NumberTheoreticTransform::InverseTransformFromBitReverseInPlace() */ - void InverseTransformFromBitReverse(const VecType& element, const IntType& rootOfUnity, const usint CycloOrder, + void InverseTransformFromBitReverse(const VecType& element, const IntType& rootOfUnity, const uint32_t CycloOrder, VecType* result); /** @@ -316,7 +316,7 @@ class ChineseRemainderTransformFTTNat final : public lbcrypto::ChineseRemainderT * @return none * @see NumberTheoreticTransform::InverseTransformFromBitReverseInPlace() */ - void InverseTransformFromBitReverseInPlace(const IntType& rootOfUnity, const usint CycloOrder, VecType* element); + void InverseTransformFromBitReverseInPlace(const IntType& rootOfUnity, const uint32_t CycloOrder, VecType* element); /** * Precomputation of root of unity tables for transforms in the ring @@ -328,7 +328,7 @@ class ChineseRemainderTransformFTTNat final : public lbcrypto::ChineseRemainderT * @param CycloOrder is a power-of-two, equal to 2n. * @param modulus is q, the prime modulus */ - void PreCompute(const IntType& rootOfUnity, const usint CycloOrder, const IntType& modulus); + void PreCompute(const IntType& rootOfUnity, const uint32_t CycloOrder, const IntType& modulus); /** * Precomputation of root of unity tables for transforms in the ring @@ -340,7 +340,7 @@ class ChineseRemainderTransformFTTNat final : public lbcrypto::ChineseRemainderT * @param CycloOrder is a power-of-two, equal to 2n. * @param &moduliChain is the vector of prime moduli qi such that 2n|qi-1 */ - void PreCompute(std::vector& rootOfUnity, const usint CycloOrder, std::vector& moduliChain); + void PreCompute(std::vector& rootOfUnity, const uint32_t CycloOrder, std::vector& moduliChain); /** * Reset cached values for the root of unity tables to empty. @@ -391,8 +391,8 @@ class BluesteinFFTNat { * @param cycloOrder is the cyclotomic order. * @return is the output result of the transform. */ - VecType ForwardTransform(const VecType& element, const IntType& root, const usint cycloOrder); - VecType ForwardTransform(const VecType& element, const IntType& root, const usint cycloOrder, + VecType ForwardTransform(const VecType& element, const IntType& root, const uint32_t cycloOrder); + VecType ForwardTransform(const VecType& element, const IntType& root, const uint32_t cycloOrder, const ModulusRoot& nttModulusRoot); /** @@ -402,7 +402,7 @@ class BluesteinFFTNat { * @return output vector padded with (finalSize - initial size)additional * zeros. */ - VecType PadZeros(const VecType& a, const usint finalSize); + VecType PadZeros(const VecType& a, const uint32_t finalSize); /** * @@ -411,9 +411,9 @@ class BluesteinFFTNat { * @param hi is higher coefficient index. * @return output vector s.t output vector = a[lo]...a[hi]. */ - VecType Resize(const VecType& a, usint lo, usint hi); + VecType Resize(const VecType& a, uint32_t lo, uint32_t hi); - // void PreComputeNTTModulus(usint cycloOrder, const std::vector + // void PreComputeNTTModulus(uint32_t cycloOrder, const std::vector // &modulii); /** @@ -422,7 +422,7 @@ class BluesteinFFTNat { * @param cycloOrder is the cyclotomic order of the polynomial. * @param modulus is the modulus of the polynomial. */ - void PreComputeDefaultNTTModulusRoot(usint cycloOrder, const IntType& modulus); + void PreComputeDefaultNTTModulusRoot(uint32_t cycloOrder, const IntType& modulus); /** * @brief Precomputes the root of unity table needed for NTT operation in @@ -430,7 +430,7 @@ class BluesteinFFTNat { * @param cycloOrder is the cyclotomic order of the polynomial ring. * @param modulus is the modulus of the polynomial. */ - void PreComputeRootTableForNTT(usint cycloOrder, const ModulusRoot& nttModulusRoot); + void PreComputeRootTableForNTT(uint32_t cycloOrder, const ModulusRoot& nttModulusRoot); /** * @brief precomputes the powers of root used in forward Bluestein transform. @@ -438,7 +438,7 @@ class BluesteinFFTNat { * @param modulus is the modulus of the polynomial ring. * @param root is the root of unity s.t. root^2m = 1. */ - void PreComputePowers(usint cycloOrder, const ModulusRoot& modulusRoot); + void PreComputePowers(uint32_t cycloOrder, const ModulusRoot& modulusRoot); /** * @brief precomputes the NTT transform of the power of root of unity used in @@ -449,7 +449,7 @@ class BluesteinFFTNat { * @param bigMod is the modulus required for the NTT transform. * @param bigRoot is the root of unity required for the NTT transform. */ - void PreComputeRBTable(usint cycloOrder, const ModulusRootPair& modulusRootPair); + void PreComputeRBTable(uint32_t cycloOrder, const ModulusRootPair& modulusRootPair); /** * Reset cached values for the transform to empty. @@ -501,7 +501,7 @@ class ChineseRemainderTransformArbNat final : public lbcrypto::ChineseRemainderT * @return is the output result of the transform. */ VecType ForwardTransform(const VecType& element, const IntType& root, const IntType& bigMod, const IntType& bigRoot, - const usint cycloOrder); + const uint32_t cycloOrder); /** * Inverse transform. @@ -515,7 +515,7 @@ class ChineseRemainderTransformArbNat final : public lbcrypto::ChineseRemainderT * @return is the output result of the transform. */ VecType InverseTransform(const VecType& element, const IntType& root, const IntType& bigMod, const IntType& bigRoot, - const usint cycloOrder); + const uint32_t cycloOrder); /** * Reset cached values for the transform to empty. @@ -528,7 +528,7 @@ class ChineseRemainderTransformArbNat final : public lbcrypto::ChineseRemainderT * @param cycloOrder is the cyclotomic order of the polynomial ring. * @param modulus is the modulus of the polynomial ring. */ - void PreCompute(const usint cyclotoOrder, const IntType& modulus); + void PreCompute(const uint32_t cyclotoOrder, const IntType& modulus); /** * @brief Sets the precomputed root of unity and modulus needed for NTT @@ -540,7 +540,7 @@ class ChineseRemainderTransformArbNat final : public lbcrypto::ChineseRemainderT * @param nttRoot is the root of unity needed for the NTT operation in forward * Bluestein transform. */ - void SetPreComputedNTTModulus(usint cyclotoOrder, const IntType& modulus, const IntType& nttMod, + void SetPreComputedNTTModulus(uint32_t cyclotoOrder, const IntType& modulus, const IntType& nttMod, const IntType& nttRoot); /** @@ -554,7 +554,7 @@ class ChineseRemainderTransformArbNat final : public lbcrypto::ChineseRemainderT * @param nttRoot is the root of unity needed for the NTT operation in forward * Bluestein transform. */ - void SetPreComputedNTTDivisionModulus(usint cyclotoOrder, const IntType& modulus, const IntType& nttMod, + void SetPreComputedNTTDivisionModulus(uint32_t cyclotoOrder, const IntType& modulus, const IntType& nttMod, const IntType& nttRoot); /** @@ -564,7 +564,7 @@ class ChineseRemainderTransformArbNat final : public lbcrypto::ChineseRemainderT * @param modulus is the modulus of the polynomial ring. * @return inverse polynomial. */ - VecType InversePolyMod(const VecType& cycloPoly, const IntType& modulus, usint power); + VecType InversePolyMod(const VecType& cycloPoly, const IntType& modulus, uint32_t power); private: /** @@ -574,7 +574,7 @@ class ChineseRemainderTransformArbNat final : public lbcrypto::ChineseRemainderT * @param forward is a flag for forward/inverse transform padding. * @return is result vector with &element values with padded zeros to it */ - VecType Pad(const VecType& element, const usint cycloOrder, bool forward); + VecType Pad(const VecType& element, const uint32_t cycloOrder, bool forward); /** * @brief Dropping elements from a vector @@ -587,7 +587,7 @@ class ChineseRemainderTransformArbNat final : public lbcrypto::ChineseRemainderT * tables if needed. The tables are used in the inverse dropping computations * @return is result vector with &element values with dropped elements from it */ - VecType Drop(const VecType& element, const usint cycloOrder, bool forward, const IntType& bigMod, + VecType Drop(const VecType& element, const uint32_t cycloOrder, bool forward, const IntType& bigMod, const IntType& bigRoot); // map to store the cyclotomic polynomial with polynomial ring's modulus as @@ -616,7 +616,7 @@ class ChineseRemainderTransformArbNat final : public lbcrypto::ChineseRemainderT static std::map m_DivisionNTTRootOfUnity; // dimension of the NTT transform in NTT based polynomial division. - static std::map m_nttDivisionDim; + static std::map m_nttDivisionDim; }; } // namespace intnat diff --git a/src/core/include/math/hal/intnat/ubintnat.h b/src/core/include/math/hal/intnat/ubintnat.h index 04adbb94b..2454b5ac1 100644 --- a/src/core/include/math/hal/intnat/ubintnat.h +++ b/src/core/include/math/hal/intnat/ubintnat.h @@ -79,7 +79,7 @@ template class NativeVectorT; // constexpr double LOG2_10 = 3.32192809; //!< @brief A pre-computed constant of Log base 2 of 10. -// constexpr usint BARRETT_LEVELS = 8; //!< @brief The number of levels (precomputed +// constexpr uint32_t BARRETT_LEVELS = 8; //!< @brief The number of levels (precomputed //!< values) used in the Barrett reductions. /** @@ -131,8 +131,8 @@ class NativeIntegerT final : public lbcrypto::BigIntegerInterface::max()}; // variable to store the bit width of the integral data type. - // static constexpr usint m_uintBitLength{sizeof(NativeInt) * 8}; - static constexpr usint m_uintBitLength{std::numeric_limits::digits}; + // static constexpr uint32_t m_uintBitLength{sizeof(NativeInt) * 8}; + static constexpr uint32_t m_uintBitLength{std::numeric_limits::digits}; friend class NativeVectorT>; @@ -495,7 +495,7 @@ class NativeIntegerT final : public lbcrypto::BigIntegerInterface 0; p >>= 1, x *= x) r *= (p & 0x1) ? x : 1; @@ -508,7 +508,7 @@ class NativeIntegerT final : public lbcrypto::BigIntegerInterface 0; p >>= 1, x *= x) @@ -1594,7 +1594,7 @@ class NativeIntegerT final : public lbcrypto::BigIntegerInterface> shift}; } @@ -1624,7 +1624,7 @@ class NativeIntegerT final : public lbcrypto::BigIntegerInterface> shift; } @@ -1642,7 +1642,7 @@ class NativeIntegerT final : public lbcrypto::BigIntegerInterface || std::is_same_v || std::is_same_v, @@ -1685,7 +1685,7 @@ class NativeIntegerT final : public lbcrypto::BigIntegerInterface((m_value >> (index - 1)) & 0x1); + return static_cast((m_value >> (index - 1)) & 0x1); } /** @@ -1860,7 +1860,7 @@ class NativeIntegerT final : public lbcrypto::BigIntegerInterface& rootOfUnity, const usint CycloOrder, + virtual void PreCompute(std::vector& rootOfUnity, const uint32_t CycloOrder, std::vector& moduliChain) = 0; /** @@ -189,7 +189,7 @@ class ChineseRemainderTransformArbInterface { * @return is the output result of the transform. */ virtual VecType ForwardTransform(const VecType& element, const IntType& root, const IntType& bigMod, - const IntType& bigRoot, const usint cycloOrder) = 0; + const IntType& bigRoot, const uint32_t cycloOrder) = 0; /** * Inverse transform. @@ -203,7 +203,7 @@ class ChineseRemainderTransformArbInterface { * @return is the output result of the transform. */ virtual VecType InverseTransform(const VecType& element, const IntType& root, const IntType& bigMod, - const IntType& bigRoot, const usint cycloOrder) = 0; + const IntType& bigRoot, const uint32_t cycloOrder) = 0; /** * Reset cached values for the transform to empty. @@ -216,7 +216,7 @@ class ChineseRemainderTransformArbInterface { * @param cycloOrder is the cyclotomic order of the polynomial ring. * @param modulus is the modulus of the polynomial ring. */ - virtual void PreCompute(const usint cyclotoOrder, const IntType& modulus) = 0; + virtual void PreCompute(const uint32_t cyclotoOrder, const IntType& modulus) = 0; /** * @brief Sets the precomputed root of unity and modulus needed for NTT @@ -228,7 +228,7 @@ class ChineseRemainderTransformArbInterface { * @param nttRoot is the root of unity needed for the NTT operation in forward * Bluestein transform. */ - virtual void SetPreComputedNTTModulus(usint cyclotoOrder, const IntType& modulus, const IntType& nttMod, + virtual void SetPreComputedNTTModulus(uint32_t cyclotoOrder, const IntType& modulus, const IntType& nttMod, const IntType& nttRoot) = 0; /** @@ -242,7 +242,7 @@ class ChineseRemainderTransformArbInterface { * @param nttRoot is the root of unity needed for the NTT operation in forward * Bluestein transform. */ - virtual void SetPreComputedNTTDivisionModulus(usint cyclotoOrder, const IntType& modulus, const IntType& nttMod, + virtual void SetPreComputedNTTDivisionModulus(uint32_t cyclotoOrder, const IntType& modulus, const IntType& nttMod, const IntType& nttRoot) = 0; /** @@ -252,7 +252,7 @@ class ChineseRemainderTransformArbInterface { * @param modulus is the modulus of the polynomial ring. * @return inverse polynomial. */ - virtual VecType InversePolyMod(const VecType& cycloPoly, const IntType& modulus, usint power) = 0; + virtual VecType InversePolyMod(const VecType& cycloPoly, const IntType& modulus, uint32_t power) = 0; private: /** @@ -262,7 +262,7 @@ class ChineseRemainderTransformArbInterface { * @param forward is a flag for forward/inverse transform padding. * @return is result vector with &element values with padded zeros to it */ - virtual VecType Pad(const VecType& element, const usint cycloOrder, bool forward) = 0; + virtual VecType Pad(const VecType& element, const uint32_t cycloOrder, bool forward) = 0; /** * @brief Dropping elements from a vector @@ -275,7 +275,7 @@ class ChineseRemainderTransformArbInterface { * tables if needed. The tables are used in the inverse dropping computations * @return is result vector with &element values with dropped elements from it */ - virtual VecType Drop(const VecType& element, const usint cycloOrder, bool forward, const IntType& bigMod, + virtual VecType Drop(const VecType& element, const uint32_t cycloOrder, bool forward, const IntType& bigMod, const IntType& bigRoot) = 0; }; } // namespace lbcrypto diff --git a/src/core/include/math/hal/vector.h b/src/core/include/math/hal/vector.h index 2d816184b..f841a36af 100644 --- a/src/core/include/math/hal/vector.h +++ b/src/core/include/math/hal/vector.h @@ -108,7 +108,7 @@ class BigVectorInterface { if ((a.GetLength() != b.GetLength()) || (a.GetModulus() != b.GetModulus())) { return false; } - for (usint i = 0; i < a.GetLength(); ++i) { + for (uint32_t i = 0; i < a.GetLength(); ++i) { if (a[i] != b[i]) { return false; } @@ -223,7 +223,7 @@ class BigVectorInterface { * @param &b is the scalar to add. * @return is the result of the modulus addition operation. */ - T ModAddAtIndex(usint i, const I& b) const; + T ModAddAtIndex(uint32_t i, const I& b) const; /** * Scalar modulus addition at a particular index. In-place variant. @@ -232,7 +232,7 @@ class BigVectorInterface { * @param &b is the scalar to add. * @return is the result of the modulus addition operation. */ - T& ModAddAtIndexEq(usint i, const I& b); + T& ModAddAtIndexEq(uint32_t i, const I& b); /** * Vector component wise modulus addition. @@ -470,7 +470,7 @@ class BigVectorInterface { * @return is the digit at a specific index for all entries for a given number * base */ - T GetDigitAtIndexForBase(usint index, usint base) const; + T GetDigitAtIndexForBase(uint32_t index, uint32_t base) const; protected: ~BigVectorInterface() = default; diff --git a/src/core/include/math/matrix.h b/src/core/include/math/matrix.h index a8dab4488..da621cc5f 100644 --- a/src/core/include/math/matrix.h +++ b/src/core/include/math/matrix.h @@ -620,7 +620,7 @@ class Matrix : public Serializable { inline Matrix ExtractRows(size_t row_start, size_t row_end) const { Matrix result(this->allocZero, row_end - row_start + 1, this->cols); - for (usint row = row_start; row < row_end + 1; row++) { + for (uint32_t row = row_start; row < row_end + 1; row++) { int i = 0; for (auto elem = this->GetData()[row].begin(); elem != this->GetData()[row].end(); ++elem) { diff --git a/src/core/include/math/nbtheory-impl.h b/src/core/include/math/nbtheory-impl.h index 7865ffc9b..ec3e57d97 100644 --- a/src/core/include/math/nbtheory-impl.h +++ b/src/core/include/math/nbtheory-impl.h @@ -88,10 +88,10 @@ static IntType RNG(const IntType& modulus) { false if p is likely prime */ template -static bool WitnessFunction(const IntType& a, const IntType& d, usint s, const IntType& p) { +static bool WitnessFunction(const IntType& a, const IntType& d, uint32_t s, const IntType& p) { IntType mod = a.ModExp(d, p); bool prevMod = false; - for (usint i = 0; i < s; ++i) { + for (uint32_t i = 0; i < s; ++i) { prevMod = (mod != IntType(1) && mod != p - IntType(1)); mod.ModMulFastEq(mod, p); if (mod == IntType(1) && prevMod) @@ -110,7 +110,7 @@ static IntType FindGenerator(const IntType& q) { IntType qm2(q - IntType(2)); std::set primeFactors; PrimeFactorize(qm1, primeFactors); - usint cnt; + uint32_t cnt; IntType gen; do { cnt = 0; @@ -134,7 +134,7 @@ IntType FindGeneratorCyclic(const IntType& q) { IntType phi_q_m1(GetTotient(q.ConvertToInt())); std::set primeFactors; PrimeFactorize(phi_q, primeFactors); - usint cnt; + uint32_t cnt; IntType gen; do { cnt = 0; @@ -163,7 +163,7 @@ bool IsGenerator(const IntType& g, const IntType& q) { IntType qm1(GetTotient(q.ConvertToInt())); std::set primeFactors; PrimeFactorize(qm1, primeFactors); - usint cnt = 0; + uint32_t cnt = 0; for (auto it = primeFactors.begin(); it != primeFactors.end(); ++it, ++cnt) { if (g.ModExp(qm1 / (*it), q) == IntType(1)) break; @@ -180,7 +180,7 @@ bool IsGenerator(const IntType& g, const IntType& q) { output: root of unity (in format of BigInteger) */ template -IntType RootOfUnity(usint m, const IntType& modulo) { +IntType RootOfUnity(uint32_t m, const IntType& modulo) { IntType M(m); if ((modulo - IntType(1)).Mod(M) != IntType(0)) { std::string errMsg = @@ -231,7 +231,7 @@ IntType RootOfUnity(usint m, const IntType& modulo) { } template -std::vector RootsOfUnity(usint m, const std::vector& moduli) { +std::vector RootsOfUnity(uint32_t m, const std::vector& moduli) { std::vector rootsOfUnity(moduli.size()); for (size_t i = 0; i < moduli.size(); ++i) rootsOfUnity[i] = RootOfUnity(m, moduli[i]); @@ -258,7 +258,7 @@ IntType GreatestCommonDivisor(const IntType& a, const IntType& b) { false if p is not prime */ template -bool MillerRabinPrimalityTest(const IntType& p, const usint niter) { +bool MillerRabinPrimalityTest(const IntType& p, const uint32_t niter) { static const IntType ZERO(0); static const IntType TWO(2); static const IntType THREE(3); @@ -270,13 +270,13 @@ bool MillerRabinPrimalityTest(const IntType& p, const usint niter) { return false; IntType d(p - IntType(1)); - usint s(0); + uint32_t s(0); while (d.Mod(TWO) == ZERO) { // d.DividedByEq(TWO); d.RShiftEq(1); ++s; } - for (usint i = 0; i < niter; ++i) { + for (uint32_t i = 0; i < niter; ++i) { if (WitnessFunction(RNG(p - THREE).ModAdd(TWO, p), d, s, p)) return false; } @@ -394,7 +394,7 @@ IntType PreviousPrime(const IntType& q, uint64_t m) { template IntType NextPowerOfTwo(IntType n) { - usint result = std::ceil(std::log2(n)); + uint32_t result = std::ceil(std::log2(n)); return result; } @@ -414,15 +414,15 @@ std::vector GetTotientList(const IntType& n) { template IntVector PolyMod(const IntVector& dividend, const IntVector& divisor, const typename IntVector::Integer& modulus) { auto mu(modulus.ComputeMu()); - usint divisorLength(divisor.GetLength()); - usint dividendLength(dividend.GetLength()); - usint runs(dividendLength - divisorLength + 1); + uint32_t divisorLength(divisor.GetLength()); + uint32_t dividendLength(dividend.GetLength()); + uint32_t runs(dividendLength - divisorLength + 1); IntVector runningDividend(dividend); - for (usint i = 0; i < runs; ++i) { + for (uint32_t i = 0; i < runs; ++i) { // get the highest degree coeff auto divConst(runningDividend[dividendLength - 1]); - usint divisorPtr(divisorLength - 1); - for (usint j = 0; j < dividendLength - i - 1; j++) { + uint32_t divisorPtr(divisorLength - 1); + for (uint32_t j = 0; j < dividendLength - i - 1; j++) { auto& rdtmp1 = runningDividend[dividendLength - 1 - j]; rdtmp1 = runningDividend[dividendLength - 2 - j]; if (divisorPtr > j) @@ -431,20 +431,20 @@ IntVector PolyMod(const IntVector& dividend, const IntVector& divisor, const typ } IntVector result(divisorLength - 1, modulus); - for (usint i = 0, j = runs; i < divisorLength - 1; ++i, ++j) + for (uint32_t i = 0, j = runs; i < divisorLength - 1; ++i, ++j) result[i] = runningDividend[j]; return result; } template IntVector PolynomialMultiplication(const IntVector& a, const IntVector& b) { - usint degreeA(a.GetLength()); - usint degreeB(b.GetLength()); - usint degreeResultant(degreeA + degreeB - 1); + uint32_t degreeA(a.GetLength()); + uint32_t degreeB(b.GetLength()); + uint32_t degreeResultant(degreeA + degreeB - 1); const auto& modulus = a.GetModulus(); IntVector result(degreeResultant, modulus); - for (usint i = 0; i < degreeA; i++) { - for (usint j = 0; j < degreeB; j++) { + for (uint32_t i = 0; i < degreeA; i++) { + for (uint32_t j = 0; j < degreeB; j++) { result[i + j].ModAddEq(a[i] * b[j], modulus); } } @@ -452,10 +452,10 @@ IntVector PolynomialMultiplication(const IntVector& a, const IntVector& b) { } template -IntVector GetCyclotomicPolynomial(usint m, const typename IntVector::Integer& modulus) { +IntVector GetCyclotomicPolynomial(uint32_t m, const typename IntVector::Integer& modulus) { auto intCP = GetCyclotomicPolynomialRecursive(m); IntVector result(intCP.size(), modulus); - for (usint i = 0; i < intCP.size(); i++) { + for (uint32_t i = 0; i < intCP.size(); i++) { auto val = intCP[i]; if (val > -1) { result[i] = typename IntVector::Integer(val); @@ -481,16 +481,16 @@ template IntVector SyntheticPolyRemainder(const IntVector& dividend, const IntVector& aList, const typename IntVector::Integer& modulus) { IntVector result(aList.GetLength(), modulus); - for (usint i = 0; i < aList.GetLength(); ++i) + for (uint32_t i = 0; i < aList.GetLength(); ++i) result[i] = SyntheticRemainder(dividend, aList[i], modulus); return result; } template -IntVector PolynomialPower(const IntVector& input, usint power) { - usint finalDegree = (input.GetLength() - 1) * power; +IntVector PolynomialPower(const IntVector& input, uint32_t power) { + uint32_t finalDegree = (input.GetLength() - 1) * power; IntVector finalPoly(finalDegree + 1, input.GetModulus()); - for (usint i = 0; i < input.GetLength(); ++i) + for (uint32_t i = 0; i < input.GetLength(); ++i) finalPoly[i * power] = input[i]; return finalPoly; } @@ -499,7 +499,7 @@ template IntVector SyntheticPolynomialDivision(const IntVector& dividend, const typename IntVector::Integer& a, const typename IntVector::Integer& modulus) { auto mu(modulus.ComputeMu()); - usint n(dividend.GetLength() - 1); + uint32_t n(dividend.GetLength() - 1); IntVector result(n, modulus); result[n - 1] = dividend[n]; auto val(dividend[n]); diff --git a/src/core/include/math/nbtheory.h b/src/core/include/math/nbtheory.h index b5f1748bf..2e87dec3d 100644 --- a/src/core/include/math/nbtheory.h +++ b/src/core/include/math/nbtheory.h @@ -82,7 +82,7 @@ namespace lbcrypto { * @return a root of unity. */ template -IntType RootOfUnity(usint m, const IntType& modulo); +IntType RootOfUnity(uint32_t m, const IntType& modulo); /** * Finds roots of unity for given input. Assumes the the input cyclotomicorder @@ -94,7 +94,7 @@ IntType RootOfUnity(usint m, const IntType& modulo); * @returns a vector of roots of unity corresponding to each modulus. */ template -std::vector RootsOfUnity(usint m, const std::vector& moduli); +std::vector RootsOfUnity(uint32_t m, const std::vector& moduli); /** * Method to reverse bits of num and return an unsigned int, for all bits up to @@ -132,8 +132,8 @@ inline static unsigned char reverse_byte(unsigned char x) { static int shift_trick[] = {0, 7, 6, 5, 4, 3, 2, 1}; /* Function to reverse bits of num */ -inline usint ReverseBits(usint num, usint msb) { - usint msbb = (msb >> 3) + (msb & 0x7 ? 1 : 0); +inline uint32_t ReverseBits(uint32_t num, uint32_t msb) { + uint32_t msbb = (msb >> 3) + (msb & 0x7 ? 1 : 0); switch (msbb) { case 1: return (reverse_byte((num)&0xff) >> shift_trick[msb & 0x7]); @@ -166,7 +166,7 @@ inline usint ReverseBits(usint num, usint msb) { template < typename T, std::enable_if_t || std::is_same_v || std::is_same_v, bool> = true> -inline constexpr usint GetMSB(T x) { +inline constexpr uint32_t GetMSB(T x) { if constexpr (sizeof(T) <= 8) { if (x == 0) return 0; @@ -201,7 +201,7 @@ inline constexpr usint GetMSB(T x) { * * @return the index of the MSB bit location. */ -inline constexpr usint GetMSB64(uint64_t x) { +inline constexpr uint32_t GetMSB64(uint64_t x) { return GetMSB(x); } @@ -249,7 +249,7 @@ IntType GreatestCommonDivisor(const IntType& a, const IntType& b); * non-primality is found. */ template -bool MillerRabinPrimalityTest(const IntType& p, const usint niter = 100); +bool MillerRabinPrimalityTest(const IntType& p, const uint32_t niter = 100); /** * Perform the PollardRho factorization of a IntType. @@ -323,7 +323,7 @@ IntType PreviousPrime(const IntType& q, uint64_t m); * * @return the multiplicative inverse */ -usint ModInverse(usint a, usint b); +uint32_t ModInverse(uint32_t a, uint32_t b); /** * Returns the next power of 2 that is greater than the input number. @@ -386,7 +386,7 @@ IntVector PolynomialMultiplication(const IntVector& a, const IntVector& b); * @return resultant m-th cyclotomic polynomial with coefficients in modulus. */ template -IntVector GetCyclotomicPolynomial(usint m, const typename IntVector::Integer& modulus); +IntVector GetCyclotomicPolynomial(uint32_t m, const typename IntVector::Integer& modulus); /** * Returns the m-th cyclotomic polynomial. @@ -394,7 +394,7 @@ IntVector GetCyclotomicPolynomial(usint m, const typename IntVector::Integer& mo * @param &m the input cyclotomic order. * @return resultant m-th cyclotomic polynomial. */ -std::vector GetCyclotomicPolynomialRecursive(usint m); +std::vector GetCyclotomicPolynomialRecursive(uint32_t m); /** * Returns the remainder after polynomial division of dividend with divisor = @@ -428,7 +428,7 @@ IntVector SyntheticPolyRemainder(const IntVector& dividend, const IntVector& aLi * @return exponentiated polynomial. */ template -IntVector PolynomialPower(const IntVector& input, usint power); +IntVector PolynomialPower(const IntVector& input, uint32_t power); /** * Returns the quotient after polynomial division of dividend with divisor = diff --git a/src/core/include/utils/blockAllocator/xvector.h b/src/core/include/utils/blockAllocator/xvector.h index e41e2ac43..3be84b043 100644 --- a/src/core/include/utils/blockAllocator/xvector.h +++ b/src/core/include/utils/blockAllocator/xvector.h @@ -44,8 +44,8 @@ template > class xvector : public std::vector<_Ty, _Ax> { public: constexpr xvector() noexcept : std::vector<_Ty, _Ax>() {} - explicit constexpr xvector(usint length) noexcept : std::vector<_Ty, _Ax>(length) {} - constexpr xvector(usint length, const _Ty& val) noexcept : std::vector<_Ty, _Ax>(length, val) {} + explicit constexpr xvector(uint32_t length) noexcept : std::vector<_Ty, _Ax>(length) {} + constexpr xvector(uint32_t length, const _Ty& val) noexcept : std::vector<_Ty, _Ax>(length, val) {} }; #endif diff --git a/src/core/include/utils/inttypes.h b/src/core/include/utils/inttypes.h index ca390d00f..40af966fc 100644 --- a/src/core/include/utils/inttypes.h +++ b/src/core/include/utils/inttypes.h @@ -41,21 +41,6 @@ #include #include -/** - * @brief Type used for representing unsigned 8-bit integers. - */ -typedef uint8_t uschar; - -/** - * @brief Type used for representing unsigned 16-bit short integers. - */ -typedef uint16_t usshort; - -/** - * @brief Type used for representing unsigned 32-bit integers. - */ -typedef uint32_t usint; - typedef uint64_t PlaintextModulus; /** diff --git a/src/core/lib/lattice/stdlatticeparms.cpp b/src/core/lib/lattice/stdlatticeparms.cpp index 948b5ff21..b20a3400a 100644 --- a/src/core/lib/lattice/stdlatticeparms.cpp +++ b/src/core/lib/lattice/stdlatticeparms.cpp @@ -113,8 +113,8 @@ std::ostream& operator<<(std::ostream& s, SecurityLevel sl) { return s; } -std::map StdLatticeParm::byRing[3][6]; -std::map StdLatticeParm::byLogQ[3][6]; +std::map StdLatticeParm::byRing[3][6]; +std::map StdLatticeParm::byLogQ[3][6]; bool StdLatticeParm::initialized = false; diff --git a/src/core/lib/math/dftransform.cpp b/src/core/lib/math/dftransform.cpp index 5e6081919..42243a910 100644 --- a/src/core/lib/math/dftransform.cpp +++ b/src/core/lib/math/dftransform.cpp @@ -94,13 +94,13 @@ void DiscreteFourierTransform::PreComputeTable(uint32_t s) { } std::vector> DiscreteFourierTransform::FFTForwardTransform(std::vector>& A) { - usint m = A.size(); + uint32_t m = A.size(); std::vector> B(A); - usint l = std::floor(std::log2(m)); + uint32_t l = std::floor(std::log2(m)); - // static usint maxMCached(262144); - static usint LOGM_MAX(18); // maximum supported is 2^18 = 262144 - static std::vector cachedM(LOGM_MAX + 1, 0); + // static uint32_t maxMCached(262144); + static uint32_t LOGM_MAX(18); // maximum supported is 2^18 = 262144 + static std::vector cachedM(LOGM_MAX + 1, 0); static std::vector> cosTable(LOGM_MAX + 1); static std::vector> sinTable(LOGM_MAX + 1); @@ -119,7 +119,7 @@ std::vector> DiscreteFourierTransform::FFTForwardTransform( sinTable[l].resize(m / 2); cosTable[l].resize(m / 2); - for (usint i = 0; i < m / 2; i++) { + for (uint32_t i = 0; i < m / 2; i++) { cosTable[l][i] = cos(2 * M_PI * i / m); sinTable[l][i] = sin(2 * M_PI * i / m); } @@ -127,8 +127,8 @@ std::vector> DiscreteFourierTransform::FFTForwardTransform( } // Bit-reversed addressing permutation - for (usint i = 0; i < m; i++) { - usint j = ReverseBits(i, 32) >> (32 - l); + for (uint32_t i = 0; i < m; i++) { + uint32_t j = ReverseBits(i, 32) >> (32 - l); if (j > i) { double temp = B[i].real(); B[i].real(B[j].real()); @@ -140,11 +140,11 @@ std::vector> DiscreteFourierTransform::FFTForwardTransform( } // Cooley-Tukey decimation-in-time radix-2 FFT - for (usint size = 2; size <= m; size *= 2) { - usint halfsize = size / 2; - usint tablestep = m / size; - for (usint i = 0; i < m; i += size) { - for (usint j = i, k = 0; j < i + halfsize; j++, k += tablestep) { + for (uint32_t size = 2; size <= m; size *= 2) { + uint32_t halfsize = size / 2; + uint32_t tablestep = m / size; + for (uint32_t i = 0; i < m; i += size) { + for (uint32_t j = i, k = 0; j < i + halfsize; j++, k += tablestep) { double tpre = B[j + halfsize].real() * cosTable[l][k] + B[j + halfsize].imag() * sinTable[l][k]; double tpim = -B[j + halfsize].real() * sinTable[l][k] + B[j + halfsize].imag() * cosTable[l][k]; B[j + halfsize].real(B[j].real() - tpre); diff --git a/src/core/lib/math/discretegaussiangeneratorgeneric.cpp b/src/core/lib/math/discretegaussiangeneratorgeneric.cpp index 1c806a6f5..b618c312d 100644 --- a/src/core/lib/math/discretegaussiangeneratorgeneric.cpp +++ b/src/core/lib/math/discretegaussiangeneratorgeneric.cpp @@ -236,7 +236,7 @@ void BaseSampler::Initialize(double mean) { } // take cumulative summation - for (usint i = 1; i < m_vals.size(); i++) { + for (uint32_t i = 1; i < m_vals.size(); i++) { m_vals[i] += m_vals[i - 1]; } } @@ -260,7 +260,7 @@ int64_t BaseSampler::GenerateIntegerPeikert() const { return ans - fin + b_mean; } -usint BaseSampler::FindInVector(const std::vector& S, double search) const { +uint32_t BaseSampler::FindInVector(const std::vector& S, double search) const { // STL binary search implementation auto lower = std::lower_bound(S.begin(), S.end(), search); if (lower != S.end()) diff --git a/src/core/lib/math/hal/bigintdyn/be4-math-impl.cpp b/src/core/lib/math/hal/bigintdyn/be4-math-impl.cpp index cc08e718e..9d229eaaf 100644 --- a/src/core/lib/math/hal/bigintdyn/be4-math-impl.cpp +++ b/src/core/lib/math/hal/bigintdyn/be4-math-impl.cpp @@ -51,10 +51,10 @@ template class BinaryUniformGeneratorImpl; template class TernaryUniformGeneratorImpl; template class DiscreteUniformGeneratorImpl; -template M4Integer RootOfUnity(usint m, const M4Integer& modulo); -template std::vector RootsOfUnity(usint m, const std::vector& moduli); +template M4Integer RootOfUnity(uint32_t m, const M4Integer& modulo); +template std::vector RootsOfUnity(uint32_t m, const std::vector& moduli); template M4Integer GreatestCommonDivisor(const M4Integer& a, const M4Integer& b); -template bool MillerRabinPrimalityTest(const M4Integer& p, const usint niter); +template bool MillerRabinPrimalityTest(const M4Integer& p, const uint32_t niter); template const M4Integer PollardRhoFactorization(const M4Integer& n); template void PrimeFactorize(M4Integer n, std::set& primeFactors); template M4Integer FirstPrime(uint32_t nBits, uint64_t m); @@ -64,10 +64,10 @@ template M4Integer PreviousPrime(const M4Integer& q, uint64_t m); template std::vector GetTotientList(const M4Integer& n); template M4Vector PolyMod(const M4Vector& dividend, const M4Vector& divisor, const M4Integer& modulus); template M4Vector PolynomialMultiplication(const M4Vector& a, const M4Vector& b); -template M4Vector GetCyclotomicPolynomial(usint m, const M4Integer& modulus); +template M4Vector GetCyclotomicPolynomial(uint32_t m, const M4Integer& modulus); template M4Integer SyntheticRemainder(const M4Vector& dividend, const M4Integer& a, const M4Integer& modulus); template M4Vector SyntheticPolyRemainder(const M4Vector& dividend, const M4Vector& aList, const M4Integer& modulus); -template M4Vector PolynomialPower(const M4Vector& input, usint power); +template M4Vector PolynomialPower(const M4Vector& input, uint32_t power); template M4Vector SyntheticPolynomialDivision(const M4Vector& dividend, const M4Integer& a, const M4Integer& modulus); template M4Integer FindGeneratorCyclic(const M4Integer& modulo); template bool IsGenerator(const M4Integer& g, const M4Integer& modulo); diff --git a/src/core/lib/math/hal/bigintdyn/mubintvecdyn.cpp b/src/core/lib/math/hal/bigintdyn/mubintvecdyn.cpp index 7d101ff99..9dc97239a 100644 --- a/src/core/lib/math/hal/bigintdyn/mubintvecdyn.cpp +++ b/src/core/lib/math/hal/bigintdyn/mubintvecdyn.cpp @@ -52,7 +52,7 @@ namespace bigintdyn { template -mubintvec::mubintvec(usint length, const ubint_el_t& modulus, +mubintvec::mubintvec(uint32_t length, const ubint_el_t& modulus, std::initializer_list rhs) noexcept : m_modulus{modulus}, m_modulus_state{State::INITIALIZED}, m_data(length) { const size_t len = (rhs.size() < m_data.size()) ? rhs.size() : m_data.size(); @@ -61,7 +61,7 @@ mubintvec::mubintvec(usint length, const ubint_el_t& modulus, } template -mubintvec::mubintvec(usint length, const ubint_el_t& modulus, std::initializer_list rhs) noexcept +mubintvec::mubintvec(uint32_t length, const ubint_el_t& modulus, std::initializer_list rhs) noexcept : m_modulus{modulus}, m_modulus_state{State::INITIALIZED}, m_data(length) { const size_t len = (rhs.size() < m_data.size()) ? rhs.size() : m_data.size(); for (size_t i = 0; i < len; ++i) @@ -537,7 +537,7 @@ mubintvec& mubintvec::DivideAndRoundEq(const ubint_el_t& } template -mubintvec mubintvec::GetDigitAtIndexForBase(usint index, usint base) const { +mubintvec mubintvec::GetDigitAtIndexForBase(uint32_t index, uint32_t base) const { auto ans(*this); for (size_t i = 0; i < m_data.size(); ++i) ans[i] = static_cast(ans[i].GetDigitAtIndexForBase(index, base)); diff --git a/src/core/lib/math/hal/bigintdyn/ubintdyn.cpp b/src/core/lib/math/hal/bigintdyn/ubintdyn.cpp index d844616f0..413175a85 100644 --- a/src/core/lib/math/hal/bigintdyn/ubintdyn.cpp +++ b/src/core/lib/math/hal/bigintdyn/ubintdyn.cpp @@ -222,7 +222,7 @@ ubint& ubint::DividedByEq(const ubint& b) { } template -ubint ubint::Exp(usint p) const { +ubint ubint::Exp(uint32_t p) const { if (p == 0) return ubint(1); if (p == 1) @@ -482,8 +482,8 @@ ubint ubint::ModExp(const ubint& b, const ubint& modulus) const } template -ubint ubint::LShift(usshort shift) const { - static constexpr usshort mask{m_limbBitLength - 1}; +ubint ubint::LShift(uint16_t shift) const { + static constexpr uint16_t mask{m_limbBitLength - 1}; if (m_MSB == 0) return ubint(); auto ans(*this); @@ -511,8 +511,8 @@ ubint ubint::LShift(usshort shift) const { } template -ubint& ubint::LShiftEq(usshort shift) { - static constexpr usshort mask{m_limbBitLength - 1}; +ubint& ubint::LShiftEq(uint16_t shift) { + static constexpr uint16_t mask{m_limbBitLength - 1}; if (m_MSB == 0) return *this; m_MSB += shift; @@ -546,8 +546,8 @@ ubint& ubint::LShiftEq(usshort shift) { * Shifting is done by using bit shift operations and carry over propagation. */ template -ubint ubint::RShift(usshort shift) const { - static constexpr usshort mask{m_limbBitLength - 1}; +ubint ubint::RShift(uint16_t shift) const { + static constexpr uint16_t mask{m_limbBitLength - 1}; if (m_MSB <= shift) return ubint(0); ubint ans(*this); @@ -555,7 +555,7 @@ ubint ubint::RShift(usshort shift) const { size_t shiftByLimb{static_cast(shift) >> m_log2LimbBitLength}; shift &= mask; Dlimb_t tmp{ans.m_value[shiftByLimb++] >> shift}; - usint lshift{m_limbBitLength - shift}; + uint32_t lshift{m_limbBitLength - shift}; size_t size{ans.m_value.size() - shiftByLimb}; for (size_t i = 0; i < size; ++i, tmp >>= m_limbBitLength) { tmp |= static_cast(ans.m_value[i + shiftByLimb]) << lshift; @@ -568,8 +568,8 @@ ubint ubint::RShift(usshort shift) const { } template -ubint& ubint::RShiftEq(usshort shift) { - static constexpr usshort mask{m_limbBitLength - 1}; +ubint& ubint::RShiftEq(uint16_t shift) { + static constexpr uint16_t mask{m_limbBitLength - 1}; if (m_MSB <= shift) { m_MSB = 0; m_value.resize(1); @@ -580,7 +580,7 @@ ubint& ubint::RShiftEq(usshort shift) { size_t shiftByLimb{static_cast(shift) >> m_log2LimbBitLength}; shift &= mask; Dlimb_t tmp{m_value[shiftByLimb++] >> shift}; - usint lshift{m_limbBitLength - shift}; + uint32_t lshift{m_limbBitLength - shift}; size_t size{m_value.size() - shiftByLimb}; for (size_t i = 0; i < size; ++i, tmp >>= m_limbBitLength) { tmp |= static_cast(m_value[i + shiftByLimb]) << lshift; @@ -610,12 +610,12 @@ double ubint::ConvertToDouble() const { double ans{-1.0}; try { // ans = std::stod(this->ToString()); - usint ceilInt = MSBToLimbs(m_MSB); + uint32_t ceilInt = MSBToLimbs(m_MSB); double factor = std::pow(2, m_limbBitLength); double power = 1.0; ans = 0.0; - for (usint i = 0; i < ceilInt; ++i, power *= factor) + for (uint32_t i = 0; i < ceilInt; ++i, power *= factor) ans += power * m_value[i]; } catch (const std::exception& e) { @@ -648,18 +648,18 @@ ubint ubint::FromBinaryString(const std::string& vin) { return ubint(); ubint value; value.m_value.clear(); - usint len = v.length(); - usint cntr = MSBToLimbs(len); + uint32_t len = v.length(); + uint32_t cntr = MSBToLimbs(len); std::string val; Dlimb_t partial_value = 0; - for (usint i = 0; i < cntr; i++) { + for (uint32_t i = 0; i < cntr; i++) { if (len > ((i + 1) * m_limbBitLength)) { val = v.substr((len - (i + 1) * m_limbBitLength), m_limbBitLength); } else { val = v.substr(0, len % m_limbBitLength); } - for (usint j = 0; j < val.length(); j++) { + for (uint32_t j = 0; j < val.length(); j++) { partial_value += std::stoi(val.substr(j, 1)); partial_value <<= 1; } @@ -673,11 +673,11 @@ ubint ubint::FromBinaryString(const std::string& vin) { // TODO: * i to << i template -usint ubint::GetDigitAtIndexForBase(usint index, usint base) const { - usint DigitLen = std::ceil(std::log2(base)); - usint digit = 0; - usint newIndex = 1 + (index - 1) * DigitLen; - for (usint i = 1; i < base; i <<= 1) { +uint32_t ubint::GetDigitAtIndexForBase(uint32_t index, uint32_t base) const { + uint32_t DigitLen = std::ceil(std::log2(base)); + uint32_t digit = 0; + uint32_t newIndex = 1 + (index - 1) * DigitLen; + for (uint32_t i = 1; i < base; i <<= 1) { digit += GetBitAtIndex(newIndex++) * i; } return digit; @@ -685,9 +685,9 @@ usint ubint::GetDigitAtIndexForBase(usint index, usint base) const { template const std::string ubint::ToString() const { - std::vector val{0}; + std::vector val{0}; val.reserve(m_MSB >> 1); - for (usint i = m_MSB; i > 0; --i) { + for (uint32_t i = m_MSB; i > 0; --i) { auto ofl = GetBitAtIndex(i); // TODO: needlessly expensive here for (auto& a : val) { a = (a << 1) + ofl; @@ -975,7 +975,7 @@ void ubint::SetValue(const std::string& vin) { m_value.clear(); // m_value.reserve(MSBToLimbs(arrSize << 2)); - usint cnt{0}; + uint32_t cnt{0}; limb_t val{0}; size_t zptr{0}; while (zptr <= arrSize) { @@ -997,13 +997,13 @@ void ubint::SetValue(const std::string& vin) { } template -uschar ubint::GetBitAtIndex(usint index) const { - constexpr usint mask{m_limbBitLength - 1}; +uint8_t ubint::GetBitAtIndex(uint32_t index) const { + constexpr uint32_t mask{m_limbBitLength - 1}; if (index > m_MSB) return 0; size_t idx{MSBToLimbs(index) - 1}; index &= mask; - return static_cast((m_value[idx] >> (index ? index - 1 : mask)) & 0x1); + return static_cast((m_value[idx] >> (index ? index - 1 : mask)) & 0x1); } template class bigintdyn::ubint; diff --git a/src/core/lib/math/hal/bigintfxd/be2-math-impl.cpp b/src/core/lib/math/hal/bigintfxd/be2-math-impl.cpp index 7c92fbcea..69c321064 100644 --- a/src/core/lib/math/hal/bigintfxd/be2-math-impl.cpp +++ b/src/core/lib/math/hal/bigintfxd/be2-math-impl.cpp @@ -51,10 +51,10 @@ template class BinaryUniformGeneratorImpl; template class TernaryUniformGeneratorImpl; template class DiscreteUniformGeneratorImpl; -template M2Integer RootOfUnity(usint m, const M2Integer& modulo); -template std::vector RootsOfUnity(usint m, const std::vector& moduli); +template M2Integer RootOfUnity(uint32_t m, const M2Integer& modulo); +template std::vector RootsOfUnity(uint32_t m, const std::vector& moduli); template M2Integer GreatestCommonDivisor(const M2Integer& a, const M2Integer& b); -template bool MillerRabinPrimalityTest(const M2Integer& p, const usint niter); +template bool MillerRabinPrimalityTest(const M2Integer& p, const uint32_t niter); template const M2Integer PollardRhoFactorization(const M2Integer& n); template void PrimeFactorize(M2Integer n, std::set& primeFactors); template M2Integer FirstPrime(uint32_t nBits, uint64_t m); @@ -64,10 +64,10 @@ template M2Integer PreviousPrime(const M2Integer& q, uint64_t m); template std::vector GetTotientList(const M2Integer& n); template M2Vector PolyMod(const M2Vector& dividend, const M2Vector& divisor, const M2Integer& modulus); template M2Vector PolynomialMultiplication(const M2Vector& a, const M2Vector& b); -template M2Vector GetCyclotomicPolynomial(usint m, const M2Integer& modulus); +template M2Vector GetCyclotomicPolynomial(uint32_t m, const M2Integer& modulus); template M2Integer SyntheticRemainder(const M2Vector& dividend, const M2Integer& a, const M2Integer& modulus); template M2Vector SyntheticPolyRemainder(const M2Vector& dividend, const M2Vector& aList, const M2Integer& modulus); -template M2Vector PolynomialPower(const M2Vector& input, usint power); +template M2Vector PolynomialPower(const M2Vector& input, uint32_t power); template M2Vector SyntheticPolynomialDivision(const M2Vector& dividend, const M2Integer& a, const M2Integer& modulus); template M2Integer FindGeneratorCyclic(const M2Integer& modulo); template bool IsGenerator(const M2Integer& g, const M2Integer& modulo); diff --git a/src/core/lib/math/hal/bigintfxd/mubintvecfxd.cpp b/src/core/lib/math/hal/bigintfxd/mubintvecfxd.cpp index 2bdebd775..965662fdb 100644 --- a/src/core/lib/math/hal/bigintfxd/mubintvecfxd.cpp +++ b/src/core/lib/math/hal/bigintfxd/mubintvecfxd.cpp @@ -52,7 +52,7 @@ BigVectorFixedT::BigVectorFixedT() { } template -BigVectorFixedT::BigVectorFixedT(usint length, const IntegerType& modulus) { +BigVectorFixedT::BigVectorFixedT(uint32_t length, const IntegerType& modulus) { this->m_length = length; this->m_modulus = modulus; this->m_data = new IntegerType[m_length](); @@ -63,7 +63,7 @@ BigVectorFixedT::BigVectorFixedT(const BigVectorFixedT& bigVector) m_length = bigVector.m_length; m_modulus = bigVector.m_modulus; m_data = new IntegerType[m_length]; - for (usint i = 0; i < m_length; i++) { + for (uint32_t i = 0; i < m_length; i++) { m_data[i] = bigVector.m_data[i]; } } @@ -81,13 +81,13 @@ BigVectorFixedT::BigVectorFixedT(BigVectorFixedT&& bigVector) { } template -BigVectorFixedT::BigVectorFixedT(usint length, const IntegerType& modulus, +BigVectorFixedT::BigVectorFixedT(uint32_t length, const IntegerType& modulus, std::initializer_list rhs) { this->m_length = length; this->m_modulus = modulus; this->m_data = new IntegerType[m_length](); - usint len = rhs.size(); - for (usint i = 0; i < m_length; i++) { // this loops over each entry + uint32_t len = rhs.size(); + for (uint32_t i = 0; i < m_length; i++) { // this loops over each entry if (i < len) { m_data[i] = IntegerType(*(rhs.begin() + i)) % m_modulus; } @@ -98,13 +98,13 @@ BigVectorFixedT::BigVectorFixedT(usint length, const IntegerType& m } template -BigVectorFixedT::BigVectorFixedT(usint length, const IntegerType& modulus, +BigVectorFixedT::BigVectorFixedT(uint32_t length, const IntegerType& modulus, std::initializer_list rhs) { this->m_length = length; this->m_modulus = modulus; this->m_data = new IntegerType[m_length](); - usint len = rhs.size(); - for (usint i = 0; i < m_length; i++) { // this loops over each entry + uint32_t len = rhs.size(); + for (uint32_t i = 0; i < m_length; i++) { // this loops over each entry if (i < len) { m_data[i] = IntegerType(*(rhs.begin() + i)) % m_modulus; } @@ -204,7 +204,7 @@ void BigVectorFixedT::SwitchModulus(const IntegerType& newModulus) IntegerType n; IntegerType oldModulusByTwo(oldModulus >> 1); IntegerType diff((oldModulus > newModulus) ? (oldModulus - newModulus) : (newModulus - oldModulus)); - for (usint i = 0; i < this->m_length; i++) { + for (uint32_t i = 0; i < this->m_length; i++) { n = this->at(i); if (oldModulus < newModulus) { if (n > oldModulusByTwo) { @@ -249,7 +249,7 @@ BigVectorFixedT& BigVectorFixedT::ModEq(const IntegerT } else { IntegerType halfQ(this->GetModulus() >> 1); - for (usint i = 0; i < this->GetLength(); i++) { + for (uint32_t i = 0; i < this->GetLength(); i++) { if (this->m_data[i] > halfQ) { this->m_data[i].ModSubEq(this->GetModulus(), modulus); } @@ -271,21 +271,21 @@ BigVectorFixedT BigVectorFixedT::ModAdd(const IntegerT template BigVectorFixedT& BigVectorFixedT::ModAddEq(const IntegerType& b) { IntegerType bb = b.Mod(this->m_modulus); - for (usint i = 0; i < this->m_length; i++) { + for (uint32_t i = 0; i < this->m_length; i++) { this->m_data[i].ModAddFastEq(bb, this->m_modulus); } return *this; } template -BigVectorFixedT BigVectorFixedT::ModAddAtIndex(usint i, const IntegerType& b) const { +BigVectorFixedT BigVectorFixedT::ModAddAtIndex(uint32_t i, const IntegerType& b) const { BigVectorFixedT ans(*this); ans.ModAddAtIndexEq(i, b); return ans; } template -BigVectorFixedT& BigVectorFixedT::ModAddAtIndexEq(usint i, const IntegerType& b) { +BigVectorFixedT& BigVectorFixedT::ModAddAtIndexEq(uint32_t i, const IntegerType& b) { if (i > this->GetLength() - 1) { OPENFHE_THROW("mubintvecfxd::ModAddAtIndex. Index is out of range. i = " + std::to_string(i)); } @@ -305,7 +305,7 @@ BigVectorFixedT& BigVectorFixedT::ModAddEq(const BigVe if ((this->m_length != b.m_length) || this->m_modulus != b.m_modulus) { OPENFHE_THROW("ModAddEq called on BigVectorFixedT's with different parameters."); } - for (usint i = 0; i < this->m_length; i++) { + for (uint32_t i = 0; i < this->m_length; i++) { this->m_data[i].ModAddFastEq(b.m_data[i], this->m_modulus); } return *this; @@ -313,7 +313,7 @@ BigVectorFixedT& BigVectorFixedT::ModAddEq(const BigVe template BigVectorFixedT& BigVectorFixedT::ModAddNoCheckEq(const BigVectorFixedT& b) { - for (usint i = 0; i < m_length; ++i) + for (uint32_t i = 0; i < m_length; ++i) m_data[i].ModAddFastEq(b.m_data[i], m_modulus); return *this; } @@ -328,7 +328,7 @@ BigVectorFixedT BigVectorFixedT::ModSub(const IntegerT template BigVectorFixedT& BigVectorFixedT::ModSubEq(const IntegerType& b) { IntegerType bb = b.Mod(this->m_modulus); - for (usint i = 0; i < this->m_length; i++) { + for (uint32_t i = 0; i < this->m_length; i++) { this->m_data[i].ModSubFastEq(bb, this->m_modulus); } return *this; @@ -346,7 +346,7 @@ BigVectorFixedT& BigVectorFixedT::ModSubEq(const BigVe if ((this->m_length != b.m_length) || this->m_modulus != b.m_modulus) { OPENFHE_THROW("ModSubEq called on BigVectorFixedT's with different parameters."); } - for (usint i = 0; i < this->m_length; i++) { + for (uint32_t i = 0; i < this->m_length; i++) { this->m_data[i].ModSubFastEq(b.m_data[i], this->m_modulus); } return *this; @@ -386,7 +386,7 @@ template BigVectorFixedT& BigVectorFixedT::ModMulEq(const IntegerType& b) { IntegerType bb = b.Mod(this->m_modulus); IntegerType mu = this->m_modulus.ComputeMu(); // Precompute the Barrett mu parameter - for (usint i = 0; i < this->m_length; i++) { + for (uint32_t i = 0; i < this->m_length; i++) { this->m_data[i].ModMulEq(bb, this->m_modulus, mu); } return *this; @@ -429,7 +429,7 @@ BigVectorFixedT& BigVectorFixedT::ModMulEq(const BigVe } IntegerType mu = this->m_modulus.ComputeMu(); // Precompute the Barrett mu parameter - for (usint i = 0; i < this->m_length; i++) { + for (uint32_t i = 0; i < this->m_length; i++) { this->m_data[i].ModMulEq(b.m_data[i], this->m_modulus, mu); } return *this; @@ -438,7 +438,7 @@ BigVectorFixedT& BigVectorFixedT::ModMulEq(const BigVe template BigVectorFixedT& BigVectorFixedT::ModMulNoCheckEq(const BigVectorFixedT& b) { auto mu{m_modulus.ComputeMu()}; - for (usint i = 0; i < m_length; ++i) + for (uint32_t i = 0; i < m_length; ++i) m_data[i].ModMulEq(b[i], m_modulus, mu); return *this; } @@ -452,7 +452,7 @@ BigVectorFixedT BigVectorFixedT::ModExp(const IntegerT template BigVectorFixedT& BigVectorFixedT::ModExpEq(const IntegerType& b) { - for (usint i = 0; i < this->m_length; i++) { + for (uint32_t i = 0; i < this->m_length; i++) { this->m_data[i].ModExpEq(b, this->m_modulus); } return *this; @@ -467,7 +467,7 @@ BigVectorFixedT BigVectorFixedT::ModInverse() const { template BigVectorFixedT& BigVectorFixedT::ModInverseEq() { - for (usint i = 0; i < this->m_length; i++) { + for (uint32_t i = 0; i < this->m_length; i++) { this->m_data[i].ModInverseEq(this->m_modulus); } return *this; @@ -483,7 +483,7 @@ BigVectorFixedT BigVectorFixedT::ModByTwo() const { template BigVectorFixedT& BigVectorFixedT::ModByTwoEq() { IntegerType halfQ(this->GetModulus() >> 1); - for (usint i = 0; i < this->GetLength(); i++) { + for (uint32_t i = 0; i < this->GetLength(); i++) { if (this->m_data[i] > halfQ) { if (this->m_data[i].Mod(2) == 1) { this->m_data[i] = IntegerType(0); @@ -516,7 +516,7 @@ BigVectorFixedT& BigVectorFixedT::MultWithOutModEq(con if ((this->m_length != b.m_length) || this->m_modulus != b.m_modulus) { OPENFHE_THROW("MultWithOutMod called on BigVectorFixedT's with different parameters."); } - for (usint i = 0; i < this->m_length; i++) { + for (uint32_t i = 0; i < this->m_length; i++) { this->m_data[i].MulEq(b.m_data[i]); } return *this; @@ -535,7 +535,7 @@ BigVectorFixedT& BigVectorFixedT::MultiplyAndRoundEq(c const IntegerType& q) { IntegerType halfQ(this->m_modulus >> 1); IntegerType temp; - for (usint i = 0; i < this->m_length; i++) { + for (uint32_t i = 0; i < this->m_length; i++) { if (this->m_data[i] > halfQ) { temp = this->m_modulus - this->m_data[i]; this->m_data[i] = this->m_modulus - temp.MultiplyAndRound(p, q); @@ -559,7 +559,7 @@ template BigVectorFixedT& BigVectorFixedT::DivideAndRoundEq(const IntegerType& q) { IntegerType halfQ(this->m_modulus >> 1); IntegerType temp; - for (usint i = 0; i < this->m_length; i++) { + for (uint32_t i = 0; i < this->m_length; i++) { if (this->m_data[i] > halfQ) { temp = this->m_modulus - this->m_data[i]; this->m_data[i] = this->m_modulus - temp.DivideAndRound(q); @@ -574,9 +574,9 @@ BigVectorFixedT& BigVectorFixedT::DivideAndRoundEq(con // OTHER OPERATIONS template -BigVectorFixedT BigVectorFixedT::GetDigitAtIndexForBase(usint index, usint base) const { +BigVectorFixedT BigVectorFixedT::GetDigitAtIndexForBase(uint32_t index, uint32_t base) const { BigVectorFixedT ans(*this); - for (usint i = 0; i < this->m_length; i++) { + for (uint32_t i = 0; i < this->m_length; i++) { ans.m_data[i] = IntegerType(ans.m_data[i].GetDigitAtIndexForBase(index, base)); } return ans; diff --git a/src/core/lib/math/hal/bigintfxd/ubintfxd.cpp b/src/core/lib/math/hal/bigintfxd/ubintfxd.cpp index efd4f4e7b..1dc66d57f 100644 --- a/src/core/lib/math/hal/bigintfxd/ubintfxd.cpp +++ b/src/core/lib/math/hal/bigintfxd/ubintfxd.cpp @@ -47,37 +47,37 @@ namespace bigintfxd { // constant static member variable initialization of m_uintBitLength which is // equal to number of bits in the unit data type permitted values: 8,16,32 -template -const uschar BigIntegerFixedT::m_uintBitLength = UIntBitWidth::value; +template +const uint8_t BigIntegerFixedT::m_uintBitLength = UIntBitWidth::value; -template -const usint BigIntegerFixedT::m_numDigitInPrintval = BITLENGTH / bigintfxd::LOG2_10; +template +const uint32_t BigIntegerFixedT::m_numDigitInPrintval = BITLENGTH / bigintfxd::LOG2_10; // constant static member variable initialization of m_logUintBitLength which is // equal to log of number of bits in the unit data type permitted values: 3,4,5 -template -const uschar BigIntegerFixedT::m_logUintBitLength = LogDtype::value; +template +const uint8_t BigIntegerFixedT::m_logUintBitLength = LogDtype::value; // constant static member variable initialization of m_nSize which is size of // the array of unit data type -template -const usint BigIntegerFixedT::m_nSize = +template +const uint32_t BigIntegerFixedT::m_nSize = BITLENGTH % m_uintBitLength == 0 ? BITLENGTH / m_uintBitLength : BITLENGTH / m_uintBitLength + 1; // constant static member variable initialization of m_uintMax which is maximum // value of unit data type -template +template const uint_type BigIntegerFixedT::m_uintMax = std::numeric_limits::max(); // CONSTRUCTORS -template +template BigIntegerFixedT::BigIntegerFixedT() { memset(this->m_value, 0, sizeof(this->m_value)); this->m_MSB = 0; // MSB set to zero since value set to 0 } -template +template BigIntegerFixedT::BigIntegerFixedT(const BigIntegerFixedT& val) { m_MSB = val.m_MSB; for (size_t i = 0; i < m_nSize; ++i) { // copy array values @@ -85,7 +85,7 @@ BigIntegerFixedT::BigIntegerFixedT(const BigIntegerFixedT& } } -template +template BigIntegerFixedT::BigIntegerFixedT(BigIntegerFixedT&& val) { m_MSB = std::move(val.m_MSB); for (size_t i = 0; i < m_nSize; ++i) { @@ -93,14 +93,14 @@ BigIntegerFixedT::BigIntegerFixedT(BigIntegerFixedT&& val) } } -template +template BigIntegerFixedT::BigIntegerFixedT(const std::string& strval) { AssignVal(strval); // setting the array values from the string } -template +template BigIntegerFixedT::BigIntegerFixedT(uint64_t val) { - usint msb = lbcrypto::GetMSB64(val); + uint32_t msb = lbcrypto::GetMSB64(val); this->m_MSB = msb; uint_type ceilInt = ceilIntByUInt(msb); @@ -116,7 +116,7 @@ BigIntegerFixedT::BigIntegerFixedT(uint64_t val) { } #if defined(HAVE_INT128) -template +template BigIntegerFixedT::BigIntegerFixedT(U128BITS val) { m_MSB = lbcrypto::GetMSB(val); @@ -133,14 +133,14 @@ BigIntegerFixedT::BigIntegerFixedT(U128BITS val) { #endif /* -template +template BigIntegerFixedT::BigIntegerFixedT(const NativeInteger &val) : BigIntegerFixedT(val.ConvertToInt()) {} */ // ASSIGNMENT OPERATORS -template +template BigIntegerFixedT& BigIntegerFixedT::operator=(const BigIntegerFixedT& val) { if (this != &val) { this->m_MSB = val.m_MSB; @@ -151,7 +151,7 @@ BigIntegerFixedT& BigIntegerFixedT:: return *this; } -template +template BigIntegerFixedT& BigIntegerFixedT::operator=(BigIntegerFixedT&& val) { if (this != &val) { this->m_MSB = std::move(val.m_MSB); @@ -164,18 +164,18 @@ BigIntegerFixedT& BigIntegerFixedT:: // ACCESSORS -template +template void BigIntegerFixedT::SetValue(const std::string& str) { AssignVal(str); } -template +template void BigIntegerFixedT::SetValue(const BigIntegerFixedT& a) { *this = a; } -template -void BigIntegerFixedT::SetIntAtIndex(usint idx, uint_type value) { +template +void BigIntegerFixedT::SetIntAtIndex(uint32_t idx, uint_type value) { if (idx >= m_nSize) { OPENFHE_THROW("Index invalid"); } @@ -188,7 +188,7 @@ void BigIntegerFixedT::SetIntAtIndex(usint idx, uint_type * Algorithm used is usual school book sum and carry-over, expect for that * radix is 2^m_bitLength. */ -template +template BigIntegerFixedT BigIntegerFixedT::Add(const BigIntegerFixedT& b) const { // two operands A and B for addition, A is the greater one, B is the smaller // one @@ -220,9 +220,9 @@ BigIntegerFixedT BigIntegerFixedT::A // crashes in this function (perhaps it was never exercised) a safer // alternative would be something like what follows (the loops i fixed above // could use the same structure; note all variables become unsigned and all - // loop indices start from zero): for (usint j = 0; j < m_nSize - CeilIntB + // loop indices start from zero): for (uint32_t j = 0; j < m_nSize - CeilIntB // /*&& j < m_nSize*/; ++j) { - // usint i = m_nSize - 1 -j ; + // uint32_t i = m_nSize - 1 -j ; // ... // } for (i = m_nSize - 1; i >= m_nSize - ceilIntB; i--) { @@ -258,7 +258,7 @@ BigIntegerFixedT BigIntegerFixedT::A return result; } -template +template BigIntegerFixedT& BigIntegerFixedT::AddEq(const BigIntegerFixedT& b) { // check for trivial conditions if (b.m_MSB == 0) { @@ -321,7 +321,7 @@ BigIntegerFixedT& BigIntegerFixedT:: * Algorithm used is usual school book borrow and subtract, except for that * radix is 2^m_bitLength. */ -template +template BigIntegerFixedT BigIntegerFixedT::Sub(const BigIntegerFixedT& b) const { // return 0 if b is higher than *this as there is no support for negative // number @@ -375,7 +375,7 @@ BigIntegerFixedT BigIntegerFixedT::S return result; } -template +template BigIntegerFixedT& BigIntegerFixedT::SubEq(const BigIntegerFixedT& b) { // return 0 if b is higher than *this as there is no support for negative // number @@ -429,7 +429,7 @@ BigIntegerFixedT& BigIntegerFixedT:: * Algorithm used is usual school book shift and add after multiplication, * except for that radix is 2^m_bitLength. */ -template +template BigIntegerFixedT BigIntegerFixedT::Mul(const BigIntegerFixedT& b) const { // check for trivial conditions if (b.m_MSB == 0 || this->m_MSB == 0) { @@ -459,7 +459,7 @@ BigIntegerFixedT BigIntegerFixedT::M } // TODO reconsider operation -template +template BigIntegerFixedT& BigIntegerFixedT::MulEq(const BigIntegerFixedT& b) { return *this = this->Mul(b); } @@ -469,7 +469,7 @@ BigIntegerFixedT& BigIntegerFixedT:: * 2^m_bitLength. Optimization done: Uses bit shift operation for logarithmic * convergence. */ -template +template BigIntegerFixedT BigIntegerFixedT::DividedBy( const BigIntegerFixedT& b) const { // check for trivial conditions @@ -495,7 +495,7 @@ BigIntegerFixedT BigIntegerFixedT::D BigIntegerFixedT estimateFinder; // Initialize the running dividend - for (usint i = 0; i < ncharInDivisor; i++) { + for (uint32_t i = 0; i < ncharInDivisor; i++) { running_dividend.m_value[m_nSize - ncharInDivisor + i] = normalised_dividend.m_value[m_nSize - ncharInNormalised_dividend + i]; } @@ -505,9 +505,9 @@ BigIntegerFixedT BigIntegerFixedT::D uint_type estimate = 0; uint_type maskBit = 0; uint_type shifts = 0; - usint ansCtr = m_nSize - ncharInNormalised_dividend + ncharInDivisor - 1; + uint32_t ansCtr = m_nSize - ncharInNormalised_dividend + ncharInDivisor - 1; // Long Division Computation to determine quotient - for (usint i = ncharInNormalised_dividend - ncharInDivisor;;) { + for (uint32_t i = ncharInNormalised_dividend - ncharInDivisor;;) { runningRemainder = running_dividend.Mod(b); // Get the remainder from the Modulus operation expectedProd = running_dividend - runningRemainder; // Compute the expected product from the // running dividend and remainder @@ -573,14 +573,14 @@ BigIntegerFixedT BigIntegerFixedT::D } // TODO reconsider operation -template +template BigIntegerFixedT& BigIntegerFixedT::DividedByEq(const BigIntegerFixedT& b) { return *this = this->DividedBy(b); } // Recursive Exponentiation function -template -BigIntegerFixedT BigIntegerFixedT::Exp(usint p) const { +template +BigIntegerFixedT BigIntegerFixedT::Exp(uint32_t p) const { if (p == 0) { return 1; } @@ -597,8 +597,8 @@ BigIntegerFixedT BigIntegerFixedT::E } } -template -BigIntegerFixedT& BigIntegerFixedT::ExpEq(usint p) { +template +BigIntegerFixedT& BigIntegerFixedT::ExpEq(uint32_t p) { if (p == 0) { return *this = 1; } @@ -616,7 +616,7 @@ BigIntegerFixedT& BigIntegerFixedT:: } } -template +template BigIntegerFixedT BigIntegerFixedT::MultiplyAndRound( const BigIntegerFixedT& p, const BigIntegerFixedT& q) const { BigIntegerFixedT ans(*this); @@ -625,7 +625,7 @@ BigIntegerFixedT BigIntegerFixedT::M return ans; } -template +template BigIntegerFixedT& BigIntegerFixedT::MultiplyAndRoundEq( const BigIntegerFixedT& p, const BigIntegerFixedT& q) { this->MulEq(p); @@ -633,7 +633,7 @@ BigIntegerFixedT& BigIntegerFixedT:: return *this; } -template +template BigIntegerFixedT BigIntegerFixedT::DivideAndRound( const BigIntegerFixedT& q) const { // check for garbage initialization and 0 condition @@ -660,7 +660,7 @@ BigIntegerFixedT BigIntegerFixedT::D BigIntegerFixedT estimateFinder; // Initialize the running dividend - for (usint i = 0; i < ncharInDivisor; i++) { + for (uint32_t i = 0; i < ncharInDivisor; i++) { running_dividend.m_value[m_nSize - ncharInDivisor + i] = normalised_dividend.m_value[m_nSize - ncharInNormalised_dividend + i]; } @@ -670,9 +670,9 @@ BigIntegerFixedT BigIntegerFixedT::D uint_type estimate = 0; uint_type maskBit = 0; uint_type shifts = 0; - usint ansCtr = m_nSize - ncharInNormalised_dividend + ncharInDivisor - 1; + uint32_t ansCtr = m_nSize - ncharInNormalised_dividend + ncharInDivisor - 1; // Long Division Computation to determine quotient - for (usint i = ncharInNormalised_dividend - ncharInDivisor;;) { + for (uint32_t i = ncharInNormalised_dividend - ncharInDivisor;;) { runningRemainder = running_dividend.Mod(q); // Get the remainder from the Modulus operation expectedProd = running_dividend - runningRemainder; // Compute the expected product from the // running dividend and remainder @@ -743,7 +743,7 @@ BigIntegerFixedT BigIntegerFixedT::D } // TODO reconsider the method -template +template BigIntegerFixedT& BigIntegerFixedT::DivideAndRoundEq( const BigIntegerFixedT& q) { return *this = this->DivideAndRound(q); @@ -754,7 +754,7 @@ BigIntegerFixedT& BigIntegerFixedT:: // Algorithm used: Repeated subtraction by a multiple of modulus, which will be // referred to as "Classical Modulo Reduction Algorithm" Complexity: // O(log(*this)-log(modulus)) -template +template BigIntegerFixedT BigIntegerFixedT::Mod( const BigIntegerFixedT& modulus) const { // return the same value if value is less than modulus @@ -805,7 +805,7 @@ BigIntegerFixedT BigIntegerFixedT::M return result; } -template +template BigIntegerFixedT& BigIntegerFixedT::ModEq(const BigIntegerFixedT& modulus) { // return the same value if value is less than modulus if (*this < modulus) { @@ -854,7 +854,7 @@ BigIntegerFixedT& BigIntegerFixedT:: return *this; } -template +template BigIntegerFixedT BigIntegerFixedT::ComputeMu() const { BigIntegerFixedT temp(1); temp <<= (2 * this->GetMSB() + 3); @@ -879,7 +879,7 @@ BigIntegerFixedT BigIntegerFixedT::C dividend assuming that none of the dividends will be larger than 2^(2*n + 3). The value of \mu is computed by BigVector::ModMult. */ -template +template BigIntegerFixedT BigIntegerFixedT::Mod(const BigIntegerFixedT& modulus, const BigIntegerFixedT& mu) const { if (*this < modulus) { @@ -904,7 +904,7 @@ BigIntegerFixedT BigIntegerFixedT::M return z; } -template +template BigIntegerFixedT& BigIntegerFixedT::ModEq(const BigIntegerFixedT& modulus, const BigIntegerFixedT& mu) { if (*this < modulus) { @@ -928,7 +928,7 @@ BigIntegerFixedT& BigIntegerFixedT:: return *this; } -template +template BigIntegerFixedT BigIntegerFixedT::ModAdd( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus) const { BigIntegerFixedT a(*this); @@ -944,7 +944,7 @@ BigIntegerFixedT BigIntegerFixedT::M return a; } -template +template BigIntegerFixedT& BigIntegerFixedT::ModAddEq( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus) { BigIntegerFixedT bb(b); @@ -959,7 +959,7 @@ BigIntegerFixedT& BigIntegerFixedT:: return *this; } -template +template BigIntegerFixedT BigIntegerFixedT::ModAddFast( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus) const { BigIntegerFixedT a(*this); @@ -968,7 +968,7 @@ BigIntegerFixedT BigIntegerFixedT::M return a; } -template +template BigIntegerFixedT& BigIntegerFixedT::ModAddFastEq( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus) { this->AddEq(b); @@ -976,7 +976,7 @@ BigIntegerFixedT& BigIntegerFixedT:: return *this; } -template +template BigIntegerFixedT BigIntegerFixedT::ModAdd( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus, const BigIntegerFixedT& mu) const { BigIntegerFixedT a(*this); @@ -985,7 +985,7 @@ BigIntegerFixedT BigIntegerFixedT::M return a; } -template +template BigIntegerFixedT& BigIntegerFixedT::ModAddEq( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus, const BigIntegerFixedT& mu) { this->AddEq(b); @@ -993,7 +993,7 @@ BigIntegerFixedT& BigIntegerFixedT:: return *this; } -template +template BigIntegerFixedT BigIntegerFixedT::ModSub( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus) const { BigIntegerFixedT a(*this); @@ -1015,7 +1015,7 @@ BigIntegerFixedT BigIntegerFixedT::M return a; } -template +template BigIntegerFixedT& BigIntegerFixedT::ModSubEq( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus) { BigIntegerFixedT b_op(b); @@ -1036,7 +1036,7 @@ BigIntegerFixedT& BigIntegerFixedT:: return *this; } -template +template BigIntegerFixedT BigIntegerFixedT::ModSubFast( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus) const { BigIntegerFixedT a(*this); @@ -1051,7 +1051,7 @@ BigIntegerFixedT BigIntegerFixedT::M return a; } -template +template BigIntegerFixedT& BigIntegerFixedT::ModSubFastEq( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus) { if (*this >= b) { @@ -1065,7 +1065,7 @@ BigIntegerFixedT& BigIntegerFixedT:: return *this; } -template +template BigIntegerFixedT BigIntegerFixedT::ModSub( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus, const BigIntegerFixedT& mu) const { BigIntegerFixedT a(*this); @@ -1089,7 +1089,7 @@ BigIntegerFixedT BigIntegerFixedT::M return a; } -template +template BigIntegerFixedT& BigIntegerFixedT::ModSubEq( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus, const BigIntegerFixedT& mu) { BigIntegerFixedT b_op(b); @@ -1112,7 +1112,7 @@ BigIntegerFixedT& BigIntegerFixedT:: return *this; } -template +template BigIntegerFixedT BigIntegerFixedT::ModMul( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus) const { BigIntegerFixedT a(*this); @@ -1127,7 +1127,7 @@ BigIntegerFixedT BigIntegerFixedT::M return a.ModEq(modulus); } -template +template BigIntegerFixedT& BigIntegerFixedT::ModMulEq( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus) { BigIntegerFixedT bb(b); @@ -1142,7 +1142,7 @@ BigIntegerFixedT& BigIntegerFixedT:: return *this; } -template +template BigIntegerFixedT BigIntegerFixedT::ModMul( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus, const BigIntegerFixedT& mu) const { BigIntegerFixedT a(*this); @@ -1158,7 +1158,7 @@ BigIntegerFixedT BigIntegerFixedT::M return a; } -template +template BigIntegerFixedT& BigIntegerFixedT::ModMulEq( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus, const BigIntegerFixedT& mu) { BigIntegerFixedT bb(b); @@ -1173,7 +1173,7 @@ BigIntegerFixedT& BigIntegerFixedT:: return *this; } -template +template BigIntegerFixedT BigIntegerFixedT::ModMulFast( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus) const { BigIntegerFixedT a(*this); @@ -1182,7 +1182,7 @@ BigIntegerFixedT BigIntegerFixedT::M return a; } -template +template BigIntegerFixedT& BigIntegerFixedT::ModMulFastEq( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus) { this->MulEq(b); @@ -1215,7 +1215,7 @@ BigIntegerFixedT& BigIntegerFixedT:: this case is listed in Algorithm 6 of the source. This algorithm would most like give the biggest improvement but it sets constraints on moduli. */ -template +template BigIntegerFixedT BigIntegerFixedT::ModMulFast( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus, const BigIntegerFixedT& mu) const { BigIntegerFixedT a(*this); @@ -1224,7 +1224,7 @@ BigIntegerFixedT BigIntegerFixedT::M return a; } -template +template BigIntegerFixedT& BigIntegerFixedT::ModMulFastEq( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus, const BigIntegerFixedT& mu) { this->MulEq(b); @@ -1234,7 +1234,7 @@ BigIntegerFixedT& BigIntegerFixedT:: // Modular Multiplication using Square and Multiply Algorithm // reference:http://guan.cse.nsysu.edu.tw/note/expn.pdf -template +template BigIntegerFixedT BigIntegerFixedT::ModExp( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus) const { BigIntegerFixedT mid = this->Mod(modulus); // mid is intermidiate value that calculates mid^2%q @@ -1267,14 +1267,14 @@ BigIntegerFixedT BigIntegerFixedT::M } // TODO method should be reconsidered -template +template BigIntegerFixedT& BigIntegerFixedT::ModExpEq( const BigIntegerFixedT& b, const BigIntegerFixedT& modulus) { return *this = this->ModExp(b, modulus); } // Extended Euclid algorithm used to find the multiplicative inverse -template +template BigIntegerFixedT BigIntegerFixedT::ModInverse( const BigIntegerFixedT& modulus) const { BigIntegerFixedT second; @@ -1327,7 +1327,7 @@ BigIntegerFixedT BigIntegerFixedT::M } // Extended Euclid algorithm used to find the multiplicative inverse -template +template BigIntegerFixedT& BigIntegerFixedT::ModInverseEq( const BigIntegerFixedT& modulus) { *this = ModInverse(modulus); @@ -1341,8 +1341,8 @@ BigIntegerFixedT& BigIntegerFixedT:: *2. Shifts between 1 to bit length of uint data type. * Shifting is done by using bit shift operations and carry over propagation. */ -template -BigIntegerFixedT BigIntegerFixedT::LShift(usshort shift) const { +template +BigIntegerFixedT BigIntegerFixedT::LShift(uint16_t shift) const { if (this->m_MSB == 0) { return 0; } @@ -1351,8 +1351,8 @@ BigIntegerFixedT BigIntegerFixedT::L } BigIntegerFixedT ans(*this); - usint shiftByUint = shift >> m_logUintBitLength; - usshort remShift = (shift & (m_uintBitLength - 1)); + uint32_t shiftByUint = shift >> m_logUintBitLength; + uint16_t remShift = (shift & (m_uintBitLength - 1)); if (remShift != 0) { uint_type endVal = m_nSize - ceilIntByUInt(m_MSB); @@ -1372,11 +1372,11 @@ BigIntegerFixedT BigIntegerFixedT::L ans.m_MSB += remShift; } if (shiftByUint != 0) { - usint i = m_nSize - ceilIntByUInt(ans.m_MSB); + uint32_t i = m_nSize - ceilIntByUInt(ans.m_MSB); for (; i < m_nSize; i++) { ans.m_value[i - shiftByUint] = ans.m_value[i]; } - for (usint j = 0; j < shiftByUint; j++) { + for (uint32_t j = 0; j < shiftByUint; j++) { ans.m_value[m_nSize - 1 - j] = 0; } } @@ -1384,15 +1384,15 @@ BigIntegerFixedT BigIntegerFixedT::L return ans; } -template -BigIntegerFixedT& BigIntegerFixedT::LShiftEq(usshort shift) { +template +BigIntegerFixedT& BigIntegerFixedT::LShiftEq(uint16_t shift) { if (this->m_MSB == 0) { return *this; } if (this->m_MSB + shift > BITLENGTH) { OPENFHE_THROW("shift overflow"); } - usint shiftByUint = shift >> m_logUintBitLength; // calculate the no.of + uint32_t shiftByUint = shift >> m_logUintBitLength; // calculate the no.of // shifts uint_type remShift = (shift & (m_uintBitLength - 1)); if (remShift != 0) { @@ -1413,11 +1413,11 @@ BigIntegerFixedT& BigIntegerFixedT:: this->m_MSB += remShift; } if (shiftByUint != 0) { - usint i = m_nSize - ceilIntByUInt(this->m_MSB); + uint32_t i = m_nSize - ceilIntByUInt(this->m_MSB); for (; i < m_nSize; i++) { this->m_value[i - shiftByUint] = this->m_value[i]; } - for (usint ii = 0; ii < shiftByUint; ii++) { + for (uint32_t ii = 0; ii < shiftByUint; ii++) { this->m_value[m_nSize - 1 - ii] = 0; } } @@ -1432,19 +1432,19 @@ BigIntegerFixedT& BigIntegerFixedT:: *2. Shifts between 1 to bit length of uint data type. * Shifting is done by using bit shift operations and carry over propagation. */ -template -BigIntegerFixedT BigIntegerFixedT::RShift(usshort shift) const { +template +BigIntegerFixedT BigIntegerFixedT::RShift(uint16_t shift) const { // trivial cases if (this->m_MSB == 0 || this->m_MSB <= shift) { return BigIntegerFixedT(0); } BigIntegerFixedT ans(*this); - usint shiftByUint = shift >> m_logUintBitLength; // no of array shifts + uint32_t shiftByUint = shift >> m_logUintBitLength; // no of array shifts uint_type remShift = (shift & (m_uintBitLength - 1)); // no of bit shifts if (shiftByUint != 0) { // termination index counter - usint endVal = m_nSize - ceilIntByUInt(ans.m_MSB); - usint j = endVal; + uint32_t endVal = m_nSize - ceilIntByUInt(ans.m_MSB); + uint32_t j = endVal; // array shifting operation for (int i = m_nSize - 1 - shiftByUint; i >= static_cast(endVal); i--) { ans.m_value[i + shiftByUint] = ans.m_value[i]; @@ -1463,7 +1463,7 @@ BigIntegerFixedT BigIntegerFixedT::R uint_type oldVal; uint_type maskVal = ((uint_type)1 << (remShift)) - 1; uint_type compShiftVal = m_uintBitLength - remShift; - usint startVal = m_nSize - ceilIntByUInt(ans.m_MSB); + uint32_t startVal = m_nSize - ceilIntByUInt(ans.m_MSB); // perform shifting by bits by calculating the overflow // oveflow is added after the shifting operation for (; startVal < m_nSize; startVal++) { @@ -1477,8 +1477,8 @@ BigIntegerFixedT BigIntegerFixedT::R return ans; } -template -BigIntegerFixedT& BigIntegerFixedT::RShiftEq(usshort shift) { +template +BigIntegerFixedT& BigIntegerFixedT::RShiftEq(uint16_t shift) { if (this->m_MSB == 0) { return *this; } @@ -1487,7 +1487,7 @@ BigIntegerFixedT& BigIntegerFixedT:: return *this; } int shiftByUint = shift >> m_logUintBitLength; // no of array shifts - uschar remShift = (shift & (m_uintBitLength - 1)); // no of bit shifts + uint8_t remShift = (shift & (m_uintBitLength - 1)); // no of bit shifts // perform shifting in arrays if (shiftByUint != 0) { int endVal = m_nSize - ceilIntByUInt(this->m_MSB); @@ -1508,7 +1508,7 @@ BigIntegerFixedT& BigIntegerFixedT:: uint_type oldVal; uint_type maskVal = ((uint_type)1 << (remShift)) - 1; uint_type compShiftVal = m_uintBitLength - remShift; - usint startVal = m_nSize - ceilIntByUInt(this->m_MSB); + uint32_t startVal = m_nSize - ceilIntByUInt(this->m_MSB); // shift and add the overflow from the previous position for (; startVal < m_nSize; startVal++) { oldVal = this->m_value[startVal]; @@ -1525,7 +1525,7 @@ BigIntegerFixedT& BigIntegerFixedT:: // Compares the current object with the BigIntegerFixedT a. // Uses MSB comparision to output requisite value. -template +template int BigIntegerFixedT::Compare(const BigIntegerFixedT& a) const { if (this->m_MSB < a.m_MSB) { return -1; @@ -1534,8 +1534,8 @@ int BigIntegerFixedT::Compare(const BigIntegerFixedT& a) c return 1; } if (this->m_MSB == a.m_MSB) { - uschar ceilInt = ceilIntByUInt(this->m_MSB); - for (usint i = m_nSize - ceilInt; i < m_nSize; i++) { + uint8_t ceilInt = ceilIntByUInt(this->m_MSB); + for (uint32_t i = m_nSize - ceilInt; i < m_nSize; i++) { auto testChar = int64_t(this->m_value[i]) - int64_t(a.m_value[i]); if (testChar < 0) return -1; @@ -1548,50 +1548,50 @@ int BigIntegerFixedT::Compare(const BigIntegerFixedT& a) c // CONVERTERS -template +template inline double BigIntegerFixedT::ConvertToDouble() const { double result = 0.0; - usint ceilInt = m_nSize - ceilIntByUInt(m_MSB); + uint32_t ceilInt = m_nSize - ceilIntByUInt(m_MSB); double factor = std::pow(2.0, m_uintBitLength); double power = 1.0; // copy the values by shift and add - for (usint i = 0; (m_nSize - i - 1) >= ceilInt; i++) { + for (uint32_t i = 0; (m_nSize - i - 1) >= ceilInt; i++) { result += static_cast(this->m_value[m_nSize - i - 1]) * power; power *= factor; } return result; } -template +template inline long double BigIntegerFixedT::ConvertToLongDouble() const { long double result = 0.0; - usint ceilInt = m_nSize - ceilIntByUInt(m_MSB); + uint32_t ceilInt = m_nSize - ceilIntByUInt(m_MSB); long double factor = std::pow(2.0, m_uintBitLength); long double power = 1.0; // copy the values by shift and add - for (usint i = 0; (m_nSize - i - 1) >= ceilInt; i++) { + for (uint32_t i = 0; (m_nSize - i - 1) >= ceilInt; i++) { result += static_cast(this->m_value[m_nSize - i - 1]) * power; power *= factor; } return result; } -template +template BigIntegerFixedT BigIntegerFixedT::FromBinaryString( const std::string& bitString) { BigIntegerFixedT value; - usint len = bitString.length(); - usint cntr = ceilIntByUInt(len); + uint32_t len = bitString.length(); + uint32_t cntr = ceilIntByUInt(len); std::string val; Duint_type partial_value = 0; - for (usint i = 0; i < cntr; i++) { + for (uint32_t i = 0; i < cntr; i++) { if (len >= ((i + 1) * m_uintBitLength)) { // modified -- the fix by ES val = bitString.substr((len - (i + 1) * m_uintBitLength), m_uintBitLength); } else { val = bitString.substr(0, len % m_uintBitLength); } - for (usint j = 0; j < val.length(); j++) { + for (uint32_t j = 0; j < val.length(); j++) { partial_value += std::stoi(val.substr(j, 1)); partial_value <<= 1; } @@ -1599,7 +1599,7 @@ BigIntegerFixedT BigIntegerFixedT::F value.m_value[m_nSize - 1 - i] = (uint_type)partial_value; partial_value = 0; } - usint i = m_nSize - cntr; + uint32_t i = m_nSize - cntr; while (GetMSBUint_type(value.m_value[i]) == 0 && i < m_nSize - 1) { i++; } @@ -1611,21 +1611,21 @@ BigIntegerFixedT BigIntegerFixedT::F /* This method can be used to convert int to BigIntegerFixedT */ -template -BigIntegerFixedT BigIntegerFixedT::intToBigInteger(usint m) { +template +BigIntegerFixedT BigIntegerFixedT::intToBigInteger(uint32_t m) { return BigIntegerFixedT(m); } // OTHER OPERATIONS -template -usint BigIntegerFixedT::GetMSB() const { +template +uint32_t BigIntegerFixedT::GetMSB() const { return m_MSB; } -template +template bool BigIntegerFixedT::CheckIfPowerOfTwo(const BigIntegerFixedT& m_numToCheck) { - usint m_MSB = m_numToCheck.m_MSB; + uint32_t m_MSB = m_numToCheck.m_MSB; for (int i = m_MSB - 1; i > 0; i--) { if (static_cast(m_numToCheck.GetBitAtIndex(i)) == 1) { return false; @@ -1634,20 +1634,20 @@ bool BigIntegerFixedT::CheckIfPowerOfTwo(const BigIntegerF return true; } -template -usint BigIntegerFixedT::GetDigitAtIndexForBase(usint index, usint base) const { - usint DigitLen = std::ceil(std::log2(base)); - usint digit = 0; - usint newIndex = 1 + (index - 1) * DigitLen; - for (usint i = 1; i < base; i = i * 2) { +template +uint32_t BigIntegerFixedT::GetDigitAtIndexForBase(uint32_t index, uint32_t base) const { + uint32_t DigitLen = std::ceil(std::log2(base)); + uint32_t digit = 0; + uint32_t newIndex = 1 + (index - 1) * DigitLen; + for (uint32_t i = 1; i < base; i = i * 2) { digit += GetBitAtIndex(newIndex) * i; newIndex++; } return digit; } -template -uschar BigIntegerFixedT::GetBitAtIndex(usint index) const { +template +uint8_t BigIntegerFixedT::GetBitAtIndex(uint32_t index) const { if (index <= 0) { return 0; } @@ -1666,19 +1666,19 @@ uschar BigIntegerFixedT::GetBitAtIndex(usint index) const } result = temp & bmask; // finds the bit in bit format result >>= bmask_counter - 1; // shifting operation gives bit either 1 or 0 - return (uschar)result; + return (uint8_t)result; } // STRINGS & STREAMS -template +template const std::string BigIntegerFixedT::ToString() const { std::string bbiString; // this string object will store this BigIntegerFixedT's value - usint counter; + uint32_t counter; // print_VALUE array stores the decimal value in the array // NOLINTNEXTLINE - uschar* print_VALUE = new uschar[m_numDigitInPrintval]; + uint8_t* print_VALUE = new uint8_t[m_numDigitInPrintval]; for (size_t i = 0; i < m_numDigitInPrintval; i++) { // reset to zero *(print_VALUE + i) = 0; } @@ -1707,17 +1707,17 @@ const std::string BigIntegerFixedT::ToString() const { // Initializes the array of uint_array from the string equivalent of BigIntegerFixedT // Algorithm used is repeated division by 2 // Reference:http://pctechtips.org/convert-from-decimal-to-binary-with-recursion-in-java/ -template +template void BigIntegerFixedT::AssignVal(const std::string& v) { int arrSize = v.length(); - uschar* DecValue = new uschar[arrSize]; // memory allocated for decimal array + uint8_t* DecValue = new uint8_t[arrSize]; // memory allocated for decimal array for (int i = 0; i < arrSize; i++) { // store the string to decimal array - DecValue[i] = (uschar)atoi(v.substr(i, 1).c_str()); + DecValue[i] = (uint8_t)atoi(v.substr(i, 1).c_str()); } int zptr = 0; // index of highest non-zero number in decimal number // define bit register array - uschar* bitArr = new uschar[m_uintBitLength](); + uint8_t* bitArr = new uint8_t[m_uintBitLength](); int bitValPtr = m_nSize - 1; // bitValPtr is a pointer to the Value char array, initially pointed to the @@ -1764,10 +1764,10 @@ void BigIntegerFixedT::AssignVal(const std::string& v) { delete[] DecValue; // deallocate memory } -template +template void BigIntegerFixedT::SetMSB() { m_MSB = 0; - for (usint i = 0; i < m_nSize; i++) { // loops to find first nonzero number in char array + for (uint32_t i = 0; i < m_nSize; i++) { // loops to find first nonzero number in char array if ((Duint_type)m_value[i] != 0) { m_MSB = (m_nSize - i - 1) * m_uintBitLength; m_MSB += GetMSBUint_type(m_value[i]); @@ -1777,8 +1777,8 @@ void BigIntegerFixedT::SetMSB() { } // guessIdx is the index of largest uint_type number in array. -template -void BigIntegerFixedT::SetMSB(usint guessIdxChar) { +template +void BigIntegerFixedT::SetMSB(uint32_t guessIdxChar) { m_MSB = (m_nSize - guessIdxChar - 1) * m_uintBitLength; m_MSB += GetMSBUint_type(m_value[guessIdxChar]); } @@ -1792,7 +1792,7 @@ void BigIntegerFixedT::SetMSB(usint guessIdxChar) { // // optimized ceiling function after division by number of bits in the interal // data type. -template +template uint_type BigIntegerFixedT::ceilIntByUInt(const uint_type Number) { // mask to perform bitwise AND // static uint_type mask = m_uintBitLength-1; @@ -1808,17 +1808,17 @@ uint_type BigIntegerFixedT::ceilIntByUInt(const uint_type } } -template -usint BigIntegerFixedT::GetMSBUint_type(uint_type x) { +template +uint32_t BigIntegerFixedT::GetMSBUint_type(uint_type x) { return lbcrypto::GetMSB64(x); } -template -usint BigIntegerFixedT::GetMSBDUint_type(Duint_type x) { +template +uint32_t BigIntegerFixedT::GetMSBDUint_type(Duint_type x) { return lbcrypto::GetMSB64(x); } -template +template BigIntegerFixedT BigIntegerFixedT::MulByUint(const uint_type b) const { BigIntegerFixedT ans; MulByUintToInt(b, &ans); @@ -1829,7 +1829,7 @@ BigIntegerFixedT BigIntegerFixedT::M * Algorithm used is usual school book multiplication. * This function is used in the Multiplication of two BigIntegerFixedT objects */ -template +template void BigIntegerFixedT::MulByUintToInt(const uint_type b, BigIntegerFixedT* ans) const { // check for trivial conditions if (b == 0 || this->m_MSB == 0) { @@ -1838,7 +1838,7 @@ void BigIntegerFixedT::MulByUintToInt(const uint_type b, B } // position in the array to start multiplication - usint endVal = m_nSize - ceilIntByUInt(m_MSB); + uint32_t endVal = m_nSize - ceilIntByUInt(m_MSB); // variable to capture the overflow Duint_type temp = 0; // overflow value @@ -1861,8 +1861,8 @@ void BigIntegerFixedT::MulByUintToInt(const uint_type b, B } // Algoritm used is shift and add -template -uint_type BigIntegerFixedT::UintInBinaryToDecimal(uschar* a) { +template +uint_type BigIntegerFixedT::UintInBinaryToDecimal(uint8_t* a) { uint_type Val = 0; uint_type one = 1; for (int i = m_uintBitLength - 1; i >= 0; i--) { @@ -1873,9 +1873,9 @@ uint_type BigIntegerFixedT::UintInBinaryToDecimal(uschar* return Val; } -template -void BigIntegerFixedT::double_bitVal(uschar* a) { - uschar ofl = 0; +template +void BigIntegerFixedT::double_bitVal(uint8_t* a) { + uint8_t ofl = 0; for (int i = m_numDigitInPrintval - 1; i > -1; i--) { *(a + i) <<= 1; if (*(a + i) > 9) { @@ -1889,9 +1889,9 @@ void BigIntegerFixedT::double_bitVal(uschar* a) { } } -template -void BigIntegerFixedT::add_bitVal(uschar* a, uschar b) { - uschar ofl = 0; +template +void BigIntegerFixedT::add_bitVal(uint8_t* a, uint8_t b) { + uint8_t ofl = 0; *(a + m_numDigitInPrintval - 1) += b; for (int i = m_numDigitInPrintval - 1; i > -1; i--) { *(a + i) += ofl; diff --git a/src/core/lib/math/hal/bigintntl/be6-math-impl.cpp b/src/core/lib/math/hal/bigintntl/be6-math-impl.cpp index 20d286912..d0733e694 100644 --- a/src/core/lib/math/hal/bigintntl/be6-math-impl.cpp +++ b/src/core/lib/math/hal/bigintntl/be6-math-impl.cpp @@ -55,10 +55,10 @@ template class BinaryUniformGeneratorImpl; template class TernaryUniformGeneratorImpl; template class DiscreteUniformGeneratorImpl; -template M6Integer RootOfUnity(usint m, const M6Integer& modulo); -template std::vector RootsOfUnity(usint m, const std::vector& moduli); +template M6Integer RootOfUnity(uint32_t m, const M6Integer& modulo); +template std::vector RootsOfUnity(uint32_t m, const std::vector& moduli); template M6Integer GreatestCommonDivisor(const M6Integer& a, const M6Integer& b); -template bool MillerRabinPrimalityTest(const M6Integer& p, const usint niter); +template bool MillerRabinPrimalityTest(const M6Integer& p, const uint32_t niter); template const M6Integer PollardRhoFactorization(const M6Integer& n); template void PrimeFactorize(M6Integer n, std::set& primeFactors); template M6Integer FirstPrime(uint32_t nBits, uint64_t m); @@ -68,10 +68,10 @@ template M6Integer PreviousPrime(const M6Integer& q, uint64_t m); template std::vector GetTotientList(const M6Integer& n); template M6Vector PolyMod(const M6Vector& dividend, const M6Vector& divisor, const M6Integer& modulus); template M6Vector PolynomialMultiplication(const M6Vector& a, const M6Vector& b); -template M6Vector GetCyclotomicPolynomial(usint m, const M6Integer& modulus); +template M6Vector GetCyclotomicPolynomial(uint32_t m, const M6Integer& modulus); template M6Integer SyntheticRemainder(const M6Vector& dividend, const M6Integer& a, const M6Integer& modulus); template M6Vector SyntheticPolyRemainder(const M6Vector& dividend, const M6Vector& aList, const M6Integer& modulus); -template M6Vector PolynomialPower(const M6Vector& input, usint power); +template M6Vector PolynomialPower(const M6Vector& input, uint32_t power); template M6Vector SyntheticPolynomialDivision(const M6Vector& dividend, const M6Integer& a, const M6Integer& modulus); template M6Integer FindGeneratorCyclic(const M6Integer& modulo); template bool IsGenerator(const M6Integer& g, const M6Integer& modulo); diff --git a/src/core/lib/math/hal/bigintntl/mubintvecntl.cpp b/src/core/lib/math/hal/bigintntl/mubintvecntl.cpp index 4f0789df9..1a46fbed6 100644 --- a/src/core/lib/math/hal/bigintntl/mubintvecntl.cpp +++ b/src/core/lib/math/hal/bigintntl/mubintvecntl.cpp @@ -94,7 +94,7 @@ template myVecP::myVecP(const long n, const myT& q, std::initializer_list rhs) // NOLINT : Vec(INIT_SIZE, n) { // NOLINT this->SetModulus(q); - usint len = rhs.size(); + uint32_t len = rhs.size(); for (size_t i = 0; i < size_t(n); i++) { // this loops over each entry if (i < len) { (*this)[i] = myT(*(rhs.begin() + i)) % m_modulus; @@ -109,7 +109,7 @@ template myVecP::myVecP(const long n, const myT& q, std::initializer_list rhs) // NOLINT : Vec(INIT_SIZE, n) { // NOLINT this->SetModulus(q); - usint len = rhs.size(); + uint32_t len = rhs.size(); for (size_t i = 0; i < size_t(n); i++) { // this loops over each entry if (i < len) { (*this)[i] = myT(*(rhs.begin() + i)) % m_modulus; @@ -156,7 +156,7 @@ myVecP::myVecP(const myVecP& a, const uint64_t q) : Vec(a) { // constructor specifying the myvec as a vector of strings template myVecP::myVecP(std::vector& s) { - usint len = s.size(); + uint32_t len = s.size(); this->resize(len); for (size_t i = 0; i < len; i++) { (*this)[i] = myT(s[i]); @@ -167,7 +167,7 @@ myVecP::myVecP(std::vector& s) { // constructor specifying the myvec as a vector of strings with modulus template myVecP::myVecP(std::vector& s, const myT& q) { - usint len = s.size(); + uint32_t len = s.size(); this->resize(len); this->SetModulus(q); for (size_t i = 0; i < len; i++) { @@ -178,7 +178,7 @@ myVecP::myVecP(std::vector& s, const myT& q) { // constructor specifying the myvec as a vector of strings with modulus template myVecP::myVecP(std::vector& s, const char* sq) { - usint len = s.size(); + uint32_t len = s.size(); this->resize(len); myT zzq(sq); this->SetModulus(zzq); @@ -190,7 +190,7 @@ myVecP::myVecP(std::vector& s, const char* sq) { // constructor specifying the myvec as a vector of strings with modulus template myVecP::myVecP(std::vector& s, const uint64_t q) { - usint len = s.size(); + uint32_t len = s.size(); this->resize(len); myT zzq(q); this->SetModulus(zzq); @@ -651,7 +651,7 @@ myVecP& myVecP::DivideAndRoundEq(const myT& q) { // not sure what this does.. template -myVecP myVecP::GetDigitAtIndexForBase(size_t index, usint base) const { +myVecP myVecP::GetDigitAtIndexForBase(size_t index, uint32_t base) const { myVecP ans(*this); for (size_t i = 0; i < this->GetLength(); i++) { ans[i] = ans[i].GetDigitAtIndexForBase(index, base); diff --git a/src/core/lib/math/hal/bigintntl/ubintntl.cpp b/src/core/lib/math/hal/bigintntl/ubintntl.cpp index d95c7b34a..7ac0b0bc9 100644 --- a/src/core/lib/math/hal/bigintntl/ubintntl.cpp +++ b/src/core/lib/math/hal/bigintntl/ubintntl.cpp @@ -52,7 +52,7 @@ namespace NTL { // constant log2 of limb bitlength -const usint myZZ::m_log2LimbBitLength = Log2::value; +const uint32_t myZZ::m_log2LimbBitLength = Log2::value; // CONSTRUCTORS @@ -200,14 +200,14 @@ myZZ myZZ::FromBinaryString(const std::string& vin) { // value.clear(); //clear out all limbs clear(value); // clear out all limbs - usint len = v.length(); + uint32_t len = v.length(); /// new code here const unsigned int bitsPerByte = 8; // parse out string 8 bits at a time into array of bytes std::vector bytes; std::reverse(v.begin(), v.end()); - for (usint i = 0; i < len; i += bitsPerByte) { + for (uint32_t i = 0; i < len; i += bitsPerByte) { std::string bits = v.substr(0, bitsPerByte); // reverse the bits std::reverse(bits.begin(), bits.end()); @@ -226,7 +226,7 @@ myZZ myZZ::FromBinaryString(const std::string& vin) { // OTHER FUNCTIONS -usint myZZ::GetMSB() const { +uint32_t myZZ::GetMSB() const { // note: originally I did not worry about this, and just set the // MSB whenever this was called, but then that violated constness in the // various libraries that used this heavily @@ -235,7 +235,7 @@ usint myZZ::GetMSB() const { // SO INSTEAD I am just regenerating the MSB each time size_t sz = this->size(); - usint MSB; + uint32_t MSB; if (sz == 0) { // special case for empty data MSB = 0; return (MSB); @@ -244,7 +244,7 @@ usint myZZ::GetMSB() const { MSB = (sz - 1) * NTL_ZZ_NBITS; // figure out bit location of all but last // limb const ZZ_limb_t* zlp = ZZ_limbs_get(*this); - usint tmp = GetMSBLimb_t(zlp[sz - 1]); // add the value of that last limb. + uint32_t tmp = GetMSBLimb_t(zlp[sz - 1]); // add the value of that last limb. MSB += tmp; m_MSB = MSB; @@ -262,15 +262,15 @@ void myZZ::SetMSB() { // m_MSB = NumBytes(*this)*8; const ZZ_limb_t* zlp = ZZ_limbs_get(*this); - usint tmp = GetMSBLimb_t(zlp[sz - 1]); // add the value of that last limb. + uint32_t tmp = GetMSBLimb_t(zlp[sz - 1]); // add the value of that last limb. m_MSB += tmp; } return; } -// inline static usint GetMSBLimb_t(ZZ_limb_t x){ -usint myZZ::GetMSBLimb_t(ZZ_limb_t x) const { - const usint bval[] = {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4}; +// inline static uint32_t GetMSBLimb_t(ZZ_limb_t x){ +uint32_t myZZ::GetMSBLimb_t(ZZ_limb_t x) const { + const uint32_t bval[] = {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4}; uint64_t r = 0; if (x & 0xFFFFFFFF00000000) { @@ -294,18 +294,18 @@ usint myZZ::GetMSBLimb_t(ZZ_limb_t x) const { // utility function introduced in Backend 6 to get a subset of bits from a // Bigint -usint myZZ::GetBitRangeAtIndex(usint ppo, usint length) const { +uint32_t myZZ::GetBitRangeAtIndex(uint32_t ppo, uint32_t length) const { if (ppo == 0 || !this->rep) return 0; - usint pin = ppo - 1; + uint32_t pin = ppo - 1; int64_t bl; int64_t sa; _ntl_limb_t wh; - usint out(0); + uint32_t out(0); - for (usint p = pin, i = 0; i < length; i++, p++) { + for (uint32_t p = pin, i = 0; i < length; i++, p++) { bl = p / NTL_ZZ_NBITS; wh = ((_ntl_limb_t)1) << (p - NTL_ZZ_NBITS * bl); @@ -323,10 +323,10 @@ usint myZZ::GetBitRangeAtIndex(usint ppo, usint length) const { return out; } -usint myZZ::GetDigitAtIndexForBase(usint index, usint base) const { - usint DigitLen = std::ceil(std::log2(base)); - usint digit = 0; - usint newIndex = 1 + (index - 1) * DigitLen; +uint32_t myZZ::GetDigitAtIndexForBase(uint32_t index, uint32_t base) const { + uint32_t DigitLen = std::ceil(std::log2(base)); + uint32_t digit = 0; + uint32_t newIndex = 1 + (index - 1) * DigitLen; digit = GetBitRangeAtIndex(newIndex, DigitLen); return digit; } @@ -334,13 +334,13 @@ usint myZZ::GetDigitAtIndexForBase(usint index, usint base) const { // returns the bit at the index into the binary format of the big integer, // note that msb is 1 like all other bit indicies in OpenFHE. -uschar myZZ::GetBitAtIndex(usint index) const { - return (uschar)GetBitRangeAtIndex(index, 1); +uint8_t myZZ::GetBitAtIndex(uint32_t index) const { + return (uint8_t)GetBitRangeAtIndex(index, 1); } // optimized ceiling function after division by number of bits in the limb data // type. -usint myZZ::ceilIntByUInt(const ZZ_limb_t Number) { +uint32_t myZZ::ceilIntByUInt(const ZZ_limb_t Number) { // mask to perform bitwise AND static ZZ_limb_t mask = NTL_ZZ_NBITS - 1; diff --git a/src/core/lib/math/hal/intnat/benative-math-impl.cpp b/src/core/lib/math/hal/intnat/benative-math-impl.cpp index 8ca835d39..b63b40581 100644 --- a/src/core/lib/math/hal/intnat/benative-math-impl.cpp +++ b/src/core/lib/math/hal/intnat/benative-math-impl.cpp @@ -50,10 +50,10 @@ template class BinaryUniformGeneratorImpl; template class TernaryUniformGeneratorImpl; template class DiscreteUniformGeneratorImpl; -template NativeInteger RootOfUnity(usint m, const NativeInteger& modulo); -template std::vector RootsOfUnity(usint m, const std::vector& moduli); +template NativeInteger RootOfUnity(uint32_t m, const NativeInteger& modulo); +template std::vector RootsOfUnity(uint32_t m, const std::vector& moduli); template NativeInteger GreatestCommonDivisor(const NativeInteger& a, const NativeInteger& b); -template bool MillerRabinPrimalityTest(const NativeInteger& p, const usint niter); +template bool MillerRabinPrimalityTest(const NativeInteger& p, const uint32_t niter); template const NativeInteger PollardRhoFactorization(const NativeInteger& n); template void PrimeFactorize(NativeInteger n, std::set& primeFactors); template NativeInteger FirstPrime(uint32_t nBits, uint64_t m); @@ -62,16 +62,16 @@ template NativeInteger NextPrime(const NativeInteger& q, uint64_t m); template NativeInteger PreviousPrime(const NativeInteger& q, uint64_t m); template std::vector GetTotientList(const NativeInteger& n); -template std::vector GetTotientList(const usint& n); +template std::vector GetTotientList(const uint32_t& n); template NativeVector PolyMod(const NativeVector& dividend, const NativeVector& divisor, const NativeInteger& modulus); template NativeVector PolynomialMultiplication(const NativeVector& a, const NativeVector& b); -template NativeVector GetCyclotomicPolynomial(usint m, const NativeInteger& modulus); +template NativeVector GetCyclotomicPolynomial(uint32_t m, const NativeInteger& modulus); template NativeInteger SyntheticRemainder(const NativeVector& dividend, const NativeInteger& a, const NativeInteger& modulus); template NativeVector SyntheticPolyRemainder(const NativeVector& dividend, const NativeVector& aList, const NativeInteger& modulus); -template NativeVector PolynomialPower(const NativeVector& input, usint power); +template NativeVector PolynomialPower(const NativeVector& input, uint32_t power); template NativeVector SyntheticPolynomialDivision(const NativeVector& dividend, const NativeInteger& a, const NativeInteger& modulus); template NativeInteger FindGeneratorCyclic(const NativeInteger& modulo); diff --git a/src/core/lib/math/nbtheory2.cpp b/src/core/lib/math/nbtheory2.cpp index 547853c46..dccca26b3 100644 --- a/src/core/lib/math/nbtheory2.cpp +++ b/src/core/lib/math/nbtheory2.cpp @@ -60,7 +60,7 @@ NTL::myZZ GreatestCommonDivisor(const NTL::myZZ& a, const NTL::myZZ& b) { } // NTL native version -bool MillerRabinPrimalityTest(const NTL::myZZ& p, const usint niter) { +bool MillerRabinPrimalityTest(const NTL::myZZ& p, const uint32_t niter) { if (p < NTL::myZZ(2) || ((p != NTL::myZZ(2)) && (p.Mod(NTL::myZZ(2)) == NTL::myZZ(0)))) return false; if (p == NTL::myZZ(2) || p == NTL::myZZ(3) || p == NTL::myZZ(5)) @@ -72,10 +72,10 @@ bool MillerRabinPrimalityTest(const NTL::myZZ& p, const usint niter) { /* Finds multiplicative inverse using the Extended Euclid Algorithms */ -usint ModInverse(usint a, usint b) { - // usint b0 = b; - usint t, q; - usint x0 = 0, x1 = 1; +uint32_t ModInverse(uint32_t a, uint32_t b) { + // uint32_t b0 = b; + uint32_t t, q; + uint32_t x0 = 0, x1 = 1; if (b == 1) return 1; while (a > 1) { @@ -105,21 +105,21 @@ uint64_t GetTotient(const uint64_t n) { return primeProd.ConvertToInt(); } -std::vector GetCyclotomicPolynomialRecursive(usint m) { - auto IsPrime = [](usint val) { +std::vector GetCyclotomicPolynomialRecursive(uint32_t m) { + auto IsPrime = [](uint32_t val) { if (val % 2 == 0) return false; - for (usint i = 3; i < val; i += 2) { + for (uint32_t i = 3; i < val; i += 2) { if (val % i == 0) return false; } return true; }; - auto GetDivisibleNumbers = [](usint val) { - std::vector div; + auto GetDivisibleNumbers = [](uint32_t val) { + std::vector div; div.reserve(val / 2); - for (usint i = 1; i < val; i++) { + for (uint32_t i = 1; i < val; i++) { if (val % i == 0) div.push_back(i); } @@ -127,28 +127,28 @@ std::vector GetCyclotomicPolynomialRecursive(usint m) { }; auto PolyMult = [](const std::vector& a, const std::vector& b) { - usint degreeA(a.size()); - usint degreeB(b.size()); - usint degreeResultant(degreeA + degreeB - 1); + uint32_t degreeA(a.size()); + uint32_t degreeB(b.size()); + uint32_t degreeResultant(degreeA + degreeB - 1); std::vector product(degreeResultant, 0); - for (usint i = 0; i < degreeA; ++i) { - for (usint j = 0; j < degreeB; ++j) + for (uint32_t i = 0; i < degreeA; ++i) { + for (uint32_t j = 0; j < degreeB; ++j) product[i + j] += a[i] * b[j]; } return product; }; auto PolyQuotient = [](const std::vector& dividend, const std::vector& divisor) { - usint divisorLength(divisor.size()); - usint dividendLength(dividend.size()); - usint runs(dividendLength - divisorLength + 1); + uint32_t divisorLength(divisor.size()); + uint32_t dividendLength(dividend.size()); + uint32_t runs(dividendLength - divisorLength + 1); std::vector quotient(runs + 1); std::vector runningDividend(dividend); - for (usint i = 0; i < runs; ++i) { + for (uint32_t i = 0; i < runs; ++i) { // get the highest degree coeff int divConst = runningDividend[dividendLength - 1]; - usint divisorPtr = divisorLength - 1; - for (usint j = 0; j < dividendLength - i - 1; ++j) { + uint32_t divisorPtr = divisorLength - 1; + for (uint32_t j = 0; j < dividendLength - i - 1; ++j) { auto& rdtmp1 = runningDividend[dividendLength - 1 - j]; rdtmp1 = runningDividend[dividendLength - 2 - j]; if (divisorPtr > j) @@ -173,7 +173,7 @@ std::vector GetCyclotomicPolynomialRecursive(usint m) { std::vector product{1}; - for (usint i = 0; i < divisibleNumbers.size(); i++) { + for (uint32_t i = 0; i < divisibleNumbers.size(); i++) { auto P = GetCyclotomicPolynomialRecursive(divisibleNumbers[i]); product = PolyMult(product, P); } @@ -267,9 +267,9 @@ void PrecomputeAutoMap(uint32_t n, uint32_t k, std::vector* precomp) { uint32_t logn = std::round(std::log2(n)); for (uint32_t j = 0; j < n; j++) { uint32_t jTmp = ((j << 1) + 1); - usint idx = ((jTmp * k) - (((jTmp * k) >> logm) << logm)) >> 1; - usint jrev = ReverseBits(j, logn); - usint idxrev = ReverseBits(idx, logn); + uint32_t idx = ((jTmp * k) - (((jTmp * k) >> logm) << logm)) >> 1; + uint32_t jrev = ReverseBits(j, logn); + uint32_t idxrev = ReverseBits(idx, logn); (*precomp)[jrev] = idxrev; } } diff --git a/src/core/unittest/UnitTest128.cpp b/src/core/unittest/UnitTest128.cpp index b1e49760b..2c01126d2 100644 --- a/src/core/unittest/UnitTest128.cpp +++ b/src/core/unittest/UnitTest128.cpp @@ -111,8 +111,8 @@ TEST(UT128, modular_operations) { } TEST(UT128, NTT_operations) { - usint m1 = 16; - usint bits = 100; + uint32_t m1 = 16; + uint32_t bits = 100; auto x1p = std::make_shared(m1, bits); auto x2p = std::make_shared(m1 / 2, bits); diff --git a/src/core/unittest/UnitTestBinInt.cpp b/src/core/unittest/UnitTestBinInt.cpp index 4daaea0f8..4e6ba9a6c 100644 --- a/src/core/unittest/UnitTestBinInt.cpp +++ b/src/core/unittest/UnitTestBinInt.cpp @@ -1003,7 +1003,7 @@ void shift(const std::string& msg) { // TEST_F CASE WHEN SHIFT IS LESS THAN 4 (MAX SHIFT DONE AT A TIME) { T a("39960"); - usshort shift = 3; + uint16_t shift = 3; T calculatedResult = a << (shift); uint64_t expectedResult = 319680; @@ -1014,7 +1014,7 @@ void shift(const std::string& msg) { // TEST_F CASE WHEN SHIFT IS GREATER THAN 4 (MAX SHIFT DONE AT A TIME) { T a("39960"); - usshort shift = 6; + uint16_t shift = 6; T calculatedResult = a << (shift); uint64_t expectedResult = 2557440; @@ -1040,7 +1040,7 @@ void shift(const std::string& msg) { // TEST_F CASE WHEN SHIFT IS LESS THAN 4 (MAX SHIFT DONE AT A TIME) { T a("39960"); - usshort num = 3; + uint16_t num = 3; a <<= (num); uint64_t expectedResult = 319680; @@ -1050,7 +1050,7 @@ void shift(const std::string& msg) { // TEST_F CASE WHEN SHIFT IS GREATER THAN 4 (MAX SHIFT DONE AT A TIME) { T a("39960"); - usshort num = 6; + uint16_t num = 6; a <<= (num); uint64_t expectedResult = 2557440; @@ -1076,7 +1076,7 @@ void shift(const std::string& msg) { // TEST_F CASE WHEN SHIFT IS LESS THAN 4 (MAX SHIFT DONE AT A TIME) { T a("39965675"); - usshort shift = 3; + uint16_t shift = 3; T calculatedResult = a >> (shift); uint64_t expectedResult = 4995709; @@ -1087,7 +1087,7 @@ void shift(const std::string& msg) { // TEST_F CASE WHEN SHIFT IS GREATER THAN 4 (MAX SHIFT DONE AT A TIME) { T a("39965675"); - usshort shift = 6; + uint16_t shift = 6; T calculatedResult = a >> (shift); uint64_t expectedResult = 624463; @@ -1115,7 +1115,7 @@ void shift(const std::string& msg) { // TEST_F CASE WHEN SHIFT IS LESS THAN 4 (MAX SHIFT DONE AT A TIME) { T a("39965675"); - usshort shift = 3; + uint16_t shift = 3; a >>= (shift); uint64_t expectedResult = 4995709; @@ -1125,7 +1125,7 @@ void shift(const std::string& msg) { // TEST_F CASE WHEN SHIFT IS GREATER THAN 4 (MAX SHIFT DONE AT A TIME) { T a("39965675"); - usshort shift = 6; + uint16_t shift = 6; a >>= (shift); uint64_t expectedResult = 624463; diff --git a/src/core/unittest/UnitTestBinVect.cpp b/src/core/unittest/UnitTestBinVect.cpp index f3f48ddbc..f9d881a5c 100644 --- a/src/core/unittest/UnitTestBinVect.cpp +++ b/src/core/unittest/UnitTestBinVect.cpp @@ -58,7 +58,7 @@ using namespace lbcrypto; template void AtAndSetModulusTest(const std::string& msg) { OPENFHE_DEBUG_FLAG(false); - usint len = 10; + uint32_t len = 10; V m(len); // note at() does not set modulus @@ -81,7 +81,7 @@ void AtAndSetModulusTest(const std::string& msg) { V calculatedResult = m.Mod(q); OPENFHE_DEBUG("calculated result" << m); uint64_t expectedResult[] = {48, 53, 7, 178, 190, 120, 79, 108, 60, 12}; - for (usint i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++) { EXPECT_EQ(expectedResult[i], calculatedResult[i].ConvertToInt()) << msg << " Mod failed"; } @@ -99,7 +99,7 @@ void AtAndSetModulusTest(const std::string& msg) { n.at(9) = typename V::Integer("7698798"); OPENFHE_DEBUG("n" << n); - for (usint i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++) { if (i != 6) { // value at 6 is < q EXPECT_NE(expectedResult[i], n[i].ConvertToInt()) << msg << " at no mod failed"; } @@ -112,7 +112,7 @@ void AtAndSetModulusTest(const std::string& msg) { // note list assignment does take modulus l = {"987968", "587679", "456454", "234343", "769789", "465654", "79", "346346", "325328", "7698798"}; OPENFHE_DEBUG("l" << l); - for (usint i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++) { EXPECT_EQ(expectedResult[i], l[i].ConvertToInt()) << msg << " Mod on list assignment failed"; } } @@ -124,15 +124,15 @@ TEST(UTBinVect, AtAndSetModulusTest) { template void CTOR_Test(const std::string& msg) { typename V::Integer q("233"); - usint expectedResult[10] = {48, 53, 7, 178, 190, 120, 79, 108, 60, 12}; - const usint len = sizeof(expectedResult) / sizeof(expectedResult[0]); + uint32_t expectedResult[10] = {48, 53, 7, 178, 190, 120, 79, 108, 60, 12}; + const uint32_t len = sizeof(expectedResult) / sizeof(expectedResult[0]); { V m(len, q, {"987968", "587679", "456454", "234343", "769789", "465654", "79", "346346", "325328", "7698798"}); V calculatedResult = m.Mod(q); - for (usint i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++) { EXPECT_EQ(expectedResult[i], (calculatedResult.at(i)).ConvertToInt()) << msg; } } @@ -140,7 +140,7 @@ void CTOR_Test(const std::string& msg) { { V m(len, q, {48, 53, 7, 178, 190, 120, 79, 108, 60, 12}); - for (usint i = 0; i < len; i++) { + for (uint32_t i = 0; i < len; i++) { EXPECT_EQ(expectedResult[i], m.at(i).ConvertToInt()) << msg; } } @@ -177,7 +177,7 @@ void ModAddBigModulus(const std::string& msg) { uint64_t expectedResult[5] = {9871, 5882, 4557, 2346, 9792}; - for (usint i = 0; i < 5; i++) { + for (uint32_t i = 0; i < 5; i++) { EXPECT_EQ(expectedResult[i], (calculatedResult.at(i)).ConvertToInt()) << msg; } } @@ -216,7 +216,7 @@ void ModAddSmallerModulus(const std::string& msg) { OPENFHE_DEBUG("calculated result " << calculatedResult); uint64_t expectedResult[5] = {1825, 1370, 45, 1368, 1746}; - for (usint i = 0; i < 5; i++) { + for (uint32_t i = 0; i < 5; i++) { EXPECT_EQ(expectedResult[i], (calculatedResult.at(i)).ConvertToInt()) << msg; } } @@ -257,7 +257,7 @@ void modsub_first_less_than_second(const std::string& msg) { uint64_t expectedResult[5] = {241, 3320, 1995, 3318, 162}; - for (usint i = 0; i < 5; i++) { + for (uint32_t i = 0; i < 5; i++) { EXPECT_EQ(expectedResult[i], (calculatedResult.at(i)).ConvertToInt()) << msg; } } @@ -289,7 +289,7 @@ void modsub_first_greater_than_second(const std::string& msg) { uint64_t expectedResult[5] = {3, 4, 9, 3, 29}; - for (usint i = 0; i < 5; i++) { + for (uint32_t i = 0; i < 5; i++) { EXPECT_EQ(expectedResult[i], (calculatedResult.at(i)).ConvertToInt()) << msg; } } @@ -321,7 +321,7 @@ void ModMulTest(const std::string& msg) { uint64_t expectedResult[5] = {1576, 1850, 978, 1758, 1476}; - for (usint i = 0; i < 5; i++) { + for (uint32_t i = 0; i < 5; i++) { EXPECT_EQ(expectedResult[i], (calculatedResult.at(i)).ConvertToInt()) << msg; } } @@ -355,7 +355,7 @@ void ModExpTest(const std::string& msg) { uint64_t expectedResult[5] = {2792, 3123, 64, 159, 901}; - for (usint i = 0; i < 5; i++) { + for (uint32_t i = 0; i < 5; i++) { EXPECT_EQ(expectedResult[i], (calculatedResult.at(i)).ConvertToInt()) << msg; } } @@ -388,7 +388,7 @@ void test_modinv(const std::string& msg) { uint64_t expectedResult[5] = {32, 24, 9, 17, 13}; - for (usint i = 0; i < 5; i++) { + for (uint32_t i = 0; i < 5; i++) { EXPECT_EQ(expectedResult[i], (calculatedResult.at(i)).ConvertToInt()) << msg; } } @@ -429,7 +429,7 @@ void modadd_vector_result_smaller_modulus(const std::string& msg) { uint64_t expectedResult[5] = {14401, 10428, 11310, 3576, 17686}; - for (usint i = 0; i < 5; i++) { + for (uint32_t i = 0; i < 5; i++) { EXPECT_EQ(expectedResult[i], (calculatedResult.at(i)).ConvertToInt()) << msg; } } @@ -462,7 +462,7 @@ void modadd_vector_result_greater_modulus(const std::string& msg) { OPENFHE_DEBUG("result mod " << calculatedResult.GetModulus()); uint64_t expectedResult[5] = {604, 573, 141, 291, 604}; - for (usint i = 0; i < 5; i++) { + for (uint32_t i = 0; i < 5; i++) { EXPECT_EQ(expectedResult[i], (calculatedResult.at(i)).ConvertToInt()) << msg; } } @@ -499,7 +499,7 @@ void method_add_equals_vector_operation(const std::string& msg) { OPENFHE_DEBUG("m" << m); uint64_t expectedResult[5] = {17, 632, 21, 405, 598}; - for (usint i = 0; i < 5; i++) { + for (uint32_t i = 0; i < 5; i++) { EXPECT_EQ(expectedResult[i], (m.at(i)).ConvertToInt()) << msg; } } @@ -537,7 +537,7 @@ void modmul_vector(const std::string& msg) { uint64_t expectedResult[5] = {52, 351, 315, 450, 195}; - for (usint i = 0; i < 5; i++) { + for (uint32_t i = 0; i < 5; i++) { EXPECT_EQ(expectedResult[i], (calculatedResult.at(i)).ConvertToInt()) << msg; } } diff --git a/src/core/unittest/UnitTestDistrGen.cpp b/src/core/unittest/UnitTestDistrGen.cpp index 8709a3abb..a4f06ca01 100644 --- a/src/core/unittest/UnitTestDistrGen.cpp +++ b/src/core/unittest/UnitTestDistrGen.cpp @@ -81,7 +81,7 @@ void DiscreteUniformGenerator_LONG(const std::string& msg) { typename V::Integer modulus("10403"); auto dug = DiscreteUniformGeneratorImpl(); - usint size = 10; + uint32_t size = 10; V uniRandVector = dug.GenerateVector(size, modulus); // test length EXPECT_EQ(uniRandVector.GetLength(), size) @@ -101,7 +101,7 @@ void DiscreteUniformGenerator_LONG(const std::string& msg) { typename V::Integer modulus("10402635286389262637365363"); auto dug = DiscreteUniformGeneratorImpl(); - usint size = 100; + uint32_t size = 100; V uniRandVector = dug.GenerateVector(size, modulus); // test length EXPECT_EQ(uniRandVector.GetLength(), size) << "Failure testing vector_uniform_vector_large_modulus"; @@ -138,12 +138,12 @@ void DiscreteUniformGenerator_LONG(const std::string& msg) { typename V::Integer modulus("10402635286389262637365363"); // 10402635286389262637365363 auto dug = DiscreteUniformGeneratorImpl(); - usint eachIterationSize = 1000, noOfIterations = 100; + uint32_t eachIterationSize = 1000, noOfIterations = 100; typename V::Integer sum, mean, N(eachIterationSize); V uniRandVector = dug.GenerateVector(eachIterationSize * noOfIterations, modulus); - for (usint i = 0; i < noOfIterations; i++) { + for (uint32_t i = 0; i < noOfIterations; i++) { sum = mean = typename V::Integer(0); for (size_t j = i * eachIterationSize; j < (i + 1) * eachIterationSize; j++) { sum += uniRandVector.at(j); @@ -175,13 +175,13 @@ void testDiscreteUniformGenerator(typename V::Integer& modulus, std::string test auto distrUniGen = DiscreteUniformGeneratorImpl(); distrUniGen.SetModulus(modulus); - usint size = 50000; + uint32_t size = 50000; V randBigVector = distrUniGen.GenerateVector(size); double sum = 0; typename V::Integer length(std::to_string(randBigVector.GetLength())); - for (usint index = 0; index < size; index++) { + for (uint32_t index = 0; index < size; index++) { sum += (randBigVector.at(index)).ConvertToDouble(); } @@ -197,7 +197,7 @@ void testDiscreteUniformGenerator(typename V::Integer& modulus, std::string test sum = 0; double temp; - for (usint index = 0; index < size; index++) { + for (uint32_t index = 0; index < size; index++) { temp = (randBigVector.at(index)).ConvertToDouble() - expectedMeanInDouble; temp *= temp; sum += temp; @@ -239,8 +239,8 @@ void testParallelDiscreteUniformGenerator(typename V::Integer& modulus, std::str double modulusInDouble = modulus.ConvertToDouble(); // we expect the mean to be modulus/2 (the mid range of the min-max data); double expectedMeanInDouble = modulusInDouble / 2.0; - usint size = 50000; - // usint size = omp_get_max_threads() * 4; + uint32_t size = 50000; + // uint32_t size = omp_get_max_threads() * 4; OPENFHE_DEBUG_FLAG(false); std::vector randBigVector; @@ -253,7 +253,7 @@ void testParallelDiscreteUniformGenerator(typename V::Integer& modulus, std::str distrUniGen.SetModulus(modulus); // build the vectors in parallel #pragma omp for nowait schedule(static) - for (usint i = 0; i < size; i++) { + for (uint32_t i = 0; i < size; i++) { // build private copies in parallel randBigVectorPvt.push_back(distrUniGen.GenerateInteger()); } @@ -275,7 +275,7 @@ void testParallelDiscreteUniformGenerator(typename V::Integer& modulus, std::str double sum = 0; typename V::Integer length(std::to_string(randBigVector.size())); - for (usint index = 0; index < size; index++) { + for (uint32_t index = 0; index < size; index++) { sum += (randBigVector[index]).ConvertToDouble(); } // divide by the size (i.e. take mean) @@ -294,7 +294,7 @@ void testParallelDiscreteUniformGenerator(typename V::Integer& modulus, std::str sum = 0; double temp; - for (usint index = 0; index < size; index++) { + for (uint32_t index = 0; index < size; index++) { temp = (randBigVector[index]).ConvertToDouble() - expectedMeanInDouble; temp *= temp; sum += temp; @@ -313,14 +313,14 @@ void testParallelDiscreteUniformGenerator(typename V::Integer& modulus, std::str // TEST(UTDistrGen, DiscreteUniformGeneratorSeed ) { // typename V::Integer modulus("7919"); // test small modulus // double sum1=0; -// usint size = 10; +// uint32_t size = 10; // { // DiscreteUniformGenerator distrUniGen = // lbcrypto::DiscreteUniformGenerator(modulus, 12345); // V randBigVector1 = distrUniGen.GenerateVector(size); -// for(usint index=0; index(); - usint length = 100000; + uint32_t length = 100000; auto modulus = typename V::Integer("1041"); auto randBigVector = binaryUniGen.GenerateVector(length, modulus); - usint sum = 0; + uint32_t sum = 0; - for (usint index = 0; index < randBigVector.GetLength(); index++) { + for (uint32_t index = 0; index < randBigVector.GetLength(); index++) { sum += randBigVector.at(index).ConvertToInt(); } @@ -388,13 +388,13 @@ template void TernaryUniformGeneratorTest(const std::string& msg) { auto ternaryUniGen = TernaryUniformGeneratorImpl(); - usint length = 100000; + uint32_t length = 100000; auto modulus = typename V::Integer("1041"); V randBigVector = ternaryUniGen.GenerateVector(length, modulus); int32_t sum = 0; - for (usint index = 0; index < randBigVector.GetLength(); index++) { + for (uint32_t index = 0; index < randBigVector.GetLength(); index++) { if (randBigVector[index] == modulus - typename V::Integer(1)) sum -= 1; else @@ -424,13 +424,13 @@ void DiscreteGaussianGeneratorTest(const std::string& msg) { { int stdev = 5; - usint size = 100000; + uint32_t size = 100000; typename V::Integer modulus("10403"); auto dgg = DiscreteGaussianGeneratorImpl(stdev); auto dggCharVector = dgg.GenerateIntVector(size); double mean = 0; - for (usint i = 0; i < size; i++) { + for (uint32_t i = 0; i < size; i++) { mean += static_cast(dggCharVector[i]); } mean /= size; @@ -442,16 +442,16 @@ void DiscreteGaussianGeneratorTest(const std::string& msg) { // generate_vector_mean_test { int stdev = 5; - usint size = 100000; + uint32_t size = 100000; typename V::Integer modulus("10403"); typename V::Integer modulusByTwo(modulus.DividedBy(2)); const auto dgg = DiscreteGaussianGeneratorImpl(stdev); V dggBigVector = dgg.GenerateVector(size, modulus); - usint countOfZero = 0; + uint32_t countOfZero = 0; double mean = 0, current = 0; - for (usint i = 0; i < size; i++) { + for (uint32_t i = 0; i < size; i++) { current = std::stod(dggBigVector.at(i).ToString()); if (current == 0) countOfZero++; @@ -479,7 +479,7 @@ void ParallelDiscreteGaussianGenerator_VERY_LONG(const std::string& msg) { { int stdev = 5; - usint size = 10000; + uint32_t size = 10000; typename V::Integer modulus("10403"); std::vector dggCharVector; @@ -492,7 +492,7 @@ void ParallelDiscreteGaussianGenerator_VERY_LONG(const std::string& msg) { // build the vectors in parallel #pragma omp for nowait schedule(static) - for (usint i = 0; i < size; i++) { + for (uint32_t i = 0; i < size; i++) { // build private copies in parallel dggCharVectorPvt.push_back(dgg.GenerateInt()); } @@ -510,7 +510,7 @@ void ParallelDiscreteGaussianGenerator_VERY_LONG(const std::string& msg) { } double mean = 0; - for (usint i = 0; i < size; i++) { + for (uint32_t i = 0; i < size; i++) { mean += static_cast(dggCharVector[i]); } mean /= size; @@ -522,7 +522,7 @@ void ParallelDiscreteGaussianGenerator_VERY_LONG(const std::string& msg) { // generate_vector_mean_test { int stdev = 5; - usint size = 100000; + uint32_t size = 100000; typename V::Integer modulus("10403"); typename V::Integer modulusByTwo(modulus.DividedBy(2)); @@ -535,7 +535,7 @@ void ParallelDiscreteGaussianGenerator_VERY_LONG(const std::string& msg) { // build the vectors in parallel #pragma omp for nowait schedule(static) - for (usint i = 0; i < size; i++) { + for (uint32_t i = 0; i < size; i++) { // build private copies in parallel dggBigVectorPvt.push_back(dgg.GenerateInteger(modulus)); } @@ -552,10 +552,10 @@ void ParallelDiscreteGaussianGenerator_VERY_LONG(const std::string& msg) { } } - usint countOfZero = 0; + uint32_t countOfZero = 0; double mean = 0, current = 0; - for (usint i = 0; i < size; i++) { + for (uint32_t i = 0; i < size; i++) { current = std::stod(dggBigVector[i].ToString()); if (current == 0) countOfZero++; @@ -580,7 +580,7 @@ TEST(UTDistrGen, ParallelDiscreteGaussianGenerator_VERY_LONG) { template void Karney_Mean(const std::string& msg) { int stdev = 10; - usint size = 10000; + uint32_t size = 10000; double mean = 0; double center = 10; auto dgg = DiscreteGaussianGeneratorImpl(stdev); @@ -601,7 +601,7 @@ TEST(UTDistrGen, Karney_Mean) { template void Karney_Variance(const std::string& msg) { int stdev = 10; - usint size = 10000; + uint32_t size = 10000; double mean = 0; double variance = 0; auto dgg = DiscreteGaussianGeneratorImpl(stdev); diff --git a/src/core/unittest/UnitTestMatrix.cpp b/src/core/unittest/UnitTestMatrix.cpp index 86c2dc26b..2070c2f79 100644 --- a/src/core/unittest/UnitTestMatrix.cpp +++ b/src/core/unittest/UnitTestMatrix.cpp @@ -45,7 +45,7 @@ using namespace lbcrypto; template static std::function secureIL2nAlloc() { - usint m = 2048; + uint32_t m = 2048; typename Element::Integer secureModulus("8590983169"); typename Element::Integer secureRootOfUnity("4810681236"); return Element::Allocator(std::make_shared(m, secureModulus, secureRootOfUnity), @@ -54,7 +54,7 @@ static std::function secureIL2nAlloc() { template static std::function fastIL2nAlloc() { - usint m = 16; + uint32_t m = 16; typename Element::Integer modulus("67108913"); typename Element::Integer rootOfUnity("61564"); return Element::Allocator(std::make_shared(m, modulus, rootOfUnity), Format::EVALUATION); @@ -62,7 +62,7 @@ static std::function fastIL2nAlloc() { template static std::function fastUniformIL2nAlloc() { - usint m = 16; + uint32_t m = 16; typename Element::Integer modulus("67108913"); typename Element::Integer rootOfUnity("61564"); return Element::MakeDiscreteUniformAllocator(std::make_shared(m, modulus, rootOfUnity), diff --git a/src/core/unittest/UnitTestMubintvec.cpp b/src/core/unittest/UnitTestMubintvec.cpp index 8fcc809f6..495ba1d60 100644 --- a/src/core/unittest/UnitTestMubintvec.cpp +++ b/src/core/unittest/UnitTestMubintvec.cpp @@ -119,9 +119,9 @@ TEST(UTmubintvec, ctor_access_eq_neq) { m += n; - usint expectedResult[5] = {9872, 5888, 4620, 2376, 4631}; + uint32_t expectedResult[5] = {9872, 5888, 4620, 2376, 4631}; - for (usint i = 0; i < 5; ++i) { + for (uint32_t i = 0; i < 5; ++i) { EXPECT_EQ(expectedResult[i], (m.at(i)).ConvertToInt()) << "Failure testing method_add_equals"; } @@ -141,7 +141,7 @@ TEST(UTmubintvec, ctor_access_eq_neq) { // list"; expectedvecint = {9872ULL, 5888ULL, 4620ULL, 2376ULL, 4631ULL}; // usints - EXPECT_EQ(expectedvecint, m) << "Failure usint initializer list"; + EXPECT_EQ(expectedvecint, m) << "Failure uint32_t initializer list"; expectedvecint = {9872, 5888, 4620, 2376, 4631}; // ints (compiler promotes) EXPECT_EQ(expectedvecint, m) << "Failure int initializer list"; @@ -158,21 +158,21 @@ TEST(UTmubintvec, ctor_access_eq_neq) { bigintdyn::xmubintvec eqtest(10); EXPECT_EQ(10U, eqtest.GetLength()) << "Failure create bigintdyn::xmubintvec of 10 zeros"; - for (usint i = 0; i < eqtest.GetLength(); ++i) { + for (uint32_t i = 0; i < eqtest.GetLength(); ++i) { EXPECT_EQ(bigintdyn::xubint(0U), eqtest[i]) << "Failure create bigintdyn::xmubintvec of zeros"; } // test assignment of single bigintdyn::xubint eqtest = bigintdyn::xubint(1); EXPECT_EQ(bigintdyn::xubint(1), eqtest[0]) << "Failure assign single bigintdyn::xubint 0 index"; - for (usint i = 1; i < eqtest.GetLength(); i++) { + for (uint32_t i = 1; i < eqtest.GetLength(); i++) { EXPECT_EQ(bigintdyn::xubint(0U), eqtest[i]) << "Failure assign single bigintdyn::xubint nonzero index"; } - // test assignment of single usint + // test assignment of single uint32_t eqtest = 5U; EXPECT_EQ(bigintdyn::xubint(5U), eqtest[0]) << "Failure assign single bigintdyn::xubint 0 index"; - for (usint i = 1; i < eqtest.GetLength(); ++i) { + for (uint32_t i = 1; i < eqtest.GetLength(); ++i) { EXPECT_EQ(bigintdyn::xubint(0U), eqtest[i]) << "Failure assign single bigintdyn::xubint nonzero index"; } @@ -198,7 +198,7 @@ TEST(UTmubintvec, ctor_access_eq_neq) { EXPECT_FALSE(test1) << "Failure =="; EXPECT_TRUE(test2) << "Failure !="; - for (usint i = 0; i < m.GetLength(); ++i) { + for (uint32_t i = 0; i < m.GetLength(); ++i) { m[i] = n[i]; // test both lhs and rhs [] } @@ -227,14 +227,14 @@ TEST(UTmubintvec, constructorTest) { 120, 79, 108, 60, 12}; // the expected values are stored as one dimensional // integer array - for (usint i = 0; i < 10; i++) { + for (uint32_t i = 0; i < 10; i++) { OPENFHE_DEBUG("val " << i << " is " << m.at(i)); EXPECT_EQ(expectedResult[i], (m.at(i)).ConvertToInt()); } bigintdyn::xmubintvec binvect(m); - for (usint i = 0; i < 10; i++) { + for (uint32_t i = 0; i < 10; i++) { EXPECT_EQ(expectedResult[i], (binvect.at(i)).ConvertToInt()); } } @@ -261,7 +261,7 @@ TEST(UTmubintvec, mod) { bigintdyn::xmubintvec calculatedResult = m.Mod(q); // the expected values are stored as one dimensional integer array - usint expectedResult[10] = {48, 53, 7, 178, 190, 120, 79, 108, 60, 12}; + uint32_t expectedResult[10] = {48, 53, 7, 178, 190, 120, 79, 108, 60, 12}; for (size_t i = 0; i < 10; i++) { EXPECT_EQ(expectedResult[i], calculatedResult[i].ConvertToInt()); @@ -372,21 +372,21 @@ TEST(UTmubintvec, basic_vector_scalar_mod_math_2_limb) { bigintdyn::xubint myone(1); - for (usint i = 0; i < a2.GetLength(); i++) { + for (uint32_t i = 0; i < a2.GetLength(); i++) { a2op1[i] = a2[i] + myone; a2op1[i] %= q2; } a2op1test = a2.ModAdd(myone); EXPECT_EQ(a2op1, a2op1test) << "Failure vector scalar ModAdd()"; - for (usint i = 0; i < a2.GetLength(); i++) { + for (uint32_t i = 0; i < a2.GetLength(); i++) { a2op1[i] = a2[i] - myone; a2op1[i] %= q2; } a2op1test = a2.ModSub(myone); EXPECT_EQ(a2op1, a2op1test) << "Failure vector scalar ModSub()"; - for (usint i = 0; i < a2.GetLength(); i++) { + for (uint32_t i = 0; i < a2.GetLength(); i++) { a2op1[i] = a2[i] * myone; a2op1[i] %= q2; } diff --git a/src/core/unittest/UnitTestNTT.cpp b/src/core/unittest/UnitTestNTT.cpp index 9504497b2..d2b64ee6a 100644 --- a/src/core/unittest/UnitTestNTT.cpp +++ b/src/core/unittest/UnitTestNTT.cpp @@ -54,8 +54,8 @@ template void switch_format_simple_single_crt(const std::string& msg) { using ParmType = typename Element::Params; - usint m1 = 16; - usint bits = 16; + uint32_t m1 = 16; + uint32_t bits = 16; auto x1p = std::make_shared(m1, bits); auto x2p = std::make_shared(m1 / 2, bits); @@ -92,9 +92,9 @@ TEST(UTNTT, switch_format_simple_single_crt) { template void switch_format_simple_double_crt(const std::string& msg) { - usint init_m = 16; - usint init_size = 2; - usint init_bits = 28; + uint32_t init_m = 16; + uint32_t init_size = 2; + uint32_t init_bits = 28; auto params = std::make_shared>(init_m, init_size, init_bits); diff --git a/src/core/unittest/UnitTestNbTheory.cpp b/src/core/unittest/UnitTestNbTheory.cpp index 90752038f..a1632772d 100644 --- a/src/core/unittest/UnitTestNbTheory.cpp +++ b/src/core/unittest/UnitTestNbTheory.cpp @@ -140,8 +140,8 @@ TEST(UTNbTheory, method_factorize_returns_factors){ TEST(UTNbTheory, first_prime_overflow) { // Failure case check - usint m = 512; - usint nBits = NATIVEINT; + uint32_t m = 512; + uint32_t nBits = NATIVEINT; EXPECT_THROW(FirstPrime(nBits, m), OpenFHEException) << "did not detect overflow and throw exception for Native"; @@ -158,7 +158,7 @@ TEST(UTNbTheory, first_prime_overflow) { template void method_prime_modulus(const std::string& msg) { - usint m, nBits; + uint32_t m, nBits; { // TEST CASE TO FIND PRIME MODULUS m = 2048; @@ -187,8 +187,8 @@ void method_primitive_root_of_unity_VERY_LONG(const std::string& msg) { { // TEST CASE TO ENSURE THE ROOT OF UNITY THAT IS FOUND IS A PRIMITIVE ROOT // OF UNTIY - usint m = 4096; - usint nBits = 33; + uint32_t m = 4096; + uint32_t nBits = 33; T primeModulus = LastPrime(nBits, m); T primitiveRootOfUnity = RootOfUnity(m, primeModulus); @@ -204,9 +204,9 @@ void method_primitive_root_of_unity_VERY_LONG(const std::string& msg) { { // TEST CASE TO ENSURE THE ROOTS OF UNITY THAT ARE FOUND ARE // CONSISTENTLY THE PRIMITIVE ROOTS OF UNTIY - const usint n = 256; - const usint m = 2 * n; - const usint nBits = 43; + const uint32_t n = 256; + const uint32_t m = 2 * n; + const uint32_t nBits = 43; const int ITERATIONS = m * 2; T M(std::to_string(m)), MbyTwo(M.DividedBy(2)), MbyFour(MbyTwo.DividedBy(2)); @@ -229,7 +229,7 @@ void method_primitive_root_of_unity_VERY_LONG(const std::string& msg) { // ofstream fout; // fout.open ("primitiveRootsBug.log"); - usint nqBitsArray[] = { + uint32_t nqBitsArray[] = { 1, 1, 2, @@ -246,7 +246,7 @@ void method_primitive_root_of_unity_VERY_LONG(const std::string& msg) { 40, 2048, 41 - // const usint BIT_LENGTH = 200 and const usint FRAGMENTATION_FACTOR = + // const uint32_t BIT_LENGTH = 200 and const uint32_t FRAGMENTATION_FACTOR = // 27 ,2048, 51 , 4096, @@ -275,7 +275,7 @@ void method_primitive_root_of_unity_VERY_LONG(const std::string& msg) { }; int length = sizeof(nqBitsArray) / sizeof(nqBitsArray[0]); // double diff, start, finish; - usint n, qBits, m; + uint32_t n, qBits, m; // T M(std::to_string(m)), MbyTwo(M.DividedBy(2)), // MbyFour(MbyTwo.DividedBy(2)); @@ -373,14 +373,14 @@ TEST(UTNbTheory, method_primitive_root_of_unity_VERY_LONG) { template void test_nextQ(const std::string& msg) { - usint m = 2048; - usint bits = 22; + uint32_t m = 2048; + uint32_t bits = 22; std::vector moduliBBV = {T("4208641"), T("4263937"), T("4270081"), T("4274177"), T("4294657"), T("4300801"), T("4304897"), T("4319233"), T("4323329"), T("4360193")}; auto q = FirstPrime(bits, m); - for (usint i = 0; i < 10; i++) { + for (uint32_t i = 0; i < 10; i++) { q = NextPrime(q, m); EXPECT_EQ(q, moduliBBV[i]) << msg; } diff --git a/src/core/unittest/UnitTestTransform.cpp b/src/core/unittest/UnitTestTransform.cpp index f9ef4dbf3..fc4df5048 100644 --- a/src/core/unittest/UnitTestTransform.cpp +++ b/src/core/unittest/UnitTestTransform.cpp @@ -51,8 +51,8 @@ using namespace lbcrypto; template void CRT_polynomial_mult(const std::string& msg) { typename V::Integer primeModulus("113"); // 65537 - usint cycloOrder = 8; - usint n = cycloOrder / 2; + uint32_t cycloOrder = 8; + uint32_t n = cycloOrder / 2; typename V::Integer primitiveRootOfUnity = lbcrypto::RootOfUnity(cycloOrder, primeModulus); @@ -96,12 +96,12 @@ template void CRT_polynomial_mult_small(const std::string& msg) { OPENFHE_DEBUG_FLAG(false); - usint m = 22; + uint32_t m = 22; typename V::Integer squareRootOfRoot(3750); typename V::Integer modulus(4621); typename V::Integer bigModulus("32043581647489"); typename V::Integer bigRoot("31971887649898"); - usint n = GetTotient(m); + uint32_t n = GetTotient(m); OPENFHE_DEBUG("m is " << m << " and n is " << n); auto cycloPoly = GetCyclotomicPolynomial(m, modulus); @@ -131,7 +131,7 @@ void CRT_polynomial_mult_small(const std::string& msg) { OPENFHE_DEBUG("8"); cCheck = PolyMod(cCheck, cycloPoly, modulus); - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { EXPECT_EQ(cCheck.at(i), c.at(i)) << msg; } } @@ -145,13 +145,13 @@ TEST(UTTransform, CRT_polynomial_mult_small) { template void CRT_polynomial_mult_big_ring(const std::string& msg) { - usint m = 1800; + uint32_t m = 1800; typename V::Integer modulus(14401); typename V::Integer bigModulus("1045889179649"); typename V::Integer bigRoot("864331722621"); typename V::Integer squareRootOfRoot("972"); - usint n = GetTotient(m); + uint32_t n = GetTotient(m); auto cycloPoly = GetCyclotomicPolynomial(m, modulus); ChineseRemainderTransformArb().PreCompute(m, modulus); @@ -172,7 +172,7 @@ void CRT_polynomial_mult_big_ring(const std::string& msg) { auto cCheck = PolynomialMultiplication(a, b); cCheck = PolyMod(cCheck, cycloPoly, modulus); - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { EXPECT_EQ(cCheck.at(i), c.at(i)) << msg; } } @@ -185,13 +185,13 @@ template void CRT_polynomial_mult_big_ring_prime_cyclotomics(const std::string& msg) { OPENFHE_DEBUG_FLAG(false); - usint m = 1733; + uint32_t m = 1733; typename V::Integer modulus("1152921504606909071"); typename V::Integer bigModulus("10889035741470030830827987437816582848513"); typename V::Integer bigRoot("5879632101734955395039618227388702592012"); typename V::Integer squareRootOfRoot("44343872016735288"); - usint n = GetTotient(m); + uint32_t n = GetTotient(m); auto cycloPoly = GetCyclotomicPolynomial(m, modulus); ChineseRemainderTransformArb().PreCompute(m, modulus); @@ -228,12 +228,12 @@ TEST(UTTransform, CRT_polynomial_mult_big_ring_prime_cyclotomics) { template void CRT_CHECK_small_ring(const std::string& msg) { - usint m = 22; + uint32_t m = 22; typename V::Integer squareRootOfRoot(3750); typename V::Integer modulus(4621); typename V::Integer bigModulus("32043581647489"); typename V::Integer bigRoot("31971887649898"); - usint n = GetTotient(m); + uint32_t n = GetTotient(m); auto cycloPoly = GetCyclotomicPolynomial(m, modulus); @@ -247,7 +247,7 @@ void CRT_CHECK_small_ring(const std::string& msg) { auto inputCheck = ChineseRemainderTransformArb().InverseTransform(INPUT, squareRootOfRoot, bigModulus, bigRoot, m); - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { EXPECT_EQ(input.at(i), inputCheck.at(i)) << msg; } } @@ -262,13 +262,13 @@ TEST(UTTransform, CRT_CHECK_small_ring) { template void CRT_CHECK_big_ring(const std::string& msg) { - usint m = 1800; + uint32_t m = 1800; typename V::Integer modulus(14401); typename V::Integer squareRootOfRoot("972"); typename V::Integer bigModulus("1045889179649"); typename V::Integer bigRoot("864331722621"); - usint n = GetTotient(m); + uint32_t n = GetTotient(m); auto cycloPoly = GetCyclotomicPolynomial(m, modulus); // ChineseRemainderTransformArb::PreCompute(m, modulus); @@ -276,7 +276,7 @@ void CRT_CHECK_big_ring(const std::string& msg) { V input(n, modulus); std::uniform_int_distribution<> dis(0, 100); // generates a number in [0,100] - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { input.at(i) = typename V::Integer(dis(PseudoRandomNumberGenerator::GetPRNG())); } @@ -284,7 +284,7 @@ void CRT_CHECK_big_ring(const std::string& msg) { auto recOut = ChineseRemainderTransformArb().InverseTransform(output, squareRootOfRoot, bigModulus, bigRoot, m); - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { EXPECT_EQ(input.at(i), recOut.at(i)) << msg; } } @@ -295,10 +295,10 @@ TEST(UTTransform, CRT_CHECK_big_ring) { template void CRT_CHECK_small_ring_precomputed(const std::string& msg) { - usint m = 22; + uint32_t m = 22; typename V::Integer squareRootOfRoot(3750); typename V::Integer modulus(4621); - usint n = GetTotient(m); + uint32_t n = GetTotient(m); auto cycloPoly = GetCyclotomicPolynomial(m, modulus); typename V::Integer nttmodulus("32043581647489"); @@ -317,7 +317,7 @@ void CRT_CHECK_small_ring_precomputed(const std::string& msg) { auto inputCheck = ChineseRemainderTransformArb().InverseTransform(INPUT, squareRootOfRoot, nttmodulus, nttroot, m); - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { EXPECT_EQ(input.at(i), inputCheck.at(i)) << msg; } } @@ -329,12 +329,12 @@ TEST(UTTransform, CRT_CHECK_small_ring_precomputed) { template void CRT_CHECK_very_big_ring_precomputed(const std::string& msg) { OPENFHE_DEBUG_FLAG(false); - usint m = 8422; + uint32_t m = 8422; OPENFHE_DEBUG("1"); // find a modulus that has 2*8422 root of unity and is 120 bit long typename V::Integer modulus("619578785044668429129510602549015713"); typename V::Integer squareRootOfRoot("204851043665385327685783246012876507"); - usint n = GetTotient(m); + uint32_t n = GetTotient(m); OPENFHE_DEBUG("UT GetTotient(" << m << ")= " << n); auto cycloPoly = GetCyclotomicPolynomial(m, modulus); @@ -360,7 +360,7 @@ void CRT_CHECK_very_big_ring_precomputed(const std::string& msg) { auto inputCheck = ChineseRemainderTransformArb().InverseTransform(INPUT, squareRootOfRoot, nttmodulus, nttroot, m); OPENFHE_DEBUG("6"); - for (usint i = 0; i < n; i++) { + for (uint32_t i = 0; i < n; i++) { EXPECT_EQ(input.at(i), inputCheck.at(i)) << msg; } } diff --git a/src/core/unittest/UnitTestTrapdoor.cpp b/src/core/unittest/UnitTestTrapdoor.cpp index 5479dac15..2518acfc5 100644 --- a/src/core/unittest/UnitTestTrapdoor.cpp +++ b/src/core/unittest/UnitTestTrapdoor.cpp @@ -66,7 +66,7 @@ TEST(UTTrapdoor, randomized_round) { } TEST(UTTrapdoor, sizes) { - usint m = 16; + uint32_t m = 16; BigInteger modulus("67108913"); BigInteger rootOfUnity("61564"); float stddev = 4; @@ -74,7 +74,7 @@ TEST(UTTrapdoor, sizes) { double val = modulus.ConvertToDouble(); // TODO get the next few lines // working in a single instance. double logTwo = std::log2(val - 1.0) + 1.0; - usint k = (usint)std::floor(logTwo); // = this->m_cryptoParameters.GetModulus(); + uint32_t k = (uint32_t)std::floor(logTwo); // = this->m_cryptoParameters.GetModulus(); auto fastParams = std::make_shared(m, modulus, rootOfUnity); std::pair, RLWETrapdoorPair> trapPair = @@ -91,7 +91,7 @@ TEST(UTTrapdoor, sizes) { } TEST(UTTrapdoor, TrapDoorPairTest) { - usint m = 16; + uint32_t m = 16; BigInteger modulus("67108913"); BigInteger rootOfUnity("61564"); float stddev = 4; @@ -99,7 +99,7 @@ TEST(UTTrapdoor, TrapDoorPairTest) { double val = modulus.ConvertToDouble(); // TODO get the next few lines // working in a single instance. double logTwo = std::log2(val - 1.0) + 1.0; - usint k = (usint)std::floor(logTwo); // = this->m_cryptoParameters.GetModulus(); + uint32_t k = (uint32_t)std::floor(logTwo); // = this->m_cryptoParameters.GetModulus(); auto params = std::make_shared(m, modulus, rootOfUnity); auto zero_alloc = Poly::Allocator(params, Format::EVALUATION); @@ -129,7 +129,7 @@ TEST(UTTrapdoor, TrapDoorPairTest) { } TEST(UTTrapdoor, TrapDoorPairTestSquareMat) { - usint m = 16; + uint32_t m = 16; BigInteger modulus("67108913"); BigInteger rootOfUnity("61564"); float stddev = 4; @@ -137,7 +137,7 @@ TEST(UTTrapdoor, TrapDoorPairTestSquareMat) { double val = modulus.ConvertToDouble(); // TODO get the next few lines // working in a single instance. double logTwo = std::ceil(std::log2(val)); - usint k = (usint)std::floor(logTwo); // = this->m_cryptoParameters.GetModulus(); + uint32_t k = (uint32_t)std::floor(logTwo); // = this->m_cryptoParameters.GetModulus(); auto params = std::make_shared(m, modulus, rootOfUnity); auto zero_alloc = Poly::Allocator(params, Format::EVALUATION); @@ -166,14 +166,14 @@ TEST(UTTrapdoor, TrapDoorPairTestSquareMat) { } TEST(UTTrapdoor, GadgetTest) { - usint m = 16; + uint32_t m = 16; BigInteger modulus("67108913"); BigInteger rootOfUnity("61564"); double val = modulus.ConvertToDouble(); // TODO get the next few lines // working in a single instance. double logTwo = std::log2(val - 1.0) + 1.0; - usint k = (usint)std::floor(logTwo); // = this->m_cryptoParameters.GetModulus(); + uint32_t k = (uint32_t)std::floor(logTwo); // = this->m_cryptoParameters.GetModulus(); auto params = std::make_shared(m, modulus, rootOfUnity); auto zero_alloc = Poly::Allocator(params, Format::EVALUATION); @@ -185,7 +185,7 @@ TEST(UTTrapdoor, GadgetTest) { } TEST(UTTrapdoor, TrapDoorMultTest) { - usint m = 16; + uint32_t m = 16; BigInteger modulus("67108913"); BigInteger rootOfUnity("61564"); float stddev = 4; @@ -193,7 +193,7 @@ TEST(UTTrapdoor, TrapDoorMultTest) { double val = modulus.ConvertToDouble(); // TODO get the next few lines // working in a single instance. double logTwo = std::log2(val - 1.0) + 1.0; - usint k = (usint)std::floor(logTwo); // = this->m_cryptoParameters.GetModulus(); + uint32_t k = (uint32_t)std::floor(logTwo); // = this->m_cryptoParameters.GetModulus(); auto params = std::make_shared(m, modulus, rootOfUnity); auto zero_alloc = Poly::Allocator(params, Format::EVALUATION); @@ -220,7 +220,7 @@ TEST(UTTrapdoor, TrapDoorMultTest) { } TEST(UTTrapdoor, TrapDoorMultTestSquareMat) { - usint m = 16; + uint32_t m = 16; BigInteger modulus("67108913"); BigInteger rootOfUnity("61564"); float stddev = 4; @@ -228,7 +228,7 @@ TEST(UTTrapdoor, TrapDoorMultTestSquareMat) { double val = modulus.ConvertToDouble(); // TODO get the next few lines // working in a single instance. double logTwo = std::ceil(std::log2(val)); - usint k = (usint)std::floor(logTwo); // = this->m_cryptoParameters.GetModulus(); + uint32_t k = (uint32_t)std::floor(logTwo); // = this->m_cryptoParameters.GetModulus(); size_t d = 5; @@ -259,8 +259,8 @@ TEST(UTTrapdoor, TrapDoorMultTestSquareMat) { TEST(UTTrapdoor, TrapDoorGaussGqSampTest) { OPENFHE_DEBUG_FLAG(false); OPENFHE_DEBUG("start tests"); - usint m = 16; - usint n = m / 2; + uint32_t m = 16; + uint32_t n = m / 2; BigInteger modulus("67108913"); BigInteger rootOfUnity("61564"); // BigInteger modulus("134218081"); @@ -283,7 +283,7 @@ TEST(UTTrapdoor, TrapDoorGaussGqSampTest) { // working in a single instance. // YSP check logTwo computation double logTwo = std::log2(val - 1.0) + 1.0; - usint k = (usint)std::floor(logTwo); + uint32_t k = (uint32_t)std::floor(logTwo); Matrix zHatBBI([]() { return 0; }, k, m / 2); @@ -313,7 +313,7 @@ TEST(UTTrapdoor, TrapDoorGaussGqSampTest) { // it is not needed for the functionality exposed through the web assembly #if !defined(__EMSCRIPTEN__) && !defined(__CYGWIN__) TEST(UTTrapdoor, TrapDoorGaussSampTestDCRT) { - usint n = 16; // cyclotomic order + uint32_t n = 16; // cyclotomic order size_t kRes = 51; size_t base = 8; size_t size = 4; @@ -332,7 +332,7 @@ TEST(UTTrapdoor, TrapDoorGaussSampTestDCRT) { DCRTPoly::DugType dug; DCRTPoly u(dug, params, Format::COEFFICIENT); - usint k = size * digitCount; + uint32_t k = size * digitCount; double c = (base + 1) * SIGMA; double s = SPECTRAL_BOUND(n, k, base); @@ -361,8 +361,8 @@ TEST(UTTrapdoor, TrapDoorGaussGqSampTestBase1024) { OPENFHE_DEBUG_FLAG(false); OPENFHE_DEBUG("start tests"); - usint m = 1024; - usint n = m / 2; + uint32_t m = 1024; + uint32_t n = m / 2; BigInteger modulus("8399873"); BigInteger rootOfUnity("824894"); // BigInteger modulus("134218081"); @@ -384,11 +384,11 @@ TEST(UTTrapdoor, TrapDoorGaussGqSampTestBase1024) { // double val = modulus.ConvertToDouble(); //TODO get the next few lines // working in a single instance. YSP check logTwo computation - usint nBits = std::floor(std::log2(modulus.ConvertToDouble() - 1.0) + 1.0); - usint k = std::ceil(nBits / std::log2(base)); + uint32_t nBits = std::floor(std::log2(modulus.ConvertToDouble() - 1.0) + 1.0); + uint32_t k = std::ceil(nBits / std::log2(base)); // double logTwo = log2(val - 1.0) + 1.0; - // usint k = (usint)floor(logTwo); + // uint32_t k = (uint32_t)floor(logTwo); Matrix zHatBBI([]() { return 0; }, k, m / 2); @@ -442,8 +442,8 @@ TEST(UTTrapdoor, TrapDoorGaussGqSampTestBase1024) { TEST(UTTrapdoor, TrapDoorGaussSampTest) { OPENFHE_DEBUG_FLAG(false); OPENFHE_DEBUG("in test"); - usint m = 16; - usint n = m / 2; + uint32_t m = 16; + uint32_t n = m / 2; BigInteger modulus("67108913"); BigInteger rootOfUnity("61564"); @@ -452,7 +452,7 @@ TEST(UTTrapdoor, TrapDoorGaussSampTest) { double val = modulus.ConvertToDouble(); // TODO get the next few lines // working in a single instance. double logTwo = std::log2(val - 1.0) + 1.0; - usint k = (usint)std::floor(logTwo); // = this->m_cryptoParameters.GetModulus(); + uint32_t k = (uint32_t)std::floor(logTwo); // = this->m_cryptoParameters.GetModulus(); OPENFHE_DEBUG("k = " << k); OPENFHE_DEBUG("sigma = " << sigma); @@ -511,8 +511,8 @@ TEST(UTTrapdoor, TrapDoorGaussSampTest) { TEST(UTTrapdoor, TrapDoorGaussSampTestSquareMatrices) { OPENFHE_DEBUG_FLAG(false); OPENFHE_DEBUG("in test"); - usint m = 16; - usint n = m / 2; + uint32_t m = 16; + uint32_t n = m / 2; BigInteger modulus("67108913"); BigInteger rootOfUnity("61564"); @@ -521,7 +521,7 @@ TEST(UTTrapdoor, TrapDoorGaussSampTestSquareMatrices) { double val = modulus.ConvertToDouble(); // TODO get the next few lines // working in a single instance. double logTwo = std::ceil(std::log2(val)); - usint k = (usint)(logTwo); + uint32_t k = (uint32_t)(logTwo); auto params = std::make_shared(m, modulus, rootOfUnity); @@ -564,8 +564,8 @@ TEST(UTTrapdoor, TrapDoorGaussSampTestSquareMatrices) { #if !defined(__EMSCRIPTEN__) && !defined(__CYGWIN__) // Test of Gaussian Sampling for matrices from 2x2 to 5x5 TEST(UTTrapdoor, TrapDoorGaussSampTestSquareMatricesDCRT) { - usint m = 16; - usint n = m / 2; + uint32_t m = 16; + uint32_t n = m / 2; size_t dcrtBits = 57; size_t size = 3; double sigma = SIGMA; @@ -574,7 +574,7 @@ TEST(UTTrapdoor, TrapDoorGaussSampTestSquareMatricesDCRT) { double val = params->GetModulus().ConvertToDouble(); double logTwo = std::ceil(std::log2(val)); - usint k = (usint)(logTwo); + uint32_t k = (uint32_t)(logTwo); auto zero_alloc = DCRTPoly::Allocator(params, Format::EVALUATION); auto uniform_alloc = DCRTPoly::MakeDiscreteUniformAllocator(params, Format::EVALUATION); @@ -616,10 +616,10 @@ TEST(UTTrapdoor, TrapDoorGaussSampTestSquareMatricesDCRT) { // and makes sure no exceptions are encountered - this validates that // covariance matrices at all steps are positive definite TEST(UTTrapdoor, TrapDoorPerturbationSamplingTest) { - // usint m = 2048; - usint m = 16; - // usint m = 8192; - usint n = m / 2; + // uint32_t m = 2048; + uint32_t m = 16; + // uint32_t m = 8192; + uint32_t n = m / 2; // for m = 16 BigInteger modulus("67108913"); @@ -639,7 +639,7 @@ TEST(UTTrapdoor, TrapDoorPerturbationSamplingTest) { double val = modulus.ConvertToDouble(); // TODO get the next few lines // working in a single instance. double logTwo = std::log2(val - 1.0) + 1.0; - usint k = (usint)std::floor(logTwo); // = this->m_cryptoParameters.GetModulus(); + uint32_t k = (uint32_t)std::floor(logTwo); // = this->m_cryptoParameters.GetModulus(); // smoothing parameter // double c(2 * sqrt(log(2 * n*(1 + 1 / DG_ERROR)) / M_PI)); diff --git a/src/core/unittest/UnitTestUtils.cpp b/src/core/unittest/UnitTestUtils.cpp index 6a6150989..1dd0011b3 100644 --- a/src/core/unittest/UnitTestUtils.cpp +++ b/src/core/unittest/UnitTestUtils.cpp @@ -38,8 +38,8 @@ using namespace lbcrypto; TEST(Utilities, IsPowerOfTwo) { - std::vector powers_of_two{1, 2, 4, 8, 16, 32, 512, 1024, 2048, 4096, 16384, 32768}; - std::vector not_powers_of_two{0, 3, 5, 7, 9, 31, 33, 1025, 4095}; + std::vector powers_of_two{1, 2, 4, 8, 16, 32, 512, 1024, 2048, 4096, 16384, 32768}; + std::vector not_powers_of_two{0, 3, 5, 7, 9, 31, 33, 1025, 4095}; for (auto power_of_two : powers_of_two) { EXPECT_TRUE(IsPowerOfTwo(power_of_two)); diff --git a/src/pke/examples/advanced-ckks-bootstrapping.cpp b/src/pke/examples/advanced-ckks-bootstrapping.cpp index 4e6858d26..79b01e034 100644 --- a/src/pke/examples/advanced-ckks-bootstrapping.cpp +++ b/src/pke/examples/advanced-ckks-bootstrapping.cpp @@ -91,13 +91,13 @@ void BootstrapExample(uint32_t numSlots) { #if NATIVEINT == 128 // Currently, only FIXEDMANUAL and FIXEDAUTO modes are supported for 128-bit CKKS bootstrapping. ScalingTechnique rescaleTech = FIXEDAUTO; - usint dcrtBits = 78; - usint firstMod = 89; + uint32_t dcrtBits = 78; + uint32_t firstMod = 89; #else // All modes are supported for 64-bit CKKS bootstrapping. ScalingTechnique rescaleTech = FLEXIBLEAUTO; - usint dcrtBits = 59; - usint firstMod = 60; + uint32_t dcrtBits = 59; + uint32_t firstMod = 60; #endif parameters.SetScalingModSize(dcrtBits); @@ -129,7 +129,7 @@ void BootstrapExample(uint32_t numSlots) { * depth. */ uint32_t levelsAvailableAfterBootstrap = 10; - usint depth = levelsAvailableAfterBootstrap + FHECKKSRNS::GetBootstrapDepth(levelBudget, secretKeyDist); + uint32_t depth = levelsAvailableAfterBootstrap + FHECKKSRNS::GetBootstrapDepth(levelBudget, secretKeyDist); parameters.SetMultiplicativeDepth(depth); // Generate crypto context. @@ -142,7 +142,7 @@ void BootstrapExample(uint32_t numSlots) { cryptoContext->Enable(ADVANCEDSHE); cryptoContext->Enable(FHE); - usint ringDim = cryptoContext->GetRingDimension(); + uint32_t ringDim = cryptoContext->GetRingDimension(); std::cout << "CKKS scheme is using ring dimension " << ringDim << std::endl << std::endl; // Step 2: Precomputations for bootstrapping diff --git a/src/pke/examples/ckks-noise-flooding.cpp b/src/pke/examples/ckks-noise-flooding.cpp index 7774c54a0..96f231189 100644 --- a/src/pke/examples/ckks-noise-flooding.cpp +++ b/src/pke/examples/ckks-noise-flooding.cpp @@ -93,7 +93,7 @@ void CKKSNoiseFloodingDemo() { auto cryptoContextNoiseEstimation = GetCryptoContext(parametersNoiseEstimation); - usint ringDim = cryptoContextNoiseEstimation->GetRingDimension(); + uint32_t ringDim = cryptoContextNoiseEstimation->GetRingDimension(); std::cout << "CKKS scheme is using ring dimension " << ringDim << std::endl << std::endl; // Key Generation @@ -169,8 +169,8 @@ CryptoContext GetCryptoContext(CCParams& paramet parameters.SetRingDim(1 << 16); ScalingTechnique rescaleTech = FIXEDAUTO; - usint dcrtBits = 59; - usint firstMod = 60; + uint32_t dcrtBits = 59; + uint32_t firstMod = 60; parameters.SetScalingTechnique(rescaleTech); parameters.SetScalingModSize(dcrtBits); diff --git a/src/pke/examples/function-evaluation.cpp b/src/pke/examples/function-evaluation.cpp index 14a7347c4..9ff54a3a5 100644 --- a/src/pke/examples/function-evaluation.cpp +++ b/src/pke/examples/function-evaluation.cpp @@ -61,11 +61,11 @@ void EvalLogisticExample() { parameters.SetSecurityLevel(HEStd_NotSet); parameters.SetRingDim(1 << 10); #if NATIVEINT == 128 - usint scalingModSize = 78; - usint firstModSize = 89; + uint32_t scalingModSize = 78; + uint32_t firstModSize = 89; #else - usint scalingModSize = 50; - usint firstModSize = 60; + uint32_t scalingModSize = 50; + uint32_t firstModSize = 60; #endif parameters.SetScalingModSize(scalingModSize); parameters.SetFirstModSize(firstModSize); @@ -122,11 +122,11 @@ void EvalFunctionExample() { parameters.SetSecurityLevel(HEStd_NotSet); parameters.SetRingDim(1 << 10); #if NATIVEINT == 128 - usint scalingModSize = 78; - usint firstModSize = 89; + uint32_t scalingModSize = 78; + uint32_t firstModSize = 89; #else - usint scalingModSize = 50; - usint firstModSize = 60; + uint32_t scalingModSize = 50; + uint32_t firstModSize = 60; #endif parameters.SetScalingModSize(scalingModSize); parameters.SetFirstModSize(firstModSize); diff --git a/src/pke/examples/functional-bootstrapping-ckks.cpp b/src/pke/examples/functional-bootstrapping-ckks.cpp index 98540fb08..ad08fdcfc 100644 --- a/src/pke/examples/functional-bootstrapping-ckks.cpp +++ b/src/pke/examples/functional-bootstrapping-ckks.cpp @@ -230,13 +230,13 @@ void ArbitraryLUT(BigInteger QBFVInit, BigInteger PInput, BigInteger POutput, Bi std::cerr << "]" << std::endl; auto exact(x); - std::transform(x.begin(), x.end(), exact.begin(), [&](const int64_t& elem) { + std::transform(x.begin(), x.end(), exact.begin(), [&](int64_t elem) { return (func(elem) > POutput.ConvertToDouble() / 2.) ? func(elem) - POutput.ConvertToInt() : func(elem); }); std::transform(exact.begin(), exact.end(), computed.begin(), exact.begin(), std::minus()); std::transform(exact.begin(), exact.end(), exact.begin(), - [&](const int64_t& elem) { return (std::abs(elem)) % (POutput.ConvertToInt()); }); + [&](int64_t elem) { return (std::abs(elem)) % (POutput.ConvertToInt()); }); auto max_error_it = std::max_element(exact.begin(), exact.end()); std::cerr << "Max absolute error obtained: " << *max_error_it << std::endl << std::endl; } @@ -393,12 +393,12 @@ void MultiValueBootstrapping(BigInteger QBFVInit, BigInteger PInput, BigInteger Ciphertext ctxtAfterFBT1, ctxtAfterFBT2; auto exact(x); - std::transform(x.begin(), x.end(), exact.begin(), [&](const int64_t& elem) { + std::transform(x.begin(), x.end(), exact.begin(), [&](int64_t elem) { return (func1(elem) > POutput.ConvertToDouble() / 2.) ? func1(elem) - POutput.ConvertToInt() : func1(elem); }); auto exact2(x); - std::transform(x.begin(), x.end(), exact2.begin(), [&](const int64_t& elem) { + std::transform(x.begin(), x.end(), exact2.begin(), [&](int64_t elem) { return (func2(elem) > POutput.ConvertToDouble() / 2.) ? func2(elem) - POutput.ConvertToInt() : func2(elem); }); @@ -459,7 +459,7 @@ void MultiValueBootstrapping(BigInteger QBFVInit, BigInteger PInput, BigInteger std::transform(exact.begin(), exact.end(), computed.begin(), exact.begin(), std::minus()); std::transform(exact.begin(), exact.end(), exact.begin(), - [&](const int64_t& elem) { return (std::abs(elem)) % (POutput.ConvertToInt()); }); + [&](int64_t elem) { return (std::abs(elem)) % (POutput.ConvertToInt()); }); auto max_error_it = std::max_element(exact.begin(), exact.end()); std::cerr << "Max absolute error obtained in the first LUT: " << *max_error_it << std::endl << std::endl; @@ -473,7 +473,7 @@ void MultiValueBootstrapping(BigInteger QBFVInit, BigInteger PInput, BigInteger std::transform(exact2.begin(), exact2.end(), computed.begin(), exact2.begin(), std::minus()); std::transform(exact2.begin(), exact2.end(), exact2.begin(), - [&](const int64_t& elem) { return (std::abs(elem)) % (POutput.ConvertToInt()); }); + [&](int64_t elem) { return (std::abs(elem)) % (POutput.ConvertToInt()); }); max_error_it = std::max_element(exact2.begin(), exact2.end()); std::cerr << "Max absolute error obtained in the second LUT: " << *max_error_it << std::endl << std::endl; } @@ -514,7 +514,7 @@ void MultiPrecisionSign(BigInteger QBFVInit, BigInteger PInput, BigInteger PDigi auto exact(x); std::transform(x.begin(), x.end(), exact.begin(), - [&](const int64_t& elem) { return (elem >= PInput.ConvertToDouble() / 2.); }); + [&](int64_t elem) { return (elem >= PInput.ConvertToDouble() / 2.); }); /* 4. The case of Boolean LUTs using the first order Trigonometric Hermite Interpolation * supports an optimized implementation. @@ -691,7 +691,7 @@ void MultiPrecisionSign(BigInteger QBFVInit, BigInteger PInput, BigInteger PDigi std::transform(exact.begin(), exact.end(), computed.begin(), exact.begin(), std::minus()); std::transform(exact.begin(), exact.end(), exact.begin(), - [&](const int64_t& elem) { return (std::abs(elem)) % (pOrig.ConvertToInt()); }); + [&](int64_t elem) { return (std::abs(elem)) % (pOrig.ConvertToInt()); }); auto max_error_it = std::max_element(exact.begin(), exact.end()); std::cerr << "\nMax absolute error obtained: " << *max_error_it << std::endl << std::endl; } diff --git a/src/pke/examples/interactive-bootstrapping.cpp b/src/pke/examples/interactive-bootstrapping.cpp index 6d98ed1ae..817f36bbe 100644 --- a/src/pke/examples/interactive-bootstrapping.cpp +++ b/src/pke/examples/interactive-bootstrapping.cpp @@ -199,7 +199,7 @@ void Chebyshev(enum ScalingTechnique rescaleTech) { // Generate evalsum key part for A cc->EvalSumKeyGen(kp1.secretKey); auto evalSumKeys = - std::make_shared>>(cc->GetEvalSumKeyMap(kp1.secretKey->GetKeyTag())); + std::make_shared>>(cc->GetEvalSumKeyMap(kp1.secretKey->GetKeyTag())); std::cout << "Round 1 of key generation completed." << std::endl; diff --git a/src/pke/examples/iterative-ckks-bootstrapping-composite-scaling.cpp b/src/pke/examples/iterative-ckks-bootstrapping-composite-scaling.cpp index 80e4f8fae..1a807a789 100644 --- a/src/pke/examples/iterative-ckks-bootstrapping-composite-scaling.cpp +++ b/src/pke/examples/iterative-ckks-bootstrapping-composite-scaling.cpp @@ -88,9 +88,9 @@ void IterativeBootstrapExample() { // All modes are supported for 64-bit CKKS bootstrapping. // For this configuration, 3 words per level will be used ScalingTechnique rescaleTech = COMPOSITESCALINGAUTO; - usint dcrtBits = 61; - usint firstMod = 66; - usint registerWordSize = 27; + uint32_t dcrtBits = 61; + uint32_t firstMod = 66; + uint32_t registerWordSize = 27; parameters.SetScalingModSize(dcrtBits); parameters.SetScalingTechnique(rescaleTech); @@ -106,7 +106,7 @@ void IterativeBootstrapExample() { uint32_t levelsAvailableAfterBootstrap = 10; // Each extra iteration on top of 1 requires an extra level to be consumed. - usint depth = + uint32_t depth = levelsAvailableAfterBootstrap + FHECKKSRNS::GetBootstrapDepth(levelBudget, secretKeyDist) + (numIterations - 1); parameters.SetMultiplicativeDepth(depth); @@ -120,12 +120,12 @@ void IterativeBootstrapExample() { cryptoContext->Enable(ADVANCEDSHE); cryptoContext->Enable(FHE); - usint ringDim = cryptoContext->GetRingDimension(); + uint32_t ringDim = cryptoContext->GetRingDimension(); std::cout << "CKKS scheme is using ring dimension " << ringDim << std::endl << std::endl; const auto cryptoParamsCKKSRNS = std::dynamic_pointer_cast(cryptoContext->GetCryptoParameters()); - usint compositeDegree = cryptoParamsCKKSRNS->GetCompositeDegree(); + uint32_t compositeDegree = cryptoParamsCKKSRNS->GetCompositeDegree(); std::cout << "compositeDegree=" << cryptoParamsCKKSRNS->GetCompositeDegree() << " modBitWidth=" << static_cast(dcrtBits) / compositeDegree << " targetHWArchWordSize=" << registerWordSize << std::endl; diff --git a/src/pke/examples/linearwsum-evaluation.cpp b/src/pke/examples/linearwsum-evaluation.cpp index 2fcdee4a2..a6bae88b6 100644 --- a/src/pke/examples/linearwsum-evaluation.cpp +++ b/src/pke/examples/linearwsum-evaluation.cpp @@ -82,7 +82,7 @@ int main(int argc, char* argv[]) { std::cout << "Completed." << std::endl; std::vector> ciphertextVec; - for (usint i = 0; i < encodedLength; ++i) { + for (uint32_t i = 0; i < encodedLength; ++i) { Plaintext plaintext = cc->MakeCKKSPackedPlaintext(input[i]); ciphertextVec.push_back(cc->Encrypt(keyPair.publicKey, plaintext)); } @@ -94,9 +94,9 @@ int main(int argc, char* argv[]) { timeEvalLinearWSum = TOC(t); std::vector> unencIP; - for (usint i = 0; i < input[0].size(); ++i) { + for (uint32_t i = 0; i < input[0].size(); ++i) { std::complex x = 0; - for (usint j = 0; j < encodedLength; ++j) { + for (uint32_t j = 0; j < encodedLength; ++j) { x += input[j][i] * coefficients[j]; } unencIP.push_back(x); diff --git a/src/pke/examples/rotation.cpp b/src/pke/examples/rotation.cpp index bce6d60e3..2790883c5 100644 --- a/src/pke/examples/rotation.cpp +++ b/src/pke/examples/rotation.cpp @@ -124,7 +124,7 @@ void CKKSEvalRotate2n() { cc->Enable(KEYSWITCH); cc->Enable(LEVELEDSHE); - usint cyclOrder = cc->GetCyclotomicOrder(); + uint32_t cyclOrder = cc->GetCyclotomicOrder(); // Initialize the public key containers. KeyPair kp = cc->KeyGen(); diff --git a/src/pke/examples/scheme-switching.cpp b/src/pke/examples/scheme-switching.cpp index 2f9b9e85e..b222170cc 100644 --- a/src/pke/examples/scheme-switching.cpp +++ b/src/pke/examples/scheme-switching.cpp @@ -1489,14 +1489,14 @@ void PolyViaSchemeSwitching() { std::vector x1Rot(RotateInt(x1, 1)); std::transform(x1Rot.begin(), x1Rot.end(), x1.begin(), x1Rot.begin(), std::plus()); std::vector x1Int(slots); - std::transform(x1Rot.begin(), x1Rot.end(), x1Int.begin(), [&](const int32_t& elem) { + std::transform(x1Rot.begin(), x1Rot.end(), x1Int.begin(), [&](int32_t elem) { return static_cast(static_cast(std::round(0.25 * elem * elem)) % pLWE1); }); std::vector x2Rot(RotateInt(x2, 2)); std::transform(x2Rot.begin(), x2Rot.end(), x2.begin(), x2Rot.begin(), std::plus()); std::vector x2Int(slots); - std::transform(x2Rot.begin(), x2Rot.end(), x2Int.begin(), [&](const int32_t& elem) { + std::transform(x2Rot.begin(), x2Rot.end(), x2Int.begin(), [&](int32_t elem) { return static_cast(static_cast(std::round(0.25 * elem * elem)) % pLWE2); }); diff --git a/src/pke/examples/simple-real-numbers-serial.cpp b/src/pke/examples/simple-real-numbers-serial.cpp index ad6ffbb87..0e73ceb94 100644 --- a/src/pke/examples/simple-real-numbers-serial.cpp +++ b/src/pke/examples/simple-real-numbers-serial.cpp @@ -355,7 +355,7 @@ int main() { // Set main params const int multDepth = 5; const int scaleModSize = 40; - const usint batchSize = 32; + const uint32_t batchSize = 32; const int cryptoContextIdx = 0; const int keyPairIdx = 1; diff --git a/src/pke/examples/tckks-interactive-mp-bootstrapping-Chebyshev.cpp b/src/pke/examples/tckks-interactive-mp-bootstrapping-Chebyshev.cpp index 4ac1c5fed..ba4168dd4 100644 --- a/src/pke/examples/tckks-interactive-mp-bootstrapping-Chebyshev.cpp +++ b/src/pke/examples/tckks-interactive-mp-bootstrapping-Chebyshev.cpp @@ -116,8 +116,8 @@ void TCKKSCollectiveBoot(enum ScalingTechnique scaleTech) { * to obtain a good precision and performance tradeoff. We recommend keeping the parameters * below unless you are an FHE expert. */ - usint dcrtBits = 50; - usint firstMod = 60; + uint32_t dcrtBits = 50; + uint32_t firstMod = 60; parameters.SetScalingModSize(dcrtBits); parameters.SetScalingTechnique(scaleTech); @@ -161,15 +161,15 @@ void TCKKSCollectiveBoot(enum ScalingTechnique scaleTech) { cryptoContext->Enable(ADVANCEDSHE); cryptoContext->Enable(MULTIPARTY); - usint ringDim = cryptoContext->GetRingDimension(); + uint32_t ringDim = cryptoContext->GetRingDimension(); // This is the maximum number of slots that can be used for full packing. - usint maxNumSlots = ringDim / 2; + uint32_t maxNumSlots = ringDim / 2; std::cout << "TCKKS scheme is using ring dimension " << ringDim << std::endl; std::cout << "TCKKS scheme number of slots " << batchSize << std::endl; std::cout << "TCKKS scheme max number of slots " << maxNumSlots << std::endl; std::cout << "TCKKS example with Scaling Technique " << scaleTech << std::endl; - const usint numParties = 3; + const uint32_t numParties = 3; std::cout << "\n===========================IntMPBoot protocol parameters===========================\n"; std::cout << "num of parties: " << numParties << "\n"; @@ -196,7 +196,7 @@ void TCKKSCollectiveBoot(enum ScalingTechnique scaleTech) { // Generate evalsum key part for A cryptoContext->EvalSumKeyGen(kp1.secretKey); - auto evalSumKeys = std::make_shared>>( + auto evalSumKeys = std::make_shared>>( cryptoContext->GetEvalSumKeyMap(kp1.secretKey->GetKeyTag())); // Round 2 (party B) @@ -253,7 +253,7 @@ void TCKKSCollectiveBoot(enum ScalingTechnique scaleTech) { double b = 4; Plaintext pt1 = cryptoContext->MakeCKKSPackedPlaintext(input); - usint encodedLength = input.size(); + uint32_t encodedLength = input.size(); auto ct1 = cryptoContext->Encrypt(kp3.publicKey, pt1); diff --git a/src/pke/examples/tckks-interactive-mp-bootstrapping.cpp b/src/pke/examples/tckks-interactive-mp-bootstrapping.cpp index 076587258..345693ff9 100644 --- a/src/pke/examples/tckks-interactive-mp-bootstrapping.cpp +++ b/src/pke/examples/tckks-interactive-mp-bootstrapping.cpp @@ -50,7 +50,7 @@ using namespace lbcrypto; */ struct Party { public: - usint id; // unique party identifier starting from 0 + uint32_t id; // unique party identifier starting from 0 std::vector> sharesPair; // (h_{0,i}, h_{1,i}) = (masked decryption // share, re-encryption share) @@ -113,8 +113,8 @@ void TCKKSCollectiveBoot(enum ScalingTechnique scaleTech) { * to obtain a good precision and performance tradeoff. We recommend keeping the parameters * below unless you are an FHE expert. */ - usint dcrtBits = 50; - usint firstMod = 60; + uint32_t dcrtBits = 50; + uint32_t firstMod = 60; parameters.SetScalingModSize(dcrtBits); parameters.SetScalingTechnique(scaleTech); @@ -159,15 +159,15 @@ void TCKKSCollectiveBoot(enum ScalingTechnique scaleTech) { cryptoContext->Enable(ADVANCEDSHE); cryptoContext->Enable(MULTIPARTY); - usint ringDim = cryptoContext->GetRingDimension(); + uint32_t ringDim = cryptoContext->GetRingDimension(); // This is the maximum number of slots that can be used for full packing. - usint maxNumSlots = ringDim / 2; + uint32_t maxNumSlots = ringDim / 2; std::cout << "TCKKS scheme is using ring dimension " << ringDim << std::endl; std::cout << "TCKKS scheme number of slots " << batchSize << std::endl; std::cout << "TCKKS scheme max number of slots " << maxNumSlots << std::endl; std::cout << "TCKKS example with Scaling Technique " << scaleTech << std::endl; - const usint numParties = 3; // n: number of parties involved in the interactive protocol + const uint32_t numParties = 3; // n: number of parties involved in the interactive protocol std::cout << "\n===========================IntMPBoot protocol parameters===========================\n"; std::cout << "number of parties: " << numParties << "\n"; @@ -186,7 +186,7 @@ void TCKKSCollectiveBoot(enum ScalingTechnique scaleTech) { // Initialization - Assuming numParties (n) of parties // P0 is the leading party - for (usint i = 0; i < numParties; i++) { + for (uint32_t i = 0; i < numParties; i++) { parties[i].id = i; std::cout << "Party " << parties[i].id << " started.\n"; if (0 == i) @@ -198,7 +198,7 @@ void TCKKSCollectiveBoot(enum ScalingTechnique scaleTech) { std::cout << "Joint public key for (s_0 + s_1 + ... + s_n) is generated..." << std::endl; // Assert everything is good - for (usint i = 0; i < numParties; i++) { + for (uint32_t i = 0; i < numParties; i++) { if (!parties[i].kpShard.good()) { std::cout << "Key generation failed for party " << i << "!" << std::endl; exit(1); @@ -207,7 +207,7 @@ void TCKKSCollectiveBoot(enum ScalingTechnique scaleTech) { // Generate the collective public key std::vector> secretKeys; - for (usint i = 0; i < numParties; i++) { + for (uint32_t i = 0; i < numParties; i++) { secretKeys.push_back(parties[i].kpShard.secretKey); } kpMultiparty = cryptoContext->MultipartyKeyGen(secretKeys); // This is the same core key generation operation. @@ -239,7 +239,7 @@ void TCKKSCollectiveBoot(enum ScalingTechnique scaleTech) { // c1 for IntMPBootDecrypt auto c1 = inCtxt->Clone(); c1->GetElements().erase(c1->GetElements().begin()); - for (usint i = 0; i < numParties; i++) { + for (uint32_t i = 0; i < numParties; i++) { std::cout << "Party " << i << " started its part in the Collective Bootstrapping Protocol\n"; parties[i].sharesPair = cryptoContext->IntMPBootDecrypt(parties[i].kpShard.secretKey, c1, a); sharesPairVec.push_back(parties[i].sharesPair); @@ -262,7 +262,7 @@ void TCKKSCollectiveBoot(enum ScalingTechnique scaleTech) { std::cout << "Party 0 started its part in the collective decryption protocol\n"; partialCiphertextVec.push_back(cryptoContext->MultipartyDecryptLead({outCtxt}, parties[0].kpShard.secretKey)[0]); - for (usint i = 1; i < numParties; i++) { + for (uint32_t i = 1; i < numParties; i++) { std::cout << "Party " << i << " started its part in the collective decryption protocol\n"; partialCiphertextVec.push_back( cryptoContext->MultipartyDecryptMain({outCtxt}, parties[i].kpShard.secretKey)[0]); diff --git a/src/pke/examples/threshold-fhe-5p.cpp b/src/pke/examples/threshold-fhe-5p.cpp index 255803b27..3088d0c2b 100644 --- a/src/pke/examples/threshold-fhe-5p.cpp +++ b/src/pke/examples/threshold-fhe-5p.cpp @@ -38,7 +38,7 @@ using namespace lbcrypto; void RunBFVrns(); -void EvalNoiseBFV(PrivateKey privateKey, ConstCiphertext ciphertext, Plaintext ptxt, usint ptm, +void EvalNoiseBFV(PrivateKey privateKey, ConstCiphertext ciphertext, Plaintext ptxt, uint32_t ptm, double& noise, double& logQ, EncryptionTechnique encMethod); int main(int argc, char* argv[]) { @@ -54,10 +54,10 @@ void RunBFVrns() { double sigma = 3.2; lbcrypto::SecurityLevel securityLevel = lbcrypto::SecurityLevel::HEStd_128_classic; - usint batchSize = 16; - usint multDepth = 4; - usint digitSize = 30; - usint dcrtBits = 60; + uint32_t batchSize = 16; + uint32_t multDepth = 4; + uint32_t digitSize = 30; + uint32_t dcrtBits = 60; lbcrypto::CCParams parameters; @@ -154,7 +154,7 @@ void RunBFVrns() { // Generate evalsum key part for A cc->EvalSumKeyGen(kp1.secretKey); auto evalSumKeys = - std::make_shared>>(cc->GetEvalSumKeyMap(kp1.secretKey->GetKeyTag())); + std::make_shared>>(cc->GetEvalSumKeyMap(kp1.secretKey->GetKeyTag())); auto evalSumKeysB = cc->MultiEvalSumKeyGen(kp2.secretKey, evalSumKeys, kp2.publicKey->GetKeyTag()); diff --git a/src/pke/examples/threshold-fhe.cpp b/src/pke/examples/threshold-fhe.cpp index 1901e649d..8bad9ab32 100644 --- a/src/pke/examples/threshold-fhe.cpp +++ b/src/pke/examples/threshold-fhe.cpp @@ -201,7 +201,7 @@ void RunBGVrnsAdditive() { } void RunBFVrns() { - usint batchSize = 16; + uint32_t batchSize = 16; CCParams parameters; parameters.SetPlaintextModulus(65537); @@ -253,7 +253,7 @@ void RunBFVrns() { // Generate evalsum key part for A cc->EvalSumKeyGen(kp1.secretKey); auto evalSumKeys = - std::make_shared>>(cc->GetEvalSumKeyMap(kp1.secretKey->GetKeyTag())); + std::make_shared>>(cc->GetEvalSumKeyMap(kp1.secretKey->GetKeyTag())); std::cout << "Round 1 of key generation completed." << std::endl; @@ -417,7 +417,7 @@ void RunBFVrns() { } void RunCKKS() { - usint batchSize = 16; + uint32_t batchSize = 16; CCParams parameters; parameters.SetMultiplicativeDepth(3); @@ -466,7 +466,7 @@ void RunCKKS() { // Generate evalsum key part for A cc->EvalSumKeyGen(kp1.secretKey); auto evalSumKeys = - std::make_shared>>(cc->GetEvalSumKeyMap(kp1.secretKey->GetKeyTag())); + std::make_shared>>(cc->GetEvalSumKeyMap(kp1.secretKey->GetKeyTag())); std::cout << "Round 1 of key generation completed." << std::endl; diff --git a/src/pke/extras/bfv-encode-vs-ptxt-ctxt-benchmark.cpp.cpp b/src/pke/extras/bfv-encode-vs-ptxt-ctxt-benchmark.cpp.cpp index 22582e6e2..648775a6d 100644 --- a/src/pke/extras/bfv-encode-vs-ptxt-ctxt-benchmark.cpp.cpp +++ b/src/pke/extras/bfv-encode-vs-ptxt-ctxt-benchmark.cpp.cpp @@ -58,7 +58,7 @@ int main() { std::cout << "Element parameters: \n" << *cryptoContext->GetElementParams() << "\n"; - usint ringDim = cryptoContext->GetRingDimension(); + uint32_t ringDim = cryptoContext->GetRingDimension(); std::cout << "BFVrns scheme is using ring dimension " << ringDim << std::endl << std::endl; // Enable features that you wish to use diff --git a/src/pke/extras/bfv-mult-bug.cpp b/src/pke/extras/bfv-mult-bug.cpp index 5eb864784..a5e25edab 100644 --- a/src/pke/extras/bfv-mult-bug.cpp +++ b/src/pke/extras/bfv-mult-bug.cpp @@ -37,7 +37,7 @@ using namespace lbcrypto; -void EvalNoiseBFV(PrivateKey privateKey, ConstCiphertext ciphertext, Plaintext ptxt, usint ptm, +void EvalNoiseBFV(PrivateKey privateKey, ConstCiphertext ciphertext, Plaintext ptxt, uint32_t ptm, double& noise, double& logQ); int main() { @@ -108,7 +108,7 @@ int main() { return 0; } -void EvalNoiseBFV(PrivateKey privateKey, ConstCiphertext ciphertext, Plaintext ptxt, usint ptm, +void EvalNoiseBFV(PrivateKey privateKey, ConstCiphertext ciphertext, Plaintext ptxt, uint32_t ptm, double& noise, double& logQ) { const auto cryptoParams = std::static_pointer_cast(privateKey->GetCryptoParameters()); @@ -156,7 +156,7 @@ void EvalNoiseBFV(PrivateKey privateKey, ConstCiphertext cip noise = (std::log2(res.Norm())); logQ = 0; - for (usint i = 0; i < sizeQ; i++) { + for (uint32_t i = 0; i < sizeQ; i++) { double logqi = std::log2(cryptoParams->GetElementParams()->GetParams()[i]->GetModulus().ConvertToInt()); logQ += logqi; } diff --git a/src/pke/extras/ckks-bootstrap.cpp b/src/pke/extras/ckks-bootstrap.cpp index 4403dd959..562f15a03 100644 --- a/src/pke/extras/ckks-bootstrap.cpp +++ b/src/pke/extras/ckks-bootstrap.cpp @@ -87,16 +87,16 @@ void BootstrapExample(SecretKeyDist secretKeyDist, uint32_t n, uint32_t slots, u #if NATIVEINT == 128 ScalingTechnique rescaleTech = FIXEDMANUAL; - usint dcrtBits = 78; - usint firstMod = 89; /*firstMod*/ + uint32_t dcrtBits = 78; + uint32_t firstMod = 89; /*firstMod*/ #else ScalingTechnique rescaleTech = FLEXIBLEAUTO; - usint dcrtBits = 59; - usint firstMod = 60; /*firstMod*/ + uint32_t dcrtBits = 59; + uint32_t firstMod = 60; /*firstMod*/ #endif // computes how many levels are needed for - usint depth = levelsRemaining + FHECKKSRNS::GetBootstrapDepth(9, levelBudget1, secretKeyDist); + uint32_t depth = levelsRemaining + FHECKKSRNS::GetBootstrapDepth(9, levelBudget1, secretKeyDist); CCParams parameters; parameters.SetMultiplicativeDepth(depth); @@ -255,16 +255,16 @@ void BootstrapExampleClean(SecretKeyDist secretKeyDist, uint32_t n, uint32_t slo #if NATIVEINT == 128 ScalingTechnique rescaleTech = FIXEDMANUAL; - usint dcrtBits = 78; - usint firstMod = 89; /*firstMod*/ + uint32_t dcrtBits = 78; + uint32_t firstMod = 89; /*firstMod*/ #else ScalingTechnique rescaleTech = FLEXIBLEAUTO; - usint dcrtBits = 59; - usint firstMod = 60; /*firstMod*/ + uint32_t dcrtBits = 59; + uint32_t firstMod = 60; /*firstMod*/ #endif // computes how many levels are needed for - usint depth = levelsRemaining + FHECKKSRNS::GetBootstrapDepth(9, levelBudget, secretKeyDist); + uint32_t depth = levelsRemaining + FHECKKSRNS::GetBootstrapDepth(9, levelBudget, secretKeyDist); CCParams parameters; parameters.SetMultiplicativeDepth(depth); diff --git a/src/pke/include/scheme/bfvrns/bfvrns-cryptoparameters.h b/src/pke/include/scheme/bfvrns/bfvrns-cryptoparameters.h index ed074d2ec..1c792e83a 100644 --- a/src/pke/include/scheme/bfvrns/bfvrns-cryptoparameters.h +++ b/src/pke/include/scheme/bfvrns/bfvrns-cryptoparameters.h @@ -55,7 +55,7 @@ class CryptoParametersBFVRNS : public CryptoParametersRNS { CryptoParametersBFVRNS(std::shared_ptr params, const PlaintextModulus& plaintextModulus, float distributionParameter, float assuranceMeasure, SecurityLevel securityLevel, - usint digitSize, SecretKeyDist secretKeyDist, int maxRelinSkDeg = 2, + uint32_t digitSize, SecretKeyDist secretKeyDist, int maxRelinSkDeg = 2, KeySwitchTechnique ksTech = BV, ScalingTechnique scalTech = FIXEDMANUAL, EncryptionTechnique encTech = STANDARD, MultiplicationTechnique multTech = HPS, MultipartyMode multipartyMode = FIXED_NOISE_MULTIPARTY) @@ -64,7 +64,7 @@ class CryptoParametersBFVRNS : public CryptoParametersRNS { multipartyMode) {} CryptoParametersBFVRNS(std::shared_ptr params, EncodingParams encodingParams, float distributionParameter, - float assuranceMeasure, SecurityLevel securityLevel, usint digitSize, + float assuranceMeasure, SecurityLevel securityLevel, uint32_t digitSize, SecretKeyDist secretKeyDist, int maxRelinSkDeg = 2, KeySwitchTechnique ksTech = BV, ScalingTechnique scalTech = FIXEDMANUAL, EncryptionTechnique encTech = STANDARD, MultiplicationTechnique multTech = HPS, ProxyReEncryptionMode PREMode = NOT_SET, diff --git a/src/pke/include/scheme/bgvrns/bgvrns-cryptoparameters.h b/src/pke/include/scheme/bgvrns/bgvrns-cryptoparameters.h index d4f87b8b9..deaea25e4 100644 --- a/src/pke/include/scheme/bgvrns/bgvrns-cryptoparameters.h +++ b/src/pke/include/scheme/bgvrns/bgvrns-cryptoparameters.h @@ -55,7 +55,7 @@ class CryptoParametersBGVRNS : public CryptoParametersRNS { CryptoParametersBGVRNS(std::shared_ptr params, const PlaintextModulus& plaintextModulus, float distributionParameter, float assuranceMeasure, SecurityLevel securityLevel, - usint digitSize, SecretKeyDist secretKeyDist, int maxRelinSkDeg = 2, + uint32_t digitSize, SecretKeyDist secretKeyDist, int maxRelinSkDeg = 2, KeySwitchTechnique ksTech = BV, ScalingTechnique scalTech = FIXEDMANUAL, EncryptionTechnique encTech = STANDARD, MultiplicationTechnique multTech = HPS, MultipartyMode multipartyMode = FIXED_NOISE_MULTIPARTY) @@ -64,7 +64,7 @@ class CryptoParametersBGVRNS : public CryptoParametersRNS { multipartyMode) {} CryptoParametersBGVRNS(std::shared_ptr params, EncodingParams encodingParams, float distributionParameter, - float assuranceMeasure, SecurityLevel securityLevel, usint digitSize, + float assuranceMeasure, SecurityLevel securityLevel, uint32_t digitSize, SecretKeyDist secretKeyDist, int maxRelinSkDeg = 2, KeySwitchTechnique ksTech = BV, ScalingTechnique scalTech = FIXEDMANUAL, EncryptionTechnique encTech = STANDARD, MultiplicationTechnique multTech = HPS, ProxyReEncryptionMode PREMode = NOT_SET, diff --git a/src/pke/include/scheme/ckksrns/gen-cryptocontext-ckksrns-internal.h b/src/pke/include/scheme/ckksrns/gen-cryptocontext-ckksrns-internal.h index 2291bb751..58eeca866 100644 --- a/src/pke/include/scheme/ckksrns/gen-cryptocontext-ckksrns-internal.h +++ b/src/pke/include/scheme/ckksrns/gen-cryptocontext-ckksrns-internal.h @@ -67,8 +67,8 @@ typename ContextGeneratorType::ContextType genCryptoContextCKKSRNSInternal( auto ep = std::make_shared(); - usint scalingModSize = parameters.GetScalingModSize(); - usint firstModSize = parameters.GetFirstModSize(); + uint32_t scalingModSize = parameters.GetScalingModSize(); + uint32_t firstModSize = parameters.GetFirstModSize(); double floodingNoiseStd = 0; if (parameters.GetDecryptionNoiseMode() == NOISE_FLOODING_DECRYPT && parameters.GetExecutionMode() == EXEC_EVALUATION) { diff --git a/src/pke/include/schemebase/base-multiparty.h b/src/pke/include/schemebase/base-multiparty.h index 4f373d863..ca62cfe42 100644 --- a/src/pke/include/schemebase/base-multiparty.h +++ b/src/pke/include/schemebase/base-multiparty.h @@ -146,9 +146,9 @@ class MultipartyBase { * @param &indexVec a vector of automorphism indices. * @return a dictionary with new joined automorphism keys. */ - virtual std::shared_ptr>> MultiEvalAutomorphismKeyGen( - const PrivateKey privateKey, const std::shared_ptr>> evalKeyMap, - const std::vector& indexVec) const; + virtual std::shared_ptr>> MultiEvalAutomorphismKeyGen( + const PrivateKey privateKey, const std::shared_ptr>> evalKeyMap, + const std::vector& indexVec) const; /** * Threshold FHE: Generates evaluation keys for a list of indices for a @@ -160,8 +160,8 @@ class MultipartyBase { * @param indexVec list of indices to be computed * @return returns the joined evaluation keys */ - virtual std::shared_ptr>> MultiEvalAtIndexKeyGen( - const PrivateKey privateKey, const std::shared_ptr>> evalKeyMap, + virtual std::shared_ptr>> MultiEvalAtIndexKeyGen( + const PrivateKey privateKey, const std::shared_ptr>> evalKeyMap, const std::vector& indexVec) const; /** @@ -173,9 +173,9 @@ class MultipartyBase { * @param evalKeyMap a dictionary with prior joined summation keys. * @return new joined summation keys. */ - virtual std::shared_ptr>> MultiEvalSumKeyGen( + virtual std::shared_ptr>> MultiEvalSumKeyGen( const PrivateKey privateKey, - const std::shared_ptr>> evalKeyMap) const; + const std::shared_ptr>> evalKeyMap) const; // MULTIPARTY PKE @@ -268,9 +268,9 @@ class MultipartyBase { * @param evalKeyMap2 second automorphism key set. * @return the new joined key set for summation. */ - virtual std::shared_ptr>> MultiAddEvalAutomorphismKeys( - const std::shared_ptr>> evalKeyMap1, - const std::shared_ptr>> evalKeyMap2) const; + virtual std::shared_ptr>> MultiAddEvalAutomorphismKeys( + const std::shared_ptr>> evalKeyMap1, + const std::shared_ptr>> evalKeyMap2) const; /** * Threshold FHE: Adds two prior evaluation key sets for summation @@ -279,9 +279,9 @@ class MultipartyBase { * @param evalKeyMap2 second summation key set. * @return the new joined key set for summation. */ - virtual std::shared_ptr>> MultiAddEvalSumKeys( - const std::shared_ptr>> evalKeyMap1, - const std::shared_ptr>> evalKeyMap2) const; + virtual std::shared_ptr>> MultiAddEvalSumKeys( + const std::shared_ptr>> evalKeyMap1, + const std::shared_ptr>> evalKeyMap2) const; /** * Prepare a ciphertext for interactive bootstraping. diff --git a/src/pke/lib/scheme/bfvrns/bfvrns-multiparty.cpp b/src/pke/lib/scheme/bfvrns/bfvrns-multiparty.cpp index 3a94dd551..05a060ae3 100644 --- a/src/pke/lib/scheme/bfvrns/bfvrns-multiparty.cpp +++ b/src/pke/lib/scheme/bfvrns/bfvrns-multiparty.cpp @@ -124,8 +124,8 @@ KeyPair MultipartyBFVRNS::MultipartyKeyGen(CryptoContext cc, // When PRE is not used, a joint key is computed DCRTPoly b = fresh ? (ns * e - a * s) : (ns * e - a * s + pk[0]); - usint sizeQ = elementParams->GetParams().size(); - usint sizePK = paramsPK->GetParams().size(); + uint32_t sizeQ = elementParams->GetParams().size(); + uint32_t sizePK = paramsPK->GetParams().size(); if (sizePK > sizeQ) { s.DropLastElements(sizePK - sizeQ); } diff --git a/src/pke/lib/scheme/bfvrns/bfvrns-pke.cpp b/src/pke/lib/scheme/bfvrns/bfvrns-pke.cpp index e57b69dd8..48253b87c 100644 --- a/src/pke/lib/scheme/bfvrns/bfvrns-pke.cpp +++ b/src/pke/lib/scheme/bfvrns/bfvrns-pke.cpp @@ -83,8 +83,8 @@ KeyPair PKEBFVRNS::KeyGenInternal(CryptoContext cc, bool mak DCRTPoly e(dgg, paramsPK, Format::EVALUATION); DCRTPoly b(ns * e - a * s); - usint sizeQ = elementParams->GetParams().size(); - usint sizePK = paramsPK->GetParams().size(); + uint32_t sizeQ = elementParams->GetParams().size(); + uint32_t sizePK = paramsPK->GetParams().size(); if (sizePK > sizeQ) { s.DropLastElements(sizePK - sizeQ); } diff --git a/src/pke/lib/scheme/bgvrns/bgvrns-cryptoparameters.cpp b/src/pke/lib/scheme/bgvrns/bgvrns-cryptoparameters.cpp index b78e3cea4..053d8d783 100644 --- a/src/pke/lib/scheme/bgvrns/bgvrns-cryptoparameters.cpp +++ b/src/pke/lib/scheme/bgvrns/bgvrns-cryptoparameters.cpp @@ -68,7 +68,7 @@ void CryptoParametersBGVRNS::PrecomputeCRTTables(KeySwitchTechnique ksTech, Scal // Pre-compute values [t^{-1}]_{q_i}, precomputations for [t]_{q_i} m_tInvModq.resize(sizeQ); m_tInvModqPrecon.resize(sizeQ); - for (usint i = 0; i < sizeQ; i++) { + for (uint32_t i = 0; i < sizeQ; i++) { m_tInvModq[i] = t.ModInverse(moduliQ[i]); m_tInvModqPrecon[i] = m_tInvModq[i].PrepModMulConst(moduliQ[i]); } @@ -76,7 +76,7 @@ void CryptoParametersBGVRNS::PrecomputeCRTTables(KeySwitchTechnique ksTech, Scal // Pre-compute values [t^{-1}]_{p_i}, precomputations for [t]_{q_i} m_tInvModp.resize(sizeP); m_tInvModpPrecon.resize(sizeP); - for (usint j = 0; j < sizeP; j++) { + for (uint32_t j = 0; j < sizeP; j++) { m_tInvModp[j] = t.ModInverse(moduliP[j]); m_tInvModpPrecon[j] = m_tInvModp[j].PrepModMulConst(moduliP[j]); } @@ -87,14 +87,14 @@ void CryptoParametersBGVRNS::PrecomputeCRTTables(KeySwitchTechnique ksTech, Scal m_tModqPrecon.resize(sizeQ); m_qlInvModq.resize(sizeQ); m_qlInvModqPrecon.resize(sizeQ); - for (usint i = 0; i < sizeQ; i++) { + for (uint32_t i = 0; i < sizeQ; i++) { m_negtInvModq[i] = moduliQ[i] - t.ModInverse(moduliQ[i]); m_negtInvModqPrecon[i] = m_negtInvModq[i].PrepModMulConst(moduliQ[i]); NativeInteger tModQi = t.Mod(moduliQ[i]); m_tModqPrecon[i] = tModQi.PrepModMulConst(moduliQ[i]); m_qlInvModq[i].resize(i); m_qlInvModqPrecon[i].resize(i); - for (usint j = 0; j < i; ++j) { + for (uint32_t j = 0; j < i; ++j) { m_qlInvModq[i][j] = moduliQ[i].ModInverse(moduliQ[j]); m_qlInvModqPrecon[i][j] = m_qlInvModq[i][j].PrepModMulConst(moduliQ[j]); } @@ -129,7 +129,7 @@ void CryptoParametersBGVRNS::PrecomputeCRTTables(KeySwitchTechnique ksTech, Scal // Moduli mod t m_qModt.resize(sizeQ); - for (usint i = 0; i < sizeQ; i++) { + for (uint32_t i = 0; i < sizeQ; i++) { m_qModt[i] = moduliQ[i].Mod(t); } } @@ -145,9 +145,9 @@ void CryptoParametersBGVRNS::PrecomputeCRTTables(KeySwitchTechnique ksTech, Scal uint64_t CryptoParametersBGVRNS::FindAuxPrimeStep() const { size_t n = GetElementParams()->GetRingDimension(); - usint plaintextModulus = GetPlaintextModulus(); - usint cyclOrder = 2 * n; - usint pow2ptm = 1; + uint32_t plaintextModulus = GetPlaintextModulus(); + uint32_t cyclOrder = 2 * n; + uint32_t pow2ptm = 1; // The largest power of 2 dividing ptm // Check whether it is larger than cyclOrder or not diff --git a/src/pke/lib/scheme/bgvrns/bgvrns-pke.cpp b/src/pke/lib/scheme/bgvrns/bgvrns-pke.cpp index 82c954838..941068bd4 100644 --- a/src/pke/lib/scheme/bgvrns/bgvrns-pke.cpp +++ b/src/pke/lib/scheme/bgvrns/bgvrns-pke.cpp @@ -73,7 +73,7 @@ DecryptResult PKEBGVRNS::Decrypt(ConstCiphertext ciphertext, const Pri std::vector ct(cv); if (sizeQl > 0) { for (size_t j = sizeQl - 1; j > 0; j--) { - for (usint i = 0; i < ct.size(); i++) { + for (uint32_t i = 0; i < ct.size(); i++) { ct[i].ModReduce(cryptoParams->GetPlaintextModulus(), cryptoParams->GettModqPrecon(), cryptoParams->GetNegtInvModq(j), cryptoParams->GetNegtInvModqPrecon(j), cryptoParams->GetqlInvModq(j), cryptoParams->GetqlInvModqPrecon(j)); diff --git a/src/pke/lib/scheme/ckksrns/ckksrns-cryptoparameters.cpp b/src/pke/lib/scheme/ckksrns/ckksrns-cryptoparameters.cpp index 712e218ed..5ed391450 100644 --- a/src/pke/lib/scheme/ckksrns/ckksrns-cryptoparameters.cpp +++ b/src/pke/lib/scheme/ckksrns/ckksrns-cryptoparameters.cpp @@ -75,7 +75,7 @@ void CryptoParametersCKKSRNS::PrecomputeCRTTables(KeySwitchTechnique ksTech, Sca m_qlInvModqPrecon[k].resize(l); BigInteger QlInvModql = modulusQ.ModInverse(moduliQ[l]); BigInteger result = (QlInvModql * modulusQ) / BigInteger(moduliQ[l]); - for (usint i = 0; i < l; i++) { + for (uint32_t i = 0; i < l; i++) { m_QlQlInvModqlDivqlModq[k][i] = result.Mod(moduliQ[i]).ConvertToInt(); m_QlQlInvModqlDivqlModqPrecon[k][i] = m_QlQlInvModqlDivqlModq[k][i].PrepModMulConst(moduliQ[i]); m_qlInvModq[k][i] = moduliQ[l].ModInverse(moduliQ[i]); diff --git a/src/pke/lib/scheme/gen-cryptocontext-params-impl.cpp b/src/pke/lib/scheme/gen-cryptocontext-params-impl.cpp index a68c3923e..1a93249db 100644 --- a/src/pke/lib/scheme/gen-cryptocontext-params-impl.cpp +++ b/src/pke/lib/scheme/gen-cryptocontext-params-impl.cpp @@ -111,41 +111,41 @@ Params::Params(const std::vector& vals) { if (!(++it)->empty()) ptModulus = static_cast(std::stoul(*it)); if (!(++it)->empty()) - digitSize = static_cast(std::stoul(*it)); + digitSize = static_cast(std::stoul(*it)); if (!(++it)->empty()) standardDeviation = static_cast(std::stof(*it)); if (!(++it)->empty()) secretKeyDist = convertToSecretKeyDist(*it); if (!(++it)->empty()) - maxRelinSkDeg = static_cast(std::stoul(*it)); + maxRelinSkDeg = static_cast(std::stoul(*it)); if (!(++it)->empty()) ksTech = convertToKeySwitchTechnique(*it); if (!(++it)->empty()) scalTech = convertToScalingTechnique(*it); if (!(++it)->empty()) - firstModSize = static_cast(std::stoul(*it)); + firstModSize = static_cast(std::stoul(*it)); if (!(++it)->empty()) - batchSize = static_cast(std::stoul(*it)); + batchSize = static_cast(std::stoul(*it)); if (!(++it)->empty()) - numLargeDigits = static_cast(std::stoul(*it)); + numLargeDigits = static_cast(std::stoul(*it)); if (!(++it)->empty()) - multiplicativeDepth = static_cast(std::stoul(*it)); + multiplicativeDepth = static_cast(std::stoul(*it)); if (!(++it)->empty()) - scalingModSize = static_cast(std::stoul(*it)); + scalingModSize = static_cast(std::stoul(*it)); if (!(++it)->empty()) securityLevel = convertToSecurityLevel(*it); if (!(++it)->empty()) - ringDim = static_cast(std::stoul(*it)); + ringDim = static_cast(std::stoul(*it)); if (!(++it)->empty()) - evalAddCount = static_cast(std::stoul(*it)); + evalAddCount = static_cast(std::stoul(*it)); if (!(++it)->empty()) - keySwitchCount = static_cast(std::stoul(*it)); + keySwitchCount = static_cast(std::stoul(*it)); if (!(++it)->empty()) encryptionTechnique = convertToEncryptionTechnique(*it); if (!(++it)->empty()) multiplicationTechnique = convertToMultiplicationTechnique(*it); if (!(++it)->empty()) - PRENumHops = static_cast(std::stoul(*it)); + PRENumHops = static_cast(std::stoul(*it)); if (!(++it)->empty()) PREMode = convertToProxyReEncryptionMode(*it); if (!(++it)->empty()) @@ -159,17 +159,17 @@ Params::Params(const std::vector& vals) { if (!(++it)->empty()) desiredPrecision = std::stod(*it); if (!(++it)->empty()) - statisticalSecurity = static_cast(std::stoul(*it)); + statisticalSecurity = static_cast(std::stoul(*it)); if (!(++it)->empty()) - numAdversarialQueries = static_cast(std::stoul(*it)); + numAdversarialQueries = static_cast(std::stoul(*it)); if (!(++it)->empty()) - thresholdNumOfParties = static_cast(std::stoul(*it)); + thresholdNumOfParties = static_cast(std::stoul(*it)); if (!(++it)->empty()) interactiveBootCompressionLevel = convertToCompressionLevel(*it); if (!(++it)->empty()) - compositeDegree = static_cast(std::stoul(*it)); + compositeDegree = static_cast(std::stoul(*it)); if (!(++it)->empty()) - registerWordSize = static_cast(std::stoul(*it)); + registerWordSize = static_cast(std::stoul(*it)); if (!(++it)->empty()) ckksDataType = convertToCKKSDataType(*it); } diff --git a/src/pke/lib/scheme/gen-cryptocontext-params-validation.cpp b/src/pke/lib/scheme/gen-cryptocontext-params-validation.cpp index 32fc95c17..717b2088c 100644 --- a/src/pke/lib/scheme/gen-cryptocontext-params-validation.cpp +++ b/src/pke/lib/scheme/gen-cryptocontext-params-validation.cpp @@ -179,7 +179,7 @@ void validateParametersForCryptocontext(const Params& parameters) { } } //==================================================================================================================== - constexpr usint maxMultiplicativeDepthValue = 1000; + constexpr uint32_t maxMultiplicativeDepthValue = 1000; if (parameters.GetMultiplicativeDepth() > maxMultiplicativeDepthValue) { std::string errorMsg(std::string("The provided multiplicative depth [") + std::to_string(parameters.GetMultiplicativeDepth()) + diff --git a/src/pke/lib/schemebase/base-advancedshe.cpp b/src/pke/lib/schemebase/base-advancedshe.cpp index 9e2671538..f97795674 100644 --- a/src/pke/lib/schemebase/base-advancedshe.cpp +++ b/src/pke/lib/schemebase/base-advancedshe.cpp @@ -130,7 +130,7 @@ Ciphertext AdvancedSHEBase::AddRandomNoise(ConstCiphertextGetEncodingParams(); const auto elementParams = cryptoParams->GetElementParams(); - usint n = elementParams->GetRingDimension(); + uint32_t n = elementParams->GetRingDimension(); auto cc = ciphertext->GetCryptoContext(); @@ -142,7 +142,7 @@ Ciphertext AdvancedSHEBase::AddRandomNoise(ConstCiphertext AdvancedSHEBase::AddRandomNoise(ConstCiphertext AdvancedSHEBase::AddRandomNoise(ConstCiphertext -std::shared_ptr>> AdvancedSHEBase::EvalSumKeyGen( +std::shared_ptr>> AdvancedSHEBase::EvalSumKeyGen( const PrivateKey privateKey) const { if (!privateKey) OPENFHE_THROW("Input private key is nullptr"); @@ -186,14 +186,14 @@ std::shared_ptr>> AdvancedSHEBase::Eva } template -std::shared_ptr>> AdvancedSHEBase::EvalSumRowsKeyGen( - const PrivateKey privateKey, usint rowSize, usint subringDim, std::vector& indices) const { +std::shared_ptr>> AdvancedSHEBase::EvalSumRowsKeyGen( + const PrivateKey privateKey, uint32_t rowSize, uint32_t subringDim, std::vector& indices) const { auto cc = privateKey->GetCryptoContext(); if (!isCKKS(cc->getSchemeId())) OPENFHE_THROW("Matrix summation of row-vectors is only supported for CKKSPackedEncoding."); - usint m = + uint32_t m = (subringDim == 0) ? privateKey->GetCryptoParameters()->GetElementParams()->GetCyclotomicOrder() : subringDim; if (!IsPowerOfTwo(m)) @@ -208,19 +208,19 @@ std::shared_ptr>> AdvancedSHEBase::Eva } template -std::shared_ptr>> AdvancedSHEBase::EvalSumColsKeyGen( - const PrivateKey privateKey, std::vector& indices) const { +std::shared_ptr>> AdvancedSHEBase::EvalSumColsKeyGen( + const PrivateKey privateKey, std::vector& indices) const { auto cc = privateKey->GetCryptoContext(); if (!isCKKS(cc->getSchemeId())) OPENFHE_THROW("Matrix summation of column-vectors is only supported for CKKSPackedEncoding."); const auto cryptoParams = privateKey->GetCryptoParameters(); - usint M = cryptoParams->GetElementParams()->GetCyclotomicOrder(); + uint32_t M = cryptoParams->GetElementParams()->GetCyclotomicOrder(); if (!IsPowerOfTwo(M)) OPENFHE_THROW("Matrix summation of column-vectors is not supported for arbitrary cyclotomics."); - usint batchSize = cryptoParams->GetEncodingParams()->GetBatchSize(); + uint32_t batchSize = cryptoParams->GetEncodingParams()->GetBatchSize(); // get indices for EvalSumCols() and merge them with the indices for EvalSum() std::set evalSumColsIndices = GenerateIndices2nComplexCols(batchSize, M); @@ -234,8 +234,8 @@ std::shared_ptr>> AdvancedSHEBase::Eva } template -Ciphertext AdvancedSHEBase::EvalSum(ConstCiphertext ciphertext, usint batchSize, - const std::map>& evalKeyMap) const { +Ciphertext AdvancedSHEBase::EvalSum(ConstCiphertext ciphertext, uint32_t batchSize, + const std::map>& evalKeyMap) const { const auto cryptoParams = ciphertext->GetCryptoParameters(); const auto encodingParams = cryptoParams->GetEncodingParams(); @@ -244,7 +244,7 @@ Ciphertext AdvancedSHEBase::EvalSum(ConstCiphertext c "Packed encoding parameters 'batch size' is not set; " "Please check the EncodingParams passed to the crypto context."); - usint m = cryptoParams->GetElementParams()->GetCyclotomicOrder(); + uint32_t m = cryptoParams->GetElementParams()->GetCyclotomicOrder(); Ciphertext newCiphertext = ciphertext->Clone(); @@ -264,7 +264,7 @@ Ciphertext AdvancedSHEBase::EvalSum(ConstCiphertext c else { auto algo = ciphertext->GetCryptoContext()->GetScheme(); - usint g = encodingParams->GetPlaintextGenerator(); + uint32_t g = encodingParams->GetPlaintextGenerator(); for (int i = 0; i < std::floor(std::log2(batchSize)); i++) { auto ea = algo->EvalAutomorphism(newCiphertext, g, evalKeyMap); newCiphertext = algo->EvalAdd(newCiphertext, ea); @@ -341,8 +341,8 @@ Ciphertext AdvancedSHEBase::EvalSumCols( template Ciphertext AdvancedSHEBase::EvalInnerProduct(ConstCiphertext ciphertext1, - ConstCiphertext ciphertext2, usint batchSize, - const std::map>& evalSumKeyMap, + ConstCiphertext ciphertext2, uint32_t batchSize, + const std::map>& evalSumKeyMap, const EvalKey evalMultKey) const { auto algo = ciphertext1->GetCryptoContext()->GetScheme(); @@ -359,8 +359,8 @@ Ciphertext AdvancedSHEBase::EvalInnerProduct(ConstCiphertext Ciphertext AdvancedSHEBase::EvalInnerProduct( - ConstCiphertext ciphertext, ConstPlaintext plaintext, usint batchSize, - const std::map>& evalSumKeyMap) const { + ConstCiphertext ciphertext, ConstPlaintext plaintext, uint32_t batchSize, + const std::map>& evalSumKeyMap) const { auto algo = ciphertext->GetCryptoContext()->GetScheme(); Ciphertext result = algo->EvalMult(ciphertext, plaintext); @@ -376,7 +376,7 @@ Ciphertext AdvancedSHEBase::EvalInnerProduct( template Ciphertext AdvancedSHEBase::EvalMerge(const std::vector>& ciphertextVec, - const std::map>& evalKeyMap) const { + const std::map>& evalKeyMap) const { if (ciphertextVec.size() == 0) OPENFHE_THROW("the vector of ciphertexts to be merged cannot be empty"); @@ -408,11 +408,11 @@ Ciphertext AdvancedSHEBase::EvalMerge(const std::vector -std::set AdvancedSHEBase::GenerateIndices_2n(usint batchSize, usint m) const { +std::set AdvancedSHEBase::GenerateIndices_2n(uint32_t batchSize, uint32_t m) const { std::set indices; if (batchSize > 1) { auto isize = static_cast(std::ceil(std::log2(batchSize)) - 1); - usint g = 5; + uint32_t g = 5; for (size_t i = 0; i < isize; ++i) { indices.insert(g); g = (g * g) % m; @@ -427,7 +427,7 @@ std::set AdvancedSHEBase::GenerateIndices_2n(usint batchSize, } template -std::set AdvancedSHEBase::GenerateIndices2nComplex(usint batchSize, usint m) const { +std::set AdvancedSHEBase::GenerateIndices2nComplex(uint32_t batchSize, uint32_t m) const { auto isize = static_cast(std::ceil(std::log2(batchSize))); std::set indices; @@ -441,7 +441,7 @@ std::set AdvancedSHEBase::GenerateIndices2nComplex(usint batc } template -std::set AdvancedSHEBase::GenerateIndices2nComplexRows(usint rowSize, usint m) const { +std::set AdvancedSHEBase::GenerateIndices2nComplexRows(uint32_t rowSize, uint32_t m) const { uint32_t colSize = m / (4 * rowSize); auto isize = static_cast(std::ceil(std::log2(colSize))); @@ -456,7 +456,7 @@ std::set AdvancedSHEBase::GenerateIndices2nComplexRows(usint } template -std::set AdvancedSHEBase::GenerateIndices2nComplexCols(usint batchSize, usint m) const { +std::set AdvancedSHEBase::GenerateIndices2nComplexCols(uint32_t batchSize, uint32_t m) const { auto isize = static_cast(std::ceil(std::log2(batchSize))); std::set indices; @@ -522,8 +522,8 @@ Ciphertext AdvancedSHEBase::EvalSum_2n(ConstCiphertext Ciphertext AdvancedSHEBase::EvalSum2nComplex( - ConstCiphertext ciphertext, usint batchSize, usint m, - const std::map>& evalKeys) const { + ConstCiphertext ciphertext, uint32_t batchSize, uint32_t m, + const std::map>& evalKeys) const { Ciphertext newCiphertext(std::make_shared>(*ciphertext)); uint32_t g = 5; @@ -539,8 +539,8 @@ Ciphertext AdvancedSHEBase::EvalSum2nComplex( template Ciphertext AdvancedSHEBase::EvalSum2nComplexRows( - ConstCiphertext ciphertext, usint rowSize, usint m, - const std::map>& evalKeys) const { + ConstCiphertext ciphertext, uint32_t rowSize, uint32_t m, + const std::map>& evalKeys) const { Ciphertext newCiphertext(std::make_shared>(*ciphertext)); uint32_t colSize = m / (4 * rowSize); @@ -557,8 +557,8 @@ Ciphertext AdvancedSHEBase::EvalSum2nComplexRows( template Ciphertext AdvancedSHEBase::EvalSum2nComplexCols( - ConstCiphertext ciphertext, usint batchSize, usint m, - const std::map>& evalKeys) const { + ConstCiphertext ciphertext, uint32_t batchSize, uint32_t m, + const std::map>& evalKeys) const { Ciphertext newCiphertext(std::make_shared>(*ciphertext)); uint32_t g = NativeInteger(5).ModInverse(m).ConvertToInt(); diff --git a/src/pke/lib/schemerns/rns-cryptoparameters.cpp b/src/pke/lib/schemerns/rns-cryptoparameters.cpp index c49e993d2..02c659239 100644 --- a/src/pke/lib/schemerns/rns-cryptoparameters.cpp +++ b/src/pke/lib/schemerns/rns-cryptoparameters.cpp @@ -95,8 +95,8 @@ void CryptoParametersRNS::PrecomputeCRTTables(KeySwitchTechnique ksTech, Scaling // Compute the composite digits PartQ = Q_j std::vector moduliPartQ(m_numPartQ, 1); - for (usint j = 0; j < m_numPartQ; j++) { - for (usint i = a * j; i < (j + 1) * a; i++) { + for (uint32_t j = 0; j < m_numPartQ; j++) { + for (uint32_t i = a * j; i < (j + 1) * a; i++) { if (i < moduliQ.size()) moduliPartQ[j] *= moduliQ[i]; } @@ -166,7 +166,7 @@ void CryptoParametersRNS::PrecomputeCRTTables(KeySwitchTechnique ksTech, Scaling do { moduliP[i] = PreviousPrime(pPrev, primeStep); foundInQ = false; - for (usint j = 0; j < sizeQ; j++) + for (uint32_t j = 0; j < sizeQ; j++) if (moduliP[i] == moduliQ[j]) foundInQ = true; pPrev = moduliP[i]; @@ -198,7 +198,7 @@ void CryptoParametersRNS::PrecomputeCRTTables(KeySwitchTechnique ksTech, Scaling // Pre-compute values [P]_{q_i} m_PModq.resize(sizeQ); - for (usint i = 0; i < sizeQ; i++) { + for (uint32_t i = 0; i < sizeQ; i++) { m_PModq[i] = modulusP.Mod(moduliQ[i]).ConvertToInt(); } @@ -378,12 +378,12 @@ void CryptoParametersRNS::PrecomputeCRTTables(KeySwitchTechnique ksTech, Scaling modulusQ = BigInteger(GetElementParams()->GetModulus()) / BigInteger(moduliQ[0]); m_multipartyAlphaQModq0.resize(sizeQ - 1); - for (usint l = sizeQ - 1; l > 0; l--) { + for (uint32_t l = sizeQ - 1; l > 0; l--) { if (l < sizeQ - 1) modulusQ = modulusQ / BigInteger(moduliQ[l + 1]); m_multipartyAlphaQModq0[l - 1].resize(l + 1); NativeInteger QlModq0 = modulusQ.Mod(moduliQ[0]).ConvertToInt(); - for (usint j = 0; j < l + 1; ++j) { + for (uint32_t j = 0; j < l + 1; ++j) { m_multipartyAlphaQModq0[l - 1][j] = {QlModq0.ModMul(NativeInteger(j), moduliQ[0])}; } } diff --git a/src/pke/lib/schemerns/rns-multiparty.cpp b/src/pke/lib/schemerns/rns-multiparty.cpp index 3472181fd..8e82aa5ad 100644 --- a/src/pke/lib/schemerns/rns-multiparty.cpp +++ b/src/pke/lib/schemerns/rns-multiparty.cpp @@ -201,19 +201,19 @@ EvalKey MultipartyRNS::MultiMultEvalKey(PrivateKey privateKe const auto& paramsQ = cryptoParams->GetElementParams(); const auto& paramsQP = cryptoParams->GetParamsQP(); - usint sizeQ = paramsQ->GetParams().size(); - usint sizeQP = paramsQP->GetParams().size(); + uint32_t sizeQ = paramsQ->GetParams().size(); + uint32_t sizeQP = paramsQP->GetParams().size(); DCRTPoly s = privateKey->GetPrivateElement().Clone(); s.SetFormat(Format::COEFFICIENT); DCRTPoly sExt(paramsQP, Format::COEFFICIENT, true); - for (usint i = 0; i < sizeQ; i++) { + for (uint32_t i = 0; i < sizeQ; i++) { sExt.SetElementAtIndex(i, s.GetElementAtIndex(i)); } - for (usint j = sizeQ; j < sizeQP; j++) { + for (uint32_t j = sizeQ; j < sizeQP; j++) { NativeInteger pj = paramsQP->GetParams()[j]->GetModulus(); NativeInteger rooti = paramsQP->GetParams()[j]->GetRootOfUnity(); auto sNew0 = s.GetElementAtIndex(0); @@ -222,7 +222,7 @@ EvalKey MultipartyRNS::MultiMultEvalKey(PrivateKey privateKe } sExt.SetFormat(Format::EVALUATION); - for (usint i = 0; i < size; i++) { + for (uint32_t i = 0; i < size; i++) { a.push_back(a0[i] * sExt + ns * DCRTPoly(dgg, paramsQP, Format::EVALUATION)); b.push_back(b0[i] * sExt + ns * DCRTPoly(dgg, paramsQP, Format::EVALUATION)); } @@ -300,9 +300,9 @@ void ExtendBasis(DCRTPoly& dcrtpoly, const std::shared_ptr par } const auto paramsQ = dcrtpoly.GetParams(); - usint sizeQP = paramsQP->GetParams().size(); - usint sizeQ = paramsQ->GetParams().size(); - usint sizeP = sizeQP - sizeQ; + uint32_t sizeQP = paramsQP->GetParams().size(); + uint32_t sizeQ = paramsQ->GetParams().size(); + uint32_t sizeP = sizeQP - sizeQ; // Loads all moduli and roots of unity std::vector moduliQ(sizeQ); @@ -327,22 +327,22 @@ void ExtendBasis(DCRTPoly& dcrtpoly, const std::shared_ptr par NativeInteger::DNativeInt modulusQ = dcrtpoly.GetModulus().ConvertToInt(); - for (usint i = 0; i < sizeQ; i++) { + for (uint32_t i = 0; i < sizeQ; i++) { NativeInteger::DNativeInt qi(moduliQ[i].ConvertToInt()); NativeInteger QHati = modulusQ / qi; QHatInvModq[i] = QHati.ModInverse(moduliQ[i]).Mod(moduliQ[i]); QHatInvModqPrecon[i] = QHatInvModq[i].PrepModMulConst(moduliQ[i]); - for (usint j = 0; j < sizeP; j++) { + for (uint32_t j = 0; j < sizeP; j++) { const NativeInteger& pj = moduliP[j]; QHatModp[j].push_back(QHati.Mod(pj)); } } std::vector> alphaQModp(sizeQ + 1); - for (usint j = 0; j < sizeP; j++) { + for (uint32_t j = 0; j < sizeP; j++) { NativeInteger::DNativeInt pj(moduliP[j].ConvertToInt()); NativeInteger QModpj = modulusQ % pj; - for (usint i = 0; i < sizeQ + 1; i++) { + for (uint32_t i = 0; i < sizeQ + 1; i++) { alphaQModp[i].push_back(QModpj.ModMul(NativeInteger(i), moduliP[j])); } } diff --git a/src/pke/unittest/UnitTestENCRYPT.cpp b/src/pke/unittest/UnitTestENCRYPT.cpp index df6d3e1c8..2fdf86e22 100644 --- a/src/pke/unittest/UnitTestENCRYPT.cpp +++ b/src/pke/unittest/UnitTestENCRYPT.cpp @@ -94,8 +94,8 @@ static std::ostream& operator<<(std::ostream& os, const TEST_CASE_UTGENERAL_ENCR return os << test.toString(); } //=========================================================================================================== -constexpr usint BATCH = 16; -constexpr usint BV_DSIZE = 4; +constexpr uint32_t BATCH = 16; +constexpr uint32_t BV_DSIZE = 4; // clang-format off static std::vector testCases = { // TestType, Descr, Scheme, RDim, MultDepth, SModSize, DSize, BatchSz, SecKeyDist, MaxRelinSkDeg, FModSize, SecLvl, KSTech, ScalTech, LDigits, PtMod, StdDev, EvalAddCt, KSCt, MultTech, EncTech, PREMode diff --git a/src/pke/unittest/UnitTestEvalMult.cpp b/src/pke/unittest/UnitTestEvalMult.cpp index c5f6e5cd3..0010d19a1 100644 --- a/src/pke/unittest/UnitTestEvalMult.cpp +++ b/src/pke/unittest/UnitTestEvalMult.cpp @@ -114,15 +114,15 @@ static std::ostream& operator<<(std::ostream& os, const TEST_CASE_UTGENERAL_EVAL } //=========================================================================================================== #if NATIVEINT == 128 -constexpr usint SCALE = 78; +constexpr uint32_t SCALE = 78; #else -constexpr usint SCALE = 50; +constexpr uint32_t SCALE = 50; #endif -constexpr usint RING_DIM = 16; -constexpr usint BATCH = 8; -constexpr usint MULT_DEPTH = 4; +constexpr uint32_t RING_DIM = 16; +constexpr uint32_t BATCH = 8; +constexpr uint32_t MULT_DEPTH = 4; constexpr SecurityLevel SEC_LVL = HEStd_NotSet; -constexpr usint PTM = 65537; +constexpr uint32_t PTM = 65537; // clang-format off static std::vector testCasesUTGENERAL_EVALMULT = { diff --git a/src/pke/unittest/UnitTestPRE.cpp b/src/pke/unittest/UnitTestPRE.cpp index 88f93d7ab..6446b5f57 100644 --- a/src/pke/unittest/UnitTestPRE.cpp +++ b/src/pke/unittest/UnitTestPRE.cpp @@ -90,10 +90,10 @@ static std::ostream& operator<<(std::ostream& os, const TEST_CASE_UTGENERAL_REEN return os << test.toString(); } //=========================================================================================================== -const usint PTMOD = 256; -const usint BATCH = 16; -const usint SCALE = 60; -const usint DSIZ = 20; +const uint32_t PTMOD = 256; +const uint32_t BATCH = 16; +const uint32_t SCALE = 60; +const uint32_t DSIZ = 20; // clang-format off static std::vector testCases = { // TestType, Descr, Scheme, RDim, MultDepth, SModSize, DSize,BatchSz, SecKeyDist, MaxRelinSkDeg, FModSize, SecLvl, KSTech, ScalTech, LDigits, PtMod, StdDev, EvalAddCt, KSCt, MultTech, EncTech, PREMode diff --git a/src/pke/unittest/UnitTestSHE.cpp b/src/pke/unittest/UnitTestSHE.cpp index bf5044f4f..aaddc3660 100644 --- a/src/pke/unittest/UnitTestSHE.cpp +++ b/src/pke/unittest/UnitTestSHE.cpp @@ -143,13 +143,13 @@ static std::ostream& operator<<(std::ostream& os, const TEST_CASE_UTGENERAL_SHE& } //=========================================================================================================== // NOTE the SHE tests are all based on these -constexpr usint BATCH = 16; -constexpr usint BATCH_LRG = 1 << 12; -constexpr usint PTM = 64; -constexpr usint PTM_LRG = 65537; +constexpr uint32_t BATCH = 16; +constexpr uint32_t BATCH_LRG = 1 << 12; +constexpr uint32_t PTM = 64; +constexpr uint32_t PTM_LRG = 65537; // checks BFV for a 46-bit plaintext modulus constexpr uint64_t PTM_XTR_LRG = 35184372744193; -constexpr usint BV_DSIZE = 4; +constexpr uint32_t BV_DSIZE = 4; // clang-format off static std::vector testCases = { // TestType, Descr, Scheme, RDim, MultDepth, SModSize, DSize, BatchSz, SecKeyDist, MaxRelinSkDeg, FModSize, SecLvl, KSTech, ScalTech, LDigits, PtMod, StdDev, EvalAddCt, KSCt, MultTech, EncTech, PREMode @@ -1019,7 +1019,7 @@ class UTGENERAL_SHE : public ::testing::TestWithParam { << "Ciphertext metadata mismatch in EvalAtIndex -2"; std::vector weights(2); - for (usint i = 0; i < 2; i++) + for (uint32_t i = 0; i < 2; i++) weights[i] = i; std::vector> ciphertexts(2); diff --git a/src/pke/unittest/utbfvrns/UnitTestBFVrns.cpp b/src/pke/unittest/utbfvrns/UnitTestBFVrns.cpp index 42b4c1cf0..767845020 100644 --- a/src/pke/unittest/utbfvrns/UnitTestBFVrns.cpp +++ b/src/pke/unittest/utbfvrns/UnitTestBFVrns.cpp @@ -94,8 +94,8 @@ static std::ostream& operator<<(std::ostream& os, const TEST_CASE_UTBFVRNS& test return os << test.toString(); } //=========================================================================================================== -constexpr usint MULDEPTH = 7; -constexpr usint PTM = 65537; +constexpr uint32_t MULDEPTH = 7; +constexpr uint32_t PTM = 65537; // clang-format off static std::vector testCases = { // TestType, Descr, Scheme, RDim, MultDepth, SModSize, DSize, BatchSz, SecKeyDist, MaxRelinSkDeg, FModSize, SecLvl, KSTech, ScalTech, LDigits, PtMod, StdDev, EvalAddCt, KSCt, MultTech, EncTech, PREMode diff --git a/src/pke/unittest/utbfvrns/UnitTestBFVrnsAutomorphism.cpp b/src/pke/unittest/utbfvrns/UnitTestBFVrnsAutomorphism.cpp index 113210c6c..04df458f6 100644 --- a/src/pke/unittest/utbfvrns/UnitTestBFVrnsAutomorphism.cpp +++ b/src/pke/unittest/utbfvrns/UnitTestBFVrnsAutomorphism.cpp @@ -61,8 +61,8 @@ class UTBFVRNS_AUTOMORPHISM : public ::testing::Test { const std::vector vector8{1, 2, 3, 4, 5, 6, 7, 8}; const std::vector vector10{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; const std::vector vectorFailure{1, 2, 3, 4}; -const std::vector initIndexList{3, 5, 7, 9, 11, 13, 15}; -const usint invalidIndexAutomorphism = 4; +const std::vector initIndexList{3, 5, 7, 9, 11, 13, 15}; +const uint32_t invalidIndexAutomorphism = 4; const int64_t vector8Sum = std::accumulate(vector8.begin(), vector8.end(), int64_t(0)); // 36 enum TEST_ESTIMATED_RESULT { @@ -82,7 +82,7 @@ enum TEST_ESTIMATED_RESULT { // declaration for Automorphism Test on BFVrns scheme with polynomial operation // in power of 2 cyclotomics. -std::vector BFVrnsAutomorphismPackedArray(usint i, TEST_ESTIMATED_RESULT testResult = SUCCESS) { +std::vector BFVrnsAutomorphismPackedArray(uint32_t i, TEST_ESTIMATED_RESULT testResult = SUCCESS) { using Element = DCRTPoly; CCParams parameters; parameters.SetPlaintextModulus(65537); @@ -105,13 +105,13 @@ std::vector BFVrnsAutomorphismPackedArray(usint i, TEST_ESTIMATED_RESUL cc->Encrypt(PublicKey(nullptr), intArray) : cc->Encrypt(kp.publicKey, intArray); - std::vector indexList(initIndexList); + std::vector indexList(initIndexList); auto evalKeys = (INVALID_PRIVATE_KEY == testResult) ? cc->EvalAutomorphismKeyGen(PrivateKey(nullptr), indexList) : cc->EvalAutomorphismKeyGen(kp.secretKey, indexList); - std::map> emptyEvalKeys; + std::map> emptyEvalKeys; Ciphertext p1 = (INVALID_EVAL_KEY == testResult) ? cc->EvalAutomorphism(ciphertext, i, emptyEvalKeys) : cc->EvalAutomorphism(ciphertext, i, *evalKeys); diff --git a/src/pke/unittest/utbfvrns/UnitTestBFVrnsCRTOperations.cpp b/src/pke/unittest/utbfvrns/UnitTestBFVrnsCRTOperations.cpp index 7d93909b1..0b7fe6acc 100644 --- a/src/pke/unittest/utbfvrns/UnitTestBFVrnsCRTOperations.cpp +++ b/src/pke/unittest/utbfvrns/UnitTestBFVrnsCRTOperations.cpp @@ -59,7 +59,7 @@ class UTBFVRNS_CRT : public ::testing::Test { }; void BFVrns_TestMultiplicativeDepthLimitation(MultiplicationTechnique multiplicationTechnique, - usint multiplicativeDepth) { + uint32_t multiplicativeDepth) { CCParams parameters; const uint64_t ptm = 786433; @@ -220,7 +220,7 @@ TEST_F(UTBFVRNS_CRT, BFVrns_FastBaseConvqToBskMontgomery) { // Generate the element "a" of the public key DCRTPoly a(params, Format::EVALUATION); - usint m1 = 16; + uint32_t m1 = 16; NativeInteger modulus0 = 1152921504606846577; NativeInteger modulus1 = 1152921504606846097; NativeInteger rootOfUnity0(RootOfUnity(m1, modulus0)); @@ -306,7 +306,7 @@ TEST_F(UTBFVRNS_CRT, BFVrns_FastExpandCRTBasisPloverQ) { // Generate the element "a" of the public key DCRTPoly a(params, Format::COEFFICIENT); - usint m1 = 16; + uint32_t m1 = 16; NativeInteger modulus0 = NativeInteger("1152921504606846577"); NativeInteger modulus1 = NativeInteger("1152921504606846097"); NativeInteger rootOfUnity0(RootOfUnity(m1, modulus0)); @@ -387,7 +387,7 @@ TEST_F(UTBFVRNS_CRT, BFVrns_FastExpandCRTBasisPloverQ) { TEST_F(UTBFVRNS_CRT, BFVrns_SwitchCRTBasis) { CCParams parameters; - usint ptm = 1 << 31; + uint32_t ptm = 1 << 31; parameters.SetPlaintextModulus(ptm); parameters.SetMultiplicativeDepth(7); parameters.SetMaxRelinSkDeg(8); @@ -433,7 +433,7 @@ TEST_F(UTBFVRNS_CRT, BFVrns_SwitchCRTBasis) { // TESTING POLYNOMIAL MULTIPLICATION - ONE TERM IS CONSTANT POLYNOMIAL TEST_F(UTBFVRNS_CRT, BFVrns_Mult_by_Constant) { CCParams parameters; - usint ptm = 1 << 15; + uint32_t ptm = 1 << 15; parameters.SetPlaintextModulus(ptm); parameters.SetScalingModSize(60); parameters.SetMultiplicationTechnique(HPS); @@ -502,7 +502,7 @@ TEST_F(UTBFVRNS_CRT, BFVrns_Mult_by_Constant) { BigInteger modulus("1606938044258990275541962092341162602522202993782792836833281"); BigInteger root("859703842628303907691187858658134128225754111718143879712783"); - usint m = 8192; + uint32_t m = 8192; auto paramsPoly = std::make_shared(m, modulus, root); @@ -563,7 +563,7 @@ TEST_F(UTBFVRNS_CRT, BFVrns_Mult_by_Constant) { // TESTING POLYNOMIAL MULTIPLICATION - UNIFORM AND GAUSSIAN RANDOM POLYNOMIALS TEST_F(UTBFVRNS_CRT, BFVrns_Mult_by_Gaussian) { CCParams parameters; - usint ptm = 1 << 15; + uint32_t ptm = 1 << 15; parameters.SetPlaintextModulus(ptm); parameters.SetScalingModSize(60); parameters.SetMultiplicationTechnique(HPS); @@ -633,7 +633,7 @@ TEST_F(UTBFVRNS_CRT, BFVrns_Mult_by_Gaussian) { BigInteger modulus("1606938044258990275541962092341162602522202993782792836833281"); BigInteger root("859703842628303907691187858658134128225754111718143879712783"); - usint m = 8192; + uint32_t m = 8192; auto paramsPoly = std::make_shared(m, modulus, root); diff --git a/src/pke/unittest/utbfvrns/UnitTestBFVrnsDecrypt.cpp b/src/pke/unittest/utbfvrns/UnitTestBFVrnsDecrypt.cpp index cf61adf6d..1cb431111 100644 --- a/src/pke/unittest/utbfvrns/UnitTestBFVrnsDecrypt.cpp +++ b/src/pke/unittest/utbfvrns/UnitTestBFVrnsDecrypt.cpp @@ -41,7 +41,7 @@ using namespace lbcrypto; -class UTBFVRNS_DECRYPT : public ::testing::TestWithParam> { +class UTBFVRNS_DECRYPT : public ::testing::TestWithParam> { protected: void SetUp() { OpenFHEParallelControls.UnitTestStart(); @@ -63,8 +63,8 @@ class UTBFVRNS_DECRYPT : public ::testing::TestWithParam& a, const std::vector& b, int vectorSize, const std::string& failmsg) { - std::vector allTrue(vectorSize); - std::vector tmp(vectorSize); + std::vector allTrue(vectorSize); + std::vector tmp(vectorSize); for (int i = 0; i < vectorSize; i++) { allTrue[i] = 1; tmp[i] = (a[i] == b[i]); @@ -72,12 +72,12 @@ static void checkEquality(const std::vector& a, const std::vector ptm_args{2, 65537, 5308417}; -// static std::vector dcrtbit_args{30, 40, 50, 60}; +// static std::vector ptm_args{2, 65537, 5308417}; +// static std::vector dcrtbit_args{30, 40, 50, 60}; TEST_P(UTBFVRNS_DECRYPT, BFVrns_Decrypt) { - usint ptm = std::get<0>(GetParam()); - usint dcrtBits = std::get<1>(GetParam()); + uint32_t ptm = std::get<0>(GetParam()); + uint32_t dcrtBits = std::get<1>(GetParam()); CCParams parameters; parameters.SetPlaintextModulus(ptm); @@ -90,9 +90,9 @@ TEST_P(UTBFVRNS_DECRYPT, BFVrns_Decrypt) { KeyPair kp = cc->KeyGen(); - usint vecsize = 8; + uint32_t vecsize = 8; std::vector vectorOfInts(8); - for (usint i = 0; i < vecsize; ++i) { + for (uint32_t i = 0; i < vecsize; ++i) { if (ptm == 2) { vectorOfInts[i] = rand() % ptm; // NOLINT } diff --git a/src/pke/unittest/utbgvrns/UnitTestBGVrns.cpp b/src/pke/unittest/utbgvrns/UnitTestBGVrns.cpp index 304d86aee..57802d36f 100644 --- a/src/pke/unittest/utbgvrns/UnitTestBGVrns.cpp +++ b/src/pke/unittest/utbgvrns/UnitTestBGVrns.cpp @@ -135,14 +135,14 @@ static std::ostream& operator<<(std::ostream& os, const TEST_CASE_UTBGVRNS& test * PTM: The plaintext modulus. * BATCH: The length of the packed vectors to be used with CKKS. */ -constexpr usint RING_DIM = 512; -constexpr usint MULT_DEPTH = 7; -constexpr usint MAX_RELIN_DEG = 2; -constexpr usint DSIZE = 0; -constexpr usint BV_DSIZE = 4; -constexpr usint PTM = 65537; -constexpr usint BATCH = 16; -constexpr usint FIRST_MOD_SIZE = 0; +constexpr uint32_t RING_DIM = 512; +constexpr uint32_t MULT_DEPTH = 7; +constexpr uint32_t MAX_RELIN_DEG = 2; +constexpr uint32_t DSIZE = 0; +constexpr uint32_t BV_DSIZE = 4; +constexpr uint32_t PTM = 65537; +constexpr uint32_t BATCH = 16; +constexpr uint32_t FIRST_MOD_SIZE = 0; constexpr SecurityLevel SEC_LVL = HEStd_NotSet; // clang-format off @@ -252,7 +252,7 @@ class UTBGVRNS : public ::testing::TestWithParam { using Element = DCRTPoly; // the size for all vectors remains const - 8 elements - const usint VECTOR_SIZE = 8; + const uint32_t VECTOR_SIZE = 8; // The precision after which we consider two values equal. Necessary for the checkEquality() calls const double eps = EPSILON; @@ -295,7 +295,7 @@ class UTBGVRNS : public ::testing::TestWithParam { // std::vector vectorOfIntsSub = { -7,-5,-3,-1,1,3,5,7 }; std::vector vectorOfIntsSub(VECTOR_SIZE); - for (usint i = 0; i < VECTOR_SIZE; i++) { + for (uint32_t i = 0; i < VECTOR_SIZE; i++) { vectorOfIntsSub[i] = static_cast(2 * i) - VECTOR_SIZE + 1; } Plaintext plaintextSub = cc->MakePackedPlaintext(vectorOfIntsSub); @@ -399,7 +399,7 @@ class UTBGVRNS : public ::testing::TestWithParam { // vectorOfIntsMult = { 0,6,10,12,12,10,6,0 }; std::vector vectorOfIntsMult(VECTOR_SIZE); - for (usint i = 0; i < VECTOR_SIZE; i++) { + for (uint32_t i = 0; i < VECTOR_SIZE; i++) { vectorOfIntsMult[i] = i * VECTOR_SIZE - i * i - i; } Plaintext plaintextMult = cc->MakePackedPlaintext(vectorOfIntsMult); @@ -474,14 +474,14 @@ class UTBGVRNS : public ::testing::TestWithParam { // vIntsRightShift2 = { 0,0,1,2,3,4,5,6 }; std::vector vIntsRightShift2(VECTOR_SIZE); - for (usint i = 0; i < VECTOR_SIZE; i++) { + for (uint32_t i = 0; i < VECTOR_SIZE; i++) { vIntsRightShift2[i] = (i >= 2) ? vectorOfInts1[i - 2] : 0; } Plaintext plaintextRight2 = cc->MakePackedPlaintext(vIntsRightShift2); // vIntsLeftShift2 = { 3,4,5,6,7,8,0,0 }; std::vector vIntsLeftShift2(VECTOR_SIZE); - for (usint i = 0; i < VECTOR_SIZE; i++) { + for (uint32_t i = 0; i < VECTOR_SIZE; i++) { vIntsLeftShift2[i] = (i < VECTOR_SIZE - 2) ? vectorOfInts1[i + 2] : 0; } Plaintext plaintextLeft2 = cc->MakePackedPlaintext(vIntsLeftShift2); @@ -679,7 +679,7 @@ class UTBGVRNS : public ::testing::TestWithParam { std::vector pCt12(VECTOR_SIZE); std::vector pCt13(VECTOR_SIZE); std::vector pCt14(VECTOR_SIZE); - for (usint i = 0; i < VECTOR_SIZE; i++) { + for (uint32_t i = 0; i < VECTOR_SIZE; i++) { pCtMult[i] = vectorOfInts1[i] * vectorOfInts2[i]; pCt3[i] = pCtMult[i] + vectorOfInts1[i]; pCt4[i] = pCtMult[i] - vectorOfInts1[i]; @@ -926,14 +926,14 @@ class UTBGVRNS : public ::testing::TestWithParam { // vIntsRightShift2 = { 0,0,1,2,3,4,5,6 }; std::vector vIntsRightShift2(VECTOR_SIZE); - for (usint i = 0; i < VECTOR_SIZE; i++) { + for (uint32_t i = 0; i < VECTOR_SIZE; i++) { vIntsRightShift2[i] = (i >= 2) ? vectorOfInts1[i - 2] : 0; } Plaintext plaintextRight2 = cc->MakePackedPlaintext(vIntsRightShift2); // vIntsLeftShift2 = { 3,4,5,6,7,8,0,0 }; std::vector vIntsLeftShift2(VECTOR_SIZE); - for (usint i = 0; i < VECTOR_SIZE; i++) { + for (uint32_t i = 0; i < VECTOR_SIZE; i++) { vIntsLeftShift2[i] = (i < VECTOR_SIZE - 2) ? vectorOfInts1[i + 2] : 0; } Plaintext plaintextLeft2 = cc->MakePackedPlaintext(vIntsLeftShift2); @@ -959,7 +959,7 @@ class UTBGVRNS : public ::testing::TestWithParam { auto decompose = cc->EvalFastRotationPrecompute(ciphertext1); - usint m = cc->GetCryptoParameters()->GetElementParams()->GetCyclotomicOrder(); + uint32_t m = cc->GetCryptoParameters()->GetElementParams()->GetCyclotomicOrder(); // Testing EvalAtIndex +2 cResult = cc->EvalFastRotation(ciphertext1, 2, m, decompose); cc->Decrypt(kp.secretKey, cResult, &results); diff --git a/src/pke/unittest/utbgvrns/UnitTestBGVrnsAdvancedSHE.cpp b/src/pke/unittest/utbgvrns/UnitTestBGVrnsAdvancedSHE.cpp index d19be3192..db026410c 100644 --- a/src/pke/unittest/utbgvrns/UnitTestBGVrnsAdvancedSHE.cpp +++ b/src/pke/unittest/utbgvrns/UnitTestBGVrnsAdvancedSHE.cpp @@ -95,9 +95,9 @@ static std::ostream& operator<<(std::ostream& os, const TEST_CASE_UTBGVRNS_SHEAD return os << test.toString(); } //=========================================================================================================== -constexpr usint RING_DIM = 8192; -constexpr usint PTM = 20; -constexpr usint DSIZE = 4; +constexpr uint32_t RING_DIM = 8192; +constexpr uint32_t PTM = 20; +constexpr uint32_t DSIZE = 4; constexpr double STD_DEV = 3.19; // clang-format off diff --git a/src/pke/unittest/utbgvrns/UnitTestBGVrnsAutomorphism.cpp b/src/pke/unittest/utbgvrns/UnitTestBGVrnsAutomorphism.cpp index 55a90e519..5ae41ddfe 100644 --- a/src/pke/unittest/utbgvrns/UnitTestBGVrnsAutomorphism.cpp +++ b/src/pke/unittest/utbgvrns/UnitTestBGVrnsAutomorphism.cpp @@ -185,7 +185,7 @@ class UTBGVRNS_AUTOMORPHISM : public ::testing::TestWithParam vector8{1, 2, 3, 4, 5, 6, 7, 8}; const std::vector vectorFailure{1, 2, 3, 4}; - const usint invalidIndexAutomorphism = 4; + const uint32_t invalidIndexAutomorphism = 4; const int64_t vector8Sum = std::accumulate(vector8.begin(), vector8.end(), int64_t(0)); // 36 protected: @@ -216,14 +216,14 @@ class UTBGVRNS_AUTOMORPHISM : public ::testing::TestWithParamEncrypt(static_cast>(nullptr), intArray) : cc->Encrypt(kp.publicKey, intArray); - std::vector indexList(testData.indexList); + std::vector indexList(testData.indexList); auto evalKeys = (INVALID_PRIVATE_KEY == testData.error) ? cc->EvalAutomorphismKeyGen(static_cast>(nullptr), indexList) : cc->EvalAutomorphismKeyGen(kp.secretKey, indexList); - std::map> emptyEvalKeys; + std::map> emptyEvalKeys; Ciphertext p1 = (INVALID_EVAL_KEY == testData.error) ? cc->EvalAutomorphism(ciphertext, index, emptyEvalKeys) : cc->EvalAutomorphism(ciphertext, index, *evalKeys); diff --git a/src/pke/unittest/utbgvrns/UnitTestBGVrnsSerialize.cpp b/src/pke/unittest/utbgvrns/UnitTestBGVrnsSerialize.cpp index a693eff38..6fb1e0c25 100644 --- a/src/pke/unittest/utbgvrns/UnitTestBGVrnsSerialize.cpp +++ b/src/pke/unittest/utbgvrns/UnitTestBGVrnsSerialize.cpp @@ -110,13 +110,13 @@ static std::ostream& operator<<(std::ostream& os, const TEST_CASE_UTBGVRNS_SER& * PTM: The plaintext modulus. * BATCH: The length of the packed vectors to be used with CKKS. */ -constexpr usint RING_DIM = 32; -constexpr usint MULT_DEPTH = 3; -constexpr usint MAX_RELIN_DEG = 2; -constexpr usint DSIZE = 4; -constexpr usint PTM = 65537; -constexpr usint BATCH = 16; -constexpr usint FIRST_MOD_SIZE = 0; +constexpr uint32_t RING_DIM = 32; +constexpr uint32_t MULT_DEPTH = 3; +constexpr uint32_t MAX_RELIN_DEG = 2; +constexpr uint32_t DSIZE = 4; +constexpr uint32_t PTM = 65537; +constexpr uint32_t BATCH = 16; +constexpr uint32_t FIRST_MOD_SIZE = 0; constexpr SecurityLevel SEC_LVL = HEStd_NotSet; // TODO (dsuponit): are there any changes under this condition - #if NATIVEINT != 128? diff --git a/src/pke/unittest/utckksrns/UnitTestCKKSrns.cpp b/src/pke/unittest/utckksrns/UnitTestCKKSrns.cpp index 2b92d5e8a..3e99c8d26 100644 --- a/src/pke/unittest/utckksrns/UnitTestCKKSrns.cpp +++ b/src/pke/unittest/utckksrns/UnitTestCKKSrns.cpp @@ -166,12 +166,12 @@ static std::ostream& operator<<(std::ostream& os, const TEST_CASE_UTCKKSRNS& tes * DSIZE: The bit decomposition count used in BV relinearization. * BATCH: The length of the packed vectors to be used with CKKS. */ -constexpr usint RING_DIM = 512; -constexpr usint RING_DIM_HALF = 256; -constexpr usint DSIZE = 10; -constexpr usint BATCH = 8; +constexpr uint32_t RING_DIM = 512; +constexpr uint32_t RING_DIM_HALF = 256; +constexpr uint32_t DSIZE = 10; +constexpr uint32_t BATCH = 8; #if NATIVEINT != 128 -constexpr usint RING_DIM_PREC = 2048; // for test cases with approximation error comparison only +constexpr uint32_t RING_DIM_PREC = 2048; // for test cases with approximation error comparison only #endif // MIN_PRECISION_DIFF is the minimal difference expected between approximation error/precision for FLEXIBLEAUTO and FLEXIBLEAUTOEXT constexpr double MIN_PRECISION_DIFF = 1.5; @@ -602,7 +602,7 @@ class UTCKKSRNS : public ::testing::TestWithParam { using Element = DCRTPoly; // the size for all vectors remains const - 8 elements - const usint VECTOR_SIZE = 8; + const uint32_t VECTOR_SIZE = 8; // The precision after which we consider two values equal. // This is necessary because CKKS works for approximate numbers. @@ -1027,7 +1027,7 @@ class UTCKKSRNS : public ::testing::TestWithParam { std::vector> vectorOfIntsSubAfterMult(VECTOR_SIZE); std::vector> vectorOfIntsAddAfterMult2(VECTOR_SIZE); std::vector> vectorOfIntsSubAfterMult2(VECTOR_SIZE); - for (usint i = 0; i < VECTOR_SIZE; i++) { + for (uint32_t i = 0; i < VECTOR_SIZE; i++) { vectorOfIntsMult[i] = i * VECTOR_SIZE - i * i - i; vectorOfIntsAddAfterMult[i] = vectorOfIntsMult[i] + std::complex(10, 0); vectorOfIntsSubAfterMult[i] = vectorOfIntsMult[i] - std::complex(10, 0); @@ -1191,7 +1191,7 @@ class UTCKKSRNS : public ::testing::TestWithParam { std::vector> pCt12(VECTOR_SIZE); std::vector> pCt13(VECTOR_SIZE); std::vector> pCt14(VECTOR_SIZE); - for (usint i = 0; i < VECTOR_SIZE; i++) { + for (uint32_t i = 0; i < VECTOR_SIZE; i++) { pCtMult[i] = vectorOfInts1[i] * vectorOfInts2[i]; pCt3[i] = pCtMult[i] + vectorOfInts1[i]; pCt4[i] = pCtMult[i] - vectorOfInts1[i]; @@ -1524,7 +1524,7 @@ class UTCKKSRNS : public ::testing::TestWithParam { // vIntsRightShift2 = { 7,8,1,2,3,4,5,6 } if slots = 8; std::vector> vIntsRightShift2(VECTOR_SIZE); uint32_t slots = (testData.slots != 0) ? testData.slots : (BATCH != 0) ? BATCH : cc->GetRingDimension() / 2; - for (usint i = 0; i < VECTOR_SIZE; i++) { + for (uint32_t i = 0; i < VECTOR_SIZE; i++) { if ((slots + i - 2) % slots < VECTOR_SIZE) { vIntsRightShift2[i] = vectorOfInts1_8[(slots + i - 2) % slots]; } @@ -1537,7 +1537,7 @@ class UTCKKSRNS : public ::testing::TestWithParam { // vIntsRightShift2 = { 3,4,5,6,7,8,0,0 } if slots > 8; // vIntsRightShift2 = { 3,4,5,6,7,8,1,2 } if slots = 8; std::vector> vIntsLeftShift2(VECTOR_SIZE); - for (usint i = 0; i < VECTOR_SIZE; i++) { + for (uint32_t i = 0; i < VECTOR_SIZE; i++) { if ((i + 2) % slots < VECTOR_SIZE) { vIntsLeftShift2[i] = vectorOfInts1_8[(i + 2) % slots]; } @@ -1677,7 +1677,7 @@ class UTCKKSRNS : public ::testing::TestWithParam { std::vector> in2(VECTOR_SIZE, 2); // all 2's std::vector> in3(VECTOR_SIZE, 1); // all 1's std::vector> out(VECTOR_SIZE); - for (usint i = 0; i < VECTOR_SIZE; i++) { + for (uint32_t i = 0; i < VECTOR_SIZE; i++) { // TODO (dsuponit): what is the purpose of this calculation? to have a noise? // otherwise it is better to create "out" without calculating values in the loop out[i] = weights[0] * in1[i] + weights[1] * in2[i] + weights[2] * in3[i]; diff --git a/src/pke/unittest/utckksrns/UnitTestCKKSrnsAutomorphism.cpp b/src/pke/unittest/utckksrns/UnitTestCKKSrnsAutomorphism.cpp index 00edc0f3b..dcedb60d1 100644 --- a/src/pke/unittest/utckksrns/UnitTestCKKSrnsAutomorphism.cpp +++ b/src/pke/unittest/utckksrns/UnitTestCKKSrnsAutomorphism.cpp @@ -114,10 +114,10 @@ static std::ostream& operator<<(std::ostream& os, const TEST_CASE_UTCKKSRNS_AUTO return os << test.toString(); } //=========================================================================================================== -constexpr usint SMODSIZE = 50; -constexpr usint RING_DIM = 16; -constexpr usint BATCH = 8; -constexpr usint MULT_DEPTH = 1; +constexpr uint32_t SMODSIZE = 50; +constexpr uint32_t RING_DIM = 16; +constexpr uint32_t BATCH = 8; +constexpr uint32_t MULT_DEPTH = 1; constexpr SecurityLevel SEC_LVL = HEStd_NotSet; static const std::vector initIndexList{3, 5, 7, 9, 11, 13, 15}; static const std::vector cornerCaseIndexList{0}; @@ -201,7 +201,7 @@ class UTCKKSRNS_AUTOMORPHISM : public ::testing::TestWithParam vector8{1, 2, 3, 4, 5, 6, 7, 8}; const std::vector vector10{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; const std::vector vectorFailure{1, 2, 3, 4}; - const usint invalidIndexAutomorphism = 4; + const uint32_t invalidIndexAutomorphism = 4; const std::vector> vectorComplexFailure{1.0, 2.0, 3.0, 4.0}; const std::vector> vector8Complex{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0}; const std::complex vector8ComplexSum = diff --git a/src/pke/unittest/utckksrns/UnitTestCKKSrnsCompositeScaling.cpp b/src/pke/unittest/utckksrns/UnitTestCKKSrnsCompositeScaling.cpp index 48bcd711c..c5c82c001 100644 --- a/src/pke/unittest/utckksrns/UnitTestCKKSrnsCompositeScaling.cpp +++ b/src/pke/unittest/utckksrns/UnitTestCKKSrnsCompositeScaling.cpp @@ -162,12 +162,12 @@ static std::ostream& operator<<(std::ostream& os, const TEST_CASE_UTCKKSRNS_CS& * DSIZE: The bit decomposition count used in BV relinearization. * BATCH: The length of the packed vectors to be used with CKKS. */ -constexpr usint RING_DIM = 512; -constexpr usint RING_DIM_HALF = 256; -constexpr usint DSIZE = 10; -constexpr usint BATCH = 8; +constexpr uint32_t RING_DIM = 512; +constexpr uint32_t RING_DIM_HALF = 256; +constexpr uint32_t DSIZE = 10; +constexpr uint32_t BATCH = 8; // #if NATIVEINT != 128 && !defined(__EMSCRIPTEN__) -// constexpr usint RING_DIM_PREC = 2048; // for test cases with approximation error comparison only +// constexpr uint32_t RING_DIM_PREC = 2048; // for test cases with approximation error comparison only // #endif // MIN_PRECISION_DIFF is the minimal difference expected between approximation error/precision for FLEXIBLEAUTO and FLEXIBLEAUTOEXT constexpr double MIN_PRECISION_DIFF = 1.5; @@ -401,7 +401,7 @@ class UTCKKSRNSCS : public ::testing::TestWithParam { using Element = DCRTPoly; // the size for all vectors remains const - 8 elements - const usint VECTOR_SIZE = 8; + const uint32_t VECTOR_SIZE = 8; // The precision after which we consider two values equal. // This is necessary because CKKS works for approximate numbers. @@ -826,7 +826,7 @@ class UTCKKSRNSCS : public ::testing::TestWithParam { std::vector> vectorOfIntsSubAfterMult(VECTOR_SIZE); std::vector> vectorOfIntsAddAfterMult2(VECTOR_SIZE); std::vector> vectorOfIntsSubAfterMult2(VECTOR_SIZE); - for (usint i = 0; i < VECTOR_SIZE; i++) { + for (uint32_t i = 0; i < VECTOR_SIZE; i++) { vectorOfIntsMult[i] = i * VECTOR_SIZE - i * i - i; vectorOfIntsAddAfterMult[i] = vectorOfIntsMult[i] + std::complex(10, 0); vectorOfIntsSubAfterMult[i] = vectorOfIntsMult[i] - std::complex(10, 0); @@ -990,7 +990,7 @@ class UTCKKSRNSCS : public ::testing::TestWithParam { std::vector> pCt12(VECTOR_SIZE); std::vector> pCt13(VECTOR_SIZE); std::vector> pCt14(VECTOR_SIZE); - for (usint i = 0; i < VECTOR_SIZE; i++) { + for (uint32_t i = 0; i < VECTOR_SIZE; i++) { pCtMult[i] = vectorOfInts1[i] * vectorOfInts2[i]; pCt3[i] = pCtMult[i] + vectorOfInts1[i]; pCt4[i] = pCtMult[i] - vectorOfInts1[i]; @@ -1326,7 +1326,7 @@ class UTCKKSRNSCS : public ::testing::TestWithParam { // vIntsRightShift2 = { 7,8,1,2,3,4,5,6 } if slots = 8; std::vector> vIntsRightShift2(VECTOR_SIZE); uint32_t slots = (testData.slots != 0) ? testData.slots : (BATCH != 0) ? BATCH : cc->GetRingDimension() / 2; - for (usint i = 0; i < VECTOR_SIZE; i++) { + for (uint32_t i = 0; i < VECTOR_SIZE; i++) { if ((slots + i - 2) % slots < VECTOR_SIZE) { vIntsRightShift2[i] = vectorOfInts1_8[(slots + i - 2) % slots]; } @@ -1339,7 +1339,7 @@ class UTCKKSRNSCS : public ::testing::TestWithParam { // vIntsRightShift2 = { 3,4,5,6,7,8,0,0 } if slots > 8; // vIntsRightShift2 = { 3,4,5,6,7,8,1,2 } if slots = 8; std::vector> vIntsLeftShift2(VECTOR_SIZE); - for (usint i = 0; i < VECTOR_SIZE; i++) { + for (uint32_t i = 0; i < VECTOR_SIZE; i++) { if ((i + 2) % slots < VECTOR_SIZE) { vIntsLeftShift2[i] = vectorOfInts1_8[(i + 2) % slots]; } @@ -1479,7 +1479,7 @@ class UTCKKSRNSCS : public ::testing::TestWithParam { std::vector> in2(VECTOR_SIZE, 2); // all 2's std::vector> in3(VECTOR_SIZE, 1); // all 1's std::vector> out(VECTOR_SIZE); - for (usint i = 0; i < VECTOR_SIZE; i++) { + for (uint32_t i = 0; i < VECTOR_SIZE; i++) { // TODO (dsuponit): what is the purpose of this calculation? to have a noise? // otherwise it is better to create "out" without calculating values in the loop out[i] = weights[0] * in1[i] + weights[1] * in2[i] + weights[2] * in3[i]; diff --git a/src/pke/unittest/utckksrns/UnitTestCKKSrnsCompositeScalingBootstrap.cpp b/src/pke/unittest/utckksrns/UnitTestCKKSrnsCompositeScalingBootstrap.cpp index 638440729..488e5170e 100644 --- a/src/pke/unittest/utckksrns/UnitTestCKKSrnsCompositeScalingBootstrap.cpp +++ b/src/pke/unittest/utckksrns/UnitTestCKKSrnsCompositeScalingBootstrap.cpp @@ -356,8 +356,8 @@ class UTCKKSRNSCS_BOOT : public ::testing::TestWithParamEncrypt(keyPair.publicKey, plaintext_a); firstCurrent = ciphertext->GetElements()[0]; // Find the automorphism index that corresponds to rotation index index. - usint autoIndex = FindAutomorphismIndex2nComplex(1, 4096); - std::vector map(4096 / 2); + uint32_t autoIndex = FindAutomorphismIndex2nComplex(1, 4096); + std::vector map(4096 / 2); PrecomputeAutoMap(4096 / 2, autoIndex, &map); firstCurrent = firstCurrent.AutomorphismTransform(autoIndex, map); digits = cc->EvalFastRotationPrecompute(ciphertext); diff --git a/src/pke/unittest/utckksrns/UnitTestCKKSrnsSerialize.cpp b/src/pke/unittest/utckksrns/UnitTestCKKSrnsSerialize.cpp index 1b5a207c9..ad91d6043 100644 --- a/src/pke/unittest/utckksrns/UnitTestCKKSrnsSerialize.cpp +++ b/src/pke/unittest/utckksrns/UnitTestCKKSrnsSerialize.cpp @@ -111,11 +111,11 @@ static std::ostream& operator<<(std::ostream& os, const TEST_CASE_UTCKKSRNS_SER& * Use small values (3-4?) if you need rotations before any multiplications. * BATCH: The length of the packed vectors to be used with CKKS. */ -constexpr usint RING_DIM = 32; -constexpr usint SMODSIZE = 50; -constexpr usint MULT_DEPTH = 3; -constexpr usint DSIZE = 20; -constexpr usint BATCH = 16; +constexpr uint32_t RING_DIM = 32; +constexpr uint32_t SMODSIZE = 50; +constexpr uint32_t MULT_DEPTH = 3; +constexpr uint32_t DSIZE = 20; +constexpr uint32_t BATCH = 16; // clang-format off static std::vector testCases = { // TestType, Descr, Scheme, RDim, MultDepth, SModSize, DSize, BatchSz, SecKeyDist, MaxRelinSkDeg, FModSize, SecLvl, KSTech, ScalTech, LDigits, PtMod, StdDev, EvalAddCt, KSCt, MultTech, EncTech, PREMode diff --git a/src/pke/unittest/utckksrns/UnitTestFBT.cpp b/src/pke/unittest/utckksrns/UnitTestFBT.cpp index 8792376ff..71cb17770 100644 --- a/src/pke/unittest/utckksrns/UnitTestFBT.cpp +++ b/src/pke/unittest/utckksrns/UnitTestFBT.cpp @@ -429,14 +429,14 @@ class UTCKKSRNS_FBT : public ::testing::TestWithParam { #endif auto exact(x); - std::transform(x.begin(), x.end(), exact.begin(), [&](const int64_t& elem) { + std::transform(x.begin(), x.end(), exact.begin(), [&](int64_t elem) { return (f(elem) > t.POutput.ConvertToDouble() / 2.) ? f(elem) - t.POutput.ConvertToInt() : f(elem); }); std::transform(exact.begin(), exact.end(), computed.begin(), exact.begin(), std::minus()); std::transform(exact.begin(), exact.end(), exact.begin(), - [&](const int64_t& elem) { return (std::abs(elem)) % (t.POutput.ConvertToInt()); }); + [&](int64_t elem) { return (std::abs(elem)) % (t.POutput.ConvertToInt()); }); auto max_error_it = std::max_element(exact.begin(), exact.end()); // std::cerr << "\n=======Error count: " << std::accumulate(exact.begin(), exact.end(), 0) << "\n"; // std::cerr << "\n=======Max absolute error: " << *max_error_it << "\n"; @@ -480,7 +480,7 @@ class UTCKKSRNS_FBT : public ::testing::TestWithParam { auto exact(x); std::transform(x.begin(), x.end(), exact.begin(), - [&](const int64_t& elem) { return (elem >= t.PInput.ConvertToDouble() / 2.); }); + [&](int64_t elem) { return (elem >= t.PInput.ConvertToDouble() / 2.); }); std::vector coeffintMod; std::vector> coeffcompMod; @@ -660,7 +660,7 @@ class UTCKKSRNS_FBT : public ::testing::TestWithParam { std::transform(exact.begin(), exact.end(), computed.begin(), exact.begin(), std::minus()); std::transform(exact.begin(), exact.end(), exact.begin(), - [&](const int64_t& elem) { return (std::abs(elem)) % (t.PInput.ConvertToInt()); }); + [&](int64_t elem) { return (std::abs(elem)) % (t.PInput.ConvertToInt()); }); auto max_error_it = std::max_element(exact.begin(), exact.end()); // std::cerr << "\n=======Error count: " << std::accumulate(exact.begin(), exact.end(), 0) << "\n"; // std::cerr << "\n=======Max absolute error: " << *max_error_it << "\n"; @@ -860,7 +860,7 @@ class UTCKKSRNS_FBT : public ::testing::TestWithParam { #endif auto exact(x); - std::transform(x.begin(), x.end(), exact.begin(), [&](const int64_t& elem) { + std::transform(x.begin(), x.end(), exact.begin(), [&](int64_t elem) { return (f(elem) % t.POutput.ConvertToInt() > t.POutput.ConvertToDouble() / 2.) ? f(elem) % t.POutput.ConvertToInt() - t.POutput.ConvertToInt() : f(elem) % t.POutput.ConvertToInt(); @@ -875,14 +875,14 @@ class UTCKKSRNS_FBT : public ::testing::TestWithParam { std::transform(exact2.begin(), exact2.end(), computed1.begin(), exact2.begin(), std::minus()); std::transform(exact2.begin(), exact2.end(), exact2.begin(), - [&](const int64_t& elem) { return (std::abs(elem)) % (t.POutput.ConvertToInt()); }); + [&](int64_t elem) { return (std::abs(elem)) % (t.POutput.ConvertToInt()); }); auto max_error_it = std::max_element(exact2.begin(), exact2.end()); // std::cerr << "\n=======Error count: " << std::accumulate(exact.begin(), exact.end(), 0) << "\n"; // std::cerr << "\n=======Max absolute error: " << *max_error_it << "\n"; checkEquality((*max_error_it), int64_t(0), 0.0001, failmsg + " LUT evaluation fails"); - std::transform(exact3.begin(), exact3.end(), exact.begin(), [&](const int64_t& elem) { + std::transform(exact3.begin(), exact3.end(), exact.begin(), [&](int64_t elem) { return (f(elem) % t.POutput.ConvertToInt() > t.POutput.ConvertToDouble() / 2.) ? f(elem) % t.POutput.ConvertToInt() - t.POutput.ConvertToInt() : f(elem) % t.POutput.ConvertToInt(); @@ -890,7 +890,7 @@ class UTCKKSRNS_FBT : public ::testing::TestWithParam { std::transform(exact.begin(), exact.end(), computed2.begin(), exact.begin(), std::minus()); std::transform(exact.begin(), exact.end(), exact.begin(), - [&](const int64_t& elem) { return (std::abs(elem)) % (t.POutput.ConvertToInt()); }); + [&](int64_t elem) { return (std::abs(elem)) % (t.POutput.ConvertToInt()); }); max_error_it = std::max_element(exact.begin(), exact.end()); // std::cerr << "\n=======Error count: " << std::accumulate(exact.begin(), exact.end(), 0) << "\n"; // std::cerr << "\n=======Max absolute error: " << *max_error_it << "\n"; @@ -1069,7 +1069,7 @@ class UTCKKSRNS_FBT : public ::testing::TestWithParam { #endif auto exact(x); - std::transform(x.begin(), x.end(), exact.begin(), [&](const int64_t& elem) { + std::transform(x.begin(), x.end(), exact.begin(), [&](int64_t elem) { return (f1(elem) % t.POutput.ConvertToInt() > t.POutput.ConvertToDouble() / 2.) ? f1(elem) % t.POutput.ConvertToInt() - t.POutput.ConvertToInt() : f1(elem); @@ -1077,13 +1077,13 @@ class UTCKKSRNS_FBT : public ::testing::TestWithParam { std::transform(exact.begin(), exact.end(), computed1.begin(), exact.begin(), std::minus()); std::transform(exact.begin(), exact.end(), exact.begin(), - [&](const int64_t& elem) { return (std::abs(elem)) % (t.POutput.ConvertToInt()); }); + [&](int64_t elem) { return (std::abs(elem)) % (t.POutput.ConvertToInt()); }); auto max_error_it = std::max_element(exact.begin(), exact.end()); // std::cerr << "\n=======Error count: " << std::accumulate(exact.begin(), exact.end(), 0) << "\n"; // std::cerr << "\n=======Max absolute error: " << *max_error_it << "\n"; checkEquality((*max_error_it), int64_t(0), 0.0001, failmsg + " LUT evaluation fails"); - std::transform(x.begin(), x.end(), exact.begin(), [&](const int64_t& elem) { + std::transform(x.begin(), x.end(), exact.begin(), [&](int64_t elem) { return (f2(elem) % t.POutput.ConvertToInt() > t.POutput.ConvertToDouble() / 2.) ? f2(elem) % t.POutput.ConvertToInt() - t.POutput.ConvertToInt() : f2(elem); @@ -1091,7 +1091,7 @@ class UTCKKSRNS_FBT : public ::testing::TestWithParam { std::transform(exact.begin(), exact.end(), computed2.begin(), exact.begin(), std::minus()); std::transform(exact.begin(), exact.end(), exact.begin(), - [&](const int64_t& elem) { return (std::abs(elem)) % (t.POutput.ConvertToInt()); }); + [&](int64_t elem) { return (std::abs(elem)) % (t.POutput.ConvertToInt()); }); max_error_it = std::max_element(exact.begin(), exact.end()); // std::cerr << "\n=======Error count: " << std::accumulate(exact.begin(), exact.end(), 0) << "\n"; // std::cerr << "\n=======Max absolute error: " << *max_error_it << "\n"; From 467d7b513bcdb064990f793cb706bf28e706eed3 Mon Sep 17 00:00:00 2001 From: yspolyakov <89226542+yspolyakov@users.noreply.github.com> Date: Tue, 28 Apr 2026 17:23:45 -0400 Subject: [PATCH 2/3] Update acknowledgments in README.md (#1176) Added funding acknowledgment for ARPA-H research. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4f16f0a4d..b56f77fe5 100644 --- a/README.md +++ b/README.md @@ -153,4 +153,5 @@ or, alternatively (original WAHC@CCS'22 version), ## Acknowledgments ## -Distribution Statement "A" (Approved for Public Release, Distribution Unlimited). This work is supported in part by DARPA through HR0011-21-9-0003 and HR0011-20-9-0102. The views, opinions, and/or findings expressed are those of the author(s) and should not be interpreted as representing the official views or policies of the Department of Defense or the U.S. Government. +* Distribution Statement "A" (Approved for Public Release, Distribution Unlimited). This work is supported in part by DARPA through HR0011-21-9-0003 and HR0011-20-9-0102. The views, opinions, and/or findings expressed are those of the author(s) and should not be interpreted as representing the official views or policies of the Department of Defense or the U.S. Government. +* This research was funded, in part, by the Advanced Research Projects Agency for Health (ARPA-H). The views and conclusions contained in this document are those of the authors and should not be interpreted as representing the official policies, either expressed or implied, of the U.S. Government. From aaea1f2b1370d2124d22da6f14af5bb033863512 Mon Sep 17 00:00:00 2001 From: pascoec <123595534+pascoec@users.noreply.github.com> Date: Thu, 30 Apr 2026 16:33:02 -0400 Subject: [PATCH 3/3] omp parallelization for AutomorphismTransform() (#1178) --- benchmark/src/lib-benchmark.cpp | 140 +++++++++++++----- .../lattice/hal/default/dcrtpoly-impl.h | 49 +++--- src/pke/lib/schemebase/base-advancedshe.cpp | 14 +- src/pke/lib/schemebase/base-leveledshe.cpp | 17 +-- 4 files changed, 135 insertions(+), 85 deletions(-) diff --git a/benchmark/src/lib-benchmark.cpp b/benchmark/src/lib-benchmark.cpp index 461686357..08c897320 100644 --- a/benchmark/src/lib-benchmark.cpp +++ b/benchmark/src/lib-benchmark.cpp @@ -66,7 +66,7 @@ using namespace lbcrypto; parameters.SetPlaintextModulus(65537); parameters.SetScalingModSize(60); parameters.SetMultiplicativeDepth(mdepth); - CryptoContext cc = GenCryptoContext(parameters); + auto cc = GenCryptoContext(parameters); cc->Enable(PKE); cc->Enable(KEYSWITCH); cc->Enable(LEVELEDSHE); @@ -92,7 +92,7 @@ using namespace lbcrypto; parameters.SetMaxRelinSkDeg(1); parameters.SetScalingTechnique(FIXEDMANUAL); parameters.SetMultiplicativeDepth(mdepth); - CryptoContext cc = GenCryptoContext(parameters); + auto cc = GenCryptoContext(parameters); cc->Enable(PKE); cc->Enable(KEYSWITCH); cc->Enable(LEVELEDSHE); @@ -196,7 +196,7 @@ BENCHMARK(NativeINTTInPlace)->Unit(benchmark::kMicrosecond)->Apply(RingArgs); / * BFVrns benchmarks */ -void BFVrns_KeyGen(benchmark::State& state) { +[[maybe_unused]] void BFVrns_KeyGen(benchmark::State& state) { CryptoContext cryptoContext = GenerateBFVrnsContext(); KeyPair keyPair; @@ -208,7 +208,7 @@ void BFVrns_KeyGen(benchmark::State& state) { BENCHMARK(BFVrns_KeyGen)->Unit(benchmark::kMicrosecond); -void BFVrns_MultKeyGen(benchmark::State& state) { +[[maybe_unused]] void BFVrns_MultKeyGen(benchmark::State& state) { CryptoContext cc = GenerateBFVrnsContext(); KeyPair keyPair; @@ -222,7 +222,7 @@ void BFVrns_MultKeyGen(benchmark::State& state) { BENCHMARK(BFVrns_MultKeyGen)->Unit(benchmark::kMicrosecond); // TODO: revisit this? -void BFVrns_EvalAtIndexKeyGen(benchmark::State& state) { +[[maybe_unused]] void BFVrns_EvalAtIndexKeyGen(benchmark::State& state) { CryptoContext cc = GenerateBFVrnsContext(); KeyPair keyPair; @@ -240,7 +240,7 @@ void BFVrns_EvalAtIndexKeyGen(benchmark::State& state) { BENCHMARK(BFVrns_EvalAtIndexKeyGen)->Unit(benchmark::kMicrosecond); -void BFVrns_Encryption(benchmark::State& state) { +[[maybe_unused]] void BFVrns_Encryption(benchmark::State& state) { CryptoContext cryptoContext = GenerateBFVrnsContext(); KeyPair keyPair = cryptoContext->KeyGen(); @@ -255,7 +255,7 @@ void BFVrns_Encryption(benchmark::State& state) { BENCHMARK(BFVrns_Encryption)->Unit(benchmark::kMicrosecond); -void BFVrns_Decryption(benchmark::State& state) { +[[maybe_unused]] void BFVrns_Decryption(benchmark::State& state) { CryptoContext cryptoContext = GenerateBFVrnsContext(); KeyPair keyPair = cryptoContext->KeyGen(); @@ -273,7 +273,7 @@ void BFVrns_Decryption(benchmark::State& state) { BENCHMARK(BFVrns_Decryption)->Unit(benchmark::kMicrosecond); -void BFVrns_Add(benchmark::State& state) { +[[maybe_unused]] void BFVrns_Add(benchmark::State& state) { CryptoContext cc = GenerateBFVrnsContext(); KeyPair keyPair = cc->KeyGen(); @@ -294,7 +294,7 @@ void BFVrns_Add(benchmark::State& state) { BENCHMARK(BFVrns_Add)->Unit(benchmark::kMicrosecond); -void BFVrns_AddInPlace(benchmark::State& state) { +[[maybe_unused]] void BFVrns_AddInPlace(benchmark::State& state) { CryptoContext cc = GenerateBFVrnsContext(); KeyPair keyPair = cc->KeyGen(); @@ -315,7 +315,7 @@ void BFVrns_AddInPlace(benchmark::State& state) { BENCHMARK(BFVrns_AddInPlace)->Unit(benchmark::kMicrosecond); -void BFVrns_MultNoRelin(benchmark::State& state) { +[[maybe_unused]] void BFVrns_MultNoRelin(benchmark::State& state) { CryptoContext cryptoContext = GenerateBFVrnsContext(state.range(0)); KeyPair keyPair = cryptoContext->KeyGen(); @@ -338,7 +338,7 @@ void BFVrns_MultNoRelin(benchmark::State& state) { BENCHMARK(BFVrns_MultNoRelin)->Unit(benchmark::kMicrosecond)->Apply(DepthArgs); // ->Complexity(benchmark::oAuto); -void BFVrns_MultRelin(benchmark::State& state) { +[[maybe_unused]] void BFVrns_MultRelin(benchmark::State& state) { CryptoContext cryptoContext = GenerateBFVrnsContext(state.range(0)); KeyPair keyPair = cryptoContext->KeyGen(); @@ -362,7 +362,7 @@ void BFVrns_MultRelin(benchmark::State& state) { BENCHMARK(BFVrns_MultRelin)->Unit(benchmark::kMicrosecond)->Apply(DepthArgs); // ->Complexity(benchmark::oAuto); -void BFVrns_EvalAtIndex(benchmark::State& state) { +[[maybe_unused]] void BFVrns_EvalAtIndex(benchmark::State& state) { CryptoContext cc = GenerateBFVrnsContext(); KeyPair keyPair = cc->KeyGen(); @@ -393,11 +393,31 @@ void BFVrns_EvalAtIndex(benchmark::State& state) { BENCHMARK(BFVrns_EvalAtIndex)->Unit(benchmark::kMicrosecond); +[[maybe_unused]] void BFVrns_EvalFastRotation(benchmark::State& state) { + auto cc = GenerateBFVrnsContext(state.range(0)); + + auto keys = cc->KeyGen(); + cc->EvalRotateKeyGen(keys.secretKey, {1}); + + std::vector x{1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0}; + auto ptxt = cc->MakePackedPlaintext(x); + + auto c = cc->Encrypt(keys.publicKey, ptxt); + + auto cPrecomp = cc->EvalFastRotationPrecompute(c); + + while (state.KeepRunning()) { + auto res = cc->EvalFastRotation(c, 1, 2 * cc->GetRingDimension(), cPrecomp); + } +} + +BENCHMARK(BFVrns_EvalFastRotation)->Unit(benchmark::kMicrosecond)->Apply(DepthArgs); + /* * CKKS benchmarks * */ -void CKKSrns_KeyGen(benchmark::State& state) { +[[maybe_unused]] void CKKSrns_KeyGen(benchmark::State& state) { CryptoContext cryptoContext = GenerateCKKSContext(); KeyPair keyPair; @@ -409,7 +429,7 @@ void CKKSrns_KeyGen(benchmark::State& state) { BENCHMARK(CKKSrns_KeyGen)->Unit(benchmark::kMicrosecond); -void CKKSrns_MultKeyGen(benchmark::State& state) { +[[maybe_unused]] void CKKSrns_MultKeyGen(benchmark::State& state) { CryptoContext cc = GenerateCKKSContext(); KeyPair keyPair; @@ -422,7 +442,7 @@ void CKKSrns_MultKeyGen(benchmark::State& state) { BENCHMARK(CKKSrns_MultKeyGen)->Unit(benchmark::kMicrosecond); -void CKKSrns_EvalAtIndexKeyGen(benchmark::State& state) { +[[maybe_unused]] void CKKSrns_EvalAtIndexKeyGen(benchmark::State& state) { CryptoContext cc = GenerateCKKSContext(); KeyPair keyPair; @@ -440,7 +460,7 @@ void CKKSrns_EvalAtIndexKeyGen(benchmark::State& state) { BENCHMARK(CKKSrns_EvalAtIndexKeyGen)->Unit(benchmark::kMicrosecond); -void CKKSrns_Encryption(benchmark::State& state) { +[[maybe_unused]] void CKKSrns_Encryption(benchmark::State& state) { CryptoContext cc = GenerateCKKSContext(); KeyPair keyPair = cc->KeyGen(); @@ -460,7 +480,7 @@ void CKKSrns_Encryption(benchmark::State& state) { BENCHMARK(CKKSrns_Encryption)->Unit(benchmark::kMicrosecond); -void CKKSrns_Decryption(benchmark::State& state) { +[[maybe_unused]] void CKKSrns_Decryption(benchmark::State& state) { CryptoContext cc = GenerateCKKSContext(); KeyPair keyPair = cc->KeyGen(); @@ -484,7 +504,7 @@ void CKKSrns_Decryption(benchmark::State& state) { BENCHMARK(CKKSrns_Decryption)->Unit(benchmark::kMicrosecond); -void CKKSrns_Add(benchmark::State& state) { +[[maybe_unused]] void CKKSrns_Add(benchmark::State& state) { CryptoContext cc = GenerateCKKSContext(); KeyPair keyPair = cc->KeyGen(); @@ -509,7 +529,7 @@ void CKKSrns_Add(benchmark::State& state) { BENCHMARK(CKKSrns_Add)->Unit(benchmark::kMicrosecond); -void CKKSrns_AddInPlace(benchmark::State& state) { +[[maybe_unused]] void CKKSrns_AddInPlace(benchmark::State& state) { CryptoContext cc = GenerateCKKSContext(); KeyPair keyPair = cc->KeyGen(); @@ -534,7 +554,7 @@ void CKKSrns_AddInPlace(benchmark::State& state) { BENCHMARK(CKKSrns_AddInPlace)->Unit(benchmark::kMicrosecond); -void CKKSrns_MultNoRelin(benchmark::State& state) { +[[maybe_unused]] void CKKSrns_MultNoRelin(benchmark::State& state) { CryptoContext cc = GenerateCKKSContext(state.range(0)); KeyPair keyPair = cc->KeyGen(); @@ -561,7 +581,7 @@ void CKKSrns_MultNoRelin(benchmark::State& state) { BENCHMARK(CKKSrns_MultNoRelin)->Unit(benchmark::kMicrosecond)->Apply(DepthArgs); // ->Complexity(benchmark::oAuto); -void CKKSrns_MultRelin(benchmark::State& state) { +[[maybe_unused]] void CKKSrns_MultRelin(benchmark::State& state) { CryptoContext cc = GenerateCKKSContext(state.range(0)); KeyPair keyPair = cc->KeyGen(); @@ -589,7 +609,7 @@ void CKKSrns_MultRelin(benchmark::State& state) { BENCHMARK(CKKSrns_MultRelin)->Unit(benchmark::kMicrosecond)->Apply(DepthArgs); // ->Complexity(benchmark::oAuto); -void CKKSrns_Relin(benchmark::State& state) { +[[maybe_unused]] void CKKSrns_Relin(benchmark::State& state) { CryptoContext cc = GenerateCKKSContext(); KeyPair keyPair = cc->KeyGen(); @@ -617,7 +637,7 @@ void CKKSrns_Relin(benchmark::State& state) { BENCHMARK(CKKSrns_Relin)->Unit(benchmark::kMicrosecond); -void CKKSrns_RelinInPlace(benchmark::State& state) { +[[maybe_unused]] void CKKSrns_RelinInPlace(benchmark::State& state) { CryptoContext cc = GenerateCKKSContext(); KeyPair keyPair = cc->KeyGen(); @@ -649,7 +669,7 @@ void CKKSrns_RelinInPlace(benchmark::State& state) { BENCHMARK(CKKSrns_RelinInPlace)->Unit(benchmark::kMicrosecond); -void CKKSrns_Rescale(benchmark::State& state) { +[[maybe_unused]] void CKKSrns_Rescale(benchmark::State& state) { CryptoContext cc = GenerateCKKSContext(); KeyPair keyPair = cc->KeyGen(); @@ -677,7 +697,7 @@ void CKKSrns_Rescale(benchmark::State& state) { BENCHMARK(CKKSrns_Rescale)->Unit(benchmark::kMicrosecond); -void CKKSrns_RescaleInPlace(benchmark::State& state) { +[[maybe_unused]] void CKKSrns_RescaleInPlace(benchmark::State& state) { CryptoContext cc = GenerateCKKSContext(); KeyPair keyPair = cc->KeyGen(); @@ -704,7 +724,7 @@ void CKKSrns_RescaleInPlace(benchmark::State& state) { BENCHMARK(CKKSrns_RescaleInPlace)->Unit(benchmark::kMicrosecond); -void CKKSrns_EvalAtIndex(benchmark::State& state) { +[[maybe_unused]] void CKKSrns_EvalAtIndex(benchmark::State& state) { CryptoContext cc = GenerateCKKSContext(); KeyPair keyPair = cc->KeyGen(); @@ -739,11 +759,31 @@ void CKKSrns_EvalAtIndex(benchmark::State& state) { BENCHMARK(CKKSrns_EvalAtIndex)->Unit(benchmark::kMicrosecond); +[[maybe_unused]] void CKKSrns_EvalFastRotation(benchmark::State& state) { + auto cc = GenerateCKKSContext(state.range(0)); + + auto keys = cc->KeyGen(); + cc->EvalRotateKeyGen(keys.secretKey, {1}); + + std::vector x{0, 0, 0, 0, 0, 0, 0, 1}; + auto ptxt = cc->MakeCKKSPackedPlaintext(x); + + auto c = cc->Encrypt(keys.publicKey, ptxt); + + auto cPrecomp = cc->EvalFastRotationPrecompute(c); + + while (state.KeepRunning()) { + auto res = cc->EvalFastRotation(c, 1, 2 * cc->GetRingDimension(), cPrecomp); + } +} + +BENCHMARK(CKKSrns_EvalFastRotation)->Unit(benchmark::kMicrosecond)->Apply(DepthArgs); + /* * BGVrns benchmarks * */ -void BGVrns_KeyGen(benchmark::State& state) { +[[maybe_unused]] void BGVrns_KeyGen(benchmark::State& state) { CryptoContext cryptoContext = GenerateBGVrnsContext(); KeyPair keyPair; @@ -755,7 +795,7 @@ void BGVrns_KeyGen(benchmark::State& state) { BENCHMARK(BGVrns_KeyGen)->Unit(benchmark::kMicrosecond); -void BGVrns_MultKeyGen(benchmark::State& state) { +[[maybe_unused]] void BGVrns_MultKeyGen(benchmark::State& state) { CryptoContext cc = GenerateBGVrnsContext(); KeyPair keyPair; @@ -768,7 +808,7 @@ void BGVrns_MultKeyGen(benchmark::State& state) { BENCHMARK(BGVrns_MultKeyGen)->Unit(benchmark::kMicrosecond); -void BGVrns_EvalAtIndexKeyGen(benchmark::State& state) { +[[maybe_unused]] void BGVrns_EvalAtIndexKeyGen(benchmark::State& state) { CryptoContext cc = GenerateBGVrnsContext(); KeyPair keyPair; @@ -786,7 +826,7 @@ void BGVrns_EvalAtIndexKeyGen(benchmark::State& state) { BENCHMARK(BGVrns_EvalAtIndexKeyGen)->Unit(benchmark::kMicrosecond); -void BGVrns_Encryption(benchmark::State& state) { +[[maybe_unused]] void BGVrns_Encryption(benchmark::State& state) { CryptoContext cryptoContext = GenerateBGVrnsContext(); KeyPair keyPair = cryptoContext->KeyGen(); @@ -801,7 +841,7 @@ void BGVrns_Encryption(benchmark::State& state) { BENCHMARK(BGVrns_Encryption)->Unit(benchmark::kMicrosecond); -void BGVrns_Decryption(benchmark::State& state) { +[[maybe_unused]] void BGVrns_Decryption(benchmark::State& state) { CryptoContext cc = GenerateBGVrnsContext(); KeyPair keyPair = cc->KeyGen(); @@ -821,7 +861,7 @@ void BGVrns_Decryption(benchmark::State& state) { BENCHMARK(BGVrns_Decryption)->Unit(benchmark::kMicrosecond); -void BGVrns_Add(benchmark::State& state) { +[[maybe_unused]] void BGVrns_Add(benchmark::State& state) { CryptoContext cc = GenerateBGVrnsContext(); KeyPair keyPair = cc->KeyGen(); @@ -842,7 +882,7 @@ void BGVrns_Add(benchmark::State& state) { BENCHMARK(BGVrns_Add)->Unit(benchmark::kMicrosecond); -void BGVrns_AddInPlace(benchmark::State& state) { +[[maybe_unused]] void BGVrns_AddInPlace(benchmark::State& state) { CryptoContext cc = GenerateBGVrnsContext(); KeyPair keyPair = cc->KeyGen(); @@ -863,7 +903,7 @@ void BGVrns_AddInPlace(benchmark::State& state) { BENCHMARK(BGVrns_AddInPlace)->Unit(benchmark::kMicrosecond); -void BGVrns_MultNoRelin(benchmark::State& state) { +[[maybe_unused]] void BGVrns_MultNoRelin(benchmark::State& state) { CryptoContext cc = GenerateBGVrnsContext(state.range(0)); KeyPair keyPair = cc->KeyGen(); @@ -886,7 +926,7 @@ void BGVrns_MultNoRelin(benchmark::State& state) { BENCHMARK(BGVrns_MultNoRelin)->Unit(benchmark::kMicrosecond)->Apply(DepthArgs); // ->Complexity(benchmark::oAuto); -void BGVrns_MultRelin(benchmark::State& state) { +[[maybe_unused]] void BGVrns_MultRelin(benchmark::State& state) { CryptoContext cc = GenerateBGVrnsContext(state.range(0)); KeyPair keyPair = cc->KeyGen(); @@ -910,7 +950,7 @@ void BGVrns_MultRelin(benchmark::State& state) { BENCHMARK(BGVrns_MultRelin)->Unit(benchmark::kMicrosecond)->Apply(DepthArgs); // ->Complexity(benchmark::oAuto); -void BGVrns_Relin(benchmark::State& state) { +[[maybe_unused]] void BGVrns_Relin(benchmark::State& state) { CryptoContext cc = GenerateBGVrnsContext(); KeyPair keyPair = cc->KeyGen(); @@ -934,7 +974,7 @@ void BGVrns_Relin(benchmark::State& state) { BENCHMARK(BGVrns_Relin)->Unit(benchmark::kMicrosecond); -void BGVrns_RelinInPlace(benchmark::State& state) { +[[maybe_unused]] void BGVrns_RelinInPlace(benchmark::State& state) { CryptoContext cc = GenerateBGVrnsContext(); KeyPair keyPair = cc->KeyGen(); @@ -962,7 +1002,7 @@ void BGVrns_RelinInPlace(benchmark::State& state) { BENCHMARK(BGVrns_RelinInPlace)->Unit(benchmark::kMicrosecond); -void BGVrns_ModSwitch(benchmark::State& state) { +[[maybe_unused]] void BGVrns_ModSwitch(benchmark::State& state) { CryptoContext cc = GenerateBGVrnsContext(); KeyPair keyPair = cc->KeyGen(); @@ -986,7 +1026,7 @@ void BGVrns_ModSwitch(benchmark::State& state) { BENCHMARK(BGVrns_ModSwitch)->Unit(benchmark::kMicrosecond); -void BGVrns_ModSwitchInPlace(benchmark::State& state) { +[[maybe_unused]] void BGVrns_ModSwitchInPlace(benchmark::State& state) { CryptoContext cc = GenerateBGVrnsContext(); KeyPair keyPair = cc->KeyGen(); @@ -1009,7 +1049,7 @@ void BGVrns_ModSwitchInPlace(benchmark::State& state) { BENCHMARK(BGVrns_ModSwitchInPlace)->Unit(benchmark::kMicrosecond); -void BGVrns_EvalAtIndex(benchmark::State& state) { +[[maybe_unused]] void BGVrns_EvalAtIndex(benchmark::State& state) { CryptoContext cc = GenerateBGVrnsContext(); KeyPair keyPair = cc->KeyGen(); @@ -1040,4 +1080,24 @@ void BGVrns_EvalAtIndex(benchmark::State& state) { BENCHMARK(BGVrns_EvalAtIndex)->Unit(benchmark::kMicrosecond); +[[maybe_unused]] void BGVrns_EvalFastRotation(benchmark::State& state) { + auto cc = GenerateBGVrnsContext(state.range(0)); + + auto keys = cc->KeyGen(); + cc->EvalRotateKeyGen(keys.secretKey, {1}); + + std::vector x{1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0}; + auto ptxt = cc->MakePackedPlaintext(x); + + auto c = cc->Encrypt(keys.publicKey, ptxt); + + auto cPrecomp = cc->EvalFastRotationPrecompute(c); + + while (state.KeepRunning()) { + auto res = cc->EvalFastRotation(c, 1, 2 * cc->GetRingDimension(), cPrecomp); + } +} + +BENCHMARK(BGVrns_EvalFastRotation)->Unit(benchmark::kMicrosecond)->Apply(DepthArgs); + BENCHMARK_MAIN(); diff --git a/src/core/include/lattice/hal/default/dcrtpoly-impl.h b/src/core/include/lattice/hal/default/dcrtpoly-impl.h index 2bb592d77..384d57bc3 100644 --- a/src/core/include/lattice/hal/default/dcrtpoly-impl.h +++ b/src/core/include/lattice/hal/default/dcrtpoly-impl.h @@ -311,25 +311,24 @@ std::vector> DCRTPolyImpl::PowersOfBase(uint32_t } template -DCRTPolyImpl DCRTPolyImpl::AutomorphismTransform(uint32_t i) const { - DCRTPolyImpl result; - result.m_params = m_params; - result.m_format = m_format; - result.m_vectors.reserve(m_vectors.size()); - for (const auto& v : m_vectors) - result.m_vectors.emplace_back(v.AutomorphismTransform(i)); - return result; +DCRTPolyImpl DCRTPolyImpl::AutomorphismTransform(uint32_t idx) const { + DCRTPolyImpl tmp(m_params, m_format); + uint32_t size(m_vectors.size()); +#pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(size)) + for (uint32_t i = 0; i < size; ++i) + tmp.m_vectors[i] = m_vectors[i].AutomorphismTransform(idx); + return tmp; } template -DCRTPolyImpl DCRTPolyImpl::AutomorphismTransform(uint32_t i, const std::vector& vec) const { - DCRTPolyImpl result; - result.m_params = m_params; - result.m_format = m_format; - result.m_vectors.reserve(m_vectors.size()); - for (const auto& v : m_vectors) - result.m_vectors.emplace_back(v.AutomorphismTransform(i, vec)); - return result; +DCRTPolyImpl DCRTPolyImpl::AutomorphismTransform(uint32_t idx, + const std::vector& vec) const { + DCRTPolyImpl tmp(m_params, m_format); + uint32_t size(m_vectors.size()); +#pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(size)) + for (uint32_t i = 0; i < size; ++i) + tmp.m_vectors[i] = m_vectors[i].AutomorphismTransform(idx, vec); + return tmp; } template @@ -970,7 +969,7 @@ DCRTPolyImpl DCRTPolyImpl::ApproxModDown( const std::vector>& PHatModq, const std::vector& modqBarrettMu, const std::vector& tInvModp, const std::vector& tInvModpPrecon, const NativeInteger& t, const std::vector& tModqPrecon) const { - DCRTPolyImpl partP(paramsP, m_format, true); + DCRTPolyImpl partP(paramsP, m_format); uint32_t sizeP = paramsP->GetParams().size(); uint32_t sizeQ = m_vectors.size() - sizeP; @@ -983,23 +982,19 @@ DCRTPolyImpl DCRTPolyImpl::ApproxModDown( partP.m_vectors[j] *= tInvModp[j]; } partP.OverrideFormat(Format::COEFFICIENT); + partP = partP.ApproxSwitchCRTBasis(paramsP, paramsQ, PHatInvModp, PHatInvModpPrecon, PHatModq, modqBarrettMu); - auto partPSwitchedToQ = - partP.ApproxSwitchCRTBasis(paramsP, paramsQ, PHatInvModp, PHatInvModpPrecon, PHatModq, modqBarrettMu); - - // Combine the switched DCRTPoly with the Q part of this to get the result - DCRTPolyImpl ans(paramsQ, Format::EVALUATION, true); - uint32_t diffQ = paramsQ->GetParams().size() - sizeQ; - if (diffQ > 0) + DCRTPolyImpl ans(paramsQ, Format::EVALUATION); + if (uint32_t diffQ = paramsQ->GetParams().size() - sizeQ; diffQ != 0) ans.DropLastElements(diffQ); #pragma omp parallel for num_threads(OpenFHEParallelControls.GetThreadLimit(sizeQ)) for (uint32_t i = 0; i < sizeQ; ++i) { // Multiply everything by t mod Q (BGVrns only) if (t > 0) - partPSwitchedToQ.m_vectors[i] *= t; - partPSwitchedToQ.m_vectors[i].SetFormat(Format::EVALUATION); - ans.m_vectors[i] = (m_vectors[i] - partPSwitchedToQ.m_vectors[i]) * PInvModq[i]; + partP.m_vectors[i] *= t; + partP.m_vectors[i].SetFormat(Format::EVALUATION); + ans.m_vectors[i] = (m_vectors[i] - partP.m_vectors[i]) * PInvModq[i]; } return ans; } diff --git a/src/pke/lib/schemebase/base-advancedshe.cpp b/src/pke/lib/schemebase/base-advancedshe.cpp index f97795674..c8a6a27c0 100644 --- a/src/pke/lib/schemebase/base-advancedshe.cpp +++ b/src/pke/lib/schemebase/base-advancedshe.cpp @@ -216,7 +216,7 @@ std::shared_ptr>> AdvancedSHEBase:: OPENFHE_THROW("Matrix summation of column-vectors is only supported for CKKSPackedEncoding."); const auto cryptoParams = privateKey->GetCryptoParameters(); - uint32_t M = cryptoParams->GetElementParams()->GetCyclotomicOrder(); + uint32_t M = cryptoParams->GetElementParams()->GetCyclotomicOrder(); if (!IsPowerOfTwo(M)) OPENFHE_THROW("Matrix summation of column-vectors is not supported for arbitrary cyclotomics."); @@ -266,8 +266,7 @@ Ciphertext AdvancedSHEBase::EvalSum(ConstCiphertext c uint32_t g = encodingParams->GetPlaintextGenerator(); for (int i = 0; i < std::floor(std::log2(batchSize)); i++) { - auto ea = algo->EvalAutomorphism(newCiphertext, g, evalKeyMap); - newCiphertext = algo->EvalAdd(newCiphertext, ea); + newCiphertext = algo->EvalAdd(newCiphertext, algo->EvalAutomorphism(newCiphertext, g, evalKeyMap)); g = (g * g) % m; } } @@ -340,10 +339,9 @@ Ciphertext AdvancedSHEBase::EvalSumCols( } template -Ciphertext AdvancedSHEBase::EvalInnerProduct(ConstCiphertext ciphertext1, - ConstCiphertext ciphertext2, uint32_t batchSize, - const std::map>& evalSumKeyMap, - const EvalKey evalMultKey) const { +Ciphertext AdvancedSHEBase::EvalInnerProduct( + ConstCiphertext ciphertext1, ConstCiphertext ciphertext2, uint32_t batchSize, + const std::map>& evalSumKeyMap, const EvalKey evalMultKey) const { auto algo = ciphertext1->GetCryptoContext()->GetScheme(); Ciphertext result = algo->EvalMult(ciphertext1, ciphertext2, evalMultKey); @@ -412,7 +410,7 @@ std::set AdvancedSHEBase::GenerateIndices_2n(uint32_t batchSi std::set indices; if (batchSize > 1) { auto isize = static_cast(std::ceil(std::log2(batchSize)) - 1); - uint32_t g = 5; + uint32_t g = 5; for (size_t i = 0; i < isize; ++i) { indices.insert(g); g = (g * g) % m; diff --git a/src/pke/lib/schemebase/base-leveledshe.cpp b/src/pke/lib/schemebase/base-leveledshe.cpp index 5a7af3a64..b029ed902 100644 --- a/src/pke/lib/schemebase/base-leveledshe.cpp +++ b/src/pke/lib/schemebase/base-leveledshe.cpp @@ -409,12 +409,12 @@ Ciphertext LeveledSHEBase::EvalAutomorphism(ConstCiphertextClone(); - ciphertext->GetCryptoContext()->GetScheme()->KeySwitchInPlace(result, evalKeyIterator->second); - std::vector vec(N); PrecomputeAutoMap(N, i, &vec); + auto result = ciphertext->Clone(); + result->GetCryptoContext()->GetScheme()->KeySwitchInPlace(result, evalKeyIterator->second); + auto& rcv = result->GetElements(); rcv[0] = rcv[0].AutomorphismTransform(i, vec); rcv[1] = rcv[1].AutomorphismTransform(i, vec); @@ -442,18 +442,15 @@ Ciphertext LeveledSHEBase::EvalFastRotation( auto evalKeyIterator = evalKeyMap.find(autoIndex); if (evalKeyIterator == evalKeyMap.end()) OPENFHE_THROW("EvalKey for index [" + std::to_string(autoIndex) + "] is not found."); - auto evalKey = evalKeyIterator->second; - - const auto cryptoParams = ciphertext->GetCryptoParameters(); - const uint32_t N = cryptoParams->GetElementParams()->GetRingDimension(); + const uint32_t N = cc->GetRingDimension(); std::vector vec(N); PrecomputeAutoMap(N, autoIndex, &vec); - const auto& cv = ciphertext->GetElements(); + const auto& cv0 = ciphertext->GetElements()[0]; - auto ba = *cc->GetScheme()->EvalFastKeySwitchCore(digits, evalKey, cv[0].GetParams()); - ba[0] += cv[0]; + auto ba = *cc->GetScheme()->EvalFastKeySwitchCore(digits, evalKeyIterator->second, cv0.GetParams()); + ba[0] += cv0; ba[0] = ba[0].AutomorphismTransform(autoIndex, vec); ba[1] = ba[1].AutomorphismTransform(autoIndex, vec);