aws-crt 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/VERSION +1 -1
  4. data/aws-crt-ffi/crt/aws-c-cal/CMakeLists.txt +2 -0
  5. data/aws-crt-ffi/crt/aws-c-cal/bin/produce_x_platform_fuzz_corpus/CMakeLists.txt +30 -0
  6. data/aws-crt-ffi/crt/aws-c-cal/bin/produce_x_platform_fuzz_corpus/main.c +208 -0
  7. data/aws-crt-ffi/crt/aws-c-cal/bin/run_x_platform_fuzz_corpus/CMakeLists.txt +30 -0
  8. data/aws-crt-ffi/crt/aws-c-cal/bin/run_x_platform_fuzz_corpus/main.c +244 -0
  9. data/aws-crt-ffi/crt/aws-c-cal/ecdsa-fuzz-corpus/darwin/p256_sig_corpus.txt +10000 -0
  10. data/aws-crt-ffi/crt/aws-c-cal/ecdsa-fuzz-corpus/windows/p256_sig_corpus.txt +10000 -0
  11. data/aws-crt-ffi/crt/aws-c-cal/source/windows/bcrypt_ecc.c +8 -0
  12. data/aws-crt-ffi/crt/aws-c-http/tests/CMakeLists.txt +11 -10
  13. data/aws-crt-ffi/crt/aws-c-io/include/aws/io/tls_channel_handler.h +2 -0
  14. data/aws-crt-ffi/crt/aws-c-io/source/darwin/darwin_pki_utils.c +8 -0
  15. data/aws-crt-ffi/crt/aws-c-io/source/tls_channel_handler.c +2 -0
  16. data/aws-crt-ffi/crt/aws-c-io/source/windows/windows_pki_utils.c +65 -35
  17. data/aws-crt-ffi/crt/s2n/CMakeLists.txt +67 -21
  18. data/aws-crt-ffi/crt/s2n/Makefile +10 -0
  19. data/aws-crt-ffi/crt/s2n/bin/Makefile +9 -0
  20. data/aws-crt-ffi/crt/s2n/bindings/rust/Makefile +14 -0
  21. data/aws-crt-ffi/crt/s2n/bindings/rust/integration/Cargo.toml +2 -2
  22. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls/Cargo.toml +3 -2
  23. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls/src/raw/config.rs +265 -39
  24. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls/src/raw/connection.rs +170 -20
  25. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls/src/testing/s2n_tls.rs +120 -0
  26. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls/src/testing.rs +58 -23
  27. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-sys/Cargo.toml +1 -1
  28. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-sys/src/internal.rs +3 -0
  29. data/aws-crt-ffi/crt/s2n/crypto/s2n_composite_cipher_aes_sha.c +1 -1
  30. data/aws-crt-ffi/crt/s2n/crypto/s2n_drbg.c +8 -3
  31. data/aws-crt-ffi/crt/s2n/error/s2n_errno.c +3 -0
  32. data/aws-crt-ffi/crt/s2n/error/s2n_errno.h +2 -0
  33. data/aws-crt-ffi/crt/s2n/lib/Makefile +11 -0
  34. data/aws-crt-ffi/crt/s2n/pq-crypto/kyber_90s_r2/ntt.h +2 -2
  35. data/aws-crt-ffi/crt/s2n/pq-crypto/kyber_r2/ntt.h +2 -2
  36. data/aws-crt-ffi/crt/s2n/pq-crypto/kyber_r3/kyber512r3_poly_avx2.h +2 -2
  37. data/aws-crt-ffi/crt/s2n/pq-crypto/kyber_r3/kyber512r3_polyvec_avx2.h +2 -2
  38. data/aws-crt-ffi/crt/s2n/pq-crypto/sike_r1/P503_internal_r1.h +1 -1
  39. data/aws-crt-ffi/crt/s2n/pq-crypto/sike_r1/fips202_r1.h +1 -1
  40. data/aws-crt-ffi/crt/s2n/pq-crypto/sike_r3/sikep434r3_fp_x64_asm.S +4 -0
  41. data/aws-crt-ffi/crt/s2n/s2n.mk +25 -0
  42. data/aws-crt-ffi/crt/s2n/scripts/s2n_safety_macros.py +14 -0
  43. data/aws-crt-ffi/crt/s2n/tests/benchmark/Readme.md +23 -9
  44. data/aws-crt-ffi/crt/s2n/tests/features/clone.c +24 -0
  45. data/aws-crt-ffi/crt/s2n/tests/features/madvise.c +27 -0
  46. data/aws-crt-ffi/crt/s2n/tests/features/minherit.c +22 -0
  47. data/aws-crt-ffi/crt/s2n/tests/integrationv2/conftest.py +2 -2
  48. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_connection_test.c +1 -1
  49. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_fork_generation_number_test.c +335 -0
  50. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_mem_usage_test.c +1 -1
  51. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_self_talk_client_hello_cb_test.c +93 -11
  52. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_server_hello_retry_test.c +123 -1
  53. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_key_schedule_rfc8448_test.c +18 -3
  54. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_key_schedule_test.c +0 -38
  55. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_secrets_test.c +134 -15
  56. data/aws-crt-ffi/crt/s2n/tls/s2n_cipher_suites.c +1 -1
  57. data/aws-crt-ffi/crt/s2n/tls/s2n_client_hello.c +20 -9
  58. data/aws-crt-ffi/crt/s2n/tls/s2n_client_hello.h +8 -0
  59. data/aws-crt-ffi/crt/s2n/tls/s2n_config.c +13 -0
  60. data/aws-crt-ffi/crt/s2n/tls/s2n_config.h +6 -0
  61. data/aws-crt-ffi/crt/s2n/tls/s2n_handshake_io.c +2 -1
  62. data/aws-crt-ffi/crt/s2n/tls/s2n_internal.h +9 -0
  63. data/aws-crt-ffi/crt/s2n/tls/s2n_tls13_key_schedule.c +7 -7
  64. data/aws-crt-ffi/crt/s2n/tls/s2n_tls13_secrets.c +61 -8
  65. data/aws-crt-ffi/crt/s2n/tls/s2n_tls13_secrets.h +11 -5
  66. data/aws-crt-ffi/crt/s2n/utils/s2n_fork_detection.c +367 -0
  67. data/aws-crt-ffi/crt/s2n/utils/s2n_fork_detection.h +28 -0
  68. data/aws-crt-ffi/crt/s2n/utils/s2n_safety_macros.h +13 -22
  69. metadata +18 -3
