WindowsXPKg/src/header.h

140 lines
3.6 KiB
C
Raw Normal View History

/**
2023-06-17 00:58:22 +03:00
* This file is a part of the UMSKT Project
*
2023-06-17 00:58:22 +03:00
* Copyleft (C) 2019-2023 UMSKT Contributors (et.al.)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @FileCreated by Neo on 5/26/2023
* @Maintainer Neo
*/
2023-06-01 16:09:22 +03:00
2023-06-17 00:58:22 +03:00
#ifndef UMSKT_HEADER_H
#define UMSKT_HEADER_H
2023-06-01 16:09:22 +03:00
#ifdef DEBUG
2023-06-01 16:09:22 +03:00
#include <cassert>
#else
#define assert(x) /* nothing */
#endif
2023-06-01 16:09:22 +03:00
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <ctime>
2023-06-01 23:09:44 +03:00
#include <random>
#include <iostream>
#include <fstream>
#include <filesystem>
2023-06-01 16:09:22 +03:00
#include <string>
#include <vector>
#include <unordered_map>
#include <fmt/core.h>
#include <nlohmann/json.hpp>
2023-06-01 16:09:22 +03:00
#include <openssl/bn.h>
#include <openssl/ec.h>
#include <openssl/sha.h>
#include <openssl/evp.h>
2023-06-01 16:09:22 +03:00
#include <openssl/rand.h>
2023-06-02 17:13:57 +03:00
// Algorithm macros
#define PK_LENGTH 25
#define NULL_TERMINATOR 1
2023-06-01 16:09:22 +03:00
#define FIELD_BITS 384
#define FIELD_BYTES 48
#define FIELD_BITS_2003 512
#define FIELD_BYTES_2003 64
2023-06-01 16:09:22 +03:00
#define SHA_MSG_LENGTH_XP (4 + 2 * FIELD_BYTES)
2023-06-05 00:27:50 +03:00
#define SHA_MSG_LENGTH_2003 (3 + 2 * FIELD_BYTES_2003)
#define NEXTSNBITS(field, n, offset) (((QWORD)(field) >> (offset)) & ((1ULL << (n)) - 1))
#define FIRSTNBITS(field, n) NEXTSNBITS((field), (n), 0)
2023-06-04 15:06:51 +03:00
#define HIBYTES(field, bytes) NEXTSNBITS((QWORD)(field), ((bytes) * 8), ((bytes) * 8))
#define LOBYTES(field, bytes) FIRSTNBITS((QWORD)(field), ((bytes) * 8))
2023-06-05 15:07:31 +03:00
#define BYDWORD(n) (DWORD)(*((n) + 0) | *((n) + 1) << 8 | *((n) + 2) << 16 | *((n) + 3) << 24)
#define BITMASK(n) ((1ULL << (n)) - 1)
using json = nlohmann::json;
namespace fs = std::filesystem;
2023-06-07 22:23:59 +03:00
enum MODE {
MODE_BINK1998_GENERATE = 0,
MODE_BINK2002_GENERATE = 1,
2023-06-07 22:23:59 +03:00
MODE_CONFIRMATION_ID = 2,
MODE_BINK1998_VALIDATE = 3,
MODE_BINK2002_VALIDATE = 4,
2023-06-07 22:23:59 +03:00
};
struct Options {
std::string binkid;
std::string keysFilename;
std::string instid;
std::string keyToCheck;
2023-06-07 22:23:59 +03:00
int channelID;
bool serialSet;
int serial;
2023-06-07 22:23:59 +03:00
int numKeys;
bool verbose;
bool help;
bool error;
bool list;
MODE applicationMode;
};
2023-06-02 17:13:57 +03:00
// Type definitions
2023-06-10 19:40:18 +03:00
typedef bool BOOL;
2023-06-02 17:13:57 +03:00
typedef uint8_t BYTE;
typedef uint16_t WORD;
typedef uint32_t DWORD;
typedef uint64_t QWORD;
2023-06-01 16:09:22 +03:00
2023-06-07 22:23:59 +03:00
#ifdef __SIZEOF_INT128__
2023-06-09 21:07:29 +03:00
typedef unsigned __int128 OWORD;
2023-06-07 22:23:59 +03:00
#endif
2023-06-02 17:13:57 +03:00
// Global variables
2023-06-10 19:38:22 +03:00
extern Options options;
2023-06-01 16:09:22 +03:00
// util.cpp
int BN_bn2lebin(const BIGNUM *a, unsigned char *to, int tolen); // Hello OpenSSL developers, please tell me, where is this function at?
2023-06-04 13:31:24 +03:00
void endian(BYTE *data, int length);
EC_GROUP *initializeEllipticCurve(
2023-06-02 17:13:57 +03:00
std::string pSel,
std::string aSel,
std::string bSel,
std::string generatorXSel,
std::string generatorYSel,
std::string publicKeyXSel,
std::string publicKeyYSel,
2023-06-09 21:07:29 +03:00
EC_POINT *&genPoint,
EC_POINT *&pubPoint
);
2023-06-01 16:09:22 +03:00
// key.cpp
extern char pKeyCharset[];
void unbase24(BYTE *byteSeq, const char *cdKey);
void base24(char *cdKey, BYTE *byteSeq);
2023-06-01 16:09:22 +03:00
2023-06-17 00:58:22 +03:00
#endif //UMSKT_HEADER_H