2019-06-18 10:28:41 +01:00
|
|
|
#include "blas_u32.h"
|
|
|
|
#include "gf.h"
|
|
|
|
|
2019-07-24 09:41:42 +01:00
|
|
|
void PQCLEAN_RAINBOWIACYCLIC_CLEAN_gf256v_predicated_add_u32(uint8_t *accu_b, uint8_t predicate, const uint8_t *a, unsigned int _num_byte) {
|
2019-07-24 09:15:48 +01:00
|
|
|
uint32_t pr_u32 = ((uint32_t)0) - ((uint32_t)predicate);
|
2019-06-18 10:28:41 +01:00
|
|
|
uint8_t pr_u8 = pr_u32 & 0xff;
|
|
|
|
|
2019-07-24 09:41:42 +01:00
|
|
|
unsigned int n_u32 = _num_byte >> 2;
|
2019-07-24 09:15:48 +01:00
|
|
|
uint32_t *b_u32 = (uint32_t *)accu_b;
|
|
|
|
const uint32_t *a_u32 = (const uint32_t *)a;
|
2019-07-24 09:41:42 +01:00
|
|
|
for (unsigned int i = 0; i < n_u32; i++) {
|
2019-06-18 10:28:41 +01:00
|
|
|
b_u32[i] ^= (a_u32[i] & pr_u32);
|
|
|
|
}
|
|
|
|
|
|
|
|
a += (n_u32 << 2);
|
|
|
|
accu_b += (n_u32 << 2);
|
2019-07-24 09:41:42 +01:00
|
|
|
unsigned int rem = _num_byte & 3;
|
|
|
|
for (unsigned int i = 0; i < rem; i++) {
|
2019-06-18 10:28:41 +01:00
|
|
|
accu_b[i] ^= (a[i] & pr_u8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-24 09:41:42 +01:00
|
|
|
void PQCLEAN_RAINBOWIACYCLIC_CLEAN_gf256v_add_u32(uint8_t *accu_b, const uint8_t *a, unsigned int _num_byte) {
|
|
|
|
unsigned int n_u32 = _num_byte >> 2;
|
2019-07-24 09:15:48 +01:00
|
|
|
uint32_t *b_u32 = (uint32_t *)accu_b;
|
|
|
|
const uint32_t *a_u32 = (const uint32_t *)a;
|
2019-07-24 09:41:42 +01:00
|
|
|
for (unsigned int i = 0; i < n_u32; i++) {
|
2019-06-18 10:28:41 +01:00
|
|
|
b_u32[i] ^= a_u32[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
a += (n_u32 << 2);
|
|
|
|
accu_b += (n_u32 << 2);
|
2019-07-24 09:41:42 +01:00
|
|
|
unsigned int rem = _num_byte & 3;
|
|
|
|
for (unsigned int i = 0; i < rem; i++) {
|
2019-06-18 10:28:41 +01:00
|
|
|
accu_b[i] ^= a[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-24 09:41:42 +01:00
|
|
|
void PQCLEAN_RAINBOWIACYCLIC_CLEAN_gf16v_mul_scalar_u32(uint8_t *a, uint8_t gf16_b, unsigned int _num_byte) {
|
|
|
|
unsigned int n_u32 = _num_byte >> 2;
|
2019-07-24 09:15:48 +01:00
|
|
|
uint32_t *a_u32 = (uint32_t *)a;
|
2019-07-24 09:41:42 +01:00
|
|
|
for (unsigned int i = 0; i < n_u32; i++) {
|
2019-06-18 10:28:41 +01:00
|
|
|
a_u32[i] = PQCLEAN_RAINBOWIACYCLIC_CLEAN_gf16v_mul_u32(a_u32[i], gf16_b);
|
|
|
|
}
|
|
|
|
|
|
|
|
union tmp_32 {
|
|
|
|
uint8_t u8[4];
|
|
|
|
uint32_t u32;
|
|
|
|
} t;
|
|
|
|
t.u32 = 0;
|
|
|
|
a += (n_u32 << 2);
|
2019-07-24 09:41:42 +01:00
|
|
|
unsigned int rem = _num_byte & 3;
|
|
|
|
for (unsigned int i = 0; i < rem; i++) {
|
2019-06-18 10:28:41 +01:00
|
|
|
t.u8[i] = a[i];
|
|
|
|
}
|
|
|
|
t.u32 = PQCLEAN_RAINBOWIACYCLIC_CLEAN_gf16v_mul_u32(t.u32, gf16_b);
|
2019-07-24 09:41:42 +01:00
|
|
|
for (unsigned int i = 0; i < rem; i++) {
|
2019-06-18 10:28:41 +01:00
|
|
|
a[i] = t.u8[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-24 09:41:42 +01:00
|
|
|
void PQCLEAN_RAINBOWIACYCLIC_CLEAN_gf16v_madd_u32(uint8_t *accu_c, const uint8_t *a, uint8_t gf16_b, unsigned int _num_byte) {
|
|
|
|
unsigned int n_u32 = _num_byte >> 2;
|
2019-07-24 09:15:48 +01:00
|
|
|
uint32_t *c_u32 = (uint32_t *)accu_c;
|
|
|
|
const uint32_t *a_u32 = (const uint32_t *)a;
|
2019-07-24 09:41:42 +01:00
|
|
|
for (unsigned int i = 0; i < n_u32; i++) {
|
2019-06-18 10:28:41 +01:00
|
|
|
c_u32[i] ^= PQCLEAN_RAINBOWIACYCLIC_CLEAN_gf16v_mul_u32(a_u32[i], gf16_b);
|
|
|
|
}
|
|
|
|
|
|
|
|
union tmp_32 {
|
|
|
|
uint8_t u8[4];
|
|
|
|
uint32_t u32;
|
|
|
|
} t;
|
|
|
|
t.u32 = 0;
|
|
|
|
accu_c += (n_u32 << 2);
|
|
|
|
a += (n_u32 << 2);
|
2019-07-24 09:41:42 +01:00
|
|
|
unsigned int rem = _num_byte & 3;
|
|
|
|
for (unsigned int i = 0; i < rem; i++) {
|
2019-06-18 10:28:41 +01:00
|
|
|
t.u8[i] = a[i];
|
|
|
|
}
|
|
|
|
t.u32 = PQCLEAN_RAINBOWIACYCLIC_CLEAN_gf16v_mul_u32(t.u32, gf16_b);
|
2019-07-24 09:41:42 +01:00
|
|
|
for (unsigned int i = 0; i < rem; i++) {
|
2019-06-18 10:28:41 +01:00
|
|
|
accu_c[i] ^= t.u8[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-24 09:41:42 +01:00
|
|
|
uint8_t PQCLEAN_RAINBOWIACYCLIC_CLEAN_gf16v_dot_u32(const uint8_t *a, const uint8_t *b, unsigned int _num_byte) {
|
|
|
|
unsigned int n_u32 = _num_byte >> 2;
|
2019-07-24 09:15:48 +01:00
|
|
|
const uint32_t *a_u32 = (const uint32_t *)a;
|
|
|
|
const uint32_t *b_u32 = (const uint32_t *)b;
|
2019-06-18 10:28:41 +01:00
|
|
|
uint32_t r = 0;
|
2019-07-24 09:41:42 +01:00
|
|
|
for (unsigned int i = 0; i < n_u32; i++) {
|
2019-06-18 10:28:41 +01:00
|
|
|
r ^= PQCLEAN_RAINBOWIACYCLIC_CLEAN_gf16v_mul_u32_u32(a_u32[i], b_u32[i]);
|
|
|
|
}
|
|
|
|
|
2019-07-24 09:41:42 +01:00
|
|
|
unsigned int rem = _num_byte & 3;
|
2019-06-18 10:28:41 +01:00
|
|
|
if (rem) {
|
|
|
|
union tmp_32 {
|
|
|
|
uint8_t u8[4];
|
|
|
|
uint32_t u32;
|
|
|
|
} ta, tb;
|
|
|
|
ta.u32 = 0;
|
|
|
|
tb.u32 = 0;
|
2019-07-24 09:41:42 +01:00
|
|
|
for (unsigned int i = 0; i < rem; i++) {
|
2019-06-18 10:28:41 +01:00
|
|
|
ta.u8[i] = a[(n_u32 << 2) + i];
|
|
|
|
}
|
2019-07-24 09:41:42 +01:00
|
|
|
for (unsigned int i = 0; i < rem; i++) {
|
2019-06-18 10:28:41 +01:00
|
|
|
tb.u8[i] = b[(n_u32 << 2) + i];
|
|
|
|
}
|
|
|
|
r ^= PQCLEAN_RAINBOWIACYCLIC_CLEAN_gf16v_mul_u32_u32(ta.u32, tb.u32);
|
|
|
|
}
|
|
|
|
return PQCLEAN_RAINBOWIACYCLIC_CLEAN_gf16v_reduce_u32(r);
|
|
|
|
}
|
|
|
|
|