forked from martijnvanbrummelen/nwipe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
234 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
# what flags you want to pass to the C compiler & linker | ||
#CFLAGS = -lncurses -lparted | ||
AM_CFLAGS = | ||
AM_CFLAGS = -march=native -O3 -std=c11 | ||
AM_LDFLAGS = | ||
|
||
# this lists the binaries to produce, the (non-PHONY, binary) targets in | ||
# the previous manual Makefile | ||
bin_PROGRAMS = nwipe | ||
nwipe_SOURCES = context.h logging.h options.h prng.h version.h temperature.h nwipe.c gui.c method.h pass.c device.c gui.h isaac_rand/isaac_standard.h isaac_rand/isaac_rand.h isaac_rand/isaac_rand.c isaac_rand/isaac64.h isaac_rand/isaac64.c mt19937ar-cok/mt19937ar-cok.c nwipe.h mt19937ar-cok/mt19937ar-cok.h alfg/add_lagg_fibonacci_prng.h alfg/add_lagg_fibonacci_prng.c xor/xoroshiro256_prng.h xor/xoroshiro256_prng.c pass.h device.h logging.c method.c options.c prng.c version.c temperature.c PDFGen/pdfgen.h PDFGen/pdfgen.c create_pdf.c create_pdf.h embedded_images/shred_db.jpg.c embedded_images/shred_db.jpg.h embedded_images/tick_erased.jpg.c embedded_images/tick_erased.jpg.h embedded_images/redcross.c embedded_images/redcross.h hpa_dco.h hpa_dco.c miscellaneous.h miscellaneous.c embedded_images/nwipe_exclamation.jpg.h embedded_images/nwipe_exclamation.jpg.c conf.h conf.c customers.h customers.c hddtemp_scsi/hddtemp.h hddtemp_scsi/scsi.h hddtemp_scsi/scsicmds.h hddtemp_scsi/get_scsi_temp.c hddtemp_scsi/scsi.c hddtemp_scsi/scsicmds.c | ||
nwipe_SOURCES = context.h logging.h options.h prng.h version.h temperature.h nwipe.c gui.c method.h pass.c device.c gui.h isaac_rand/isaac_standard.h isaac_rand/isaac_rand.h isaac_rand/isaac_rand.c isaac_rand/isaac64.h isaac_rand/isaac64.c mt19937ar-cok/mt19937ar-cok.c nwipe.h mt19937ar-cok/mt19937ar-cok.h alfg/add_lagg_fibonacci_prng.h alfg/add_lagg_fibonacci_prng.c xor/xoroshiro256_prng.h xor/xoroshiro256_prng.c philox/philox_prng.h philox/philox_prng.c pass.h device.h logging.c method.c options.c prng.c version.c temperature.c PDFGen/pdfgen.h PDFGen/pdfgen.c create_pdf.c create_pdf.h embedded_images/shred_db.jpg.c embedded_images/shred_db.jpg.h embedded_images/tick_erased.jpg.c embedded_images/tick_erased.jpg.h embedded_images/redcross.c embedded_images/redcross.h hpa_dco.h hpa_dco.c miscellaneous.h miscellaneous.c embedded_images/nwipe_exclamation.jpg.h embedded_images/nwipe_exclamation.jpg.c conf.h conf.c customers.h customers.c hddtemp_scsi/hddtemp.h hddtemp_scsi/scsi.h hddtemp_scsi/scsicmds.h hddtemp_scsi/get_scsi_temp.c hddtemp_scsi/scsi.c hddtemp_scsi/scsicmds.c | ||
nwipe_LDADD = $(PARTED_LIBS) $(LIBCONFIG) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include <immintrin.h> // Für AVX2-Instruktionen | ||
#include <assert.h> | ||
#include <string.h> | ||
#include "philox_prng.h" | ||
|
||
|
||
|
||
// Funktion zur Initialisierung des PRNG-Zustands mit einem Schlüssel | ||
void philox_prng_init(philox_state_t* state, unsigned long init_key[], unsigned long key_length) { | ||
assert(state != NULL && init_key != NULL); | ||
|
||
// Initialisiere den Zähler mit Null | ||
state->counter = _mm256_setzero_si256(); | ||
|
||
// Initialisiere den Schlüssel. Da wir AVX2 verwenden, passen maximal vier 64-Bit-Schlüssel in einen __m256i. | ||
// Fülle den Schlüsselbereich auf, falls key_length < 4 ist. | ||
if (key_length >= 4) { | ||
state->key = _mm256_set_epi64x(init_key[3], init_key[2], init_key[1], init_key[0]); | ||
} else { | ||
unsigned long temp_key[4] = {0, 0, 0, 0}; // Fülle mit Nullen auf | ||
for (unsigned long i = 0; i < key_length; ++i) { | ||
temp_key[i] = init_key[i]; | ||
} | ||
state->key = _mm256_set_epi64x(temp_key[3], temp_key[2], temp_key[1], temp_key[0]); | ||
} | ||
} | ||
|
||
// Funktion zur Erzeugung von 512 Bit Zufallszahlen und Kopieren in einen Puffer | ||
void philox_prng_genrand_uint512_to_buf(philox_state_t* state, unsigned char* bufpos) { | ||
assert(state != NULL && bufpos != NULL); // Validiere Eingaben | ||
|
||
// Temporärer Puffer für 512 Bit (64 Bytes) | ||
unsigned char temp_buffer[64]; | ||
memset(temp_buffer, 0, sizeof(temp_buffer)); // Initialisiere temporären Puffer mit Nullen | ||
|
||
// Philox-Kernberechnung: | ||
__m256i multiplier = _mm256_set1_epi64x(0xD2B74407B1CE6E93); // Philox-Konstante für Multiplikation | ||
__m256i increment = _mm256_set1_epi64x(0x9E3779B97F4A7C15); // Philox-Konstante für Inkrementierung | ||
|
||
// Hauptschleife, die den Zähler und Schlüssel transformiert (Philox-Kern, z.B. 10 Runden) | ||
for (int i = 0; i < 10; ++i) { | ||
// Untere 32 Bit multiplizieren und obere 32 Bit für weitere Operationen nutzen | ||
__m256i lo = _mm256_mul_epu32(state->counter, multiplier); // Untere 32 Bit multiplizieren | ||
__m256i hi = _mm256_srli_epi64(state->counter, 32); // Höhere 32 Bit verschieben | ||
|
||
// Schlüssel und Zähler modifizieren | ||
state->counter = _mm256_add_epi64(state->counter, increment); | ||
state->key = _mm256_xor_si256(state->key, hi); // XOR mit den oberen Bits des Zählers | ||
} | ||
|
||
// Die Ergebnisse in den temporären Puffer kopieren | ||
_mm256_storeu_si256((__m256i*)temp_buffer, state->counter); // Speichere die ersten 256 Bit | ||
_mm256_storeu_si256((__m256i*)(temp_buffer + 32), state->key); // Speichere die zweiten 256 Bit | ||
|
||
// Kopiere die generierten Pseudozufallsdaten in den Zielpuffer | ||
memcpy(bufpos, temp_buffer, sizeof(temp_buffer)); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* philox_prng.h | ||
* Header-Datei für die optimierte Philox PRNG Implementierung mit AVX2 | ||
* Autor: [Ihr Name] | ||
* Datum: [Aktuelles Datum] | ||
* | ||
* Dieses Werk ist gemeinfrei. Es kann von jedermann für beliebige Zwecke | ||
* genutzt werden, ohne jegliche Bedingungen, es sei denn, solche Bedingungen | ||
* sind gesetzlich vorgeschrieben. | ||
*/ | ||
|
||
#ifndef PHILOX_PRNG_H | ||
#define PHILOX_PRNG_H | ||
|
||
#include <stdint.h> | ||
#include <immintrin.h> // Für AVX2-Intrinsics | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
// Anzahl der Runden für den Philox 4x32 Algorithmus | ||
#define NUM_ROUNDS 10 // Anzahl der Runden für Philox 4x32 | ||
|
||
|
||
typedef struct philox_state_s { | ||
__m256i counter; // Verwende 256-Bit AVX2 Register für den Zähler | ||
__m256i key; // Verwende 256-Bit AVX2 Register für den Schlüssel | ||
} philox_state_t; | ||
|
||
/* Initialisiert den Philox PRNG Zustand. | ||
- state: Zeiger auf den Philox PRNG Zustandsstruktur. | ||
- init_key: Array, das den Seed-Schlüssel enthält. | ||
- key_length: Länge des Schlüsselarrays. */ | ||
void philox_prng_init(philox_state_t* state, unsigned long init_key[], unsigned long key_length); | ||
|
||
/* Generiert Pseudorandom-Zahlen und schreibt sie in einen Puffer. | ||
- state: Zeiger auf den initialisierten Philox PRNG Zustand. | ||
- bufpos: Zielpuffer, in den die Pseudorandom-Zahlen geschrieben werden. | ||
Der Puffer sollte mindestens 64 Bytes groß sein. */ | ||
void philox_prng_genrand_uint512_to_buf(philox_state_t* state, unsigned char* bufpos); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // PHILOX_PRNG_H | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters