Skip to content

Missing input length validation in PKCS#1 v1.5 decoder #782

Description

@headscott

ltc_pkcs_1_v1_5_decode accepts input shorter than the expected modulus length (msglen < modulus_len), but subsequently accesses the input as if it were modulus_len bytes long. This may result in out-of-bounds reads when processing truncated input.

According to PKCS#1 v1.5 (RFC 8017), the encoded message must be exactly the length of the RSA modulus. Rejecting inputs whose length differs from modulus_len prevents truncated inputs from being processed and avoids out-of-bounds reads.

Affected Code

Location: Location: src/pk/pkcs1/pkcs_1_v1_5_decode.c:42

if ((msglen > modulus_len) || (modulus_len < 11)) {
    return CRYPT_PK_INVALID_SIZE;
}

Expected Behavior

if ((msglen != modulus_len) || (modulus_len < 11)) {
    return CRYPT_PK_INVALID_SIZE;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions