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

Side by Side Diff: crypto/openpgp_symmetric_encryption.cc

Issue 11186004: Use the NSS internal key slot for all temporary key operations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "crypto/openpgp_symmetric_encryption.h" 5 #include "crypto/openpgp_symmetric_encryption.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <sechash.h> 9 #include <sechash.h>
10 #include <cryptohi.h> 10 #include <cryptohi.h>
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 done += todo; 143 done += todo;
144 } 144 }
145 145
146 HASH_Destroy(hash_context); 146 HASH_Destroy(hash_context);
147 } 147 }
148 148
149 // CreateAESContext sets up |out_key| to be an AES context, with the given key, 149 // CreateAESContext sets up |out_key| to be an AES context, with the given key,
150 // in ECB mode and with no IV. 150 // in ECB mode and with no IV.
151 bool CreateAESContext(const uint8* key, unsigned key_len, 151 bool CreateAESContext(const uint8* key, unsigned key_len,
152 ScopedPK11Context* out_decryption_context) { 152 ScopedPK11Context* out_decryption_context) {
153 ScopedPK11Slot slot(PK11_GetBestSlot(CKM_AES_ECB, NULL)); 153 ScopedPK11Slot slot(PK11_GetInternalSlot());
154 if (!slot.get()) 154 if (!slot.get())
155 return false; 155 return false;
156 SECItem key_item; 156 SECItem key_item;
157 key_item.type = siBuffer; 157 key_item.type = siBuffer;
158 key_item.data = const_cast<uint8*>(key); 158 key_item.data = const_cast<uint8*>(key);
159 key_item.len = key_len; 159 key_item.len = key_len;
160 ScopedPK11SymKey pk11_key(PK11_ImportSymKey( 160 ScopedPK11SymKey pk11_key(PK11_ImportSymKey(
161 slot.get(), CKM_AES_ECB, PK11_OriginUnwrap, CKA_ENCRYPT, &key_item, 161 slot.get(), CKM_AES_ECB, PK11_OriginUnwrap, CKA_ENCRYPT, &key_item,
162 NULL)); 162 NULL));
163 if (!pk11_key.get()) 163 if (!pk11_key.get())
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 base::StringPiece plaintext, 786 base::StringPiece plaintext,
787 base::StringPiece passphrase) { 787 base::StringPiece passphrase) {
788 EnsureNSSInit(); 788 EnsureNSSInit();
789 789
790 Encrypter::ByteString b = 790 Encrypter::ByteString b =
791 Encrypter::Encrypt(plaintext, passphrase); 791 Encrypter::Encrypt(plaintext, passphrase);
792 return std::string(reinterpret_cast<const char*>(b.data()), b.size()); 792 return std::string(reinterpret_cast<const char*>(b.data()), b.size());
793 } 793 }
794 794
795 } // namespace crypto 795 } // namespace crypto
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698