Exemple #1
0
        /// <summary>
        ///     Create a configuration for a stream cipher.
        /// </summary>
        /// <param name="cipher">Stream cipher to use.</param>
        /// <param name="keySize">Key size to use, in bits.</param>
        /// <returns>Stream cipher configuration DTO.</returns>
        public static CipherConfiguration CreateStreamCipherConfiguration(StreamCipher cipher, int?keySize = null)
        {
            var config = new CipherConfiguration {
                Type = CipherType.Stream
            };

            int keySizeNonNull = keySize ?? Athena.Cryptography.StreamCiphers[cipher].DefaultKeySizeBits;

            if (keySize == null || Athena.Cryptography.StreamCiphers[cipher].AllowableKeySizesBits.Contains(keySizeNonNull))
            {
                config.KeySizeBits = keySizeNonNull;
            }
            else
            {
                throw new CipherKeySizeException(cipher, keySizeNonNull);
            }
            config.CipherName = cipher.ToString();

            if (Athena.Cryptography.StreamCiphers[cipher].DefaultNonceSizeBits != -1)
            {
                config.InitialisationVector = new byte[Athena.Cryptography.StreamCiphers[cipher].DefaultNonceSizeBits / 8];
                StratCom.EntropySupplier.NextBytes(config.InitialisationVector);
            }

            return(config);
        }
Exemple #2
0
 public CipherKeySizeException(StreamCipher cipherEnum, int requestedSizeBits)
     : this(cipherEnum.ToString(), requestedSizeBits, Athena.Cryptography.StreamCiphers[cipherEnum].AllowableKeySizesBits.ToList())
 {
 }
Exemple #3
0
 /// <summary>
 ///     Stream cipher to be used e.g. Salsa20, HC-128, etc.
 /// </summary>
 public void SetStreamCipher(StreamCipher value)
 {
     Configuration.CipherName = value.ToString();
 }