@@ -198,6 +198,7 @@ impl<'a, T: 'a + Context> Callback<'a, T> {
198
198
  #[cfg(test)]
199
199
  mod tests {
200
200
  use crate::testing::*;
201
+ use futures_test::task::new_count_waker;
201
202
 
202
203
  #[test]
203
204
  fn handshake_default() {
@@ -210,4 +211,123 @@ mod tests {
210
211
  let config = build_config(&security::DEFAULT_TLS13).unwrap();
211
212
  s2n_tls_pair(config)
212
213
  }
214
+
215
+ #[test]
216
+ fn static_config_and_clone_interaction() {
217
+ let config = build_config(&security::DEFAULT_TLS13).unwrap();
218
+ assert_eq!(config.test_get_refcount().unwrap(), 1);
219
+ {
220
+ let mut server = crate::raw::connection::Connection::new_server();
221
+ // default config is not returned on the connection
222
+ assert!(server.test_config_exists().is_err());
223
+ assert_eq!(config.test_get_refcount().unwrap(), 1);
224
+ server.set_config(config.clone()).unwrap();
225
+ assert_eq!(config.test_get_refcount().unwrap(), 2);
226
+ assert!(server.test_config_exists().is_ok());
227
+
228
+ let mut client = crate::raw::connection::Connection::new_client();
229
+ // default config is not returned on the connection
230
+ assert!(client.test_config_exists().is_err());
231
+ assert_eq!(config.test_get_refcount().unwrap(), 2);
232
+ client.set_config(config.clone()).unwrap();
233
+ assert_eq!(config.test_get_refcount().unwrap(), 3);
234
+ assert!(client.test_config_exists().is_ok());
235
+
236
+ let mut third = crate::raw::connection::Connection::new_server();
237
+ // default config is not returned on the connection
238
+ assert!(third.test_config_exists().is_err());
239
+ assert_eq!(config.test_get_refcount().unwrap(), 3);
240
+ third.set_config(config.clone()).unwrap();
241
+ assert_eq!(config.test_get_refcount().unwrap(), 4);
242
+ assert!(third.test_config_exists().is_ok());
243
+
244
+ // drop all the clones
245
+ }
246
+ assert_eq!(config.test_get_refcount().unwrap(), 1);
247
+ }
248
+
249
+ #[test]
250
+ fn set_config_multiple_times() {
251
+ let config = build_config(&security::DEFAULT_TLS13).unwrap();
252
+ assert_eq!(config.test_get_refcount().unwrap(), 1);
253
+
254
+ let mut server = crate::raw::connection::Connection::new_server();
255
+ // default config is not returned on the connection
256
+ assert!(server.test_config_exists().is_err());
257
+ assert_eq!(config.test_get_refcount().unwrap(), 1);
258
+
259
+ // call set_config once
260
+ server.set_config(config.clone()).unwrap();
261
+ assert_eq!(config.test_get_refcount().unwrap(), 2);
262
+ assert!(server.test_config_exists().is_ok());
263
+
264
+ // calling set_config multiple times works since we drop the previous config
265
+ server.set_config(config.clone()).unwrap();
266
+ assert_eq!(config.test_get_refcount().unwrap(), 2);
267
+ assert!(server.test_config_exists().is_ok());
268
+ }
269
+
270
+ #[test]
271
+ fn connnection_waker() {
272
+ let config = build_config(&security::DEFAULT_TLS13).unwrap();
273
+ assert_eq!(config.test_get_refcount().unwrap(), 1);
274
+
275
+ let mut server = crate::raw::connection::Connection::new_server();
276
+ server.set_config(config).unwrap();
277
+
278
+ assert!(server.waker().is_none());
279
+
280
+ let (waker, wake_count) = new_count_waker();
281
+ server.set_waker(Some(&waker)).unwrap();
282
+ assert!(server.waker().is_some());
283
+
284
+ server.set_waker(None).unwrap();
285
+ assert!(server.waker().is_none());
286
+
287
+ assert_eq!(wake_count, 0);
288
+ }
289
+
290
+ #[test]
291
+ fn client_hello_callback() {
292
+ let (waker, wake_count) = new_count_waker();
293
+ let require_pending_count = 10;
294
+ let handle = MockClientHelloHandler::new(require_pending_count);
295
+ let config = {
296
+ let mut config = config_builder(&security::DEFAULT_TLS13).unwrap();
297
+ config.set_client_hello_handler(handle.clone()).unwrap();
298
+ // multiple calls to set_client_hello_handler should succeed
299
+ config.set_client_hello_handler(handle.clone()).unwrap();
300
+ config.build().unwrap()
301
+ };
302
+
303
+ let server = {
304
+ // create and configure a server connection
305
+ let mut server = crate::raw::connection::Connection::new_server();
306
+ server
307
+ .set_config(config.clone())
308
+ .expect("Failed to bind config to server connection");
309
+ server.set_waker(Some(&waker)).unwrap();
310
+ Harness::new(server)
311
+ };
312
+
313
+ let client = {
314
+ // create a client connection
315
+ let mut client = crate::raw::connection::Connection::new_client();
316
+ client
317
+ .set_config(config)
318
+ .expect("Unable to set client config");
319
+ Harness::new(client)
320
+ };
321
+
322
+ let pair = Pair::new(server, client, SAMPLES);
323
+
324
+ poll_tls_pair(pair);
325
+ // confirm that the callback returned Pending `require_pending_count` times
326
+ assert_eq!(wake_count, require_pending_count);
327
+ // confirm that the final invoked count is +1 more than `require_pending_count`
328
+ assert_eq!(
329
+ handle.invoked.load(Ordering::SeqCst),
330
+ require_pending_count + 1
331
+ );
332
+ }
213
333
  }
@@ -5,9 +5,10 @@ use crate::{
5
5
  raw::{config::*, security},
6
6
  testing::s2n_tls::Harness,
7
7
  };
8
+ use alloc::{collections::VecDeque, sync::Arc};
8
9
  use bytes::Bytes;
9
- use core::task::Poll;
10
- use std::collections::VecDeque;
10
+ use core::{sync::atomic::Ordering, task::Poll};
11
+ use std::sync::atomic::AtomicUsize;
11
12
 
12
13
  pub mod s2n_tls;
13
14
 
@@ -133,7 +134,22 @@ impl CertKeyPair {
133
134
  }
134
135
  }
