Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: omaha_hash_calculator.cc

Issue 6271003: AU: Support signed payload verification through the delta generator. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git@master
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « omaha_hash_calculator.h ('k') | payload_signer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium OS 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 "update_engine/omaha_hash_calculator.h" 5 #include "update_engine/omaha_hash_calculator.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 8
9 #include <base/eintr_wrapper.h> 9 #include <base/eintr_wrapper.h>
10 #include <base/logging.h> 10 #include <base/logging.h>
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 TEST_AND_RETURN_FALSE(raw_hash_.empty()); 98 TEST_AND_RETURN_FALSE(raw_hash_.empty());
99 raw_hash_.resize(SHA256_DIGEST_LENGTH); 99 raw_hash_.resize(SHA256_DIGEST_LENGTH);
100 TEST_AND_RETURN_FALSE( 100 TEST_AND_RETURN_FALSE(
101 SHA256_Final(reinterpret_cast<unsigned char*>(&raw_hash_[0]), 101 SHA256_Final(reinterpret_cast<unsigned char*>(&raw_hash_[0]),
102 &ctx_) == 1); 102 &ctx_) == 1);
103 103
104 // Convert raw_hash_ to base64 encoding and store it in hash_. 104 // Convert raw_hash_ to base64 encoding and store it in hash_.
105 return Base64Encode(&raw_hash_[0], raw_hash_.size(), &hash_);; 105 return Base64Encode(&raw_hash_[0], raw_hash_.size(), &hash_);;
106 } 106 }
107 107
108 bool OmahaHashCalculator::RawHashOfBytes(const char* data,
109 size_t length,
110 vector<char>* out_hash) {
111 OmahaHashCalculator calc;
112 TEST_AND_RETURN_FALSE(calc.Update(data, length));
113 TEST_AND_RETURN_FALSE(calc.Finalize());
114 *out_hash = calc.raw_hash();
115 return true;
116 }
117
108 bool OmahaHashCalculator::RawHashOfData(const vector<char>& data, 118 bool OmahaHashCalculator::RawHashOfData(const vector<char>& data,
109 vector<char>* out_hash) { 119 vector<char>* out_hash) {
110 OmahaHashCalculator calc; 120 return RawHashOfBytes(data.data(), data.size(), out_hash);
111 calc.Update(&data[0], data.size());
112
113 out_hash->resize(out_hash->size() + SHA256_DIGEST_LENGTH);
114 TEST_AND_RETURN_FALSE(
115 SHA256_Final(reinterpret_cast<unsigned char*>(&(*(out_hash->end() -
116 SHA256_DIGEST_LENGTH))),
117 &calc.ctx_) == 1);
118 return true;
119 } 121 }
120 122
121 off_t OmahaHashCalculator::RawHashOfFile(const std::string& name, off_t length, 123 off_t OmahaHashCalculator::RawHashOfFile(const string& name, off_t length,
122 std::vector<char>* out_hash) { 124 vector<char>* out_hash) {
123 OmahaHashCalculator calc; 125 OmahaHashCalculator calc;
124 off_t res = calc.UpdateFile(name, length); 126 off_t res = calc.UpdateFile(name, length);
125 if (res < 0) { 127 if (res < 0) {
126 return res; 128 return res;
127 } 129 }
128 if (!calc.Finalize()) { 130 if (!calc.Finalize()) {
129 return -1; 131 return -1;
130 } 132 }
131 *out_hash = calc.raw_hash(); 133 *out_hash = calc.raw_hash();
132 return res; 134 return res;
(...skipping 19 matching lines...) Expand all
152 return string(reinterpret_cast<const char*>(&ctx_), sizeof(ctx_)); 154 return string(reinterpret_cast<const char*>(&ctx_), sizeof(ctx_));
153 } 155 }
154 156
155 bool OmahaHashCalculator::SetContext(const std::string& context) { 157 bool OmahaHashCalculator::SetContext(const std::string& context) {
156 TEST_AND_RETURN_FALSE(context.size() == sizeof(ctx_)); 158 TEST_AND_RETURN_FALSE(context.size() == sizeof(ctx_));
157 memcpy(&ctx_, context.data(), sizeof(ctx_)); 159 memcpy(&ctx_, context.data(), sizeof(ctx_));
158 return true; 160 return true;
159 } 161 }
160 162
161 } // namespace chromeos_update_engine 163 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « omaha_hash_calculator.h ('k') | payload_signer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698