public NetworkClientConnection(Protocol protocol, Func<IPublicKeyCrypto> publicKeyCryptoFactory, IAsymmetricKey authKey)
            : base(new [] { protocol }, publicKeyCryptoFactory, authKey, false)
        {
            Interlocked.Add (ref sendBufferLimit, AutoSizeFactor);

            if (authKey == null)
                throw new ArgumentNullException ("authKey");
        }
 /// <summary>
 /// Initialize this class
 /// </summary>
 /// 
 /// <param name="Key">The public or private key</param>
 /// 
 /// <exception cref="CryptoAsymmetricException">Thrown if an invalid key is used</exception>
 public MPKCKeyPair(IAsymmetricKey Key)
 {
     if (Key is MPKCPublicKey)
         _publicKey = (MPKCPublicKey)Key;
     else if (Key is MPKCPrivateKey)
         _privateKey = (MPKCPrivateKey)Key;
     else
         throw new CryptoAsymmetricException("MPKCKeyPair:Ctor", "Not a valid McEliece key!", new ArgumentException());
 }
Exemple #3
0
 /// <summary>
 /// Constructs a new key pair
 /// </summary>
 /// 
 /// <param name="Key">The public or private key</param>
 /// 
 /// <exception cref="CryptoAsymmetricException">Thrown if an invalid name is used</exception>
 public NTRUKeyPair(IAsymmetricKey Key)
 {
     if (Key is NTRUPublicKey)
         _publicKey = (NTRUPublicKey)Key;
     else if (Key is NTRUPrivateKey)
         _privateKey = (NTRUPrivateKey)Key;
     else
         throw new CryptoAsymmetricException("NTRUKeyPair:CTor", "Not a valid NTRU key!", new InvalidDataException());
 }
        /// <summary>
        /// Initialize this class
        /// </summary>
        /// 
        /// <param name="Parameters">The cipher Parameters</param>
        /// <param name="KeyPair">The public or private key</param>
        /// <param name="Tag">An identity field</param>
        /// 
        /// <exception cref="CryptoAsymmetricException">Thrown if an invalid key is used</exception>
        public AsymmetricContainer(IAsymmetricParameters Parameters, IAsymmetricKeyPair KeyPair, byte[] Tag = null)
        {
            if (!(KeyPair is IAsymmetricKeyPair))
                throw new CryptoAsymmetricException("KeyContainer:Ctor", "Not a valid key-pair!", new InvalidDataException());

            _publicKey = KeyPair.PublicKey;
            _privateKey = KeyPair.PrivateKey;
            _asmParameters = Parameters;
            _idTag = Tag;
        }
        /// <summary>
        /// Initialize this class
        /// </summary>
        /// 
        /// <param name="Parameters">The cipher Parameters</param>
        /// <param name="AsmKey">The Public or Private asymmetric key</param>
        /// <param name="Tag">An identity field</param>
        /// 
        /// <exception cref="CryptoAsymmetricException">Thrown if an invalid key is used</exception>
        public AsymmetricContainer(IAsymmetricParameters Parameters, IAsymmetricKey AsmKey, byte[] Tag = null)
        {
            _asmParameters = Parameters;
            _idTag = Tag;

            if (AsymmetricUtils.IsPublicKey(AsmKey))
                _publicKey = AsmKey;
            else
                _privateKey = AsmKey;
        }
