public PseudoRandomFunctionTLSGeneric(string type) { if (type.Equals("MD5")) { _type = TLSGenericType.MD5; } else if (type.Equals("SHA1")) { _type = TLSGenericType.SHA1; } else if (type.Equals("SHA256")) { _type = TLSGenericType.SHA256; } else if (type.Equals("SHA384")) { _type = TLSGenericType.SHA384; } else if (type.Equals("SHA512")) { _type = TLSGenericType.SHA512; } else { throw new Exception("Unsupported PRF type"); } }
public TLSGenericDeriveBytes(TLSGenericType type, byte[] secret, byte[] seed) { /* Here should be all supported types */ switch (type) { case TLSGenericType.MD5: _hmac = new HMACGeneric(secret, type, 64); break; case TLSGenericType.SHA1: _hmac = new HMACGeneric(secret, type, 64); break; case TLSGenericType.SHA256: _hmac = new HMACGeneric(secret, type, 64); break; case TLSGenericType.SHA384: _hmac = new HMACGeneric(secret, type, 128); break; case TLSGenericType.SHA512: _hmac = new HMACGeneric(secret, type, 128); break; default: throw new Exception("Unsupported TLSGenericType"); } /* Set the seed as our parameter */ _seed = seed; /* Reset the HMAC generators */ Reset(); }
public HMACGeneric(byte[] key, TLSGenericType hashType, int blockSize) { if (key == null) { throw new ArgumentNullException("key"); } _hashType = hashType; this._hashAlgorithm = CreateHashAlgorithm(); _blockSize = blockSize; if (key.Length > blockSize) { KeyValue = _hashAlgorithm.ComputeHash(key); } else { KeyValue = (byte[])key.Clone(); } HashSizeValue = _hashAlgorithm.HashSize; }
public TLSGenericDeriveBytes(TLSGenericType type, byte[] secret, byte[] seed) { /* Here should be all supported types */ switch (type) { case TLSGenericType.MD5: _hmac = new HMACGeneric(secret, "MD5", 64); break; case TLSGenericType.SHA1: _hmac = new HMACGeneric(secret, "SHA1", 64); break; case TLSGenericType.SHA256: _hmac = new HMACGeneric(secret, "SHA256", 64); break; case TLSGenericType.SHA384: _hmac = new HMACGeneric(secret, "SHA384", 128); break; case TLSGenericType.SHA512: _hmac = new HMACGeneric(secret, "SHA512", 128); break; default: throw new Exception("Unsupported TLSGenericType"); } /* Set the seed as our parameter */ _seed = seed; /* Reset the HMAC generators */ Reset(); }