public void ShouldThrowArgumentExceptionOnInvalidMacType(KeyAgreementMacType keyAgreementMacType) { ModeValues mode = ModeValues.SHA1; DigestSizes digestSize = DigestSizes.NONE; Assert.Throws(typeof(ArgumentException), () => EnumMapping.GetHashFunctionOptions(keyAgreementMacType, ref mode, ref digestSize)); }
public INoKeyConfirmation GetInstance(INoKeyConfirmationParameters parameters) { switch (parameters.KeyAgreementMacType) { case KeyAgreementMacType.AesCcm: return(new NoKeyConfirmationAesCcm(_macDataCreator, parameters, new CcmBlockCipher(new AesEngine(), new ModeBlockCipherFactory(), new AES_CCMInternals()))); case KeyAgreementMacType.CmacAes: return(new NoKeyConfirmationCmac(_macDataCreator, parameters, _cmacFactory.GetCmacInstance(CmacTypes.AES128))); // doesn't matter as long as aea case KeyAgreementMacType.HmacSha1: case KeyAgreementMacType.HmacSha2D224: case KeyAgreementMacType.HmacSha2D256: case KeyAgreementMacType.HmacSha2D384: case KeyAgreementMacType.HmacSha2D512: case KeyAgreementMacType.HmacSha2D512_T224: case KeyAgreementMacType.HmacSha2D512_T256: case KeyAgreementMacType.HmacSha3D224: case KeyAgreementMacType.HmacSha3D256: case KeyAgreementMacType.HmacSha3D384: case KeyAgreementMacType.HmacSha3D512: ModeValues modeValue = ModeValues.SHA2; DigestSizes digestSize = DigestSizes.NONE; EnumMapping.GetHashFunctionOptions(parameters.KeyAgreementMacType, ref modeValue, ref digestSize); return(new NoKeyConfirmationHmac(_macDataCreator, parameters, _hmacFactory.GetHmacInstance(new HashFunction(modeValue, digestSize)))); default: throw new ArgumentException($"{GetType().Name}, {nameof(parameters.KeyAgreementMacType)}"); } }
public void ShouldSetCorrectHashFunctionAttributesFromHmac(KeyAgreementMacType keyAgreementMacType, ModeValues expectedModeValue, DigestSizes expectedDigestSize) { ModeValues mode = ModeValues.SHA1; DigestSizes digestSize = DigestSizes.NONE; EnumMapping.GetHashFunctionOptions(keyAgreementMacType, ref mode, ref digestSize); Assert.AreEqual(expectedModeValue, mode, nameof(expectedModeValue)); Assert.AreEqual(expectedDigestSize, digestSize, nameof(expectedDigestSize)); }
public IKeyConfirmation GetInstance(IKeyConfirmationParameters parameters) { switch (parameters.MacType) { case KeyAgreementMacType.AesCcm: ConfirmKeyLengthAesCcm(parameters.KeyLength); return(new KeyConfirmationAesCcm( _macDataCreator, parameters, new CcmBlockCipher(new AesEngine(), new ModeBlockCipherFactory(), new AES_CCMInternals()))); case KeyAgreementMacType.CmacAes: var cmacEnum = MapCmacEnum(parameters.KeyLength); return(new KeyConfirmationCmac( _macDataCreator, parameters, _cmacFactory.GetCmacInstance(cmacEnum))); case KeyAgreementMacType.HmacSha1: case KeyAgreementMacType.HmacSha2D224: case KeyAgreementMacType.HmacSha2D256: case KeyAgreementMacType.HmacSha2D384: case KeyAgreementMacType.HmacSha2D512: case KeyAgreementMacType.HmacSha2D512_T224: case KeyAgreementMacType.HmacSha2D512_T256: case KeyAgreementMacType.HmacSha3D224: case KeyAgreementMacType.HmacSha3D256: case KeyAgreementMacType.HmacSha3D384: case KeyAgreementMacType.HmacSha3D512: ModeValues modeValue = ModeValues.SHA2; DigestSizes digestSize = DigestSizes.NONE; EnumMapping.GetHashFunctionOptions(parameters.MacType, ref modeValue, ref digestSize); return(new KeyConfirmationHmac( _macDataCreator, parameters, _hmacFactory.GetHmacInstance(new HashFunction(modeValue, digestSize)))); case KeyAgreementMacType.Kmac_128: return(new KeyConfirmationKmac(_macDataCreator, parameters, _kmacFactory, 256)); case KeyAgreementMacType.Kmac_256: return(new KeyConfirmationKmac(_macDataCreator, parameters, _kmacFactory, 512)); default: throw new ArgumentException($"{GetType().Name}, {nameof(parameters.MacType)}"); } }
public void ShouldMacCorrectly(int keyLength, int macLength, KeyAgreementMacType keyAgreementMacType, BitString dkm, BitString nonce, BitString expectedMacData, BitString expectedMac) { ModeValues modeValue = ModeValues.SHA2; DigestSizes digestSize = DigestSizes.NONE; EnumMapping.GetHashFunctionOptions(keyAgreementMacType, ref modeValue, ref digestSize); NoKeyConfirmationParameters p = new NoKeyConfirmationParameters(keyAgreementMacType, macLength, dkm, nonce); _subject = new NoKeyConfirmationHmac(new NoKeyConfirmationMacDataCreator(), p, _algoFactory.GetHmacInstance(new HashFunction(modeValue, digestSize))); var result = _subject.ComputeMac(); Assert.That(result.Success, nameof(result.Success)); Assert.AreEqual(expectedMacData.ToHex(), result.MacData.ToHex(), nameof(result.MacData)); Assert.AreEqual(expectedMac.ToHex(), result.Mac.ToHex(), nameof(result.Mac)); }