Exemple #6
0
        /// <summary>
        /// Constructs a new key pair
        /// </summary>
        /// 
        /// <param name="PublicKey">The Public key</param>
        /// <param name="PrivateKey">The Private Key</param>
        /// 
        /// <exception cref="CryptoAsymmetricException">Thrown if an invalid key is used</exception>
        public NTRUKeyPair(IAsymmetricKey PublicKey, IAsymmetricKey PrivateKey)
        {
            if (!(PublicKey is NTRUPublicKey))
                throw new CryptoAsymmetricException("NTRUKeyPair:CTor", "Not a valid NTRU Public key!", new InvalidDataException());
            if (!(PrivateKey is NTRUPrivateKey))
                throw new CryptoAsymmetricException("NTRUKeyPair:CTor", "Not a valid NTRU Private key!", new InvalidDataException());

            _publicKey = (NTRUPublicKey)PublicKey;
            _privateKey = (NTRUPrivateKey)PrivateKey;
        }
        /// <summary>
        /// Initialize this class
        /// </summary>
        /// 
        /// <param name="PublicKey">The public key</param>
        /// <param name="PrivateKey">The corresponding private key</param>
        /// 
        /// <exception cref="CryptoAsymmetricSignException">Thrown if an invalid key is used</exception>
        public GMSSKeyPair(IAsymmetricKey PublicKey, IAsymmetricKey PrivateKey)
        {
            if (!(PublicKey is GMSSPublicKey))
                throw new CryptoAsymmetricSignException("GMSSKeyPair:Ctor", "Not a valid GMSS Public key!", new InvalidDataException());
            if (!(PrivateKey is GMSSPrivateKey))
                throw new CryptoAsymmetricSignException("GMSSKeyPair:Ctor", "Not a valid GMSS Private key!", new InvalidDataException());

            _publicKey = (GMSSPublicKey)PublicKey;
            _privateKey = (GMSSPrivateKey)PrivateKey;
            _publicKey = PublicKey;
            _privateKey = PrivateKey;
        }
Exemple #8
0
        /// <summary>
        /// Initialize this class
        /// </summary>
        /// 
        /// <param name="PublicKey">The public key</param>
        /// <param name="PrivateKey">The corresponding private key</param>
        /// 
        /// <exception cref="CryptoAsymmetricException">Thrown if an invalid key is used</exception>
        public RLWEKeyPair(IAsymmetricKey PublicKey, IAsymmetricKey PrivateKey)
        {
            if (!(PublicKey is RLWEPublicKey))
                throw new CryptoAsymmetricException("RLWEKeyPair:Ctor", "Not a valid RLWE Public key!", new InvalidDataException());
            if (!(PrivateKey is RLWEPrivateKey))
                throw new CryptoAsymmetricException("RLWEKeyPair:Ctor", "Not a valid RLWE Private key!", new InvalidDataException());

            _publicKey = (RLWEPublicKey)PublicKey;
            _privateKey = (RLWEPrivateKey)PrivateKey;
            _publicKey = PublicKey;
            _privateKey = PrivateKey;
        }
Exemple #9
0
 /// <summary>
 /// Returns the asymmetric keys family type
 /// </summary>
 /// 
 /// <param name="AsmKey">An asymmetric Public or Private key</param>
 /// 
 /// <returns>The asymmetric family designator</returns>
 public static AsymmetricEngines GetKeyType(IAsymmetricKey AsmKey)
 {
     if (AsmKey.GetType().Equals(typeof(NTRUPublicKey)) || AsmKey.GetType().Equals(typeof(NTRUPrivateKey)))
         return AsymmetricEngines.NTRU;
     else if (AsmKey.GetType().Equals(typeof(MPKCPublicKey)) || AsmKey.GetType().Equals(typeof(MPKCPrivateKey)))
         return AsymmetricEngines.McEliece;
     else if (AsmKey.GetType().Equals(typeof(RLWEPublicKey)) || AsmKey.GetType().Equals(typeof(RLWEPrivateKey)))
         return AsymmetricEngines.RingLWE;
     else if (AsmKey.GetType().Equals(typeof(RNBWPublicKey)) || AsmKey.GetType().Equals(typeof(RNBWPrivateKey)))
         return AsymmetricEngines.Rainbow;
     else
         return AsymmetricEngines.GMSS;
 }
