ooxml_crypt 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (264) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +58 -0
  5. data/Rakefile +12 -0
  6. data/bin/console +15 -0
  7. data/bin/setup +8 -0
  8. data/ext/ooxml_crypt/extconf.rb +18 -0
  9. data/ext/ooxml_crypt/ooxml_crypt.c +27 -0
  10. data/ext/ooxml_crypt/ooxml_crypt.h +7 -0
  11. data/lib/ooxml_crypt/version.rb +5 -0
  12. data/lib/ooxml_crypt.rb +75 -0
  13. data/vendor/cybozulib/.github/workflows/main.yml +12 -0
  14. data/vendor/cybozulib/.gitignore +5 -0
  15. data/vendor/cybozulib/CMakeLists.txt +6 -0
  16. data/vendor/cybozulib/COPYRIGHT +27 -0
  17. data/vendor/cybozulib/Makefile +26 -0
  18. data/vendor/cybozulib/bin/libeay32.dll +0 -0
  19. data/vendor/cybozulib/bin/libmecab.dll +0 -0
  20. data/vendor/cybozulib/bin/ssleay32.dll +0 -0
  21. data/vendor/cybozulib/common.mk +116 -0
  22. data/vendor/cybozulib/common.props +25 -0
  23. data/vendor/cybozulib/cybozulib.sln +286 -0
  24. data/vendor/cybozulib/debug.props +14 -0
  25. data/vendor/cybozulib/include/cybozu/array.hpp +197 -0
  26. data/vendor/cybozulib/include/cybozu/atoi.hpp +238 -0
  27. data/vendor/cybozulib/include/cybozu/atomic.hpp +146 -0
  28. data/vendor/cybozulib/include/cybozu/base64.hpp +210 -0
  29. data/vendor/cybozulib/include/cybozu/benchmark.hpp +212 -0
  30. data/vendor/cybozulib/include/cybozu/bfd.hpp +105 -0
  31. data/vendor/cybozulib/include/cybozu/bit_operation.hpp +139 -0
  32. data/vendor/cybozulib/include/cybozu/bitvector.hpp +358 -0
  33. data/vendor/cybozulib/include/cybozu/condition_variable.hpp +113 -0
  34. data/vendor/cybozulib/include/cybozu/condition_variable_cs.hpp +74 -0
  35. data/vendor/cybozulib/include/cybozu/config.hpp +392 -0
  36. data/vendor/cybozulib/include/cybozu/critical_section.hpp +60 -0
  37. data/vendor/cybozulib/include/cybozu/crypto.hpp +321 -0
  38. data/vendor/cybozulib/include/cybozu/csucvector.hpp +624 -0
  39. data/vendor/cybozulib/include/cybozu/csv.hpp +294 -0
  40. data/vendor/cybozulib/include/cybozu/data_type.hpp +27 -0
  41. data/vendor/cybozulib/include/cybozu/endian.hpp +224 -0
  42. data/vendor/cybozulib/include/cybozu/env.hpp +63 -0
  43. data/vendor/cybozulib/include/cybozu/event.hpp +122 -0
  44. data/vendor/cybozulib/include/cybozu/exception.hpp +253 -0
  45. data/vendor/cybozulib/include/cybozu/file.hpp +626 -0
  46. data/vendor/cybozulib/include/cybozu/fmindex.hpp +291 -0
  47. data/vendor/cybozulib/include/cybozu/format.hpp +93 -0
  48. data/vendor/cybozulib/include/cybozu/frequency.hpp +264 -0
  49. data/vendor/cybozulib/include/cybozu/hash.hpp +67 -0
  50. data/vendor/cybozulib/include/cybozu/inttype.hpp +174 -0
  51. data/vendor/cybozulib/include/cybozu/itoa.hpp +336 -0
  52. data/vendor/cybozulib/include/cybozu/json.hpp +120 -0
  53. data/vendor/cybozulib/include/cybozu/line_stream.hpp +149 -0
  54. data/vendor/cybozulib/include/cybozu/link_libeay32.hpp +21 -0
  55. data/vendor/cybozulib/include/cybozu/link_mpir.hpp +18 -0
  56. data/vendor/cybozulib/include/cybozu/link_ssleay32.hpp +19 -0
  57. data/vendor/cybozulib/include/cybozu/log.hpp +237 -0
  58. data/vendor/cybozulib/include/cybozu/minixml.hpp +452 -0
  59. data/vendor/cybozulib/include/cybozu/mmap.hpp +143 -0
  60. data/vendor/cybozulib/include/cybozu/mutex.hpp +144 -0
  61. data/vendor/cybozulib/include/cybozu/nlp/mecab.hpp +96 -0
  62. data/vendor/cybozulib/include/cybozu/nlp/plsi.hpp +315 -0
  63. data/vendor/cybozulib/include/cybozu/nlp/random.hpp +74 -0
  64. data/vendor/cybozulib/include/cybozu/nlp/sparse.hpp +529 -0
  65. data/vendor/cybozulib/include/cybozu/nlp/svd.hpp +486 -0
  66. data/vendor/cybozulib/include/cybozu/nlp/tfidf.hpp +226 -0
  67. data/vendor/cybozulib/include/cybozu/nlp/top_score.hpp +75 -0
  68. data/vendor/cybozulib/include/cybozu/option.hpp +743 -0
  69. data/vendor/cybozulib/include/cybozu/parallel.hpp +88 -0
  70. data/vendor/cybozulib/include/cybozu/pcg.hpp +72 -0
  71. data/vendor/cybozulib/include/cybozu/process.hpp +324 -0
  72. data/vendor/cybozulib/include/cybozu/quit_signal_handler.hpp +66 -0
  73. data/vendor/cybozulib/include/cybozu/random_generator.hpp +144 -0
  74. data/vendor/cybozulib/include/cybozu/regex.hpp +463 -0
  75. data/vendor/cybozulib/include/cybozu/select8.hpp +279 -0
  76. data/vendor/cybozulib/include/cybozu/serializer.hpp +363 -0
  77. data/vendor/cybozulib/include/cybozu/sha1.hpp +209 -0
  78. data/vendor/cybozulib/include/cybozu/sha2.hpp +506 -0
  79. data/vendor/cybozulib/include/cybozu/siphash.hpp +105 -0
  80. data/vendor/cybozulib/include/cybozu/socket.hpp +785 -0
  81. data/vendor/cybozulib/include/cybozu/ssl.hpp +203 -0
  82. data/vendor/cybozulib/include/cybozu/stacktrace.hpp +291 -0
  83. data/vendor/cybozulib/include/cybozu/stream.hpp +269 -0
  84. data/vendor/cybozulib/include/cybozu/string.hpp +1746 -0
  85. data/vendor/cybozulib/include/cybozu/string_operation.hpp +365 -0
  86. data/vendor/cybozulib/include/cybozu/sucvector.hpp +378 -0
  87. data/vendor/cybozulib/include/cybozu/test.hpp +373 -0
  88. data/vendor/cybozulib/include/cybozu/thread.hpp +229 -0
  89. data/vendor/cybozulib/include/cybozu/time.hpp +281 -0
  90. data/vendor/cybozulib/include/cybozu/tls.hpp +115 -0
  91. data/vendor/cybozulib/include/cybozu/unordered_map.hpp +13 -0
  92. data/vendor/cybozulib/include/cybozu/unordered_set.hpp +13 -0
  93. data/vendor/cybozulib/include/cybozu/v128.hpp +376 -0
  94. data/vendor/cybozulib/include/cybozu/wavelet_matrix.hpp +345 -0
  95. data/vendor/cybozulib/include/cybozu/xorshift.hpp +189 -0
  96. data/vendor/cybozulib/include/cybozu/zlib.hpp +325 -0
  97. data/vendor/cybozulib/include/sais.hxx +364 -0
  98. data/vendor/cybozulib/misc/make_select8tbl.cpp +26 -0
  99. data/vendor/cybozulib/mk.bat +37 -0
  100. data/vendor/cybozulib/readme.md +29 -0
  101. data/vendor/cybozulib/release.props +12 -0
  102. data/vendor/cybozulib/sample/Makefile +30 -0
  103. data/vendor/cybozulib/sample/csucvector_smpl.cpp +42 -0
  104. data/vendor/cybozulib/sample/data/svd/org/test1.S +4 -0
  105. data/vendor/cybozulib/sample/data/svd/org/test1.U +4 -0
  106. data/vendor/cybozulib/sample/data/svd/org/test1.V +6 -0
  107. data/vendor/cybozulib/sample/data/svd/test1 +4 -0
  108. data/vendor/cybozulib/sample/data/svd/test2 +4 -0
  109. data/vendor/cybozulib/sample/desymbol.cpp +127 -0
  110. data/vendor/cybozulib/sample/exception_smpl.cpp +46 -0
  111. data/vendor/cybozulib/sample/fmindex_smpl.cpp +231 -0
  112. data/vendor/cybozulib/sample/log_smpl.cpp +19 -0
  113. data/vendor/cybozulib/sample/mecab_smpl.cpp +37 -0
  114. data/vendor/cybozulib/sample/option2_smpl.cpp +68 -0
  115. data/vendor/cybozulib/sample/option_smpl.cpp +42 -0
  116. data/vendor/cybozulib/sample/plsi_smpl.cpp +207 -0
  117. data/vendor/cybozulib/sample/proj/exception_smpl.vcproj +184 -0
  118. data/vendor/cybozulib/sample/proj/mecab_smpl.vcproj +184 -0
  119. data/vendor/cybozulib/sample/proj/ssl_smpl/ssl_smpl.vcxproj +85 -0
  120. data/vendor/cybozulib/sample/proj/ssl_smpl.vcproj +347 -0
  121. data/vendor/cybozulib/sample/proj/stacktrace_smpl/stacktrace_smpl.vcxproj +85 -0
  122. data/vendor/cybozulib/sample/proj/svd_smpl.vcproj +184 -0
  123. data/vendor/cybozulib/sample/quit_signal_handler.cpp +30 -0
  124. data/vendor/cybozulib/sample/serializer_smpl.cpp +196 -0
  125. data/vendor/cybozulib/sample/socket_smpl.cpp +82 -0
  126. data/vendor/cybozulib/sample/ssl_smpl.cpp +39 -0
  127. data/vendor/cybozulib/sample/stacktrace_smpl.cpp +52 -0
  128. data/vendor/cybozulib/sample/svd_bench_smpl.cpp +143 -0
  129. data/vendor/cybozulib/sample/svd_smpl.cpp +94 -0
  130. data/vendor/cybozulib/sample/wm_bench_smpl.cpp +182 -0
  131. data/vendor/cybozulib/sample/zlib_smpl.cpp +41 -0
  132. data/vendor/cybozulib/src/Makefile +8 -0
  133. data/vendor/cybozulib/src/base/Makefile +19 -0
  134. data/vendor/cybozulib/test/Makefile +12 -0
  135. data/vendor/cybozulib/test/base/Makefile +37 -0
  136. data/vendor/cybozulib/test/base/array_test.cpp +173 -0
  137. data/vendor/cybozulib/test/base/atoi_test.cpp +774 -0
  138. data/vendor/cybozulib/test/base/atomic_test.cpp +49 -0
  139. data/vendor/cybozulib/test/base/base64_test.cpp +113 -0
  140. data/vendor/cybozulib/test/base/bit_operation_test.cpp +134 -0
  141. data/vendor/cybozulib/test/base/bitvector_test.cpp +204 -0
  142. data/vendor/cybozulib/test/base/condition_variable_cs_test.cpp +92 -0
  143. data/vendor/cybozulib/test/base/condition_variable_test.cpp +88 -0
  144. data/vendor/cybozulib/test/base/config_test.cpp +236 -0
  145. data/vendor/cybozulib/test/base/crypto_test.cpp +122 -0
  146. data/vendor/cybozulib/test/base/csucvector_test.cpp +63 -0
  147. data/vendor/cybozulib/test/base/csv_test.cpp +182 -0
  148. data/vendor/cybozulib/test/base/data/a.xml +26 -0
  149. data/vendor/cybozulib/test/base/endian_test.cpp +56 -0
  150. data/vendor/cybozulib/test/base/env_test.cpp +22 -0
  151. data/vendor/cybozulib/test/base/event_test.cpp +41 -0
  152. data/vendor/cybozulib/test/base/file_test.cpp +233 -0
  153. data/vendor/cybozulib/test/base/fmindex_test.cpp +118 -0
  154. data/vendor/cybozulib/test/base/format_test.cpp +12 -0
  155. data/vendor/cybozulib/test/base/frequency_test.cpp +104 -0
  156. data/vendor/cybozulib/test/base/itoa_test.cpp +522 -0
  157. data/vendor/cybozulib/test/base/line_stream_test.cpp +208 -0
  158. data/vendor/cybozulib/test/base/mecab_test.cpp +41 -0
  159. data/vendor/cybozulib/test/base/minixml_test.cpp +103 -0
  160. data/vendor/cybozulib/test/base/mmap_test.cpp +15 -0
  161. data/vendor/cybozulib/test/base/option_test.cpp +487 -0
  162. data/vendor/cybozulib/test/base/parallel_test.cpp +48 -0
  163. data/vendor/cybozulib/test/base/proj/array_test/array_test.vcxproj +86 -0
  164. data/vendor/cybozulib/test/base/proj/atoi_test/atoi_test.vcxproj +86 -0
  165. data/vendor/cybozulib/test/base/proj/atomic_test/atomic_test.vcxproj +86 -0
  166. data/vendor/cybozulib/test/base/proj/base64_test/base64_test.vcxproj +86 -0
  167. data/vendor/cybozulib/test/base/proj/condition_variable_cs_test/condition_variable_cs_test.vcxproj +86 -0
  168. data/vendor/cybozulib/test/base/proj/condition_variable_test/condition_variable_test.vcxproj +86 -0
  169. data/vendor/cybozulib/test/base/proj/config_test/config_test.vcxproj +86 -0
  170. data/vendor/cybozulib/test/base/proj/csv_test/csv_test.vcxproj +86 -0
  171. data/vendor/cybozulib/test/base/proj/endian_test/endian_test.vcxproj +86 -0
  172. data/vendor/cybozulib/test/base/proj/env_test/env_test.vcxproj +86 -0
  173. data/vendor/cybozulib/test/base/proj/event_test/event_test.vcxproj +86 -0
  174. data/vendor/cybozulib/test/base/proj/file_test/file_test.vcxproj +86 -0
  175. data/vendor/cybozulib/test/base/proj/itoa_test/itoa_test.vcxproj +86 -0
  176. data/vendor/cybozulib/test/base/proj/mecab_test/mecab_test.vcxproj +88 -0
  177. data/vendor/cybozulib/test/base/proj/minixml_test/minixml_test.vcxproj +86 -0
  178. data/vendor/cybozulib/test/base/proj/mmap_test/mmap_test.vcxproj +86 -0
  179. data/vendor/cybozulib/test/base/proj/serializer_test/serializer_test.vcxproj +86 -0
  180. data/vendor/cybozulib/test/base/proj/sha1_test/sha1_test.vcxproj +86 -0
  181. data/vendor/cybozulib/test/base/proj/stream_test/stream_test.vcxproj +86 -0
  182. data/vendor/cybozulib/test/base/proj/string_operation_test/string_operation_test.vcxproj +86 -0
  183. data/vendor/cybozulib/test/base/proj/string_test/string_test.vcxproj +86 -0
  184. data/vendor/cybozulib/test/base/proj/thread_test/thread_test.vcxproj +86 -0
  185. data/vendor/cybozulib/test/base/proj/time_test/time_test.vcxproj +86 -0
  186. data/vendor/cybozulib/test/base/proj/tls_test/tls_test.vcxproj +86 -0
  187. data/vendor/cybozulib/test/base/proj/zlib_test/zlib_test.vcxproj +86 -0
  188. data/vendor/cybozulib/test/base/random_generator_test.cpp +28 -0
  189. data/vendor/cybozulib/test/base/regex_test.cpp +74 -0
  190. data/vendor/cybozulib/test/base/serializer_test.cpp +483 -0
  191. data/vendor/cybozulib/test/base/sha1_test.cpp +61 -0
  192. data/vendor/cybozulib/test/base/sha2_test.cpp +191 -0
  193. data/vendor/cybozulib/test/base/siphash_test.cpp +33 -0
  194. data/vendor/cybozulib/test/base/socket_test.cpp +76 -0
  195. data/vendor/cybozulib/test/base/stream_test.cpp +101 -0
  196. data/vendor/cybozulib/test/base/string_operation_test.cpp +340 -0
  197. data/vendor/cybozulib/test/base/string_test.cpp +1705 -0
  198. data/vendor/cybozulib/test/base/sucvector_test.cpp +312 -0
  199. data/vendor/cybozulib/test/base/thread_test.cpp +62 -0
  200. data/vendor/cybozulib/test/base/time_test.cpp +164 -0
  201. data/vendor/cybozulib/test/base/tls_test.cpp +50 -0
  202. data/vendor/cybozulib/test/base/wavelet_matrix_test.cpp +145 -0
  203. data/vendor/cybozulib/test/base/zlib_test.cpp +371 -0
  204. data/vendor/cybozulib/test/nlp/Makefile +27 -0
  205. data/vendor/cybozulib/test/nlp/proj/random_test.vcproj +184 -0
  206. data/vendor/cybozulib/test/nlp/proj/sparse_test.vcproj +184 -0
  207. data/vendor/cybozulib/test/nlp/proj/svd_test.vcproj +184 -0
  208. data/vendor/cybozulib/test/nlp/random_test.cpp +62 -0
  209. data/vendor/cybozulib/test/nlp/sparse_test.cpp +347 -0
  210. data/vendor/cybozulib/test/nlp/svd_test.cpp +234 -0
  211. data/vendor/cybozulib/test/nlp/top_score_test.cpp +40 -0
  212. data/vendor/cybozulib/tool/create_vcproj.py +186 -0
  213. data/vendor/cybozulib/tool/vcproj_tmpl.py +185 -0
  214. data/vendor/msoffice/COPYRIGHT +27 -0
  215. data/vendor/msoffice/Makefile +29 -0
  216. data/vendor/msoffice/bin/64/msoc.dll +0 -0
  217. data/vendor/msoffice/bin/64/msocsample.exe +0 -0
  218. data/vendor/msoffice/bin/64/msoffice-crypt.exe +0 -0
  219. data/vendor/msoffice/bin/msoc.dll +0 -0
  220. data/vendor/msoffice/bin/msocsample.exe +0 -0
  221. data/vendor/msoffice/bin/msoffice-crypt.exe +0 -0
  222. data/vendor/msoffice/common.mk +71 -0
  223. data/vendor/msoffice/common.props +26 -0
  224. data/vendor/msoffice/debug.props +14 -0
  225. data/vendor/msoffice/include/attack.hpp +211 -0
  226. data/vendor/msoffice/include/cfb.hpp +777 -0
  227. data/vendor/msoffice/include/crypto_util.hpp +450 -0
  228. data/vendor/msoffice/include/custom_sha1.hpp +342 -0
  229. data/vendor/msoffice/include/decode.hpp +240 -0
  230. data/vendor/msoffice/include/encode.hpp +221 -0
  231. data/vendor/msoffice/include/make_dataspace.hpp +316 -0
  232. data/vendor/msoffice/include/msoc.h +129 -0
  233. data/vendor/msoffice/include/resource.hpp +7 -0
  234. data/vendor/msoffice/include/standard_encryption.hpp +145 -0
  235. data/vendor/msoffice/include/uint32vec.hpp +179 -0
  236. data/vendor/msoffice/include/util.hpp +212 -0
  237. data/vendor/msoffice/lib/.emptydir +0 -0
  238. data/vendor/msoffice/misc/decrypt-xls.vbs +46 -0
  239. data/vendor/msoffice/mk.bat +1 -0
  240. data/vendor/msoffice/mkdll.bat +3 -0
  241. data/vendor/msoffice/msoc.def +13 -0
  242. data/vendor/msoffice/msocsample.py +178 -0
  243. data/vendor/msoffice/msoffice12.sln +31 -0
  244. data/vendor/msoffice/readme.md +110 -0
  245. data/vendor/msoffice/release.props +28 -0
  246. data/vendor/msoffice/src/Makefile +19 -0
  247. data/vendor/msoffice/src/attack.cpp +124 -0
  248. data/vendor/msoffice/src/cfb_test.cpp +77 -0
  249. data/vendor/msoffice/src/minisample.c +54 -0
  250. data/vendor/msoffice/src/msocdll.cpp +276 -0
  251. data/vendor/msoffice/src/msocsample.c +136 -0
  252. data/vendor/msoffice/src/msoffice-crypt.cpp +219 -0
  253. data/vendor/msoffice/src/proj/attack/attack.vcxproj +88 -0
  254. data/vendor/msoffice/src/proj/main/msoffice-crypt.vcxproj +88 -0
  255. data/vendor/msoffice/src/sha1.cpp +234 -0
  256. data/vendor/msoffice/test/Makefile +20 -0
  257. data/vendor/msoffice/test/cfb_test.cpp +74 -0
  258. data/vendor/msoffice/test/hash_test.cpp +59 -0
  259. data/vendor/msoffice/test/proj/cfb/cfb_test.vcxproj +90 -0
  260. data/vendor/msoffice/test/proj/hash/hash_test.vcxproj +90 -0
  261. data/vendor/msoffice/test/sampl.bat +8 -0
  262. data/vendor/msoffice/test_all.py +46 -0
  263. data/vendor/update +4 -0
  264. metadata +351 -0
