2014-05-13 18:00:26 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright 2004 The WebRTC Project Authors. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#ifndef RTC_BASE_OPENSSL_DIGEST_H_
|
|
|
|
|
#define RTC_BASE_OPENSSL_DIGEST_H_
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2019-02-12 18:30:45 -08:00
|
|
|
#include <openssl/ossl_typ.h>
|
2018-10-23 12:03:01 +02:00
|
|
|
#include <stddef.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2018-10-05 15:39:24 +02:00
|
|
|
#include <string>
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2022-03-17 15:47:49 +01:00
|
|
|
#include "absl/strings/string_view.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/message_digest.h"
|
2017-06-29 07:52:50 +02:00
|
|
|
|
|
|
|
|
namespace rtc {
|
|
|
|
|
|
|
|
|
|
// An implementation of the digest class that uses OpenSSL.
|
2018-10-26 17:50:00 -07:00
|
|
|
class OpenSSLDigest final : public MessageDigest {
|
2017-06-29 07:52:50 +02:00
|
|
|
public:
|
2021-07-26 16:03:14 +02:00
|
|
|
// Creates an OpenSSLDigest with `algorithm` as the hash algorithm.
|
2022-03-17 15:47:49 +01:00
|
|
|
explicit OpenSSLDigest(absl::string_view algorithm);
|
2017-06-29 07:52:50 +02:00
|
|
|
~OpenSSLDigest() override;
|
|
|
|
|
// Returns the digest output size (e.g. 16 bytes for MD5).
|
|
|
|
|
size_t Size() const override;
|
2021-07-26 16:03:14 +02:00
|
|
|
// Updates the digest with `len` bytes from `buf`.
|
2017-06-29 07:52:50 +02:00
|
|
|
void Update(const void* buf, size_t len) override;
|
2021-07-26 16:03:14 +02:00
|
|
|
// Outputs the digest value to `buf` with length `len`.
|
2017-06-29 07:52:50 +02:00
|
|
|
size_t Finish(void* buf, size_t len) override;
|
|
|
|
|
|
|
|
|
|
// Helper function to look up a digest's EVP by name.
|
2022-03-17 15:47:49 +01:00
|
|
|
static bool GetDigestEVP(absl::string_view algorithm, const EVP_MD** md);
|
2017-06-29 07:52:50 +02:00
|
|
|
// Helper function to look up a digest's name by EVP.
|
|
|
|
|
static bool GetDigestName(const EVP_MD* md, std::string* algorithm);
|
|
|
|
|
// Helper function to get the length of a digest.
|
2022-03-17 15:47:49 +01:00
|
|
|
static bool GetDigestSize(absl::string_view algorithm, size_t* len);
|
2017-06-29 07:52:50 +02:00
|
|
|
|
|
|
|
|
private:
|
2018-02-02 14:51:18 -08:00
|
|
|
EVP_MD_CTX* ctx_ = nullptr;
|
2017-06-29 07:52:50 +02:00
|
|
|
const EVP_MD* md_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace rtc
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#endif // RTC_BASE_OPENSSL_DIGEST_H_
|