summaryrefslogtreecommitdiffstats
path: root/crypto/openpgp_symmetric_encryption.h
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-27 20:37:27 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-27 20:37:27 +0000
commite0faab534a55740aa26e5025baaab9d20537e575 (patch)
tree2585ecc37839376a10d38824c38c9cba52d80431 /crypto/openpgp_symmetric_encryption.h
parent68d4743c92ccca8b2f87c7891733c021d921aa1a (diff)
downloadchromium_src-e0faab534a55740aa26e5025baaab9d20537e575.zip
chromium_src-e0faab534a55740aa26e5025baaab9d20537e575.tar.gz
chromium_src-e0faab534a55740aa26e5025baaab9d20537e575.tar.bz2
crypto: add OpenPGP symmetric encryption for ChromeOS
This contains a basic implementation of OpenPGP (RFC 4880) symmetric encryption and decryption. It's written specifically on top of OpenSSL, which should suffice for the intended use case. BUG=none TEST=crypto_unittest Review URL: http://codereview.chromium.org/7247005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90633 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'crypto/openpgp_symmetric_encryption.h')
-rw-r--r--crypto/openpgp_symmetric_encryption.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/crypto/openpgp_symmetric_encryption.h b/crypto/openpgp_symmetric_encryption.h
new file mode 100644
index 0000000..d49d216
--- /dev/null
+++ b/crypto/openpgp_symmetric_encryption.h
@@ -0,0 +1,45 @@
+// 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 CRYPTO_OPENPGP_SYMMETRIC_ENCRYPTION_H_
+#define CRYPTO_OPENPGP_SYMMETRIC_ENCRYPTION_H_
+#pragma once
+
+#include <string>
+
+#include "base/string_piece.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 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_
+