Skip to content

Conversation

@michaelbeale-IL
Copy link

Potential fix for https://github.com/IntelLabs/HEC-openfhe-development-test/security/code-scanning/35

To fix the problem, the multiplication should be performed using the larger integer type so that if the result would exceed the range of a 32-bit unsigned integer, the correct (unwrapped) value will be produced. The best way to achieve this is to cast one of the operands (bStep or j) to size_t or std::vector<>::size_type before doing the multiplication, so that the multiplication will be promoted to the larger type. Update all instances of bStep * j that index into vectors or are used as arguments requiring larger types to use the cast.

For the code in question, change line 1608:

Ciphertext<DCRTPoly> inner = EvalMultExt(cc->KeySwitchExt(ct, true), A[bStep * j]);

to:

Ciphertext<DCRTPoly> inner = EvalMultExt(cc->KeySwitchExt(ct, true), A[static_cast<size_t>(bStep) * j]);

You may similarly want to update the subsequent uses (e.g., A[bStep * j + i], FindAutomorphismIndex2nComplex(bStep * j, M)) for consistency and safety, but only the highlighted multiplication needs fixing per the error report.

No new methods, imports, or external dependencies are required.


Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…onverted to larger type

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant