/// <summary>
 /// Validates that a key is provided when required.
 /// When "Generates" is required, ensure you have at a minimum the public key.
 /// </summary>
 /// <param name="generationRequirements">The generation requirements for this party and scheme.</param>
 /// <exception cref="ArgumentNullException">Throw when required value is not provided.</exception>
 private void ValidateKey(SchemeKeyNonceGenRequirement generationRequirements)
 {
     if (generationRequirements.GeneratesEphemeralKeyPair && _key?.PubKey == null)
     {
         throw new ArgumentException($"{nameof(_key.PubKey)} cannot be null with this party's contributions.");
     }
 }
Example #2
0
 private void ValidateDomainParameters(SchemeKeyNonceGenRequirement schemeRequirements, IDsaDomainParameters domainParameters)
 {
     if (domainParameters == null)
     {
         throw new ArgumentNullException(nameof(domainParameters));
     }
 }
Example #3
0
 private void ValidateEphemeralKey(SchemeKeyNonceGenRequirement schemeRequirements, IDsaKeyPair ephemeralKey)
 {
     if (schemeRequirements.GeneratesEphemeralKeyPair && ephemeralKey == null)
     {
         throw new ArgumentNullException(nameof(ephemeralKey));
     }
 }
Example #4
0
 private void ValidatePartyId(SchemeKeyNonceGenRequirement schemeRequirements, BitString partyId)
 {
     if (schemeRequirements.KasMode != KasMode.NoKdfNoKc && partyId == null)
     {
         throw new ArgumentNullException(nameof(partyId));
     }
 }
Example #5
0
 private void ValidateDkmNonce(SchemeKeyNonceGenRequirement schemeRequirements, BitString dkmNonce)
 {
     if (schemeRequirements.GeneratesDkmNonce && dkmNonce == null)
     {
         throw new ArgumentNullException(nameof(dkmNonce));
     }
 }
Example #6
0
 private void ValidateEphemeralNonce(SchemeKeyNonceGenRequirement schemeRequirements, BitString ephemeralNonce)
 {
     if (schemeRequirements.GeneratesEphemeralNonce && ephemeralNonce == null)
     {
         throw new ArgumentNullException(nameof(ephemeralNonce));
     }
 }
Example #7
0
 private void ValidateStaticKey(SchemeKeyNonceGenRequirement schemeRequirements, IDsaKeyPair staticKey)
 {
     if (schemeRequirements.GeneratesStaticKeyPair && staticKey == null)
     {
         throw new ArgumentNullException(nameof(staticKey));
     }
 }
        /// <summary>
        /// Validates the "k" is provided when party U for KTS scheme.
        /// </summary>
        /// <param name="generationRequirements">The generation requirements for this party and scheme.</param>
        /// <param name="scheme">The scheme utilized for the KAS/KTS.</param>
        /// <exception cref="ArgumentNullException">Throw when required value is not provided.</exception>
        private void ValidateK(SchemeKeyNonceGenRequirement generationRequirements, IfcScheme scheme)
        {
            var ktsSchemes = new[] { IfcScheme.Kts_oaep_basic, IfcScheme.Kts_oaep_partyV_keyConfirmation };

            if (generationRequirements.ThisPartyKasRole == KeyAgreementRole.InitiatorPartyU && ktsSchemes.Contains(scheme) && _k?.BitLength == 0)
            {
                throw new ArgumentNullException($"{nameof(_key.PubKey)} cannot be null for this party and scheme.");
            }
        }
        /// <summary>
        /// Validates that a nonce is provided when required.
        /// </summary>
        /// <param name="generationRequirements">The generation requirements for this party and scheme.</param>
        /// <exception cref="ArgumentNullException">Throw when required value is not provided.</exception>
        private void ValidateNonce(SchemeKeyNonceGenRequirement generationRequirements)
        {
            if (generationRequirements.KasMode == KasMode.NoKdfNoKc)
            {
                return;
            }

            if (generationRequirements.GeneratesDkmNonce && _dkmNonce?.BitLength == 0)
            {
                throw new ArgumentNullException($"{nameof(_dkmNonce)} cannot be null with this party's contributions.");
            }
        }
        /// <summary>
        /// Validates a party id is provided.
        /// </summary>
        /// <param name="generationRequirements">The generation requirements for this party and scheme.</param>
        /// <exception cref="ArgumentNullException">Throw when required value is not provided.</exception>
        private void ValidatePartyId(SchemeKeyNonceGenRequirement generationRequirements)
        {
            if (generationRequirements.KasMode == KasMode.NoKdfNoKc)
            {
                return;
            }

            if (_partyId?.BitLength == 0)
            {
                throw new ArgumentNullException($"{nameof(_partyId)} cannot be null.");
            }
        }
Example #11
0
        private void ValidateConsistentAlgorithm(KasAlgorithm schemeRequirementsKasAlgo, SchemeKeyNonceGenRequirement schemeRequirementsRequirments, IDsaDomainParameters domainParameters, IDsaKeyPair ephemeralKey, IDsaKeyPair staticKey)
        {
            switch (schemeRequirementsKasAlgo)
            {
            case KasAlgorithm.Ffc:
                if (domainParameters.GetType() != typeof(FfcDomainParameters))
                {
                    throw new ArgumentException($"{nameof(domainParameters)} expected type {typeof(FfcDomainParameters)} got {domainParameters.GetType()}");
                }

                if (ephemeralKey != null && ephemeralKey.GetType() != typeof(FfcKeyPair))
                {
                    throw new ArgumentException($"{nameof(ephemeralKey)} expected type {typeof(FfcKeyPair)} got {ephemeralKey.GetType()}");
                }

                if (staticKey != null && staticKey.GetType() != typeof(FfcKeyPair))
                {
                    throw new ArgumentException($"{nameof(staticKey)} expected type {typeof(FfcKeyPair)} got {staticKey.GetType()}");
                }
                break;

            case KasAlgorithm.Ecc:
                if (domainParameters.GetType() != typeof(EccDomainParameters))
                {
                    throw new ArgumentException($"{nameof(domainParameters)} expected type {typeof(EccDomainParameters)} got {domainParameters.GetType()}");
                }

                if (ephemeralKey != null && ephemeralKey.GetType() != typeof(EccKeyPair))
                {
                    throw new ArgumentException($"{nameof(ephemeralKey)} expected type {typeof(EccKeyPair)} got {ephemeralKey.GetType()}");
                }

                if (staticKey != null && staticKey.GetType() != typeof(EccKeyPair))
                {
                    throw new ArgumentException($"{nameof(staticKey)} expected type {typeof(EccKeyPair)} got {staticKey.GetType()}");
                }
                break;

            default:
                throw new ArgumentException(nameof(schemeRequirementsKasAlgo));
            }
        }