@@ -52,18 +52,20 @@ class ScopedBioHandle {
52
52
};
53
53
54
54
OmahaHashCalculator::OmahaHashCalculator () : valid_(false ) {
55
- valid_ = ( SHA256_Init (&ctx_) == 1 );
56
- LOG_IF (ERROR, !valid_) << " SHA256_Init failed" ;
55
+ valid_ = ! crypto_hash_sha256_init (&hash_state_ );
56
+ LOG_IF (ERROR, !valid_) << " crypto_hash_sha256_init() failed" ;
57
57
}
58
58
59
59
// Update is called with all of the data that should be hashed in order.
60
60
// Mostly just passes the data through to OpenSSL's SHA256_Update()
61
61
bool OmahaHashCalculator::Update (const char * data, size_t length) {
62
62
TEST_AND_RETURN_FALSE (valid_);
63
63
TEST_AND_RETURN_FALSE (hash_.empty ());
64
- static_assert (sizeof (size_t ) <= sizeof (unsigned long ),
65
- " length param may be truncated in SHA256_Update" );
66
- TEST_AND_RETURN_FALSE (SHA256_Update (&ctx_, data, length) == 1 );
64
+ static_assert (sizeof (size_t ) <= sizeof (unsigned long long ),
65
+ " length param may be truncated in crypto_hash_sha256_update" );
66
+
67
+ TEST_AND_RETURN_FALSE (crypto_hash_sha256_update (&hash_state_,
68
+ reinterpret_cast <const unsigned char *>(data), length) == 0 );
67
69
return true ;
68
70
}
69
71
@@ -170,13 +172,14 @@ bool OmahaHashCalculator::Base64Decode(const string& raw_in,
170
172
bool OmahaHashCalculator::Finalize () {
171
173
TEST_AND_RETURN_FALSE (hash_.empty ());
172
174
TEST_AND_RETURN_FALSE (raw_hash_.empty ());
173
- raw_hash_.resize (SHA256_DIGEST_LENGTH);
175
+ raw_hash_.resize (crypto_hash_sha256_BYTES);
176
+
174
177
TEST_AND_RETURN_FALSE (
175
- SHA256_Final ( reinterpret_cast < unsigned char *>(&raw_hash_[ 0 ]) ,
176
- &ctx_) == 1 );
178
+ crypto_hash_sha256_final (&hash_state_ ,
179
+ reinterpret_cast < unsigned char *>(raw_hash_. data ())) == 0 );
177
180
178
181
// Convert raw_hash_ to base64 encoding and store it in hash_.
179
- return Base64Encode (& raw_hash_[ 0 ] , raw_hash_.size (), &hash_);
182
+ return Base64Encode (raw_hash_. data () , raw_hash_.size (), &hash_);
180
183
}
181
184
182
185
bool OmahaHashCalculator::RawHashOfBytes (const char * data,
@@ -221,16 +224,16 @@ string OmahaHashCalculator::OmahaHashOfString(const string& str) {
221
224
}
222
225
223
226
string OmahaHashCalculator::OmahaHashOfData (const vector<char >& data) {
224
- return OmahaHashOfBytes (& data[ 0 ] , data.size ());
227
+ return OmahaHashOfBytes (data. data () , data.size ());
225
228
}
226
229
227
230
string OmahaHashCalculator::GetContext () const {
228
- return string (reinterpret_cast <const char *>(&ctx_ ), sizeof (ctx_ ));
231
+ return string (reinterpret_cast <const char *>(&hash_state_ ), sizeof (hash_state_ ));
229
232
}
230
233
231
234
bool OmahaHashCalculator::SetContext (const std::string& context) {
232
- TEST_AND_RETURN_FALSE (context.size () == sizeof (ctx_ ));
233
- memcpy (&ctx_ , context.data (), sizeof (ctx_ ));
235
+ TEST_AND_RETURN_FALSE (context.size () == sizeof (hash_state_ ));
236
+ memcpy (&hash_state_ , context.data (), sizeof (hash_state_ ));
234
237
return true ;
235
238
}
236
239
0 commit comments