Exemple #10
0
        public AlloyClient(IMachine machine, Func<IPublicKeyCrypto> cryptoFactory, IAsymmetricKey key)
            : base(new NetworkClientConnection (AlloyProtocol.Instance, cryptoFactory), MessageTypes.Reliable)
        {
            if (machine == null)
                throw new ArgumentNullException ("machine");

            this.machine = machine;
            this.machine.ScreenChanged += OnMachineScreensChanged;
            //this.machine.KeyboardEvent += OnKeyboardEvent;
            //this.machine.MouseEvent += OnMouseEvent;

            this.RegisterMessageHandler<MachineStateMessage> (OnMachineStateMessage);
            this.RegisterMessageHandler<MouseEventMessage> (OnMouseEventMessage);
            this.RegisterMessageHandler<KeyboardEventMessage> (OnKeyboardEventMessage);
        }
Exemple #11
0
 public void ShouldMapPrivateKeyContentTypeToPemWhenContentIsOpenSshAndPrivateKeyIsNotEcKey()
 {
     key    = Mock.Of <IAsymmetricKey>(k => k.IsPrivateKey && k.CipherType == CipherType.Rsa);
     result = provider.GetWriteKeyToFileCommand(key, "key", ContentType.OpenSsh);
     Assert.AreEqual(ContentType.Pem, result.ContentType);
 }
 /// <summary>
 /// Initialize this class
 /// </summary>
 /// 
 /// <param name="Key">The public or private key</param>
 /// 
 /// <exception cref="CryptoAsymmetricSignException">Thrown if an invalid key is used</exception>
 public GMSSKeyPair(IAsymmetricKey Key)
 {
     if (Key is GMSSPublicKey)
         _publicKey = (GMSSPublicKey)Key;
     else if (Key is GMSSPrivateKey)
         _privateKey = (GMSSPrivateKey)Key;
     else
         throw new CryptoAsymmetricSignException("GMSSKeyPair:Ctor", "Not a valid GMSS key!", new InvalidDataException());
 }
Exemple #13
0
        /// <summary>
        /// Initialize the cipher.
        /// <para>Requires a <see cref="MPKCPublicKey"/> for encryption, or a <see cref="MPKCPrivateKey"/> for decryption</para>
        /// </summary>
        /// 
        /// <param name="AsmKey">The <see cref="IAsymmetricKey"/> containing the McEliece public or private key</param>
        /// 
        /// <exception cref="CryptoAsymmetricException">Thrown if the cipher is not initialized or the key is invalid</exception>
        public void Initialize(IAsymmetricKey AsmKey)
        {
            if (!(AsmKey is MPKCPublicKey) && !(AsmKey is MPKCPrivateKey))
                throw new CryptoAsymmetricException("MPKCEncrypt:Initialize", "The key is not a valid Ring-KWE key!", new InvalidDataException());

            _isEncryption = (AsmKey is MPKCPublicKey);

            // init implementation engine
            _encEngine.Initialize(AsmKey);

            // get the sizes
            if (_isEncryption)
            {
                if (AsmKey == null)
                    throw new CryptoAsymmetricException("MPKCEncrypt:Initialize", "Encryption requires a public key!", new InvalidOperationException());
                if (!(AsmKey is MPKCPublicKey))
                    throw new CryptoAsymmetricException("MPKCEncrypt:Initialize", "The public key is invalid!", new ArgumentException());

                _maxCipherText = ((MPKCPublicKey)AsmKey).N >> 3;
                _maxPlainText = ((MPKCPublicKey)AsmKey).K >> 3;
            }
            else
            {
                if (AsmKey == null)
                    throw new CryptoAsymmetricException("MPKCEncrypt:Initialize", "Decryption requires a private key!", new InvalidOperationException());
                if (!(AsmKey is MPKCPrivateKey))
                    throw new CryptoAsymmetricException("MPKCEncrypt:Initialize", "The private key is invalid!", new ArgumentException());

                _maxPlainText = ((MPKCPrivateKey)AsmKey).K >> 3;
                _maxCipherText = ((MPKCPrivateKey)AsmKey).N >> 3;
            }

            _isInitialized = true;
        }
