I have a requirement which states.
use, to calculate the Shared Secret Z, the Static Unified Model, C(0e, 2s, ECC CDH)Key Agreement technique (as specified in NIST Special Publication 800-56Ar214 save for the requirement to zeroize the Shared Secret) with:
the Single-step Key Derivation Function (KDF) based on SHA-256, as specified in NIST Special Publication 800-56Ar2; and
the P-256 curve for the elliptic curve operations
I have already read and tried to implement what I found here but it does not work.
At this point I can verify the Shared Secret is correct but I cannot get the proper key nor can I (without editing Bouncy Castle source) figure how to bring OtherInfo into the calculaiton. I have searched and searched...
The code is quite simple
private static Byte[] getSingleStepKDF_SHA256( Byte[] OtherInfo,
Byte[] PrivateKey,
Byte[] PublicKey,
Int32 DesiredKeyBitLength
)
{
BigInteger bi = null;
X9ECParameters curve = null;
ECDomainParameters ecParam = null;
ECPrivateKeyParameters privKey = null;
ECPublicKeyParameters pubKey = null;
ECDHWithKdfBasicAgreement agree = null;
ECPoint point = null;
ECDHKekGenerator ecGen = null;
/***********************************************************************
*
* I currently do not know how to include OtherInfo into the
* calculation. I have tried actually modifying ECDHKekGenerator by
* overloading CalculateAgreement to accept OtherInfo. This had no
* affect on the resulting key. I have tried using KdfParameters but
* ECDHWithKdfBasicAgreement raises an exception when I do that.
*
* The shared seceret is always correct.
*
************************************************************************/
curve = NistNamedCurves.GetByName( "P-256" );
ecParam = new ECDomainParameters( curve.Curve, curve.G, curve.N, curve.H, curve.GetSeed() );
privKey = new ECPrivateKeyParameters( new BigInteger( PrivateKey ), ecParam );
point = ecParam.Curve.DecodePoint( PublicKey );
pubKey = new ECPublicKeyParameters( point, ecParam );
ecGen = new ECDHKekGenerator( DigestUtilities.GetDigest( "SHA256" ) );
agree = new ECDHWithKdfBasicAgreement( NistObjectIdentifiers.IdAes256Cbc.ToString(), ecGen );
agree.Init( privKey );
// The shared secret is calculated in this method as well as the key
bi = agree.CalculateAgreement( pubKey );
return bi.ToByteArrayUnsigned().Take( ( int )( DesiredKeyBitLength / 8 ) ).ToArray();
}
I am stumped and would appreciate any help on what I am doing wrong. Thanks