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

Unified Diff: crypto/ec_signature_creator_nss.cc

Issue 10910226: crypto: change ECSignatureCreator defaults to match SPDY. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 8 years, 3 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/ec_signature_creator_impl.h ('k') | crypto/ec_signature_creator_openssl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crypto/ec_signature_creator_nss.cc
diff --git a/crypto/ec_signature_creator_nss.cc b/crypto/ec_signature_creator_nss.cc
index a85b1e94fecf20299494fcffdc95c7894fb375da..3e3626f449982fba2171767d278fefffccdc88e2 100644
--- a/crypto/ec_signature_creator_nss.cc
+++ b/crypto/ec_signature_creator_nss.cc
@@ -24,7 +24,8 @@ namespace {
SECStatus SignData(SECItem* result,
SECItem* input,
SECKEYPrivateKey* key,
- HASH_HashType hash_type) {
+ HASH_HashType hash_type,
+ size_t* out_signature_len) {
if (key->keyType != ecKey) {
DLOG(FATAL) << "Should be using an EC key.";
PORT_SetError(SEC_ERROR_INVALID_ARGS);
@@ -49,6 +50,8 @@ SECStatus SignData(SECItem* result,
if (rv != SECSuccess)
return rv;
+ *out_signature_len = sig.len;
+
// DER encode the signature.
return DSAU_EncodeDerSigWithLen(result, &sig, sig.len);
}
@@ -56,7 +59,8 @@ SECStatus SignData(SECItem* result,
} // namespace
ECSignatureCreatorImpl::ECSignatureCreatorImpl(ECPrivateKey* key)
- : key_(key) {
+ : key_(key),
+ signature_len_(0) {
EnsureNSSInit();
}
@@ -79,7 +83,7 @@ bool ECSignatureCreatorImpl::Sign(const uint8* data,
// Sign the secret data and save it to |result|.
SECStatus rv =
- SignData(&result, &secret, key_->key(), HASH_AlgSHA1);
+ SignData(&result, &secret, key_->key(), HASH_AlgSHA256, &signature_len_);
if (rv != SECSuccess) {
DLOG(ERROR) << "DerSignData: " << PORT_GetError();
return false;
@@ -91,4 +95,20 @@ bool ECSignatureCreatorImpl::Sign(const uint8* data,
return true;
}
+bool ECSignatureCreatorImpl::DecodeSignature(
+ const std::vector<uint8>& der_sig,
+ std::vector<uint8>* out_raw_sig) {
+ SECItem der_sig_item;
+ der_sig_item.type = siBuffer;
+ der_sig_item.len = der_sig.size();
+ der_sig_item.data = const_cast<uint8*>(&der_sig[0]);
+
+ SECItem* raw_sig = DSAU_DecodeDerSigToLen(&der_sig_item, signature_len_);
+ if (!raw_sig)
+ return false;
+ out_raw_sig->assign(raw_sig->data, raw_sig->data + raw_sig->len);
+ SECITEM_FreeItem(raw_sig, PR_TRUE /* free SECItem structure itself. */);
+ return true;
+}
+
} // namespace crypto
« no previous file with comments | « crypto/ec_signature_creator_impl.h ('k') | crypto/ec_signature_creator_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698