OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/rsa_private_key.h" | 5 #include "crypto/rsa_private_key.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <list> | 8 #include <list> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 } | 178 } |
179 | 179 |
180 void PrivateKeyInfoCodec::PrependIntegerImpl(uint8* val, | 180 void PrivateKeyInfoCodec::PrependIntegerImpl(uint8* val, |
181 int num_bytes, | 181 int num_bytes, |
182 std::list<uint8>* data, | 182 std::list<uint8>* data, |
183 bool big_endian) { | 183 bool big_endian) { |
184 // Reverse input if little-endian. | 184 // Reverse input if little-endian. |
185 std::vector<uint8> tmp; | 185 std::vector<uint8> tmp; |
186 if (!big_endian) { | 186 if (!big_endian) { |
187 tmp.assign(val, val + num_bytes); | 187 tmp.assign(val, val + num_bytes); |
188 reverse(tmp.begin(), tmp.end()); | 188 std::reverse(tmp.begin(), tmp.end()); |
189 val = &tmp.front(); | 189 val = &tmp.front(); |
190 } | 190 } |
191 | 191 |
192 // ASN.1 integers are unpadded byte arrays, so skip any null padding bytes | 192 // ASN.1 integers are unpadded byte arrays, so skip any null padding bytes |
193 // from the most-significant end of the integer. | 193 // from the most-significant end of the integer. |
194 int start = 0; | 194 int start = 0; |
195 while (start < (num_bytes - 1) && val[start] == 0x00) { | 195 while (start < (num_bytes - 1) && val[start] == 0x00) { |
196 start++; | 196 start++; |
197 num_bytes--; | 197 num_bytes--; |
198 } | 198 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 index++; | 233 index++; |
234 } else { | 234 } else { |
235 READ_ASSERT(out->size() <= expected_size); | 235 READ_ASSERT(out->size() <= expected_size); |
236 } | 236 } |
237 | 237 |
238 out->insert(out->end(), pad, 0x00); | 238 out->insert(out->end(), pad, 0x00); |
239 out->insert(out->end(), temp.begin(), temp.end()); | 239 out->insert(out->end(), temp.begin(), temp.end()); |
240 | 240 |
241 // Reverse output if little-endian. | 241 // Reverse output if little-endian. |
242 if (!big_endian_) | 242 if (!big_endian_) |
243 reverse(out->begin(), out->end()); | 243 std::reverse(out->begin(), out->end()); |
244 return true; | 244 return true; |
245 } | 245 } |
246 | 246 |
247 bool PrivateKeyInfoCodec::ReadIntegerImpl(uint8** pos, | 247 bool PrivateKeyInfoCodec::ReadIntegerImpl(uint8** pos, |
248 uint8* end, | 248 uint8* end, |
249 std::vector<uint8>* out, | 249 std::vector<uint8>* out, |
250 bool big_endian) { | 250 bool big_endian) { |
251 uint32 length = 0; | 251 uint32 length = 0; |
252 if (!ReadTypeHeaderAndLength(pos, end, kIntegerTag, &length) || !length) | 252 if (!ReadTypeHeaderAndLength(pos, end, kIntegerTag, &length) || !length) |
253 return false; | 253 return false; |
254 | 254 |
255 // The first byte can be zero to force positiveness. We can ignore this. | 255 // The first byte can be zero to force positiveness. We can ignore this. |
256 if (**pos == 0x00) { | 256 if (**pos == 0x00) { |
257 ++(*pos); | 257 ++(*pos); |
258 --length; | 258 --length; |
259 } | 259 } |
260 | 260 |
261 if (length) | 261 if (length) |
262 out->insert(out->end(), *pos, (*pos) + length); | 262 out->insert(out->end(), *pos, (*pos) + length); |
263 | 263 |
264 (*pos) += length; | 264 (*pos) += length; |
265 | 265 |
266 // Reverse output if little-endian. | 266 // Reverse output if little-endian. |
267 if (!big_endian) | 267 if (!big_endian) |
268 reverse(out->begin(), out->end()); | 268 std::reverse(out->begin(), out->end()); |
269 return true; | 269 return true; |
270 } | 270 } |
271 | 271 |
272 void PrivateKeyInfoCodec::PrependBytes(uint8* val, | 272 void PrivateKeyInfoCodec::PrependBytes(uint8* val, |
273 int start, | 273 int start, |
274 int num_bytes, | 274 int num_bytes, |
275 std::list<uint8>* data) { | 275 std::list<uint8>* data) { |
276 while (num_bytes > 0) { | 276 while (num_bytes > 0) { |
277 --num_bytes; | 277 --num_bytes; |
278 data->push_front(val[start + num_bytes]); | 278 data->push_front(val[start + num_bytes]); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 // The version should be zero. | 375 // The version should be zero. |
376 for (uint32 i = 0; i < length; ++i) { | 376 for (uint32 i = 0; i < length; ++i) { |
377 READ_ASSERT(**pos == 0x00); | 377 READ_ASSERT(**pos == 0x00); |
378 (*pos)++; | 378 (*pos)++; |
379 } | 379 } |
380 | 380 |
381 return true; | 381 return true; |
382 } | 382 } |
383 | 383 |
384 } // namespace crypto | 384 } // namespace crypto |
OLD | NEW |