| 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/ghash.h" | 5 #include "crypto/ghash.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/sys_byteorder.h" | 8 #include "base/sys_byteorder.h" |
| 9 | 9 |
| 10 namespace crypto { | 10 namespace crypto { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 y_.low ^= Get64(bytes); | 222 y_.low ^= Get64(bytes); |
| 223 bytes += 8; | 223 bytes += 8; |
| 224 y_.hi ^= Get64(bytes); | 224 y_.hi ^= Get64(bytes); |
| 225 bytes += 8; | 225 bytes += 8; |
| 226 MulAfterPrecomputation(product_table_, &y_); | 226 MulAfterPrecomputation(product_table_, &y_); |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 | 229 |
| 230 void GaloisHash::Update(const uint8* data, size_t length) { | 230 void GaloisHash::Update(const uint8* data, size_t length) { |
| 231 if (buf_used_ > 0) { | 231 if (buf_used_ > 0) { |
| 232 const size_t n = std::min(length, buf_used_); | 232 const size_t n = std::min(length, sizeof(buf_) - buf_used_); |
| 233 memcpy(&buf_[buf_used_], data, n); | 233 memcpy(&buf_[buf_used_], data, n); |
| 234 buf_used_ += n; | 234 buf_used_ += n; |
| 235 length -= n; | 235 length -= n; |
| 236 data += n; | 236 data += n; |
| 237 | 237 |
| 238 if (buf_used_ == sizeof(buf_)) { | 238 if (buf_used_ == sizeof(buf_)) { |
| 239 UpdateBlocks(buf_, 1); | 239 UpdateBlocks(buf_, 1); |
| 240 buf_used_ = 0; | 240 buf_used_ = 0; |
| 241 } | 241 } |
| 242 } | 242 } |
| 243 | 243 |
| 244 if (length >= 16) { | 244 if (length >= 16) { |
| 245 const size_t n = length / 16; | 245 const size_t n = length / 16; |
| 246 UpdateBlocks(data, n); | 246 UpdateBlocks(data, n); |
| 247 length -= n*16; | 247 length -= n*16; |
| 248 data += n*16; | 248 data += n*16; |
| 249 } | 249 } |
| 250 | 250 |
| 251 if (length > 0) { | 251 if (length > 0) { |
| 252 memcpy(buf_, data, length); | 252 memcpy(buf_, data, length); |
| 253 buf_used_ = length; | 253 buf_used_ = length; |
| 254 } | 254 } |
| 255 } | 255 } |
| 256 | 256 |
| 257 } // namespace crypto | 257 } // namespace crypto |
| OLD | NEW |