Skip to content

Comments

Return an error from BN_mod_inverse if n is 1 (or -1)#6119

Closed
mattcaswell wants to merge 1 commit intoopenssl:masterfrom
mattcaswell:bn-mod-inverse
Closed

Return an error from BN_mod_inverse if n is 1 (or -1)#6119
mattcaswell wants to merge 1 commit intoopenssl:masterfrom
mattcaswell:bn-mod-inverse

Conversation

@mattcaswell
Copy link
Member

Calculating BN_mod_inverse where n is 1 (or -1) doesn't make sense. We
should return an error in that case. Instead we were returning a valid
result with value 0.

Fixes #6004

I've marked this as WIP because I'd like some feedback on this. It turns out that, even though it doesn't make any sense to ask for BN_mod_inverse() with n set to 1 we were doing it anyway - and rely on the fact that the result is 0. I have fixed the instance where that occurred, but it made me worry that if we are doing it, are there other applications doing it too (which we would break)?

The alternative to fixing it is to just document the quirk.

Should we fix it or document it?

Calculating BN_mod_inverse where n is 1 (or -1) doesn't make sense. We
should return an error in that case. Instead we were returning a valid
result with value 0.

Fixes openssl#6004
@mattcaswell
Copy link
Member Author

Ping @openssl/committers. Thoughts please!

@richsalz
Copy link
Contributor

Fix it. It's a math error.

@mattcaswell mattcaswell changed the title WIP: Return an error from BN_mod_inverse if n is 1 (or -1) Return an error from BN_mod_inverse if n is 1 (or -1) May 2, 2018
@mattcaswell
Copy link
Member Author

Taken out of WIP.

@mattcaswell mattcaswell added branch: master Applies to master branch 1.1.0 branch: 1.1.1 Applies to OpenSSL_1_1_1-stable branch (EOL) labels May 2, 2018
@mattcaswell
Copy link
Member Author

Forgot to add target branch labels. @richsalz are you ok for backport to 1.1.0? It cherry-picks cleanly.

@richsalz
Copy link
Contributor

richsalz commented May 3, 2018

Yes, I am fine with merging to other branches.

@richsalz richsalz added the approval: done This pull request has the required number of approvals label May 3, 2018
levitte pushed a commit that referenced this pull request May 3, 2018
Calculating BN_mod_inverse where n is 1 (or -1) doesn't make sense. We
should return an error in that case. Instead we were returning a valid
result with value 0.

Fixes #6004

Reviewed-by: Rich Salz <[email protected]>
(Merged from #6119)
levitte pushed a commit that referenced this pull request May 3, 2018
Calculating BN_mod_inverse where n is 1 (or -1) doesn't make sense. We
should return an error in that case. Instead we were returning a valid
result with value 0.

Fixes #6004

Reviewed-by: Rich Salz <[email protected]>
(Merged from #6119)

(cherry picked from commit b1860d6)
@mattcaswell
Copy link
Member Author

Pushed to master and 1.1.0. Thanks.

@mattcaswell mattcaswell closed this May 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: done This pull request has the required number of approvals branch: master Applies to master branch branch: 1.1.1 Applies to OpenSSL_1_1_1-stable branch (EOL)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BN_mod_inverse undocumented behaviour

2 participants