135
136
 
137
+ #[derive(Default)]
138
+ pub struct UnsecureAcceptAllClientCertificatesHandler {}
139
+ impl VerifyClientCertificateHandler for UnsecureAcceptAllClientCertificatesHandler {
140
+ fn verify_host_name(&self, _host_name: &str) -> bool {
141
+ true
142
+ }
143
+ }
144
+
136
145
  pub fn build_config(cipher_prefs: &security::Policy) -> Result<crate::raw::config::Config, Error> {
146
+ let builder = config_builder(cipher_prefs)?;
147
+ Ok(builder.build().expect("Unable to build server config"))
148
+ }
149
+
150
+ pub fn config_builder(
151
+ cipher_prefs: &security::Policy,
152
+ ) -> Result<crate::raw::config::Builder, Error> {
137
153
  let mut builder = Builder::new();
138
154
  let mut keypair = CertKeyPair::default();
139
155
  // Build a config
@@ -144,32 +160,14 @@ pub fn build_config(cipher_prefs: &security::Policy) -> Result<crate::raw::confi
144
160
  .load_pem(keypair.cert(), keypair.key())
145
161
  .expect("Unable to load cert/pem");
146
162
  unsafe {
147
- let ctx: *mut core::ffi::c_void = std::ptr::null_mut();
148
163
  builder
149
- .set_verify_host_callback(Some(verify_host_cb), ctx)
164
+ .set_verify_host_handler(UnsecureAcceptAllClientCertificatesHandler::default())
150
165
  .expect("Unable to set a host verify callback.");
151
166
  builder
152
167
  .disable_x509_verification()
153
168
  .expect("Unable to disable x509 verification");
154
169
  };
155
- Ok(builder.build().expect("Unable to build server config"))
156
- }
157
-
158
- // host verify callback for x509
159
- // see: https://github.com/aws/s2n-tls/blob/main/docs/USAGE-GUIDE.md#s2n_verify_host_fn
160
- unsafe extern "C" fn verify_host_cb(
161
- hostname: *const i8,
162
- hostname_len: usize,
163
- _context: *mut core::ffi::c_void,
164
- ) -> u8 {
165
- let host_str = ::std::str::from_utf8(::std::slice::from_raw_parts(
166
- hostname as *const u8,
167
- hostname_len,
168
- ));
169
- match host_str {
170
- Err(_) => 0,
171
- Ok(_host) => 1,
172
- }
170
+ Ok(builder)
173
171
  }
