Generated EC key has wrong length?

Roger Lipscombe roger@REDACTED
Thu May 20 17:29:56 CEST 2021


On Thu, 20 May 2021 at 16:28, Roger Lipscombe <roger@REDACTED> wrote:
>
> On Thu, 20 May 2021 at 16:26, Roger Lipscombe <roger@REDACTED> wrote:
> > The following snippet...
> >
> > [] = lists:foldl(fun(_, Acc) ->
> >         Key = public_key:generate_key({namedCurve, secp256r1}),
> >         {'ECPrivateKey', 1, PrivateKey, _Parameters, _PublicKey} = Key,
> >         case byte_size(PrivateKey) of
> >             32 -> Acc;
> >             _ -> [Key | Acc]
> >         end
> >     end, [], lists:seq(1, 10_000)).
> >
> > ...fails.
> >
> > secp256r1 private keys should be 32-bytes long, afaict. Should OTP be
> > zero-prefixing the key when converting to binary?
>
> OTP-24.0; should've mentioned that.

Bah. OTP-23.x; but it also fails in OTP-24.0 if you change the relevant line:

        {'ECPrivateKey', 1, PrivateKey, _Parameters, _PublicKey, _} = Key,


More information about the erlang-questions mailing list