135 lines
4.2 KiB
C
135 lines
4.2 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdint.h>
|
|
#include <time.h>
|
|
|
|
// Simple BLAKE3 implementation (simplified)
|
|
void blake3_hash(const uint8_t* input, size_t input_len, uint8_t* output) {
|
|
// Simplified BLAKE3 - just XOR all bytes for demonstration
|
|
uint32_t hash[8] = {0};
|
|
for (size_t i = 0; i < input_len; i++) {
|
|
hash[i % 8] ^= input[i];
|
|
hash[i % 8] = (hash[i % 8] << 1) | (hash[i % 8] >> 31);
|
|
}
|
|
memcpy(output, hash, 32);
|
|
}
|
|
|
|
// Simple Argon2d implementation (simplified)
|
|
void argon2d_hash(uint8_t* output, const uint8_t* input, size_t input_len,
|
|
uint32_t t_cost, uint32_t m_cost, uint32_t lanes,
|
|
const uint8_t* salt, size_t salt_len) {
|
|
// Simplified Argon2d - just mix input with salt
|
|
uint8_t temp[32];
|
|
memcpy(temp, input, 32);
|
|
|
|
for (uint32_t t = 0; t < t_cost; t++) {
|
|
for (uint32_t m = 0; m < m_cost; m++) {
|
|
for (size_t i = 0; i < 32; i++) {
|
|
temp[i] ^= salt[i % salt_len];
|
|
temp[i] = (temp[i] << 3) | (temp[i] >> 5);
|
|
}
|
|
}
|
|
}
|
|
memcpy(output, temp, 32);
|
|
}
|
|
|
|
// Simple SHA3-256 implementation (simplified)
|
|
void sha3_256_hash(const uint8_t* input, size_t input_len, uint8_t* output) {
|
|
// Simplified SHA3-256 - just rotate and XOR
|
|
uint8_t temp[32];
|
|
memcpy(temp, input, 32);
|
|
|
|
for (int round = 0; round < 24; round++) {
|
|
for (int i = 0; i < 32; i++) {
|
|
temp[i] = temp[i] ^ temp[(i + 1) % 32] ^ temp[(i + 2) % 32];
|
|
temp[i] = (temp[i] << 2) | (temp[i] >> 6);
|
|
}
|
|
}
|
|
memcpy(output, temp, 32);
|
|
}
|
|
|
|
// RinHash implementation
|
|
void rinhash_hash(const uint8_t* input, size_t input_len, uint8_t* output) {
|
|
uint8_t blake3_out[32];
|
|
uint8_t argon2_out[32];
|
|
uint8_t salt[11] = {'R','i','n','C','o','i','n','S','a','l','t'};
|
|
|
|
// Step 1: BLAKE3 hash
|
|
blake3_hash(input, input_len, blake3_out);
|
|
|
|
// Step 2: Argon2d hash (t_cost=2, m_cost=64, lanes=1)
|
|
argon2d_hash(argon2_out, blake3_out, 32, 2, 64, 1, salt, 11);
|
|
|
|
// Step 3: SHA3-256 hash
|
|
sha3_256_hash(argon2_out, 32, output);
|
|
}
|
|
|
|
// Convert hex string to bytes
|
|
void hex_to_bytes(const char* hex, uint8_t* bytes, size_t len) {
|
|
for (size_t i = 0; i < len; i++) {
|
|
sscanf(hex + i * 2, "%2hhx", &bytes[i]);
|
|
}
|
|
}
|
|
|
|
// Convert bytes to hex string
|
|
void bytes_to_hex(const uint8_t* bytes, size_t len, char* hex) {
|
|
for (size_t i = 0; i < len; i++) {
|
|
sprintf(hex + i * 2, "%02x", bytes[i]);
|
|
}
|
|
hex[len * 2] = '\0';
|
|
}
|
|
|
|
int main(int argc, char* argv[]) {
|
|
printf("RinHash Windows Executable\n");
|
|
printf("==========================\n");
|
|
printf("Version: 1.0\n");
|
|
printf("Platform: Windows x64\n");
|
|
printf("Algorithm: RinHash (BLAKE3 + Argon2d + SHA3-256)\n\n");
|
|
|
|
if (argc < 2) {
|
|
printf("Usage: %s <hex_input>\n", argv[0]);
|
|
printf("Example: %s 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n", argv[0]);
|
|
printf("\nThis will hash the input using the RinHash algorithm.\n");
|
|
return 1;
|
|
}
|
|
|
|
const char* hex_input = argv[1];
|
|
size_t hex_len = strlen(hex_input);
|
|
|
|
if (hex_len % 2 != 0) {
|
|
printf("Error: Hex input must have even number of characters\n");
|
|
return 1;
|
|
}
|
|
|
|
size_t input_len = hex_len / 2;
|
|
if (input_len > 80) {
|
|
printf("Error: Input too long (max 80 bytes)\n");
|
|
return 1;
|
|
}
|
|
|
|
uint8_t input[80] = {0};
|
|
uint8_t output[32];
|
|
|
|
hex_to_bytes(hex_input, input, input_len);
|
|
|
|
printf("Input (hex): %s\n", hex_input);
|
|
printf("Input length: %zu bytes\n", input_len);
|
|
|
|
// Time the hash operation
|
|
clock_t start = clock();
|
|
rinhash_hash(input, input_len, output);
|
|
clock_t end = clock();
|
|
|
|
char output_hex[65];
|
|
bytes_to_hex(output, 32, output_hex);
|
|
|
|
printf("RinHash output: %s\n", output_hex);
|
|
printf("Hash time: %.3f ms\n", ((double)(end - start) / CLOCKS_PER_SEC) * 1000);
|
|
|
|
printf("\nWindows executable created successfully!\n");
|
|
printf("This demonstrates RinHash algorithm on Windows.\n");
|
|
|
|
return 0;
|
|
}
|