@@ -0,0 +1,191 @@
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include <time.h>
4
+ #include <vector>
5
+ #define CYBOZU_DONT_USE_OPENSSL
6
+ #include <cybozu/sha2.hpp>
7
+ #include <cybozu/test.hpp>
8
+ #include <cybozu/itoa.hpp>
9
+ #include <cybozu/atoi.hpp>
10
+ #include <cybozu/benchmark.hpp>
11
+
12
+ const struct Tbl {
13
+ const char *out;
14
+ const char *in;
15
+ } sha256Tbl[] = {
16
+ {"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", ""},
17
+ {"ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb", "a"},
18
+ {"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "abc"},
19
+ {"52cbf04bed1f02f43d1caab3b63930c41010ecde117928724be789dac5fa18bb", "111111111111111111111111111111111111111111111111111111"},
20
+ {"31f713cc40a632a9ce454b3029b727e9bb6d0eea11460f1d7818852c2565b9cd", "1111111111111111111111111111111111111111111111111111111"},
21
+ {"9df2565d5163d54a49e6a8126bbd689614aeab8bc4aabfe69a8cb20975918ef2", "11111111111111111111111111111111111111111111111111111111"},
22
+ {"dd6bc04f6a40788d771c73b4b8732a00a2c7e6b9520776265c31c0692326865c", "111111111111111111111111111111111111111111111111111111111"},
23
+ {"c8c0cc46e25f2681e7fe5b795cf879fb05fcebf52f8fadd07c20b2e9ac75e0ba", "1111111111111111111111111111111111111111111111111111111111"},
24
+ {"4fb703f4bf6bd112d2c8450ec4d66cc39456e75a4e10ab8ff25512b76eeb0b89", "11111111111111111111111111111111111111111111111111111111111"},
25
+ {"70d36dedb311176c76ecd7f78d72340dbbaa364d23923239c8fda5b8c6ead201", "111111111111111111111111111111111111111111111111111111111111"},
26
+ {"94dbfd746e995562d7f119e930564676e4bd1a6ec4ed3088222b09c76d88c87d", "1111111111111111111111111111111111111111111111111111111111111"},
27
+ {"4d15cac6cec2d518728004ae016f33eb791f6b89edebd6c1e5eabd7e6f7826ad", "11111111111111111111111111111111111111111111111111111111111111"},
28
+ {"60ac1bebb39f2d0bbd04fddaabe70270c3401c25e441a5a5bea291adef129d33", "111111111111111111111111111111111111111111111111111111111111111"},
29
+ {"3138bb9bc78df27c473ecfd1410f7bd45ebac1f59cf3ff9cfe4db77aab7aedd3", "1111111111111111111111111111111111111111111111111111111111111111"},
30
+ {"466680e1d9448572b0b27905731f290e591a52cfdfa2edf7a32169a3f6957af1", "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
31
+ {"3e8df35dfbeb228cfef6361ce98e975db153fdd9ea42522a581a015908d23e02", "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
32
+ {"70ff2d4782bd27b199315e8c770c5b1bed76d9c8c262dbe03112c5cbb0d8bfb6", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
33
+ {"965f77ba47402e8ffa4c594f116ffe1a99b6ed1f49341aa27a0fdebf5e18bd2a", "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
34
+ {"2c779adb8ae79df3965a9b8d62d6f64f05f4f82abef3bc8814f8374fac478582", "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
35
+ {"4f58aea7c1c88ffaa58b1218e304add251deaf291bbaddcd095079bbca333338", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
36
+ {"b922a0085535438943e1fecf51c9bc6c13f38977f779cfce9934f422239a8f4a", "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
37
+ {"cc46aec737b147f9b27f4aaa75cd58e62399d3b78cbed29f4ebb81d87734ad25", "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
38
+ {"9c1debdbfea404f078d84ddaf6db820b3ad7f9700743ccbc78708578fc1bb53f", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
39
+ {"52d844e0aa05175167543882659c5ecfb8bdf0bf3d0eefd3ab86643078cecf2b", "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
40
+ {"a174ccedaef055e5757f74f2bcc1a15e2e4065066b3ea9a34bdf89735bc6e10c", "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
41
+ {"ab29b49e48726959285d8fe8e19f78b7e5bdb2c3184d99cb0890e69acc71bcc7", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
42
+ {"ce232fb8cf607fe6e620da8f1c316a940dbe514f2f9f8d4212bbd74cf144dd9f", "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
43
+ {"8e73e16d08a10ff853f3816d10ba58821e1e9230973a7f320867bd0dde5b30c6", "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
44
+ {"f4056698c3dc1d7352d38544c0435b17106ab359ebfb2b69ce6b69e30ee0e8cc", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
45
+ {"0d0c64e24843a0fad6ed192c1f3cf7db7a02d8edb17b10808ef106fb1107bd06", "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
46
+ {"fc18053578d5dfb935474ff8cea71709cf0b0722799f7a98b0ef31276248386f", "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
47
+ {"eef81ea912795a61bf2d3a29dc71faedd45157fe88220db7f92040aa9328cee6", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
48
+ {"4ff5ac52aa16dbe3db447ea12d090c5bb6f1325aaaca5ee059b248a89f673972", "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
49
+ {"8dceb93f4389e8bd2bb482a145ed2a22172b6ddc9e4696cedf9f0da8008fc11c", "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
50
+ }, sha512Tbl[] = {
51
+ {"cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e", ""},
52
+ {"1f40fc92da241694750979ee6cf582f2d5d7d28e18335de05abc54d0560e0f5302860c652bf08d560252aa5e74210546f369fbbbce8c12cfc7957b2652fe9a75", "a"},
53
+ {"ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f", "abc"},
54
+ {"0bd33523145765f125a0c72556bb7657d4356c6c30fee54eca5f2de60687cbdb81e4b2f73350481e430208a6d703ec23f009881dd3793dbd2d67c21fde7259be", "111111111111111111111111111111111111111111111111111111"},
55
+ {"70e4e22118ff7bfb284b8f691b95550e62f06c33103b5c7beb6e89ad29530aafd245cc3b00fb16f662d1b41fca5b62bc7dd0782951c3966f4cd101208e1e087f", "1111111111111111111111111111111111111111111111111111111"},
56
+ {"fdb318fc2e4c7774cfe1586e4de0dcd3d315bde65c49074caed4d0b234fb78a38f920f49ec5c47a6cc53afd2523f730b4ab8c552f0a594b08fe20592d5fa63b7", "11111111111111111111111111111111111111111111111111111111"},
57
+ {"63e1c7b0e145cca735a43a8cf4e900935313f635f8ce874739d8ed834ec795924cf6cc84fe41edcb822a32932450b8870a0e8342f47a694b3524af0b3b83c7a4", "111111111111111111111111111111111111111111111111111111111"},
58
+ {"efdbc3fed2133cf1a80a40ee97517bc96763cc8021fd992e7f295caccf9a1422fc7ad6d0c87bdeb91540a35125335a95763430f45896119400d822ad7be5a3d5", "1111111111111111111111111111111111111111111111111111111111"},
59
+ {"65e4ef6d196916e8d860f93692fc86057c51d8737a033ecc8338f35316645dc55b7505eb8cc05f83501032ff04d28e59a019e215f05d6ee076672b22198ab7a1", "11111111111111111111111111111111111111111111111111111111111"},
60
+ {"864a668d13f625b71d091b922463abed0fd0c12f7a7cb3eca555e6c8e2c9340fc53be60932c85a43f9d4fc9fd6283fe316349d12c940f257e8b9843272a355a8", "111111111111111111111111111111111111111111111111111111111111"},
61
+ {"1614c97345e38788881e7b5bd632cdeea514c23d0cb649024b32ddb3fc3a29d4fd36b7e6247566dc081aff7bdc343c7fefdab3a5837864bc7e7f71620a65c2d1", "1111111111111111111111111111111111111111111111111111111111111"},
62
+ {"0b03d0ca8d199c9770ac23d69659f16a183041e167998942dac8a5e36d5e36a669f36faa7905e8d69a470168e295c150bf6bfc62be96df1b6a872fb152ab7c9c", "11111111111111111111111111111111111111111111111111111111111111"},
63
+ {"448401d5fe535761e155306aaebb0b5779550906dbd9a34d00b5006cf32f9661ffc46245c59c5e32a551ba81eeccaa482ee7bcf03c13d58a9bfac6399f2b94c8", "111111111111111111111111111111111111111111111111111111111111111"},
64
+ {"6723a63fc813efa037dab2128781cbc395a90ffd83bf2b520d6d62488350d898fd5624717ac2fa443388cb80fb7a784a04aa4fa6659c4fcce87e62dec718bb95", "1111111111111111111111111111111111111111111111111111111111111111"},
65
+ {"b3c1fb2783d41ac463785fa06a43019d061a7ada06516fb0b9d7547f5ea5194fe9a90423d6b5439eaa425354a86f6bbeeea7edf2e8ae0c6fb02482bf944b8576", "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
66
+ {"70d3a8248c60b0ba3f33a908cd4d0f1222838abf2cff71a53098dd32387f004dabf73534835c7b9caa2d1ca39d4747ae3ee0a182f47f8386c18645c12c41c967", "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
67
+ {"f16ddb94ff68cd33936dad110b0a841bcc9d7e489c848326d9c0edf15564ffbdb59d3436b45b45e10f57ab5750ebf2a53126be988476cf727b03641ba442118b", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
68
+ {"0e8381d0b523d45cd129317e497c87f51fc47b023c8ba6ba3c0ff3307e663ca35c98edcb3bdc0c9fd21ce3cea4371109df68cc91d55b725bed7a2ebeb10e661f", "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
69
+ {"a7ee8984e60b34b35f5fbf91fa8af8f8644a62901797aca654f51b6dd97a72aed723dd5ea60b0fdad7979bac442b50fb98af532271deb54c2b2ea96313a02cf9", "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
70
+ {"9308b12413b6d29a31c261bc94a2a6b603bf114e0fabcf26b0b1a2174d4088c41d41422d7cdba5a304185c4e1f0069b5c72be1eb68de3e96f24c8352b46fb3f3", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
71
+ {"0008c0aab2eb0297d8a84dd4134122d6f979207840b163f413e82f0de0fb612053e70c90c4d60921b447e015b87c51ae9455e65ff832009aebde451b2176d559", "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
72
+ {"88275c81b599b1e973bf2498a8ce58104b54508035a11c4f3f73985d7438b7f5261c0089d3aa2e6b4e2f7ae22e6924a79078d02afc1608850b3f70b2d6cfaa7e", "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
73
+ {"1af08e4ee1bf4faa7b2d429f9e9d8130edbfcae1120b31e4c3aafa63a1b465a40e6b79ca3f9f84576f848a5b19bbd1d1eba69153229af8d00ab700c90525a27d", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
74
+ {"aecd6a988c19492bebf9ba3115c80c71546871e602f7253e6485702b3d6e3a4f1f1b268ab4e47e57f8157441c7c36782faa9ae14526f86aaa9dfcfaae07c4664", "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
75
+ {"b9aa2ed0e0ad16f56b577a81619efb66e6e52c2ad5f0a978063644306dafadce26671b1ae0039fcd9bc836c2d3d25ad59b2f647f6ad9dec68f5156036e0bdcfe", "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
76
+ {"ce1f55ec8efb498920b008ff773fa722d4c908441412238c571032af6e47a9cfe14d2e3a336e4e53d337addae09a0524cbdac4af0f7e1ae70afb6d4fcd493b72", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
77
+ {"ea4cac877cbc6caaf75c4846c577bd3ac6cfe44f792a70fa4b9f43671e95fa8d015149f2a007aed563ef4491d40c1e2639cf3be724baa4c801eeb97d9da265bf", "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
78
+ {"754a60a0fc302f33a0562f3d17e50711d4460c55eb71125485d73fbeb5e9f7b8139b7117a734ccbb05220d0c691c0d318bd32cfd1a6b2c9ac37b3174667b37b2", "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
79
+ {"c947046f78ae3861db81c34e28ae056aa4c6b8385e2625a4a914c1f89a30ff111c4325f68149f0cbcd72b4b69aee82ebb384e43c9ab82d782da79b6692f6262f", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
80
+ {"4e93a6e9505945164b02e8bd8df53e3bf9bf43faffcfb386972eedc8828662a95debd0cffadf658ccb17815327ddb7f24b3c818efb832f5bca1104355bce9b8b", "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
81
+ {"a1f050c7941148611bcbdea943e1b5fc9653af772d235a004c42e2871e2c3ef42214d9c03ca9f728e9853c16f8d31777099d9e8278021f51b3eda8d875610dd7", "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
82
+ {"1f0ac4e2a57efc5459bc1d21a0e6502eec953f11021db44f62fd13a4c70000f04f71296224f3595f57ea5f99f61cc9bf9e81e8fd469b60961c45058fdf475f39", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
83
+ {"610e0f364ac647d7a78be9e1e4b1f423132a5cb2fa94b0d8baa8d21d42639a77da897f3d8b3aec464b44d170eb9cf8020b6e4a377672bce649746be941a1d47d", "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
84
+ {"0f431aa36a3953f27987552b70ae548bf77be26b6100a710b0d870d7a5c538b9215e4dd6692b966f58b3710889adbd3fc4cab3a1618eb4d06b031e27f33ca3a1", "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"},
85
+ };
86
+
87
+ std::string toHex(const std::string& s)
88
+ {
89
+ std::string ret(s.size() * 2, 0);
90
+ for (size_t i = 0; i < s.size(); i++) {
91
+ cybozu::itohex(&ret[i * 2], 2, uint8_t(s[i]), false);
92
+ }
93
+ return ret;
94
+ }
95
+
96
+ typedef std::vector<uint8_t> Uint8Vec;
97
+
98
+ Uint8Vec fromHex(const std::string& s)
99
+ {
100
+ Uint8Vec ret(s.size() / 2);
101
+ for (size_t i = 0; i < s.size(); i += 2) {
102
+ ret[i / 2] = cybozu::hextoi(&s[i], 2);
103
+ }
104
+ return ret;
105
+ }
106
+
107
+ CYBOZU_TEST_AUTO(sha256)
108
+ {
109
+ for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(sha256Tbl); i++) {
110
+ const char *msg = sha256Tbl[i].in;
111
+ std::string md = toHex(cybozu::Sha256().digest(msg, strlen(msg)));
112
+ CYBOZU_TEST_EQUAL(md, sha256Tbl[i].out);
113
+ char buf[32];
114
+ CYBOZU_BENCH_C("sha256", 100000, cybozu::Sha256().digest, buf, sizeof(buf), msg, strlen(msg));
115
+ }
116
+ }
117
+
118
+ CYBOZU_TEST_AUTO(sha512)
119
+ {
120
+ for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(sha512Tbl); i++) {
121
+ const char *msg = sha512Tbl[i].in;
122
+ std::string md = toHex(cybozu::Sha512().digest(msg, strlen(msg)));
123
+ CYBOZU_TEST_EQUAL(md, sha512Tbl[i].out);
124
+ }
125
+ }
126
+
127
+ const struct HmacTbl {
128
+ const char *key;
129
+ const char *msg;
130
+ const char *mac;
131
+ } hmac256Tbl[] = {
132
+ {
133
+ "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b",
134
+ "4869205468657265",
135
+ "b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7",
136
+ },
137
+ {
138
+ "",
139
+ "",
140
+ "b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad"
141
+ },
142
+ {
143
+ "4a656665",
144
+ "7768617420646f2079612077616e7420666f72206e6f7468696e673f",
145
+ "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843",
146
+ },
147
+ {
148
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
149
+ "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd",
150
+ "773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe",
151
+ },
152
+ {
153
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
154
+ "54657374205573696e67204c6172676572205468616e20426c6f636b2d53697a65204b6579202d2048617368204b6579204669727374",
155
+ "60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54",
156
+ },
157
+ {
158
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
159
+ "5468697320697320612074657374207573696e672061206c6172676572207468616e20626c6f636b2d73697a65206b657920616e642061206c6172676572207468616e20626c6f636b2d73697a6520646174612e20546865206b6579206e6565647320746f20626520686173686564206265666f7265206265696e6720757365642062792074686520484d414320616c676f726974686d2e",
160
+ "9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f51535c3a35e2",
161
+ },
162
+ {
163
+ "01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101",
164
+ "12",
165
+ "9fc5fd7acf75bf2125220240293bd8221d72a25ffb5bfb397ee1a2a00df7a1ad",
166
+ },
167
+ {
168
+ "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101",
169
+ "12",
170
+ "4a8ac5b5f14061a2ed19ea9ac716b3c2c27343ac4dc52e42fabb9b1ab019d335",
171
+ },
172
+ {
173
+ "010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101",
174
+ "12",
175
+ "e4ab292c53a535617d5d5a80a74de6e5e2516faba8708ac536a5bb79c7c8e989",
176
+ },
177
+ };
178
+
179
+ CYBOZU_TEST_AUTO(hmac256)
180
+ {
181
+ for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(hmac256Tbl); i++) {
182
+ char hmac[32];
183
+ Uint8Vec key, msg;
184
+ key = fromHex(hmac256Tbl[i].key);
185
+ msg = fromHex(hmac256Tbl[i].msg);
186
+ cybozu::hmac256(hmac, key.data(), key.size(), msg.data(), msg.size());
187
+ std::string h = toHex(std::string(hmac, sizeof(hmac)));
188
+ CYBOZU_TEST_EQUAL(h, hmac256Tbl[i].mac);
189
+ }
190
+ }
191
+
@@ -0,0 +1,33 @@
1
+ #include <cybozu/test.hpp>
2
+ #include <cybozu/siphash.hpp>
3
+
4
+ const uint64_t vectors[64] = {
5
+ 0x726fdb47dd0e0e31ULL, 0x74f839c593dc67fdULL, 0x0d6c8009d9a94f5aULL, 0x85676696d7fb7e2dULL,
6
+ 0xcf2794e0277187b7ULL, 0x18765564cd99a68dULL, 0xcbc9466e58fee3ceULL, 0xab0200f58b01d137ULL,
7
+ 0x93f5f5799a932462ULL, 0x9e0082df0ba9e4b0ULL, 0x7a5dbbc594ddb9f3ULL, 0xf4b32f46226bada7ULL,
8
+ 0x751e8fbc860ee5fbULL, 0x14ea5627c0843d90ULL, 0xf723ca908e7af2eeULL, 0xa129ca6149be45e5ULL,
9
+ 0x3f2acc7f57c29bdbULL, 0x699ae9f52cbe4794ULL, 0x4bc1b3f0968dd39cULL, 0xbb6dc91da77961bdULL,
10
+ 0xbed65cf21aa2ee98ULL, 0xd0f2cbb02e3b67c7ULL, 0x93536795e3a33e88ULL, 0xa80c038ccd5ccec8ULL,
11
+ 0xb8ad50c6f649af94ULL, 0xbce192de8a85b8eaULL, 0x17d835b85bbb15f3ULL, 0x2f2e6163076bcfadULL,
12
+ 0xde4daaaca71dc9a5ULL, 0xa6a2506687956571ULL, 0xad87a3535c49ef28ULL, 0x32d892fad841c342ULL,
13
+ 0x7127512f72f27cceULL, 0xa7f32346f95978e3ULL, 0x12e0b01abb051238ULL, 0x15e034d40fa197aeULL,
14
+ 0x314dffbe0815a3b4ULL, 0x027990f029623981ULL, 0xcadcd4e59ef40c4dULL, 0x9abfd8766a33735cULL,
15
+ 0x0e3ea96b5304a7d0ULL, 0xad0c42d6fc585992ULL, 0x187306c89bc215a9ULL, 0xd4a60abcf3792b95ULL,
16
+ 0xf935451de4f21df2ULL, 0xa9538f0419755787ULL, 0xdb9acddff56ca510ULL, 0xd06c98cd5c0975ebULL,
17
+ 0xe612a3cb9ecba951ULL, 0xc766e62cfcadaf96ULL, 0xee64435a9752fe72ULL, 0xa192d576b245165aULL,
18
+ 0x0a8787bf8ecb74b2ULL, 0x81b3e73d20b49b6fULL, 0x7fa8220ba3b2eceaULL, 0x245731c13ca42499ULL,
19
+ 0xb78dbfaf3a8d83bdULL, 0xea1ad565322a1a0bULL, 0x60e61c23a3795013ULL, 0x6606d7e446282b93ULL,
20
+ 0x6ca4ecb15c5f91e1ULL, 0x9f626da15c9625f3ULL, 0xe51b38608ef25f57ULL, 0x958a324ceb064572ULL,
21
+ };
22
+
23
+ CYBOZU_TEST_AUTO(siphash)
24
+ {
25
+ char plaintext[64];
26
+ for (int i = 0; i < 64; i++) {
27
+ plaintext[i] = (char)i;
28
+ }
29
+
30
+ for (int i = 0; i < 64; i++) {
31
+ CYBOZU_TEST_EQUAL(cybozu::siphash24(plaintext, i), vectors[i]);
32
+ }
33
+ }
@@ -0,0 +1,76 @@
1
+ #include <cybozu/test.hpp>
2
+ #include <cybozu/thread.hpp>
3
+ #include <cybozu/socket.hpp>
4
+
5
+ CYBOZU_TEST_AUTO(open_move)
6
+ {
7
+ cybozu::Socket s;
8
+ CYBOZU_TEST_ASSERT(!s.isValid());
9
+ s.bind(65000);
10
+ CYBOZU_TEST_ASSERT(s.isValid());
11
+ #if CYBOZU_CPP_VERSION == CYBOZU_CPP_VERSION_CPP11
12
+ cybozu::Socket t(std::move(s));
13
+ #else
14
+ cybozu::Socket t;
15
+ t.moveFrom(s);
16
+ #endif
17
+ CYBOZU_TEST_ASSERT(!s.isValid());
18
+ CYBOZU_TEST_ASSERT(t.isValid());
19
+ #if CYBOZU_CPP_VERSION == CYBOZU_CPP_VERSION_CPP11
20
+ cybozu::Socket u(std::move(t));
21
+ #else
22
+ cybozu::Socket u;
23
+ u.moveFrom(t);
24
+ #endif
25
+ CYBOZU_TEST_ASSERT(!t.isValid());
26
+ CYBOZU_TEST_ASSERT(u.isValid());
27
+
28
+ cybozu::Socket v;
29
+ CYBOZU_TEST_ASSERT(!v.isValid());
30
+ v.moveFrom(u);
31
+ CYBOZU_TEST_ASSERT(v.isValid());
32
+ CYBOZU_TEST_ASSERT(!u.isValid());
33
+ }
34
+
35
+ CYBOZU_TEST_AUTO(timeout)
36
+ {
37
+ cybozu::Socket s;
38
+ s.bind(60000);
39
+ s.setSendTimeout(12000);
40
+ CYBOZU_TEST_EQUAL(s.getSendTimeout(), 12000);
41
+ s.setReceiveTimeout(54000);
42
+ CYBOZU_TEST_EQUAL(s.getReceiveTimeout(), 54000);
43
+ }
44
+
45
+ CYBOZU_TEST_AUTO(compare_SocketAddr)
46
+ {
47
+ cybozu::SocketAddr v4("74.125.235.73", 80, false);
48
+ cybozu::SocketAddr v6("74.125.235.73", 81, true);
49
+ cybozu::SocketAddr v4x("74.125.235.72", 82, false);
50
+ cybozu::SocketAddr v6x("2001:db8::1234:ace:6006:1e", 83, true);
51
+
52
+ CYBOZU_TEST_ASSERT(v4.hasSameAddr(v4));
53
+ CYBOZU_TEST_ASSERT(v4.hasSameAddr(v6));
54
+ CYBOZU_TEST_ASSERT(!v4.hasSameAddr(v4x));
55
+ CYBOZU_TEST_ASSERT(!v4.hasSameAddr(v6x));
56
+
57
+ CYBOZU_TEST_ASSERT(v6.hasSameAddr(v4));
58
+ CYBOZU_TEST_ASSERT(v6.hasSameAddr(v6));
59
+ CYBOZU_TEST_ASSERT(!v6.hasSameAddr(v4x));
60
+ CYBOZU_TEST_ASSERT(!v6.hasSameAddr(v6x));
61
+
62
+ CYBOZU_TEST_ASSERT(!v4x.hasSameAddr(v4));
63
+ CYBOZU_TEST_ASSERT(!v4x.hasSameAddr(v6));
64
+ CYBOZU_TEST_ASSERT(v4x.hasSameAddr(v4x));
65
+ CYBOZU_TEST_ASSERT(!v4x.hasSameAddr(v6x));
66
+
67
+ CYBOZU_TEST_ASSERT(!v6x.hasSameAddr(v4));
68
+ CYBOZU_TEST_ASSERT(!v6x.hasSameAddr(v6));
69
+ CYBOZU_TEST_ASSERT(!v6x.hasSameAddr(v4x));
70
+ CYBOZU_TEST_ASSERT(v6x.hasSameAddr(v6x));
71
+
72
+ CYBOZU_TEST_EQUAL(v4.getPort(), 80);
73
+ CYBOZU_TEST_EQUAL(v6.getPort(), 81);
74
+ CYBOZU_TEST_EQUAL(v4x.getPort(), 82);
75
+ CYBOZU_TEST_EQUAL(v6x.getPort(), 83);
76
+ }
@@ -0,0 +1,101 @@
1
+ #include <cybozu/test.hpp>
2
+ #include <cybozu/stream.hpp>
3
+ #include <sstream>
4
+
5
+ CYBOZU_TEST_AUTO(sstream)
6
+ {
7
+ const std::string str = "123";
8
+ {
9
+ std::ostringstream os;
10
+ cybozu::OutputStreamTag<std::ostringstream>::write(os, str.c_str(), str.size());
11
+ CYBOZU_TEST_EQUAL(os.str(), str);
12
+ }
13
+ {
14
+ char buf[64] = {};
15
+ std::istringstream is(str);
16
+ size_t readSize = cybozu::readSome(buf, sizeof(buf), is);
17
+ CYBOZU_TEST_EQUAL(str.size(), readSize);
18
+ CYBOZU_TEST_ASSERT(memcmp(buf, str.c_str(), str.size()) == 0);
19
+ }
20
+ {
21
+ char buf[64] = {};
22
+ std::istringstream is(str);
23
+ cybozu::read(buf, str.size(), is);
24
+ CYBOZU_TEST_ASSERT(memcmp(buf, str.c_str(), str.size()) == 0);
25
+ }
26
+ {
27
+ std::istringstream is("123");
28
+ char c;
29
+ CYBOZU_TEST_ASSERT(cybozu::readChar(&c, is));
30
+ CYBOZU_TEST_EQUAL(c, '1');
31
+ CYBOZU_TEST_ASSERT(cybozu::readChar(&c, is));
32
+ CYBOZU_TEST_EQUAL(c, '2');
33
+ CYBOZU_TEST_ASSERT(cybozu::readChar(&c, is));
34
+ CYBOZU_TEST_EQUAL(c, '3');
35
+ CYBOZU_TEST_ASSERT(!cybozu::readChar(&c, is));
36
+ }
37
+ }
38
+
39
+ CYBOZU_TEST_AUTO(memory)
40
+ {
41
+ const std::string str = "123";
42
+ {
43
+ char buf[64] = {};
44
+ cybozu::MemoryOutputStream os(buf, sizeof(buf));
45
+ cybozu::OutputStreamTag<cybozu::MemoryOutputStream>::write(os, str.c_str(), str.size());
46
+ CYBOZU_TEST_EQUAL(str.size(), os.getPos());
47
+ CYBOZU_TEST_ASSERT(memcmp(buf, str.c_str(), str.size()) == 0);
48
+ }
49
+ {
50
+ cybozu::MemoryInputStream is(str.c_str(), str.size());
51
+ char buf[64] = {};
52
+ size_t readSize = cybozu::readSome(buf, sizeof(buf), is);
53
+ CYBOZU_TEST_EQUAL(str.size(), readSize);
54
+ CYBOZU_TEST_EQUAL(is.getPos(), readSize);
55
+ CYBOZU_TEST_ASSERT(memcmp(buf, str.c_str(), str.size()) == 0);
56
+ }
57
+ {
58
+ cybozu::MemoryInputStream is(str.c_str(), str.size());
59
+ char buf[64] = {};
60
+ cybozu::read(buf, str.size(), is);
61
+ CYBOZU_TEST_EQUAL(str.size(), is.getPos());
62
+ CYBOZU_TEST_ASSERT(memcmp(buf, str.c_str(), str.size()) == 0);
63
+ }
64
+ {
65
+ cybozu::MemoryInputStream is(str.c_str(), str.size());
66
+ char c = 0;
67
+ CYBOZU_TEST_ASSERT(cybozu::readChar(&c, is));
68
+ CYBOZU_TEST_EQUAL(c, '1');
69
+ CYBOZU_TEST_ASSERT(cybozu::readChar(&c, is));
70
+ CYBOZU_TEST_EQUAL(c, '2');
71
+ CYBOZU_TEST_ASSERT(cybozu::readChar(&c, is));
72
+ CYBOZU_TEST_EQUAL(c, '3');
73
+ CYBOZU_TEST_ASSERT(!cybozu::readChar(&c, is));
74
+ }
75
+ }
76
+
77
+ CYBOZU_TEST_AUTO(string)
78
+ {
79
+ const std::string str = "123";
80
+ {
81
+ std::string s;
82
+ cybozu::StringOutputStream os(s);
83
+ cybozu::OutputStreamTag<cybozu::StringOutputStream>::write(os, str.c_str(), str.size());
84
+ CYBOZU_TEST_EQUAL(str, s);
85
+ }
86
+ {
87
+ cybozu::StringInputStream is(str);
88
+ char buf[64] = {};
89
+ size_t readSize = cybozu::readSome(buf, sizeof(buf), is);
90
+ CYBOZU_TEST_EQUAL(str.size(), readSize);
91
+ CYBOZU_TEST_EQUAL(is.getPos(), readSize);
92
+ CYBOZU_TEST_ASSERT(memcmp(buf, str.c_str(), str.size()) == 0);
93
+ }
94
+ {
95
+ cybozu::StringInputStream is(str);
96
+ char buf[64] = {};
97
+ cybozu::read(buf, str.size(), is);
98
+ CYBOZU_TEST_EQUAL(str.size(), is.getPos());
99
+ CYBOZU_TEST_ASSERT(memcmp(buf, str.c_str(), str.size()) == 0);
100
+ }
101
+ }