Exemple #14
0
        /// <summary>
        /// Initialize the cipher for Encryption; This Initialize() method is only for Encryption.
        /// <para>Requires a <see cref="NTRUPublicKey"/> for encryption operations.
        /// For Decryption use the se the <see cref="Initialize(IAsymmetricKeyPair)"/> method and pass a KeyPair with both Public and Private keys.
        /// </para>
        /// </summary>
        /// 
        /// <param name="AsmKey">The <see cref="IAsymmetricKey"/> containing the NTRU Public key</param>
        /// 
        /// <exception cref="CryptoAsymmetricException">Thrown if a key is invalid</exception>
        public void Initialize(IAsymmetricKey AsmKey)
        {
            if (AsmKey == null)
                throw new CryptoAsymmetricException("NTRUEncrypt:Initialize", "Not a valid NTRU public key!", new InvalidDataException());
            if (!(AsmKey is NTRUPublicKey))
                throw new CryptoAsymmetricException("NTRUEncrypt:Initialize", "Not a valid NTRU public key!", new InvalidDataException());

            _keyPair = new NTRUKeyPair(AsmKey);
            _isEncryption = true;
            _isInitialized = true;
        }
Exemple #15
0
        /// <summary>
        /// Return the key size of the working key
        /// </summary>
        /// 
        /// <param name="AsmKey">The key</param>
        /// 
        /// <returns>The size of the key</returns>
        /// 
        /// <exception cref="CryptoAsymmetricException">Thrown if cipher has not been initialized, or key is invalid</exception>
        public int GetKeySize(IAsymmetricKey AsmKey)
        {
            if (!_isInitialized)
                throw new CryptoAsymmetricException("RLWEEncrypt:GetKeySize", "The cipher has not been initialized!", new InvalidOperationException());

            if (AsmKey is RLWEPublicKey)
                return ((RLWEPublicKey)AsmKey).N;
            if (AsmKey is RLWEPrivateKey)
                return ((RLWEPrivateKey)AsmKey).N;

            throw new CryptoAsymmetricException("RLWEEncrypt:GetKeySize", "Unsupported key type!", new InvalidDataException());
        }
        /// <summary>
        /// Return the key size of the working key
        /// </summary>
        /// 
        /// <returns>The size of the key</returns>
        public int GetKeySize(IAsymmetricKey AsmKey)
        {
            if (AsmKey is MPKCPublicKey)
                return ((MPKCPublicKey)AsmKey).N;
            if (AsmKey is MPKCPrivateKey)
                return ((MPKCPrivateKey)AsmKey).N;

            throw new CryptoAsymmetricSignException("KobaraImaiCipher:Encrypt", "Unsupported Key type!", new ArgumentException());
        }
Exemple #17
0
        internal A CreateService <A>(ICryptoServiceType <A> type, IAsymmetricKey key, SecureRandom random)
        {
            CryptoStatus.IsReady();

            return((type as IServiceProvider <A>).GetFunc(this).Invoke(new KeyWithRandom(key, random)));
        }
Exemple #18
0
 public PublicKeyPayload(IAsymmetricKey publicKey, TryteString requestAddress)
     : base(publicKey.ToBytes().EncodeBytesAsString() + Constants.LineBreak + requestAddress.Value + Constants.End)
 {
     this.PublicKey      = publicKey;
     this.RequestAddress = requestAddress;
 }
Exemple #19
0
 /// <summary>
 /// Reads a key pair from an input stream.
 /// <para>Note: both keys must be present in the stream; ordered Public, Private.</para>
 /// </summary>
 ///
 /// <param name="KeyStream">An input stream containing an encoded key pair</param>
 public RLWEKeyPair(MemoryStream KeyStream)
 {
     _publicKey  = new RLWEPublicKey(KeyStream);
     _privateKey = new RLWEPrivateKey(KeyStream);
 }
