| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/devtools/adb/android_rsa.h" | 5 #include "chrome/browser/devtools/adb/android_rsa.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "chrome/browser/prefs/pref_service_syncable.h" | 9 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 uint32* BnNew() { | 69 uint32* BnNew() { |
| 70 uint32* result = new uint32[kBigIntSize]; | 70 uint32* result = new uint32[kBigIntSize]; |
| 71 memset(result, 0, kBigIntSize * sizeof(uint32)); | 71 memset(result, 0, kBigIntSize * sizeof(uint32)); |
| 72 return result; | 72 return result; |
| 73 } | 73 } |
| 74 | 74 |
| 75 void BnFree(uint32* a) { | 75 void BnFree(uint32* a) { |
| 76 delete[] a; | 76 delete[] a; |
| 77 } | 77 } |
| 78 | 78 |
| 79 void BnPrint(const std::string& title, uint32_t* a) { | |
| 80 int i = kBigIntSize - 1; | |
| 81 fprintf(stderr, "%s: ", title.c_str()); | |
| 82 while (!a[i]) --i; | |
| 83 for (; i >= 0; --i) | |
| 84 fprintf(stderr, "%08x", a[i]); | |
| 85 fprintf(stderr, "\n"); | |
| 86 } | |
| 87 | |
| 88 uint32* BnCopy(uint32* a) { | 79 uint32* BnCopy(uint32* a) { |
| 89 uint32* result = new uint32[kBigIntSize]; | 80 uint32* result = new uint32[kBigIntSize]; |
| 90 memcpy(result, a, kBigIntSize * sizeof(uint32)); | 81 memcpy(result, a, kBigIntSize * sizeof(uint32)); |
| 91 return result; | 82 return result; |
| 92 } | 83 } |
| 93 | 84 |
| 94 void BnAdd(uint32* a, uint32* b) { | |
| 95 uint64 carry_over = 0; | |
| 96 for (size_t i = 0; i < kBigIntSize; ++i) { | |
| 97 carry_over += static_cast<uint64>(a[i]) + b[i]; | |
| 98 a[i] = carry_over & kuint32max; | |
| 99 carry_over >>= 32; | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 uint32* BnMul(uint32* a, uint32 b) { | 85 uint32* BnMul(uint32* a, uint32 b) { |
| 104 uint32* result = BnNew(); | 86 uint32* result = BnNew(); |
| 105 uint64 carry_over = 0; | 87 uint64 carry_over = 0; |
| 106 for (size_t i = 0; i < kBigIntSize; ++i) { | 88 for (size_t i = 0; i < kBigIntSize; ++i) { |
| 107 carry_over += static_cast<uint64>(a[i]) * b; | 89 carry_over += static_cast<uint64>(a[i]) * b; |
| 108 result[i] = carry_over & kuint32max; | 90 result[i] = carry_over & kuint32max; |
| 109 carry_over >>= 32; | 91 carry_over >>= 32; |
| 110 } | 92 } |
| 111 return result; | 93 return result; |
| 112 } | 94 } |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 std::string AndroidRSASign(crypto::RSAPrivateKey* key, | 262 std::string AndroidRSASign(crypto::RSAPrivateKey* key, |
| 281 const std::string& body) { | 263 const std::string& body) { |
| 282 std::vector<uint8> digest(body.begin(), body.end()); | 264 std::vector<uint8> digest(body.begin(), body.end()); |
| 283 std::vector<uint8> result; | 265 std::vector<uint8> result; |
| 284 if (!crypto::SignatureCreator::Sign(key, vector_as_array(&digest), | 266 if (!crypto::SignatureCreator::Sign(key, vector_as_array(&digest), |
| 285 digest.size(), &result)) { | 267 digest.size(), &result)) { |
| 286 return std::string(); | 268 return std::string(); |
| 287 } | 269 } |
| 288 return std::string(result.begin(), result.end()); | 270 return std::string(result.begin(), result.end()); |
| 289 } | 271 } |
| OLD | NEW |