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

Unified Diff: crypto/secure_hash.cc

Issue 2080753002: crypto: Add BoringSSL accelerated version of SHA-1 Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « crypto/secure_hash.h ('k') | crypto/sha1.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crypto/secure_hash.cc
diff --git a/crypto/secure_hash.cc b/crypto/secure_hash.cc
index 2a5a1f02089e6f1ddd24523ab6f39fd31bea744a..09cbb0139ee4414a0f997c8be1cad17e7cf15e78 100644
--- a/crypto/secure_hash.cc
+++ b/crypto/secure_hash.cc
@@ -16,6 +16,34 @@ namespace crypto {
namespace {
+class SecureHashSHA1 : public SecureHash {
+ public:
+ SecureHashSHA1() { SHA1_Init(&ctx_); }
+
+ SecureHashSHA1(const SecureHashSHA1& other) {
+ memcpy(&ctx_, &other.ctx_, sizeof(ctx_));
+ }
+
+ ~SecureHashSHA1() override { OPENSSL_cleanse(&ctx_, sizeof(ctx_)); }
+
+ void Update(const void* input, size_t len) override {
+ SHA1_Update(&ctx_, static_cast<const unsigned char*>(input), len);
+ }
+
+ void Finish(void* output, size_t len) override {
+ ScopedOpenSSLSafeSizeBuffer<SHA_DIGEST_LENGTH> result(
+ static_cast<unsigned char*>(output), len);
+ SHA1_Final(result.safe_buffer(), &ctx_);
+ }
+
+ SecureHash* Clone() const override { return new SecureHashSHA1(*this); }
+
+ size_t GetHashLength() const override { return SHA_DIGEST_LENGTH; }
+
+ private:
+ SHA_CTX ctx_;
+};
+
class SecureHashSHA256 : public SecureHash {
public:
SecureHashSHA256() {
@@ -56,6 +84,8 @@ SecureHash* SecureHash::Create(Algorithm algorithm) {
switch (algorithm) {
case SHA256:
return new SecureHashSHA256();
+ case SHA1:
+ return new SecureHashSHA1();
default:
NOTIMPLEMENTED();
return NULL;
« no previous file with comments | « crypto/secure_hash.h ('k') | crypto/sha1.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698