#ifndef ENCRYPTIONIDENTIFY_H #define ENCRYPTIONIDENTIFY_H #include #include #include #include #include #include typedef unsigned char BYTE; // 8-bit byte typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines typedef struct { unsigned char data[64]; // current 512-bit chunk of message data, just like a buffer unsigned int datalen; // sign the data length of current chunk unsigned long long bitlen; // the bit length of the total message unsigned int state[8]; // store the middle state of hash abstract } SHA256_CTX; /** * @brief 封装的加密认证类 * */ class EncryptionIdentify { public: /** * @brief Construct a new Encryption Identify object - default * */ EncryptionIdentify(); /** * @brief Construct a new EncryptionIdentify object * */ EncryptionIdentify(std::string cryptFilePath); /** * @brief Destroy the EncryptionIdentify object * */ ~EncryptionIdentify(); public: int init(); private: int readEncryptMapValue(); void sha256_transform(SHA256_CTX *ctx, const BYTE data[]); void sha256_init(SHA256_CTX *ctx); void sha256_update(SHA256_CTX *ctx, const BYTE data[], size_t len); void sha256_final(SHA256_CTX *ctx, BYTE hash[]); public: void genZZ(unsigned int equipmentCode); private: std::vector split(const std::string &str, const std::string &pattern); unsigned short safeMapXYtoR(unsigned char X, unsigned char Y); public: int combineData(unsigned short & R, unsigned char hash[], unsigned char * dBodyBuf, int dBodyLen); private: unsigned char swapBit8(unsigned char & byte8); unsigned short swapBit16(unsigned short & buf16); unsigned short genJMByCRC16IBM(unsigned char * buf, int len); private: std::string filePath; SHA256_CTX * ctx; BYTE hash[32]; unsigned short A[256][256]; public: unsigned char * buf; }; #endif // !ENCRYPTIONIDENTIFY_H