Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions fizz/crypto/Sha-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@

namespace fizz {

template <typename T>
void Sha<T>::hash_init() {
digest_.hash_init(T::HashEngine());
}

template <typename T>
void Sha<T>::hash_update(folly::ByteRange data) {
digest_.hash_update(data);
}

template <typename T>
void Sha<T>::hash_update(const folly::IOBuf& data) {
digest_.hash_update(data);
}

template <typename T>
void Sha<T>::hash_final(folly::MutableByteRange out) {
digest_.hash_final(out);
}

template <typename T>
void Sha<T>::hmac(
folly::ByteRange key,
Expand Down
14 changes: 13 additions & 1 deletion fizz/crypto/Sha.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ namespace fizz {
* - BlankHash: ByteRange containing the digest of a hash of empty input
*/
template <typename T>
struct Sha {
class Sha {
public:
void hash_init();

void hash_update(folly::ByteRange data);

void hash_update(const folly::IOBuf& data);

void hash_final(folly::MutableByteRange out);

/**
* Puts HMAC(key, in) into out. Out must be at least of size HashLen.
*/
Expand All @@ -36,6 +45,9 @@ struct Sha {
* Puts Hash(in) into out. Out must be at least of size HashLen.
*/
static void hash(const folly::IOBuf& in, folly::MutableByteRange out);

private:
folly::ssl::OpenSSLHash::Digest digest_;
};
} // namespace fizz
#include <fizz/crypto/Sha-inl.h>
3 changes: 2 additions & 1 deletion fizz/crypto/Sha256.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

namespace fizz {

struct Sha256 : Sha<Sha256> {
class Sha256 : public Sha<Sha256> {
public:
static constexpr size_t HashLen = 32;

static constexpr auto HashEngine = EVP_sha256;
Expand Down
3 changes: 2 additions & 1 deletion fizz/crypto/Sha384.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

namespace fizz {

struct Sha384 : Sha<Sha384> {
class Sha384 : public Sha<Sha384> {
public:
static constexpr size_t HashLen = 48;

static constexpr auto HashEngine = EVP_sha384;
Expand Down
5 changes: 2 additions & 3 deletions fizz/protocol/HandshakeContext-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ template <typename Hash>
HandshakeContextImpl<Hash>::HandshakeContextImpl(
const std::string& hkdfLabelPrefix)
: hkdfLabelPrefix_(hkdfLabelPrefix) {
hashState_ = folly::ssl::OpenSSLHash::Digest();
hashState_.hash_init(Hash::HashEngine());
hashState_.hash_init();
}

template <typename Hash>
Expand All @@ -25,7 +24,7 @@ void HandshakeContextImpl<Hash>::appendToTranscript(const Buf& data) {

template <typename Hash>
Buf HandshakeContextImpl<Hash>::getHandshakeContext() const {
folly::ssl::OpenSSLHash::Digest copied(hashState_);
Hash copied(hashState_);
auto out = folly::IOBuf::create(Hash::HashLen);
out->append(Hash::HashLen);
folly::MutableByteRange outRange(out->writableData(), out->length());
Expand Down
3 changes: 1 addition & 2 deletions fizz/protocol/HandshakeContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#pragma once

#include <fizz/record/Types.h>
#include <folly/ssl/OpenSSLHash.h>

namespace fizz {

Expand Down Expand Up @@ -59,7 +58,7 @@ class HandshakeContextImpl : public HandshakeContext {
}

private:
folly::ssl::OpenSSLHash::Digest hashState_;
Hash hashState_;
std::string hkdfLabelPrefix_;
};
} // namespace fizz
Expand Down