grpc 1.10.0.pre1 → 1.10.0.pre2

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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +3 -3
  3. data/src/core/ext/filters/max_age/max_age_filter.cc +3 -0
  4. data/src/core/lib/surface/version.cc +1 -1
  5. data/src/ruby/lib/grpc/version.rb +1 -1
  6. data/third_party/boringssl/crypto/fipsmodule/aes/aes.c +1100 -0
  7. data/third_party/boringssl/crypto/fipsmodule/aes/key_wrap.c +138 -0
  8. data/third_party/boringssl/crypto/fipsmodule/aes/mode_wrappers.c +112 -0
  9. data/third_party/boringssl/crypto/fipsmodule/bn/add.c +375 -0
  10. data/third_party/boringssl/crypto/fipsmodule/bn/asm/x86_64-gcc.c +537 -0
  11. data/third_party/boringssl/crypto/fipsmodule/bn/bn.c +370 -0
  12. data/third_party/boringssl/crypto/fipsmodule/bn/bytes.c +269 -0
  13. data/third_party/boringssl/crypto/fipsmodule/bn/cmp.c +239 -0
  14. data/third_party/boringssl/crypto/fipsmodule/bn/ctx.c +303 -0
  15. data/third_party/boringssl/crypto/fipsmodule/bn/div.c +726 -0
  16. data/third_party/boringssl/crypto/fipsmodule/bn/exponentiation.c +1233 -0
  17. data/third_party/boringssl/crypto/fipsmodule/bn/gcd.c +627 -0
  18. data/third_party/boringssl/crypto/fipsmodule/bn/generic.c +715 -0
  19. data/third_party/boringssl/crypto/fipsmodule/bn/jacobi.c +146 -0
  20. data/third_party/boringssl/crypto/fipsmodule/bn/montgomery.c +430 -0
  21. data/third_party/boringssl/crypto/fipsmodule/bn/montgomery_inv.c +207 -0
  22. data/third_party/boringssl/crypto/fipsmodule/bn/mul.c +869 -0
  23. data/third_party/boringssl/crypto/fipsmodule/bn/prime.c +894 -0
  24. data/third_party/boringssl/crypto/fipsmodule/bn/random.c +283 -0
  25. data/third_party/boringssl/crypto/fipsmodule/bn/rsaz_exp.c +254 -0
  26. data/third_party/boringssl/crypto/fipsmodule/bn/shift.c +307 -0
  27. data/third_party/boringssl/crypto/fipsmodule/bn/sqrt.c +502 -0
  28. data/third_party/boringssl/crypto/fipsmodule/cipher/aead.c +284 -0
  29. data/third_party/boringssl/crypto/fipsmodule/cipher/cipher.c +613 -0
  30. data/third_party/boringssl/crypto/fipsmodule/cipher/e_aes.c +1437 -0
  31. data/third_party/boringssl/crypto/fipsmodule/cipher/e_des.c +233 -0
  32. data/third_party/boringssl/crypto/fipsmodule/des/des.c +785 -0
  33. data/third_party/boringssl/crypto/fipsmodule/digest/digest.c +256 -0
  34. data/third_party/boringssl/crypto/fipsmodule/digest/digests.c +280 -0
  35. data/third_party/boringssl/crypto/fipsmodule/ec/ec.c +842 -0
  36. data/third_party/boringssl/crypto/fipsmodule/ec/ec_key.c +517 -0
  37. data/third_party/boringssl/crypto/fipsmodule/ec/ec_montgomery.c +304 -0
  38. data/third_party/boringssl/crypto/fipsmodule/ec/oct.c +404 -0
  39. data/third_party/boringssl/crypto/fipsmodule/ec/p224-64.c +1165 -0
  40. data/third_party/boringssl/crypto/fipsmodule/ec/p256-64.c +1708 -0
  41. data/third_party/boringssl/crypto/fipsmodule/ec/p256-x86_64.c +561 -0
  42. data/third_party/boringssl/crypto/fipsmodule/ec/simple.c +1113 -0
  43. data/third_party/boringssl/crypto/fipsmodule/ec/util-64.c +109 -0
  44. data/third_party/boringssl/crypto/fipsmodule/ec/wnaf.c +456 -0
  45. data/third_party/boringssl/crypto/fipsmodule/ecdsa/ecdsa.c +444 -0
  46. data/third_party/boringssl/crypto/fipsmodule/hmac/hmac.c +228 -0
  47. data/third_party/boringssl/crypto/fipsmodule/md4/md4.c +254 -0
  48. data/third_party/boringssl/crypto/fipsmodule/md5/md5.c +298 -0
  49. data/third_party/boringssl/crypto/fipsmodule/modes/cbc.c +212 -0
  50. data/third_party/boringssl/crypto/fipsmodule/modes/cfb.c +230 -0
  51. data/third_party/boringssl/crypto/fipsmodule/modes/ctr.c +219 -0
  52. data/third_party/boringssl/crypto/fipsmodule/modes/gcm.c +1074 -0
  53. data/third_party/boringssl/crypto/fipsmodule/modes/ofb.c +95 -0
  54. data/third_party/boringssl/crypto/fipsmodule/modes/polyval.c +91 -0
  55. data/third_party/boringssl/crypto/fipsmodule/rand/ctrdrbg.c +200 -0
  56. data/third_party/boringssl/crypto/fipsmodule/rand/rand.c +358 -0
  57. data/third_party/boringssl/crypto/fipsmodule/rand/urandom.c +302 -0
  58. data/third_party/boringssl/crypto/fipsmodule/rsa/blinding.c +263 -0
  59. data/third_party/boringssl/crypto/fipsmodule/rsa/padding.c +692 -0
  60. data/third_party/boringssl/crypto/fipsmodule/rsa/rsa.c +855 -0
  61. data/third_party/boringssl/crypto/fipsmodule/rsa/rsa_impl.c +1061 -0
  62. data/third_party/boringssl/crypto/fipsmodule/sha/sha1-altivec.c +361 -0
  63. data/third_party/boringssl/crypto/fipsmodule/sha/sha1.c +375 -0
  64. data/third_party/boringssl/crypto/fipsmodule/sha/sha256.c +337 -0
  65. data/third_party/boringssl/crypto/fipsmodule/sha/sha512.c +608 -0
  66. metadata +62 -2
