ntt_parameters.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright 2017 Google LLC.
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * https://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #include "ntt_parameters.h"
  16. namespace rlwe {
  17. namespace internal {
  18. // Bit reverse only among the rightmost log_n bytes.
  19. unsigned int Bitrev(unsigned int input, unsigned int log_n) {
  20. unsigned int output = 0;
  21. for (unsigned int i = 0; i < log_n; i++) {
  22. output <<= 1;
  23. output |= input & 0x01;
  24. input >>= 1;
  25. }
  26. return output;
  27. }
  28. std::vector<unsigned int> BitrevArray(unsigned int log_n) {
  29. unsigned int n = 1 << log_n;
  30. std::vector<unsigned int> output(n);
  31. for (unsigned int i = 0; i < n; i++) {
  32. output[i] = Bitrev(i, log_n);
  33. }
  34. return output;
  35. }
  36. } // namespace internal
  37. } // namespace rlwe