Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SM2 failed to generate public key from private key #24305

Open
Mnogard opened this issue Apr 30, 2024 · 5 comments
Open

SM2 failed to generate public key from private key #24305

Mnogard opened this issue Apr 30, 2024 · 5 comments
Labels
branch: master Merge to master branch branch: 3.0 Merge to openssl-3.0 branch branch: 3.1 Merge to openssl-3.1 branch: 3.2 Merge to openssl-3.2 branch: 3.3 Merge to openssl-3.3 help wanted triaged: bug The issue/pr is/fixes a bug

Comments

@Mnogard
Copy link

Mnogard commented Apr 30, 2024

Problem Description:

SM2 failed to generate public key from private key of 3.0 and 3.2.

command

1. generate sm2 private key file by OpenSSL commands of 3.0 and 3.2:

openssl ecparam -genkey -name SM2 -out sm2-private.key

2. failed to generate public key file with sm2 private key file

openssl ec -in sm2-private.key -pubout -out sm2-public.key

Preliminary analysis:

private key file

file generated by 1.1 as

-----BEGIN EC PARAMETERS-----
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
-----END EC PRIVATE KEY-----

file generated by 3.0 or 3.2 as

-----BEGIN SM2 PARAMETERS-----
-----END SM2 PARAMETERS-----
-----BEGIN SM2 PRIVATE KEY-----
-----END SM2 PRIVATE KEY-----

error in generating public key

read EC key
unable to enable public key encoding
4076A04EF87F0000:error:030000A3:digital envelope routines:EVP_PKEY_set_params:invalid key:crypto/evp/p_lib.c:2386:

analysis

Guess whether the high version is not compatible with the low version, or update the usage rules of related commands, because this group of commands is correct in version 1.1.

Tasks

No tasks being tracked yet.
@Mnogard Mnogard added the issue: bug report The issue was opened to report a bug label Apr 30, 2024
@t8m t8m added branch: master Merge to master branch help wanted triaged: bug The issue/pr is/fixes a bug branch: 3.0 Merge to openssl-3.0 branch branch: 3.1 Merge to openssl-3.1 branch: 3.2 Merge to openssl-3.2 branch: 3.3 Merge to openssl-3.3 and removed issue: bug report The issue was opened to report a bug labels Apr 30, 2024
@t8m
Copy link
Member

t8m commented Apr 30, 2024

Would these commands work for you:

openssl genpkey -algorithm SM2 -out sm2-private.key
openssl pkey -in sm2-private.key -pubout -out sm2-public.key

@Mnogard
Copy link
Author

Mnogard commented Apr 30, 2024

Is the sm2 key generated in this way provided by you the same as that generated in version 1.1 in the way mentioned earlier? I checked that the key generated by this method you provided is missing the contents of the PARAMETERS field.

@t8m
Copy link
Member

t8m commented Apr 30, 2024

Yes, the encoding of the key is different. The parameters are defined by the SM2 OID in the encoding of the key.

@Mnogard
Copy link
Author

Mnogard commented May 7, 2024

How to get the SM2 key I need in the version 3.0 or above?

@Mnogard
Copy link
Author

Mnogard commented May 9, 2024

Is this problem a bug in the current version 3.0 and above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
branch: master Merge to master branch branch: 3.0 Merge to openssl-3.0 branch branch: 3.1 Merge to openssl-3.1 branch: 3.2 Merge to openssl-3.2 branch: 3.3 Merge to openssl-3.3 help wanted triaged: bug The issue/pr is/fixes a bug
Projects
None yet
Development

No branches or pull requests

2 participants