154 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-09 18:50:47 -08:00
enum CONFIRMATION_ID_STATUS {
SUCCESS = 0,
ERR_TOO_SHORT = 1,
ERR_TOO_LARGE = 2,
ERR_INVALID_CHARACTER = 3,
ERR_INVALID_CHECK_DIGIT = 4,
ERR_UNKNOWN_VERSION = 5,
ERR_UNLUCKY = 6
};
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
typedef struct {
QWORD u[2];
QWORD v[2];
} TDivisor;
2023-12-09 18:50:47 -08:00
enum ACTIVATION_ALGORITHM {
WINDOWS = 0,
OFFICE_XP = 1,
OFFICE_2K3 = 2,
OFFICE_2K7 = 3,
PLUS_DME = 4,
};
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
EXPORT class ConfirmationID {
2023-12-09 18:50:47 -08:00
QWORD MOD = 0, NON_RESIDUE = 0;
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-09 18:50:47 -08:00
unsigned char iid_key[4] = { 0x0, 0x0, 0x0, 0x0};
BOOL isOffice = false, isXPBrand = false;
unsigned flagVersion = 0;
2023-06-07 12:23:59 -07:00
public:
2023-12-09 18:50:47 -08:00
void setFlagVersion(unsigned int flagVersion);
private:
int calculateCheckDigit(int pid);
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);
friend class Residue;
Residue *residue;
friend class Polynomial;
Polynomial *polynomial;
friend class Divisor;
Divisor *divisor;
public:
int Generate(const char* installation_id_str, char confirmation_id[49], std::string productid);
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);
ConfirmationID() {
residue = new Residue(this);
polynomial = new Polynomial(this);
divisor = new Divisor(this);
}
~ConfirmationID() {
delete residue, polynomial, divisor;
}
2023-06-07 12:23:59 -07:00
};
2023-12-09 18:50:47 -08:00
class Residue {
ConfirmationID *parent;
public:
explicit Residue(ConfirmationID *in) {
parent = in;
}
QWORD add(QWORD x, QWORD y);
QWORD sub(QWORD x, QWORD y);
QWORD __umul128(QWORD a, QWORD b, QWORD* hi);
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);
};
class Polynomial {
ConfirmationID *parent;
public:
explicit Polynomial(ConfirmationID *in) {
parent = in;
}
int mul(int adeg, const QWORD a[], int bdeg, const QWORD b[], int resultprevdeg, QWORD result[]);
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]);
};
class Divisor {
ConfirmationID *parent;
public:
explicit Divisor(ConfirmationID *in) {
parent = in;
}
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-06-16 14:58:22 -07:00
#endif //UMSKT_CONFID_H