RSA key import can succeed with an invalid/undefined version #803

Open
opened 2026-09-03 02:00:46 -05:00 by headscott · 0 comments
headscott commented 2026-09-03 02:00:46 -05:00 (Migrated from github.com)

In rsa_import_pkcs1, after handling version == 0 and version == 1, there is no fallback case:

Affected Code
src/pk/rsa/rsa_import.c:57-78

if (version == 0) {
    ...
} else if (version == 1) {
    ...
}
err = CRYPT_OK;

An unsupported version or a not set version retaining its initial value (-1) could therefore fall through and return CRYPT_OK even though no key fields were decoded. The key could be uninitialized.

Suggested Fix
add this branch:

} else {
   err = CRYPT_PK_INVALID_TYPE;
   goto LBL_OUT;
}

This ensures that rsa_import_pkcs1 never reports successful key import unless a supported RSA key version was actually decoded.

In `rsa_import_pkcs1`, after handling `version == 0` and `version == 1`, there is no fallback case: **Affected Code** **src/pk/rsa/rsa_import.c:57-78** ```c if (version == 0) { ... } else if (version == 1) { ... } err = CRYPT_OK; ``` An unsupported version or a not set version retaining its initial value (`-1`) could therefore fall through and `return CRYPT_OK` even though no key fields were decoded. The key could be uninitialized. **Suggested Fix** add this branch: ```c } else { err = CRYPT_PK_INVALID_TYPE; goto LBL_OUT; } ``` This ensures that `rsa_import_pkcs1` never reports successful key import unless a supported RSA key version was actually decoded.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-libtom/libtomcrypt#803
No description provided.