Files
WindowsXPKg/src/libumskt/libumskt.h

82 lines
2.3 KiB
C++

/**
* This file is a part of the UMSKT Project
*
* Copyleft (C) 2019-2024 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 06/24/2023
* @Maintainer Neo
*/
#ifndef UMSKT_LIBUMSKT_H
#define UMSKT_LIBUMSKT_H
#include "../typedefs.h"
#include <iostream>
#include <sstream>
#include <string>
#include <openssl/bn.h>
#include <openssl/ec.h>
#include <openssl/evp.h>
#include <openssl/rand.h>
#include <openssl/sha.h>
#include <fmt/core.h>
#include <fmt/format.h>
// Algorithm macros
#define PK_LENGTH 25
#define NULL_TERMINATOR 1
#define FIELD_BITS 384
#define FIELD_BYTES 48
#define FIELD_BITS_2003 512
#define FIELD_BYTES_2003 64
#define SHA_MSG_LENGTH_XP (4 + 2 * FIELD_BYTES)
#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)
#define HIBYTES(field, bytes) NEXTSNBITS((QWORD)(field), ((bytes)*8), ((bytes)*8))
#define LOBYTES(field, bytes) FIRSTNBITS((QWORD)(field), ((bytes)*8))
#define BYDWORD(n) (DWORD)(*((n) + 0) | *((n) + 1) << 8 | *((n) + 2) << 16 | *((n) + 3) << 24)
#define BITMASK(n) ((1ULL << (n)) - 1)
class UMSKT
{
public:
static std::FILE *debug;
static BOOL VERBOSE;
static BOOL DEBUG;
static void setDebugOutput(std::FILE *input);
template <typename T> static T getRandom()
{
T retval;
BIGNUM *bnrand = BN_new();
BN_rand(bnrand, sizeof(T) * 8, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY);
BN_bn2lebinpad(bnrand, (unsigned char *)&retval, sizeof(T));
BN_free(bnrand);
return retval;
}
};
#endif // UMSKT_LIBUMSKT_H