mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-08 22:17:03 +02:00
Quick trial of HMAC-MD5 auth + timings
This commit is contained in:
parent
82b68fce8d
commit
480f76c21a
3 changed files with 33 additions and 3 deletions
|
@ -13,6 +13,12 @@
|
||||||
|
|
||||||
#include "HmacAuth.h"
|
#include "HmacAuth.h"
|
||||||
|
|
||||||
|
#define HIFI_HASH_TIMINGS
|
||||||
|
#ifdef HIFI_HASH_TIMINGS
|
||||||
|
#include "NetworkLogging.h"
|
||||||
|
#include "SharedUtil.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
int NLPacket::localHeaderSize(PacketType type) {
|
int NLPacket::localHeaderSize(PacketType type) {
|
||||||
bool nonSourced = PacketTypeEnum::getNonSourcedPackets().contains(type);
|
bool nonSourced = PacketTypeEnum::getNonSourcedPackets().contains(type);
|
||||||
bool nonVerified = PacketTypeEnum::getNonVerifiedPackets().contains(type);
|
bool nonVerified = PacketTypeEnum::getNonVerifiedPackets().contains(type);
|
||||||
|
@ -230,7 +236,19 @@ void NLPacket::writeVerificationHashGivenSecret(const QUuid& connectionSecret) c
|
||||||
|
|
||||||
auto offset = Packet::totalHeaderSize(isPartOfMessage()) + sizeof(PacketType) + sizeof(PacketVersion)
|
auto offset = Packet::totalHeaderSize(isPartOfMessage()) + sizeof(PacketType) + sizeof(PacketVersion)
|
||||||
+ NUM_BYTES_RFC4122_UUID;
|
+ NUM_BYTES_RFC4122_UUID;
|
||||||
|
#ifdef HIFI_HASH_TIMINGS
|
||||||
|
static quint64 totalTime = 0;
|
||||||
|
static int timedHashes = 0;
|
||||||
|
quint64 startTime = usecTimestampNow();
|
||||||
|
#endif
|
||||||
QByteArray verificationHash = hashForPacketAndSecret(*this, connectionSecret);
|
QByteArray verificationHash = hashForPacketAndSecret(*this, connectionSecret);
|
||||||
|
#ifdef HIFI_HASH_TIMINGS
|
||||||
|
quint64 endTime = usecTimestampNow();
|
||||||
|
totalTime += endTime - startTime;
|
||||||
|
if ((++timedHashes % 20) == 0) {
|
||||||
|
qCDebug(networking) << "Average packet hash time " << (totalTime / timedHashes / 1000.0f) << " ms";
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
memcpy(_packet.get() + offset, verificationHash.data(), verificationHash.size());
|
memcpy(_packet.get() + offset, verificationHash.data(), verificationHash.size());
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,10 +22,22 @@ bool HmacAuth::setKey(const char * keyValue, int keyLen) {
|
||||||
|
|
||||||
switch (_authMethod)
|
switch (_authMethod)
|
||||||
{
|
{
|
||||||
|
case MD5:
|
||||||
|
sslStruct = EVP_md5();
|
||||||
|
break;
|
||||||
|
|
||||||
case SHA1:
|
case SHA1:
|
||||||
sslStruct = EVP_sha1();
|
sslStruct = EVP_sha1();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SHA224:
|
||||||
|
sslStruct = EVP_sha224();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SHA256:
|
||||||
|
sslStruct = EVP_sha256();
|
||||||
|
break;
|
||||||
|
|
||||||
case RIPEMD160:
|
case RIPEMD160:
|
||||||
sslStruct = EVP_ripemd160();
|
sslStruct = EVP_ripemd160();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -13,10 +13,10 @@ class QUuid;
|
||||||
|
|
||||||
class HmacAuth {
|
class HmacAuth {
|
||||||
public:
|
public:
|
||||||
enum AuthMethod { SHA1, RIPEMD160 };
|
enum AuthMethod { MD5, SHA1, SHA224, SHA256, RIPEMD160 };
|
||||||
typedef std::vector<unsigned char> HmacHash;
|
typedef std::vector<unsigned char> HmacHash;
|
||||||
|
|
||||||
HmacAuth(AuthMethod authMethod = SHA1);
|
explicit HmacAuth(AuthMethod authMethod = MD5);
|
||||||
~HmacAuth();
|
~HmacAuth();
|
||||||
|
|
||||||
bool setKey(const char * keyValue, int keyLen);
|
bool setKey(const char * keyValue, int keyLen);
|
||||||
|
@ -26,7 +26,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<hmac_ctx_st> _hmacContext;
|
std::unique_ptr<hmac_ctx_st> _hmacContext;
|
||||||
AuthMethod _authMethod { SHA1 };
|
AuthMethod _authMethod { MD5 };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_HmacAuth_h
|
#endif // hifi_HmacAuth_h
|
||||||
|
|
Loading…
Reference in a new issue