Skip to content

Commit 6340ad1

Browse files
committed
fixed decoder and sparse multiplication, added forceful zeroize to buffer
1 parent 5364628 commit 6340ad1

File tree

7 files changed

+52
-39
lines changed

7 files changed

+52
-39
lines changed

CHANGELOG

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
Version 1.0.2 (tag v1.0.2)
2+
3+
* Fixed decoding bug, unelicited by submission parameters.
4+
5+
* Fixed sparse multiplication bug, unelicited by submission parameters.
6+
7+
* Added forced zero filling for the memory area which subsequently holds
8+
the data to be hashed whenever a decoding failure takes place.
9+
10+
----------------------------
111
Version 1.0.1 (tag v1.0.1)
212

313
* Added the secret key to the hash which generates the pseudorandom value

Reference_Implementation/KEM/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ endif
5656
CFLAGS = -DCATEGORY=$(SL) -DN0=$(N0) -DCPU_WORD_BITS=64 \
5757
-std=c99 -Wall -pedantic -Wmaybe-uninitialized -Wuninitialized \
5858
-march=native -O3
59-
LDFLAGS = -lm
59+
LDFLAGS =
6060
INCLUDES = -I./include
6161
SRCDIR = library
6262
OBJDIR = bin

Reference_Implementation/KEM/include/gf2x_arith_mod_xPplusOne.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@
9090

9191
/*----------------------------------------------------------------------------*/
9292

