diff --git a/lib/public_key/src/public_key.erl b/lib/public_key/src/public_key.erl index f2e675eb372f..243e5548d3b3 100644 --- a/lib/public_key/src/public_key.erl +++ b/lib/public_key/src/public_key.erl @@ -422,7 +422,7 @@ pem_entry_decode({'SubjectPublicKeyInfo', Der, _}) -> {params, DssParams} = der_decode('DSAParams', Params), {der_decode(KeyType, Key0), DssParams}; 'ECPoint' -> - ECCParams = der_decode('EcpkParameters', Params), + ECCParams = ec_decode_params(AlgId, Params), {#'ECPoint'{point = Key0}, ECCParams} end; pem_entry_decode({Asn1Type, Der, not_encrypted}) when is_atom(Asn1Type), @@ -2271,6 +2271,12 @@ cacerts_clear() -> %%-------------------------------------------------------------------- %%% Internal functions %%-------------------------------------------------------------------- +ec_decode_params(AlgId, _) when AlgId == ?'id-Ed25519'; + AlgId == ?'id-Ed448' -> + {namedCurve, AlgId}; +ec_decode_params(_, Params) -> + der_decode('EcpkParameters', Params). + default_options([]) -> [{rsa_padding, rsa_pkcs1_padding}]; default_options(Opts) -> diff --git a/lib/public_key/test/public_key_SUITE.erl b/lib/public_key/test/public_key_SUITE.erl index ca34d7d4139b..a85a5d4b017a 100644 --- a/lib/public_key/test/public_key_SUITE.erl +++ b/lib/public_key/test/public_key_SUITE.erl @@ -61,6 +61,8 @@ eddsa_priv_pkcs8/1, eddsa_priv_rfc5958/0, eddsa_priv_rfc5958/1, + eddsa_pub/0, + eddsa_pub/1, eddsa_sign_verify_24_compat/1, init_ec_pem_encode_generated/1, ec_pem_encode_generated/0, @@ -495,6 +497,20 @@ eddsa_priv_rfc5958(Config) when is_list(Config) -> ECPemNoEndNewLines = strip_superfluous_newlines(ECPrivPem), ECPemNoEndNewLines = strip_superfluous_newlines(public_key:pem_encode([PrivEntry0])). +eddsa_pub() -> + [{doc, "EDDSA PKCS8 public key decode/encode"}]. +eddsa_pub(Config) when is_list(Config) -> + Datadir = proplists:get_value(data_dir, Config), + {ok, EDDSAPubPem} = file:read_file(filename:join(Datadir, "public_eddsa.pem")), + [{'SubjectPublicKeyInfo', _, not_encrypted} = Key] = PemEntry = + public_key:pem_decode(EDDSAPubPem), + EDDSAPubKey = public_key:pem_entry_decode(PemEntry), + true = check_entry_type(EDDSAPubKey, 'ECPoint'), + {_, {namedCurve, ?'id-Ed25519'}} = EDDSAPubKey, + PrivEntry0 = public_key:pem_entry_encode('SubjectPublicKeyInfo', EDDSAPubKey), + ECPemNoEndNewLines = strip_superfluous_newlines(EDDSAPubPem), + ECPemNoEndNewLines = strip_superfluous_newlines(public_key:pem_encode([PemEntry])). + eddsa_sign_verify_24_compat(_Config) -> Key = {'ECPrivateKey',1, diff --git a/lib/public_key/test/public_key_SUITE_data/public_eddsa.pem b/lib/public_key/test/public_key_SUITE_data/public_eddsa.pem new file mode 100644 index 000000000000..43db3af730e8 --- /dev/null +++ b/lib/public_key/test/public_key_SUITE_data/public_eddsa.pem @@ -0,0 +1,3 @@ +-----BEGIN PUBLIC KEY----- +MCowBQYDK2VwAyEAzVMFUvlbihtNisegppBVAct8qRH2Ql3KZ57JAxt8Gms= +-----END PUBLIC KEY-----