/// <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(NativeULong macSizeInBits, NativeULong keySizeInBits, NativeULong ivSizeInBits, bool isExport, ICkSsl3RandomData randomInfo, NativeULong 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> /// Initializes a new instance of the CkTlsKdfParams class. /// </summary> /// <param name="prfMechanism">Hash mechanism used in the TLS 1.2 PRF construct or CKM_TLS_PRF to use with the TLS 1.0 and 1.1 PRF construct (CKM)</param> /// <param name="label">Label for this key derivation</param> /// <param name="randomInfo">Random data for the key derivation</param> /// <param name="contextData">Context data for this key derivation</param> public CkTlsKdfParams(NativeULong prfMechanism, byte[] label, ICkSsl3RandomData randomInfo, byte[] contextData) { _lowLevelStruct.Label = IntPtr.Zero; _lowLevelStruct.LabelLength = 0; _lowLevelStruct.ContextData = IntPtr.Zero; _lowLevelStruct.ContextDataLength = 0; if (randomInfo == null) { throw new ArgumentNullException("randomInfo"); } // Keep reference to randomInfo so GC will not free it while this object exists _randomInfo = randomInfo; _lowLevelStruct.PrfMechanism = prfMechanism; if (label != null) { _lowLevelStruct.Label = UnmanagedMemory.Allocate(label.Length); UnmanagedMemory.Write(_lowLevelStruct.Label, label); _lowLevelStruct.LabelLength = ConvertUtils.UInt64FromInt32(label.Length); } _lowLevelStruct.RandomInfo = (CK_SSL3_RANDOM_DATA)_randomInfo.ToMarshalableStructure(); if (contextData != null) { _lowLevelStruct.ContextData = UnmanagedMemory.Allocate(contextData.Length); UnmanagedMemory.Write(_lowLevelStruct.ContextData, contextData); _lowLevelStruct.ContextDataLength = ConvertUtils.UInt64FromInt32(contextData.Length); } }
/// <summary> /// Initializes a new instance of the CkSsl3MasterKeyDeriveParams class. /// </summary> /// <param name='randomInfo'>Client's and server's random data information</param> /// <param name='dh'>Set to false for CKM_SSL3_MASTER_KEY_DERIVE mechanism and to true for CKM_SSL3_MASTER_KEY_DERIVE_DH mechanism</param> public CkSsl3MasterKeyDeriveParams(ICkSsl3RandomData randomInfo, bool dh) { if (randomInfo == null) { throw new ArgumentNullException("randomInfo"); } // Keep reference to randomInfo so GC will not free it while this object exists _randomInfo = randomInfo; _lowLevelStruct.RandomInfo = (CK_SSL3_RANDOM_DATA)_randomInfo.ToMarshalableStructure(); _lowLevelStruct.Version = (dh) ? IntPtr.Zero : UnmanagedMemory.Allocate(UnmanagedMemory.SizeOf(typeof(CK_VERSION))); }
/// <summary> /// Initializes a new instance of the CkTls12MasterKeyDeriveParams class. /// </summary> /// <param name="randomInfo">Client's and server's random data information</param> /// <param name="prfHashMechanism">Base hash used in the underlying TLS 1.2 PRF operation used to derive the master key (CKM)</param> public CkTls12MasterKeyDeriveParams(ICkSsl3RandomData randomInfo, NativeULong prfHashMechanism) { if (randomInfo == null) { throw new ArgumentNullException("randomInfo"); } // Keep reference to randomInfo so GC will not free it while this object exists _randomInfo = randomInfo; _lowLevelStruct.RandomInfo = (CK_SSL3_RANDOM_DATA)_randomInfo.ToMarshalableStructure(); _lowLevelStruct.Version = UnmanagedMemory.Allocate(UnmanagedMemory.SizeOf(typeof(CK_VERSION))); _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 // Release the reference to randomInfo so GC knows this object doesn't need it anymore _randomInfo = null; } // Dispose unmanaged objects UnmanagedMemory.Free(ref _lowLevelStruct.Version); _disposed = true; } }
/// <summary> /// Create parameters for the CKM_TLS_KDF mechanism /// </summary> /// <param name="prfMechanism">Hash mechanism used in the TLS 1.2 PRF construct or CKM_TLS_PRF to use with the TLS 1.0 and 1.1 PRF construct (CKM)</param> /// <param name="label">Label for this key derivation</param> /// <param name="randomInfo">Random data for the key derivation</param> /// <param name="contextData">Context data for this key derivation</param> /// <returns>Parameters for the CKM_TLS_KDF mechanism</returns> public ICkTlsKdfParams CreateCkTlsKdfParams(ulong prfMechanism, byte[] label, ICkSsl3RandomData randomInfo, byte[] contextData) { return _factory.CreateCkTlsKdfParams(prfMechanism, label, randomInfo, contextData); }
/// <summary> /// Creates parameters for the CKM_TLS12_MASTER_KEY_DERIVE mechanism /// </summary> /// <param name="randomInfo">Client's and server's random data information</param> /// <param name="prfHashMechanism">Base hash used in the underlying TLS 1.2 PRF operation used to derive the master key (CKM)</param> /// <returns>Parameters for the CKM_TLS12_MASTER_KEY_DERIVE mechanism</returns> public ICkTls12MasterKeyDeriveParams CreateCkTls12MasterKeyDeriveParams(ICkSsl3RandomData randomInfo, ulong prfHashMechanism) { return _factory.CreateCkTls12MasterKeyDeriveParams(randomInfo, prfHashMechanism); }
/// <summary> /// Creates parameters for the CKM_TLS12_KEY_AND_MAC_DERIVE mechanism /// </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> /// <returns>Parameters for the CKM_TLS12_KEY_AND_MAC_DERIVE mechanism</returns> public ICkTls12KeyMatParams CreateCkTls12KeyMatParams(ulong macSizeInBits, ulong keySizeInBits, ulong ivSizeInBits, bool isExport, ICkSsl3RandomData randomInfo, ulong prfHashMechanism) { return _factory.CreateCkTls12KeyMatParams(macSizeInBits, keySizeInBits, ivSizeInBits, isExport, randomInfo, prfHashMechanism); }
/// <summary> /// Creates parameters for the CKM_SSL3_MASTER_KEY_DERIVE and CKM_SSL3_MASTER_KEY_DERIVE_DH mechanisms /// </summary> /// <param name='randomInfo'>Client's and server's random data information</param> /// <param name='dh'>Set to false for CKM_SSL3_MASTER_KEY_DERIVE mechanism and to true for CKM_SSL3_MASTER_KEY_DERIVE_DH mechanism</param> /// <returns>Parameters for the CKM_SSL3_MASTER_KEY_DERIVE and CKM_SSL3_MASTER_KEY_DERIVE_DH mechanisms</returns> public ICkSsl3MasterKeyDeriveParams CreateCkSsl3MasterKeyDeriveParams(ICkSsl3RandomData randomInfo, bool dh) { return _factory.CreateCkSsl3MasterKeyDeriveParams(randomInfo, dh); }
// Note : CkSsl3KeyMatOut does not need to be constructed here /// <summary> /// Creates parameters for the CKM_SSL3_KEY_AND_MAC_DERIVE mechanism /// </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> /// <returns>Parameters for the CKM_SSL3_KEY_AND_MAC_DERIVE mechanism</returns> public ICkSsl3KeyMatParams CreateCkSsl3KeyMatParams(ulong macSizeInBits, ulong keySizeInBits, ulong ivSizeInBits, bool isExport, ICkSsl3RandomData randomInfo) { return _factory.CreateCkSsl3KeyMatParams(macSizeInBits, keySizeInBits, ivSizeInBits, isExport, randomInfo); }
/// <summary> /// Create parameters for the CKM_TLS_KDF mechanism /// </summary> /// <param name="prfMechanism">Hash mechanism used in the TLS 1.2 PRF construct or CKM_TLS_PRF to use with the TLS 1.0 and 1.1 PRF construct (CKM)</param> /// <param name="label">Label for this key derivation</param> /// <param name="randomInfo">Random data for the key derivation</param> /// <param name="contextData">Context data for this key derivation</param> /// <returns>Parameters for the CKM_TLS_KDF mechanism</returns> public ICkTlsKdfParams CreateCkTlsKdfParams(ulong prfMechanism, byte[] label, ICkSsl3RandomData randomInfo, byte[] contextData) { return(new CkTlsKdfParams(ConvertUtils.UInt32FromUInt64(prfMechanism), label, randomInfo, contextData)); }
/// <summary> /// Creates parameters for the CKM_TLS12_MASTER_KEY_DERIVE mechanism /// </summary> /// <param name="randomInfo">Client's and server's random data information</param> /// <param name="prfHashMechanism">Base hash used in the underlying TLS 1.2 PRF operation used to derive the master key (CKM)</param> /// <returns>Parameters for the CKM_TLS12_MASTER_KEY_DERIVE mechanism</returns> public ICkTls12MasterKeyDeriveParams CreateCkTls12MasterKeyDeriveParams(ICkSsl3RandomData randomInfo, ulong prfHashMechanism) { return(new CkTls12MasterKeyDeriveParams(randomInfo, ConvertUtils.UInt32FromUInt64(prfHashMechanism))); }
/// <summary> /// Creates parameters for the CKM_TLS12_KEY_AND_MAC_DERIVE mechanism /// </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> /// <returns>Parameters for the CKM_TLS12_KEY_AND_MAC_DERIVE mechanism</returns> public ICkTls12KeyMatParams CreateCkTls12KeyMatParams(ulong macSizeInBits, ulong keySizeInBits, ulong ivSizeInBits, bool isExport, ICkSsl3RandomData randomInfo, ulong prfHashMechanism) { return(new CkTls12KeyMatParams(ConvertUtils.UInt32FromUInt64(macSizeInBits), ConvertUtils.UInt32FromUInt64(keySizeInBits), ConvertUtils.UInt32FromUInt64(ivSizeInBits), isExport, randomInfo, ConvertUtils.UInt32FromUInt64(prfHashMechanism))); }
/// <summary> /// Creates parameters for the CKM_SSL3_MASTER_KEY_DERIVE and CKM_SSL3_MASTER_KEY_DERIVE_DH mechanisms /// </summary> /// <param name='randomInfo'>Client's and server's random data information</param> /// <param name='dh'>Set to false for CKM_SSL3_MASTER_KEY_DERIVE mechanism and to true for CKM_SSL3_MASTER_KEY_DERIVE_DH mechanism</param> /// <returns>Parameters for the CKM_SSL3_MASTER_KEY_DERIVE and CKM_SSL3_MASTER_KEY_DERIVE_DH mechanisms</returns> public ICkSsl3MasterKeyDeriveParams CreateCkSsl3MasterKeyDeriveParams(ICkSsl3RandomData randomInfo, bool dh) { return(new CkSsl3MasterKeyDeriveParams(randomInfo, dh)); }
// Note : CkSsl3KeyMatOut does not need to be constructed here /// <summary> /// Creates parameters for the CKM_SSL3_KEY_AND_MAC_DERIVE mechanism /// </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> /// <returns>Parameters for the CKM_SSL3_KEY_AND_MAC_DERIVE mechanism</returns> public ICkSsl3KeyMatParams CreateCkSsl3KeyMatParams(ulong macSizeInBits, ulong keySizeInBits, ulong ivSizeInBits, bool isExport, ICkSsl3RandomData randomInfo) { return(new CkSsl3KeyMatParams(ConvertUtils.UInt32FromUInt64(macSizeInBits), ConvertUtils.UInt32FromUInt64(keySizeInBits), ConvertUtils.UInt32FromUInt64(ivSizeInBits), isExport, randomInfo)); }