93-
94-
95-
/*----------------------------------------------------------------------------*/
96-
9793
static inline void gf2x_copy(DIGIT dest[], const DIGIT in[])
9894
{
9995
for (int i = NUM_DIGITS_GF2X_ELEMENT-1; i >= 0; i--)

Reference_Implementation/KEM/library/bf_decoding.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* <bf_decoding.c>
44
*
5-
* @version 1.0 (September 2017)
5+
* @version 1.0.2 (September 2018)
66
*
77
* Reference ISO-C99 Implementation of LEDAkem cipher" using GCC built-ins.
88
*
@@ -84,7 +84,7 @@ int bf_decoding(DIGIT out[], // N0 polynomials
8484
int correlation =0;
8585

8686
for (int blockIdx = 0; blockIdx < N0; blockIdx++) {
87-
endQblockIdx += qBlockWeights[i][blockIdx];
87+
endQblockIdx += qBlockWeights[blockIdx][i];
8888
for (; currQoneIdx < endQblockIdx; currQoneIdx++) {
8989
currQ_pos[currQoneIdx] = ((QtrPosOnes[i][currQoneIdx]+j) % P) + blockIdx*P;
9090
correlation += upc[currQ_pos[currQoneIdx]];

Reference_Implementation/KEM/library/gf2x_arith_mod_xPplusOne.c

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* <gf2x_arith_mod_xPplusOne.c>
44
*
5-
* @version 1.0 (September 2017)
5+
* @version 1.0.2 (September 2018)
66
*
77
* Reference ISO-C99 Implementation of LEDAkem cipher" using GCC built-ins.
88
*
@@ -372,9 +372,9 @@ int gf2x_mod_inverse(DIGIT out[], const DIGIT in[]) /* in^{-1} mod x^P-1 */
372372
int i;
373373
long int delta = 0;
374374
DIGIT u[NUM_DIGITS_GF2X_ELEMENT] = {0},
375-
v[NUM_DIGITS_GF2X_ELEMENT] = {0},
376-
s[NUM_DIGITS_GF2X_MODULUS] = {0},
377-
f[NUM_DIGITS_GF2X_MODULUS] = {0};
375+
v[NUM_DIGITS_GF2X_ELEMENT] = {0},
376+
s[NUM_DIGITS_GF2X_MODULUS] = {0},
377+
f[NUM_DIGITS_GF2X_MODULUS] = {0};
378378

379379
DIGIT mask;
380380
u[NUM_DIGITS_GF2X_ELEMENT-1] = 0x1;
@@ -507,43 +507,48 @@ void gf2x_mod_mul_sparse(int
507507
int sizeB, /*number of ones in B*/
508508
const POSITION_T B[])
509509
{
510-
for(int i = 0; i< sizeR; i++) {
511-
Res[i]= INVALID_POS_VALUE;
512-
}
513510
/* compute all the coefficients, filling invalid positions with P*/
514-
unsigned i = 0;
515-
for(; i < sizeA && A[i] != INVALID_POS_VALUE; i++) {
516-
unsigned j = 0;
517-
for (; j < sizeB && B[j] != INVALID_POS_VALUE; j++) {
518-
uint32_t prod = ((uint32_t) A[i]) + ((uint32_t) B[j]);
519-
Res[i*sizeB+j] = prod >= P ? prod - P : prod;
520-
}
521-
for (; j < sizeB ; j++) {
522-
Res[i*sizeB+j] = INVALID_POS_VALUE;
523-
}
524-
}
525-
526-
for(; i < sizeA; i++) {
527-
for (unsigned j = 0; j < sizeB; j++) {
528-
Res[i*sizeB+j] = INVALID_POS_VALUE;
529-
}
511+
unsigned lastFilledPos=0;
512+
for(int i = 0 ; i < sizeA ; i++){
513+
for(int j = 0 ; j < sizeB ; j++){
514+
uint32_t prod = ((uint32_t) A[i]) + ((uint32_t) B[j]);
515+
prod = ( (prod >= P) ? prod - P : prod);
516+
if ((A[i] != INVALID_POS_VALUE) &&
517+
(B[i] != INVALID_POS_VALUE)){
518+
Res[lastFilledPos] = prod;
519+
} else{
520+
Res[lastFilledPos] = INVALID_POS_VALUE;
521+
}
522+
lastFilledPos++;
523+
}
524+
}
525+
while(lastFilledPos < sizeR){
526+
Res[lastFilledPos] = INVALID_POS_VALUE;
527+
lastFilledPos++;
530528
}
531529
quicksort(Res, sizeR);
532530
/* eliminate duplicates */
531+
POSITION_T lastReadPos = Res[0];
532+
int duplicateCount;
533533
int write_idx = 0;
534-
for(unsigned i = 0; i < sizeR-1 && Res[i] != INVALID_POS_VALUE; i++) {
535-
if (Res[i] == Res[i+1]) {
536-
i++;
537-
} else {
538-
Res[write_idx] = Res[i];
539-
write_idx++;
534+
int read_idx = 0;
535+
while(read_idx < sizeR && Res[read_idx] != INVALID_POS_VALUE){
536+
lastReadPos = Res[read_idx];
537+
read_idx++;
538+
duplicateCount=1;
539+
while( (Res[read_idx] == lastReadPos) && (Res[read_idx] != INVALID_POS_VALUE)){
540+
read_idx++;
541+
duplicateCount++;
542+
}
543+
if (duplicateCount % 2) {
544+
Res[write_idx] = lastReadPos;
545+
write_idx++;
540546
}
541547
}
542548
/* fill remaining cells with INVALID_POS_VALUE */
543549
for(; write_idx < sizeR; write_idx++) {
544550
Res[write_idx] = INVALID_POS_VALUE;
545551
}
546-
547552
} // end gf2x_mod_mul_sparse
548553

549554

Reference_Implementation/KEM/library/kem.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* <kem.c>
44
*
5-
* @version 1.0.1 (July 2018)
5+
* @version 1.0.2 (September 2018)
66
*
77
* Reference ISO-C99 Implementation of LEDAkem cipher" using GCC built-ins.
88
*
@@ -87,6 +87,7 @@ int crypto_kem_dec( unsigned char *ss,
8787
{
8888
DIGIT decoded_error_vector[N0*NUM_DIGITS_GF2X_ELEMENT];
8989
DIGIT mockup_error_vector[N0*NUM_DIGITS_GF2X_ELEMENT];
90+
memset(mockup_error_vector, 0x00, N0*NUM_DIGITS_GF2X_ELEMENT*DIGIT_SIZE_B);
9091
memcpy(mockup_error_vector, ct, NUM_DIGITS_GF2X_ELEMENT*DIGIT_SIZE_B);
9192
/* adding the prng seed to the final hash in case of decryption failure
9293
* to address the official comment by Keita Xagawa */

Reference_Implementation/KEM/library/sha3.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,5 @@ void Keccak( unsigned int rate,
314314
}
315315
}
316316

317-
/*----------------------------------------------------------------------------*/
317+
/*----------------------------------------------------------------------------*/
318+

0 commit comments

Comments
 (0)