Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
InvoxiPlayGames committed Jan 12, 2024
0 parents commit 7138842
Show file tree
Hide file tree
Showing 68 changed files with 11,490 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Build

on: [push]

jobs:
Linux:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Compile
run: make
- name: Upload
uses: actions/upload-artifact@v2
with:
name: linux
path: |
xenon-bltool
macOS:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Compile
run: make
- name: Upload
uses: actions/upload-artifact@v2
with:
name: macos
path: |
xenon-bltool
Windows:
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: mingw64
install: make mingw-w64-x86_64-gcc
- name: Compile
run: make CC=gcc
- name: Upload
uses: actions/upload-artifact@v2
with:
name: windows-mingw64-gcc
path: |
xenon-bltool.exe
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# build artifacts
xenon-bltool.exe
xenon-bltool
# leftover files
out/
*.bin
*.dec
# extra annoyances
*.dSYM
.DS_Store
29 changes: 29 additions & 0 deletions 3rdparty/ExCrypt_LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2020, emoose
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 changes: 24 additions & 0 deletions 3rdparty/Xenia_LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2015, Ben Vanik.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the project nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL BEN VANIK BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 changes: 44 additions & 0 deletions 3rdparty/excrypt/excrypt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>

#define U8V(data) ((uint8_t)(data) & 0xFF)
#define ROTL8(data, bits) (U8V((data) << (bits)) | ((data) >> (8 - (bits))))

#define U16V(data) ((uint16_t)(data) & 0xFFFF)
#define ROTL16(data, bits) (U16V((data) << (bits)) | ((data) >> (16 - (bits))))

#define U32V(data) ((uint32_t)(data) & 0xFFFFFFFF)
#define ROTL32(data, bits) (U32V((data) << (bits)) | ((data) >> (32 - (bits))))

#define ROTL64(data, bits) (((data) << (bits)) | ((data) >> (64 - (bits))))

#ifndef SHOULD_BE_BE
#define BE16(i) ((((i) & 0xFF) << 8 | ((i) >> 8) & 0xFF) & 0xFFFF)
#define BE(i) (((i) & 0xff) << 24 | ((i) & 0xff00) << 8 | ((i) & 0xff0000) >> 8 | ((i) >> 24) & 0xff)
#define BE64(i) (BE((i) & 0xFFFFFFFF) << 32 | BE(((i) >> 32) & 0xFFFFFFFF))
#else
#define BE16(i) i
#define BE(i) i
#define BE64(i) i
#endif

typedef int BOOL;

#include "excrypt_aes.h"
#include "excrypt_bn.h"
#include "excrypt_des.h"
#include "excrypt_ecc.h"
#include "excrypt_md5.h"
#include "excrypt_mem.h"
#include "excrypt_parve.h"
#include "excrypt_rc4.h"
#include "excrypt_rotsum.h"
#include "excrypt_sha.h"
#include "excrypt_sha2.h"
#include "exkeys.h"
#ifdef __cplusplus
}
#endif
146 changes: 146 additions & 0 deletions 3rdparty/excrypt/excrypt_aes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#include <string.h>

#include "excrypt.h"

// reference rijndael implementation, from http://www.efgh.com/software/rijndael.htm
#include "rijndael.h"

// function signature shared between reference impl. and our AESNI versions
typedef void(*rijndaelCrypt_fn)(const unsigned long*, int, const unsigned char*, unsigned char*);

rijndaelCrypt_fn AesEnc = rijndaelEncrypt;
rijndaelCrypt_fn AesDec = rijndaelDecrypt;

void ExCryptAesKey(EXCRYPT_AES_STATE* state, const uint8_t* key)
{
rijndaelSetupEncrypt((unsigned long*)state->keytabenc, key, 128);
memcpy(state->keytabdec, state->keytabenc, sizeof(state->keytabdec));
rijndaelSetupDecrypt((unsigned long*)state->keytabdec, key, 128);
}

void ExCryptAesEcb(const EXCRYPT_AES_STATE* state, const uint8_t* input, uint8_t* output, uint8_t encrypt)
{
if (encrypt)
{
AesEnc((unsigned long*)state->keytabenc, 10, input, output);
}
else
{
AesDec((unsigned long*)state->keytabdec, 10, input, output);
}
}

void xorWithIv(const uint8_t* input, uint8_t* output, const uint8_t* iv)
{
for (uint32_t i = 0; i < AES_BLOCKLEN; i++)
{
output[i] = input[i] ^ iv[i];
}
}

void rijndaelCbcEncrypt(const unsigned long* rk, const uint8_t* input, uint32_t input_size, uint8_t* output, uint8_t* feed)
{
uint8_t* iv = feed;
for (uint32_t i = 0; i < input_size; i += AES_BLOCKLEN)
{
xorWithIv(input, output, iv);
AesEnc(rk, 10, output, output);
iv = output;
output += AES_BLOCKLEN;
input += AES_BLOCKLEN;
}
// store IV in feed param for next call
memcpy(feed, iv, AES_BLOCKLEN);
}

void rijndaelCbcDecrypt(const unsigned long* rk, const uint8_t* input, uint32_t input_size, uint8_t* output, uint8_t* feed)
{
const uint8_t* iv = feed;
for (uint32_t i = 0; i < input_size; i += AES_BLOCKLEN)
{
AesDec(rk, 10, input, output);
xorWithIv(output, output, iv);
iv = input;
output += AES_BLOCKLEN;
input += AES_BLOCKLEN;
}
// store IV in feed param for next call
memcpy(feed, iv, AES_BLOCKLEN);
}

