Discussion:
Generated EC key has wrong length?
Roger Lipscombe
2021-05-20 15:26:49 UTC
Permalink
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?
Roger Lipscombe
2021-05-20 15:28:06 UTC
Permalink
Post by Roger Lipscombe
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.
Roger Lipscombe
2021-05-20 15:29:56 UTC
Permalink
Post by Roger Lipscombe
Post by Roger Lipscombe
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,
Stanislav Ledenev
2021-05-22 11:16:46 UTC
Permalink
This will concern me in near future.
It's very strange and more like some kind of error (round-off or smth.).
As far as I remember there was nothing with elliptic curves which requires
any kind of prefixes(padding) by any standards.
Keys sizes are quite clear. And variability of length is with
compressed/uncompressed public key. I think...

Sorry, nothing helpful just to bump up this question.
Roger Lipscombe
2021-05-22 12:25:59 UTC
Permalink
This is now filed as https://github.com/erlang/otp/issues/4861
Post by Stanislav Ledenev
This will concern me in near future.
It's very strange and more like some kind of error (round-off or smth.).
As far as I remember there was nothing with elliptic curves which requires any kind of prefixes(padding) by any standards.
Keys sizes are quite clear. And variability of length is with compressed/uncompressed public key. I think...
Sorry, nothing helpful just to bump up this question.
Stanislav Ledenev
2021-05-22 18:06:26 UTC
Permalink
Thank you. I'll keep an eye on that!
Post by Roger Lipscombe
This is now filed as https://github.com/erlang/otp/issues/4861
Continue reading on narkive:
Loading...