ooxml_crypt 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/ext/ooxml_crypt/extconf.rb +1 -0
  3. data/lib/ooxml_crypt/version.rb +1 -1
  4. data/vendor/cybozulib/common.mk +3 -3
  5. data/vendor/cybozulib/common.props +1 -1
  6. data/vendor/cybozulib/debug.props +1 -1
  7. data/vendor/cybozulib/include/cybozu/atomic.hpp +15 -5
  8. data/vendor/cybozulib/include/cybozu/bfd.hpp +1 -1
  9. data/vendor/cybozulib/include/cybozu/bit_operation.hpp +8 -10
  10. data/vendor/cybozulib/include/cybozu/crypto.hpp +59 -5
  11. data/vendor/cybozulib/include/cybozu/endian.hpp +0 -2
  12. data/vendor/cybozulib/include/cybozu/inttype.hpp +17 -3
  13. data/vendor/cybozulib/include/cybozu/link_libeay32.hpp +1 -1
  14. data/vendor/cybozulib/include/cybozu/link_mpir.hpp +1 -1
  15. data/vendor/cybozulib/include/cybozu/link_ssleay32.hpp +1 -1
  16. data/vendor/cybozulib/include/cybozu/random_generator.hpp +1 -0
  17. data/vendor/cybozulib/include/cybozu/sha2.hpp +102 -0
  18. data/vendor/cybozulib/sample/proj/ssl_smpl/ssl_smpl.vcxproj +1 -1
  19. data/vendor/cybozulib/sample/proj/stacktrace_smpl/stacktrace_smpl.vcxproj +1 -1
  20. data/vendor/cybozulib/test/Makefile +3 -3
  21. data/vendor/cybozulib/test/base/proj/array_test/array_test.vcxproj +1 -1
  22. data/vendor/cybozulib/test/base/proj/atoi_test/atoi_test.vcxproj +1 -1
  23. data/vendor/cybozulib/test/base/proj/atomic_test/atomic_test.vcxproj +1 -1
  24. data/vendor/cybozulib/test/base/proj/base64_test/base64_test.vcxproj +1 -1
  25. data/vendor/cybozulib/test/base/proj/condition_variable_cs_test/condition_variable_cs_test.vcxproj +1 -1
  26. data/vendor/cybozulib/test/base/proj/condition_variable_test/condition_variable_test.vcxproj +1 -1
  27. data/vendor/cybozulib/test/base/proj/config_test/config_test.vcxproj +1 -1
  28. data/vendor/cybozulib/test/base/proj/csv_test/csv_test.vcxproj +1 -1
  29. data/vendor/cybozulib/test/base/proj/endian_test/endian_test.vcxproj +1 -1
  30. data/vendor/cybozulib/test/base/proj/env_test/env_test.vcxproj +1 -1
  31. data/vendor/cybozulib/test/base/proj/event_test/event_test.vcxproj +1 -1
  32. data/vendor/cybozulib/test/base/proj/file_test/file_test.vcxproj +1 -1
  33. data/vendor/cybozulib/test/base/proj/itoa_test/itoa_test.vcxproj +1 -1
  34. data/vendor/cybozulib/test/base/proj/mecab_test/mecab_test.vcxproj +1 -1
  35. data/vendor/cybozulib/test/base/proj/minixml_test/minixml_test.vcxproj +1 -1
  36. data/vendor/cybozulib/test/base/proj/mmap_test/mmap_test.vcxproj +1 -1
  37. data/vendor/cybozulib/test/base/proj/serializer_test/serializer_test.vcxproj +1 -1
  38. data/vendor/cybozulib/test/base/proj/sha1_test/sha1_test.vcxproj +1 -1
  39. data/vendor/cybozulib/test/base/proj/stream_test/stream_test.vcxproj +1 -1
  40. data/vendor/cybozulib/test/base/proj/string_operation_test/string_operation_test.vcxproj +1 -1
  41. data/vendor/cybozulib/test/base/proj/string_test/string_test.vcxproj +1 -1
  42. data/vendor/cybozulib/test/base/proj/thread_test/thread_test.vcxproj +1 -1
  43. data/vendor/cybozulib/test/base/proj/time_test/time_test.vcxproj +1 -1
  44. data/vendor/cybozulib/test/base/proj/tls_test/tls_test.vcxproj +1 -1
  45. data/vendor/cybozulib/test/base/proj/zlib_test/zlib_test.vcxproj +1 -1
  46. data/vendor/cybozulib/test/base/sha2_test.cpp +1 -1
  47. data/vendor/cybozulib/test/base/zlib_test.cpp +2 -0
  48. data/vendor/msoffice/Makefile +2 -2
  49. data/vendor/msoffice/bin/msoffice-crypt.exe +0 -0
  50. data/vendor/msoffice/common.mk +11 -6
  51. data/vendor/msoffice/common.props +25 -25
  52. data/vendor/msoffice/debug.props +13 -13
  53. data/vendor/msoffice/include/crypto_util.hpp +454 -450
  54. data/vendor/msoffice/readme.md +2 -0
  55. data/vendor/msoffice/release.props +27 -27
  56. data/vendor/msoffice/test/Makefile +4 -1
  57. data/vendor/msoffice/test/proj/cfb/cfb_test.vcxproj +89 -89
  58. data/vendor/msoffice/test/proj/hash/hash_test.vcxproj +89 -89
  59. data/vendor/msoffice/test_all.py +4 -4
  60. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64e15ec061f119a4cd42d96bf9d78379ab414baac2a7cf112c1949dd2c8cf7dd
4
- data.tar.gz: 8d2d7db90bf52b382930d39fb0cd1070d354b40554a02b77dda4bea37ba3d919
3
+ metadata.gz: 56e9f314d176274949daedac49d7d95477067389a622183e53563fc431293644
4
+ data.tar.gz: 80ea63bd8a6ecbce9379ce1273422fce8f8e385db3e10ace6dc8019a452384b4
5
5
  SHA512:
6
- metadata.gz: a750fccb3208adafc918e7b215875348e6c8afd372a759d8d3eb8eb89fc4c11225b7a4e2f3cdb0ba0dab938a33c9513e1489c48edd1160a66463a8acb6fedaac
7
- data.tar.gz: 47abbf6cb88ec6eedea69c89fa10cb743d36b14c1e71d4567afa4771364b5aa4273a71f57c96cb96ec39f19087f18efbd2c68e88c1be175fb24fdd14afbc3a32
6
+ metadata.gz: 7ce0ee6c41ccbe97fe1534365498d294706890273f99026762c17c7bb6e397af3e702efac0b9863d7c1c0d883b1a9b4c22d815beddd6429e0cac2aaf7e8237b3
7
+ data.tar.gz: 11f8442f5a69161f0800de3439904950c46b164dd6274854e478cf6cc483dfbff67166a82be5e939e660ababce291d23db27fc4acb38d41443f327b3ec83eb25
@@ -11,6 +11,7 @@ abort("Please install OpenSSL development libraries!") unless have_header("opens
11
11
  # setup build configuration
12
12
  vendor = File.realpath(File.join(__dir__, "..", "..", "vendor"))
13
13
  $INCFLAGS << " -I#{vendor}/cybozulib/include -I#{vendor}/msoffice/include"
14
+ $defs << "-DCYBOZU_USE_OPENSSL_NEW_HASH=0" # fix compatibility with old OpenSSL versions
14
15
  $VPATH << "#{vendor}/msoffice/src"
15
16
  $srcs = ["ooxml_crypt.c", "msocdll.cpp"]
16
17
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OoxmlCrypt
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
@@ -65,9 +65,9 @@ EXTDIR:=$(TOPDIR)../cybozulib_ext/
65
65
 
66
66
  CFLAGS+= -I$(TOPDIR)include
67
67
  LDFLAGS += -lz -lpthread -lssl -lcrypto
68
- HAS_BOOST=$(shell echo "\#include <boost/version.hpp>" | ($(CXX) -E - 2>/dev/null) | grep "boost/version.hpp" >/dev/null && echo "1")
69
- HAS_MECAB=$(shell echo "\#include <mecab.h>" | ($(CXX) -E - 2>/dev/null) | grep "mecab.h" >/dev/null && echo "1")
70
- HAS_EIGEN=$(shell echo "\#include <eigen3/Eigen/Sparse>" | ($(CXX) -E - 2>/dev/null) | grep "eigen3/Eigen/Sparse" >/dev/null && echo "1")
68
+ HAS_BOOST=0#$(shell echo "\#include <boost/version.hpp>" | ($(CXX) -E - 2>/dev/null) | grep "boost/version.hpp" >/dev/null && echo "1")
69
+ HAS_MECAB=0#$(shell echo "\#include <mecab.h>" | ($(CXX) -E - 2>/dev/null) | grep "mecab.h" >/dev/null && echo "1")
70
+ HAS_EIGEN=0#$(shell echo "\#include <eigen3/Eigen/Sparse>" | ($(CXX) -E - 2>/dev/null) | grep "eigen3/Eigen/Sparse" >/dev/null && echo "1")
71
71
  ifeq ($(HAS_BOOST),1)
72
72
  LDFLAGS += -lboost_regex
73
73
  endif
@@ -1,4 +1,4 @@
1
- ����<?xml version="1.0" encoding="utf-8"?>
1
+ <?xml version="1.0" encoding="utf-8"?>
2
2
  <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
3
  <ImportGroup Label="PropertySheets" />
4
4
  <PropertyGroup Label="UserMacros" />
@@ -1,4 +1,4 @@
1
- ����<?xml version="1.0" encoding="utf-8"?>
1
+ <?xml version="1.0" encoding="utf-8"?>
2
2
  <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
3
  <ImportGroup Label="PropertySheets" />
4
4
  <PropertyGroup Label="UserMacros" />
@@ -8,13 +8,17 @@
8
8
  */
9
9
  #include <cybozu/inttype.hpp>
10
10
  #ifdef _WIN32
11
+ #include <intrin.h>
12
+ #if CYBOZU_HOST == CYBOZU_HOST_INTEL
11
13
  #ifndef WIN32_LEAN_AND_MEAN
12
14
  #define WIN32_LEAN_AND_MEAN
13
15
  #endif
14
- #include <windows.h>
15
- #include <intrin.h>
16
+ #include <windows.h> // _mm_mfence
17
+ #endif
16
18
  #else
17
- #include <emmintrin.h>
19
+ #if CYBOZU_HOST == CYBOZU_HOST_INTEL
20
+ #include <x86intrin.h>
21
+ #endif
18
22
  #endif
19
23
 
20
24
  namespace cybozu {
@@ -136,10 +140,16 @@ T AtomicExchange(T *p, T newValue)
136
140
 
137
141
  inline void mfence()
138
142
  {
139
- #ifdef _MSC_VER
143
+ #if defined(_WIN32) && CYBOZU_HOST == CYBOZU_HOST_INTEL
140
144
  MemoryBarrier();
141
- #else
145
+ #elif defined(_WIN32) && CYBOZU_HOST == CYBOZU_HOST_ARM
146
+ __dsb(0xf);
147
+ #elif CYBOZU_HOST == CYBOZU_HOST_INTEL
142
148
  _mm_mfence();
149
+ #elif CYBOZU_HOST == CYBOZU_HOST_ARM
150
+ __sync_synchronize();
151
+ #else
152
+ #error "not supported"
143
153
  #endif
144
154
  }
145
155
 
@@ -89,7 +89,7 @@ private:
89
89
  Data *data = (Data*)self;
90
90
  if (data->found) return;
91
91
  if (section == 0) return;
92
- bfd_vma vma = bfd_section_vma(bfd, section);
92
+ bfd_vma vma = bfd_section_vma(section);
93
93
  if (data->pc < vma) return;
94
94
  bfd_size_type size = bfd_section_size(section);
95
95
  if (data->pc >= vma + size) return;
@@ -6,14 +6,8 @@
6
6
  #include <assert.h>
7
7
  #include <cybozu/inttype.hpp>
8
8
 
9
- #if (CYBOZU_HOST == CYBOZU_HOST_INTEL)
10
- #if defined(_WIN32)
11
- #include <intrin.h>
12
- #elif defined(__linux__) || defined(__CYGWIN__) || defined(__clang__)
13
- #include <x86intrin.h>
14
- #elif defined(__GNUC__)
15
- #include <emmintrin.h>
16
- #endif
9
+ #if defined(_WIN32)
10
+ #include <intrin.h>
17
11
  #endif
18
12
 
19
13
  namespace cybozu {
@@ -117,7 +111,9 @@ uint32_t popcnt(T x);
117
111
  template<>
118
112
  inline uint32_t popcnt<uint32_t>(uint32_t x)
119
113
  {
120
- #if defined(_MSC_VER)
114
+ #if defined(_M_ARM64)
115
+ return static_cast<uint32_t>(_CountOneBits(x));
116
+ #elif defined(_MSC_VER) && !defined(__clang__)
121
117
  return static_cast<uint32_t>(_mm_popcnt_u32(x));
122
118
  #else
123
119
  return static_cast<uint32_t>(__builtin_popcount(x));
@@ -127,7 +123,9 @@ inline uint32_t popcnt<uint32_t>(uint32_t x)
127
123
  template<>
128
124
  inline uint32_t popcnt<uint64_t>(uint64_t x)
129
125
  {
130
- #if defined(__x86_64__)
126
+ #if defined(_M_ARM64)
127
+ return static_cast<uint32_t>(_CountOneBits64(x));
128
+ #elif defined(__x86_64__)
131
129
  return static_cast<uint32_t>(__builtin_popcountll(x));
132
130
  #elif defined(_WIN64)
133
131
  return static_cast<uint32_t>(_mm_popcnt_u64(x));
@@ -6,6 +6,13 @@
6
6
  */
7
7
 
8
8
  #include <cybozu/exception.hpp>
9
+
10
+ #ifndef CYBOZU_USE_OPENSSL_NEW_HASH
11
+ #ifndef _MSC_VER
12
+ #define CYBOZU_USE_OPENSSL_NEW_HASH 1
13
+ #endif
14
+ #endif
15
+
9
16
  #ifdef __APPLE__
10
17
  #pragma GCC diagnostic push
11
18
  #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
@@ -22,8 +29,10 @@
22
29
  #else
23
30
  #include <openssl/hmac.h>
24
31
  #include <openssl/evp.h>
32
+ #if CYBOZU_USE_OPENSSL_NEW_HASH != 1
25
33
  #include <openssl/sha.h>
26
34
  #endif
35
+ #endif
27
36
  #ifdef _MSC_VER
28
37
  #include <cybozu/link_libeay32.hpp>
29
38
  #endif
@@ -44,20 +53,33 @@ public:
44
53
  private:
45
54
  Name name_;
46
55
  size_t hashSize_;
56
+ #if CYBOZU_USE_OPENSSL_NEW_HASH == 1
57
+ EVP_MD_CTX *ctx_;
58
+ void setCTX(const char *name)
59
+ {
60
+ const EVP_MD *md = EVP_get_digestbyname(name);
61
+ if (md == 0) {
62
+ throw cybozu::Exception("EVP_get_digestbyname") << name;
63
+ }
64
+ EVP_MD_CTX_reset(ctx_);
65
+ EVP_DigestInit_ex(ctx_, md, NULL);
66
+ }
67
+ #else
47
68
  union {
48
69
  SHA_CTX sha1;
49
70
  SHA256_CTX sha256;
50
71
  SHA512_CTX sha512;
51
72
  } ctx_;
73
+ #endif
52
74
  public:
53
75
  static inline size_t getSize(Name name)
54
76
  {
55
77
  switch (name) {
56
- case N_SHA1: return SHA_DIGEST_LENGTH;
57
- case N_SHA224: return SHA224_DIGEST_LENGTH;
58
- case N_SHA256: return SHA256_DIGEST_LENGTH;
59
- case N_SHA384: return SHA384_DIGEST_LENGTH;
60
- case N_SHA512: return SHA512_DIGEST_LENGTH;
78
+ case N_SHA1: return 160 / 8;
79
+ case N_SHA224: return 224 / 8;
80
+ case N_SHA256: return 256 / 8;
81
+ case N_SHA384: return 384 / 8;
82
+ case N_SHA512: return 512 / 8;
61
83
  default:
62
84
  throw cybozu::Exception("crypto:Hash:getSize") << name;
63
85
  }
@@ -94,11 +116,23 @@ public:
94
116
  explicit Hash(Name name = N_SHA1)
95
117
  : name_(name)
96
118
  , hashSize_(getSize(name))
119
+ #if CYBOZU_USE_OPENSSL_NEW_HASH == 1
120
+ , ctx_(EVP_MD_CTX_new())
121
+ #endif
97
122
  {
98
123
  reset();
99
124
  }
125
+ #if CYBOZU_USE_OPENSSL_NEW_HASH == 1
126
+ ~Hash()
127
+ {
128
+ EVP_MD_CTX_free(ctx_);
129
+ }
130
+ #endif
100
131
  void update(const void *buf, size_t bufSize)
101
132
  {
133
+ #if CYBOZU_USE_OPENSSL_NEW_HASH == 1
134
+ EVP_DigestUpdate(ctx_, buf, bufSize);
135
+ #else
102
136
  switch (name_) {
103
137
  case N_SHA1: SHA1_Update(&ctx_.sha1, buf, bufSize); break;
104
138
  case N_SHA224: SHA224_Update(&ctx_.sha256, buf, bufSize); break;
@@ -106,6 +140,7 @@ public:
106
140
  case N_SHA384: SHA384_Update(&ctx_.sha512, buf, bufSize); break;
107
141
  case N_SHA512: SHA512_Update(&ctx_.sha512, buf, bufSize); break;
108
142
  }
143
+ #endif
109
144
  }
110
145
  void update(const std::string& buf)
111
146
  {
@@ -114,11 +149,19 @@ public:
114
149
  void reset()
115
150
  {
116
151
  switch (name_) {
152
+ #if CYBOZU_USE_OPENSSL_NEW_HASH == 1
153
+ case N_SHA1: setCTX("sha1"); break;
154
+ case N_SHA224: setCTX("sha224"); break;
155
+ case N_SHA256: setCTX("sha256"); break;
156
+ case N_SHA384: setCTX("sha384"); break;
157
+ case N_SHA512: setCTX("sha512"); break;
158
+ #else
117
159
  case N_SHA1: SHA1_Init(&ctx_.sha1); break;
118
160
  case N_SHA224: SHA224_Init(&ctx_.sha256); break;
119
161
  case N_SHA256: SHA256_Init(&ctx_.sha256); break;
120
162
  case N_SHA384: SHA384_Init(&ctx_.sha512); break;
121
163
  case N_SHA512: SHA512_Init(&ctx_.sha512); break;
164
+ #endif
122
165
  default:
123
166
  throw cybozu::Exception("crypto:Hash:rset") << name_;
124
167
  }
@@ -131,6 +174,10 @@ public:
131
174
  {
132
175
  update(buf, bufSize);
133
176
  unsigned char *md = reinterpret_cast<unsigned char*>(out);
177
+ #if CYBOZU_USE_OPENSSL_NEW_HASH == 1
178
+ unsigned int len;
179
+ EVP_DigestFinal_ex(ctx_, md, &len);
180
+ #else
134
181
  switch (name_) {
135
182
  case N_SHA1: SHA1_Final(md, &ctx_.sha1); break;
136
183
  case N_SHA224: SHA224_Final(md, &ctx_.sha256); break;
@@ -140,6 +187,7 @@ public:
140
187
  default:
141
188
  throw cybozu::Exception("crypto:Hash:digest") << name_;
142
189
  }
190
+ #endif
143
191
  reset();
144
192
  }
145
193
  std::string digest(const void *buf, size_t bufSize)
@@ -159,6 +207,11 @@ public:
159
207
  */
160
208
  static inline size_t digest(void *out, Name name, const void *buf, size_t bufSize)
161
209
  {
210
+ #if 1
211
+ Hash h(name);
212
+ h.digest(out, buf, bufSize);
213
+ return getSize(name);
214
+ #else
162
215
  unsigned char *md = (unsigned char*)out;
163
216
  const unsigned char *src = cybozu::cast<const unsigned char *>(buf);
164
217
  switch (name) {
@@ -170,6 +223,7 @@ public:
170
223
  default:
171
224
  return 0;
172
225
  }
226
+ #endif
173
227
  }
174
228
  static inline std::string digest(Name name, const void *buf, size_t bufSize)
175
229
  {
@@ -8,8 +8,6 @@
8
8
  */
9
9
  #include <cybozu/inttype.hpp>
10
10
  #include <string.h>
11
- #include <stdlib.h>
12
- #include <stdio.h>
13
11
 
14
12
  namespace cybozu {
15
13
 
@@ -71,6 +71,20 @@
71
71
  #define CYBOZU_SNPRINTF(x, len, ...) (void)snprintf(x, len, __VA_ARGS__)
72
72
  #endif
73
73
  #endif
74
+ #ifndef CYBOZU_ASSUME
75
+ #ifdef NDEBUG
76
+ #if defined(__clang__)
77
+ #define CYBOZU_ASSUME(x) __builtin_assume(x)
78
+ #elif defined(_MSC_VER) || defined(__ICC)
79
+ #define CYBOZU_ASSUME(x) __assume(x)
80
+ #else
81
+ #define CYBOZU_ASSUME(x) if (!(x)) { __builtin_unreachable(); }
82
+ #endif
83
+ #else
84
+ #define CYBOZU_ASSUME(x) assert(x)
85
+ #endif
86
+ #endif
87
+
74
88
 
75
89
  // LLONG_MIN in limits.h is not defined in some env.
76
90
  #define CYBOZU_LLONG_MIN (-9223372036854775807ll-1)
@@ -118,7 +132,7 @@
118
132
  #endif
119
133
 
120
134
  #ifndef CYBOZU_OS_BIT
121
- #if defined(_WIN64) || defined(__x86_64__) || defined(__AARCH64EL__) || defined(__EMSCRIPTEN__) || defined(__LP64__)
135
+ #if defined(_WIN64) || defined(__x86_64__) || defined(__AARCH64EL__) || defined(__EMSCRIPTEN__) || defined(__LP64__) || defined(_M_ARM64)
122
136
  #define CYBOZU_OS_BIT 64
123
137
  #else
124
138
  #define CYBOZU_OS_BIT 32
@@ -131,7 +145,7 @@
131
145
  #define CYBOZU_HOST_ARM 2
132
146
  #if defined(_M_IX86) || defined(_M_AMD64) || defined(__x86_64__) || defined(__i386__)
133
147
  #define CYBOZU_HOST CYBOZU_HOST_INTEL
134
- #elif defined(__arm__) || defined(__AARCH64EL__)
148
+ #elif defined(__arm__) || defined(__AARCH64EL__) || defined(_M_ARM64)
135
149
  #define CYBOZU_HOST CYBOZU_HOST_ARM
136
150
  #else
137
151
  #define CYBOZU_HOST CYBOZU_HOST_UNKNOWN
@@ -144,7 +158,7 @@
144
158
  #define CYBOZU_ENDIAN_BIG 2
145
159
  #if (CYBOZU_HOST == CYBOZU_HOST_INTEL)
146
160
  #define CYBOZU_ENDIAN CYBOZU_ENDIAN_LITTLE
147
- #elif (CYBOZU_HOST == CYBOZU_HOST_ARM) && (defined(__ARM_EABI__) || defined(__AARCH64EL__))
161
+ #elif (CYBOZU_HOST == CYBOZU_HOST_ARM) && (defined(__ARM_EABI__) || defined(__AARCH64EL__) || defined(_M_ARM64))
148
162
  #define CYBOZU_ENDIAN CYBOZU_ENDIAN_LITTLE
149
163
  #elif defined(__s390x__)
150
164
  #define CYBOZU_ENDIAN CYBOZU_ENDIAN_BIG
@@ -4,7 +4,7 @@
4
4
  @brief link libeay32.lib of openssl
5
5
  @author MITSUNARI Shigeo(@herumi)
6
6
  */
7
- #if defined(_WIN32) && defined(_MT)
7
+ #if defined(_MSC_VER) && defined(_MT)
8
8
  #if _MSC_VER >= 1900 // VC2015
9
9
  #ifdef _WIN64
10
10
  #pragma comment(lib, "mt/14/libeay32.lib")
@@ -4,7 +4,7 @@
4
4
  @brief link mpir/mpirxx of mpir
5
5
  @author MITSUNARI Shigeo(@herumi)
6
6
  */
7
- #if defined(_WIN32) && defined(_MT)
7
+ #if defined(_MSC_VER) && defined(_MT)
8
8
  #if _MSC_VER >= 1900 // VC2015, VC2017(1910)
9
9
  #pragma comment(lib, "mt/14/mpir.lib")
10
10
  #pragma comment(lib, "mt/14/mpirxx.lib")
@@ -4,7 +4,7 @@
4
4
  @brief link ssleay32.lib of openssl
5
5
  @author MITSUNARI Shigeo(@herumi)
6
6
  */
7
- #if defined(_WIN32) && defined(_MT)
7
+ #if defined(_MSC_VER) && defined(_MT)
8
8
  #if _MSC_VER >= 1900 // VC2015
9
9
  #ifdef _WIN64
10
10
  #pragma comment(lib, "mt/14/ssleay32.lib")
@@ -20,6 +20,7 @@
20
20
  #pragma comment (lib, "advapi32.lib")
21
21
  #endif
22
22
  #else
23
+ #include <stdio.h>
23
24
  #include <sys/types.h>
24
25
  #include <fcntl.h>
25
26
  #endif
@@ -16,11 +16,23 @@
16
16
  #include <memory.h>
17
17
 
18
18
  #ifdef CYBOZU_USE_OPENSSL_SHA
19
+
20
+ #ifndef CYBOZU_USE_OPENSSL_NEW_HASH
21
+ #ifndef _MSC_VER
22
+ #define CYBOZU_USE_OPENSSL_NEW_HASH 1
23
+ #endif
24
+ #endif
25
+
19
26
  #ifdef __APPLE__
20
27
  #pragma GCC diagnostic push
21
28
  #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
22
29
  #endif
30
+ #if CYBOZU_USE_OPENSSL_NEW_HASH == 1
31
+ #include <openssl/evp.h>
32
+ #include <assert.h>
33
+ #else
23
34
  #include <openssl/sha.h>
35
+ #endif
24
36
  #ifdef _MSC_VER
25
37
  #include <cybozu/link_libeay32.hpp>
26
38
  #endif
@@ -31,27 +43,90 @@
31
43
 
32
44
  namespace cybozu {
33
45
 
46
+ #if CYBOZU_USE_OPENSSL_NEW_HASH == 1
47
+ namespace local {
48
+
49
+ template<size_t MD_SIZE_>
50
+ struct NewHash {
51
+ static const size_t MD_SIZE = MD_SIZE_;
52
+ EVP_MD_CTX *mdctx_;
53
+ const EVP_MD *md_;
54
+ explicit NewHash(const char *name)
55
+ : mdctx_(EVP_MD_CTX_new())
56
+ , md_(EVP_get_digestbyname(name))
57
+ {
58
+ if (md_ == 0) {
59
+ fprintf(stderr, "fatail error NewHash %s\n", name);
60
+ }
61
+ assert(md_);
62
+ }
63
+ ~NewHash()
64
+ {
65
+ EVP_MD_CTX_free(mdctx_);
66
+ }
67
+ void clear()
68
+ {
69
+ EVP_MD_CTX_reset(mdctx_);
70
+ EVP_DigestInit_ex(mdctx_, md_, NULL);
71
+ }
72
+ void update(const void *buf, size_t bufSize)
73
+ {
74
+ EVP_DigestUpdate(mdctx_, buf, bufSize);
75
+ }
76
+ size_t digest(void *md, size_t mdSize, const void *buf, size_t bufSize)
77
+ {
78
+ if (mdSize < MD_SIZE) return 0;
79
+ update(buf, bufSize);
80
+ unsigned int len;
81
+ EVP_DigestFinal_ex(mdctx_, (unsigned char*)md, &len);
82
+ assert(len == MD_SIZE);
83
+ return MD_SIZE;
84
+ }
85
+ };
86
+
87
+ } // local
88
+ #endif
89
+
34
90
  class Sha256 {
91
+ #if CYBOZU_USE_OPENSSL_NEW_HASH == 1
92
+ local::NewHash<32> ctx_;
93
+ #else
35
94
  SHA256_CTX ctx_;
95
+ #endif
36
96
  public:
37
97
  Sha256()
98
+ #if CYBOZU_USE_OPENSSL_NEW_HASH == 1
99
+ : ctx_("sha256")
100
+ #endif
38
101
  {
39
102
  clear();
40
103
  }
41
104
  void clear()
42
105
  {
106
+ #if CYBOZU_USE_OPENSSL_NEW_HASH == 1
107
+ ctx_.clear();
108
+ #else
43
109
  SHA256_Init(&ctx_);
110
+ #endif
44
111
  }
45
112
  void update(const void *buf, size_t bufSize)
46
113
  {
114
+ #if CYBOZU_USE_OPENSSL_NEW_HASH == 1
115
+ ctx_.update(buf, bufSize);
116
+ #else
47
117
  SHA256_Update(&ctx_, buf, bufSize);
118
+ #endif
48
119
  }
49
120
  size_t digest(void *md, size_t mdSize, const void *buf, size_t bufSize)
50
121
  {
122
+ #if CYBOZU_USE_OPENSSL_NEW_HASH == 1
123
+ return ctx_.digest(md, mdSize, buf, bufSize);
124
+ #else
51
125
  if (mdSize < SHA256_DIGEST_LENGTH) return 0;
52
126
  update(buf, bufSize);
53
127
  SHA256_Final(reinterpret_cast<uint8_t*>(md), &ctx_);
54
128
  return SHA256_DIGEST_LENGTH;
129
+ #endif
55
130
  }
56
131
  #ifndef CYBOZU_DONT_USE_STRING
57
132
  void update(const std::string& buf)
@@ -64,7 +139,11 @@ public:
64
139
  }
65
140
  std::string digest(const void *buf, size_t bufSize)
66
141
  {
142
+ #if CYBOZU_USE_OPENSSL_NEW_HASH == 1
143
+ std::string md(ctx_.MD_SIZE, 0);
144
+ #else
67
145
  std::string md(SHA256_DIGEST_LENGTH, 0);
146
+ #endif
68
147
  digest(&md[0], md.size(), buf, bufSize);
69
148
  return md;
70
149
  }
@@ -72,26 +151,45 @@ public:
72
151
  };
73
152
 
74
153
  class Sha512 {
154
+ #if CYBOZU_USE_OPENSSL_NEW_HASH == 1
155
+ local::NewHash<64> ctx_;
156
+ #else
75
157
  SHA512_CTX ctx_;
158
+ #endif
76
159
  public:
77
160
  Sha512()
161
+ #if CYBOZU_USE_OPENSSL_NEW_HASH == 1
162
+ : ctx_("sha512")
163
+ #endif
78
164
  {
79
165
  clear();
80
166
  }
81
167
  void clear()
82
168
  {
169
+ #if CYBOZU_USE_OPENSSL_NEW_HASH == 1
170
+ ctx_.clear();
171
+ #else
83
172
  SHA512_Init(&ctx_);
173
+ #endif
84
174
  }
85
175
  void update(const void *buf, size_t bufSize)
86
176
  {
177
+ #if CYBOZU_USE_OPENSSL_NEW_HASH == 1
178
+ ctx_.update(buf, bufSize);
179
+ #else
87
180
  SHA512_Update(&ctx_, buf, bufSize);
181
+ #endif
88
182
  }
89
183
  size_t digest(void *md, size_t mdSize, const void *buf, size_t bufSize)
90
184
  {
185
+ #if CYBOZU_USE_OPENSSL_NEW_HASH == 1
186
+ return ctx_.digest(md, mdSize, buf, bufSize);
187
+ #else
91
188
  if (mdSize < SHA512_DIGEST_LENGTH) return 0;
92
189
  update(buf, bufSize);
93
190
  SHA512_Final(reinterpret_cast<uint8_t*>(md), &ctx_);
94
191
  return SHA512_DIGEST_LENGTH;
192
+ #endif
95
193
  }
96
194
  #ifndef CYBOZU_DONT_USE_STRING
97
195
  void update(const std::string& buf)
@@ -104,7 +202,11 @@ public:
104
202
  }
105
203
  std::string digest(const void *buf, size_t bufSize)
106
204
  {
205
+ #if CYBOZU_USE_OPENSSL_NEW_HASH == 1
206
+ std::string md(ctx_.MD_SIZE, 0);
207
+ #else
107
208
  std::string md(SHA512_DIGEST_LENGTH, 0);
209
+ #endif
108
210
  digest(&md[0], md.size(), buf, bufSize);
109
211
  return md;
110
212
  }
@@ -1,4 +1,4 @@
1
- ����<?xml version="1.0" encoding="utf-8"?>
1
+ <?xml version="1.0" encoding="utf-8"?>
2
2
  <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
3
  <ItemGroup Label="ProjectConfigurations">
4
4
  <ProjectConfiguration Include="Debug|x64">
@@ -1,4 +1,4 @@
1
- ����<?xml version="1.0" encoding="utf-8"?>
1
+ <?xml version="1.0" encoding="utf-8"?>
2
2
  <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
3
  <ItemGroup Label="ProjectConfigurations">
4
4
  <ProjectConfiguration Include="Debug|x64">
@@ -1,12 +1,12 @@
1
1
 
2
2
  all:
3
3
  $(MAKE) -C base
4
- $(MAKE) -C nlp
4
+ # $(MAKE) -C nlp
5
5
 
6
6
  test:
7
7
  $(MAKE) -C base test
8
- $(MAKE) -C nlp test
8
+ # $(MAKE) -C nlp test
9
9
  clean:
10
10
  $(MAKE) -C base clean
11
- $(MAKE) -C nlp clean
11
+ # $(MAKE) -C nlp clean
12
12
 
@@ -1,4 +1,4 @@
1
- ����<?xml version="1.0" encoding="utf-8"?>
1
+ <?xml version="1.0" encoding="utf-8"?>
2
2
  <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
3
  <ItemGroup Label="ProjectConfigurations">
4
4
  <ProjectConfiguration Include="Debug|x64">
@@ -1,4 +1,4 @@
1
- ����<?xml version="1.0" encoding="utf-8"?>
1
+ <?xml version="1.0" encoding="utf-8"?>
2
2
  <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
3
  <ItemGroup Label="ProjectConfigurations">
4
4
  <ProjectConfiguration Include="Debug|x64">
@@ -1,4 +1,4 @@
1
- ����<?xml version="1.0" encoding="utf-8"?>
1
+ <?xml version="1.0" encoding="utf-8"?>
2
2
  <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
3
  <ItemGroup Label="ProjectConfigurations">
4
4
  <ProjectConfiguration Include="Debug|x64">
@@ -1,4 +1,4 @@
1
- ����<?xml version="1.0" encoding="utf-8"?>
1
+ <?xml version="1.0" encoding="utf-8"?>
2
2
  <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
3
  <ItemGroup Label="ProjectConfigurations">
4
4
  <ProjectConfiguration Include="Debug|x64">
@@ -1,4 +1,4 @@
1
- ����<?xml version="1.0" encoding="utf-8"?>
1
+ <?xml version="1.0" encoding="utf-8"?>
2
2
  <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
3
  <ItemGroup Label="ProjectConfigurations">
4
4
  <ProjectConfiguration Include="Debug|x64">
@@ -1,4 +1,4 @@
1
- ����<?xml version="1.0" encoding="utf-8"?>
1
+ <?xml version="1.0" encoding="utf-8"?>
2
2
  <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
3
  <ItemGroup Label="ProjectConfigurations">
4
4
  <ProjectConfiguration Include="Debug|x64">
@@ -1,4 +1,4 @@
1
- ����<?xml version="1.0" encoding="utf-8"?>
1
+ <?xml version="1.0" encoding="utf-8"?>
2
2
  <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
3
  <ItemGroup Label="ProjectConfigurations">
4
4
  <ProjectConfiguration Include="Debug|x64">
@@ -1,4 +1,4 @@
1
- ����<?xml version="1.0" encoding="utf-8"?>
1
+ <?xml version="1.0" encoding="utf-8"?>
2
2
  <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
3
  <ItemGroup Label="ProjectConfigurations">
4
4
  <ProjectConfiguration Include="Debug|x64">