OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/crypto/chacha20_poly1305_decrypter.h" | 5 #include "net/quic/crypto/chacha20_poly1305_decrypter.h" |
6 | 6 |
7 #include <pk11pub.h> | 7 #include <pk11pub.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 | 10 |
(...skipping 18 matching lines...) Loading... |
29 NOTIMPLEMENTED(); | 29 NOTIMPLEMENTED(); |
30 } | 30 } |
31 | 31 |
32 ChaCha20Poly1305Decrypter::~ChaCha20Poly1305Decrypter() {} | 32 ChaCha20Poly1305Decrypter::~ChaCha20Poly1305Decrypter() {} |
33 | 33 |
34 // static | 34 // static |
35 bool ChaCha20Poly1305Decrypter::IsSupported() { | 35 bool ChaCha20Poly1305Decrypter::IsSupported() { |
36 return false; | 36 return false; |
37 } | 37 } |
38 | 38 |
39 void ChaCha20Poly1305Decrypter::FillAeadParams(StringPiece nonce, | 39 void ChaCha20Poly1305Decrypter::FillAeadParams( |
40 StringPiece associated_data, | 40 StringPiece nonce, |
41 size_t auth_tag_size, | 41 const StringPiece& associated_data, |
42 AeadParams* aead_params) const { | 42 size_t auth_tag_size, |
| 43 AeadParams* aead_params) const { |
43 NOTIMPLEMENTED(); | 44 NOTIMPLEMENTED(); |
44 } | 45 } |
45 | 46 |
46 #else // defined(USE_NSS) | 47 #else // defined(USE_NSS) |
47 | 48 |
48 ChaCha20Poly1305Decrypter::ChaCha20Poly1305Decrypter() | 49 ChaCha20Poly1305Decrypter::ChaCha20Poly1305Decrypter() |
49 : AeadBaseDecrypter(CKM_NSS_CHACHA20_POLY1305, PK11_Decrypt, kKeySize, | 50 : AeadBaseDecrypter(CKM_NSS_CHACHA20_POLY1305, PK11_Decrypt, kKeySize, |
50 kAuthTagSize, kNoncePrefixSize) { | 51 kAuthTagSize, kNoncePrefixSize) { |
51 static_assert(kKeySize <= kMaxKeySize, "key size too big"); | 52 static_assert(kKeySize <= kMaxKeySize, "key size too big"); |
52 static_assert(kNoncePrefixSize <= kMaxNoncePrefixSize, | 53 static_assert(kNoncePrefixSize <= kMaxNoncePrefixSize, |
53 "nonce prefix size too big"); | 54 "nonce prefix size too big"); |
54 } | 55 } |
55 | 56 |
56 ChaCha20Poly1305Decrypter::~ChaCha20Poly1305Decrypter() {} | 57 ChaCha20Poly1305Decrypter::~ChaCha20Poly1305Decrypter() {} |
57 | 58 |
58 // static | 59 // static |
59 bool ChaCha20Poly1305Decrypter::IsSupported() { | 60 bool ChaCha20Poly1305Decrypter::IsSupported() { |
60 return true; | 61 return true; |
61 } | 62 } |
62 | 63 |
63 void ChaCha20Poly1305Decrypter::FillAeadParams(StringPiece nonce, | 64 void ChaCha20Poly1305Decrypter::FillAeadParams( |
64 StringPiece associated_data, | 65 StringPiece nonce, |
65 size_t auth_tag_size, | 66 const StringPiece& associated_data, |
66 AeadParams* aead_params) const { | 67 size_t auth_tag_size, |
| 68 AeadParams* aead_params) const { |
67 aead_params->len = sizeof(aead_params->data.nss_aead_params); | 69 aead_params->len = sizeof(aead_params->data.nss_aead_params); |
68 CK_NSS_AEAD_PARAMS* nss_aead_params = &aead_params->data.nss_aead_params; | 70 CK_NSS_AEAD_PARAMS* nss_aead_params = &aead_params->data.nss_aead_params; |
69 nss_aead_params->pIv = | 71 nss_aead_params->pIv = |
70 reinterpret_cast<CK_BYTE*>(const_cast<char*>(nonce.data())); | 72 reinterpret_cast<CK_BYTE*>(const_cast<char*>(nonce.data())); |
71 nss_aead_params->ulIvLen = nonce.size(); | 73 nss_aead_params->ulIvLen = nonce.size(); |
72 nss_aead_params->pAAD = | 74 nss_aead_params->pAAD = |
73 reinterpret_cast<CK_BYTE*>(const_cast<char*>(associated_data.data())); | 75 reinterpret_cast<CK_BYTE*>(const_cast<char*>(associated_data.data())); |
74 nss_aead_params->ulAADLen = associated_data.size(); | 76 nss_aead_params->ulAADLen = associated_data.size(); |
75 nss_aead_params->ulTagLen = auth_tag_size; | 77 nss_aead_params->ulTagLen = auth_tag_size; |
76 } | 78 } |
77 | 79 |
78 #endif // defined(USE_NSS) | 80 #endif // defined(USE_NSS) |
79 | 81 |
80 } // namespace net | 82 } // namespace net |
OLD | NEW |