Commit 22743cdf authored by rsleevi@chromium.org's avatar rsleevi@chromium.org

Remove unused bits implementing parts of RFC 4880

BUG=none
R=wtc@chromium.org, brettw@chromium.org

Review URL: https://codereview.chromium.org/253643002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266475 0039d316-1c4b-4281-b951-d872f2087c98
parent 66068e6e
......@@ -49,8 +49,6 @@ component("crypto") {
"nss_util.cc",
"nss_util.h",
"nss_util_internal.h",
"openpgp_symmetric_encryption.cc",
"openpgp_symmetric_encryption.h",
"openssl_util.cc",
"openssl_util.h",
"p224.cc",
......@@ -105,12 +103,6 @@ component("crypto") {
]
}
if (use_openssl || !is_linux) {
sources -= [
"openpgp_symmetric_encryption.cc",
"openpgp_symmetric_encryption.h",
]
}
if (!is_mac) {
sources -= [
"cssm_init.cc",
......@@ -218,21 +210,17 @@ test("crypto_unittests") {
"signature_creator_unittest.cc",
"signature_verifier_unittest.cc",
"symmetric_key_unittest.cc",
"openpgp_symmetric_encryption_unittest.cc",
]
if (use_openssl) {
sources -= [
"nss_util_unittest.cc",
"openpgp_symmetric_encryption_unittest.cc",
"rsa_private_key_nss_unittest.cc",
]
}
if (use_openssl || !is_linux) {
sources -= [
"rsa_private_key_nss_unittest.cc",
"openpgp_symmetric_encryption_unittest.cc",
]
}
......
......@@ -41,8 +41,6 @@
}, { # os_posix != 1 or OS == "mac" or OS == "ios" or OS == "android"
'sources!': [
'hmac_win.cc',
'openpgp_symmetric_encryption.cc',
'openpgp_symmetric_encryption.h',
'symmetric_key_win.cc',
],
}],
......@@ -113,7 +111,6 @@
'hmac_nss.cc',
'nss_util.cc',
'nss_util.h',
'openpgp_symmetric_encryption.cc',
'rsa_private_key_nss.cc',
'secure_hash_default.cc',
'signature_creator_nss.cc',
......@@ -171,7 +168,6 @@
'signature_creator_unittest.cc',
'signature_verifier_unittest.cc',
'symmetric_key_unittest.cc',
'openpgp_symmetric_encryption_unittest.cc',
],
'dependencies': [
'crypto',
......@@ -198,7 +194,6 @@
}, { # os_posix != 1 or OS == "mac" or OS == "android" or OS == "ios"
'sources!': [
'rsa_private_key_nss_unittest.cc',
'openpgp_symmetric_encryption_unittest.cc',
]
}],
[ 'use_openssl == 0 and (OS == "mac" or OS == "ios" or OS == "win")', {
......@@ -213,7 +208,6 @@
[ 'use_openssl==1', {
'sources!': [
'nss_util_unittest.cc',
'openpgp_symmetric_encryption_unittest.cc',
'rsa_private_key_nss_unittest.cc',
],
}],
......
......@@ -68,8 +68,6 @@
'nss_util.cc',
'nss_util.h',
'nss_util_internal.h',
'openpgp_symmetric_encryption.cc',
'openpgp_symmetric_encryption.h',
'openssl_util.cc',
'openssl_util.h',
'p224.cc',
......
......@@ -36,7 +36,6 @@
['exclude', '_nss\.(cc|h)$'],
['exclude', '^(mock_)?apple_'],
['exclude', '^capi_'],
['exclude', '^openpgp_'],
['exclude', '^cssm_'],
['exclude', '^nss_'],
['exclude', '^mac_'],
......
This diff is collapsed.
// Copyright (c) 2012 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 CRYPTO_OPENPGP_SYMMETRIC_ENCRYPTION_H_
#define CRYPTO_OPENPGP_SYMMETRIC_ENCRYPTION_H_
#include <string>
#include "base/strings/string_piece.h"
#include "crypto/crypto_export.h"
namespace crypto {
// OpenPGPSymmetricEncrytion implements enough of RFC 4880 to read and write
// uncompressed, symmetrically encrypted data. You can create ciphertext
// compatable with this code from the command line with:
// gpg --compress-algo=NONE --cipher-algo=AES -c
//
// Likewise, the output of this can be decrypted on the command line with:
// gpg < input
class CRYPTO_EXPORT OpenPGPSymmetricEncrytion {
public:
enum Result {
OK,
UNKNOWN_CIPHER, // you forgot to pass --cipher-algo=AES to gpg
UNKNOWN_HASH,
NOT_SYMMETRICALLY_ENCRYPTED, // it's OpenPGP data, but not correct form
COMPRESSED, // you forgot to pass --compress-algo=NONE
PARSE_ERROR, // it's not OpenPGP data.
INTERNAL_ERROR,
};
static Result Decrypt(base::StringPiece encrypted,
base::StringPiece passphrase,
std::string *out);
static std::string Encrypt(base::StringPiece plaintext,
base::StringPiece passphrase);
};
} // namespace crypto
#endif // CRYPTO_OPENPGP_SYMMETRIC_ENCRYPTION_H_
// 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.
#include "crypto/openpgp_symmetric_encryption.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace crypto {
// These test vectors were created by hand using either GPG or the Go OpenPGP
// library.
// AES-128, GPG
static const uint8 kTestMessage1[] = {
0x8c, 0x0d, 0x04, 0x07, 0x03, 0x02, 0x69, 0x24, 0xaf, 0xbf, 0x0b, 0x31, 0x98,
0x6d, 0x60, 0xd2, 0x3d, 0x01, 0xc4, 0x29, 0xab, 0xec, 0x1b, 0xdf, 0xfa, 0x90,
0x86, 0x92, 0x94, 0xc7, 0xa5, 0xe7, 0xd8, 0x80, 0x0a, 0x55, 0x3e, 0xbd, 0x10,
0xef, 0x40, 0xfe, 0xb7, 0x39, 0x83, 0x4e, 0x5e, 0x77, 0x9d, 0x57, 0x94, 0xb6,
0xe4, 0x59, 0xa7, 0x32, 0x76, 0x22, 0x48, 0xed, 0x37, 0xe8, 0x6f, 0xf9, 0x80,
0x04, 0xa1, 0xe4, 0xbf, 0x40, 0xa6, 0x9b, 0xd1, 0x3e, 0xba, 0xaa, 0x52, 0xd0,
};
// AES-256, GPG
static const uint8 kTestMessage2[] = {
0x8c, 0x0d, 0x04, 0x09, 0x03, 0x02, 0xd6, 0xb0, 0x34, 0xa0, 0xb8, 0x6c, 0x15,
0xb8, 0x60, 0xd2, 0x3d, 0x01, 0x97, 0xe4, 0x46, 0x56, 0xc5, 0xc9, 0xc7, 0x81,
0xd1, 0x09, 0xf3, 0xa0, 0x5d, 0x3b, 0xa7, 0xe3, 0x68, 0xb4, 0x19, 0xd2, 0x76,
0x83, 0x38, 0x13, 0x98, 0xb8, 0xaf, 0x54, 0x51, 0x52, 0xbb, 0xc5, 0x7d, 0x8a,
0x70, 0x66, 0x40, 0x0b, 0xb5, 0x92, 0xc3, 0xd3, 0x51, 0x63, 0x5d, 0x99, 0x9b,
0x96, 0x82, 0xe1, 0xfe, 0xac, 0xa8, 0xa5, 0x87, 0x8b, 0x3f, 0xd1, 0x90, 0x70,
};
// AES-128, Go
static const uint8 kTestMessage3[] = {
0xc3, 0x1e, 0x04, 0x07, 0x03, 0x02, 0x74, 0x1e, 0x2d, 0x7d, 0x2e, 0xdf, 0x20,
0xdb, 0x60, 0xb1, 0x22, 0xca, 0x39, 0x74, 0x2f, 0xe8, 0x2f, 0x09, 0xf8, 0xa4,
0x13, 0x76, 0x14, 0x65, 0x6e, 0xb9, 0xd2, 0xe0, 0x01, 0xe4, 0x40, 0x83, 0x90,
0x3c, 0x76, 0xac, 0x23, 0x3e, 0xd2, 0xb0, 0xb2, 0x1c, 0x9d, 0x24, 0xcb, 0x7b,
0xe1, 0x0c, 0x6b, 0xe0, 0x86, 0xe0, 0x22, 0xe1, 0xf2, 0xcb, 0xe0, 0xf3, 0xe2,
0xbf, 0xdd, 0x89, 0xda, 0xe0, 0x83, 0xe3, 0xd9, 0x34, 0xf9, 0xaa, 0x17, 0x96,
0x6a, 0x28, 0xe0, 0xca, 0xe2, 0x78, 0xca, 0x0e, 0x7d, 0xe0, 0xeb, 0xe4, 0xca,
0xe6, 0xf0, 0x90, 0x4f, 0x22, 0x91, 0xf9, 0xb2, 0xbb, 0x19, 0x0b, 0x45, 0xc0,
0x16, 0x9e, 0xe2, 0xdb, 0x30, 0xad, 0xbb, 0xe1, 0xb8, 0x12, 0x00,
};
// AES-128, salted S2K, GPG
static const uint8 kTestMessage4[] = {
0x8c, 0x0c, 0x04, 0x07, 0x01, 0x02, 0xf8, 0x42, 0x78, 0x07, 0x04, 0xaa, 0x54,
0xcc, 0xd2, 0x3d, 0x01, 0xcf, 0xb7, 0x30, 0xe1, 0xed, 0xb2, 0x53, 0x6e, 0x4a,
0xbc, 0x49, 0x27, 0x45, 0xde, 0x1d, 0x5b, 0xe2, 0x17, 0x43, 0x39, 0x79, 0xdc,
0xa5, 0xb7, 0x1a, 0x1b, 0xb7, 0x29, 0x9c, 0xb5, 0x69, 0x2f, 0x42, 0xc5, 0xe5,
0x0c, 0x78, 0x57, 0x16, 0xa6, 0x46, 0x22, 0x18, 0x0c, 0xa2, 0xb3, 0x8c, 0xee,
0xa1, 0xde, 0x38, 0xf1, 0xca, 0x73, 0xd3, 0xd6, 0xa3, 0x61, 0x47, 0xe2,
};
TEST(OpenPGPSymmetricEncrytionTest, AES128GPG) {
base::StringPiece encrypted(reinterpret_cast<const char*>(kTestMessage1),
sizeof(kTestMessage1));
std::string out;
OpenPGPSymmetricEncrytion::Result r =
OpenPGPSymmetricEncrytion::Decrypt(encrypted, "testing", &out);
EXPECT_EQ(OpenPGPSymmetricEncrytion::OK, r);
EXPECT_EQ("Hello world\n", out);
}
TEST(OpenPGPSymmetricEncrytionTest, AES256GPG) {
base::StringPiece encrypted(reinterpret_cast<const char*>(kTestMessage2),
sizeof(kTestMessage2));
std::string out;
OpenPGPSymmetricEncrytion::Result r =
OpenPGPSymmetricEncrytion::Decrypt(encrypted, "testing", &out);
EXPECT_EQ(OpenPGPSymmetricEncrytion::OK, r);
EXPECT_EQ("Hello world\n", out);
}
TEST(OpenPGPSymmetricEncrytionTest, AES128Go) {
base::StringPiece encrypted(reinterpret_cast<const char*>(kTestMessage3),
sizeof(kTestMessage3));
std::string out;
OpenPGPSymmetricEncrytion::Result r =
OpenPGPSymmetricEncrytion::Decrypt(encrypted, "testing", &out);
EXPECT_EQ(OpenPGPSymmetricEncrytion::OK, r);
EXPECT_EQ("Hello world\n", out);
}
TEST(OpenPGPSymmetricEncrytionTest, SaltedS2K) {
base::StringPiece encrypted(reinterpret_cast<const char*>(kTestMessage4),
sizeof(kTestMessage4));
std::string out;
OpenPGPSymmetricEncrytion::Result r =
OpenPGPSymmetricEncrytion::Decrypt(encrypted, "testing", &out);
EXPECT_EQ(OpenPGPSymmetricEncrytion::OK, r);
EXPECT_EQ("Hello world\n", out);
}
TEST(OpenPGPSymmetricEncrytionTest, Encrypt) {
for (unsigned i = 0; i < 16; i++) {
std::string encrypted =
OpenPGPSymmetricEncrytion::Encrypt("Hello world\n", "testing");
std::string out;
OpenPGPSymmetricEncrytion::Result r =
OpenPGPSymmetricEncrytion::Decrypt(encrypted, "testing", &out);
EXPECT_EQ(OpenPGPSymmetricEncrytion::OK, r);
EXPECT_EQ("Hello world\n", out);
}
}
} // namespace crypto
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment