Skip to content

Implement deterministic ECDSA sign (RFC6979)#9223

Closed
Jemmy1228 wants to merge 1 commit into
openssl:masterfrom
Jemmy1228:ecdsa_deterministic_signature
Closed

Implement deterministic ECDSA sign (RFC6979)#9223
Jemmy1228 wants to merge 1 commit into
openssl:masterfrom
Jemmy1228:ecdsa_deterministic_signature

Conversation

@Jemmy1228

@Jemmy1228 Jemmy1228 commented Jun 23, 2019

Copy link
Copy Markdown

Implements RFC6979 deterministic ECDSA/DSA sign (in this commit, only ECDSA is available)

ECDSA deterministic sign is now available by specifying "ecdsa_nonce_type:deterministic" when signing.
for example:

openssl dgst -sha1  -sign private.key -sigopt ecdsa_nonce_type:deterministic < test.data > test.sha1

Maybe fixed #2078

Checklist
  • documentation is added or updated
  • tests are added or updated

I haven't thought of that there would be so many comments in this PR.
I read through this thread and list the up-to-date TO-DOs here:

@openssl-machine openssl-machine added the hold: cla required The contributor needs to submit a license agreement label Jun 23, 2019
@beldmit

beldmit commented Jun 23, 2019

Copy link
Copy Markdown
Member

Is it possible to implement the deterministic signature schema via special EVP ctrl call?

@Jemmy1228

Copy link
Copy Markdown
Author

@beldmit It seems all signing calls would finally call EC_KEY_METHOD->sign_sig, in this case it would be ossl_ecdsa_sign_sig defined in crypto/ec/ec_kmeth.c . However, this method doesn't accept parameter about hash method, as I think, this has to be changed...

@Jemmy1228

Copy link
Copy Markdown
Author

@beldmit I missunderstood your meaning just now....
Yes, it is implemented via EVP ctrl call. ctrl_call can only set hash algorithm in the ctx. However, when producing ECDSA signatures, neither the ctx nor the hash nid will be passed to the real method that does the signing (ossl_ecdsa_sign_sig)

@Jemmy1228

Copy link
Copy Markdown
Author

Maybe call sign_setup directly in EVP, initialize k_reverse and r before calling sign_sig is a good way?

Comment thread include/openssl/bn.h Outdated
Comment thread include/openssl/bn.h Outdated
Comment thread include/openssl/ec.h Outdated
@Jemmy1228

Copy link
Copy Markdown
Author

Okay, I will change the code tonnight.
But, should I add a new user visible API for deterministic sign ?

@bbbrumley

Copy link
Copy Markdown
Contributor

@JemmyLoveJenny At a minimum, you should integrate the test vectors from RFC 6979 as plaintext EVP tests.

If you need help with that, my team has some tooling. Tagging @romen

@kroeckx

kroeckx commented Jun 24, 2019 via email

Copy link
Copy Markdown
Member

@Jemmy1228

Copy link
Copy Markdown
Author

@kroeckx Actually, the EVP ctx pmeth->sign would call ECDSA_sign. You mean that I can skip that method and call the kmeth->sign_sig directly in EVP ?

@Jemmy1228

Copy link
Copy Markdown
Author

@bbbrumley Yes, I will integrate these test vectors into EVP test finally.

@Jemmy1228 Jemmy1228 force-pushed the ecdsa_deterministic_signature branch from fd0175c to 1bd48bf Compare June 24, 2019 12:33
@Jemmy1228

Copy link
Copy Markdown
Author

@kroeckx
Please have a look at the new commit.
User visible APIs are not modified this time.

Comment thread crypto/ec/ec_lcl.h Outdated
Comment thread crypto/ec/ec_pmeth.c Outdated
@Jemmy1228

Jemmy1228 commented Jun 24, 2019

Copy link
Copy Markdown
Author

I have some questions about the checks

  1. [Solved] I should fill in the ICLA form in my language or English? If in Englilsh, the "Full Name" field would be my legal name in English form or the name that Engilsh-speaking people call me?

  2. [Solved] AppVeyor build fails and show the following result ..........

  3. Some of the Travis CI fail reasons are the same as AppVeyor, the others are related to documentation and MAKE UPDATE (mknum.pl). Whether it means there are no more errors with the code?

@mattcaswell

Copy link
Copy Markdown
Member

I should fill in the ICLA form in my language or English?

Yes.

If in Englilsh, the "Full Name" field would be my legal name in English form or the name that Engilsh-speaking people call me?

Please give your legal name in English.

@Jemmy1228

Copy link
Copy Markdown
Author

@beldmit Updated according to your suggestions

@slontis slontis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this code looked familiar.
Did you look at HMAC_DRBG.c ?
@paulidale would there be some way to rework this so it can use the drbg code?

Have a look at test/drbg_cavs_test.c for an example of how to drive the code..

Comment thread crypto/bn/bn_dsa.c Outdated
Comment thread crypto/bn/bn_dsa.c Outdated
Comment thread crypto/bn/bn_dsa.c Outdated
Comment thread crypto/bn/bn_dsa.c Outdated
Comment thread crypto/bn/bn_dsa.c Outdated
Comment thread crypto/ec/ec_pmeth.c Outdated
Comment thread crypto/ec/ec_pmeth.c Outdated
Comment thread crypto/ec/ec_pmeth.c Outdated
Comment thread crypto/ec/ecdsa_ossl.c Outdated
Comment thread crypto/ec/ec_pmeth.c Outdated
@slontis

slontis commented Jun 24, 2019

Copy link
Copy Markdown
Member

Travis failures are relevant. You have a memory leak somewhere.
Use valgrind on ./test/ecdsatest to track it down

@paulidale

Copy link
Copy Markdown
Contributor

Did you look at HMAC_DRBG.c

The similarity is great. Direct sharing of internal code between the two possibly isn't a great idea but if there was a way of using the HMAC-DRBG to get the same output, that would be worthwhile.

@Jemmy1228

Copy link
Copy Markdown
Author

@slontis Is the Travis ECDSA tests still failing? I thought it was solved in the most recent commit.

@slontis

slontis commented Jun 25, 2019

Copy link
Copy Markdown
Member

Maybe you havent pushed the new commits?

@Jemmy1228

Copy link
Copy Markdown
Author

@slontis
No, I've pushed it .
AppVeyor build contain ECDSA tests, it shows that tests passed.
I think the reason why Travis CI fails is that I didn't MAKE UPDATE (update libcrypto.num) and I didn't update the documentation.
Is the ECDSA tests still failing now? I didnt't find ECDSA failure in the Travis build log

@slontis

slontis commented Jun 25, 2019

Copy link
Copy Markdown
Member

I looked in travis 26035.2 (open the raw log and search for not ok)

@slontis

slontis commented Jun 25, 2019

Copy link
Copy Markdown
Member

If you look at the options for each build e.g for 26035.2 you will see what options it uses..
i.e "no-asm -Werror --debug no-afalgeng no-shared enable-crypto-mdebug enable-rc5 enable-md2"
So you can do the same locally and see if you reproduce the error. It is finding a problem because of the enable-crypto-mdebug option.
If you are using linux I would just run valgrind on the test.

@Jemmy1228

Copy link
Copy Markdown
Author

@slontis Oh, I see it... but it is confusing to me, some ECDH tests failed, even tests unrelated to EC failed...
I'm sorry that I'm at school now and won't be able to make commits until I get home.
I'll re-formate code and look into the ECDSA failure later.

@slontis

slontis commented Jun 25, 2019

Copy link
Copy Markdown
Member

No problems.. All those tests use ECDSA. Fix the one problem in a simpler test (which is a memory leak) and the others will most likely all be fixed also..

@Jemmy1228 Jemmy1228 closed this Jun 25, 2019
@Jemmy1228

Jemmy1228 commented Aug 27, 2020

Copy link
Copy Markdown
Author

@mspncp I noticed that OpenSSL has recently changed the RAND_DRBG API as described in #12509
I have read the documentation and find that it suggests using EVP_RAND_CTX instead.
I was suggested to write something like this example

If I understood it correctly, the fetched RAND_DRBG_CTX would call the real random generator to provide entropy and nonce, which means I have no chance to provide my own ones.

