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

Unified Diff: chrome/browser/autofill/crypto/rc4_decryptor.h

Issue 12434004: Move remaining Autofill code to //components/autofill. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix long lines Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/autofill/credit_card_unittest.cc ('k') | chrome/browser/autofill/data_driven_test.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autofill/crypto/rc4_decryptor.h
diff --git a/chrome/browser/autofill/crypto/rc4_decryptor.h b/chrome/browser/autofill/crypto/rc4_decryptor.h
deleted file mode 100644
index 462e0868699b6bb574b28e126633c5620ad1ff80..0000000000000000000000000000000000000000
--- a/chrome/browser/autofill/crypto/rc4_decryptor.h
+++ /dev/null
@@ -1,103 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_AUTOFILL_CRYPTO_RC4_DECRYPTOR_H_
-#define CHROME_BROWSER_AUTOFILL_CRYPTO_RC4_DECRYPTOR_H_
-
-#include <string>
-#include "base/basictypes.h"
-#include "base/memory/scoped_ptr.h"
-
-// This is modified RC4 decryption used for import of Toolbar autofill data
-// only. The difference from the Crypto Api implementation is twofold:
-// First, it uses a non-standard key size (160 bit), not supported by Microsoft
-// (it supports only 40 and 128 bit for RC4). Second, it codes 128 words with
-// value 0x0020 at the beginning of the code to enhance security.
-// This class used in chrome/browser/autofill/autofill_ie_toolbar_import_win.cc.
-// This class should not be used anywhere else!!!
-class RC4Decryptor {
- public:
- explicit RC4Decryptor(wchar_t const* password) {
- PrepareKey(reinterpret_cast<const uint8 *>(password),
- wcslen(password) * sizeof(wchar_t));
- std::wstring data;
- // First 128 bytes should be spaces.
- data.resize(128, L' ');
- Run(data.c_str());
- }
-
- // Run the algorithm
- std::wstring Run(const std::wstring& data) {
- int data_size = data.length() * sizeof(wchar_t);
-
- scoped_array<wchar_t> buffer(new wchar_t[data.length() + 1]);
- memset(buffer.get(), 0, (data.length() + 1) * sizeof(wchar_t));
- memcpy(buffer.get(), data.c_str(), data_size);
-
- RunInternal(reinterpret_cast<uint8 *>(buffer.get()), data_size);
-
- std::wstring result(buffer.get());
-
- // Clear the memory
- memset(buffer.get(), 0, data_size);
- return result;
- }
-
- private:
- static const int kKeyDataSize = 256;
- struct Rc4Key {
- uint8 state[kKeyDataSize];
- uint8 x;
- uint8 y;
- };
-
- void SwapByte(uint8* byte1, uint8* byte2) {
- uint8 temp = *byte1;
- *byte1 = *byte2;
- *byte2 = temp;
- }
-
- void PrepareKey(const uint8 *key_data, int key_data_len) {
- uint8 index1 = 0;
- uint8 index2 = 0;
- uint8* state;
- short counter;
-
- state = &key_.state[0];
- for (counter = 0; counter < kKeyDataSize; ++counter)
- state[counter] = static_cast<uint8>(counter);
-
- key_.x = key_.y = 0;
-
- for (counter = 0; counter < kKeyDataSize; counter++) {
- index2 = (key_data[index1] + state[counter] + index2) % kKeyDataSize;
- SwapByte(&state[counter], &state[index2]);
- index1 = (index1 + 1) % key_data_len;
- }
- }
-
- void RunInternal(uint8 *buffer, int buffer_len) {
- uint8 x, y;
- uint8 xor_index = 0;
- uint8* state;
- int counter;
-
- x = key_.x;
- y = key_.y;
- state = &key_.state[0];
- for (counter = 0; counter < buffer_len; ++counter) {
- x = (x + 1) % kKeyDataSize;
- y = (state[x] + y) % kKeyDataSize;
- SwapByte(&state[x], &state[y]);
- xor_index = (state[x] + state[y]) % kKeyDataSize;
- buffer[counter] ^= state[xor_index];
- }
- key_.x = x;
- key_.y = y;
- }
-
- Rc4Key key_;
-};
-
-#endif // CHROME_BROWSER_AUTOFILL_CRYPTO_RC4_DECRYPTOR_H_
« no previous file with comments | « chrome/browser/autofill/credit_card_unittest.cc ('k') | chrome/browser/autofill/data_driven_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698