pqc/crypto_kem/hqc-256-1-cca2/leaktime/tensor.c
Sebastian 33232a0343
HQC submission (#202)
* Sebastian's HQC merge request

* Clean up changes to common infrastructure

* Fix Bitmask macro

It assumed that ``unsigned long`` was 64 bit

* Remove maxlen from nistseedexpander

It's a complicated thing to handle because the value is larger than size_t supports on 32-bit platforms

* Initialize buffers to help linter

* Add Nistseedexpander test

* Resolve UB in gf2x.c

Some of the shifts could be larger than WORD_SIZE_BITS, ie. larger than
the width of uint64_t. This apparently on Intel gets interpreted as the
shift mod 64, but on ARM something else happened.

* Fix Windows complaints

* rename log, exp which appear to be existing functions on MS

* Solve endianness problems

* remove all spaces before ';'

* Fix duplicate consistency

* Fix duplicate consistency

* Fix complaints by MSVC about narrowing int

* Add nistseedexpander.obj to COMMON_OBJECTS_NOPATH

* astyle format util.[ch]

* add util.h to makefile

* Sort includes in util.h

* Fix more Windows MSVC complaints

Co-authored-by: Sebastian Verschoor <sebastian@zeroknowledge.me>
Co-authored-by: Thom Wiggers <thom@thomwiggers.nl>
2020-04-01 13:57:21 +08:00

43 lines
1.2 KiB
C

/**
* @file tensor.c
* @brief Implementation of tensor code
*/
#include "bch.h"
#include "parameters.h"
#include "repetition.h"
#include "tensor.h"
#include <stdint.h>
/**
* @brief Encoding the message m to a code word em using the tensor code
*
* First we encode the message using the BCH code, then with the repetition code to obtain
* a tensor code word.
*
* @param[out] em Pointer to an array that is the tensor code word
* @param[in] m Pointer to an array that is the message
*/
void PQCLEAN_HQC2561CCA2_LEAKTIME_tensor_code_encode(uint8_t *em, const uint8_t *m) {
uint8_t tmp[VEC_N1_SIZE_BYTES] = {0};
PQCLEAN_HQC2561CCA2_LEAKTIME_bch_code_encode(tmp, m);
PQCLEAN_HQC2561CCA2_LEAKTIME_repetition_code_encode(em, tmp);
}
/**
* @brief Decoding the code word em to a message m using the tensor code
*
* @param[out] m Pointer to an array that is the message
* @param[in] em Pointer to an array that is the code word
*/
void PQCLEAN_HQC2561CCA2_LEAKTIME_tensor_code_decode(uint8_t *m, const uint8_t *em) {
uint8_t tmp[VEC_N1_SIZE_BYTES] = {0};
PQCLEAN_HQC2561CCA2_LEAKTIME_repetition_code_decode(tmp, em);
PQCLEAN_HQC2561CCA2_LEAKTIME_bch_code_decode(m, tmp);
}