void ExCryptAesCbc(const EXCRYPT_AES_STATE* state, const uint8_t* input, uint32_t input_size, uint8_t* output, uint8_t* feed, uint8_t encrypt)
{
if (encrypt)
{
rijndaelCbcEncrypt((unsigned long*)state->keytabenc, input, input_size, output, feed);
}
else
{
rijndaelCbcDecrypt((unsigned long*)state->keytabdec, input, input_size, output, feed);
}
}

unsigned long* aesschedule_dectable(EXCRYPT_AES_SCHEDULE* state)
{
return (unsigned long*)&state->keytab[state->num_rounds + 1]; // dec table starts at last entry of enc table
}

void ExCryptAesCreateKeySchedule(const uint8_t* key, uint32_t key_size, EXCRYPT_AES_SCHEDULE* state)
{
if (key_size != 0x10 && key_size != 0x18 && key_size != 0x20)
{
return; // invalid key size, must be 128/192/256 bits
}

state->num_rounds = (key_size >> 2) + 5; // seems to be nr - 1 ?

rijndaelSetupEncrypt((unsigned long*)state->keytab, key, key_size * 8);
memcpy(aesschedule_dectable(state), state->keytab, (state->num_rounds + 2) * 0x10);
rijndaelSetupDecrypt(aesschedule_dectable(state), key, key_size * 8);
}

void ExCryptAesCbcEncrypt(EXCRYPT_AES_SCHEDULE* state, const uint8_t* input, uint32_t input_size, uint8_t* output, uint8_t* feed)
{
uint8_t* iv = feed;
for (uint32_t i = 0; i < input_size; i += AES_BLOCKLEN)
{
xorWithIv(input, output, iv);
rijndaelEncrypt((unsigned long*)state->keytab, state->num_rounds + 1, output, output);
iv = output;
output += AES_BLOCKLEN;
input += AES_BLOCKLEN;
}
// store IV in feed param for next call
memcpy(feed, iv, AES_BLOCKLEN);
}

void ExCryptAesCbcDecrypt(EXCRYPT_AES_SCHEDULE* state, const uint8_t* input, uint32_t input_size, uint8_t* output, uint8_t* feed)
{
const uint8_t* iv = feed;
for (uint32_t i = 0; i < input_size; i += AES_BLOCKLEN)
{
rijndaelDecrypt(aesschedule_dectable(state), state->num_rounds + 1, input, output);
xorWithIv(output, output, iv);
iv = input;
output += AES_BLOCKLEN;
input += AES_BLOCKLEN;
}
// store IV in feed param for next call
memcpy(feed, iv, AES_BLOCKLEN);
}

void ExCryptAesEncryptOne(EXCRYPT_AES_SCHEDULE* state, const uint8_t* input, uint8_t* output)
{
uint8_t feed[0x10];
memset(feed, 0, 0x10);

ExCryptAesCbcEncrypt(state, input, 0x10, output, feed);
}

void ExCryptAesDecryptOne(EXCRYPT_AES_SCHEDULE* state, const uint8_t* input, uint8_t* output)
{
uint8_t feed[0x10];
memset(feed, 0, 0x10);

ExCryptAesCbcDecrypt(state, input, 0x10, output, feed);
}
33 changes: 33 additions & 0 deletions 3rdparty/excrypt/excrypt_aes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

typedef struct _EXCRYPT_AES_STATE
{
uint8_t keytabenc[11][4][4];
uint8_t keytabdec[11][4][4];
} EXCRYPT_AES_STATE;

#define AES_BLOCKLEN 16

void ExCryptAesKey(EXCRYPT_AES_STATE * state, const uint8_t * key);
void ExCryptAesEcb(const EXCRYPT_AES_STATE* state, const uint8_t* input, uint8_t* output, uint8_t encrypt);
void ExCryptAesCbc(const EXCRYPT_AES_STATE* state, const uint8_t* input, uint32_t input_size, uint8_t* output, uint8_t* feed, uint8_t encrypt);

// AES Schedule functions - allows using AES128/192/256

typedef struct _EXCRYPT_AES_SCHEDULE
{
uint8_t keytab[29][4][4];
uint32_t num_rounds; // actual nr = num_rounds + 1
} EXCRYPT_AES_SCHEDULE;

void ExCryptAesCreateKeySchedule(const uint8_t* key, uint32_t key_size, EXCRYPT_AES_SCHEDULE* state);

void ExCryptAesCbcEncrypt(EXCRYPT_AES_SCHEDULE* state, const uint8_t* input, uint32_t input_size, uint8_t* output, uint8_t* feed);
void ExCryptAesCbcDecrypt(EXCRYPT_AES_SCHEDULE* state, const uint8_t* input, uint32_t input_size, uint8_t* output, uint8_t* feed);

void ExCryptAesEncryptOne(EXCRYPT_AES_SCHEDULE* state, const uint8_t* input, uint8_t* output);
void ExCryptAesDecryptOne(EXCRYPT_AES_SCHEDULE* state, const uint8_t* input, uint8_t* output);

//void ExCryptAesCtr(const EXCRYPT_AES_STATE* pAesState, const uint8_t* input, uint32_t input_size, uint8_t* output, uint8_t* counter);
//void ExCryptAesCbcMac(const uint8_t* key, const uint8_t* input, uint32_t input_size, uint8_t* output);
//void ExCryptAesDmMac(const uint8_t* key, const uint8_t* input, uint32_t input_size, uint8_t* output);
Loading

0 comments on commit 7138842

Please sign in to comment.