111 lines
3.4 KiB
C
111 lines
3.4 KiB
C
#include "cpuminer-config.h"
|
|
#include "miner.h"
|
|
|
|
#include "yespower-1.0.1/yespower.h"
|
|
#include "yespower.h"
|
|
#include "sysendian.h"
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <inttypes.h>
|
|
|
|
const yespower_params_t *select_yespower_params(const char *cpu_info) {
|
|
#ifdef __arm__
|
|
if (strstr(cpu_info, "BCM2837") || strstr(cpu_info, "BCM2711")) {
|
|
static const yespower_params_t params_rpi = {
|
|
.version = YESPOWER_1_0,
|
|
.N = 2048,
|
|
.r = 8,
|
|
.pers = (const uint8_t *)"Raspberry",
|
|
.perslen = 7
|
|
};
|
|
return ¶ms_rpi;
|
|
} else if (strstr(cpu_info, "BCM2712")) {
|
|
static const yespower_params_t params_rpi5 = {
|
|
.version = YESPOWER_1_0,
|
|
.N = 3072,
|
|
.r = 12,
|
|
.pers = (const uint8_t *)"Raspberry5",
|
|
.perslen = 7
|
|
};
|
|
return ¶ms_rpi5;
|
|
} else {
|
|
// ARM-Server
|
|
static const yespower_params_t params_arm_server = {
|
|
.version = YESPOWER_1_0,
|
|
.N = 4096,
|
|
.r = 16,
|
|
.pers = (const uint8_t *)"ARMServer",
|
|
.perslen = 10
|
|
};
|
|
return ¶ms_arm_server;
|
|
}
|
|
#else
|
|
static const yespower_params_t params_default = {
|
|
.version = YESPOWER_1_0,
|
|
.N = 4096,
|
|
.r = 16,
|
|
.pers = (const uint8_t *)"Default",
|
|
.perslen = 7
|
|
};
|
|
return ¶ms_default;
|
|
#endif
|
|
}
|
|
static void get_cpu_info(char *cpu_info, size_t max_size) {
|
|
#ifdef __arm__
|
|
FILE *cpuinfo_file = fopen("/proc/cpuinfo", "r");
|
|
if (cpuinfo_file) {
|
|
fread(cpu_info, 1, max_size - 1, cpuinfo_file);
|
|
fclose(cpuinfo_file);
|
|
cpu_info[max_size - 1] = '\0';
|
|
} else {
|
|
strncpy(cpu_info, "Unknown ARM", max_size);
|
|
}
|
|
#else
|
|
strncpy(cpu_info, "x86/x64", max_size);
|
|
#endif
|
|
}
|
|
|
|
int yespower_hash(const char *input, char *output) {
|
|
char cpu_info[256] = {0};
|
|
get_cpu_info(cpu_info, sizeof(cpu_info));
|
|
|
|
const yespower_params_t *params = select_yespower_params(cpu_info);
|
|
return yespower_tls(input, 80, params, (yespower_binary_t *) output);
|
|
}
|
|
|
|
int scanhash_arm_yespower(int thr_id, uint32_t *data, uint32_t *target, uint32_t max_nonce, unsigned long *hashes_done) {
|
|
uint32_t nonce = data[19]; // Nonce ist das 20. Element der Daten
|
|
unsigned char hash[32]; // Speicher für den berechneten Hash
|
|
int result = 0; // Rückgabewert
|
|
*hashes_done = 0; // Initialisierung der Hashanzahl
|
|
|
|
// Initialisierung des CPU-Informationspuffers
|
|
char cpu_info[256] = {0};
|
|
get_cpu_info(cpu_info, sizeof(cpu_info));
|
|
|
|
// Wähle die Yespower-Parameter basierend auf CPU-Informationen
|
|
const yespower_params_t *params = select_yespower_params(cpu_info);
|
|
|
|
for (; nonce < max_nonce; nonce++) {
|
|
data[19] = nonce; // Aktualisiere die Nonce
|
|
|
|
// Berechne den Hash mit Yespower
|
|
if (yespower_tls((const uint8_t *)data, 80, params, (yespower_binary_t *)hash) != 0) {
|
|
fprintf(stderr, "Thread %d: Fehler bei der Yespower-Berechnung.\n", thr_id);
|
|
break;
|
|
}
|
|
|
|
// Prüfe, ob der berechnete Hash kleiner als das Ziel ist
|
|
if (memcmp(hash, target, 32) <= 0) {
|
|
printf("Thread %d: Gültiger Hash gefunden! Nonce: %u\n", thr_id, nonce);
|
|
result = 1;
|
|
break;
|
|
}
|
|
|
|
(*hashes_done)++;
|
|
}
|
|
|
|
data[19] = nonce; // Stelle die Nonce wieder her
|
|
return result;
|
|
}
|