public void ShouldThrowWithInvalidKeyLengthCmac(KeyAgreementMacType macType, int keyLength) { var p = new KeyConfirmationParameters(0, 0, 0, macType, keyLength, 0, null, null, null, null, null); Assert.Throws(typeof(ArgumentException), () => _subject.GetInstance(p)); }
public void ShouldReturnCorrectMac( int keySize, int tagLength, BitString serverId, BitString iutId, BitString serverPublicKey, BitString iutPublicKey, BitString derivedKeyingMaterial, BitString expectedMacData, BitString expectedTag) { var cmac = _cmacFactory.GetCmacInstance(CmacTypes.AES128); // doesn't matter for scope of testing this, as long as AES var p = new KeyConfirmationParameters( KeyAgreementRole.InitiatorPartyU, KeyConfirmationRole.Provider, KeyConfirmationDirection.Bilateral, KeyAgreementMacType.CmacAes, // note this doesn't matter for the scope of this test keySize, tagLength, iutId, serverId, iutPublicKey, serverPublicKey, derivedKeyingMaterial ); _subject = new KeyConfirmationCmac(new KeyConfirmationMacDataCreator(), p, cmac); var result = _subject.ComputeMac(); Assert.That(result.Success); Assert.AreEqual(expectedMacData.ToHex(), result.MacData.ToHex(), nameof(expectedMacData)); Assert.AreEqual(expectedTag.ToHex(), result.Mac.ToHex(), nameof(expectedTag)); }
public void ShouldReturnCorrectMac( int keySize, int tagLength, BitString serverId, BitString iutId, BitString nonce, BitString serverPublicKey, BitString iutPublicKey, BitString derivedKeyingMaterial, BitString expectedMacData, BitString expectedTag) { var ccm = new CcmBlockCipher(new AesEngine(), new ModeBlockCipherFactory(), new AES_CCMInternals()); var p = new KeyConfirmationParameters( KeyAgreementRole.InitiatorPartyU, KeyConfirmationRole.Provider, KeyConfirmationDirection.Bilateral, KeyAgreementMacType.AesCcm, // note this doesn't matter for the scope of this test keySize, tagLength, iutId, serverId, iutPublicKey, serverPublicKey, derivedKeyingMaterial, nonce ); _subject = new KeyConfirmationAesCcm(new KeyConfirmationMacDataCreator(), p, ccm); var result = _subject.ComputeMac(); Assert.That(result.Success); Assert.AreEqual(expectedMacData.ToHex(), result.MacData.ToHex(), nameof(expectedMacData)); Assert.AreEqual(expectedTag.ToHex(), result.Mac.ToHex(), nameof(expectedTag)); }
public void ShouldReturnCorrectMac( string label, KeyAgreementRole thisKaRole, KeyConfirmationRole thisKcRole, KeyConfirmationDirection thisKcType, BitString thisId, BitString otherId, BitString thisPublicKey, BitString otherPublicKey, BitString expectedMacData) { var p = new KeyConfirmationParameters( thisKaRole, thisKcRole, thisKcType, KeyAgreementMacType.CmacAes, 0, 0, thisId, otherId, thisPublicKey, otherPublicKey, new BitString(0) ); _subject = new FakeKeyConfirmationBase(new KeyConfirmationMacDataCreator(), p); var result = _subject.GetMacData(); Assert.AreEqual(expectedMacData.ToHex(), result.ToHex()); }
public void ShouldReturnCorrectInstance(KeyAgreementMacType macType, int keyLength, Type expectedType) { IKeyConfirmation result = null; if (macType == KeyAgreementMacType.AesCcm) { KeyConfirmationParameters p = new KeyConfirmationParameters(0, 0, 0, macType, keyLength, 0, null, null, null, null, null, new BitString(1)); result = _subject.GetInstance(p); } else { KeyConfirmationParameters p = new KeyConfirmationParameters(0, 0, 0, macType, keyLength, 0, null, null, null, null, null); result = _subject.GetInstance(p); } Assert.IsInstanceOf(expectedType, result); }