diff --git a/headers/system.h b/headers/system.h index ae39b99caaabca1e3a42894bc7918a6d9ff62959..f1ce59b6dd056879c57ba0aac6b740aec947d80c 100644 --- a/headers/system.h +++ b/headers/system.h @@ -1,9 +1,62 @@ #ifndef SYSTEM_H #define SYSTEM_H +#include <stdint.h> + typedef struct { // TODO } system_t; +/** + * + * Add two vectors in a Galois Field 256 + * @param symbol_1: the first symbol to add + * @param symbol_2: the second symbol to add + * @param symbol_size: size of the two symbols (of the same size!) + * @return: a new vector of `symbol_size` byte containing the result of symbol_1 + symbol_2 in GF(256) + */ +uint8_t *gf256_add_two_vectors(uint8_t *symbol_1, uint8_t *symbol_2, uint32_t symbol_size); + +/** + * + * Add two vectors in a Galois Field 256 where the second vector is scaled + * @param symbol_1: the first symbol to add + * @param symbol_2: the second symbol to add (the scaled one) + * @param coef: the coefficient of the scaling + * @param symbol_size: size of the two symbols (of the same size!) + * @return: a new vector of `symbol_size` byte containing the result of symbol_1 + symbol_2 * coef in GF(256) + */ +uint8_t *gf256_add_two_vectors_scaled(uint8_t *symbol_1, uint8_t *symbol_2, uint8_t coef, uint32_t symbol_size); + +/** + * + * Divide a vector in a Galois Field 25§ by a coefficient + * @param symbol: the symbol to add + * @param coef: the dividing coefficient + * @param symbol_size: size of the two symbols (of the same size!) + * @return: a new vector of `symbol_size` byte containing the result of symbol_1 / coef + */ +uint8_t *gf256_divide_vector_scaled(uint8_t *symbol, uint8_t coef, uint32_t symbol_size); + +/** + * + * Resolve the linear system Ax=b in a Galois Field 256. The result is stored in the independent terms after the resolution + * @param A: matrix of coefficients + * @param b: independent terms + * @param symbol_size: size of the independent terms + * @param system_size: the size of the system (i.e., number of rows/columns) + */ +void gf256_gaussian_elimination(uint8_t **A, uint8_t **b, uint32_t symbol_size, uint32_t system_size); + +/** + * + * Generate all coefficients for a block + * @param seed: the seed to generate the coefficients + * @param nss: number of source symbols in a block + * @param nrs: number of repair symbols in a block + * @return: a nss * nrs array of coefficients + */ +uint8_t **gen_coef(uint32_t seed, uint32_t nss, uint32_t nrs); + #endif /* SYSTEM_H */ \ No newline at end of file diff --git a/main.c b/main.c index 9d9262b46a86dfbb8eeec750611c0f3ee8b274ac..7dac80bdb229374f02fe6cb51f2f997a8bff3bec 100644 --- a/main.c +++ b/main.c @@ -142,19 +142,19 @@ int main(int argc, char *argv[]) // You may modify or delete the following lines. This is just an example of how to use tinymt32 uint32_t seed = 42; // Replace with the seed from the instance file! - - tinymt32_t prng; - memset(&prng, 0, sizeof(tinymt32_t)); - // Do not modify these values! - prng.mat1 = 0x8f7011ee; - prng.mat2 = 0xfc78ff1f; - prng.tmat = 0x3793fdff; - tinymt32_init(&prng, seed); - - // You can generate coefficients by calling this function - // Do not forget that we use byte values, so we have to - // cast the uint32_t returned value to only keep the last 8 bits. - uint8_t coef = (uint8_t)tinymt32_generate_uint32(&prng); + + tinymt32_t prng; + memset(&prng, 0, sizeof(tinymt32_t)); + // Do not modify these values! + prng.mat1 = 0x8f7011ee; + prng.mat2 = 0xfc78ff1f; + prng.tmat = 0x3793fdff; + tinymt32_init(&prng, seed); + + // You can generate coefficients by calling this function + // Do not forget that we use byte values, so we have to + // cast the uint32_t returned value to only keep the last 8 bits. + uint8_t coef = (uint8_t)tinymt32_generate_uint32(&prng); if (args.verbose) { printf("Coefficient: %u\n", coef);