Changeset 1832


Ignore:
Timestamp:
02/12/10 08:39:59 (5 years ago)
Author:
lowjoel
Message:

Removed CryptGenRandom? for a few reasons:

  • The only use was in the Entropy gathering code. We default to using RNGCryptoServiceProvider which is already a CSPRNG.
  • Since RNGCryptoServiceProvider doesn't accept seeds, we can't seed it with our entropy
  • CryptGenRandom? involved a lot of setting up -- certain computers do not have it and would result in a crash
Location:
trunk/eraser6
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser6/Eraser.Manager/EntropySource.cs

    r1802 r1832  
    271271            //Ticks since start up 
    272272            result.AddRange(StructToBuffer(Environment.TickCount)); 
    273  
    274             //CryptGenRandom 
    275             byte[] cryptGenRandom = new byte[160]; 
    276             if (Security.Randomise(cryptGenRandom)) 
    277                 result.AddRange(cryptGenRandom); 
    278  
    279273            return result.ToArray(); 
    280274        } 
     
    293287                result.AddRange(netApiStats); 
    294288 
    295 #if false 
    296             //Get disk I/O statistics for all the hard drives 
    297             try 
    298             { 
    299                 for (int drive = 0; ; ++drive) 
    300                 { 
    301                     //Try to open the drive. 
    302                     StreamInfo info = new StreamInfo(string.Format(CultureInfo.InvariantCulture, 
    303                         "\\\\.\\PhysicalDrive{0}", drive)); 
    304                     using (FileStream stream = info.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) 
    305                     { 
    306                         SafeFileHandle device = stream.SafeFileHandle; 
    307                         KernelApi.DiskPerformanceInfo diskPerformance = 
    308                             KernelApi.QueryDiskPerformanceInfo(device); 
    309                         if (diskPerformance != null) 
    310                         { 
    311                             result.AddRange(StructToBuffer(diskPerformance.BytesRead)); 
    312                             result.AddRange(StructToBuffer(diskPerformance.BytesWritten)); 
    313                             result.AddRange(StructToBuffer(diskPerformance.IdleTime)); 
    314                             result.AddRange(StructToBuffer(diskPerformance.QueryTime)); 
    315                             result.AddRange(StructToBuffer(diskPerformance.QueueDepth)); 
    316                             result.AddRange(StructToBuffer(diskPerformance.ReadCount)); 
    317                             result.AddRange(StructToBuffer(diskPerformance.ReadTime)); 
    318                             result.AddRange(StructToBuffer(diskPerformance.SplitCount)); 
    319                             result.AddRange(StructToBuffer(diskPerformance.StorageDeviceNumber)); 
    320                             result.AddRange(Encoding.UTF8.GetBytes(diskPerformance.StorageManagerName)); 
    321                             result.AddRange(StructToBuffer(diskPerformance.WriteCount)); 
    322                             result.AddRange(StructToBuffer(diskPerformance.WriteTime)); 
    323                         } 
    324                     } 
    325                 } 
    326             } 
    327             catch (FileNotFoundException) 
    328             { 
    329             } 
    330             catch (UnauthorizedAccessException) 
    331             { 
     289#false 
     290            foreach (VolumeInfo info in VolumeInfo.Volumes) 
     291            { 
     292                /*DiskPerformanceInfo performance = info.Performance; 
     293                result.AddRange(StructToBuffer(performance.BytesRead)); 
     294                result.AddRange(StructToBuffer(performance.BytesWritten)); 
     295                result.AddRange(StructToBuffer(performance.IdleTime)); 
     296                result.AddRange(StructToBuffer(performance.QueryTime)); 
     297                result.AddRange(StructToBuffer(performance.QueueDepth)); 
     298                result.AddRange(StructToBuffer(performance.ReadCount)); 
     299                result.AddRange(StructToBuffer(performance.ReadTime)); 
     300                result.AddRange(StructToBuffer(performance.SplitCount)); 
     301                result.AddRange(StructToBuffer(performance.WriteCount)); 
     302                result.AddRange(StructToBuffer(performance.WriteTime));*/ 
    332303            } 
    333304#endif 
    334             //Finally, our good friend CryptGenRandom() 
    335             byte[] cryptGenRandom = new byte[1536]; 
    336             if (Security.Randomise(cryptGenRandom)) 
    337                 result.AddRange(cryptGenRandom); 
    338305 
    339306            return result.ToArray(); 
  • trunk/eraser6/Eraser.Util/Eraser.Util.csproj

    r1802 r1832  
    7676    <Compile Include="BlackBox.cs" /> 
    7777    <Compile Include="Localisation.cs" /> 
    78     <Compile Include="NativeMethods\AdvApi.cs" /> 
    7978    <Compile Include="NativeMethods\Kernel.cs" /> 
    8079    <Compile Include="NativeMethods\MsCorEE.cs" /> 
  • trunk/eraser6/Eraser.Util/Security.cs

    r1802 r1832  
    9292                out wasVerified) && wasVerified; 
    9393        } 
    94  
    95         /// <summary> 
    96         /// Randomises the provided buffer using CryptGenRandom. 
    97         /// </summary> 
    98         /// <param name="cryptGenRandom">The buffer which receives the random 
    99         /// data. The contents of this buffer can also be used as a random 
    100         /// seed.</param> 
    101         /// <returns>True if the operation suceeded.</returns> 
    102         public static bool Randomise(byte[] buffer) 
    103         { 
    104             return CryptApi.CryptGenRandom(buffer); 
    105         } 
    106     } 
    107  
    108     internal sealed class CryptApi : IDisposable 
    109     { 
    110         /// <summary> 
    111         /// Constructor. 
    112         /// </summary> 
    113         private CryptApi() 
    114         { 
    115             /* Intel i8xx (82802 Firmware Hub Device) hardware random number generator */ 
    116             const string IntelDefaultProvider = "Intel Hardware Cryptographic Service Provider"; 
    117  
    118             handle = new SafeCryptHandle(); 
    119             if (NativeMethods.CryptAcquireContext(out handle, null, 
    120                 IntelDefaultProvider, NativeMethods.PROV_INTEL_SEC, 0)) 
    121             { 
    122                 return; 
    123             } 
    124             else if (NativeMethods.CryptAcquireContext(out handle, null, 
    125                 null, NativeMethods.PROV_RSA_FULL, 0)) 
    126             { 
    127                 return; 
    128             } 
    129             else if (Marshal.GetLastWin32Error() == NativeMethods.NTE_BAD_KEYSET) 
    130             { 
    131                 //Default keyset doesn't exist, attempt to create a new one 
    132                 if (NativeMethods.CryptAcquireContext(out handle, null, null, 
    133                     NativeMethods.PROV_RSA_FULL, NativeMethods.CRYPT_NEWKEYSET)) 
    134                 { 
    135                     return; 
    136                 } 
    137             } 
    138  
    139             throw new NotSupportedException("Unable to acquire a cryptographic service provider."); 
    140         } 
    141  
    142         #region IDisposable Members 
    143         ~CryptApi() 
    144         { 
    145             Dispose(false); 
    146         } 
    147  
    148         private void Dispose(bool disposing) 
    149         { 
    150             //If we already have run Dispose, then handle will be null. 
    151             if (handle == null) 
    152                 return; 
    153  
    154             if (disposing) 
    155                 handle.Close(); 
    156  
    157             //Don't run Dispose again. 
    158             handle = null; 
    159         } 
    160  
    161         public void Dispose() 
    162         { 
    163             Dispose(true); 
    164             GC.SuppressFinalize(this); 
    165         } 
    166         #endregion 
    167  
    168         /// <summary> 
    169         /// The GenRandom function fills a buffer with cryptographically random bytes. 
    170         /// </summary> 
    171         /// <param name="buffer">Buffer to receive the returned data. This buffer 
    172         /// must be at least dwLen bytes in length. 
    173         ///  
    174         /// Optionally, the application can fill this buffer with data to use as 
    175         /// an auxiliary random seed.</param> 
    176         public static bool CryptGenRandom(byte[] buffer) 
    177         { 
    178             return NativeMethods.CryptGenRandom(instance.handle, (uint)buffer.Length, buffer); 
    179         } 
    180  
    181         /// <summary> 
    182         /// The HCRYPTPROV handle. 
    183         /// </summary> 
    184         private SafeCryptHandle handle; 
    185  
    186         /// <summary> 
    187         /// The global CryptAPI instance. 
    188         /// </summary> 
    189         private static CryptApi instance = new CryptApi(); 
    190     } 
    191  
    192     internal class SafeCryptHandle : SafeHandleZeroOrMinusOneIsInvalid 
    193     { 
    194         public SafeCryptHandle() 
    195             : base(true) 
    196         { 
    197         } 
    198  
    199         protected override bool ReleaseHandle() 
    200         { 
    201             NativeMethods.CryptReleaseContext(handle, 0u); 
    202             handle = IntPtr.Zero; 
    203             return true; 
    204         } 
    20594    } 
    20695} 
Note: See TracChangeset for help on using the changeset viewer.