| 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 <cryptohi.h> | 5 #include <cryptohi.h> |
| 6 | 6 |
| 7 #include "base/numerics/safe_math.h" | 7 #include "base/numerics/safe_math.h" |
| 8 #include "base/stl_util.h" |
| 8 #include "content/child/webcrypto/crypto_data.h" | 9 #include "content/child/webcrypto/crypto_data.h" |
| 9 #include "content/child/webcrypto/nss/aes_key_nss.h" | 10 #include "content/child/webcrypto/nss/aes_key_nss.h" |
| 10 #include "content/child/webcrypto/nss/key_nss.h" | 11 #include "content/child/webcrypto/nss/key_nss.h" |
| 11 #include "content/child/webcrypto/nss/util_nss.h" | 12 #include "content/child/webcrypto/nss/util_nss.h" |
| 12 #include "content/child/webcrypto/status.h" | 13 #include "content/child/webcrypto/status.h" |
| 13 #include "content/child/webcrypto/webcrypto_util.h" | 14 #include "content/child/webcrypto/webcrypto_util.h" |
| 14 #include "crypto/scoped_nss_types.h" | 15 #include "crypto/scoped_nss_types.h" |
| 15 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 16 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
| 16 | 17 |
| 17 namespace content { | 18 namespace content { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // https://bugzilla.mozilla.com/show_bug.cgi?id=921687. | 66 // https://bugzilla.mozilla.com/show_bug.cgi?id=921687. |
| 66 if (operation == CKA_DECRYPT && | 67 if (operation == CKA_DECRYPT && |
| 67 (data.byte_length() == 0 || (data.byte_length() % AES_BLOCK_SIZE != 0))) { | 68 (data.byte_length() == 0 || (data.byte_length() % AES_BLOCK_SIZE != 0))) { |
| 68 return Status::OperationError(); | 69 return Status::OperationError(); |
| 69 } | 70 } |
| 70 | 71 |
| 71 // TODO(eroman): Refine the output buffer size. It can be computed exactly for | 72 // TODO(eroman): Refine the output buffer size. It can be computed exactly for |
| 72 // encryption, and can be smaller for decryption. | 73 // encryption, and can be smaller for decryption. |
| 73 buffer->resize(output_max_len.ValueOrDie()); | 74 buffer->resize(output_max_len.ValueOrDie()); |
| 74 | 75 |
| 75 unsigned char* buffer_data = Uint8VectorStart(buffer); | 76 unsigned char* buffer_data = vector_as_array(buffer); |
| 76 | 77 |
| 77 int output_len; | 78 int output_len; |
| 78 if (SECSuccess != PK11_CipherOp(context.get(), | 79 if (SECSuccess != PK11_CipherOp(context.get(), |
| 79 buffer_data, | 80 buffer_data, |
| 80 &output_len, | 81 &output_len, |
| 81 buffer->size(), | 82 buffer->size(), |
| 82 data.bytes(), | 83 data.bytes(), |
| 83 data.byte_length())) { | 84 data.byte_length())) { |
| 84 return Status::OperationError(); | 85 return Status::OperationError(); |
| 85 } | 86 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 119 |
| 119 } // namespace | 120 } // namespace |
| 120 | 121 |
| 121 AlgorithmImplementation* CreatePlatformAesCbcImplementation() { | 122 AlgorithmImplementation* CreatePlatformAesCbcImplementation() { |
| 122 return new AesCbcImplementation; | 123 return new AesCbcImplementation; |
| 123 } | 124 } |
| 124 | 125 |
| 125 } // namespace webcrypto | 126 } // namespace webcrypto |
| 126 | 127 |
| 127 } // namespace content | 128 } // namespace content |
| OLD | NEW |