public AsyncDtlsClientContext(SecureRandom secureRandom, AsyncDtlsSecurityParameters securityParameters)
        {
            IDigest d = TlsUtilities.CreateHash(HashAlgorithm.sha256);

            byte[] seed = new byte[d.GetDigestSize()];
            secureRandom.NextBytes(seed);

            this.nonceRandom = new DigestRandomGenerator(d);
            nonceRandom.AddSeedMaterial(NextCounterValue());
            nonceRandom.AddSeedMaterial(Times.NanoTime());
            nonceRandom.AddSeedMaterial(seed);

            this.secureRandom       = secureRandom;
            this.securityParameters = securityParameters;
        }
Пример #2
0
        internal AbstractTlsContext(SecureRandom secureRandom, SecurityParameters securityParameters)
        {
            IDigest d = TlsUtilities.CreateHash(HashAlgorithm.sha256);

            byte[] seed = new byte[d.GetDigestSize()];
            secureRandom.NextBytes(seed);

            this.mNonceRandom = new DigestRandomGenerator(d);
            mNonceRandom.AddSeedMaterial(NextCounterValue());
            mNonceRandom.AddSeedMaterial(Times.NanoTime());
            mNonceRandom.AddSeedMaterial(seed);

            this.mSecureRandom       = secureRandom;
            this.mSecurityParameters = securityParameters;
        }
Пример #3
0
 public DTLSContext(bool client, Version version, HandshakeInfo handshakeInfo)
 {
     IsServer = !client;
     if (version == DTLSRecord.Version1_2)
     {
         ClientVersion = ProtocolVersion.DTLSv12;
         ServerVersion = ProtocolVersion.DTLSv12;
     }
     else
     {
         ClientVersion = ProtocolVersion.DTLSv10;
         ServerVersion = ProtocolVersion.DTLSv10;
     }
     SecurityParameters   = new DTLSSecurityParameters(version, handshakeInfo);
     NonceRandomGenerator = new DigestRandomGenerator(TlsUtilities.CreateHash(HashAlgorithm.sha256));
     NonceRandomGenerator.AddSeedMaterial(Times.NanoTime());
 }
        private static IRandomGenerator CreateNonceRandom(SecureRandom secureRandom, int connectionEnd)
        {
            byte[] additionalSeedMaterial = new byte[16];
            Pack.UInt64_To_BE((ulong)NextCounterValue(), additionalSeedMaterial, 0);
            Pack.UInt64_To_BE((ulong)Times.NanoTime(), additionalSeedMaterial, 8);
            additionalSeedMaterial[0] &= 0x7F;
            additionalSeedMaterial[0] |= (byte)(connectionEnd << 7);

            IDigest digest = TlsUtilities.CreateHash(HashAlgorithm.sha256);

            byte[] seed = new byte[digest.GetDigestSize()];
            secureRandom.NextBytes(seed);

            IRandomGenerator nonceRandom = new DigestRandomGenerator(digest);

            nonceRandom.AddSeedMaterial(additionalSeedMaterial);
            nonceRandom.AddSeedMaterial(seed);
            return(nonceRandom);
        }