@@ -0,0 +1,212 @@
1
+ /* ====================================================================
2
+ * Copyright (c) 2008 The OpenSSL Project. All rights reserved.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions
6
+ * are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright
9
+ * notice, this list of conditions and the following disclaimer.
10
+ *
11
+ * 2. Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in
13
+ * the documentation and/or other materials provided with the
14
+ * distribution.
15
+ *
16
+ * 3. All advertising materials mentioning features or use of this
17
+ * software must display the following acknowledgment:
18
+ * "This product includes software developed by the OpenSSL Project
19
+ * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20
+ *
21
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22
+ * endorse or promote products derived from this software without
23
+ * prior written permission. For written permission, please contact
24
+ * openssl-core@openssl.org.
25
+ *
26
+ * 5. Products derived from this software may not be called "OpenSSL"
27
+ * nor may "OpenSSL" appear in their names without prior written
28
+ * permission of the OpenSSL Project.
29
+ *
30
+ * 6. Redistributions of any form whatsoever must retain the following
31
+ * acknowledgment:
32
+ * "This product includes software developed by the OpenSSL Project
33
+ * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34
+ *
35
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
47
+ * ==================================================================== */
48
+
49
+ #include <assert.h>
50
+ #include <string.h>
51
+
52
+ #include "internal.h"
53
+
54
+
55
+ void CRYPTO_cbc128_encrypt(const uint8_t *in, uint8_t *out, size_t len,
56
+ const void *key, uint8_t ivec[16],
57
+ block128_f block) {
58
+ size_t n;
59
+ const uint8_t *iv = ivec;
60
+
61
+ assert(key != NULL && ivec != NULL);
62
+ assert(len == 0 || (in != NULL && out != NULL));
63
+
64
+ if (STRICT_ALIGNMENT &&
65
+ ((size_t)in | (size_t)out | (size_t)ivec) % sizeof(size_t) != 0) {
66
+ while (len >= 16) {
67
+ for (n = 0; n < 16; ++n) {
68
+ out[n] = in[n] ^ iv[n];
69
+ }
70
+ (*block)(out, out, key);
71
+ iv = out;
72
+ len -= 16;
73
+ in += 16;
74
+ out += 16;
75
+ }
76
+ } else {
77
+ while (len >= 16) {
78
+ for (n = 0; n < 16; n += sizeof(size_t)) {
79
+ *(size_t *)(out + n) = *(size_t *)(in + n) ^ *(size_t *)(iv + n);
80
+ }
81
+ (*block)(out, out, key);
82
+ iv = out;
83
+ len -= 16;
84
+ in += 16;
85
+ out += 16;
86
+ }
87
+ }
88
+
89
+ while (len) {
90
+ for (n = 0; n < 16 && n < len; ++n) {
91
+ out[n] = in[n] ^ iv[n];
92
+ }
93
+ for (; n < 16; ++n) {
94
+ out[n] = iv[n];
95
+ }
96
+ (*block)(out, out, key);
97
+ iv = out;
98
+ if (len <= 16) {
99
+ break;
100
+ }
101
+ len -= 16;
102
+ in += 16;
103
+ out += 16;
104
+ }
105
+
106
+ OPENSSL_memcpy(ivec, iv, 16);
107
+ }
108
+
109
+ void CRYPTO_cbc128_decrypt(const uint8_t *in, uint8_t *out, size_t len,
110
+ const void *key, uint8_t ivec[16],
111
+ block128_f block) {
112
+ size_t n;
113
+ union {
114
+ size_t t[16 / sizeof(size_t)];
115
+ uint8_t c[16];
116
+ } tmp;
117
+
118
+ assert(key != NULL && ivec != NULL);
119
+ assert(len == 0 || (in != NULL && out != NULL));
120
+
121
+ const uintptr_t inptr = (uintptr_t) in;
122
+ const uintptr_t outptr = (uintptr_t) out;
123
+ // If |in| and |out| alias, |in| must be ahead.
124
+ assert(inptr >= outptr || inptr + len <= outptr);
125
+
126
+ if ((inptr >= 32 && outptr <= inptr - 32) || inptr < outptr) {
127
+ // If |out| is at least two blocks behind |in| or completely disjoint, there
128
+ // is no need to decrypt to a temporary block.
129
+ const uint8_t *iv = ivec;
130
+
131
+ if (STRICT_ALIGNMENT &&
132
+ ((size_t)in | (size_t)out | (size_t)ivec) % sizeof(size_t) != 0) {
133
+ while (len >= 16) {
134
+ (*block)(in, out, key);
135
+ for (n = 0; n < 16; ++n) {
136
+ out[n] ^= iv[n];
137
+ }
138
+ iv = in;
139
+ len -= 16;
140
+ in += 16;
141
+ out += 16;
142
+ }
143
+ } else if (16 % sizeof(size_t) == 0) { // always true
144
+ while (len >= 16) {
145
+ size_t *out_t = (size_t *)out, *iv_t = (size_t *)iv;
146
+
147
+ (*block)(in, out, key);
148
+ for (n = 0; n < 16 / sizeof(size_t); n++) {
149
+ out_t[n] ^= iv_t[n];
150
+ }
151
+ iv = in;
152
+ len -= 16;
153
+ in += 16;
154
+ out += 16;
155
+ }
156
+ }
157
+ OPENSSL_memcpy(ivec, iv, 16);
158
+ } else {
159
+ // |out| is less than two blocks behind |in|. Decrypting an input block
160
+ // directly to |out| would overwrite a ciphertext block before it is used as
161
+ // the next block's IV. Decrypt to a temporary block instead.
162
+ if (STRICT_ALIGNMENT &&
163
+ ((size_t)in | (size_t)out | (size_t)ivec) % sizeof(size_t) != 0) {
164
+ uint8_t c;
165
+ while (len >= 16) {
166
+ (*block)(in, tmp.c, key);
167
+ for (n = 0; n < 16; ++n) {
168
+ c = in[n];
169
+ out[n] = tmp.c[n] ^ ivec[n];
170
+ ivec[n] = c;
171
+ }
172
+ len -= 16;
173
+ in += 16;
174
+ out += 16;
175
+ }
176
+ } else if (16 % sizeof(size_t) == 0) { // always true
177
+ while (len >= 16) {
178
+ size_t c, *out_t = (size_t *)out, *ivec_t = (size_t *)ivec;
179
+ const size_t *in_t = (const size_t *)in;
180
+
181
+ (*block)(in, tmp.c, key);
182
+ for (n = 0; n < 16 / sizeof(size_t); n++) {
183
+ c = in_t[n];
184
+ out_t[n] = tmp.t[n] ^ ivec_t[n];
185
+ ivec_t[n] = c;
186
+ }
187
+ len -= 16;
188
+ in += 16;
189
+ out += 16;
190
+ }
191
+ }
192
+ }
193
+
194
+ while (len) {
195
+ uint8_t c;
196
+ (*block)(in, tmp.c, key);
197
+ for (n = 0; n < 16 && n < len; ++n) {
198
+ c = in[n];
199
+ out[n] = tmp.c[n] ^ ivec[n];
200
+ ivec[n] = c;
201
+ }
202
+ if (len <= 16) {
203
+ for (; n < 16; ++n) {
204
+ ivec[n] = in[n];
205
+ }
206
+ break;
207
+ }
208
+ len -= 16;
209
+ in += 16;
210
+ out += 16;
211
+ }
212
+ }
@@ -0,0 +1,230 @@
1
+ /* ====================================================================
2
+ * Copyright (c) 2008 The OpenSSL Project. All rights reserved.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions
6
+ * are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright
9
+ * notice, this list of conditions and the following disclaimer.
10
+ *
11
+ * 2. Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in
13
+ * the documentation and/or other materials provided with the
14
+ * distribution.
15
+ *
16
+ * 3. All advertising materials mentioning features or use of this
17
+ * software must display the following acknowledgment:
18
+ * "This product includes software developed by the OpenSSL Project
19
+ * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20
+ *
21
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22
+ * endorse or promote products derived from this software without
23
+ * prior written permission. For written permission, please contact
24
+ * openssl-core@openssl.org.
25
+ *
26
+ * 5. Products derived from this software may not be called "OpenSSL"
27
+ * nor may "OpenSSL" appear in their names without prior written
28
+ * permission of the OpenSSL Project.
29
+ *
30
+ * 6. Redistributions of any form whatsoever must retain the following
31
+ * acknowledgment:
32
+ * "This product includes software developed by the OpenSSL Project
33
+ * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34
+ *
35
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
47
+ * ==================================================================== */
48
+
49
+ #include <openssl/type_check.h>
50
+
51
+ #include <assert.h>
52
+ #include <string.h>
53
+
54
+ #include "internal.h"
55
+
56
+
57
+ OPENSSL_COMPILE_ASSERT((16 % sizeof(size_t)) == 0, bad_size_t_size_cfb);
58
+
59
+ void CRYPTO_cfb128_encrypt(const uint8_t *in, uint8_t *out, size_t len,
60
+ const void *key, uint8_t ivec[16], unsigned *num,
61
+ int enc, block128_f block) {
62
+ size_t l = 0;
63
+
64
+ assert(in && out && key && ivec && num);
65
+
66
+ unsigned n = *num;
67
+
68
+ if (enc) {
69
+ while (n && len) {
70
+ *(out++) = ivec[n] ^= *(in++);
71
+ --len;
72
+ n = (n + 1) % 16;
73
+ }
74
+ #if STRICT_ALIGNMENT
75
+ if (((size_t)in | (size_t)out | (size_t)ivec) % sizeof(size_t) != 0) {
76
+ while (l < len) {
77
+ if (n == 0) {
78
+ (*block)(ivec, ivec, key);
79
+ }
80
+ out[l] = ivec[n] ^= in[l];
81
+ ++l;
82
+ n = (n + 1) % 16;
83
+ }
84
+ *num = n;
85
+ return;
86
+ }
87
+ #endif
88
+ while (len >= 16) {
89
+ (*block)(ivec, ivec, key);
90
+ for (; n < 16; n += sizeof(size_t)) {
91
+ *(size_t *)(out + n) = *(size_t *)(ivec + n) ^= *(size_t *)(in + n);
92
+ }
93
+ len -= 16;
94
+ out += 16;
95
+ in += 16;
96
+ n = 0;
97
+ }
98
+ if (len) {
99
+ (*block)(ivec, ivec, key);
100
+ while (len--) {
101
+ out[n] = ivec[n] ^= in[n];
102
+ ++n;
103
+ }
104
+ }
105
+ *num = n;
106
+ return;
107
+ } else {
108
+ while (n && len) {
109
+ uint8_t c;
110
+ *(out++) = ivec[n] ^ (c = *(in++));
111
+ ivec[n] = c;
112
+ --len;
113
+ n = (n + 1) % 16;
114
+ }
115
+ if (STRICT_ALIGNMENT && ((size_t)in | (size_t)out | (size_t)ivec) % sizeof(size_t) != 0) {
116
+ while (l < len) {
117
+ unsigned char c;
118
+ if (n == 0) {
119
+ (*block)(ivec, ivec, key);
120
+ }
121
+ out[l] = ivec[n] ^ (c = in[l]);
122
+ ivec[n] = c;
123
+ ++l;
124
+ n = (n + 1) % 16;
125
+ }
126
+ *num = n;
127
+ return;
128
+ }
129
+ while (len >= 16) {
130
+ (*block)(ivec, ivec, key);
131
+ for (; n < 16; n += sizeof(size_t)) {
132
+ size_t t = *(size_t *)(in + n);
133
+ *(size_t *)(out + n) = *(size_t *)(ivec + n) ^ t;
134
+ *(size_t *)(ivec + n) = t;
135
+ }
136
+ len -= 16;
137
+ out += 16;
138
+ in += 16;
139
+ n = 0;
140
+ }
141
+ if (len) {
142
+ (*block)(ivec, ivec, key);
143
+ while (len--) {
144
+ uint8_t c;
145
+ out[n] = ivec[n] ^ (c = in[n]);
146
+ ivec[n] = c;
147
+ ++n;
148
+ }
149
+ }
150
+ *num = n;
151
+ return;
152
+ }
153
+ }
154
+
155
+
156
+ /* This expects a single block of size nbits for both in and out. Note that
157
+ it corrupts any extra bits in the last byte of out */
158
+ static void cfbr_encrypt_block(const uint8_t *in, uint8_t *out, unsigned nbits,
159
+ const void *key, uint8_t ivec[16], int enc,
160
+ block128_f block) {
161
+ int n, rem, num;
162
+ uint8_t ovec[16 * 2 + 1]; /* +1 because we dererefence (but don't use) one
163
+ byte off the end */
164
+
165
+ if (nbits <= 0 || nbits > 128) {
166
+ return;
167
+ }
168
+
169
+ // fill in the first half of the new IV with the current IV
170
+ OPENSSL_memcpy(ovec, ivec, 16);
171
+ // construct the new IV
172
+ (*block)(ivec, ivec, key);
173
+ num = (nbits + 7) / 8;
174
+ if (enc) {
175
+ // encrypt the input
176
+ for (n = 0; n < num; ++n) {
177
+ out[n] = (ovec[16 + n] = in[n] ^ ivec[n]);
178
+ }
179
+ } else {
180
+ // decrypt the input
181
+ for (n = 0; n < num; ++n) {
182
+ out[n] = (ovec[16 + n] = in[n]) ^ ivec[n];
183
+ }
184
+ }
185
+ // shift ovec left...
186
+ rem = nbits % 8;
187
+ num = nbits / 8;
188
+ if (rem == 0) {
189
+ OPENSSL_memcpy(ivec, ovec + num, 16);
190
+ } else {
191
+ for (n = 0; n < 16; ++n) {
192
+ ivec[n] = ovec[n + num] << rem | ovec[n + num + 1] >> (8 - rem);
193
+ }
194
+ }
195
+
196
+ // it is not necessary to cleanse ovec, since the IV is not secret
197
+ }
198
+
199
+ // N.B. This expects the input to be packed, MS bit first
200
+ void CRYPTO_cfb128_1_encrypt(const uint8_t *in, uint8_t *out, size_t bits,
201
+ const void *key, uint8_t ivec[16], unsigned *num,
202
+ int enc, block128_f block) {
203
+ size_t n;
204
+ uint8_t c[1], d[1];
205
+
206
+ assert(in && out && key && ivec && num);
207
+ assert(*num == 0);
208
+
209
+ for (n = 0; n < bits; ++n) {
210
+ c[0] = (in[n / 8] & (1 << (7 - n % 8))) ? 0x80 : 0;
211
+ cfbr_encrypt_block(c, d, 1, key, ivec, enc, block);
212
+ out[n / 8] = (out[n / 8] & ~(1 << (unsigned int)(7 - n % 8))) |
213
+ ((d[0] & 0x80) >> (unsigned int)(n % 8));
214
+ }
215
+ }
216
+
217
+ void CRYPTO_cfb128_8_encrypt(const unsigned char *in, unsigned char *out,
218
+ size_t length, const void *key,
219
+ unsigned char ivec[16], unsigned *num, int enc,
220
+ block128_f block) {
221
+ size_t n;
222
+
223
+ assert(in && out && key && ivec && num);
224
+ assert(*num == 0);
225
+
226
+ for (n = 0; n < length; ++n) {
227
+ cfbr_encrypt_block(&in[n], &out[n], 8, key, ivec, enc, block);
228
+ }
229
+ }
230
+
@@ -0,0 +1,219 @@
1
+ /* ====================================================================
2
+ * Copyright (c) 2008 The OpenSSL Project. All rights reserved.
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without
5
+ * modification, are permitted provided that the following conditions
6
+ * are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright
9
+ * notice, this list of conditions and the following disclaimer.
10
+ *
11
+ * 2. Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in
13
+ * the documentation and/or other materials provided with the
14
+ * distribution.
15
+ *
16
+ * 3. All advertising materials mentioning features or use of this
17
+ * software must display the following acknowledgment:
18
+ * "This product includes software developed by the OpenSSL Project
19
+ * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20
+ *
21
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22
+ * endorse or promote products derived from this software without
23
+ * prior written permission. For written permission, please contact
24
+ * openssl-core@openssl.org.
25
+ *
26
+ * 5. Products derived from this software may not be called "OpenSSL"
27
+ * nor may "OpenSSL" appear in their names without prior written
28
+ * permission of the OpenSSL Project.
29
+ *
30
+ * 6. Redistributions of any form whatsoever must retain the following
31
+ * acknowledgment:
32
+ * "This product includes software developed by the OpenSSL Project
33
+ * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34
+ *
35
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
47
+ * ==================================================================== */
48
+
49
+ #include <openssl/type_check.h>
50
+
51
+ #include <assert.h>
52
+ #include <string.h>
53
+
54
+ #include "internal.h"
55
+
56
+
57
+ // NOTE: the IV/counter CTR mode is big-endian. The code itself
58
+ // is endian-neutral.
59
+
60
+ // increment counter (128-bit int) by 1
61
+ static void ctr128_inc(uint8_t *counter) {
62
+ uint32_t n = 16, c = 1;
63
+
64
+ do {
65
+ --n;
66
+ c += counter[n];
67
+ counter[n] = (uint8_t) c;
68
+ c >>= 8;
69
+ } while (n);
70
+ }
71
+
72
+ OPENSSL_COMPILE_ASSERT((16 % sizeof(size_t)) == 0, bad_size_t_size_ctr);
73
+
74
+ // The input encrypted as though 128bit counter mode is being used. The extra
75
+ // state information to record how much of the 128bit block we have used is
76
+ // contained in *num, and the encrypted counter is kept in ecount_buf. Both
77
+ // *num and ecount_buf must be initialised with zeros before the first call to
78
+ // CRYPTO_ctr128_encrypt().
79
+ //
80
+ // This algorithm assumes that the counter is in the x lower bits of the IV
81
+ // (ivec), and that the application has full control over overflow and the rest
82
+ // of the IV. This implementation takes NO responsibility for checking that
83
+ // the counter doesn't overflow into the rest of the IV when incremented.
84
+ void CRYPTO_ctr128_encrypt(const uint8_t *in, uint8_t *out, size_t len,
85
+ const void *key, uint8_t ivec[16],
86
+ uint8_t ecount_buf[16], unsigned int *num,
87
+ block128_f block) {
88
+ unsigned int n;
89
+
90
+ assert(key && ecount_buf && num);
91
+ assert(len == 0 || (in && out));
92
+ assert(*num < 16);
93
+
94
+ n = *num;
95
+
96
+ while (n && len) {
97
+ *(out++) = *(in++) ^ ecount_buf[n];
98
+ --len;
99
+ n = (n + 1) % 16;
100
+ }
101
+
102
+ #if STRICT_ALIGNMENT
103
+ if (((size_t)in | (size_t)out | (size_t)ecount_buf) % sizeof(size_t) != 0) {
104
+ size_t l = 0;
105
+ while (l < len) {
106
+ if (n == 0) {
107
+ (*block)(ivec, ecount_buf, key);
108
+ ctr128_inc(ivec);
109
+ }
110
+ out[l] = in[l] ^ ecount_buf[n];
111
+ ++l;
112
+ n = (n + 1) % 16;
113
+ }
114
+
115
+ *num = n;
116
+ return;
117
+ }
118
+ #endif
119
+
120
+ while (len >= 16) {
121
+ (*block)(ivec, ecount_buf, key);
122
+ ctr128_inc(ivec);
123
+ for (n = 0; n < 16; n += sizeof(size_t)) {
124
+ *(size_t *)(out + n) = *(const size_t *)(in + n) ^
125
+ *(const size_t *)(ecount_buf + n);
126
+ }
127
+ len -= 16;
128
+ out += 16;
129
+ in += 16;
130
+ n = 0;
131
+ }
132
+ if (len) {
133
+ (*block)(ivec, ecount_buf, key);
134
+ ctr128_inc(ivec);
135
+ while (len--) {
136
+ out[n] = in[n] ^ ecount_buf[n];
137
+ ++n;
138
+ }
139
+ }
140
+ *num = n;
141
+ }
142
+
143
+ // increment upper 96 bits of 128-bit counter by 1
144
+ static void ctr96_inc(uint8_t *counter) {
145
+ uint32_t n = 12, c = 1;
146
+
147
+ do {
148
+ --n;
149
+ c += counter[n];
150
+ counter[n] = (uint8_t) c;
151
+ c >>= 8;
152
+ } while (n);
153
+ }
154
+
155
+ void CRYPTO_ctr128_encrypt_ctr32(const uint8_t *in, uint8_t *out,
156
+ size_t len, const void *key,
157
+ uint8_t ivec[16],
158
+ uint8_t ecount_buf[16],
159
+ unsigned int *num, ctr128_f func) {
160
+ unsigned int n, ctr32;
161
+
162
+ assert(key && ecount_buf && num);
163
+ assert(len == 0 || (in && out));
164
+ assert(*num < 16);
165
+
166
+ n = *num;
167
+
168
+ while (n && len) {
169
+ *(out++) = *(in++) ^ ecount_buf[n];
170
+ --len;
171
+ n = (n + 1) % 16;
172
+ }
173
+
174
+ ctr32 = GETU32(ivec + 12);
175
+ while (len >= 16) {
176
+ size_t blocks = len / 16;
177
+ // 1<<28 is just a not-so-small yet not-so-large number...
178
+ // Below condition is practically never met, but it has to
179
+ // be checked for code correctness.
180
+ if (sizeof(size_t) > sizeof(unsigned int) && blocks > (1U << 28)) {
181
+ blocks = (1U << 28);
182
+ }
183
+ // As (*func) operates on 32-bit counter, caller
184
+ // has to handle overflow. 'if' below detects the
185
+ // overflow, which is then handled by limiting the
186
+ // amount of blocks to the exact overflow point...
187
+ ctr32 += (uint32_t)blocks;
188
+ if (ctr32 < blocks) {
189
+ blocks -= ctr32;
190
+ ctr32 = 0;
191
+ }
192
+ (*func)(in, out, blocks, key, ivec);
193
+ // (*func) does not update ivec, caller does:
194
+ PUTU32(ivec + 12, ctr32);
195
+ // ... overflow was detected, propogate carry.
196
+ if (ctr32 == 0) {
197
+ ctr96_inc(ivec);
198
+ }
199
+ blocks *= 16;
200
+ len -= blocks;
201
+ out += blocks;
202
+ in += blocks;
203
+ }
204
+ if (len) {
205
+ OPENSSL_memset(ecount_buf, 0, 16);
206
+ (*func)(ecount_buf, ecount_buf, 1, key, ivec);
207
+ ++ctr32;
208
+ PUTU32(ivec + 12, ctr32);
209
+ if (ctr32 == 0) {
210
+ ctr96_inc(ivec);
211
+ }
212
+ while (len--) {
213
+ out[n] = in[n] ^ ecount_buf[n];
214
+ ++n;
215
+ }
216
+ }
217
+
218
+ *num = n;
219
+ }