Answer the question
In order to leave comments, you need to log in
Why are different keys obtained in Diffie-Hellman?
Hello.
Problem: I am writing a chat on sockets and when creating a shared secret key using the Diffie-Hellman protocol, this very shared secret is not obtained. Features below.
Question: how to make sure that the shared secret key is correctly generated.
function computePartial(base, module, secret) {
return Math.pow(base, secret) % module;
}
function computeCommon(module, partial, secret) {
return Math.pow(partial, secret) % module;
}
Answer the question
In order to leave comments, you need to log in
1. All calculations must be in integers. Your Math.pow yields a real value greater than Number.MAX_SAFE_INTEGER, which makes the calculation pointless.
2. base (or g in the standard notation) must be a primitive root modulo module (or m in the standard notation). This means that the following conditions must be met:
g i % m ≠ 1, 1 ≤ i < m-1
g m-1 % m = 1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question