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 <stdint.h> |
9 #include <stdlib.h> | 10 #include <stdlib.h> |
10 | 11 |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "crypto/nss_util.h" | 14 #include "crypto/nss_util.h" |
14 #include "crypto/rsa_private_key.h" | 15 #include "crypto/rsa_private_key.h" |
15 | 16 |
16 namespace crypto { | 17 namespace crypto { |
17 | 18 |
18 namespace { | 19 namespace { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 NOTREACHED(); | 62 NOTREACHED(); |
62 return NULL; | 63 return NULL; |
63 } | 64 } |
64 | 65 |
65 return result.release(); | 66 return result.release(); |
66 } | 67 } |
67 | 68 |
68 // static | 69 // static |
69 bool SignatureCreator::Sign(RSAPrivateKey* key, | 70 bool SignatureCreator::Sign(RSAPrivateKey* key, |
70 HashAlgorithm hash_alg, | 71 HashAlgorithm hash_alg, |
71 const uint8* data, | 72 const uint8_t* data, |
72 int data_len, | 73 int data_len, |
73 std::vector<uint8>* signature) { | 74 std::vector<uint8_t>* signature) { |
74 SECItem data_item; | 75 SECItem data_item; |
75 data_item.type = siBuffer; | 76 data_item.type = siBuffer; |
76 data_item.data = const_cast<unsigned char*>(data); | 77 data_item.data = const_cast<unsigned char*>(data); |
77 data_item.len = data_len; | 78 data_item.len = data_len; |
78 | 79 |
79 SECItem signature_item; | 80 SECItem signature_item; |
80 SECStatus rv = SGN_Digest(key->key(), ToNSSHashOid(hash_alg), &signature_item, | 81 SECStatus rv = SGN_Digest(key->key(), ToNSSHashOid(hash_alg), &signature_item, |
81 &data_item); | 82 &data_item); |
82 if (rv != SECSuccess) { | 83 if (rv != SECSuccess) { |
83 NOTREACHED(); | 84 NOTREACHED(); |
84 return false; | 85 return false; |
85 } | 86 } |
86 signature->assign(signature_item.data, | 87 signature->assign(signature_item.data, |
87 signature_item.data + signature_item.len); | 88 signature_item.data + signature_item.len); |
88 SECITEM_FreeItem(&signature_item, PR_FALSE); | 89 SECITEM_FreeItem(&signature_item, PR_FALSE); |
89 return true; | 90 return true; |
90 } | 91 } |
91 | 92 |
92 bool SignatureCreator::Update(const uint8* data_part, int data_part_len) { | 93 bool SignatureCreator::Update(const uint8_t* data_part, int data_part_len) { |
93 SECStatus rv = SGN_Update(sign_context_, data_part, data_part_len); | 94 SECStatus rv = SGN_Update(sign_context_, data_part, data_part_len); |
94 if (rv != SECSuccess) { | 95 if (rv != SECSuccess) { |
95 NOTREACHED(); | 96 NOTREACHED(); |
96 return false; | 97 return false; |
97 } | 98 } |
98 | 99 |
99 return true; | 100 return true; |
100 } | 101 } |
101 | 102 |
102 bool SignatureCreator::Final(std::vector<uint8>* signature) { | 103 bool SignatureCreator::Final(std::vector<uint8_t>* signature) { |
103 SECItem signature_item; | 104 SECItem signature_item; |
104 SECStatus rv = SGN_End(sign_context_, &signature_item); | 105 SECStatus rv = SGN_End(sign_context_, &signature_item); |
105 if (rv != SECSuccess) { | 106 if (rv != SECSuccess) { |
106 return false; | 107 return false; |
107 } | 108 } |
108 signature->assign(signature_item.data, | 109 signature->assign(signature_item.data, |
109 signature_item.data + signature_item.len); | 110 signature_item.data + signature_item.len); |
110 SECITEM_FreeItem(&signature_item, PR_FALSE); | 111 SECITEM_FreeItem(&signature_item, PR_FALSE); |
111 return true; | 112 return true; |
112 } | 113 } |
113 | 114 |
114 SignatureCreator::SignatureCreator() : sign_context_(NULL) { | 115 SignatureCreator::SignatureCreator() : sign_context_(NULL) { |
115 EnsureNSSInit(); | 116 EnsureNSSInit(); |
116 } | 117 } |
117 | 118 |
118 } // namespace crypto | 119 } // namespace crypto |
OLD | NEW |