Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/builtin/rs_vand/liberasurecode_rs_vand.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ void region_multiply(char *from_buf, char *to_buf, int mult, int xor, int blocks

if (trailing_bytes == 1) {
i = blocksize - 1;
to_buf[i] = to_buf[i] ^ (char)rs_galois_mult(from_buf[i], mult);
to_buf[i] = to_buf[i] ^ (char)rs_galois_mult((unsigned char)from_buf[i], mult);
}
} else {
for (i = 0; i < adj_blocksize; i++) {
Expand All @@ -379,7 +379,7 @@ void region_multiply(char *from_buf, char *to_buf, int mult, int xor, int blocks

if (trailing_bytes == 1) {
i = blocksize - 1;
to_buf[i] = (char)rs_galois_mult(from_buf[i], mult);
to_buf[i] = (char)rs_galois_mult((unsigned char)from_buf[i], mult);
}
}
}
Expand Down
34 changes: 24 additions & 10 deletions src/builtin/rs_vand/rs_galois.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,45 @@
int *log_table = NULL;
int *ilog_table = NULL;
int *ilog_table_begin = NULL;
static int init_counter = 0;

void rs_galois_init_tables()
{
log_table = (int*)malloc(sizeof(int)*FIELD_SIZE);
ilog_table_begin = (int*)malloc(sizeof(int)*FIELD_SIZE*3);
void rs_galois_init_tables() {
if (init_counter++ > 0) {
/* already initialized */
return;
}
log_table = (int *)malloc(sizeof(int) * FIELD_SIZE);
ilog_table_begin = (int *)malloc(sizeof(int) * FIELD_SIZE * 3);
int i = 0;
int x = 1;

for (i = 0; i < GROUP_SIZE; i++) {
log_table[x] = i;
ilog_table_begin[i] = x;
ilog_table_begin[i + GROUP_SIZE] = x;
ilog_table_begin[i + (GROUP_SIZE*2)] = x;
ilog_table_begin[i + (GROUP_SIZE * 2)] = x;
x = x << 1;
if (x & FIELD_SIZE) {
x ^= PRIM_POLY;
x ^= PRIM_POLY;
}
}
ilog_table = &ilog_table_begin[GROUP_SIZE];
}

void rs_galois_deinit_tables()
{
free(log_table);
free(ilog_table_begin);
void rs_galois_deinit_tables() {
init_counter--;
if (init_counter < 0) {
/* deinit when not initialized?? */
init_counter = 0;
} else if (init_counter > 0) {
/* still at least one desc using it */
return;
} else {
free(log_table);
log_table = NULL;
free(ilog_table_begin);
ilog_table_begin = NULL;
}
}

int rs_galois_mult(int x, int y)
Expand Down