Skip to content

Commit

Permalink
Merge pull request #5 from 2Toad/jp-3
Browse files Browse the repository at this point in the history
Fixes #3: Rename Config to Settings
  • Loading branch information
JasonPierce committed Jan 31, 2017
2 parents 6cd0a76 + da628a5 commit f27cd60
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,23 @@ Rijndael.Decrypt(ciphertextFile, plaintextFile, password, KeySize.Aes256);

----------

## Configuration
## Settings

The *Config* object is a collection of mutable defaults used throughout the library
The *Settings* object is a collection of mutable defaults used throughout the library. Modification of these defaults is not necessary, but is made available for developers who want finer control of Rijndael256.

| Name | Description | Default |
| Setting | Description | Default |
|----------------|------------------------------------------------|---------|
| HashIterations | The number of iterations used to derive hashes | 10000 |

### Example

```C#
// The HashIterations setting is used in several places throughout the lib,
// with Rijndael.Encrypt being just one of them. After making this change,
// any future calls to Rijndael.Encrypt will make use of this new value
Settings.HashIterations = 25000;
```

## Appendix

### Authenticated Encryption (AE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Rijndael256.Tests
{
public class ConfigTests
public class SettingsTests
{
const string Plaintext = "A secret phrase to test hashing.";
const string Salt = "0A9FDB669FA44FF1BEC484A1BE6B6E2A";
Expand All @@ -22,24 +22,24 @@ public void HashIterations()
{
var proofDefault = Convert.FromBase64String("pGnGDWwZAVvIlmDgGZ1gkvqEqm2DvkYdPRygUjZGIW/Ts+q2R+ZdMlRzfV1Dlz4udcHwS+A/1TjP+6jBDUTBMQ==");

var hashDefault = Hash.Pbkdf2(Plaintext, Salt, Config.HashIterations);
var hashDefault = Hash.Pbkdf2(Plaintext, Salt, Settings.HashIterations);
Assert.True(hashDefault.SequenceEqual(proofDefault));

Config.HashIterations = 500;
Settings.HashIterations = 500;

var hashChanged = Hash.Pbkdf2(Plaintext, Salt, Config.HashIterations);
var hashChanged = Hash.Pbkdf2(Plaintext, Salt, Settings.HashIterations);
Assert.False(hashChanged.SequenceEqual(proofDefault));

RestoreDefaults();
}

/// <summary>
/// Config is global, so we need to restore defaults before the other
/// Settings is global, so we need to restore defaults before the other
/// unit tests, which depend on said defaults, are run.
/// </summary>
private void RestoreDefaults()
{
Config.HashIterations = 10000;
Settings.HashIterations = 10000;
}
}
}
4 changes: 2 additions & 2 deletions Rijndael256/Rijndael.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ public static void Decrypt(string ciphertextFile, string plaintextFile, string p
public static byte[] GenerateKey(string password, KeySize keySize)
{
// Create a salt to help prevent rainbow table attacks
var salt = Hash.Pbkdf2(password, Hash.Sha512(password + password.Length), Config.HashIterations);
var salt = Hash.Pbkdf2(password, Hash.Sha512(password + password.Length), Settings.HashIterations);

// Generate a key from the password and salt
return Hash.Pbkdf2(password, salt, Config.HashIterations, (int)keySize / 8);
return Hash.Pbkdf2(password, salt, Settings.HashIterations, (int)keySize / 8);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Rijndael256/RijndaelEtM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public class RijndaelEtM : Rijndael
/// <returns>The MAC.</returns>
public static byte[] CalculateMac(byte[] ciphertext, byte[] key)
{
return Hash.Pbkdf2(ciphertext, key, Config.HashIterations);
return Hash.Pbkdf2(ciphertext, key, Settings.HashIterations);
}
}
}
4 changes: 2 additions & 2 deletions Rijndael256/Config.cs → Rijndael256/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
namespace Rijndael256
{
/// <summary>
/// Global configurations
/// A collection of mutable defaults
/// </summary>
public static class Config
public static class Settings
{
/// <summary>
/// The number of iterations used to derive hashes.
Expand Down

0 comments on commit f27cd60

Please sign in to comment.