run.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. #!/usr/bin/env python3
  2. import json
  3. import os
  4. import sys
  5. import random
  6. build_dirs = [ "./../build/bin/" , "./../build/py/" ]
  7. targets = [ "tests-128", "tests-256", "tests-dbg-128", "tests-dbg-256", "examples-256", "examples-128", "xrnlib-128-cli", "xrnlib-cli", "xrnlib-256-cli", "_xrnlib256.so", "_xrnlib128.so" ]
  8. target_path = ""
  9. target_name = ""
  10. for build_dir in build_dirs :
  11. for target in targets :
  12. if ( os.path.exists(build_dir+target) ):
  13. target_path = build_dir+target
  14. target_name = target
  15. break
  16. if ( target_name == "xrnlib-cli" ) :
  17. if ( len(sys.argv) == 2 ) :
  18. cmd="cd ./backend/parser_tests/; bash ./run_parser_tests.sh " + sys.argv[1]
  19. os.system(cmd);
  20. else :
  21. cmd="cd ./backend/parser_tests/; bash ./run_parser_tests.sh "
  22. os.system(cmd);
  23. if (( target_name == "tests-128" ) or ( target_name == "tests-256" )):
  24. clean_cache_str = " rm -rf ../cache/* ; "
  25. cmd = clean_cache_str + " cd ../cache ; cp -r ../archives/resources/code_examples/* . ; " + target_path
  26. os.system(cmd);
  27. if (( target_name == "tests-dbg-128" ) or ( target_name == "tests-dbg-256" )):
  28. clean_cache_str = " rm -rf ../cache/* ; "
  29. cmd = clean_cache_str + " cd ../cache ; cp -r ../archives/resources/code_examples/* . ; valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes " + target_path + " 2>../build/reports/valgrind_stderr.rep >../build/reports/valgrind_stdout.rep "
  30. print(cmd)
  31. os.system(cmd);
  32. if ( target_name == "examples-256" ) or ( target_name == "examples-128" ):
  33. cache_dir = "../cache"
  34. cache_example_dir = cache_dir + "/examples"
  35. cache_example_init_structures_dir = cache_example_dir + "/datastructures"
  36. cache_example_init_exec_dir = cache_example_dir + "/exec"
  37. if ( False == os.path.exists( cache_example_init_structures_dir ) ):
  38. if ( False == os.path.exists( cache_example_dir )):
  39. if ( False == os.path.exists( cache_dir )):
  40. cmd = "mkdir " + cache_dir
  41. os.system(cmd);
  42. cmd = "mkdir " + cache_example_dir
  43. os.system(cmd);
  44. cmd = "mkdir " + cache_example_init_structures_dir
  45. os.system(cmd);
  46. # generate_xrn_matrix_one_third()
  47. cmd = " cd " + cache_example_init_structures_dir + " ; ../../" + target_path + " " + str(0)
  48. os.system(cmd);
  49. # generate_keys_with_wrapper_functions()
  50. cmd = " cd " + cache_example_init_structures_dir + " ; ../../" + target_path + " " + str(2)
  51. os.system(cmd);
  52. if ( False == os.path.exists( cache_example_init_exec_dir )):
  53. cmd = "mkdir " + cache_example_init_exec_dir
  54. os.system(cmd);
  55. clean_cache_str = " rm -rf " + cache_example_init_exec_dir + "/* "
  56. os.system(clean_cache_str );
  57. copy_data = " cp " + cache_example_init_structures_dir + "/xrn_matrix_compressed.xmc " + cache_example_init_exec_dir + " ; "
  58. copy_data = copy_data + " cp " + cache_example_init_structures_dir + "/xrn_matrix.xm " + cache_example_init_exec_dir + " ; "
  59. copy_data = copy_data + " cp " + cache_example_init_structures_dir + "/xbinomial_key.xf " + cache_example_init_exec_dir + " ; "
  60. copy_data = copy_data + " cp " + cache_example_init_structures_dir + "/xmonomial_key.xf " + cache_example_init_exec_dir + " ; "
  61. copy_data = copy_data + " cp " + cache_example_init_structures_dir + "/xmonovalent_key.xf " + cache_example_init_exec_dir + " ; "
  62. copy_data = copy_data + " cp " + cache_example_init_structures_dir + "/xpolyvalent_key.xf " + cache_example_init_exec_dir + " ; "
  63. copy_data = copy_data + " cp " + cache_example_init_structures_dir + "/xpolyvalent_proof.xf " + cache_example_init_exec_dir + " ; "
  64. copy_data = copy_data + " cp " + cache_example_init_structures_dir + "/xstart_point.xf " + cache_example_init_exec_dir + " ; "
  65. copy_data = copy_data + " cp ../archives/resources/code_examples/lorem_ipsum.py " + cache_example_init_exec_dir + " ; "
  66. copy_data = copy_data + " cp ../archives/resources/code_examples/lorem_ipsum.txt " + cache_example_init_exec_dir + " ; "
  67. if ( len(sys.argv) == 2 ) :
  68. if ( sys.argv[1] == "all" ):
  69. for i in range ( 35 ) :
  70. print("running "+str(i)+"/35")
  71. os.system(clean_cache_str);
  72. cmd = copy_data + " cd " + cache_example_init_exec_dir + " ; ../../" + target_path + " " + str(i)
  73. os.system(cmd)
  74. else :
  75. os.system(clean_cache_str);
  76. cmd = copy_data + " cd " + cache_example_init_exec_dir + " ; ../../" + target_path + " " + sys.argv[1]
  77. os.system(cmd)
  78. else :
  79. os.system(clean_cache_str)
  80. cmd = target_path
  81. os.system(cmd)
  82. if (( target_name == "_xrnlib256.so" ) or ( target_name == "_xrnlib128.so" )):
  83. ordered_script_list = [ "generate_xrn_matrix_one_third.py",
  84. "generate_xrn_matrix_all_rnd.py",
  85. "generate_keys_with_wrapper_functions.py",
  86. "check_xrn_matrix.py",
  87. "split_join_encryption_wrapper.py",
  88. "split_join_encryption_bytes_wrapper.py",
  89. "encrypt_symmetric_wrapper.py",
  90. "encrypt_symmetric_bytes_wrapper.py",
  91. "encrypt_asymmetric_wrapper.py",
  92. "encrypt_asymmetric_bytes_wrapper.py",
  93. "hash_bytes_wrapper.py",
  94. "hash_file_wrapper.py",
  95. "symmetric_signature_file_wrapper.py",
  96. "symmetric_signature_bytes_wrapper.py",
  97. "asymmetric_signature_file_wrapper.py",
  98. "asymmetric_signature_bytes_wrapper.py",
  99. "pseudo_random_number_generator_wrapper.py",
  100. "ring_signature_file_wrapper.py",
  101. "ring_signature_bytes_wrapper.py",
  102. "monomial_key_exchange.py",
  103. "certificate_symmetric.py",
  104. "certificate_asymmetric.py",
  105. "zero_knowledge_proof_binomial_key.py",
  106. "zero_knowledge_proof_signature.py",
  107. "zero_knowledge_proof_signature_bytes.py",
  108. "zero_knowledge_proof_certificate.py",
  109. "permute_xrn_matrix_compressed_rnd.py",
  110. "permute_xrn_matrix_compressed_deterministic.py",
  111. "permute_xrn_matrix_compressed_key.py",
  112. "encoding_decoding_file_wrapper.py",
  113. "encoding_decoding_bytes_wrapper.py",
  114. "polyvalent_key_exchange.py",
  115. "checksum_dump_file_wrapper.py",
  116. "checksum_dump_bytes_wrapper.py",
  117. "create_blocks_from_file.py",
  118. "create_blocks_from_bytes.py",
  119. "steganography_block_file.py",
  120. "steganography_block_bytes.py",
  121. "steganography_raw_file.py",
  122. "steganography_raw_bytes.py"
  123. ]
  124. cache_dir = "../cache"
  125. cache_example_dir = cache_dir + "/examples"
  126. cache_example_init_structures_dir = cache_example_dir + "/datastructures"
  127. cache_example_init_exec_dir = cache_example_dir + "/exec"
  128. if ( False == os.path.exists( cache_example_init_structures_dir ) ):
  129. if ( False == os.path.exists( cache_example_dir )):
  130. if ( False == os.path.exists( cache_dir )):
  131. cmd = "mkdir " + cache_dir
  132. os.system(cmd);
  133. cmd = "mkdir " + cache_example_dir
  134. os.system(cmd);
  135. cmd = "mkdir " + cache_example_init_structures_dir
  136. os.system(cmd);
  137. #cmd = " cd " + cache_example_init_structures_dir + " ; ../../" + target_path + " " + str(0)
  138. if target_name == "_xrnlib128.so" :
  139. cmd = " cp ./../build/py/_xrnlib128.so " + cache_example_init_structures_dir + " ; "
  140. cmd = cmd + " cp ./../build/py/xrnlib128.py " + cache_example_init_structures_dir + " ; "
  141. else :
  142. cmd = " cp ./../build/py/_xrnlib256.so " + cache_example_init_structures_dir + " ; "
  143. cmd = cmd + " cp ./../build/py/xrnlib256.py " + cache_example_init_structures_dir + " ; "
  144. cmd = cmd + " cp ../code/xrnlib/app/examples/py/" + ordered_script_list[0] + " " + cache_example_init_structures_dir + " ; "
  145. cmd = cmd + " cp ../code/xrnlib/app/examples/py/" + ordered_script_list[2] + " " + cache_example_init_structures_dir + " ; "
  146. print("cmd: " + cmd); os.system(cmd);
  147. # generate_xrn_matrix_one_third()
  148. if target_name == "_xrnlib128.so" :
  149. cmd = "sed -i 's/xrnlib256/xrnlib128/' " + cache_example_init_structures_dir + "/" + ordered_script_list[0]
  150. print(cmd)
  151. os.system(cmd);
  152. cmd = "sed -i 's/xrnlib256/xrnlib128/' " + cache_example_init_structures_dir + "/" + ordered_script_list[2]
  153. print(cmd)
  154. os.system(cmd);
  155. cmd = "cd " + cache_example_init_structures_dir + " ; python3 " + ordered_script_list[0] + " ;"
  156. print("cmd: " + cmd); os.system(cmd);
  157. # generate_keys_with_wrapper_functions()
  158. cmd = "cd " + cache_example_init_structures_dir + " ; python3 " + ordered_script_list[2] + " ;"
  159. print("cmd: " + cmd); os.system(cmd);
  160. if ( False == os.path.exists( cache_example_init_exec_dir )):
  161. cmd = "mkdir " + cache_example_init_exec_dir
  162. os.system(cmd);
  163. clean_cache_str = " rm -rf " + cache_example_init_exec_dir + "/* "
  164. os.system(clean_cache_str );
  165. copy_data = " cp " + cache_example_init_structures_dir + "/xrn_matrix_compressed.xmc " + cache_example_init_exec_dir + " ; "
  166. if target_name == "_xrnlib256.so" :
  167. copy_data = copy_data + " cp " + cache_example_init_structures_dir + "/_xrnlib256.so " + cache_example_init_exec_dir + " ; "
  168. copy_data = copy_data + " cp " + cache_example_init_structures_dir + "/xrnlib256.py " + cache_example_init_exec_dir + " ; "
  169. else :
  170. copy_data = copy_data + " cp " + cache_example_init_structures_dir + "/_xrnlib128.so " + cache_example_init_exec_dir + " ; "
  171. copy_data = copy_data + " cp " + cache_example_init_structures_dir + "/xrnlib128.py " + cache_example_init_exec_dir + " ; "
  172. copy_data = copy_data + " cp " + cache_example_init_structures_dir + "/xrn_matrix.xm " + cache_example_init_exec_dir + " ; "
  173. copy_data = copy_data + " cp " + cache_example_init_structures_dir + "/xbinomial_key.xf " + cache_example_init_exec_dir + " ; "
  174. copy_data = copy_data + " cp " + cache_example_init_structures_dir + "/xmonomial_key.xf " + cache_example_init_exec_dir + " ; "
  175. copy_data = copy_data + " cp " + cache_example_init_structures_dir + "/xmonovalent_key.xf " + cache_example_init_exec_dir + " ; "
  176. copy_data = copy_data + " cp " + cache_example_init_structures_dir + "/xpolyvalent_key.xf " + cache_example_init_exec_dir + " ; "
  177. copy_data = copy_data + " cp " + cache_example_init_structures_dir + "/xpolyvalent_proof.xf " + cache_example_init_exec_dir + " ; "
  178. copy_data = copy_data + " cp " + cache_example_init_structures_dir + "/xstart_point.xf " + cache_example_init_exec_dir + " ; "
  179. copy_data = copy_data + " cp ../archives/resources/code_examples/lorem_ipsum.py " + cache_example_init_exec_dir + " ; "
  180. copy_data = copy_data + " cp ../archives/resources/code_examples/lorem_ipsum.txt " + cache_example_init_exec_dir + " ; "
  181. clean_cache_str = " rm -rf " + cache_example_init_exec_dir + "/* "
  182. runall = 0
  183. if ( len(sys.argv) == 2 ) :
  184. if ( sys.argv[1] == "all" ):
  185. runall = 1
  186. argvint = 0
  187. else :
  188. argvint = int(sys.argv[1])
  189. if (( len(sys.argv) != 2 ) or ( argvint < 0 ) or ( argvint >= 40 )):
  190. print( "implemented Python examples:" )
  191. i = 0
  192. for script in ordered_script_list :
  193. print( str(i) + ") " + ordered_script_list[i] ) ; i = i + 1
  194. exit(0)
  195. if ( runall == 0 ) :
  196. pyscript = ordered_script_list[ argvint ]
  197. print("\n\nrunning " + pyscript + "\n" )
  198. os.system(clean_cache_str);
  199. os.system(copy_data);
  200. cmd = "cp ../code/xrnlib/app/examples/py/" + pyscript + " " + cache_example_init_exec_dir + " ; "
  201. os.system(cmd);
  202. if target_name == "_xrnlib128.so" :
  203. cmd = "sed -i 's/xrnlib256/xrnlib128/' " + cache_example_init_exec_dir + "/" + pyscript
  204. os.system(cmd);
  205. cmd = "sed -i 's/xrnlib256/xrnlib128/' " + cache_example_init_exec_dir + "/lorem_ipsum.py"
  206. os.system(cmd);
  207. cmd = "cd " + cache_example_init_exec_dir + " ; python3 " + pyscript + " ;"
  208. os.system(cmd);
  209. else :
  210. for i in range (len(ordered_script_list)):
  211. print("running "+str(i)+"/"+ str(len(ordered_script_list)))
  212. os.system(clean_cache_str);
  213. os.system(copy_data);
  214. pyscript = ordered_script_list[ i ]
  215. cmd = "cp ../code/xrnlib/app/examples/py/" + pyscript + " " + cache_example_init_exec_dir + " ; "
  216. os.system(cmd);
  217. if target_name == "_xrnlib128.so" :
  218. cmd = "sed -i 's/xrnlib256/xrnlib128/' " + cache_example_init_exec_dir + "/" + pyscript
  219. os.system(cmd);
  220. cmd = "sed -i 's/xrnlib256/xrnlib128/' " + cache_example_init_exec_dir + "/lorem_ipsum.py"
  221. os.system(cmd);
  222. cmd = "cd " + cache_example_init_exec_dir + " ; python3 " + pyscript + " ;"
  223. os.system(cmd);