Closed iodev closed 6 years ago
The errors go away if I change the first line of GetAgreement to use:
new BigInteger(1, Privkey)
This ensures the byte array is interpreted as a positive integer. It's not obvious to me where Privkey picks up a signed value (i.e. high-bit 1), but all of the code seems a bit confused about converting to/from byte arrays.
e.g. the last line of GetAgreement should be:
return BigIntegers.AsUnsignedByteArray(basicAgreement.GetFieldSize(), agreement);
so that the result is of a fixed length.
I have a blocking issue (using Portable.BouncyCastle v1.8.1.3 nuget package). Using the following code, the error is isolated. Within 55 exchanges, between receiver and sender, the agreement calculation will not match on the receiving side, at some random point. The occasion that the error occurs is flagged out in the console app attached; that is, when sender and receiver do not calculate the same agreement. To avoid the initial exchange error that would occur, you can uncomment the initial keys, or leave it as it is here, with two initial exchanges, not reporting the error. So, in Main, if you use the 4 keys, then you can comment out the first two initial exchanges before the loop.
Here is the code:
Attaching runnable console solution. My.zip