-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
196 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Guide to dcrypt keys | ||
|
||
Dcrypt likes __BIG__ keys. | ||
This document explains some of the reasoning behind these design decisions and some tips on handling keys. | ||
|
||
## Why 2048 bytes though? | ||
|
||
At 2048 bytes the probability of any byte in the 0x00 to 0xFF range being used at least once approaches 1. | ||
Unless, of course, a source of low entropy were to used for the initial keying material. | ||
|
||
A basic test is performed at run time to indicate whether the key is likely to be pseudorandom. | ||
An exception is raised if the key does not pass this test. | ||
This test is not perfect but it is simple and fast. | ||
It may become conditional in the future. | ||
|
||
A generic of the randomness test is this as follows: | ||
|
||
```php | ||
<?php | ||
if (\count(\array_unique(\str_split($key))) < 250) { | ||
// throw exception | ||
} | ||
``` | ||
|
||
The large size of 2048 bytes safely allows us to forgo computationally wasteful and potentially dangerous password derivation while still providing strong security. | ||
|
||
## Create a new key | ||
|
||
Command line to screen: | ||
|
||
```bash | ||
head -c 2048 /dev/urandom | base64 -w 0 | xargs echo | ||
``` | ||
|
||
Command line to file: | ||
|
||
```bash | ||
head -c 2048 /dev/urandom | base64 -w 0 > ~/secret.key | ||
``` | ||
|
||
PHP static function: | ||
|
||
```php | ||
<?php | ||
|
||
$key = \Dcrypt\OpensslKey::create(); | ||
|
||
file_put_contents("~/secret.key", $key); | ||
``` | ||
|
||
## Storage tips | ||
|
||
Since the key is base64 encoded it can contain any whitespace you desire. | ||
An optimal solution when using opcache is to store as a single file and use it in a `require` statement. | ||
|
||
```php | ||
<?php | ||
|
||
# content of /path/to/secret.key | ||
|
||
return <<<EOT | ||
|
||
key.................................................... | ||
key.................................................... | ||
key.................................................... | ||
key.................................................... | ||
key.................................................... | ||
|
||
EOT; | ||
|
||
``` | ||
|
||
then... | ||
|
||
```php | ||
<?php | ||
|
||
$key = require '/path/to/secret.key'; | ||
``` | ||
|
||
Keys can also be stored in environment files, functions, and class properties. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# OneTimePad | ||
|
||
A novel counter-based stream cipher. | ||
|
||
# Definitions | ||
|
||
- `DATA` data to encrypt or decrypt | ||
- `KEY` to be given to key manager | ||
- `ALGO` default sha3-512 | ||
- `COUNTER` | ||
- `HKDF` | ||
- algo | ||
- key | ||
- iv | ||
- info | ||
- `IV` __a blank string__ | ||
- `INFO` is the concatenation of `LENGTH` and index number of `CHUNK` | ||
|
||
# Method of Encrypt and Decryption | ||
1. Break `DATA` into an array (`CHUNKS`) of strings with a max width equal to the size of the hashing algo | ||
1. Compute `LENGTH` where `LENGTH = strlen(DATA)` | ||
1. For each `CHUNK` in `CHUNKS`, replace with `CHUNK = CHUNK ^ HKDF(ALGO, KEY, IV, INFO)` | ||
1. Once all elements in `CHUNKS` have been processed then `implode` and `return` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters