grpc 1.38.0 → 1.39.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +50 -19
  3. data/include/grpc/event_engine/endpoint_config.h +48 -0
  4. data/include/grpc/event_engine/event_engine.h +13 -15
  5. data/include/grpc/event_engine/port.h +2 -0
  6. data/include/grpc/event_engine/slice_allocator.h +17 -7
  7. data/include/grpc/grpc.h +9 -2
  8. data/include/grpc/grpc_security.h +32 -0
  9. data/include/grpc/grpc_security_constants.h +1 -0
  10. data/include/grpc/impl/codegen/grpc_types.h +17 -13
  11. data/include/grpc/impl/codegen/port_platform.h +17 -0
  12. data/src/core/ext/filters/client_channel/client_channel.cc +2 -2
  13. data/src/core/ext/filters/client_channel/health/health_check_client.cc +2 -0
  14. data/src/core/ext/filters/client_channel/health/health_check_client.h +3 -3
  15. data/src/core/ext/filters/client_channel/http_proxy.cc +16 -1
  16. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +755 -0
  17. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h +10 -0
  18. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +10 -24
  19. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +63 -95
  20. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +1 -3
  21. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc +31 -0
  22. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc +28 -0
  23. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +1 -3
  24. data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +7 -2
  25. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +15 -3
  26. data/src/core/ext/filters/client_channel/retry_filter.cc +665 -404
  27. data/src/core/ext/filters/client_channel/retry_service_config.cc +43 -24
  28. data/src/core/ext/filters/client_channel/retry_service_config.h +8 -2
  29. data/src/core/ext/filters/client_idle/client_idle_filter.cc +1 -1
  30. data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +6 -0
  31. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +2 -1
  32. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +3 -2
  33. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +10 -4
  34. data/src/core/ext/transport/chttp2/transport/internal.h +1 -0
  35. data/src/core/ext/transport/chttp2/transport/parsing.cc +2 -2
  36. data/src/core/ext/transport/inproc/inproc_transport.cc +42 -31
  37. data/src/core/ext/xds/xds_api.cc +247 -106
  38. data/src/core/ext/xds/xds_api.h +15 -6
  39. data/src/core/lib/address_utils/sockaddr_utils.cc +13 -0
  40. data/src/core/lib/address_utils/sockaddr_utils.h +10 -0
  41. data/src/core/lib/channel/channelz.h +3 -0
  42. data/src/core/lib/event_engine/endpoint_config.cc +46 -0
  43. data/src/core/lib/event_engine/endpoint_config_internal.h +42 -0
  44. data/src/core/lib/event_engine/event_engine.cc +50 -0
  45. data/src/core/lib/event_engine/slice_allocator.cc +33 -3
  46. data/src/core/lib/event_engine/sockaddr.cc +14 -12
  47. data/src/core/lib/event_engine/sockaddr.h +44 -0
  48. data/src/core/lib/gpr/wrap_memcpy.cc +2 -1
  49. data/src/core/lib/gprpp/status_helper.h +3 -0
  50. data/src/core/lib/iomgr/endpoint_pair_event_engine.cc +33 -0
  51. data/src/core/lib/iomgr/error.cc +5 -4
  52. data/src/core/lib/iomgr/error.h +1 -1
  53. data/src/core/lib/iomgr/event_engine/closure.cc +54 -0
  54. data/src/core/lib/iomgr/event_engine/closure.h +33 -0
  55. data/src/core/lib/iomgr/event_engine/endpoint.cc +194 -0
  56. data/src/core/lib/iomgr/event_engine/endpoint.h +53 -0
  57. data/src/core/lib/iomgr/event_engine/iomgr.cc +105 -0
  58. data/src/core/lib/iomgr/event_engine/iomgr.h +24 -0
  59. data/src/core/lib/iomgr/event_engine/pollset.cc +87 -0
  60. data/{include/grpc/event_engine/channel_args.h → src/core/lib/iomgr/event_engine/pollset.h} +7 -10
  61. data/src/core/lib/iomgr/event_engine/promise.h +51 -0
  62. data/src/core/lib/iomgr/event_engine/resolved_address_internal.cc +41 -0
  63. data/src/core/lib/iomgr/event_engine/resolved_address_internal.h +35 -0
  64. data/src/core/lib/iomgr/event_engine/resolver.cc +110 -0
  65. data/src/core/lib/iomgr/event_engine/tcp.cc +243 -0
  66. data/src/core/lib/iomgr/event_engine/timer.cc +57 -0
  67. data/src/core/lib/iomgr/exec_ctx.cc +8 -0
  68. data/src/core/lib/iomgr/exec_ctx.h +3 -4
  69. data/src/core/lib/iomgr/executor/threadpool.cc +2 -3
  70. data/src/core/lib/iomgr/executor/threadpool.h +2 -2
  71. data/src/core/lib/iomgr/iomgr.cc +1 -1
  72. data/src/core/lib/iomgr/iomgr_posix.cc +2 -0
  73. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +40 -10
  74. data/src/core/lib/iomgr/pollset_custom.cc +2 -2
  75. data/src/core/lib/iomgr/pollset_custom.h +3 -1
  76. data/src/core/lib/iomgr/pollset_uv.cc +3 -1
  77. data/src/core/lib/iomgr/pollset_uv.h +5 -1
  78. data/src/core/lib/iomgr/port.h +7 -5
  79. data/src/core/lib/iomgr/resolve_address.cc +5 -1
  80. data/src/core/lib/iomgr/resolve_address.h +6 -0
  81. data/src/core/lib/iomgr/sockaddr.h +1 -0
  82. data/src/core/lib/iomgr/socket_mutator.cc +15 -2
  83. data/src/core/lib/iomgr/socket_mutator.h +26 -2
  84. data/src/core/lib/iomgr/socket_utils_common_posix.cc +4 -4
  85. data/src/core/lib/iomgr/socket_utils_posix.h +2 -2
  86. data/src/core/lib/iomgr/tcp_client_posix.cc +7 -2
  87. data/src/core/lib/iomgr/tcp_posix.cc +42 -39
  88. data/src/core/lib/iomgr/tcp_posix.h +8 -0
  89. data/src/core/lib/iomgr/tcp_server_custom.cc +3 -4
  90. data/src/core/lib/iomgr/tcp_server_posix.cc +6 -0
  91. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +2 -1
  92. data/src/core/lib/iomgr/timer.h +6 -1
  93. data/src/core/lib/security/authorization/authorization_engine.h +44 -0
  94. data/src/core/lib/security/authorization/authorization_policy_provider.h +32 -0
  95. data/src/core/lib/security/authorization/authorization_policy_provider_vtable.cc +46 -0
  96. data/src/core/lib/security/authorization/evaluate_args.cc +209 -0
  97. data/src/core/lib/security/authorization/evaluate_args.h +91 -0
  98. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +3 -1
  99. data/src/core/lib/security/credentials/tls/tls_utils.cc +32 -0
  100. data/src/core/lib/security/credentials/tls/tls_utils.h +13 -0
  101. data/src/core/lib/security/security_connector/local/local_security_connector.cc +9 -6
  102. data/src/core/lib/security/security_connector/ssl_utils.cc +5 -0
  103. data/src/core/lib/surface/call.cc +21 -1
  104. data/src/core/lib/surface/call.h +11 -0
  105. data/src/core/lib/surface/completion_queue.cc +22 -22
  106. data/src/core/lib/surface/completion_queue.h +1 -1
  107. data/src/core/lib/surface/completion_queue_factory.cc +1 -2
  108. data/src/core/lib/surface/init.cc +1 -3
  109. data/src/core/lib/surface/init.h +10 -1
  110. data/src/core/lib/surface/version.cc +1 -1
  111. data/src/core/lib/transport/error_utils.cc +2 -2
  112. data/src/core/lib/transport/transport.h +2 -0
  113. data/src/core/lib/transport/transport_op_string.cc +1 -1
  114. data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -0
  115. data/src/core/tsi/alts/crypt/gsec.h +2 -0
  116. data/src/ruby/ext/grpc/extconf.rb +2 -0
  117. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +6 -0
  118. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +10 -1
  119. data/src/ruby/lib/grpc/version.rb +1 -1
  120. data/third_party/boringssl-with-bazel/err_data.c +269 -263
  121. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_object.c +8 -6
  122. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/cipher_extra.c +4 -0
  123. data/third_party/boringssl-with-bazel/src/crypto/curve25519/curve25519.c +1 -1
  124. data/third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h +1 -1
  125. data/third_party/boringssl-with-bazel/src/crypto/evp/evp.c +9 -0
  126. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/prime.c +0 -4
  127. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digest.c +7 -0
  128. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/md32_common.h +87 -121
  129. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/md4/md4.c +20 -30
  130. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/md5/md5.c +19 -30
  131. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/internal.h +1 -4
  132. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/rand.c +0 -13
  133. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa.c +26 -24
  134. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +10 -7
  135. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha1.c +28 -39
  136. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha256.c +48 -66
  137. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha512.c +4 -5
  138. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +362 -371
  139. data/third_party/boringssl-with-bazel/src/crypto/pkcs7/pkcs7_x509.c +4 -2
  140. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/passive.c +2 -2
  141. data/third_party/boringssl-with-bazel/src/crypto/rsa_extra/rsa_asn1.c +1 -2
  142. data/third_party/boringssl-with-bazel/src/crypto/x509/internal.h +101 -11
  143. data/third_party/boringssl-with-bazel/src/crypto/x509/t_x509a.c +3 -0
  144. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_cmp.c +2 -2
  145. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_req.c +3 -0
  146. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_set.c +1 -1
  147. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_trs.c +2 -0
  148. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +14 -15
  149. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vpm.c +53 -73
  150. data/third_party/boringssl-with-bazel/src/crypto/x509/x509cset.c +31 -0
  151. data/third_party/boringssl-with-bazel/src/crypto/x509/x509rset.c +3 -0
  152. data/third_party/boringssl-with-bazel/src/crypto/x509/x_all.c +3 -0
  153. data/third_party/boringssl-with-bazel/src/crypto/x509/x_req.c +5 -8
  154. data/third_party/boringssl-with-bazel/src/crypto/x509/x_sig.c +5 -0
  155. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509a.c +3 -0
  156. data/third_party/boringssl-with-bazel/src/crypto/x509v3/internal.h +7 -0
  157. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_purp.c +1 -1
  158. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_utl.c +5 -8
  159. data/third_party/boringssl-with-bazel/src/include/openssl/aead.h +1 -1
  160. data/third_party/boringssl-with-bazel/src/include/openssl/arm_arch.h +66 -1
  161. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +40 -9
  162. data/third_party/boringssl-with-bazel/src/include/openssl/bytestring.h +1 -0
  163. data/third_party/boringssl-with-bazel/src/include/openssl/chacha.h +1 -1
  164. data/third_party/boringssl-with-bazel/src/include/openssl/digest.h +6 -2
  165. data/third_party/boringssl-with-bazel/src/include/openssl/ecdsa.h +14 -0
  166. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +19 -11
  167. data/third_party/boringssl-with-bazel/src/include/openssl/hpke.h +325 -0
  168. data/third_party/boringssl-with-bazel/src/include/openssl/pkcs7.h +23 -7
  169. data/third_party/boringssl-with-bazel/src/include/openssl/rsa.h +99 -63
  170. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +139 -109
  171. data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +12 -19
  172. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +48 -50
  173. data/third_party/boringssl-with-bazel/src/include/openssl/x509_vfy.h +451 -435
  174. data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +0 -1
  175. data/third_party/boringssl-with-bazel/src/ssl/d1_both.cc +2 -2
  176. data/third_party/boringssl-with-bazel/src/ssl/d1_srtp.cc +1 -1
  177. data/third_party/boringssl-with-bazel/src/ssl/encrypted_client_hello.cc +773 -84
  178. data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +80 -47
  179. data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +24 -19
  180. data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +189 -86
  181. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +45 -56
  182. data/third_party/boringssl-with-bazel/src/ssl/internal.h +272 -167
  183. data/third_party/boringssl-with-bazel/src/ssl/s3_both.cc +2 -2
  184. data/third_party/boringssl-with-bazel/src/ssl/s3_lib.cc +2 -2
  185. data/third_party/boringssl-with-bazel/src/ssl/s3_pkt.cc +14 -19
  186. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +34 -102
  187. data/third_party/boringssl-with-bazel/src/ssl/ssl_privkey.cc +2 -0
  188. data/third_party/boringssl-with-bazel/src/ssl/ssl_session.cc +8 -31
  189. data/third_party/boringssl-with-bazel/src/ssl/ssl_stat.cc +3 -0
  190. data/third_party/boringssl-with-bazel/src/ssl/ssl_transcript.cc +4 -3
  191. data/third_party/boringssl-with-bazel/src/ssl/ssl_versions.cc +7 -3
  192. data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +576 -648
  193. data/third_party/boringssl-with-bazel/src/ssl/tls13_both.cc +31 -3
  194. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +98 -39
  195. data/third_party/boringssl-with-bazel/src/ssl/tls13_enc.cc +141 -94
  196. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +58 -68
  197. metadata +65 -40
  198. data/third_party/boringssl-with-bazel/src/crypto/hpke/internal.h +0 -267
  199. data/third_party/boringssl-with-bazel/src/crypto/x509/vpm_int.h +0 -71
