Skip to content

Commit

Permalink
BEHZ multiplication works now
Browse files Browse the repository at this point in the history
  • Loading branch information
kimlaine committed Apr 8, 2020
1 parent bc6f1ff commit daa262d
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 173 deletions.
2 changes: 1 addition & 1 deletion native/src/seal/ciphertext.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#include <cstdint>
#include <functional>
#include <iostream>
#include <iterator>
#include <memory>
#include <stdexcept>
#include <iterator>
#include <string>

namespace seal
Expand Down
2 changes: 1 addition & 1 deletion native/src/seal/decryptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace seal
// Allocate a full size destination to write to
destination.resize(coeff_count);

// Divide scaling variant using Bajard FullRNS techniques
// Divide scaling variant using BEHZ FullRNS techniques
context_data.rns_tool()->decrypt_scale_and_round(tmp_dest_modq.get(), destination.data(), pool);

// How many non-zero coefficients do we really have in the result?
Expand Down
294 changes: 139 additions & 155 deletions native/src/seal/evaluator.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions native/src/seal/intarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace seal
namespace ztools
{
SEAL_NODISCARD std::size_t deflate_size_bound(std::size_t in_size) noexcept;
} // namespace ztools
} // namespace util
} // namespace ztools
} // namespace util

/**
A resizable container for storing an array of arithmetic data types or
Expand Down
4 changes: 2 additions & 2 deletions native/src/seal/util/rns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ namespace seal

// We need to multiply first the input with m_tilde mod q
// This is to facilitate Montgomery reduction in the next step of multiplication
// This is NOT an ideal approach: as mentioned in Bajard et al., multiplication by
// This is NOT an ideal approach: as mentioned in BEHZ16, multiplication by
// m_tilde can be easily merge into the base conversion operation; however, then
// we could not use the BaseConvTool as below without modifications.
auto temp(allocate_poly(coeff_count_, base_q_size, pool));
Expand Down Expand Up @@ -1175,4 +1175,4 @@ namespace seal
}
}
} // namespace util
} // namespace seal
} // namespace seal
23 changes: 11 additions & 12 deletions native/src/seal/util/smallntt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,28 +190,28 @@ namespace seal
for (size_t j = j1; j < j2; j += 4)
{
tx = *X - (two_times_modulus &
static_cast<uint64_t>(-static_cast<int64_t>(*X >= two_times_modulus)));
static_cast<uint64_t>(-static_cast<int64_t>(*X >= two_times_modulus)));
multiply_uint64_hw64(Wprime, *Y, &Q);
Q = *Y * W - Q * modulus;
*X++ = tx + Q;
*Y++ = tx + two_times_modulus - Q;

tx = *X - (two_times_modulus &
static_cast<uint64_t>(-static_cast<int64_t>(*X >= two_times_modulus)));
static_cast<uint64_t>(-static_cast<int64_t>(*X >= two_times_modulus)));
multiply_uint64_hw64(Wprime, *Y, &Q);
Q = *Y * W - Q * modulus;
*X++ = tx + Q;
*Y++ = tx + two_times_modulus - Q;

tx = *X - (two_times_modulus &
static_cast<uint64_t>(-static_cast<int64_t>(*X >= two_times_modulus)));
static_cast<uint64_t>(-static_cast<int64_t>(*X >= two_times_modulus)));
multiply_uint64_hw64(Wprime, *Y, &Q);
Q = *Y * W - Q * modulus;
*X++ = tx + Q;
*Y++ = tx + two_times_modulus - Q;

tx = *X - (two_times_modulus &
static_cast<uint64_t>(-static_cast<int64_t>(*X >= two_times_modulus)));
static_cast<uint64_t>(-static_cast<int64_t>(*X >= two_times_modulus)));
multiply_uint64_hw64(Wprime, *Y, &Q);
Q = *Y * W - Q * modulus;
*X++ = tx + Q;
Expand All @@ -237,7 +237,7 @@ namespace seal
// The Harvey butterfly: assume X, Y in [0, 2p), and return X', Y' in [0, 4p).
// X', Y' = X + WY, X - WY (mod p).
tx = *X - (two_times_modulus &
static_cast<uint64_t>(-static_cast<int64_t>(*X >= two_times_modulus)));
static_cast<uint64_t>(-static_cast<int64_t>(*X >= two_times_modulus)));
multiply_uint64_hw64(Wprime, *Y, &Q);
Q = W * *Y - Q * modulus;
*X++ = tx + Q;
Expand Down Expand Up @@ -287,28 +287,28 @@ namespace seal
tx = *X + *Y;
ty = *X + two_times_modulus - *Y;
*X++ = tx - (two_times_modulus &
static_cast<uint64_t>(-static_cast<int64_t>(tx >= two_times_modulus)));
static_cast<uint64_t>(-static_cast<int64_t>(tx >= two_times_modulus)));
multiply_uint64_hw64(Wprime, ty, &Q);
*Y++ = ty * W - Q * modulus;

tx = *X + *Y;
ty = *X + two_times_modulus - *Y;
*X++ = tx - (two_times_modulus &
static_cast<uint64_t>(-static_cast<int64_t>(tx >= two_times_modulus)));
static_cast<uint64_t>(-static_cast<int64_t>(tx >= two_times_modulus)));
multiply_uint64_hw64(Wprime, ty, &Q);
*Y++ = ty * W - Q * modulus;

tx = *X + *Y;
ty = *X + two_times_modulus - *Y;
*X++ = tx - (two_times_modulus &
static_cast<uint64_t>(-static_cast<int64_t>(tx >= two_times_modulus)));
static_cast<uint64_t>(-static_cast<int64_t>(tx >= two_times_modulus)));
multiply_uint64_hw64(Wprime, ty, &Q);
*Y++ = ty * W - Q * modulus;

tx = *X + *Y;
ty = *X + two_times_modulus - *Y;
*X++ = tx - (two_times_modulus &
static_cast<uint64_t>(-static_cast<int64_t>(tx >= two_times_modulus)));
static_cast<uint64_t>(-static_cast<int64_t>(tx >= two_times_modulus)));
multiply_uint64_hw64(Wprime, ty, &Q);
*Y++ = ty * W - Q * modulus;
}
Expand All @@ -333,7 +333,7 @@ namespace seal
tx = *X + *Y;
ty = *X + two_times_modulus - *Y;
*X++ = tx - (two_times_modulus &
static_cast<uint64_t>(-static_cast<int64_t>(tx >= two_times_modulus)));
static_cast<uint64_t>(-static_cast<int64_t>(tx >= two_times_modulus)));
multiply_uint64_hw64(Wprime, ty, &Q);
*Y++ = ty * W - Q * modulus;
}
Expand Down Expand Up @@ -365,8 +365,7 @@ namespace seal
for (size_t j = (n >> 1); j < n; j++)
{
tx = *X + *Y;
tx -= two_times_modulus &
static_cast<uint64_t>(-static_cast<int64_t>(tx >= two_times_modulus));
tx -= two_times_modulus & static_cast<uint64_t>(-static_cast<int64_t>(tx >= two_times_modulus));
ty = *X + two_times_modulus - *Y;
multiply_uint64_hw64(inv_Nprime, tx, &Q);
*X++ = inv_N * tx - Q * modulus;
Expand Down
Empty file modified tools/scripts/clang-format-all.sh
100644 → 100755
Empty file.

0 comments on commit daa262d

Please sign in to comment.