case QANSEL_HARDWARE_QUANTIS:
r = ctx->chunk[ctx->pointer];
ctx->pointer += 1;
- if (ctx->pointer >= QANSEL_QUANTIS_CHUNK)
+ if (ctx->pointer >= QANSEL_QUANTIS_CHUNK_SIZE)
{
- qansel_quantis_chunk(ctx->chunk);
+ qansel_quantis_chunk(&(ctx->chunk));
ctx->pointer = 0;
}
break;
int qanselContextBegin(QAnselContext* ctx)
{
+ ctx->chunk = NULL;
if (ctx->memory_limit == 0) ctx->memory_limit = QANSEL_QUBITS_MAX;
if (ctx->memory_limit > QANSEL_QUBITS_MAX)
{
else
{
if (ctx->verbose) printf("QAnsel: Hardware `TrueRNG` selected.\n");
- strcpy(ctx->random_path, "/dev/TrueRNG0");
ctx->hardware_rng = QANSEL_HARDWARE_TRUERNG;
}
}
else
{
+ fclose(ctx->random_file);
if (ctx->verbose) printf("QAnsel: Hardware `Quantis` selected.\n");
ctx->hardware_rng = QANSEL_HARDWARE_QUANTIS;
- ctx->pointer = 0;
- qansel_quantis_chunk(ctx->chunk);
+ ctx->pointer = QUANTIS_CHUNK_SIZE;
}
}
if (ctx->optimization_level & QANSEL_MODE_METAL)
{
if (ctx->random_file != NULL) fclose(ctx->random_file);
if (ctx->optimization_level & QANSEL_MODE_METAL) cpx_mtx_clean();
- if (ctx->hardware_rng == QANSEL_HARDWARE_QUANTIS) free(ctx->chunk);
+ if (ctx->chunk != NULL) free(ctx->chunk);
return 1;
}
int qubit_count;
int bit_count;
int pointer;
- char* chunk;
- char random_path[32];
+ unsigned char* chunk;
FILE* random_file;
} QAnselContext;
//return seed;
}
-void qansel_quantis_chunk(unsigned char* chunk)
+void qansel_quantis_chunk(unsigned char** chunk)
{
- chunk = malloc(QUANTIS_CHUNK_SIZE);
+ if ((*chunk) != NULL) free(*chunk);
+ *chunk = malloc(QUANTIS_CHUNK_SIZE);
FILE* f = fopen("/dev/qrandom0", "r");
unsigned char c = fgetc(f);
while (c == 0x00) c = fgetc(f);
- chunk[0] = c;
+ (*chunk)[0] = c;
for (int i = 0; i < QUANTIS_CHUNK_SIZE - 1; i++)
{
- chunk[i + 1] = fgetc(f);
+ (*chunk)[i + 1] = fgetc(f);
}
fclose(f);
}
\ No newline at end of file
int qansel_hardware_rand_supported();
unsigned char qansel_hardware_rand();
float qansel_hardware_getseed();
-void qansel_quantis_chunk(unsigned char* chunk);
+void qansel_quantis_chunk(unsigned char** chunk);
#endif
#define QANSEL_HARDWARE_TRUERNG 2
#define QANSEL_HARDWARE_RDSEED 3
#define QANSEL_HARDWARE_QUANTIS 4
-#define QANSEL_QUANTIS_CHUNK 4096
+#define QANSEL_QUANTIS_CHUNK_SIZE 4096
#define QANSEL_INSTRUCTION_X 0x10
#define QANSEL_INSTRUCTION_Y 0x11
#define QANSEL_INSTRUCTION_Z 0x12