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

Unified Diff: crypto/signature_creator_openssl.cc

Issue 18697003: Introduce RSAPrivateKey::SignDigest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For landing Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « crypto/signature_creator_nss.cc ('k') | crypto/signature_creator_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crypto/signature_creator_openssl.cc
diff --git a/crypto/signature_creator_openssl.cc b/crypto/signature_creator_openssl.cc
index fa9ba07c3cf0f9b73fbf6ae6c0d1d9ef7fec0dd0..e46d3d002c1b24eddc94729290d6c9a3c50fb51f 100644
--- a/crypto/signature_creator_openssl.cc
+++ b/crypto/signature_creator_openssl.cc
@@ -5,6 +5,7 @@
#include "crypto/signature_creator.h"
#include <openssl/evp.h>
+#include <openssl/rsa.h>
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
@@ -24,6 +25,27 @@ SignatureCreator* SignatureCreator::Create(RSAPrivateKey* key) {
return result.release();
}
+// static
+bool SignatureCreator::Sign(RSAPrivateKey* key,
+ const uint8* data,
+ int data_len,
+ std::vector<uint8>* signature) {
+ RSA* rsa_key = EVP_PKEY_get1_RSA(key->key());
+ if (!rsa_key)
+ return false;
+ signature->resize(RSA_size(rsa_key));
+
+ unsigned int len = 0;
+ bool success = RSA_sign(NID_sha1, data, data_len, vector_as_array(signature),
+ &len, rsa_key);
+ if (!success) {
+ signature->clear();
+ return false;
+ }
+ signature->resize(len);
+ return true;
+}
+
SignatureCreator::SignatureCreator()
: sign_context_(EVP_MD_CTX_create()) {
}
« no previous file with comments | « crypto/signature_creator_nss.cc ('k') | crypto/signature_creator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698