| 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;
|
|
|