Python-ELMO is a Python library which offers an encapsulation of the binary tool ELMO, in order to manipulate it easily in Python and SageMath script.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

  1. #include <stdint.h>
  2. #include "params.h"
  3. #include "ntt.h"
  4. #include "reduce.h"
  5. int16_t zetas[128] = {
  6. 2285, 2571, 2970, 1812, 1493, 1422, 287, 202, 3158, 622, 1577, 182, 962, 2127, 1855, 1468,
  7. 573, 2004, 264, 383, 2500, 1458, 1727, 3199, 2648, 1017, 732, 608, 1787, 411, 3124, 1758,
  8. 1223, 652, 2777, 1015, 2036, 1491, 3047, 1785, 516, 3321, 3009, 2663, 1711, 2167, 126, 1469,
  9. 2476, 3239, 3058, 830, 107, 1908, 3082, 2378, 2931, 961, 1821, 2604, 448, 2264, 677, 2054,
  10. 2226, 430, 555, 843, 2078, 871, 1550, 105, 422, 587, 177, 3094, 3038, 2869, 1574, 1653,
  11. 3083, 778, 1159, 3182, 2552, 1483, 2727, 1119, 1739, 644, 2457, 349, 418, 329, 3173, 3254,
  12. 817, 1097, 603, 610, 1322, 2044, 1864, 384, 2114, 3193, 1218, 1994, 2455, 220, 2142, 1670,
  13. 2144, 1799, 2051, 794, 1819, 2475, 2459, 478, 3221, 3021, 996, 991, 958, 1869, 1522, 1628};
  14. /*************************************************
  15. * Name: fqmul
  16. *
  17. * Description: Multiplication followed by Montgomery reduction
  18. *
  19. * Arguments: - int16_t a: first factor
  20. * - int16_t b: second factor
  21. *
  22. * Returns 16-bit integer congruent to a*b*R^{-1} mod q
  23. **************************************************/
  24. static int16_t fqmul(int16_t a, int16_t b) {
  25. return montgomery_reduce((int32_t)a*b);
  26. }
  27. /*************************************************
  28. * Name: ntt
  29. *
  30. * Description: Inplace number-theoretic transform (NTT) in Rq
  31. * input is in standard order, output is in bitreversed order
  32. *
  33. * Arguments: - int16_t r[256]: pointer to input/output vector of elements of Zq
  34. **************************************************/
  35. void ntt(int16_t r[256]) {
  36. unsigned int len, start, j, k;
  37. int16_t t, zeta;
  38. k = 1;
  39. for(len = 128; len >= 2; len >>= 1) {
  40. for(start = 0; start < 256; start = j + len) {
  41. zeta = zetas[k++];
  42. for(j = start; j < start + len; ++j) {
  43. t = fqmul(zeta, r[j + len]);
  44. r[j + len] = r[j] - t;
  45. r[j] = r[j] + t;
  46. }
  47. }
  48. }
  49. }