Exemple #20
0
 public CreateSignatureCommand GetCreateSignatureCommand(IAsymmetricKey privateKey, byte[] content) => new CreateSignatureCommand
 {
     PrivateKey    = privateKey,
     ContentToSign = content
 };
                public void PrivateKeyIsAesEncrypted()
                {
                    IAsymmetricKey encryptedPrivateKey = encryptionProvider.EncryptPrivateKey(keyPair.PrivateKey, "foo", EncryptionType.Aes);

                    Assert.IsFalse(keyProvider.VerifyKeyPair(new AsymmetricKeyPair(encryptedPrivateKey, keyPair.PublicKey)));
                }
Exemple #22
0
 public void ShouldMapPrivateKeyContentTypeToPemWhenContentTypeForPublicKeyIsSec1()
 {
     key    = Mock.Of <IAsymmetricKey>(k => !k.IsPrivateKey);
     result = provider.GetWriteKeyToFileCommand(key, "key", ContentType.Sec1);
     Assert.AreEqual(ContentType.Pem, result.ContentType);
 }
Exemple #23
0
 public void ShouldNotMapPrivateKeyContentTypeToPemWhenContentIsOpenSshAndPrivateKeyIsCurve25519()
 {
     key    = Mock.Of <IEcKey>(k => k.IsPrivateKey && k.CipherType == CipherType.Ec && k.IsCurve25519);
     result = provider.GetWriteKeyToFileCommand(key, "key", ContentType.OpenSsh);
     Assert.AreEqual(ContentType.OpenSsh, result.ContentType);
 }
Exemple #24
0
 /// <summary>
 /// Initialize this class
 /// </summary>
 /// 
 /// <param name="Key">The public or private key</param>
 /// 
 /// <exception cref="CryptoAsymmetricSignException">Thrown if an invalid key is used</exception>
 public RNBWKeyPair(IAsymmetricKey Key)
 {
     if (Key is RNBWPublicKey)
         _publicKey = (RNBWPublicKey)Key;
     else if (Key is RNBWPrivateKey)
         _privateKey = (RNBWPrivateKey)Key;
     else
         throw new CryptoAsymmetricSignException("RNBWKeyPair:Ctor", "Not a valid RNBW key!", new InvalidDataException());
 }
Exemple #25
0
        /// <summary>
        /// Test if the asymmetric key is a Public key
        /// </summary>
        /// 
        /// <param name="AsmKey">The asymmetric key</param>
        /// 
        /// <returns>Returns <c>true</c> if it is a Public key, <c>false</c> for a private key</returns>
        public static bool IsPublicKey(IAsymmetricKey AsmKey)
        {
            if (AsmKey.GetType().Equals(typeof(NTRUPublicKey)) ||
                AsmKey.GetType().Equals(typeof(MPKCPublicKey)) ||
                AsmKey.GetType().Equals(typeof(RLWEPublicKey)) ||
                AsmKey.GetType().Equals(typeof(RNBWPublicKey)) ||
                AsmKey.GetType().Equals(typeof(GMSSPublicKey)))
                return true;

            return false;
        }
 /// <summary>
 /// Initialize this class
 /// </summary>
 /// 
 /// <param name="PublicKey">The public key</param>
 /// <param name="PrivateKey">The corresponding private key</param>
 public MPKCKeyPair(IAsymmetricKey PublicKey, IAsymmetricKey PrivateKey)
 {
     _publicKey = PublicKey;
     _privateKey = PrivateKey;
 }
Exemple #27
0
        public static ContactExchange Create(Contact contactDetails, IAsymmetricKey receiverPublicKey, IAsymmetricKey userPublicKey)
        {
            var encryption = NtruEncryption.Key;

            var encryptedContactDetails = encryption.Encrypt(receiverPublicKey, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(contactDetails)));
            var nonce = encryption.Encrypt(userPublicKey, Encoding.UTF8.GetBytes(DateTime.UtcNow.ToString("O")));

            return(new ContactExchange
            {
                Payload = TryteString.FromBytes(encryptedContactDetails).Concat(Constants.LineBreak).Concat(TryteString.FromBytes(nonce))
            });
        }
 /// <summary>
 /// Reads a key pair from an input stream.
 /// <para>Note: both keys must be present in the stream; ordered Public, Private.</para>
 /// </summary>
 /// 
 /// <param name="KeyStream">An input stream containing an encoded key pair</param>
 public MPKCKeyPair(MemoryStream KeyStream)
 {
     _publicKey = new MPKCPublicKey(KeyStream);
     _privateKey = new MPKCPrivateKey(KeyStream);
 }