I read the evp_test.c in order to find out how to specify custom entropy and nonce.
It seems that it first fetches a EVP_RAND-TEST-RAND and its EVP_RAND_CTX
Then, it fetches the real EVP_RAND and set the previous EVP_RAND_CTX as the parent.
Finally, set OSSL_RAND_PARAM_TEST_ parameter for the first EVP_RAND_CTX

I wonder if this is the correct way of specifying custom entropy and nonce?
I don't know the purpose of chaining EVP_RAND_CTX, does it mean that the child will obtain entropy and nonce from the parent?

@paulidale

Copy link
Copy Markdown
Contributor

I read the evp_test.c in order to find out how to specify custom entropy and nonce.
It seems that it first fetches a EVP_RAND-TEST-RAND and its EVP_RAND_CTX
Then, it fetches the real EVP_RAND and set the previous EVP_RAND_CTX as the parent.
Finally, set OSSL_RAND_PARAM_TEST_ parameter for the first EVP_RAND_CTX

Currently, this is the only way to feed a random number generator specific seed material. Another place that does this is the FIPS known answer tests. Look for self_test_drbg() in providers/fips/self_test_kats.c. The code is pretty similar.

vszakats added a commit to curl/curl-for-win that referenced this pull request Nov 8, 2020
This reverts commit 9b0e818.

Turns out ECDSA signatures aren't deterministic at the moment, meaning the
signed executables are always different when re-built, due to the nonce
included in the signature. We need to wait till OpenSSL gets support for
deterministic ECDSA signatures, or run ahead and switch to EdDSA/ED25519,
which uses a deterministic nonce, out of the box. Could not find evidence
that Windows supports such code signatures, so either solutions will have
to wait.

Relevant links:
- OpenSSL PR: openssl/openssl#9223
- OpenSSL Issue: openssl/openssl#2078
- RFC: https://tools.ietf.org/html/rfc6979
@t8m t8m added this to the Post 3.0.0 milestone Dec 4, 2020
@Sajjon

Sajjon commented Apr 10, 2021

Copy link
Copy Markdown

What is the status of this PR? How can we get it merged? And also, sorry if this is completely off-topic, but how does BoringSSL and OpenSSL sync feature wise? Does Google's BoringSSL get updated with features X, Y, Z when added to OpenSSL? I.e. if we get deterministic signing (RFC6979) merged into OpenSSL, is it likely that BoringSSL will follow and implement that/cherry-pick that commit and merge it into their code base?

@t8m t8m added the triaged: feature The issue/pr requests/adds a feature label May 4, 2021
@vdukhovni

Copy link
Copy Markdown

May I ask whether there are still plans to get this PR (deterministic signing ala RFC6979) merged.

For example, "Knot DNS" now supports deterministic zone signing, but only when linked with GnuTLS. I really do think we should have an interoperable implementation in at least a 3.1 release, if not in any earlier versions...

@t8m

t8m commented Oct 11, 2021

Copy link
Copy Markdown
Member

May I ask whether there are still plans to get this PR (deterministic signing ala RFC6979) merged.

For example, "Knot DNS" now supports deterministic zone signing, but only when linked with GnuTLS. I really do think we should have an interoperable implementation in at least a 3.1 release, if not in any earlier versions...

I'd say why not. If someone brings it up-to-date with the current master branch which means making it into a provided implementation.

@vdukhovni

Copy link
Copy Markdown

I'd say why not. If someone brings it up-to-date with the current master branch which means making it into a provided implementation.

What do you mean by a "provided implementation"? Do you mean a separate provider? Or do you mean a feature (EVP_PKEY_CTX control operation?) of the default implementation?

Any volunteers to resume this effort?

@t8m

t8m commented Oct 12, 2021

Copy link
Copy Markdown
Member

I mean a feature of the existing implementation. The question is if it should be a separate algorithm or just a parameter of the existing ECDSA.

@t8m t8m added the waiting-for: contributor response This pull request is awaiting a response by the contributor label Dec 14, 2021
@mattcaswell

Copy link
Copy Markdown
Member

OTC: Can be reviewed through the normal review process.

Please rebase

@romen

romen commented Dec 14, 2021

Copy link
Copy Markdown
Member

@bbbrumley I just don't know what to do next...... I read through this PR just now, and I find that there are many suggestions. However, these things can't be done by myself.

For example, OpenSSL officials should provide an answer to the question "How to name the control parameters?" and "How to disable the DRBG length requirement without including rand_local.h"

@openssl/otc These questions should be answered to allow @JemmyLoveJenny to continue the work

@JemmyLoveJenny , despite the delays, are you still willing to work on this PR?

@Jemmy1228

Copy link
Copy Markdown
Author

@JemmyLoveJenny , despite the delays, are you still willing to work on this PR?

Yes, I'm still willing to work on this PR. But as you have mentioned, I need to know what to do next.
I will try to rebase this PR in a few days.

@openssl-machine

Copy link
Copy Markdown
Collaborator

This PR has been closed. It was waiting for the creator to make requested changes but it has not been updated for 90 days.

slontis added a commit to slontis/openssl that referenced this pull request Jul 15, 2022
This PR is based off the contributions in PR openssl#9223 by Jemmy1228.

It has been modified and reworked to:
(1) Work with providers
(2) Support ECDSA and DSA
(3) Use OpenSSL's HMAC_DRBG via the EVP_RAND_CTX interface. To do this
some behaviour of the DRBG needed to be disabled via a new OSSL_PARAM.

A nonce_type is passed around in the API's, just in case there are
future deterministic algorithms.
@slontis

slontis commented Jul 15, 2022

Copy link
Copy Markdown
Member

Hi @Jemmy1228 I have created a new PR #18809 based off your great work. (I have referenced you in the commit - hope that is ok).

slontis added a commit to slontis/openssl that referenced this pull request Jul 19, 2022
This PR is based off the contributions in PR openssl#9223 by Jemmy1228.

It has been modified and reworked to:
(1) Work with providers
(2) Support ECDSA and DSA
(3) Use a variant of OpenSSL's HMAC_DRBG via the EVP_RAND_CTX interface.

A nonce_type is passed around in the API's, just in case there are
future deterministic algorithms.
slontis added a commit to slontis/openssl that referenced this pull request Jul 25, 2022
This PR is based off the contributions in PR openssl#9223 by Jemmy1228.

It has been modified and reworked to:
(1) Work with providers
(2) Support ECDSA and DSA
(3) Add a KDF HMAC_DRBG implementation that shares code with the RAND HMAC_DRBG.

A nonce_type is passed around inside the Signing API's, in order to support any
future deterministic algorithms.
slontis added a commit to slontis/openssl that referenced this pull request Sep 13, 2022
This PR is based off the contributions in PR openssl#9223 by Jemmy1228.

It has been modified and reworked to:
(1) Work with providers
(2) Support ECDSA and DSA
(3) Add a KDF HMAC_DRBG implementation that shares code with the RAND HMAC_DRBG.

A nonce_type is passed around inside the Signing API's, in order to support any
future deterministic algorithms.
slontis added a commit to slontis/openssl that referenced this pull request Oct 27, 2022
This PR is based off the contributions in PR openssl#9223 by Jemmy1228.

It has been modified and reworked to:
(1) Work with providers
(2) Support ECDSA and DSA
(3) Add a KDF HMAC_DRBG implementation that shares code with the RAND HMAC_DRBG.

A nonce_type is passed around inside the Signing API's, in order to support any
future deterministic algorithms.
openssl-machine pushed a commit that referenced this pull request Nov 30, 2022
This PR is based off the contributions in PR #9223 by Jemmy1228.

It has been modified and reworked to:
(1) Work with providers
(2) Support ECDSA and DSA
(3) Add a KDF HMAC_DRBG implementation that shares code with the RAND HMAC_DRBG.

A nonce_type is passed around inside the Signing API's, in order to support any
future deterministic algorithms.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from #18809)
beldmit pushed a commit to beldmit/openssl that referenced this pull request Dec 26, 2022
This PR is based off the contributions in PR openssl#9223 by Jemmy1228.

It has been modified and reworked to:
(1) Work with providers
(2) Support ECDSA and DSA
(3) Add a KDF HMAC_DRBG implementation that shares code with the RAND HMAC_DRBG.

A nonce_type is passed around inside the Signing API's, in order to support any
future deterministic algorithms.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from openssl#18809)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

branch: master Applies to master branch triaged: feature The issue/pr requests/adds a feature waiting-for: contributor response This pull request is awaiting a response by the contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing deterministic ECDSA signatures support