@@ -180,16 +180,13 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
180
180
  }
181
181
  }
182
182
 
183
- /*
184
- * only the ASN1_OBJECTs from the 'table' will have values for ->sn or
185
- * ->ln
186
- */
187
183
  if ((a == NULL) || ((*a) == NULL) ||
188
184
  !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) {
189
185
  if ((ret = ASN1_OBJECT_new()) == NULL)
190
186
  return (NULL);
191
- } else
187
+ } else {
192
188
  ret = (*a);
189
+ }
193
190
 
194
191
  p = *pp;
195
192
  /* detach data from object */
@@ -208,12 +205,17 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
208
205
  ret->flags |= ASN1_OBJECT_FLAG_DYNAMIC_DATA;
209
206
  }
210
207
  OPENSSL_memcpy(data, p, length);
208
+ /* If there are dynamic strings, free them here, and clear the flag */
209
+ if ((ret->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) != 0) {
210
+ OPENSSL_free((char *)ret->sn);
211
+ OPENSSL_free((char *)ret->ln);
212
+ ret->flags &= ~ASN1_OBJECT_FLAG_DYNAMIC_STRINGS;
213
+ }
211
214
  /* reattach data to object, after which it remains const */
212
215
  ret->data = data;
213
216
  ret->length = length;
214
217
  ret->sn = NULL;
215
218
  ret->ln = NULL;
216
- /* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */
217
219
  p += length;
218
220
 
219
221
  if (a != NULL)
@@ -89,6 +89,10 @@ const EVP_CIPHER *EVP_get_cipherbynid(int nid) {
89
89
  }
90
90
 
91
91
  const EVP_CIPHER *EVP_get_cipherbyname(const char *name) {
92
+ if (name == NULL) {
93
+ return NULL;
94
+ }
95
+
92
96
  if (OPENSSL_strcasecmp(name, "rc4") == 0) {
93
97
  return EVP_rc4();
94
98
  } else if (OPENSSL_strcasecmp(name, "des-cbc") == 0) {
@@ -820,7 +820,7 @@ static void table_select(ge_precomp *t, int pos, signed char b) {
820
820
  //
821
821
  // Preconditions:
822
822
  // a[31] <= 127
823
- void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t *a) {
823
+ void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t a[32]) {
824
824
  signed char e[64];
825
825
  signed char carry;
826
826
  ge_p1p1 r;
@@ -106,7 +106,7 @@ typedef struct {
106
106
  } ge_cached;
107
107
 
108
108
  void x25519_ge_tobytes(uint8_t s[32], const ge_p2 *h);
109
- int x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t *s);
109
+ int x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t s[32]);
110
110
  void x25519_ge_p3_to_cached(ge_cached *r, const ge_p3 *p);
111
111
  void x25519_ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p);
112
112
  void x25519_ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p);
@@ -429,6 +429,15 @@ int EVP_PKEY_CTX_get_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD **out_md) {
429
429
  0, (void *)out_md);
430
430
  }
431
431
 
432
+ void *EVP_PKEY_get0(const EVP_PKEY *pkey) {
433
+ // Node references, but never calls this function, so for now we return NULL.
434
+ // If other projects require complete support, call |EVP_PKEY_get0_RSA|, etc.,
435
+ // rather than reading |pkey->pkey.ptr| directly. This avoids problems if our
436
+ // internal representation does not match the type the caller expects from
437
+ // OpenSSL.
438
+ return NULL;
439
+ }
440
+
432
441
  void OpenSSL_add_all_algorithms(void) {}
433
442
 
434
443
  void OPENSSL_add_all_algorithms_conf(void) {}
@@ -115,10 +115,6 @@
115
115
  #include "../../internal.h"
116
116
 
117
117
 
118
- // The quick sieve algorithm approach to weeding out primes is Philip
119
- // Zimmermann's, as implemented in PGP. I have had a read of his comments and
120
- // implemented my own version.
121
-
122
118
  // kPrimes contains the first 1024 primes.
123
119
  static const uint16_t kPrimes[] = {
124
120
  2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37,
@@ -177,6 +177,13 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) {
177
177
  return 1;
178
178
  }
179
179
 
180
+ void EVP_MD_CTX_move(EVP_MD_CTX *out, EVP_MD_CTX *in) {
181
+ EVP_MD_CTX_cleanup(out);
182
+ // While not guaranteed, |EVP_MD_CTX| is currently safe to move with |memcpy|.
183
+ OPENSSL_memcpy(out, in, sizeof(EVP_MD_CTX));
184
+ EVP_MD_CTX_init(in);
185
+ }
186
+
180
187
  int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in) {
181
188
  EVP_MD_CTX_init(out);
182
189
  return EVP_MD_CTX_copy_ex(out, in);
@@ -46,6 +46,9 @@
46
46
  * OF THE POSSIBILITY OF SUCH DAMAGE.
47
47
  * ==================================================================== */
48
48
 
49
+ #ifndef OPENSSL_HEADER_DIGEST_MD32_COMMON_H
50
+ #define OPENSSL_HEADER_DIGEST_MD32_COMMON_H
51
+
49
52
  #include <openssl/base.h>
50
53
 
51
54
  #include <assert.h>
@@ -59,22 +62,15 @@ extern "C" {
59
62
 
60
63
  // This is a generic 32-bit "collector" for message digest algorithms. It
61
64
  // collects input character stream into chunks of 32-bit values and invokes the
62
- // block function that performs the actual hash calculations. To make use of
63
- // this mechanism, the following macros must be defined before including
64
- // md32_common.h.
65
- //
66
- // One of |DATA_ORDER_IS_BIG_ENDIAN| or |DATA_ORDER_IS_LITTLE_ENDIAN| must be
67
- // defined to specify the byte order of the input stream.
68
- //
69
- // |HASH_CBLOCK| must be defined as the integer block size, in bytes.
65
+ // block function that performs the actual hash calculations.
70
66
  //
71
- // |HASH_CTX| must be defined as the name of the context structure, which must
72
- // have at least the following members:
67
+ // To make use of this mechanism, the hash context should be defined with the
68
+ // following parameters.
73
69
  //
74
70
  // typedef struct <name>_state_st {
75
71
  // uint32_t h[<chaining length> / sizeof(uint32_t)];
76
72
  // uint32_t Nl, Nh;
77
- // uint8_t data[HASH_CBLOCK];
73
+ // uint8_t data[<block size>];
78
74
  // unsigned num;
79
75
  // ...
80
76
  // } <NAME>_CTX;
@@ -83,147 +79,117 @@ extern "C" {
83
79
  // any truncation (e.g. 64 for SHA-224 and SHA-256, 128 for SHA-384 and
84
80
  // SHA-512).
85
81
  //
86
- // |HASH_UPDATE| must be defined as the name of the "Update" function to
87
- // generate.
88
- //
89
- // |HASH_TRANSFORM| must be defined as the the name of the "Transform"
90
- // function to generate.
91
- //
92
- // |HASH_FINAL| must be defined as the name of "Final" function to generate.
93
- //
94
- // |HASH_BLOCK_DATA_ORDER| must be defined as the name of the "Block" function.
95
- // That function must be implemented manually. It must be capable of operating
96
- // on *unaligned* input data in its original (data) byte order. It must have
97
- // this signature:
98
- //
99
- // void HASH_BLOCK_DATA_ORDER(uint32_t *state, const uint8_t *data,
100
- // size_t num);
101
- //
102
- // It must update the hash state |state| with |num| blocks of data from |data|,
103
- // where each block is |HASH_CBLOCK| bytes; i.e. |data| points to a array of
104
- // |HASH_CBLOCK * num| bytes. |state| points to the |h| member of a |HASH_CTX|,
105
- // and so will have |<chaining length> / sizeof(uint32_t)| elements.
106
- //
107
- // |HASH_MAKE_STRING(c, s)| must be defined as a block statement that converts
108
- // the hash state |c->h| into the output byte order, storing the result in |s|.
109
-
110
- #if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN)
111
- #error "DATA_ORDER must be defined!"
112
- #endif
113
-
114
- #ifndef HASH_CBLOCK
115
- #error "HASH_CBLOCK must be defined!"
116
- #endif
117
- #ifndef HASH_CTX
118
- #error "HASH_CTX must be defined!"
119
- #endif
120
-
121
- #ifndef HASH_UPDATE
122
- #error "HASH_UPDATE must be defined!"
123
- #endif
124
- #ifndef HASH_TRANSFORM
125
- #error "HASH_TRANSFORM must be defined!"
126
- #endif
127
- #ifndef HASH_FINAL
128
- #error "HASH_FINAL must be defined!"
129
- #endif
130
-
131
- #ifndef HASH_BLOCK_DATA_ORDER
132
- #error "HASH_BLOCK_DATA_ORDER must be defined!"
133
- #endif
134
-
135
- #ifndef HASH_MAKE_STRING
136
- #error "HASH_MAKE_STRING must be defined!"
137
- #endif
138
-
139
- int HASH_UPDATE(HASH_CTX *c, const void *data_, size_t len) {
140
- const uint8_t *data = data_;
141
-
82
+ // |h| is the hash state and is updated by a function of type
83
+ // |crypto_md32_block_func|. |data| is the partial unprocessed block and has
84
+ // |num| bytes. |Nl| and |Nh| maintain the number of bits processed so far.
85
+
86
+ // A crypto_md32_block_func should incorporate |num_blocks| of input from |data|
87
+ // into |state|. It is assumed the caller has sized |state| and |data| for the
88
+ // hash function.
89
+ typedef void (*crypto_md32_block_func)(uint32_t *state, const uint8_t *data,
90
+ size_t num_blocks);
91
+
92
+ // crypto_md32_update adds |len| bytes from |in| to the digest. |data| must be a
93
+ // buffer of length |block_size| with the first |*num| bytes containing a
94
+ // partial block. This function combines the partial block with |in| and
95
+ // incorporates any complete blocks into the digest state |h|. It then updates
96
+ // |data| and |*num| with the new partial block and updates |*Nh| and |*Nl| with
97
+ // the data consumed.
98
+ static inline void crypto_md32_update(crypto_md32_block_func block_func,
99
+ uint32_t *h, uint8_t *data,
100
+ size_t block_size, unsigned *num,
101
+ uint32_t *Nh, uint32_t *Nl,
102
+ const uint8_t *in, size_t len) {
142
103
  if (len == 0) {
143
- return 1;
104
+ return;
144
105
  }
145
106
 
146
- uint32_t l = c->Nl + (((uint32_t)len) << 3);
147
- if (l < c->Nl) {
107
+ uint32_t l = *Nl + (((uint32_t)len) << 3);
108
+ if (l < *Nl) {
148
109
  // Handle carries.
149
- c->Nh++;
110
+ (*Nh)++;
150
111
  }
151
- c->Nh += (uint32_t)(len >> 29);
152
- c->Nl = l;
112
+ *Nh += (uint32_t)(len >> 29);
113
+ *Nl = l;
153
114
 
154
- size_t n = c->num;
115
+ size_t n = *num;
155
116
  if (n != 0) {
156
- if (len >= HASH_CBLOCK || len + n >= HASH_CBLOCK) {
157
- OPENSSL_memcpy(c->data + n, data, HASH_CBLOCK - n);
158
- HASH_BLOCK_DATA_ORDER(c->h, c->data, 1);
159
- n = HASH_CBLOCK - n;
160
- data += n;
117
+ if (len >= block_size || len + n >= block_size) {
118
+ OPENSSL_memcpy(data + n, in, block_size - n);
119
+ block_func(h, data, 1);
120
+ n = block_size - n;
121
+ in += n;
161
122
  len -= n;
162
- c->num = 0;
163
- // Keep |c->data| zeroed when unused.
164
- OPENSSL_memset(c->data, 0, HASH_CBLOCK);
123
+ *num = 0;
124
+ // Keep |data| zeroed when unused.
125
+ OPENSSL_memset(data, 0, block_size);
165
126
  } else {
166
- OPENSSL_memcpy(c->data + n, data, len);
167
- c->num += (unsigned)len;
168
- return 1;
127
+ OPENSSL_memcpy(data + n, in, len);
128
+ *num += (unsigned)len;
129
+ return;
169
130
  }
170
131
  }
171
132
 
172
- n = len / HASH_CBLOCK;
133
+ n = len / block_size;
173
134
  if (n > 0) {
174
- HASH_BLOCK_DATA_ORDER(c->h, data, n);
175
- n *= HASH_CBLOCK;
176
- data += n;
135
+ block_func(h, in, n);
136
+ n *= block_size;
137
+ in += n;
177
138
  len -= n;
178
139
  }
179
140
 
180
141
  if (len != 0) {
181
- c->num = (unsigned)len;
182
- OPENSSL_memcpy(c->data, data, len);
142
+ *num = (unsigned)len;
143
+ OPENSSL_memcpy(data, in, len);
183
144
  }
184
- return 1;
185
- }
186
-
187
-
188
- void HASH_TRANSFORM(HASH_CTX *c, const uint8_t data[HASH_CBLOCK]) {
189
- HASH_BLOCK_DATA_ORDER(c->h, data, 1);
190
145
  }
191
146
 
192
-
193
- int HASH_FINAL(uint8_t out[HASH_DIGEST_LENGTH], HASH_CTX *c) {
194
- // |c->data| always has room for at least one byte. A full block would have
147
+ // crypto_md32_final incorporates the partial block and trailing length into the
148
+ // digest state |h|. The trailing length is encoded in little-endian if
149
+ // |is_big_endian| is zero and big-endian otherwise. |data| must be a buffer of
150
+ // length |block_size| with the first |*num| bytes containing a partial block.
151
+ // |Nh| and |Nl| contain the total number of bits processed. On return, this
152
+ // function clears the partial block in |data| and
153
+ // |*num|.
154
+ //
155
+ // This function does not serialize |h| into a final digest. This is the
156
+ // responsibility of the caller.
157
+ static inline void crypto_md32_final(crypto_md32_block_func block_func,
158
+ uint32_t *h, uint8_t *data,
159
+ size_t block_size, unsigned *num,
160
+ uint32_t Nh, uint32_t Nl,
161
+ int is_big_endian) {
162
+ // |data| always has room for at least one byte. A full block would have
195
163
  // been consumed.
196
- size_t n = c->num;
197
- assert(n < HASH_CBLOCK);
198
- c->data[n] = 0x80;
164
+ size_t n = *num;
165
+ assert(n < block_size);
166
+ data[n] = 0x80;
199
167
  n++;
200
168
 
201
169
  // Fill the block with zeros if there isn't room for a 64-bit length.
202
- if (n > (HASH_CBLOCK - 8)) {
203
- OPENSSL_memset(c->data + n, 0, HASH_CBLOCK - n);
170
+ if (n > block_size - 8) {
171
+ OPENSSL_memset(data + n, 0, block_size - n);
204
172
  n = 0;
205
- HASH_BLOCK_DATA_ORDER(c->h, c->data, 1);
173
+ block_func(h, data, 1);
206
174
  }
207
- OPENSSL_memset(c->data + n, 0, HASH_CBLOCK - 8 - n);
175
+ OPENSSL_memset(data + n, 0, block_size - 8 - n);
208
176
 
209
177
  // Append a 64-bit length to the block and process it.
210
- uint8_t *p = c->data + HASH_CBLOCK - 8;
211
- #if defined(DATA_ORDER_IS_BIG_ENDIAN)
212
- CRYPTO_store_u32_be(p, c->Nh);
213
- CRYPTO_store_u32_be(p + 4, c->Nl);
214
- #elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
215
- CRYPTO_store_u32_le(p, c->Nl);
216
- CRYPTO_store_u32_le(p + 4, c->Nh);
217
- #endif
218
- HASH_BLOCK_DATA_ORDER(c->h, c->data, 1);
219
- c->num = 0;
220
- OPENSSL_memset(c->data, 0, HASH_CBLOCK);
221
-
222
- HASH_MAKE_STRING(c, out);
223
- return 1;
178
+ if (is_big_endian) {
179
+ CRYPTO_store_u32_be(data + block_size - 8, Nh);
180
+ CRYPTO_store_u32_be(data + block_size - 4, Nl);
181
+ } else {
182
+ CRYPTO_store_u32_le(data + block_size - 8, Nl);
183
+ CRYPTO_store_u32_le(data + block_size - 4, Nh);
184
+ }
185
+ block_func(h, data, 1);
186
+ *num = 0;
187
+ OPENSSL_memset(data, 0, block_size);
224
188
  }
225
189
 
226
190
 
227
191
  #if defined(__cplusplus)
228
192
  } // extern C
229
193
  #endif
194
+
195
+ #endif // OPENSSL_HEADER_DIGEST_MD32_COMMON_H
@@ -60,6 +60,7 @@
60
60
  #include <string.h>
61
61
 
62
62
  #include "../../internal.h"
63
+ #include "../digest/md32_common.h"
63
64
 
64
65
 
65
66
  uint8_t *MD4(const uint8_t *data, size_t len, uint8_t out[MD4_DIGEST_LENGTH]) {
@@ -84,28 +85,26 @@ int MD4_Init(MD4_CTX *md4) {
84
85
 
85
86
  void md4_block_data_order(uint32_t *state, const uint8_t *data, size_t num);
86
87
 
87
- #define DATA_ORDER_IS_LITTLE_ENDIAN
88
-
89
- #define HASH_CTX MD4_CTX
90
- #define HASH_CBLOCK 64
91
- #define HASH_DIGEST_LENGTH 16
92
- #define HASH_UPDATE MD4_Update
93
- #define HASH_TRANSFORM MD4_Transform
94
- #define HASH_FINAL MD4_Final
95
- #define HASH_MAKE_STRING(c, s) \
96
- do { \
97
- CRYPTO_store_u32_le((s), (c)->h[0]); \
98
- (s) += 4; \
99
- CRYPTO_store_u32_le((s), (c)->h[1]); \
100
- (s) += 4; \
101
- CRYPTO_store_u32_le((s), (c)->h[2]); \
102
- (s) += 4; \
103
- CRYPTO_store_u32_le((s), (c)->h[3]); \
104
- (s) += 4; \
105
- } while (0)
106
- #define HASH_BLOCK_DATA_ORDER md4_block_data_order
88
+ void MD4_Transform(MD4_CTX *c, const uint8_t data[MD4_CBLOCK]) {
89
+ md4_block_data_order(c->h, data, 1);
90
+ }
107
91
 
108
- #include "../digest/md32_common.h"
92
+ int MD4_Update(MD4_CTX *c, const void *data, size_t len) {
93
+ crypto_md32_update(&md4_block_data_order, c->h, c->data, MD4_CBLOCK, &c->num,
94
+ &c->Nh, &c->Nl, data, len);
95
+ return 1;
96
+ }
97
+
98
+ int MD4_Final(uint8_t out[MD4_DIGEST_LENGTH], MD4_CTX *c) {
99
+ crypto_md32_final(&md4_block_data_order, c->h, c->data, MD4_CBLOCK, &c->num,
100
+ c->Nh, c->Nl, /*is_big_endian=*/0);
101
+
102
+ CRYPTO_store_u32_le(out, c->h[0]);
103
+ CRYPTO_store_u32_le(out + 4, c->h[1]);
104
+ CRYPTO_store_u32_le(out + 8, c->h[2]);
105
+ CRYPTO_store_u32_le(out + 12, c->h[3]);
106
+ return 1;
107
+ }
109
108
 
110
109
  // As pointed out by Wei Dai <weidai@eskimo.com>, the above can be
111
110
  // simplified to the code below. Wei attributes these optimizations
@@ -235,15 +234,6 @@ void md4_block_data_order(uint32_t *state, const uint8_t *data, size_t num) {
235
234
  }
236
235
  }
237
236
 
238
- #undef DATA_ORDER_IS_LITTLE_ENDIAN
239
- #undef HASH_CTX
240
- #undef HASH_CBLOCK
241
- #undef HASH_DIGEST_LENGTH
242
- #undef HASH_UPDATE
243
- #undef HASH_TRANSFORM
244
- #undef HASH_FINAL
245
- #undef HASH_MAKE_STRING
246
- #undef HASH_BLOCK_DATA_ORDER
247
237
  #undef F
248
238
  #undef G
249
239
  #undef H