Exemple #29
0
 /// <summary>
 /// Encrypt an array with an asymmetric cipher
 /// </summary>
 private byte[] AsymmetricEncrypt(IAsymmetricParameters Parameters, IAsymmetricKey PublicKey, byte[] Data)
 {
     using (IAsymmetricCipher cipher = GetAsymmetricCipher(Parameters))
     {
         cipher.Initialize(PublicKey);
         return cipher.Encrypt(Data);
     }
 }
        /// <summary>
        /// Initialize the cipher.
        /// <para>Requires a <see cref="MPKCPublicKey"/> for encryption, or a <see cref="MPKCPrivateKey"/> for decryption</para>
        /// </summary>
        /// 
        /// <param name="AsmKey">The <see cref="IAsymmetricKey"/> containing the McEliece public or private key</param>
        public void Initialize(IAsymmetricKey AsmKey)
        {
            if (!(AsmKey is MPKCPublicKey) && !(AsmKey is MPKCPrivateKey))
                throw new CryptoAsymmetricSignException("KobaraImaiCipher:Initialize", "The key is not a valid McEliece key!", new InvalidDataException());

            _isEncryption = (AsmKey is MPKCPublicKey);

            _asmKey = AsmKey;

            if (_isEncryption)
            {
                _rndEngine = GetPrng(_cprParams.RandomEngine);
                _N = ((MPKCPublicKey)AsmKey).N;
                _K = ((MPKCPublicKey)AsmKey).K;
                _T = ((MPKCPublicKey)AsmKey).T;
                _maxPlainText = (((MPKCPublicKey)AsmKey).K >> 3);
            }
            else
            {
                _N = ((MPKCPrivateKey)AsmKey).N;
                _K = ((MPKCPrivateKey)AsmKey).K;
                _T = ((MPKCPrivateKey)AsmKey).T;
            }
        }
Exemple #31
0
 /// <summary>
 /// Processes the clients Primary-Stage <see cref="IAsymmetricKey">AsymmetricKey</see> Public key.
 /// </summary>
 /// 
 /// <param name="PacketStream">A Stream containing the raw packet data</param>
 private void ProcessPrimeEx(MemoryStream PacketStream)
 {
     // get the header
     DtmPacket pktHdr = new DtmPacket(PacketStream);
     // read the data
     byte[] data = new byte[pktHdr.PayloadLength];
     PacketStream.Read(data, 0, data.Length);
     // use clients symmetric key to decrypt data
     byte[] dec = SymmetricTransform(_cltSymProcessor, data);
     // remove padding
     dec = UnwrapMessage(dec);
     MemoryStream cltStream = new MemoryStream(dec);
     // store the clients public key
     _cltPublicKey = GetAsymmetricPublicKey(cltStream, _cltAsmParams);
 }
Exemple #32
0
        /// <summary>
        /// Initialize the cipher.
        /// <para>Requires a <see cref="RLWEPublicKey"/> for encryption, or a <see cref="RLWEPrivateKey"/> for decryption</para>
        /// </summary>
        /// 
        /// <param name="AsmKey">The <see cref="IAsymmetricKey"/> containing the Ring-LWE Public or Private key</param>
        /// 
        /// <exception cref="CryptoAsymmetricException">Thrown if cipher has not been initialized</exception>
        public void Initialize(IAsymmetricKey AsmKey)
        {
            if (!(AsmKey is RLWEPublicKey) && !(AsmKey is RLWEPrivateKey))
                throw new CryptoAsymmetricException("RLWEEncrypt:Initialize", "The key is not a valid Ring-KWE key!", new InvalidDataException());

            _isEncryption = (AsmKey is RLWEPublicKey);
            _asmKey = AsmKey;
            _isInitialized = true;
        }
 public void Setup()
 {
     key = Mock.Of <IAsymmetricKey>();
     keyProvider.Setup(kp => kp.GetKeyFromSsh(keyContent))
     .Returns(key);
 }
