{"action":"created","comment":{"url":"https://api.github.com/repos/quarkslab/NFLlib/pulls/comments/60737994","id":60737994,"diff_hunk":"@@ -0,0 +1,149 @@\n+#include <iostream>\n+#include <nfl.hpp>\n+#include <string>\n+#include <vector>\n+#include \"tools.h\"\n+\n+template <size_t degree, size_t modulus, class T>\n+bool run() {\n+  using poly_t = nfl::poly_from_modulus<T, degree, modulus>;\n+\n+  bool ret_value = true;\n+\n+  // Set a random number generator\n+  // (we don't need a cryptographically secure random number generator)\n+  gmp_randclass prng(gmp_randinit_default);\n+  prng.seed(0);\n+\n+  // define a random polynomial\n+  poly_t& p0 = *alloc_aligned<poly_t, 32>(1, nfl::uniform());\n+\n+  // get the corresponding array of mpz_t\n+  mpz_t* coefficients = p0.poly2mpz();\n+\n+  // construct a polynomial from mpz_t coefficients\n+  poly_t& p1 = *alloc_aligned<poly_t, 32>(1, 0);\n+  p1.mpz2poly(coefficients);\n+\n+  // verify that the first and second polynomials are equal\n+  ret_value &= (p0 == p1);\n+\n+  // construct a vector of mpz_class\n+  std::vector<mpz_class> coefficients_mpz_class(poly_t::degree);\n+  for (size_t i = 0; i < poly_t::degree; i++) {\n+    coefficients_mpz_class[i] = mpz_class(coefficients[i]);\n+  }\n+\n+  // construct a polynomial from mpz_class coefficients\n+  poly_t& p2 = *alloc_aligned<poly_t, 32>(1, 0);\n+  p2.set_mpz(coefficients_mpz_class.begin(), coefficients_mpz_class.end());\n+\n+  // verify that the first and third polynomials are equal\n+  ret_value &= (p0 == p2);\n+\n+  // Generate a random vector of mpz_class\n+  std::vector<mpz_class> big_array;\n+  for (size_t i = 0; i < poly_t::nmoduli * poly_t::degree; i++) {\n+    // (say) 200 bits, it doesn't matter as long as it is > 64 bits for the\n+    // tests\n+    big_array.push_back(prng.get_z_bits(200));\n+  }\n+\n+  // construct a polynomial from the big_array vector\n+  poly_t& p3 = *alloc_aligned<poly_t, 32>(1, 0);\n+  p3.set_mpz(big_array.begin(), big_array.end());\n+\n+  // verify that the coefficients of the polynomial have been set correctly\n+  for (size_t cm = 0; cm < poly_t::nmoduli; cm++) {\n+    mpz_class modulus_mpz_class(std::to_string(poly_t::get_modulus(cm)));\n+    for (size_t i = 0; i < poly_t::degree; i++) {\n+      mpz_class coeff(std::to_string(p3(cm, i)));\n+      ret_value &=\n+          ((big_array[cm * poly_t::degree + i] % modulus_mpz_class) == coeff);\n+    }\n+  }\n+\n+  // Cleaning\n+  for (size_t i = 0; i < poly_t::degree; i++) {\n+    mpz_clear(coefficients[i]);\n+  }\n+  delete[] coefficients;\n+  free_aligned(1, &p0);\n+  free_aligned(1, &p1);\n+  free_aligned(1, &p2);\n+  free_aligned(1, &p3);\n+\n+  return ret_value;\n+}\n+\n+template <size_t degree, size_t modulus, class T>\n+bool run_p() {\n+  using poly_p = nfl::poly_p_from_modulus<T, degree, modulus>;\n+\n+  bool ret_value = true;\n+\n+  // Set a random number generator\n+  // (we don't need a cryptographically secure random number generator)\n+  gmp_randclass prng(gmp_randinit_default);\n+  prng.seed(0);\n+\n+  // define a random polynomial\n+  poly_p p0{nfl::uniform()};\n+\n+  // get the corresponding array of mpz_t\n+  mpz_t* coefficients = p0.poly2mpz();\n+\n+  // construct a polynomial from mpz_t coefficients\n+  poly_p p1;\n+  p1.mpz2poly(coefficients);\n+\n+  // verify that the first and second polynomials are equal\n+  ret_value &= (p0 == p1);\n+\n+  // construct a vector of mpz_class\n+  std::vector<mpz_class> coefficients_mpz_class(poly_p::degree);\n+  for (size_t i = 0; i < poly_p::degree; i++) {\n+    coefficients_mpz_class[i] = mpz_class(coefficients[i]);\n+  }\n+\n+  // construct a polynomial from mpz_class coefficients\n+  poly_p p2;\n+  p2.set_mpz(coefficients_mpz_class.begin(), coefficients_mpz_class.end());\n+\n+  // verify that the first and third polynomials are equal\n+  ret_value &= (p0 == p2);\n+\n+  // Generate a random vector of mpz_class\n+  std::vector<mpz_class> big_array;\n+  for (size_t i = 0; i < poly_p::nmoduli * poly_p::degree; i++) {\n+    // (say) 200 bits, it doesn't matter as long as it is > 64 bits for the\n+    // tests\n+    big_array.push_back(prng.get_z_bits(200));\n+  }\n+\n+  // construct a polynomial from the big_array vector\n+  poly_p p3;\n+  p3.set_mpz(big_array.begin(), big_array.end());\n+\n+  // verify that the coefficients of the polynomial have been set correctly\n+  for (size_t cm = 0; cm < poly_p::nmoduli; cm++) {\n+    mpz_class modulus_mpz_class(std::to_string(poly_p::get_modulus(cm)));\n+    for (size_t i = 0; i < poly_p::degree; i++) {\n+      mpz_class coeff(std::to_string(p3(cm, i)));\n+      ret_value &=\n+          ((big_array[cm * poly_p::degree + i] % modulus_mpz_class) == coeff);\n+    }\n+  }\n+\n+  // Cleaning\n+  for (size_t i = 0; i < poly_p::degree; i++) {\n+    mpz_clear(coefficients[i]);\n+  }\n+  delete[] coefficients;\n+\n+  return ret_value;\n+}\n+\n+int main(int argc, char const* argv[]) {","path":"tests/poly_mpz.cpp","position":147,"original_position":147,"commit_id":"63b4fc44c1ad7a9569519618bc46ebdb8ee66362","original_commit_id":"63b4fc44c1ad7a9569519618bc46ebdb8ee66362","user":{"login":"serge-sans-paille","id":863807,"avatar_url":"https://avatars.githubusercontent.com/u/863807?v=3","gravatar_id":"","url":"https://api.github.com/users/serge-sans-paille","html_url":"https://github.com/serge-sans-paille","followers_url":"https://api.github.com/users/serge-sans-paille/followers","following_url":"https://api.github.com/users/serge-sans-paille/following{/other_user}","gists_url":"https://api.github.com/users/serge-sans-paille/gists{/gist_id}","starred_url":"https://api.github.com/users/serge-sans-paille/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/serge-sans-paille/subscriptions","organizations_url":"https://api.github.com/users/serge-sans-paille/orgs","repos_url":"https://api.github.com/users/serge-sans-paille/repos","events_url":"https://api.github.com/users/serge-sans-paille/events{/privacy}","received_events_url":"https://api.github.com/users/serge-sans-paille/received_events","type":"User","site_admin":false},"body":"\\o/ test for the new feature :-)","created_at":"2016-04-22T13:27:21Z","updated_at":"2016-04-22T13:27:21Z","html_url":"https://github.com/quarkslab/NFLlib/pull/10#discussion_r60737994","pull_request_url":"https://api.github.com/repos/quarkslab/NFLlib/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/quarkslab/NFLlib/pulls/comments/60737994"},"html":{"href":"https://github.com/quarkslab/NFLlib/pull/10#discussion_r60737994"},"pull_request":{"href":"https://api.github.com/repos/quarkslab/NFLlib/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/quarkslab/NFLlib/pulls/10","id":66210388,"html_url":"https://github.com/quarkslab/NFLlib/pull/10","diff_url":"https://github.com/quarkslab/NFLlib/pull/10.diff","patch_url":"https://github.com/quarkslab/NFLlib/pull/10.patch","issue_url":"https://api.github.com/repos/quarkslab/NFLlib/issues/10","number":10,"state":"open","locked":false,"title":"Feature/gmp","user":{"login":"tlepoint","id":1345502,"avatar_url":"https://avatars.githubusercontent.com/u/1345502?v=3","gravatar_id":"","url":"https://api.github.com/users/tlepoint","html_url":"https://github.com/tlepoint","followers_url":"https://api.github.com/users/tlepoint/followers","following_url":"https://api.github.com/users/tlepoint/following{/other_user}","gists_url":"https://api.github.com/users/tlepoint/gists{/gist_id}","starred_url":"https://api.github.com/users/tlepoint/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tlepoint/subscriptions","organizations_url":"https://api.github.com/users/tlepoint/orgs","repos_url":"https://api.github.com/users/tlepoint/repos","events_url":"https://api.github.com/users/tlepoint/events{/privacy}","received_events_url":"https://api.github.com/users/tlepoint/received_events","type":"User","site_admin":false},"body":"Add conversion functions from and back to gmp (mpz_t, mpz_class).\r\n\r\n","created_at":"2016-04-12T19:04:26Z","updated_at":"2016-04-22T13:27:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"33c20a451b591bd1473e3b1162104d74cc4901eb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/quarkslab/NFLlib/pulls/10/commits","review_comments_url":"https://api.github.com/repos/quarkslab/NFLlib/pulls/10/comments","review_comment_url":"https://api.github.com/repos/quarkslab/NFLlib/pulls/comments{/number}","comments_url":"https://api.github.com/repos/quarkslab/NFLlib/issues/10/comments","statuses_url":"https://api.github.com/repos/quarkslab/NFLlib/statuses/63b4fc44c1ad7a9569519618bc46ebdb8ee66362","head":{"label":"tlepoint:feature/gmp","ref":"feature/gmp","sha":"63b4fc44c1ad7a9569519618bc46ebdb8ee66362","user":{"login":"tlepoint","id":1345502,"avatar_url":"https://avatars.githubusercontent.com/u/1345502?v=3","gravatar_id":"","url":"https://api.github.com/users/tlepoint","html_url":"https://github.com/tlepoint","followers_url":"https://api.github.com/users/tlepoint/followers","following_url":"https://api.github.com/users/tlepoint/following{/other_user}","gists_url":"https://api.github.com/users/tlepoint/gists{/gist_id}","starred_url":"https://api.github.com/users/tlepoint/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tlepoint/subscriptions","organizations_url":"https://api.github.com/users/tlepoint/orgs","repos_url":"https://api.github.com/users/tlepoint/repos","events_url":"https://api.github.com/users/tlepoint/events{/privacy}","received_events_url":"https://api.github.com/users/tlepoint/received_events","type":"User","site_admin":false},"repo":{"id":51507387,"name":"NFLlib","full_name":"tlepoint/NFLlib","owner":{"login":"tlepoint","id":1345502,"avatar_url":"https://avatars.githubusercontent.com/u/1345502?v=3","gravatar_id":"","url":"https://api.github.com/users/tlepoint","html_url":"https://github.com/tlepoint","followers_url":"https://api.github.com/users/tlepoint/followers","following_url":"https://api.github.com/users/tlepoint/following{/other_user}","gists_url":"https://api.github.com/users/tlepoint/gists{/gist_id}","starred_url":"https://api.github.com/users/tlepoint/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tlepoint/subscriptions","organizations_url":"https://api.github.com/users/tlepoint/orgs","repos_url":"https://api.github.com/users/tlepoint/repos","events_url":"https://api.github.com/users/tlepoint/events{/privacy}","received_events_url":"https://api.github.com/users/tlepoint/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tlepoint/NFLlib","description":"NTT-based Fast Lattice library","fork":true,"url":"https://api.github.com/repos/tlepoint/NFLlib","forks_url":"https://api.github.com/repos/tlepoint/NFLlib/forks","keys_url":"https://api.github.com/repos/tlepoint/NFLlib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tlepoint/NFLlib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tlepoint/NFLlib/teams","hooks_url":"https://api.github.com/repos/tlepoint/NFLlib/hooks","issue_events_url":"https://api.github.com/repos/tlepoint/NFLlib/issues/events{/number}","events_url":"https://api.github.com/repos/tlepoint/NFLlib/events","assignees_url":"https://api.github.com/repos/tlepoint/NFLlib/assignees{/user}","branches_url":"https://api.github.com/repos/tlepoint/NFLlib/branches{/branch}","tags_url":"https://api.github.com/repos/tlepoint/NFLlib/tags","blobs_url":"https://api.github.com/repos/tlepoint/NFLlib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tlepoint/NFLlib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tlepoint/NFLlib/git/refs{/sha}","trees_url":"https://api.github.com/repos/tlepoint/NFLlib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tlepoint/NFLlib/statuses/{sha}","languages_url":"https://api.github.com/repos/tlepoint/NFLlib/languages","stargazers_url":"https://api.github.com/repos/tlepoint/NFLlib/stargazers","contributors_url":"https://api.github.com/repos/tlepoint/NFLlib/contributors","subscribers_url":"https://api.github.com/repos/tlepoint/NFLlib/subscribers","subscription_url":"https://api.github.com/repos/tlepoint/NFLlib/subscription","commits_url":"https://api.github.com/repos/tlepoint/NFLlib/commits{/sha}","git_commits_url":"https://api.github.com/repos/tlepoint/NFLlib/git/commits{/sha}","comments_url":"https://api.github.com/repos/tlepoint/NFLlib/comments{/number}","issue_comment_url":"https://api.github.com/repos/tlepoint/NFLlib/issues/comments{/number}","contents_url":"https://api.github.com/repos/tlepoint/NFLlib/contents/{+path}","compare_url":"https://api.github.com/repos/tlepoint/NFLlib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tlepoint/NFLlib/merges","archive_url":"https://api.github.com/repos/tlepoint/NFLlib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tlepoint/NFLlib/downloads","issues_url":"https://api.github.com/repos/tlepoint/NFLlib/issues{/number}","pulls_url":"https://api.github.com/repos/tlepoint/NFLlib/pulls{/number}","milestones_url":"https://api.github.com/repos/tlepoint/NFLlib/milestones{/number}","notifications_url":"https://api.github.com/repos/tlepoint/NFLlib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tlepoint/NFLlib/labels{/name}","releases_url":"https://api.github.com/repos/tlepoint/NFLlib/releases{/id}","deployments_url":"https://api.github.com/repos/tlepoint/NFLlib/deployments","created_at":"2016-02-11T10:21:35Z","updated_at":"2016-03-07T15:14:44Z","pushed_at":"2016-04-20T18:52:53Z","git_url":"git://github.com/tlepoint/NFLlib.git","ssh_url":"git@github.com:tlepoint/NFLlib.git","clone_url":"https://github.com/tlepoint/NFLlib.git","svn_url":"https://github.com/tlepoint/NFLlib","homepage":null,"size":174,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"quarkslab:master","ref":"master","sha":"583a1bd6795f98fc810f9b202cc68b9ace6ebcec","user":{"login":"quarkslab","id":3357711,"avatar_url":"https://avatars.githubusercontent.com/u/3357711?v=3","gravatar_id":"","url":"https://api.github.com/users/quarkslab","html_url":"https://github.com/quarkslab","followers_url":"https://api.github.com/users/quarkslab/followers","following_url":"https://api.github.com/users/quarkslab/following{/other_user}","gists_url":"https://api.github.com/users/quarkslab/gists{/gist_id}","starred_url":"https://api.github.com/users/quarkslab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quarkslab/subscriptions","organizations_url":"https://api.github.com/users/quarkslab/orgs","repos_url":"https://api.github.com/users/quarkslab/repos","events_url":"https://api.github.com/users/quarkslab/events{/privacy}","received_events_url":"https://api.github.com/users/quarkslab/received_events","type":"Organization","site_admin":false},"repo":{"id":46931019,"name":"NFLlib","full_name":"quarkslab/NFLlib","owner":{"login":"quarkslab","id":3357711,"avatar_url":"https://avatars.githubusercontent.com/u/3357711?v=3","gravatar_id":"","url":"https://api.github.com/users/quarkslab","html_url":"https://github.com/quarkslab","followers_url":"https://api.github.com/users/quarkslab/followers","following_url":"https://api.github.com/users/quarkslab/following{/other_user}","gists_url":"https://api.github.com/users/quarkslab/gists{/gist_id}","starred_url":"https://api.github.com/users/quarkslab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quarkslab/subscriptions","organizations_url":"https://api.github.com/users/quarkslab/orgs","repos_url":"https://api.github.com/users/quarkslab/repos","events_url":"https://api.github.com/users/quarkslab/events{/privacy}","received_events_url":"https://api.github.com/users/quarkslab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/quarkslab/NFLlib","description":"NTT-based Fast Lattice library","fork":false,"url":"https://api.github.com/repos/quarkslab/NFLlib","forks_url":"https://api.github.com/repos/quarkslab/NFLlib/forks","keys_url":"https://api.github.com/repos/quarkslab/NFLlib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/quarkslab/NFLlib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/quarkslab/NFLlib/teams","hooks_url":"https://api.github.com/repos/quarkslab/NFLlib/hooks","issue_events_url":"https://api.github.com/repos/quarkslab/NFLlib/issues/events{/number}","events_url":"https://api.github.com/repos/quarkslab/NFLlib/events","assignees_url":"https://api.github.com/repos/quarkslab/NFLlib/assignees{/user}","branches_url":"https://api.github.com/repos/quarkslab/NFLlib/branches{/branch}","tags_url":"https://api.github.com/repos/quarkslab/NFLlib/tags","blobs_url":"https://api.github.com/repos/quarkslab/NFLlib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/quarkslab/NFLlib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/quarkslab/NFLlib/git/refs{/sha}","trees_url":"https://api.github.com/repos/quarkslab/NFLlib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/quarkslab/NFLlib/statuses/{sha}","languages_url":"https://api.github.com/repos/quarkslab/NFLlib/languages","stargazers_url":"https://api.github.com/repos/quarkslab/NFLlib/stargazers","contributors_url":"https://api.github.com/repos/quarkslab/NFLlib/contributors","subscribers_url":"https://api.github.com/repos/quarkslab/NFLlib/subscribers","subscription_url":"https://api.github.com/repos/quarkslab/NFLlib/subscription","commits_url":"https://api.github.com/repos/quarkslab/NFLlib/commits{/sha}","git_commits_url":"https://api.github.com/repos/quarkslab/NFLlib/git/commits{/sha}","comments_url":"https://api.github.com/repos/quarkslab/NFLlib/comments{/number}","issue_comment_url":"https://api.github.com/repos/quarkslab/NFLlib/issues/comments{/number}","contents_url":"https://api.github.com/repos/quarkslab/NFLlib/contents/{+path}","compare_url":"https://api.github.com/repos/quarkslab/NFLlib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/quarkslab/NFLlib/merges","archive_url":"https://api.github.com/repos/quarkslab/NFLlib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/quarkslab/NFLlib/downloads","issues_url":"https://api.github.com/repos/quarkslab/NFLlib/issues{/number}","pulls_url":"https://api.github.com/repos/quarkslab/NFLlib/pulls{/number}","milestones_url":"https://api.github.com/repos/quarkslab/NFLlib/milestones{/number}","notifications_url":"https://api.github.com/repos/quarkslab/NFLlib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/quarkslab/NFLlib/labels{/name}","releases_url":"https://api.github.com/repos/quarkslab/NFLlib/releases{/id}","deployments_url":"https://api.github.com/repos/quarkslab/NFLlib/deployments","created_at":"2015-11-26T14:24:36Z","updated_at":"2016-03-30T04:58:28Z","pushed_at":"2016-04-20T18:52:53Z","git_url":"git://github.com/quarkslab/NFLlib.git","ssh_url":"git@github.com:quarkslab/NFLlib.git","clone_url":"https://github.com/quarkslab/NFLlib.git","svn_url":"https://github.com/quarkslab/NFLlib","homepage":null,"size":176,"stargazers_count":13,"watchers_count":13,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":1,"forks":4,"open_issues":1,"watchers":13,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/quarkslab/NFLlib/pulls/10"},"html":{"href":"https://github.com/quarkslab/NFLlib/pull/10"},"issue":{"href":"https://api.github.com/repos/quarkslab/NFLlib/issues/10"},"comments":{"href":"https://api.github.com/repos/quarkslab/NFLlib/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/quarkslab/NFLlib/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/quarkslab/NFLlib/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/quarkslab/NFLlib/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/quarkslab/NFLlib/statuses/63b4fc44c1ad7a9569519618bc46ebdb8ee66362"}}}}