Skip to content

Code flaw? Looks like Dilithium polyz_unpack masks wrong index. #2211

@paulforbugs

Description

@paulforbugs

In the many implementation files of poly.c in src/sig/dilithium/* in polyz_unpack

    r->coeffs[2*i+0] |= (uint32_t)a[5*i+1] << 8;
    r->coeffs[2*i+0] |= (uint32_t)a[5*i+2] << 16;
    r->coeffs[2*i+0] &= 0xFFFFF;

    r->coeffs[2*i+1]  = a[5*i+2] >> 4;
    r->coeffs[2*i+1] |= (uint32_t)a[5*i+3] << 4;
    r->coeffs[2*i+1] |= (uint32_t)a[5*i+4] << 12;
    r->coeffs[2*i+0] &= 0xFFFFF;

    r->coeffs[2*i+0] = GAMMA1 - r->coeffs[2*i+0];
    r->coeffs[2*i+1] = GAMMA1 - r->coeffs[2*i+1];

it may be the case that oqs code is erroneously masking the wrong bit in the second chunk, where

r->coeffs[2*i+0] &= 0xFFFFF;

might need to be

r->coeffs[2*i+1] &= 0xFFFFF;

which may affect the value obtained in the subsequent subtraction from GAMMA1.

I do see in ml-dsa implementations that it is commented out like this

/* r->coeffs[2*i+1] &= 0xFFFFF; */ /* No effect, since we're anyway at 20 bits */

Is this something to worry about?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions