Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: base/crypto/encryptor_nss.cc

Issue 4777001: Implements encryptor_openssl.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix linux & win Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/crypto/encryptor.h ('k') | base/crypto/encryptor_openssl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/crypto/encryptor.h" 5 #include "base/crypto/encryptor.h"
6 6
7 #include <cryptohi.h> 7 #include <cryptohi.h>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/crypto/symmetric_key.h" 10 #include "base/crypto/symmetric_key.h"
(...skipping 30 matching lines...) Expand all
41 iv_item.len = iv.size(); 41 iv_item.len = iv.size();
42 42
43 param_.reset(PK11_ParamFromIV(CKM_AES_CBC_PAD, &iv_item)); 43 param_.reset(PK11_ParamFromIV(CKM_AES_CBC_PAD, &iv_item));
44 if (!param_.get()) 44 if (!param_.get())
45 return false; 45 return false;
46 46
47 return true; 47 return true;
48 } 48 }
49 49
50 bool Encryptor::Encrypt(const std::string& plaintext, std::string* ciphertext) { 50 bool Encryptor::Encrypt(const std::string& plaintext, std::string* ciphertext) {
51 if (plaintext.size() == 0)
52 return false;
53
54 ScopedPK11Context context(PK11_CreateContextBySymKey(CKM_AES_CBC_PAD, 51 ScopedPK11Context context(PK11_CreateContextBySymKey(CKM_AES_CBC_PAD,
55 CKA_ENCRYPT, 52 CKA_ENCRYPT,
56 key_->key(), 53 key_->key(),
57 param_.get())); 54 param_.get()));
58 if (!context.get()) 55 if (!context.get())
59 return false; 56 return false;
60 57
61 size_t ciphertext_len = plaintext.size() + AES_BLOCK_SIZE; 58 size_t ciphertext_len = plaintext.size() + AES_BLOCK_SIZE;
62 std::vector<unsigned char> buffer(ciphertext_len); 59 std::vector<unsigned char> buffer(ciphertext_len);
63 60
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 plaintext_len - op_len); 114 plaintext_len - op_len);
118 if (SECSuccess != rv) 115 if (SECSuccess != rv)
119 return false; 116 return false;
120 117
121 plaintext->assign(reinterpret_cast<char *>(&buffer[0]), 118 plaintext->assign(reinterpret_cast<char *>(&buffer[0]),
122 op_len + digest_len); 119 op_len + digest_len);
123 return true; 120 return true;
124 } 121 }
125 122
126 } // namespace base 123 } // namespace base
OLDNEW
« no previous file with comments | « base/crypto/encryptor.h ('k') | base/crypto/encryptor_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698