Skip to content

Commit e15004e

Browse files
committed
perform the inverse transfrom in positive range
Signed-off-by: Markku-Juhani O. Saarinen <[email protected]>
1 parent 53ba4df commit e15004e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

mlkem/src/native/riscv64/src/rv64v_poly.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ void mlk_rv64v_poly_ntt(int16_t *r)
349349
u0 = __riscv_vadd_vv_i16m1(u0, u1, vl); \
350350
u0 = fq_csub(u0, vl); \
351351
u1 = fq_mul_vx(ut, uc, vl); \
352+
u1 = fq_cadd(u1, vl); \
352353
}
353354

354355
#define MLK_RVV_BFLY_RV(u0, u1, ut, uc, vl) \
@@ -357,6 +358,7 @@ void mlk_rv64v_poly_ntt(int16_t *r)
357358
u0 = __riscv_vadd_vv_i16m1(u0, u1, vl); \
358359
u0 = fq_csub(u0, vl); \
359360
u1 = fq_mul_vv(ut, uc, vl); \
361+
u1 = fq_cadd(u1, vl); \
360362
}
361363

362364
static vint16m2_t mlk_rv64v_intt2(vint16m2_t vp, vint16m1_t cz)
@@ -387,9 +389,10 @@ static vint16m2_t mlk_rv64v_intt2(vint16m2_t vp, vint16m1_t cz)
387389
t0 = __riscv_vget_v_i16m2_i16m1(vp, 0);
388390
t1 = __riscv_vget_v_i16m2_i16m1(vp, 1);
389391

390-
/* initial reduction due to lack of input assumptions on INTT */
391-
t0 = fq_mul_vx(t0, MLK_RVV_MONT_R1, vl);
392-
t1 = fq_mul_vx(t1, MLK_RVV_MONT_R1, vl);
392+
/* move to positive range [0, q-1] for the reverse transform */
393+
t0 = fq_mulq_vx(t0, MLK_RVV_MONT_R1, vl);
394+
t1 = fq_mulq_vx(t1, MLK_RVV_MONT_R1, vl);
395+
393396
c0 = __riscv_vrgather_vv_i16m1(cz, cs2, vl);
394397
MLK_RVV_BFLY_RV(t0, t1, vt, c0, vl);
395398

@@ -415,9 +418,6 @@ static vint16m2_t mlk_rv64v_intt2(vint16m2_t vp, vint16m1_t cz)
415418
t0 = __riscv_vget_v_i16m2_i16m1(vp, 0);
416419
t1 = __riscv_vget_v_i16m2_i16m1(vp, 1);
417420

418-
/* normalize first element */
419-
t0 = fq_mulq_vx(t0, MLK_RVV_MONT_R1, vl);
420-
421421
vp = __riscv_vcreate_v_i16m1_i16m2(t0, t1);
422422

423423
return vp;

0 commit comments

Comments
 (0)