Skip to content

Commit 676526e

Browse files
committed
ssh: adjust private key length for DH key generation
- if calculated private key length is equal or exceeds number of bits in P (PBits) - use PBits - 1
1 parent 412bff5 commit 676526e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/ssh/src/ssh_transport.erl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2195,7 +2195,11 @@ parallell_gen_key(Ssh = #ssh{keyex_key = {x, {G, P}},
21952195
generate_key(ecdh, Args) ->
21962196
crypto:generate_key(ecdh, Args);
21972197
generate_key(dh, [P,G,Sz2]) ->
2198-
{Public,Private} = crypto:generate_key(dh, [P, G, max(Sz2,?MIN_DH_KEY_SIZE)] ),
2198+
BitSize = fun(N) -> bit_size(binary:encode_unsigned(N)) end,
2199+
{Public,Private} =
2200+
crypto:generate_key(dh,
2201+
[P, G, max(min(BitSize(P)-1, Sz2),
2202+
?MIN_DH_KEY_SIZE)]),
21992203
{crypto:bytes_to_integer(Public), crypto:bytes_to_integer(Private)}.
22002204

22012205

0 commit comments

Comments
 (0)