Exemple #34
0
        /// <summary>
        /// Return the key size of the working key
        /// </summary>
        /// 
        /// <param name="Key">The key</param>
        /// 
        /// <returns>The size of the key</returns>
        /// 
        /// <exception cref="CryptoAsymmetricException">Thrown if the cipher is not initialized</exception>
        public int GetKeySize(IAsymmetricKey Key)
        {
            if (!_isInitialized)
                throw new CryptoAsymmetricException("MPKCEncrypt:GetKeySize", "The cipher has not been initialized!", new InvalidOperationException());

            if (Key is MPKCPublicKey)
                return ((MPKCPublicKey)Key).N;
            if (Key is MPKCPrivateKey)
                return ((MPKCPrivateKey)Key).N;

            throw new CryptoAsymmetricException("MPKCEncrypt:GetKeySize", "Unsupported key type!", new ArgumentException());
        }
Exemple #35
0
 /// <summary>
 /// Creates a new instance of the <see cref="ClientConnectedEventArgs"/> class.
 /// </summary>
 /// <param name="connection">The connection for the event.</param>
 /// <param name="publicKey">The server's public authentication key, if it has one.</param>
 public ClientConnectedEventArgs(IClientConnection connection, IAsymmetricKey publicKey)
     : base(connection)
 {
     ServerPublicKey = publicKey;
 }
Exemple #36
0
        internal A CreateService <A>(ICryptoServiceType <A> type, IAsymmetricKey key)
        {
            CryptoStatus.IsReady();

            return((type as IServiceProvider <A>).GetFunc(this).Invoke(key));
        }
Exemple #37
0
        /// <summary>
        /// Initialize the Key for Sign (Private) or Verify (Public)
        /// </summary>
        /// 
        /// <param name="AsmKey">The <see cref="IAsymmetricKey"/> containing the Generalized Merkle Signature Scheme Public (verify) or Private (sign) key</param>
        /// 
        /// <exception cref="CryptoAsymmetricSignException">Thrown if an invalid key is used</exception>
        public void Initialize(IAsymmetricKey AsmKey)
        {
            if (!(AsmKey is GMSSPublicKey) && !(AsmKey is GMSSPrivateKey))
                throw new CryptoAsymmetricSignException("GMSSSign:Initialize", "The key pair is not a valid GMSS key pair!", new InvalidDataException());

            Reset();
            _asmKey = AsmKey;
            _isInitialized = true;

            if (AsmKey is GMSSPrivateKey)
                InitSign();
            else
                InitVerify();
        }
Exemple #38
0
        /// <summary>
        /// Initialize the cipher
        /// </summary>
        /// 
        /// <param name="AsmKey">The <see cref="IAsymmetricKey"/> containing the McEliece Public (Sign) or Private (Verify) key</param>
        /// 
        /// <exception cref="CryptoAsymmetricException">Thrown if an invalid keypair is used</exception>
        public void Initialize(IAsymmetricKey AsmKey)
        {
            if (!(AsmKey is MPKCPublicKey) && !(AsmKey is MPKCPrivateKey))
                throw new CryptoAsymmetricSignException("MPKCSign:Initialize", "The key is not a valid RNBW key!", new InvalidDataException());

            Reset();
            _asmKey = AsmKey;
            _isInitialized = true;
        }
Exemple #39
0
 public void Setup()
 {
     key    = Mock.Of <IAsymmetricKey>();
     result = provider.GetWriteKeyToFileCommand(key, "key", ContentType.Der, EncryptionType.Pkcs, "foopassword");
 }
Exemple #40
0
 public SecondRankConnectionRequestMessage(byte[] symmetricKey, IAsymmetricKey networkKey, bool packetCreation = false) //-V3117
 {
     SymmetricKeyBytes = symmetricKey;
     this.networkKey   = networkKey;
 }
