Skip to content

Commit 93bb4b9

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 93bb4b9

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/ssh/src/ssh_transport.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2188,7 +2188,8 @@ dh_group('diffie-hellman-group18-sha512') -> ?dh_group18.
21882188
parallell_gen_key(Ssh = #ssh{keyex_key = {x, {G, P}},
21892189
algorithms = Algs}) ->
21902190
Sz = dh_bits(Algs),
2191-
{Public, Private} = generate_key(dh, [P,G,2*Sz]),
2191+
BitSize = fun(N) -> bit_size(binary:encode_unsigned(N)) end,
2192+
{Public, Private} = generate_key(dh, [P,G,min(BitSize(P)-1, 2*Sz)]),
21922193
Ssh#ssh{keyex_key = {{Private, Public}, {G, P}}}.
21932194

21942195

0 commit comments

Comments
 (0)