Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/crypto/signature_creator.h" | 5 #include "base/crypto/signature_creator.h" |
| 6 | 6 |
| 7 #include <openssl/evp.h> | |
| 8 | |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/openssl_util.h" | |
| 11 #include "base/scoped_ptr.h" | |
| 8 | 12 |
| 9 namespace base { | 13 namespace base { |
| 10 | 14 |
| 11 // static | 15 // static |
| 12 SignatureCreator* SignatureCreator::Create(RSAPrivateKey* key) { | 16 SignatureCreator* SignatureCreator::Create(RSAPrivateKey* key) { |
| 13 return NULL; | 17 EnsureOpenSSLInit(); |
| 18 OpenSSLErrStackTracer err_tracer("SignatureCreator::Create"); | |
| 19 scoped_ptr<SignatureCreator> self(new SignatureCreator); | |
|
bulach
2010/11/17 14:35:09
s/self/new_signature/
joth
2010/11/17 14:49:31
Done. (=>result)
| |
| 20 self->key_ = key; | |
| 21 if (!EVP_SignInit_ex(self->sign_context_, EVP_sha1(), NULL)) | |
| 22 return NULL; | |
| 23 return self.release(); | |
| 14 } | 24 } |
| 15 | 25 |
| 16 SignatureCreator::SignatureCreator() { | 26 SignatureCreator::SignatureCreator() |
| 27 : sign_context_(EVP_MD_CTX_create()) { | |
| 17 } | 28 } |
| 18 | 29 |
| 19 SignatureCreator::~SignatureCreator() { | 30 SignatureCreator::~SignatureCreator() { |
| 31 EVP_MD_CTX_destroy(sign_context_); | |
|
bulach
2010/11/17 14:35:09
scoped?
joth
2010/11/17 14:49:31
Prefer not to, for same reason as RSAPrivateKey.
| |
| 20 } | 32 } |
| 21 | 33 |
| 22 bool SignatureCreator::Update(const uint8* data_part, int data_part_len) { | 34 bool SignatureCreator::Update(const uint8* data_part, int data_part_len) { |
| 23 NOTIMPLEMENTED(); | 35 OpenSSLErrStackTracer err_tracer("SignatureCreator::Update"); |
| 24 return false; | 36 return EVP_SignUpdate(sign_context_, data_part, data_part_len) == 1; |
| 25 } | 37 } |
| 26 | 38 |
| 27 bool SignatureCreator::Final(std::vector<uint8>* signature) { | 39 bool SignatureCreator::Final(std::vector<uint8>* signature) { |
| 28 NOTIMPLEMENTED(); | 40 OpenSSLErrStackTracer err_tracer("SignatureCreator::Final"); |
| 29 return false; | 41 EVP_PKEY* key = key_->key(); |
| 42 signature->resize(EVP_PKEY_size(key)); | |
| 43 | |
| 44 unsigned int len = 0; | |
| 45 int rv = EVP_SignFinal(sign_context_, signature->data(), &len, key); | |
| 46 if (!rv) { | |
| 47 signature->clear(); | |
| 48 return false; | |
| 49 } | |
| 50 signature->resize(len); | |
| 51 return true; | |
| 30 } | 52 } |
| 31 | 53 |
| 32 } // namespace base | 54 } // namespace base |
| OLD | NEW |