174
172
 
175
173
  pub fn s2n_tls_pair(config: crate::raw::config::Config) {
@@ -190,7 +188,11 @@ pub fn s2n_tls_pair(config: crate::raw::config::Config) {
190
188
  .expect("Unabel to set client config");
191
189
  let client = Harness::new(client);
192
190
 
193
- let mut pair = Pair::new(server, client, SAMPLES);
191
+ let pair = Pair::new(server, client, SAMPLES);
192
+ poll_tls_pair(pair);
193
+ }
194
+
195
+ pub fn poll_tls_pair(mut pair: Pair<Harness, Harness>) {
194
196
  loop {
195
197
  match pair.poll() {
196
198
  Poll::Ready(result) => {
@@ -203,3 +205,36 @@ pub fn s2n_tls_pair(config: crate::raw::config::Config) {
203
205
 
204
206
  // TODO add assertions to make sure the handshake actually succeeded
205
207
  }
208
+
209
+ #[derive(Clone)]
210
+ pub struct MockClientHelloHandler {
211
+ require_pending_count: usize,
212
+ invoked: Arc<AtomicUsize>,
213
+ }
214
+
215
+ impl MockClientHelloHandler {
216
+ pub fn new(require_pending_count: usize) -> Self {
217
+ Self {
218
+ require_pending_count,
219
+ invoked: Arc::new(AtomicUsize::new(0)),
220
+ }
221
+ }
222
+ }
223
+
224
+ impl ClientHelloHandler for MockClientHelloHandler {
225
+ fn poll_client_hello(
226
+ &self,
227
+ connection: &mut crate::raw::connection::Connection,
228
+ ) -> core::task::Poll<Result<(), ()>> {
229
+ if self.invoked.fetch_add(1, Ordering::SeqCst) < self.require_pending_count {
230
+ // confirm the callback can access the waker
231
+ connection.waker().unwrap().wake_by_ref();
232
+ return Poll::Pending;
233
+ }
234
+
235
+ // Test that server_name_extension_used can be invoked
236
+ connection.server_name_extension_used();
237
+
238
+ Poll::Ready(Ok(()))
239
+ }
240
+ }
@@ -1,7 +1,7 @@
1
1
  [package]
2
2
  name = "s2n-tls-sys"
3
3
  description = "A C99 implementation of the TLS/SSL protocols"
4
- version = "0.0.2"
4
+ version = "0.0.4"
5
5
  authors = ["AWS s2n"]
6
6
  edition = "2018"
7
7
  links = "s2n-tls"
@@ -18,3 +18,6 @@ extern "C" {
18
18
  config: *mut *mut s2n_config,
19
19
  ) -> ::libc::c_int;
20
20
  }
21
+ extern "C" {
22
+ pub fn s2n_config_client_hello_cb_enable_poll(config: *mut s2n_config) -> ::libc::c_int;
23
+ }
@@ -150,7 +150,7 @@ static int s2n_composite_cipher_aes_sha_initial_hmac(struct s2n_session_key *key
150
150
  */
151
151
  int ctrl_ret = EVP_CIPHER_CTX_ctrl(key->evp_cipher_ctx, EVP_CTRL_AEAD_TLS1_AAD, S2N_TLS12_AAD_LEN, ctrl_buf);
152
152
 
153
- S2N_ERROR_IF(ctrl_ret < 0, S2N_ERR_INITIAL_HMAC);
153
+ S2N_ERROR_IF(ctrl_ret <= 0, S2N_ERR_INITIAL_HMAC);
154
154
 
155
155
  *extra = ctrl_ret;
156
156
  return 0;
@@ -197,9 +197,14 @@ int s2n_drbg_generate(struct s2n_drbg *drbg, struct s2n_blob *blob)
197
197
 
198
198
  S2N_ERROR_IF(blob->size > S2N_DRBG_GENERATE_LIMIT, S2N_ERR_DRBG_REQUEST_SIZE);
199
199
 
200
- /* Always mix in additional entropy, for prediction resistance.
201
- If s2n_drbg_mix is removed: must implement reseeding according to limit
202
- specified in NIST SP800-90A 10.2.1 Table 3. */
200
+ /* Mix in additional entropy for every randomness generation call. This
201
+ * defense mechanism is referred to as "prediction resistance".
202
+ * If we ever relax this defense, we must:
203
+ * 1. Implement reseeding according to limit specified in
204
+ * NIST SP800-90A 10.2.1 Table 3.
205
+ * 2. Re-consider whether the current fork detection strategy is still
206
+ * sufficient.
207
+ */
203
208
  POSIX_GUARD(s2n_drbg_mix(drbg, &zeros));
204
209
  POSIX_GUARD(s2n_drbg_bits(drbg, blob));
205
210
  POSIX_GUARD(s2n_drbg_update(drbg, &zeros));
@@ -265,6 +265,9 @@ static const char *no_such_error = "Internal s2n error";
265
265
  ERR_ENTRY(S2N_ERR_KEYING_MATERIAL_EXPIRED, "The lifetime of the connection keying material has exceeded the limit. Perform a new full handshake.") \
266
266
  ERR_ENTRY(S2N_ERR_EARLY_DATA_TRIAL_DECRYPT, "Unable to decrypt rejected early data") \
267
267
  ERR_ENTRY(S2N_ERR_PKEY_CTX_INIT, "Unable to initialize the libcrypto pkey context") \
268
+ ERR_ENTRY(S2N_ERR_FORK_DETECTION_INIT, "Fork detection initialization failed") \
269
+ ERR_ENTRY(S2N_ERR_RETRIEVE_FORK_GENERATION_NUMBER, "Retrieving fork generation number failed") \
270
+
268
271
  /* clang-format on */
269
272
 
270
273
  #define ERR_STR_CASE(ERR, str) case ERR: return str;
@@ -207,6 +207,8 @@ typedef enum {
207
207
  S2N_ERR_INVALID_CERT_STATE,
208
208
  S2N_ERR_INVALID_EARLY_DATA_STATE,
209
209
  S2N_ERR_PKEY_CTX_INIT,
210
+ S2N_ERR_FORK_DETECTION_INIT,
211
+ S2N_ERR_RETRIEVE_FORK_GENERATION_NUMBER,
210
212
  S2N_ERR_T_INTERNAL_END,
211
213
 
212
214
  /* S2N_ERR_T_USAGE */
@@ -33,3 +33,14 @@ libs2n.so: ${OBJS}
33
33
 
34
34
  libs2n.dylib: ${OBJS}
35
35
  test ! -f /usr/lib/libSystem.dylib || libtool -dynamic ${LIBS} -L${LIBCRYPTO_ROOT}/lib ${CRYPTO_LIBS} -o libs2n.dylib ${OBJS}
36
+
37
+ $(libdir):
38
+ @mkdir -p $(libdir)
39
+
40
+ install: libs2n.a libs2n.so $(libdir)
41
+ @cp libs2n.* $(libdir)
42
+ @cp ../api/s2n.h $(includedir)
43
+
44
+ uninstall:
45
+ @rm $(libdir)/libs2n.*
46
+ @rm $(includedir)/s2n.h
@@ -6,8 +6,8 @@
6
6
  extern const int16_t PQCLEAN_KYBER51290S_CLEAN_zetas[128];
7
7
  extern const int16_t PQCLEAN_KYBER51290S_CLEAN_zetasinv[128];
8
8
 
9
- void PQCLEAN_KYBER51290S_CLEAN_ntt(int16_t *poly);
10
- void PQCLEAN_KYBER51290S_CLEAN_invntt(int16_t *poly);
9
+ void PQCLEAN_KYBER51290S_CLEAN_ntt(int16_t poly[256]);
10
+ void PQCLEAN_KYBER51290S_CLEAN_invntt(int16_t poly[256]);
11
11
  void PQCLEAN_KYBER51290S_CLEAN_basemul(int16_t r[2], const int16_t a[2], const int16_t b[2], int16_t zeta);
12
12
 
13
13
  #endif
@@ -6,8 +6,8 @@
6
6
  extern const int16_t PQCLEAN_KYBER512_CLEAN_zetas[128];
7
7
  extern const int16_t PQCLEAN_KYBER512_CLEAN_zetasinv[128];
8
8
 
9
- void PQCLEAN_KYBER512_CLEAN_ntt(int16_t *poly);
10
- void PQCLEAN_KYBER512_CLEAN_invntt(int16_t *poly);
9
+ void PQCLEAN_KYBER512_CLEAN_ntt(int16_t poly[256]);
10
+ void PQCLEAN_KYBER512_CLEAN_invntt(int16_t poly[256]);
11
11
  void PQCLEAN_KYBER512_CLEAN_basemul(int16_t r[2], const int16_t a[2], const int16_t b[2], int16_t zeta);
12
12
 
13
13
  #endif
@@ -37,7 +37,7 @@ void poly_getnoise_eta1_4x(poly *r0,
37
37
  poly *r1,
38
38
  poly *r2,
39
39
  poly *r3,
40
- const uint8_t *seed,
40
+ const uint8_t seed[32],
41
41
  uint8_t nonce0,
42
42
  uint8_t nonce1,
43
43
  uint8_t nonce2,
@@ -48,7 +48,7 @@ void poly_getnoise_eta1122_4x(poly *r0,
48
48
  poly *r1,
49
49
  poly *r2,
50
50
  poly *r3,
51
- const uint8_t *seed,
51
+ const uint8_t seed[32],
52
52
  uint8_t nonce0,
53
53
  uint8_t nonce1,
54
54
  uint8_t nonce2,
@@ -11,10 +11,10 @@ typedef struct{
11
11
  } polyvec;
12
12
 
13
13
  #define polyvec_compress_avx2 S2N_KYBER_512_R3_NAMESPACE(polyvec_compress_avx2)
14
- void polyvec_compress_avx2(uint8_t r[S2N_KYBER_512_R3_POLYCOMPRESSEDBYTES+2], const polyvec *a);
14
+ void polyvec_compress_avx2(uint8_t r[S2N_KYBER_512_R3_POLYVECCOMPRESSEDBYTES+2], const polyvec *a);
15
15
 
16
16
  #define polyvec_decompress_avx2 S2N_KYBER_512_R3_NAMESPACE(polyvec_decompress_avx2)
17
- void polyvec_decompress_avx2(polyvec *r, const uint8_t a[S2N_KYBER_512_R3_POLYCOMPRESSEDBYTES+12]);
17
+ void polyvec_decompress_avx2(polyvec *r, const uint8_t a[S2N_KYBER_512_R3_POLYVECCOMPRESSEDBYTES+12]);
18
18
 
19
19
  #define polyvec_tobytes_avx2 S2N_KYBER_512_R3_NAMESPACE(polyvec_tobytes_avx2)
20
20
  void polyvec_tobytes_avx2(uint8_t r[S2N_KYBER_512_R3_POLYVECBYTES], const polyvec *a);
@@ -150,7 +150,7 @@ void fpdiv2_503(const digit_t* a, digit_t* c);
150
150
  void fpcorrection503(digit_t* a);
151
151
 
152
152
  // 503-bit Montgomery reduction, c = a mod p
153
- void rdc_mont(const digit_t* a, digit_t* c);
153
+ void rdc_mont(const dfelm_t ma, felm_t mc);
154
154
 
155
155
  // Field multiplication using Montgomery arithmetic, c = a*b*R^-1 mod p503, where R=2^768
156
156
  void fpmul503_mont(const felm_t a, const felm_t b, felm_t c);
@@ -7,7 +7,7 @@
7
7
  #define SHAKE128_RATE 168
8
8
  #define SHAKE256_RATE 136
9
9
 
10
- void cshake256_simple_absorb(uint64_t *s, uint16_t cstm, const unsigned char *in, unsigned long long inlen);
10
+ void cshake256_simple_absorb(uint64_t s[25], uint16_t cstm, const unsigned char *in, unsigned long long inlen);
11
11
  void cshake256_simple(unsigned char *output, unsigned long long outlen, uint16_t cstm, const unsigned char *in, unsigned long long inlen);
12
12
 
13
13
  #endif // FIPS202_R1_H
@@ -31,6 +31,10 @@
31
31
 
32
32
  #endif
33
33
 
34
+ #if defined(__linux__) && defined(__ELF__)
35
+ .section .note.GNU-stack,"",%progbits
36
+ #endif
37
+
34
38
  .text
35
39
 
36
40
  #define asm_p434 S2N_SIKE_P434_R3_NAMESPACE(asm_p434)
@@ -167,6 +167,13 @@ ifndef COV_TOOL
167
167
  endif
168
168
  endif
169
169
 
170
+ # Used for testing.
171
+ prefix ?= /usr/local
172
+ exec_prefix ?= $(prefix)
173
+ bindir ?= $(exec_prefix)/bin
174
+ libdir ?= $(exec_prefix)/lib64
175
+ includedir ?= $(exec_prefix)/include
176
+
170
177
  try_compile = $(shell $(CC) $(CFLAGS) -c -o tmp.o $(1) > /dev/null 2>&1; echo $$?; rm tmp.o > /dev/null 2>&1)
171
178
 
172
179
  # Determine if execinfo.h is available
@@ -211,6 +218,24 @@ ifeq ($(TRY_EVP_MD_CTX_SET_PKEY_CTX), 0)
211
218
  DEFAULT_CFLAGS += -DS2N_LIBCRYPTO_SUPPORTS_EVP_MD_CTX_SET_PKEY_CTX
212
219
  endif
213
220
 
221
+ # Determine if madvise() is available
222
+ TRY_COMPILE_MADVISE := $(call try_compile,$(S2N_ROOT)/tests/features/madvise.c)
223
+ ifeq ($(TRY_COMPILE_MADVISE), 0)
224
+ DEFAULT_CFLAGS += -DS2N_MADVISE_SUPPORTED
225
+ endif
226
+
227
+ # Determine if minherit() is available
228
+ TRY_COMPILE_MINHERIT:= $(call try_compile,$(S2N_ROOT)/tests/features/minherit.c)
229
+ ifeq ($(TRY_COMPILE_MINHERIT), 0)
230
+ DEFAULT_CFLAGS += -DS2N_MINHERIT_SUPPORTED
231
+ endif
232
+
233
+ # Determine if clone() is available
234
+ TRY_COMPILE_CLONE := $(call try_compile,$(S2N_ROOT)/tests/features/clone.c)
235
+ ifeq ($(TRY_COMPILE_CLONE), 0)
236
+ DEFAULT_CFLAGS += -DS2N_CLONE_SUPPORTED
237
+ endif
238
+
214
239
  CFLAGS_LLVM = ${DEFAULT_CFLAGS} -emit-llvm -c -g -O1
215
240
 
216
241
  $(BITCODE_DIR)%.bc: %.c
@@ -706,6 +706,11 @@ for context in CONTEXTS:
706
706
  doc = 'Ensures `{is_ok}`, otherwise the function will return `{error}`'
707
707
  if other == PTR:
708
708
  doc += '\n\nDoes not set s2n_errno to S2N_ERR_NULL, so is NOT a direct replacement for {prefix}ENSURE_REF.'
709
+ if context['ret'] != DEFAULT['ret']:
710
+ doc = (deprecation_message + "\n\n" + doc)
711
+
712
+ if other == context:
713
+ continue;
709
714
 
710
715
  impl = '__S2N_ENSURE({is_ok}, return {error})'
711
716
  args = {
@@ -722,7 +727,16 @@ for context in CONTEXTS:
722
727
  docs += push_doc(args)
723
728
  header += push_macro(args)
724
729
 
730
+ def cleanup(contents):
731
+ # Remove any unnecessary generated "X_GUARD_X"s, like "RESULT_GUARD_RESULT"
732
+ for context in CONTEXTS:
733
+ x_guard = "{name}_GUARD".format_map(context)
734
+ x_guard_x = "{name}_GUARD_{name}".format_map(context)
735
+ contents = contents.replace(x_guard_x, x_guard)
736
+ return contents
737
+
725
738
  def write(f, contents):
739
+ contents = cleanup(contents)
726
740
  header_file = open(f, "w")
727
741
  header_file.write(contents)
728
742
  header_file.close()
@@ -3,24 +3,38 @@ This README covers the basics on how to build the s2n-tls library to be able to
3
3
  ##Install Google Benchmark
4
4
  Follow instructions on the Google Benchmark repository to build and install [Google Benchmark](https://github.com/google/benchmark)
5
5
 
6
- ##Building the s2n-tls library
6
+ ## Building the s2n-tls library
7
7
  #### In order to enable the s2n library to build the benchmarks the following parameters must be set:
8
8
  1. `-DBUILD_TESTING=1`
9
9
  2. `-DBENCHMARK=1`
10
10
  3. `-DCMAKE_PREFIX_PATH="File/path/to/Google/Benchmark/"`
11
11
 
12
- ####Example:
13
- `cmake . -Bbuild -GNinja -DCMAKE_EXE_LINKER_FLAGS="-lcrypto -lz" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=1 -DBENCHMARK=1 -DCMAKE_PREFIX_PATH="~/benchmark/install"`
12
+ #### Example:
13
+
14
+ ```
15
+ # Starting from the top level "s2n-tls" directory, remove previous CMake build files, if any
16
+ rm -rf build
17
+
18
+ # Initialize CMake build directory with Nina build system
19
+ cmake . -Bbuild -GNinja -DCMAKE_EXE_LINKER_FLAGS="-lcrypto -lz" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=1 -DBENCHMARK=1 -DCMAKE_PREFIX_PATH="~/benchmark/install"
20
+
21
+ # Actually build the executable binaries
22
+ cd build
23
+ ninja
24
+
25
+ # Run a benchmark
26
+ ./bin/s2n_negotiate_benchmark -r 1 -i 5 -p ../tests/pems/ -o negotiate_data -t console localhost 8000
27
+ ```
14
28
 
15
29
  **If you would like to build with a different libcrypto, include the file path in -DCMAKE_PREFIX_PATH**:
16
30
 
17
31
  `-DCMAKE_PREFIX_PATH="~/aws-lc/install;~/benchmark/install"`
18
32
 
19
- ##Running benchmarks
33
+ ## Running benchmarks
20
34
  Once the s2n-tls library has completed building, the benchmarks can be located in the `build/bin` folder.
21
35
  The two benchmarks that are currently available are `s2n_negotiate_benchmark` and `s2n_send_recv_benchmark`
22
36
 
23
- ###Benchmark Options:
37
+ ### Benchmark Options:
24
38
  Each benchmark has the ability to accept different options:
25
39
 
26
40
  usage:
@@ -29,7 +43,7 @@ usage:
29
43
 
30
44
  host: hostname or IP address to connect to
31
45
  port: port to connect to
32
- ######Options:
46
+ ###### Options:
33
47
  -i [# of iterations]
34
48
  sets the number of iterations to run each repetition
35
49
 
@@ -64,14 +78,14 @@ usage:
64
78
  print debug output to terminal
65
79
 
66
80
 
67
- ###s2n_negotiate_benchmark
81
+ ### s2n_negotiate_benchmark
68
82
  Example:
69
83
 
70
- `./s2n_negotitate_benchmark -r 1 -i 5 -p /Users/sidhusn/s2n-tls/tests/pems/ -o negotiate_data -t console localhost 8000`
84
+ `./bin/s2n_negotiate_benchmark -r 1 -i 5 -p ../tests/pems/ -o negotiate_data -t console localhost 8000`
71
85
 
72
86
  or
73
87
 
74
- `./s2n_negotitate_benchmark -r 5 -i 5 -w 10 -p /Users/sidhusn/s2n-tls/tests/pems/ -o negotiate_data -t console localhost 8000`
88
+ `./bin/s2n_negotiate_benchmark -r 5 -i 5 -w 10 -p ../tests/pems/ -o negotiate_data -t console localhost 8000`
75
89
 
76
90
 
77
91
 
@@ -0,0 +1,24 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License").
5
+ * You may not use this file except in compliance with the License.
6
+ * A copy of the License is located at
7
+ *
8
+ * http://aws.amazon.com/apache2.0
9
+ *
10
+ * or in the "license" file accompanying this file. This file is distributed
11
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12
+ * express or implied. See the License for the specific language governing
13
+ * permissions and limitations under the License.
14
+ */
15
+
16
+ #define _GNU_SOURCE
17
+
18
+ #include <sched.h>
19
+ #include <stddef.h>
20
+
21
+ int main() {
22
+ clone(NULL, NULL, 0, NULL);
23
+ return 0;
24
+ }
@@ -0,0 +1,27 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License").
5
+ * You may not use this file except in compliance with the License.
6
+ * A copy of the License is located at
7
+ *
8
+ * http://aws.amazon.com/apache2.0
9
+ *
10
+ * or in the "license" file accompanying this file. This file is distributed
11
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12
+ * express or implied. See the License for the specific language governing
13
+ * permissions and limitations under the License.
14
+ */
15
+
16
+ /* Keep in sync with utils/s2n_fork_detection.c */
17
+ #if !defined(__APPLE__) && !defined(_GNU_SOURCE)
18
+ #define _GNU_SOURCE
19
+ #endif
20
+
21
+ #include <stddef.h>
22
+ #include <sys/mman.h>
23
+
24
+ int main() {
25
+ madvise(NULL, 0, 0);
26
+ return 0;
27
+ }
@@ -0,0 +1,22 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License").
5
+ * You may not use this file except in compliance with the License.
6
+ * A copy of the License is located at
7
+ *
8
+ * http://aws.amazon.com/apache2.0
9
+ *
10
+ * or in the "license" file accompanying this file. This file is distributed
11
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12
+ * express or implied. See the License for the specific language governing
13
+ * permissions and limitations under the License.
14
+ */
15
+
16
+ #include <stddef.h>
17
+ #include <sys/mman.h>
18
+
19
+ int main() {
20
+ minherit(NULL, 0, 0);
21
+ return 0;
22
+ }
@@ -19,9 +19,9 @@ def pytest_configure(config):
19
19
 
20
20
  no_pq = config.getoption('no-pq', 0)
21
21
  fips_mode = config.getoption('fips-mode', 0)
22
- if no_pq is 1:
22
+ if no_pq == 1:
23
23
  set_flag(S2N_NO_PQ, True)
24
- if fips_mode is 1:
24
+ if fips_mode == 1:
25
25
  set_flag(S2N_FIPS_MODE, True)
26
26
 
27
27
  set_flag(S2N_PROVIDER_VERSION, config.getoption('provider-version', None))
@@ -126,7 +126,7 @@ int main(int argc, char **argv)
126
126
  */
127
127
  {
128
128
  /* Carefully consider any increases to this number. */
129
- const uint16_t max_connection_size = 9000;
129
+ const uint16_t max_connection_size = 9100;
130
130
  const uint16_t min_connection_size = max_connection_size * 0.75;
131
131
 
132
132
  size_t connection_size = sizeof(struct s2n_connection);