proxygen
OpenSSLEVPCipherTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #include <gtest/gtest.h>
10 
18 #include <fizz/record/Types.h>
19 #include <folly/ExceptionWrapper.h>
20 #include <folly/String.h>
21 
22 using namespace folly;
23 
24 namespace fizz {
25 namespace test {
26 
27 struct CipherParams {
34  bool valid;
36 };
37 
38 constexpr size_t kHeadroom = 10;
39 
40 class OpenSSLEVPCipherTest : public ::testing::TestWithParam<CipherParams> {};
41 
42 std::unique_ptr<Aead> getCipher(const CipherParams& params) {
43  std::unique_ptr<Aead> cipher;
44  switch (params.cipher) {
45  case CipherSuite::TLS_AES_128_GCM_SHA256:
46  cipher = std::make_unique<OpenSSLEVPCipher<AESGCM128>>();
47  break;
48  case CipherSuite::TLS_AES_256_GCM_SHA384:
49  cipher = std::make_unique<OpenSSLEVPCipher<AESGCM256>>();
50  break;
51  case CipherSuite::TLS_CHACHA20_POLY1305_SHA256:
52  cipher = std::make_unique<OpenSSLEVPCipher<ChaCha20Poly1305>>();
53  break;
54  case CipherSuite::TLS_AES_128_OCB_SHA256_EXPERIMENTAL:
55  cipher = std::make_unique<OpenSSLEVPCipher<AESOCB128>>();
56  break;
57  default:
58  throw std::runtime_error("Invalid cipher");
59  }
60 
61  TrafficKey trafficKey;
62  trafficKey.key = toIOBuf(params.key);
63  trafficKey.iv = toIOBuf(params.iv);
64  cipher->setKey(std::move(trafficKey));
65  cipher->setEncryptedBufferHeadroom(kHeadroom);
66  return cipher;
67 }
68 
69 std::unique_ptr<IOBuf> copyBuffer(const folly::IOBuf& buf) {
70  std::unique_ptr<IOBuf> out;
71  for (auto r : buf) {
72  if (out) {
74  } else {
75  out = IOBuf::copyBuffer(r);
76  }
77  }
78  return out;
79 }
80 
81 std::unique_ptr<folly::IOBuf> callEncrypt(
82  std::unique_ptr<Aead>& cipher,
83  const CipherParams& params,
84  std::unique_ptr<IOBuf> plaintext = nullptr,
85  std::unique_ptr<IOBuf> aad = nullptr) {
86  if (!plaintext) {
87  plaintext = toIOBuf(params.plaintext);
88  }
89 
90  if (!aad && !params.aad.empty()) {
91  aad = toIOBuf(params.aad);
92  }
93  auto ptCopy = copyBuffer(*plaintext);
94  auto out = cipher->encrypt(std::move(plaintext), aad.get(), params.seqNum);
95  bool valid = IOBufEqualTo()(toIOBuf(params.ciphertext), out);
96 
97  EXPECT_EQ(valid, params.valid);
98  EXPECT_EQ(
99  out->computeChainDataLength(),
100  ptCopy->computeChainDataLength() + cipher->getCipherOverhead());
101  return out;
102 }
103 
105  std::unique_ptr<Aead>& cipher,
106  const CipherParams& params,
107  std::unique_ptr<IOBuf> ciphertext = nullptr,
108  std::unique_ptr<IOBuf> aad = nullptr) {
109  if (!ciphertext) {
110  ciphertext = toIOBuf(params.ciphertext);
111  }
112  if (!aad && !params.aad.empty()) {
113  aad = toIOBuf(params.aad);
114  }
115  auto ctCopy = copyBuffer(*ciphertext);
116  try {
117  auto out = cipher->decrypt(std::move(ciphertext), aad.get(), params.seqNum);
118  EXPECT_TRUE(params.valid);
119  EXPECT_TRUE(IOBufEqualTo()(toIOBuf(params.plaintext), out));
120 
121  EXPECT_EQ(
122  out->computeChainDataLength(),
123  ctCopy->computeChainDataLength() - cipher->getCipherOverhead());
124  } catch (const std::runtime_error&) {
125  EXPECT_FALSE(params.valid);
126  }
127 }
128 
130  auto cipher = getCipher(GetParam());
131  auto out = callEncrypt(cipher, GetParam());
132  EXPECT_EQ(out->headroom(), 0);
133 }
134 
135 TEST_P(OpenSSLEVPCipherTest, TestEncryptWithTagRoom) {
136  auto cipher = getCipher(GetParam());
137  auto input = toIOBuf(GetParam().plaintext, 0, cipher->getCipherOverhead());
138  auto out = callEncrypt(cipher, GetParam(), std::move(input));
139  EXPECT_FALSE(out->isChained());
140 }
141 
142 TEST_P(OpenSSLEVPCipherTest, TestEncryptReusedCipher) {
143  auto cipher = getCipher(GetParam());
144  auto params = GetParam();
146  callEncrypt(cipher, GetParam());
147 }
148 
149 TEST_P(OpenSSLEVPCipherTest, TestEncryptChunkedInput) {
150  auto cipher = getCipher(GetParam());
151  auto input = toIOBuf(GetParam().plaintext);
152  auto chunkedInput = chunkIOBuf(std::move(input), 3);
153  callEncrypt(cipher, GetParam(), std::move(chunkedInput));
154 }
155 
156 TEST_P(OpenSSLEVPCipherTest, TestEncryptChunkedInputWithTagRoomHead) {
157  auto cipher = getCipher(GetParam());
158  auto input = toIOBuf(GetParam().plaintext);
159  auto overhead = cipher->getCipherOverhead();
160  auto creator = [overhead](size_t len, size_t num) {
161  if (num == 0) {
162  // create a buffer w/ room for the tag
163  auto result = IOBuf::create(len + overhead);
164  result->reserve(0, overhead);
165  return result;
166  }
167  return IOBuf::create(len);
168  };
169  auto chunkedInput = chunkIOBuf(std::move(input), 3, creator);
170  auto out = callEncrypt(cipher, GetParam(), std::move(chunkedInput));
171  // even though the head element has tailroom, we don't use it since it's
172  // the last element that needs to have it for copying tag in directly
173  EXPECT_GE(out->tailroom(), overhead);
174 }
175 
176 TEST_P(OpenSSLEVPCipherTest, TestEncryptChunkedInputWithTagRoomLast) {
177  auto cipher = getCipher(GetParam());
178  auto input = toIOBuf(GetParam().plaintext);
179  auto overhead = cipher->getCipherOverhead();
180  size_t chunks = 3;
181  auto creator = [=](size_t len, size_t num) {
182  if (num == chunks - 1) {
183  // create a buffer w/ room for the tag
184  auto result = IOBuf::create(len + overhead);
185  result->reserve(0, overhead);
186  return result;
187  }
188  return IOBuf::create(len);
189  };
190  auto chunkedInput = chunkIOBuf(std::move(input), chunks, creator);
191  auto lastTailRoom = chunkedInput->prev()->tailroom();
192  auto numElements = chunkedInput->countChainElements();
193  auto out = callEncrypt(cipher, GetParam(), std::move(chunkedInput));
194  // we expect the last element in the chain to have tailroom - overhead
195  // left
196  EXPECT_EQ(out->prev()->tailroom(), lastTailRoom - overhead);
197  EXPECT_EQ(out->countChainElements(), numElements);
198 }
199 
200 TEST_P(OpenSSLEVPCipherTest, TestEncryptChunkedSharedInput) {
201  auto cipher = getCipher(GetParam());
202  auto input = toIOBuf(GetParam().plaintext);
203  auto chunkedInput = chunkIOBuf(std::move(input), 3);
204  auto out = callEncrypt(cipher, GetParam(), chunkedInput->clone());
205  // we expect headroom of record size and a single buffer in the
206  // the chain
207  EXPECT_EQ(out->headroom(), kHeadroom);
208  EXPECT_FALSE(out->isChained());
209 }
210 
211 TEST_P(OpenSSLEVPCipherTest, TestEncryptChunkedAad) {
212  auto cipher = getCipher(GetParam());
213  auto aad = toIOBuf(GetParam().aad);
214  auto chunkedAad = chunkIOBuf(std::move(aad), 3);
215  callEncrypt(cipher, GetParam(), nullptr, std::move(chunkedAad));
216 }
217 
219  auto cipher = getCipher(GetParam());
220  callDecrypt(cipher, GetParam());
221 }
222 
223 TEST_P(OpenSSLEVPCipherTest, TestDecryptReusedCipher) {
224  auto cipher = getCipher(GetParam());
225  auto params = GetParam();
227  callDecrypt(cipher, GetParam());
228 }
229 
230 TEST_P(OpenSSLEVPCipherTest, TestDecryptInputTooSmall) {
231  auto cipher = getCipher(GetParam());
232  auto in = IOBuf::copyBuffer("in");
233  auto paramsCopy = GetParam();
234  paramsCopy.valid = false;
235  callDecrypt(cipher, paramsCopy, std::move(in));
236 }
237 
238 TEST_P(OpenSSLEVPCipherTest, TestDecryptWithChunkedInput) {
239  auto cipher = getCipher(GetParam());
240  auto output = toIOBuf(GetParam().ciphertext);
241  auto chunkedOutput = chunkIOBuf(std::move(output), 3);
242  callDecrypt(cipher, GetParam(), std::move(chunkedOutput));
243 }
244 
245 TEST_P(OpenSSLEVPCipherTest, TestDecryptWithChunkedSharedInput) {
246  auto cipher = getCipher(GetParam());
247  auto output = toIOBuf(GetParam().ciphertext);
248  auto chunkedOutput = chunkIOBuf(std::move(output), 3);
249  callDecrypt(cipher, GetParam(), chunkedOutput->clone());
250 }
251 
252 TEST_P(OpenSSLEVPCipherTest, TestDecryptWithVeryChunkedInput) {
253  auto cipher = getCipher(GetParam());
254  auto output = toIOBuf(GetParam().ciphertext);
255  auto chunkedOutput = chunkIOBuf(std::move(output), 30);
256  callDecrypt(cipher, GetParam(), std::move(chunkedOutput));
257 }
258 
259 TEST_P(OpenSSLEVPCipherTest, TestDecryptWithChunkedAad) {
260  auto cipher = getCipher(GetParam());
261  auto aad = toIOBuf(GetParam().aad);
262  auto chunkedAad = chunkIOBuf(std::move(aad), 3);
263  callDecrypt(cipher, GetParam(), nullptr, std::move(chunkedAad));
264 }
265 
266 TEST_P(OpenSSLEVPCipherTest, TestTryDecrypt) {
267  auto cipher = getCipher(GetParam());
268  auto out = cipher->tryDecrypt(
269  toIOBuf(GetParam().ciphertext),
270  toIOBuf(GetParam().aad).get(),
271  GetParam().seqNum);
272  if (out) {
273  EXPECT_TRUE(GetParam().valid);
274  EXPECT_TRUE(IOBufEqualTo()(toIOBuf(GetParam().plaintext), *out));
275  } else {
276  EXPECT_FALSE(GetParam().valid);
277  }
278 }
279 
280 // Adapted from draft-thomson-tls-tls13-vectors
282  AESGCM128TestVectors,
284  ::testing::Values(
285  CipherParams{"87f6c12b1ae8a9b7efafc65af0f5c994",
286  "479e25839c19e0476f95a6f5",
287  1,
288  "",
289  "010015",
290  "9d4db5ecd768198892531eebac72cf1d477dd0",
291  true,
292  CipherSuite::TLS_AES_128_GCM_SHA256},
293  CipherParams{
294  "911dc107aa6eccb6706bdcc37e76a07a",
295  "11c7fa13e9499ed042b09e57",
296  0,
297  "",
298  "14000020de15cbc8c62d0e6fef73a6d4e70e5c372c2b94fe08ea40d11166a7e6c967ba9c16",
299  "56a21739148c898fe807026a179d59202647a3b1e01267a3883cf5f69fd233f63ff12c1c71b4c8f3d6086affb49621f96b842e1d35",
300  true,
301  CipherSuite::TLS_AES_128_GCM_SHA256},
302  CipherParams{"a0f49e7076cae6eb25ca23a2da0eaf12",
303  "3485d33f22128dff91e47062",
304  0,
305  "",
306  "41424344454617",
307  "92fdec5c241e994fb7d889e1b61d1db2b9be6777f5a393",
308  true,
309  CipherSuite::TLS_AES_128_GCM_SHA256},
310  CipherParams{
311  "fda2a4404670808f4937478b8b6e3fe1",
312  "b5f3a3fae1cb25c9dcd73993",
313  0,
314  "",
315  "0800001e001c000a00140012001d00170018001901000101010201030104000000000b0001b9000001b50001b0308201ac30820115a003020102020102300d06092a864886f70d01010b0500300e310c300a06035504031303727361301e170d3136303733303031323335395a170d3236303733303031323335395a300e310c300a0603550403130372736130819f300d06092a864886f70d010101050003818d0030818902818100b4bb498f8279303d980836399b36c6988c0c68de55e1bdb826d3901a2461eafd2de49a91d015abbc9a95137ace6c1af19eaa6af98c7ced43120998e187a80ee0ccb0524b1b018c3e0b63264d449a6d38e22a5fda430846748030530ef0461c8ca9d9efbfae8ea6d1d03e2bd193eff0ab9a8002c47428a6d35a8d88d79f7f1e3f0203010001a31a301830090603551d1304023000300b0603551d0f0404030205a0300d06092a864886f70d01010b05000381810085aad2a0e5b9276b908c65f73a7267170618a54c5f8a7b337d2df7a594365417f2eae8f8a58c8f8172f9319cf36b7fd6c55b80f21a03015156726096fd335e5e67f2dbf102702e608ccae6bec1fc63a42a99be5c3eb7107c3c54e9b9eb2bd5203b1c3b84e0a8b2f759409ba3eac9d91d402dcc0cc8f8961229ac9187b42b4de100000f000084080400804547d6168f2510c550bd949cd2bc631ff134fa10a827ff69b166a6bd95e249ed0daf571592ebbe9ff13de6b03acc218146781f693b5a692b7319d74fd2e53b6a2df0f6785d624f024a44030ca00b869ae81a532b19e47e525ff4a62c51a5889eb565fee268590d8a3ca3c1bc3bd5404e39720ca2eaee308f4e0700761e986389140000209efee03ebffbc0dc23d26d958744c09e3000477eff7ae3148a50e5670013aaaa16",
316  "c1e631f81d2af221ebb6a957f58f3ee266272635e67f99a752f0df08adeb33bab8611e55f33d72cf84382461a8bfe0a659ba2dd1873f6fcc707a9841cefc1fb03526b9ca4fe343e5805e95a5c01e56570638a76a4bc8feb07be879f90568617d905fecd5b1619fb8ec4a6628d1bb2bb224c490ff97a6c0e9acd03604bc3a59d86bdab4e084c1c1450f9c9d2afeb172c07234d739868ebd62de2060a8de989414a82920dacd1cac0c6e72ecd7f4018574ceaca6d29f361bc37ee2888b8e302ca9561a9de9163edfa66badd4894884c7b359bcacae5908051b37952e10a45fe73fda126ebd67575f1bed8a992a89474d7dec1eed327824123a414adb66d5ef7d0836ff98c2cdd7fb0781e192bf0c7568bf7d890a51c332879b5037b212d622412ca48e8323817bd6d746eef683845cec4e3ef64b3a18fcce513ea951f3366693a7ff490d09d08ab1f63e13625a545961599c0d9c7a099d1163cad1b9bcf8e917d766b98853ef6877834f891df16be1fcc9c18ea1882ea3f1f4b64358e1b146cebfb3e02e153fdb73af2693f22c6f593fa475380ba6611740ad20e319a654ac5684775236162e8447ed808861bfbda6e18ec97ae090bf703475cfb90fe20a3c55bef6f5eba6e6a1da6a1996b8bde42180608ca2279def8e8153895cc850db6420561c04b5729cc6883436ea02ee07eb9baee2fb3a9e1bbda8730d6b220576e24df70af6928eb865fee8a1d1c0f1818aca68d5002ae4c65b2f49c9e6e21dcf76784adbd0e887a36832ef85beb10587f16c6ffe60d7451059ec7f1014c3efe19e56aedb5ad31a9f29dc4458cfbf0c7070c175dcad46e1675226b47c071aad3172ebd33e45d741cb91253a01a69ae3cc292bce9c03246ac951e45e97ebf04a9d51fab5cf06d9485cce746b1c077be69ad153f1656ef89fc7d1ed8c3e2da7a2",
317  true,
318  CipherSuite::TLS_AES_128_GCM_SHA256},
319  CipherParams{"a0f49e7076cbe6eb25ca23a2da0eaf12",
320  "3485d33f22128dff91e47062",
321  0,
322  "",
323  "41424344454617",
324  "92fdec5c241e994fb7d889e1b61d1db2b9be6777f5a393",
325  false,
326  CipherSuite::TLS_AES_128_GCM_SHA256},
327  CipherParams{"a0f49e7076cae6eb25ca23a2da0eaf12",
328  "3485d33f22128dff91e47062",
329  0,
330  "",
331  "41424344454617",
332  "92fdec",
333  false,
334  CipherSuite::TLS_AES_128_GCM_SHA256},
335  CipherParams{
336  "AD7A2BD03EAC835A6F620FDCB506B345",
337  "12153524C0895E81B2C28465",
338  0,
339  "D609B1F056637A0D46DF998D88E52E00B2C2846512153524C0895E81",
340  "08000F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A0002",
341  "701AFA1CC039C0D765128A665DAB69243899BF7318CCDC81C9931DA17FBE8EDD7D17CB8B4C26FC81E3284F2B7FBA713D4F8D55E7D3F06FD5A13C0C29B9D5B880",
342  true,
343  CipherSuite::TLS_AES_128_GCM_SHA256},
344  CipherParams{
345  "AD7A2BD03EAC835A6F620FDCB506B345",
346  "12153524C0895E81B2C28465",
347  0,
348  "D609B1F056637A1D46DF998D88E52E00B2C2846512153524C0895E81",
349  "08000F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A0002",
350  "701AFA1CC039C0D765128A665DAB69243899BF7318CCDC81C9931DA17FBE8EDD7D17CB8B4C26FC81E3284F2B7FBA713D4F8D55E7D3F06FD5A13C0C29B9D5B880",
351  false,
352  CipherSuite::TLS_AES_128_GCM_SHA256}));
353 
355  AESGCM256TestVectors,
357  ::testing::Values(
358  CipherParams{
359  "E3C08A8F06C6E3AD95A70557B23F75483CE33021A9C72B7025666204C69C0B72",
360  "12153524C0895E81B2C28465",
361  0,
362  "D609B1F056637A0D46DF998D88E52E00B2C2846512153524C0895E81",
363  "08000F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A0002",
364  "E2006EB42F5277022D9B19925BC419D7A592666C925FE2EF718EB4E308EFEAA7C5273B394118860A5BE2A97F56AB78365CA597CDBB3EDB8D1A1151EA0AF7B436",
365  true,
366  CipherSuite::TLS_AES_256_GCM_SHA384},
367  CipherParams{
368  "E3C08A8F06C6E3AD95A70557B23F75483CE33021A9C72B7025666204C69C0B72",
369  "12153524C0895E81B2C28465",
370  0,
371  "D609B1F056637A0D46DF998D88E52E00B2C2846512153524C0895E81",
372  "08000F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A0002",
373  "E2006EB42F5277022D9B19925BC419D7A592666C925FE2EF718EB4E308EFEAA7C5273B394118860A5BE2A97F56AB78365CA597CDBB3EDB8D1A1151EA1AF7B436",
374  false,
375  CipherSuite::TLS_AES_256_GCM_SHA384}));
376 
377 #if FOLLY_OPENSSL_IS_110
378 // Adapted from libressl's chacha20-poly1305 aead tests
380  ChaChaTestVectors,
382  ::
383  testing::
384  Values(
385  CipherParams{
386  "9a97f65b9b4c721b960a672145fca8d4e32e67f9111ea979ce9c4826806aeee6",
387  "000000003de9c0da2bd7f91e",
388  0,
389  "",
390  "",
391  "5a6e21f4ba6dbee57380e79e79c30def",
392  true,
393  CipherSuite::TLS_CHACHA20_POLY1305_SHA256},
394  CipherParams{
395  "4290bcb154173531f314af57f3be3b5006da371ece272afa1b5dbdd1100a1007",
396  "00000000cd7cf67be39c794a",
397  0,
398  "",
399  "86d09974840bded2a5ca",
400  "e3e446f7ede9a19b62a4dc8dae9a28bb548811461f49f8cec5ae",
401  true,
402  CipherSuite::TLS_CHACHA20_POLY1305_SHA256},
403  CipherParams{
404  "808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f",
405  "070000004041424344454647",
406  0,
407  "",
408  "4c616469657320616e642047656e746c656d656e206f662074686520636c617373206f66202739393a204966204920636f756c64206f6666657220796f75206f6e6c79206f6e652074697020666f7220746865206675747572652c2073756e73637265656e20776f756c642062652069742e",
409  "d31a8d34648e60db7b86afbc53ef7ec2a4aded51296e08fea9e2b5a736ee62d63dbea45e8ca9671282fafb69da92728b1a71de0a9e060b2905d6a5b67ecd3b3692ddbd7f2d778b8c9803aee328091b58fab324e4fad675945585808b4831d7bc3ff4def08e4b7a9de576d26586cec64b61166a23a4681fd59456aea1d29f82477216",
410  true,
411  CipherSuite::TLS_CHACHA20_POLY1305_SHA256},
412  CipherParams{
413  "1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cbc207075c0",
414  "000000000102030405060708",
415  0,
416  "",
417  "496e7465726e65742d4472616674732061726520647261667420646f63756d656e74732076616c696420666f722061206d6178696d756d206f6620736978206d6f6e74687320616e64206d617920626520757064617465642c207265706c616365642c206f72206f62736f6c65746564206279206f7468657220646f63756d656e747320617420616e792074696d652e20497420697320696e617070726f70726961746520746f2075736520496e7465726e65742d447261667473206173207265666572656e6365206d6174657269616c206f7220746f2063697465207468656d206f74686572207468616e206173202fe2809c776f726b20696e2070726f67726573732e2fe2809d",
418  "64a0861575861af460f062c79be643bd5e805cfd345cf389f108670ac76c8cb24c6cfc18755d43eea09ee94e382d26b0bdb7b73c321b0100d4f03b7f355894cf332f830e710b97ce98c8a84abd0b948114ad176e008d33bd60f982b1ff37c8559797a06ef4f0ef61c186324e2b3506383606907b6a7c02b0f9f6157b53c867e4b9166c767b804d46a59b5216cde7a4e99040c5a40433225ee282a1b0a06c523eaf4534d7f83fa1155b0047718cbc546a0d072b04b3564eea1b422273f548271a0bb2316053fa76991955ebd63159434ecebb4e466dae5a1073a6727627097a1049e617d91d361094fa68f0ff77987130305beaba2eda04df997b714d6c6f2c29a6ad5cb4022b02709b6e3570b1acaaf1f24f2a644f01acd12b",
419  true,
420  CipherSuite::TLS_CHACHA20_POLY1305_SHA256},
421  CipherParams{
422  "808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f",
423  "a0a1a2a31011121314151617",
424  0,
425  "",
426  "45000054a6f200004001e778c6336405c000020508005b7a3a080000553bec100007362708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363701020204",
427  "24039428b97f417e3c13753a4f05087b67c352e6a7fab1b982d466ef407ae5c614ee8099d52844eb61aa95dfab4c02f72aa71e7c4c4f64c9befe2facc638e8f3cbec163fac469b502773f6fb94e664da9165b82829f641e07e236714fca1ccb75ab26d5f253185e6",
428  true,
429  CipherSuite::TLS_CHACHA20_POLY1305_SHA256},
430  CipherParams{
431  "808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f",
432  "a0a1a2a31011121314151617",
433  0,
434  "",
435  "0000000c000040010000000a00",
436  "610394701f8d017f7c129248895c5d2b5fa5a4723e5c38e903e5178a10",
437  true,
438  CipherSuite::TLS_CHACHA20_POLY1305_SHA256},
439  CipherParams{
440  "808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f",
441  "a0a1a2a31011121314151617",
442  0,
443  "",
444  "0000000c000040010000000a00",
445  "610394701f8d017f7c129248890c5d2b5fa5a4723e5c38e903e5178a10",
446  false,
447  CipherSuite::TLS_CHACHA20_POLY1305_SHA256},
448  CipherParams{
449  "808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f",
450  "a0a1a2a31011121314151617",
451  0,
452  "",
453  "0000000c000040010000000a00",
454  "610394701f8d017f7c129248",
455  false,
456  CipherSuite::TLS_CHACHA20_POLY1305_SHA256},
457  CipherParams{
458  "808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f",
459  "070000004041424344454647",
460  0,
461  "50515253c0c1c2c3c4c5c6c7",
462  "4c616469657320616e642047656e746c656d656e206f662074686520636c617373206f66202739393a204966204920636f756c64206f6666657220796f75206f6e6c79206f6e652074697020666f7220746865206675747572652c2073756e73637265656e20776f756c642062652069742e",
463  "d31a8d34648e60db7b86afbc53ef7ec2a4aded51296e08fea9e2b5a736ee62d63dbea45e8ca9671282fafb69da92728b1a71de0a9e060b2905d6a5b67ecd3b3692ddbd7f2d778b8c9803aee328091b58fab324e4fad675945585808b4831d7bc3ff4def08e4b7a9de576d26586cec64b61161ae10b594f09e26a7e902ecbd0600691",
464  true,
465  CipherSuite::TLS_CHACHA20_POLY1305_SHA256},
466  CipherParams{"808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f",
467  "070000004041424344454647",
468  0,
469  "51515253c0c1c2c3c4c5c6c7",
470  "4c616469657320616e642047656e746c656d656e206f662074686520636c617373206f66202739393a204966204920636f756c64206f6666657220796f75206f6e6c79206f6e652074697020666f7220746865206675747572652c2073756e73637265656e20776f756c642062652069742e",
471  "d31a8d34648e60db7b86afbc53ef7ec2a4aded51296e08fea9e2b5a736ee62d63dbea45e8ca9671282fafb69da92728b1a71de0a9e060b2905d6a5b67ecd3b3692ddbd7f2d778b8c9803aee328091b58fab324e4fad675945585808b4831d7bc3ff4def08e4b7a9de576d26586cec64b61161ae10b594f09e26a7e902ecbd0600691",
472  false,
473  CipherSuite::TLS_CHACHA20_POLY1305_SHA256}));
474 #endif
475 #if FOLLY_OPENSSL_IS_110 && !defined(OPENSSL_NO_OCB)
476 // Adapted from openssl's evptests.txt AES OCB Test vectors
478  OCBTestVectors,
480  ::testing::Values(
481  CipherParams{"000102030405060708090A0B0C0D0E0F",
482  "000102030405060708090A0B",
483  0,
484  "0001020304050607",
485  "0001020304050607",
486  "92B657130A74B85A16DC76A46D47E1EAD537209E8A96D14E",
487  true,
488  CipherSuite::TLS_AES_128_OCB_SHA256_EXPERIMENTAL},
489  CipherParams{"000102030405060708090A0B0C0D0E0F",
490  "000102030405060708090A0B",
491  0,
492  "0001020304050607",
493  "0001020304050607",
494  "82B657130A74B85A16DC76A46D47E1EAD537209E8A96D14E",
495  false,
496  CipherSuite::TLS_AES_128_OCB_SHA256_EXPERIMENTAL},
497  CipherParams{
498  "000102030405060708090A0B0C0D0E0F",
499  "000102030405060708090A0B",
500  0,
501  "000102030405060708090A0B0C0D0E0F",
502  "000102030405060708090A0B0C0D0E0F",
503  "BEA5E8798DBE7110031C144DA0B26122776C9924D6723A1FC4524532AC3E5BEB",
504  true,
505  CipherSuite::TLS_AES_128_OCB_SHA256_EXPERIMENTAL},
506  CipherParams{
507  "000102030405060708090A0B0C0D0E0F",
508  "000102030405060708090A0B",
509  0,
510  "000102030405060708090A0B0C0D0E0F",
511  "000102030405060708090A0B0C0D0E0F",
512  "CEA5E8798DBE7110031C144DA0B26122776C9924D6723A1FC4524532AC3E5BEB",
513  false,
514  CipherSuite::TLS_AES_128_OCB_SHA256_EXPERIMENTAL},
515  CipherParams{
516  "000102030405060708090A0B0C0D0E0F",
517  "000102030405060708090A0B",
518  0,
519  "000102030405060708090A0B0C0D0E0F1011121314151617",
520  "000102030405060708090A0B0C0D0E0F1011121314151617",
521  "BEA5E8798DBE7110031C144DA0B26122FCFCEE7A2A8D4D485FA94FC3F38820F1DC3F3D1FD4E55E1C",
522  true,
523  CipherSuite::TLS_AES_128_OCB_SHA256_EXPERIMENTAL},
524  CipherParams{
525  "000102030405060708090A0B0C0D0E0F",
526  "000102030405060708090A0B",
527  0,
528  "000102030405060708090A0B0C0D0E0F1011121314151617",
529  "000102030405060708090A0B0C0D0E0F1011121314151617",
530  "BFA5E8798DBE7110031C144DA0B26122FCFCEE7A2A8D4D485FA94FC3F38820F1DC3F3D1FD4E55E1C",
531  false,
532  CipherSuite::TLS_AES_128_OCB_SHA256_EXPERIMENTAL},
533  CipherParams{
534  "000102030405060708090A0B0C0D0E0F",
535  "000102030405060708090A0B",
536  0,
537  "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627",
538  "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627",
539  "BEA5E8798DBE7110031C144DA0B26122CEAAB9B05DF771A657149D53773463CB68C65778B058A635659C623211DEEA0DE30D2C381879F4C8",
540  true,
541  CipherSuite::TLS_AES_128_OCB_SHA256_EXPERIMENTAL}));
542 #endif
543 } // namespace test
544 } // namespace fizz
auto chunks
TEST_P(OpenSSLEVPCipherTest, TestTryDecrypt)
static std::unique_ptr< IOBuf > create(std::size_t capacity)
Definition: IOBuf.cpp:229
std::unique_ptr< folly::IOBuf > toIOBuf(std::string hexData)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
CipherSuite
Definition: Types.h:153
std::unique_ptr< folly::IOBuf > key
Definition: Aead.h:17
std::unique_ptr< folly::IOBuf > iv
Definition: Aead.h:18
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
std::unique_ptr< folly::IOBuf > callEncrypt(std::unique_ptr< Aead > &cipher, const CipherParams &params, std::unique_ptr< IOBuf > plaintext=nullptr, std::unique_ptr< IOBuf > aad=nullptr)
#define EXPECT_GE(val1, val2)
Definition: gtest.h:1932
void callDecrypt(std::unique_ptr< Aead > &cipher, const CipherParams &params, std::unique_ptr< IOBuf > ciphertext=nullptr, std::unique_ptr< IOBuf > aad=nullptr)
CipherSuite cipher
INSTANTIATE_TEST_CASE_P(AESGCM256TestVectors, OpenSSLEVPCipherTest,::testing::Values(CipherParams{"E3C08A8F06C6E3AD95A70557B23F75483CE33021A9C72B7025666204C69C0B72","12153524C0895E81B2C28465", 0,"D609B1F056637A0D46DF998D88E52E00B2C2846512153524C0895E81","08000F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A0002","E2006EB42F5277022D9B19925BC419D7A592666C925FE2EF718EB4E308EFEAA7C5273B394118860A5BE2A97F56AB78365CA597CDBB3EDB8D1A1151EA0AF7B436", true, CipherSuite::TLS_AES_256_GCM_SHA384}, CipherParams{"E3C08A8F06C6E3AD95A70557B23F75483CE33021A9C72B7025666204C69C0B72","12153524C0895E81B2C28465", 0,"D609B1F056637A0D46DF998D88E52E00B2C2846512153524C0895E81","08000F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A0002","E2006EB42F5277022D9B19925BC419D7A592666C925FE2EF718EB4E308EFEAA7C5273B394118860A5BE2A97F56AB78365CA597CDBB3EDB8D1A1151EA1AF7B436", false, CipherSuite::TLS_AES_256_GCM_SHA384}))
constexpr Params params[]
Definition: Actions.h:16
void prependChain(std::unique_ptr< IOBuf > &&iobuf)
Definition: IOBuf.cpp:509
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
std::unique_ptr< Aead > getCipher(const CipherParams &params)
const char * string
Definition: Conv.cpp:212
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
constexpr size_t kHeadroom
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
std::unique_ptr< IOBuf > chunkIOBuf(std::unique_ptr< IOBuf > input, size_t chunks, BufCreator creator)
Definition: TestUtil.cpp:31