Exemple #41
0
 public async Task ConnectAsync(IEndPoint endPoint, IEndPoint sourceEndPoint, bool invokeEvents, IAsymmetricKey key, ISymmetricKey dummySymmetricKey, byte[] selfCustomData)
 {
     await ConnectManyAsync(new[] { endPoint }, sourceEndPoint, invokeEvents, key, dummySymmetricKey, selfCustomData);
 }
Exemple #42
0
 /// <summary>
 /// Processes the clients Auth-Stage <see cref="IAsymmetricKey">AsymmetricKey</see> Public key.
 /// <para>Stores the clients Auth-Stage Asymmetric Public Key.</para>
 /// </summary>
 /// 
 /// <param name="PacketStream">A Stream containing the raw packet data</param>
 private void ProcessPreAuth(MemoryStream PacketStream)
 {
     // seek past header
     PacketStream.Seek(DtmPacket.GetHeaderSize(), SeekOrigin.Begin);
     // get client params
     _cltAsmParams = GetAsymmetricParams(_cltIdentity.PkeId);
     // store client public key
     _cltPublicKey = GetAsymmetricPublicKey(PacketStream, _cltAsmParams);
 }
Exemple #43
0
        /// <summary>
        /// Constructs and initializes a new instance of the <see cref="ClientConnectionResult"/> class.
        /// </summary>
        /// <param name="result">The result of the connection attempt.</param>
        /// <param name="publicKey">The server's public authentication key, if it has one.</param>
        public ClientConnectionResult(ConnectionResult result, IAsymmetricKey publicKey)
        {
            if (!Enum.IsDefined (typeof(ConnectionResult), result))
                throw new ArgumentException ("result is not a valid member of ConnectionResult", "result");

            Result = result;
            ServerPublicKey = publicKey;
        }
Exemple #44
0
        /// <summary>
        /// Tear down the connection; destroys all structures provided by this class
        /// </summary>
        private void TearDown()
        {
            if (_rndGenerator != null)
            {
                _rndGenerator.Dispose();
                _rndGenerator = null;
            }
            if (_authKeyPair != null)
            {
                _authKeyPair.Dispose();
                _authKeyPair = null;
            }
            if (_cltAsmParams != null)
            {
                _cltAsmParams.Dispose();
                _cltAsmParams = null;
            }
            if (_cltPublicKey != null)
            {
                _cltPublicKey.Dispose();
                _cltPublicKey = null;
            }
            if (_primKeyPair != null)
            {
                _primKeyPair.Dispose();
                _primKeyPair = null;
            }
            // cipher streaming managed through class
            if (SessionEstablished == null || _disposeEngines == true)
            {
                if (_cltKeyParams != null)
                {
                    _cltKeyParams.Dispose();
                    _cltKeyParams = null;
                }
                if (_srvKeyParams != null)
                {
                    _srvKeyParams.Dispose();
                    _srvKeyParams = null;
                }
                if (_srvSymProcessor != null)
                {
                    _srvSymProcessor.Dispose();
                    _srvSymProcessor = null;
                }
                if (_cltSymProcessor != null)
                {
                    _cltSymProcessor.Dispose();
                    _cltSymProcessor = null;
                }
            }

            _bufferCount = 0;
            _bytesSent = 0;
            _bytesReceived = 0;
            _cltIdentity.Reset();
            _fileCounter = 0;
            _maxSendCounter = 0;
            _maxSendAttempts = MAXSNDATTEMPT;
            _rcvSequence = 0;
            _sndSequence = 0;
        }
Exemple #45
0
 /// <summary>
 /// Initialize this class
 /// </summary>
 ///
 /// <param name="PublicKey">The public key</param>
 /// <param name="PrivateKey">The corresponding private key</param>
 public MPKCKeyPair(IAsymmetricKey PublicKey, IAsymmetricKey PrivateKey)
 {
     _publicKey  = PublicKey;
     _privateKey = PrivateKey;
 }