166 lines
4.3 KiB
C
Raw Normal View History

/**
2023-06-16 14:58:22 -07:00
* This file is a part of the UMSKT Project
*
2023-06-16 14:58:22 -07: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 6/6/2023
* @Maintainer Neo
*/
2023-06-07 12:23:59 -07:00
2023-06-16 14:58:22 -07:00
#ifndef UMSKT_CONFID_H
#define UMSKT_CONFID_H
2023-06-07 12:23:59 -07:00
Refactor/Overhaul (#40) * major refactor/overhaul move generation implementation to libumskt/* decouple CLI/Options (and JSON) from generation implementation set groundwork for future shared library use standardized PIDGEN2/PIDGEN3 naming convention create a Windows Docker file for quick compilation add Windows resouce file/header so we have an application icon on windows use icon from @Endermanch (used with permission) add support for fully-static linux/muslc-based compilation add support for a dos/windows (i486+) binary using djgpp add Dockerfile to compile gcc/djgpp/watt32/openssl to provide DOS (DPMI) binaries add @Endermanch 's Vista+ documentation update Readme for recent credits * begin work on C linkage and emscripten buildpath * Update CMake to include and build Crypto++ * move dllmain.cpp to the correct directory * add rust port info to README.md * re-add dropped changes from rebase * update build config, specify windows XP version number for crypto++ * update dos-djgpp action to use new cmake builder and options * update dos-djgpp to use UMSKT hosted forks * update other workflows to include standard header * remove crypto++ from build config for now * use the new `shell` parameter in `threeal/cmake-action` TODO: move to a stable version (v1.3.0) when ready * use full commit hash because a shortened hash is unsupported * add the required {0} parameter? * add openssl 3.1.1 to windows github runners * ensure linux matrix build compiles on the correct arch --------- Co-authored-by: Neo <321592+Neo-Desktop@users.noreply.github.com>
2023-07-09 00:08:43 -03:00
#include "../libumskt.h"
2023-06-07 12:23:59 -07:00
// Confirmation ID generator constants
2023-12-10 04:06:42 -08:00
enum CONFIRMATION_ID_STATUS
{
SUCCESS = 0,
ERR_TOO_SHORT = 1,
ERR_TOO_LARGE = 2,
ERR_INVALID_CHARACTER = 3,
2023-12-09 18:50:47 -08:00
ERR_INVALID_CHECK_DIGIT = 4,
2023-12-10 04:06:42 -08:00
ERR_UNKNOWN_VERSION = 5,
ERR_UNLUCKY = 6
2023-12-09 18:50:47 -08:00
};
2023-06-07 12:23:59 -07:00
2023-12-09 18:50:47 -08:00
#define BAD 0xFFFFFFFFFFFFFFFFull
2023-06-07 12:23:59 -07:00
2023-12-10 04:06:42 -08:00
typedef struct
{
2023-06-07 12:23:59 -07:00
QWORD u[2];
QWORD v[2];
} TDivisor;
2023-12-10 04:06:42 -08:00
enum ACTIVATION_ALGORITHM
{
WINDOWS = 0,
OFFICE_XP = 1,
OFFICE_2K3 = 2,
OFFICE_2K7 = 3,
PLUS_DME = 4,
2023-12-09 18:50:47 -08:00
};
2023-12-10 04:06:42 -08:00
EXPORT class ConfirmationID
{
2023-12-09 18:50:47 -08:00
QWORD MOD = 0, NON_RESIDUE = 0;
2023-12-10 04:06:42 -08:00
QWORD f[6] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
QWORD p[4] = {0x0, 0x0, 0x0, 0x0};
QWORD u[2] = {0x0, 0x0};
2023-06-07 12:23:59 -07:00
2023-12-10 04:06:42 -08:00
unsigned char iid_key[4] = {0x0, 0x0, 0x0, 0x0};
2023-12-09 18:50:47 -08:00
BOOL isOffice = false, isXPBrand = false;
unsigned flagVersion = 0;
2023-12-10 04:06:42 -08:00
public:
void setFlagVersion(unsigned int flagVersion);
2023-12-09 18:50:47 -08:00
2023-12-10 04:06:42 -08:00
private:
2023-12-09 18:50:47 -08:00
int calculateCheckDigit(int pid);
2023-12-10 04:06:42 -08:00
void decode_iid_new_version(unsigned char *iid, unsigned char *hwid, int *version);
void Mix(unsigned char *buffer, size_t bufSize, const unsigned char *key, size_t keySize);
void Unmix(unsigned char *buffer, size_t bufSize, const unsigned char *key, size_t keySize);
2023-12-09 18:50:47 -08:00
friend class Residue;
Residue *residue;
friend class Polynomial;
Polynomial *polynomial;
friend class Divisor;
Divisor *divisor;
2023-12-10 04:06:42 -08:00
public:
int Generate(const char *installation_id_str, char confirmation_id[49], std::string productid);
2023-12-09 18:50:47 -08:00
void setMod(QWORD mod);
void setNonResidue(QWORD nonResidue);
void setPValues(QWORD p0, QWORD p1, QWORD p2, QWORD p3);
void setPValues(QWORD pValues[4]);
void setFValues(QWORD f0, QWORD f1, QWORD f2, QWORD f3, QWORD f4, QWORD f5);
void setFValues(QWORD fValues[6]);
void setIsOffice(BOOL isOffice);
void setIsXPBrand(BOOL isXpBrand);
2023-12-10 04:06:42 -08:00
ConfirmationID()
{
2023-12-09 18:50:47 -08:00
residue = new Residue(this);
polynomial = new Polynomial(this);
divisor = new Divisor(this);
}
2023-12-10 04:06:42 -08:00
~ConfirmationID()
{
2023-12-09 18:50:47 -08:00
delete residue, polynomial, divisor;
}
2023-06-07 12:23:59 -07:00
};
2023-12-10 04:06:42 -08:00
class Residue
{
2023-12-09 18:50:47 -08:00
ConfirmationID *parent;
2023-12-10 04:06:42 -08:00
public:
explicit Residue(ConfirmationID *in)
{
2023-12-09 18:50:47 -08:00
parent = in;
}
QWORD add(QWORD x, QWORD y);
QWORD sub(QWORD x, QWORD y);
2023-12-10 04:06:42 -08:00
QWORD __umul128(QWORD a, QWORD b, QWORD *hi);
2023-12-09 18:50:47 -08:00
QWORD ui128_quotient_mod(QWORD lo, QWORD hi);
QWORD mul(QWORD x, QWORD y);
QWORD pow(QWORD x, QWORD y);
QWORD inverse(QWORD u, QWORD v);
QWORD inv(QWORD x);
QWORD sqrt(QWORD what);
};
2023-12-10 04:06:42 -08:00
class Polynomial
{
2023-12-09 18:50:47 -08:00
ConfirmationID *parent;
2023-12-10 04:06:42 -08:00
public:
explicit Polynomial(ConfirmationID *in)
{
2023-12-09 18:50:47 -08:00
parent = in;
}
int mul(int adeg, const QWORD a[], int bdeg, const QWORD b[], int resultprevdeg, QWORD result[]);
2023-12-10 04:06:42 -08:00
int div_monic(int adeg, QWORD a[], int bdeg, const QWORD b[], QWORD *quotient);
void xgcd(int adeg, const QWORD a[3], int bdeg, const QWORD b[3], int *pgcddeg, QWORD gcd[3], int *pmult1deg,
QWORD mult1[3], int *pmult2deg, QWORD mult2[3]);
int u2poly(const TDivisor *src, QWORD polyu[3], QWORD polyv[2]);
2023-12-09 18:50:47 -08:00
};
2023-12-10 04:06:42 -08:00
class Divisor
{
2023-12-09 18:50:47 -08:00
ConfirmationID *parent;
2023-12-10 04:06:42 -08:00
public:
explicit Divisor(ConfirmationID *in)
{
2023-12-09 18:50:47 -08:00
parent = in;
}
2023-12-10 04:06:42 -08:00
int find_divisor_v(TDivisor *d);
void add(const TDivisor *src1, const TDivisor *src2, TDivisor *dst);
void mul(const TDivisor *src, QWORD mult, TDivisor *dst);
void mul128(const TDivisor *src, QWORD mult_lo, QWORD mult_hi, TDivisor *dst);
2023-12-09 18:50:47 -08:00
};
2023-12-10 04:06:42 -08:00
#endif // UMSKT_CONFID_H