I am attempting to obtain a shared secret using BouncyCastle's ECDH methods in C#, however I am receiving a shared key which is much shorter than the 48 bytes I expect it to be.
I have a trusted external source providing me (Side A) with a public key and a private key, these were generated for P192, and are of length 48 for the public and 24 for the private.
Also, I'm receiving a public key for the B side to calculate the agreement with.
I am expecting the shared key to be of length 48, but ending up with length 24.
string P192publicA = ""; // 48 length key string P192privateA = ""; // 24 length key string P192publicB = ""; // 48 length key DerObjectIdentifier p192Der = Org.BouncyCastle.Asn1.Sec.SecObjectIdentifiers.SecP192r1; ECKeyGenerationParameters ecparams = new ECKeyGenerationParameters(p192Der, new SecureRandom()); ECCurve curveP192 = ecparams.DomainParameters.Curve; ECPrivateKeyParameters ecPrivateA = new ECPrivateKeyParameters("ECDSA", new BigInteger(P192privateA, 16), p192Der); ECPublicKeyParameters ecPublicA = new ECPublicKeyParameters("ECDSA", curveP192.DecodePoint(Hex.Decode("04" + P192publicA)), p192Der); ECPublicKeyParameters ecPublicB = new ECPublicKeyParameters("ECDSA", curveP192.DecodePoint(Hex.Decode("04" + P192publicB)), p192Der); IBasicAgreement aKeyAgreeBasic = AgreementUtilities.GetBasicAgreement("ECDHC"); aKeyAgreeBasic.Init(ecPrivateA); BigInteger k = aKeyAgreeBasic.CalculateAgreement(ecPublicB);
My result in hex is only length 24 while I expected 48.
It there something wrong with my understanding of the key agreement mechanism? I wasn't sure about the decoding of a point, I saw in the bouncy examples they add "04" before decoding a point, and every other prefix I tried threw an exception.
Any tips will be greatly appreciated !