/// <summary> /// Initializes a new instance of the CkSsl3KeyMatParams class. /// </summary> /// <param name='macSizeInBits'>The length (in bits) of the MACing keys agreed upon during the protocol handshake phase</param> /// <param name='keySizeInBits'>The length (in bits) of the secret keys agreed upon during the protocol handshake phase</param> /// <param name='ivSizeInBits'>The length (in bits) of the IV agreed upon during the protocol handshake phase or if no IV is required, the length should be set to 0</param> /// <param name='isExport'>Flag indicating whether the keys have to be derived for an export version of the protocol</param> /// <param name='randomInfo'>Client's and server's random data information</param> public CkSsl3KeyMatParams(NativeULong macSizeInBits, NativeULong keySizeInBits, NativeULong ivSizeInBits, bool isExport, ICkSsl3RandomData randomInfo) { if (randomInfo == null) { throw new ArgumentNullException("randomInfo"); } // Keep reference to randomInfo so GC will not free it while this object exists _randomInfo = randomInfo; if (ivSizeInBits % 8 != 0) { throw new ArgumentException("Value has to be a multiple of 8", "ivSizeInBits"); } // GC will not free ReturnedKeyMaterial while this object exists _returnedKeyMaterial = new CkSsl3KeyMatOut(ivSizeInBits / 8); _lowLevelStruct.MacSizeInBits = macSizeInBits; _lowLevelStruct.KeySizeInBits = keySizeInBits; _lowLevelStruct.IVSizeInBits = ivSizeInBits; _lowLevelStruct.IsExport = isExport; _lowLevelStruct.RandomInfo = (CK_SSL3_RANDOM_DATA)_randomInfo.ToMarshalableStructure(); // Abrakadabra :) _lowLevelStruct.ReturnedKeyMaterial = UnmanagedMemory.Allocate(UnmanagedMemory.SizeOf(typeof(CK_SSL3_KEY_MAT_OUT))); UnmanagedMemory.Write(_lowLevelStruct.ReturnedKeyMaterial, _returnedKeyMaterial._lowLevelStruct); }
/// <summary> /// Disposes object /// </summary> /// <param name="disposing">Flag indicating whether managed resources should be disposed</param> protected virtual void Dispose(bool disposing) { if (!this._disposed) { if (disposing) { // Dispose managed objects if (_returnedKeyMaterialLeftInstance == false) { if (_returnedKeyMaterial != null) { _returnedKeyMaterial.Dispose(); _returnedKeyMaterial = null; } } // Release the reference to randomInfo so GC knows this object doesn't need it anymore _randomInfo = null; } // Dispose unmanaged objects UnmanagedMemory.Free(ref _lowLevelStruct.ReturnedKeyMaterial); _disposed = true; } }
/// <summary> /// Initializes a new instance of the CkTls12KeyMatParams class. /// </summary> /// <param name="macSizeInBits">The length (in bits) of the MACing keys agreed upon during the protocol handshake phase</param> /// <param name="keySizeInBits">The length (in bits) of the secret keys agreed upon during the protocol handshake phase</param> /// <param name="ivSizeInBits">The length (in bits) of the IV agreed upon during the protocol handshake phase</param> /// <param name="isExport">Flag which must be set to false because export cipher suites must not be used in TLS 1.1 and later</param> /// <param name="randomInfo">Client's and server's random data information</param> /// <param name="prfHashMechanism">Base hash used in the underlying TLS1.2 PRF operation used to derive the master key (CKM)</param> public CkTls12KeyMatParams(ulong macSizeInBits, ulong keySizeInBits, ulong ivSizeInBits, bool isExport, CkSsl3RandomData randomInfo, ulong prfHashMechanism) { if (randomInfo == null) { throw new ArgumentNullException("randomInfo"); } // Keep reference to randomInfo so GC will not free it while this object exists _randomInfo = randomInfo; // GC will not free ReturnedKeyMaterial while this object exists _returnedKeyMaterial = new CkSsl3KeyMatOut(ivSizeInBits / 8); _lowLevelStruct.MacSizeInBits = macSizeInBits; _lowLevelStruct.KeySizeInBits = keySizeInBits; _lowLevelStruct.IVSizeInBits = ivSizeInBits; _lowLevelStruct.IsExport = isExport; _lowLevelStruct.RandomInfo = (CK_SSL3_RANDOM_DATA)_randomInfo.ToMarshalableStructure(); // Abrakadabra :) _lowLevelStruct.ReturnedKeyMaterial = UnmanagedMemory.Allocate(UnmanagedMemory.SizeOf(typeof(CK_SSL3_KEY_MAT_OUT))); UnmanagedMemory.Write(_lowLevelStruct.ReturnedKeyMaterial, _returnedKeyMaterial._lowLevelStruct); _lowLevelStruct.PrfHashMechanism = prfHashMechanism; }
/// <summary> /// Disposes object /// </summary> /// <param name="disposing">Flag indicating whether managed resources should be disposed</param> protected virtual void Dispose(bool disposing) { if (!this._disposed) { if (disposing) { // Dispose managed objects if (_returnedKeyMaterialLeftInstance == false) { if (_returnedKeyMaterial != null) { _returnedKeyMaterial.Dispose(); _returnedKeyMaterial = null; } } } // Dispose unmanaged objects UnmanagedMemory.Free(ref _lowLevelStruct.ReturnedKeyMaterial); _disposed = true; } }
/// <summary> /// Initializes a new instance of the CkSsl3KeyMatParams class. /// </summary> /// <param name='macSizeInBits'>The length (in bits) of the MACing keys agreed upon during the protocol handshake phase</param> /// <param name='keySizeInBits'>The length (in bits) of the secret keys agreed upon during the protocol handshake phase</param> /// <param name='ivSizeInBits'>The length (in bits) of the IV agreed upon during the protocol handshake phase or if no IV is required, the length should be set to 0</param> /// <param name='isExport'>Flag indicating whether the keys have to be derived for an export version of the protocol</param> /// <param name='randomInfo'>Client's and server's random data information</param> public CkSsl3KeyMatParams(ulong macSizeInBits, ulong keySizeInBits, ulong ivSizeInBits, bool isExport, CkSsl3RandomData randomInfo) { if (randomInfo == null) throw new ArgumentNullException("randomInfo"); // Keep reference to randomInfo so GC will not free it while this object exists _randomInfo = randomInfo; if (ivSizeInBits % 8 != 0) throw new ArgumentException("Value has to be a multiple of 8", "ivSizeInBits"); // GC will not free ReturnedKeyMaterial while this object exists _returnedKeyMaterial = new CkSsl3KeyMatOut(ivSizeInBits / 8); _lowLevelStruct.MacSizeInBits = macSizeInBits; _lowLevelStruct.KeySizeInBits = keySizeInBits; _lowLevelStruct.IVSizeInBits = ivSizeInBits; _lowLevelStruct.IsExport = isExport; _lowLevelStruct.RandomInfo = (CK_SSL3_RANDOM_DATA)_randomInfo.ToMarshalableStructure(); // Abrakadabra :) _lowLevelStruct.ReturnedKeyMaterial = UnmanagedMemory.Allocate(UnmanagedMemory.SizeOf(typeof(CK_SSL3_KEY_MAT_OUT))); UnmanagedMemory.Write(_lowLevelStruct.ReturnedKeyMaterial, _returnedKeyMaterial._lowLevelStruct); }