2017-09-19 04:34:08 -04:00
|
|
|
|
2014-04-29 11:37:15 -04:00
|
|
|
// Sha1Checksum.h
|
|
|
|
|
|
|
|
// Declares the cSha1Checksum class representing the SHA-1 checksum calculator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-08-30 10:00:06 -04:00
|
|
|
#include "mbedtls/sha1.h"
|
2014-04-29 11:37:15 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Calculates a SHA1 checksum for data stream */
|
|
|
|
class cSha1Checksum
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef Byte Checksum[20]; // The type used for storing the checksum
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-29 11:37:15 -04:00
|
|
|
cSha1Checksum(void);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-29 11:37:15 -04:00
|
|
|
/** Adds the specified data to the checksum */
|
|
|
|
void Update(const Byte * a_Data, size_t a_Length);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-29 11:37:15 -04:00
|
|
|
/** Calculates and returns the final checksum */
|
|
|
|
void Finalize(Checksum & a_Output);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-29 11:37:15 -04:00
|
|
|
/** Returns true if the object is accepts more input data, false if Finalize()-d (need to Restart()) */
|
|
|
|
bool DoesAcceptInput(void) const { return m_DoesAcceptInput; }
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2020-04-07 17:23:54 -04:00
|
|
|
/** Converts a SHA1 digest into hex */
|
|
|
|
static void DigestToHex(const Checksum & a_Digest, AString & a_Out);
|
|
|
|
|
2014-04-29 11:37:15 -04:00
|
|
|
/** Converts a raw 160-bit SHA1 digest into a Java Hex representation
|
2017-08-24 05:19:40 -04:00
|
|
|
According to http://wiki.vg/Protocol_Encryption
|
2014-04-29 11:37:15 -04:00
|
|
|
*/
|
2020-04-07 17:23:54 -04:00
|
|
|
static void DigestToJava(const Checksum & a_Digest, AString & a_Out);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-29 11:37:15 -04:00
|
|
|
/** Clears the current context and start a new checksum calculation */
|
|
|
|
void Restart(void);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-04-29 11:37:15 -04:00
|
|
|
protected:
|
|
|
|
/** True if the object is accepts more input data, false if Finalize()-d (need to Restart()) */
|
|
|
|
bool m_DoesAcceptInput;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2017-08-30 10:00:06 -04:00
|
|
|
mbedtls_sha1_context m_Sha1;
|
2014-04-29 11:37:15 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|