| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "crypto/signature_creator.h" | 5 #include "crypto/signature_creator.h" |
| 6 | 6 |
| 7 #include <cryptohi.h> | 7 #include <cryptohi.h> |
| 8 #include <keyhi.h> | 8 #include <keyhi.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 | 10 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 SECStatus rv = SGN_Begin(result->sign_context_); | 37 SECStatus rv = SGN_Begin(result->sign_context_); |
| 38 if (rv != SECSuccess) { | 38 if (rv != SECSuccess) { |
| 39 NOTREACHED(); | 39 NOTREACHED(); |
| 40 return NULL; | 40 return NULL; |
| 41 } | 41 } |
| 42 | 42 |
| 43 return result.release(); | 43 return result.release(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 // static |
| 47 bool SignatureCreator::Sign(RSAPrivateKey* key, |
| 48 const uint8* data, |
| 49 int data_len, |
| 50 std::vector<uint8>* signature) { |
| 51 SECItem data_item; |
| 52 data_item.type = siBuffer; |
| 53 data_item.data = const_cast<unsigned char*>(data); |
| 54 data_item.len = data_len; |
| 55 |
| 56 SECItem signature_item; |
| 57 SECStatus rv = SGN_Digest(key->key(), SEC_OID_SHA1, &signature_item, |
| 58 &data_item); |
| 59 if (rv != SECSuccess) { |
| 60 NOTREACHED(); |
| 61 return false; |
| 62 } |
| 63 signature->assign(signature_item.data, |
| 64 signature_item.data + signature_item.len); |
| 65 SECITEM_FreeItem(&signature_item, PR_FALSE); |
| 66 return true; |
| 67 } |
| 68 |
| 46 bool SignatureCreator::Update(const uint8* data_part, int data_part_len) { | 69 bool SignatureCreator::Update(const uint8* data_part, int data_part_len) { |
| 47 // TODO(wtc): Remove this const_cast when we require NSS 3.12.5. | 70 // TODO(wtc): Remove this const_cast when we require NSS 3.12.5. |
| 48 // See NSS bug https://bugzilla.mozilla.org/show_bug.cgi?id=518255 | 71 // See NSS bug https://bugzilla.mozilla.org/show_bug.cgi?id=518255 |
| 49 SECStatus rv = SGN_Update(sign_context_, | 72 SECStatus rv = SGN_Update(sign_context_, |
| 50 const_cast<unsigned char*>(data_part), | 73 const_cast<unsigned char*>(data_part), |
| 51 data_part_len); | 74 data_part_len); |
| 52 if (rv != SECSuccess) { | 75 if (rv != SECSuccess) { |
| 53 NOTREACHED(); | 76 NOTREACHED(); |
| 54 return false; | 77 return false; |
| 55 } | 78 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 70 return true; | 93 return true; |
| 71 } | 94 } |
| 72 | 95 |
| 73 SignatureCreator::SignatureCreator() | 96 SignatureCreator::SignatureCreator() |
| 74 : key_(NULL), | 97 : key_(NULL), |
| 75 sign_context_(NULL) { | 98 sign_context_(NULL) { |
| 76 EnsureNSSInit(); | 99 EnsureNSSInit(); |
| 77 } | 100 } |
| 78 | 101 |
| 79 } // namespace crypto | 102 } // namespace crypto |
| OLD | NEW |