LEFT | RIGHT |
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 /* vim: set ts=2 et sw=2 tw=80: */ | 2 /* vim: set ts=2 et sw=2 tw=80: */ |
3 /* This Source Code Form is subject to the terms of the Mozilla Public | 3 /* This Source Code Form is subject to the terms of the Mozilla Public |
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, | 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ | 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | 6 |
7 #include "nss.h" | 7 #include "nss.h" |
8 #include "pk11pub.h" | 8 #include "pk11pub.h" |
9 #include "sechash.h" | 9 #include "sechash.h" |
10 #include <memory> | 10 #include <memory> |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 public: | 116 public: |
117 void EncryptDecrypt(PK11SymKey* symKey, | 117 void EncryptDecrypt(PK11SymKey* symKey, |
118 const uint8_t* data, size_t data_len, | 118 const uint8_t* data, size_t data_len, |
119 const uint8_t* aad, size_t aad_len, | 119 const uint8_t* aad, size_t aad_len, |
120 const uint8_t* iv, size_t iv_len, | 120 const uint8_t* iv, size_t iv_len, |
121 const uint8_t* ct = nullptr, size_t ct_len = 0) | 121 const uint8_t* ct = nullptr, size_t ct_len = 0) |
122 { | 122 { |
123 // Prepare AEAD params. | 123 // Prepare AEAD params. |
124 CK_NSS_AEAD_PARAMS aead_params; | 124 CK_NSS_AEAD_PARAMS aead_params; |
125 aead_params.pNonce = toUcharPtr(iv); | 125 aead_params.pNonce = toUcharPtr(iv); |
126 aead_params.ulIvLen = iv_len; | 126 aead_params.ulNonceLen = iv_len; |
127 aead_params.pAAD = toUcharPtr(aad); | 127 aead_params.pAAD = toUcharPtr(aad); |
128 aead_params.ulAADLen = aad_len; | 128 aead_params.ulAADLen = aad_len; |
129 aead_params.ulTagLen = 16; | 129 aead_params.ulTagLen = 16; |
130 | 130 |
131 SECItem params = { siBuffer, reinterpret_cast<unsigned char*>(&aead_params), | 131 SECItem params = { siBuffer, reinterpret_cast<unsigned char*>(&aead_params), |
132 sizeof(aead_params) }; | 132 sizeof(aead_params) }; |
133 | 133 |
134 // Encrypt. | 134 // Encrypt. |
135 unsigned int outputLen = 0; | 135 unsigned int outputLen = 0; |
136 std::vector<uint8_t> output(data_len + aead_params.ulTagLen); | 136 std::vector<uint8_t> output(data_len + aead_params.ulTagLen); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 TEST_F(Pkcs11ChaCha20Poly1305Test, CheckTestVector1) { | 268 TEST_F(Pkcs11ChaCha20Poly1305Test, CheckTestVector1) { |
269 ENCRYPT_DECRYPT(kTestVector1); | 269 ENCRYPT_DECRYPT(kTestVector1); |
270 } | 270 } |
271 | 271 |
272 TEST_F(Pkcs11ChaCha20Poly1305Test, CheckTestVector2) { | 272 TEST_F(Pkcs11ChaCha20Poly1305Test, CheckTestVector2) { |
273 ENCRYPT_DECRYPT(kTestVector2); | 273 ENCRYPT_DECRYPT(kTestVector2); |
274 } | 274 } |
275 | 275 |
276 } // namespace nss_test | 276 } // namespace nss_test |
277 | 277 |
LEFT | RIGHT |