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

Side by Side Diff: crypto/openpgp_symmetric_encryption_openssl.cc

Issue 7253038: Fixes for OpenSSL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 9 years, 5 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <vector> 7 #include <vector>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 9
10 #include <openssl/evp.h> 10 #include <openssl/evp.h>
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 base::StringPiece salt, 100 base::StringPiece salt,
101 uint32 count, 101 uint32 count,
102 uint8 *out_key) { 102 uint8 *out_key) {
103 const std::string combined = salt.as_string() + passphrase.as_string(); 103 const std::string combined = salt.as_string() + passphrase.as_string();
104 const size_t combined_len = combined.size(); 104 const size_t combined_len = combined.size();
105 105
106 uint32 done = 0; 106 uint32 done = 0;
107 uint8 zero[1] = {0}; 107 uint8 zero[1] = {0};
108 108
109 EVP_MD_CTX ctx; 109 EVP_MD_CTX ctx;
110 EVP_MD_CTX_init(&context); 110 EVP_MD_CTX_init(&ctx);
111 111
112 for (uint32 i = 0; done < cipher_key_length; i++) { 112 for (uint32 i = 0; done < cipher_key_length; i++) {
113 CHECK_EQ(EVP_DigestInit_ex(&ctx, hash_function, NULL), 1); 113 CHECK_EQ(EVP_DigestInit_ex(&ctx, hash_function, NULL), 1);
114 114
115 for (uint32 j = 0; j < i; j++) 115 for (uint32 j = 0; j < i; j++)
116 EVP_DigestUpdate(&ctx, zero, sizeof(zero)); 116 EVP_DigestUpdate(&ctx, zero, sizeof(zero));
117 117
118 uint32 written = 0; 118 uint32 written = 0;
119 while (written < count) { 119 while (written < count) {
120 if (written + combined_len > count) { 120 if (written + combined_len > count) {
(...skipping 10 matching lines...) Expand all
131 uint8 hash[EVP_MAX_MD_SIZE]; 131 uint8 hash[EVP_MAX_MD_SIZE];
132 CHECK_EQ(EVP_DigestFinal_ex(&ctx, hash, &num_hash_bytes), 1); 132 CHECK_EQ(EVP_DigestFinal_ex(&ctx, hash, &num_hash_bytes), 1);
133 133
134 uint32 todo = cipher_key_length - done; 134 uint32 todo = cipher_key_length - done;
135 if (todo > num_hash_bytes) 135 if (todo > num_hash_bytes)
136 todo = num_hash_bytes; 136 todo = num_hash_bytes;
137 memcpy(out_key + done, hash, todo); 137 memcpy(out_key + done, hash, todo);
138 done += todo; 138 done += todo;
139 } 139 }
140 140
141 EVP_MD_CTX_cleanup(&context); 141 EVP_MD_CTX_cleanup(&ctx);
wtc 2011/07/01 16:41:17 I think this file has been removed.
bulach 2011/07/05 10:06:55 looks like the deletion was reverted.. :)
142 } 142 }
143 143
144 // These constants are the tag numbers for the various packet types that we 144 // These constants are the tag numbers for the various packet types that we
145 // use. 145 // use.
146 static const uint32 kSymmetricKeyEncryptedTag = 3; 146 static const uint32 kSymmetricKeyEncryptedTag = 3;
147 static const uint32 kSymmetricallyEncryptedTag = 18; 147 static const uint32 kSymmetricallyEncryptedTag = 18;
148 static const uint32 kCompressedTag = 8; 148 static const uint32 kCompressedTag = 8;
149 static const uint32 kLiteralDataTag = 11; 149 static const uint32 kLiteralDataTag = 11;
150 150
151 class Decrypter { 151 class Decrypter {
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 // static 698 // static
699 std::string OpenPGPSymmetricEncrytion::Encrypt( 699 std::string OpenPGPSymmetricEncrytion::Encrypt(
700 base::StringPiece plaintext, 700 base::StringPiece plaintext,
701 base::StringPiece passphrase) { 701 base::StringPiece passphrase) {
702 Encrypter::ByteString b = 702 Encrypter::ByteString b =
703 Encrypter::Encrypt(plaintext, passphrase); 703 Encrypter::Encrypt(plaintext, passphrase);
704 return std::string(reinterpret_cast<const char*>(b.data()), b.size()); 704 return std::string(reinterpret_cast<const char*>(b.data()), b.size());
705 } 705 }
706 706
707 } // namespace crypto 707 } // namespace crypto
OLDNEW
« no previous file with comments | « no previous file | net/socket/ssl_client_socket_openssl.h » ('j') | net/socket/ssl_client_socket_openssl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698