Skip to content

Commit b4f90fd

Browse files
committed
Initial commit
1 parent 09cf625 commit b4f90fd

13 files changed

+2955
-0
lines changed

.coveralls.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
service_name: travis-ci
2+
coverage_clover: clover.xml
3+
json_path: coveralls.json

.gitattributes

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/.gitattributes export-ignore
2+
/.gitignore export-ignore
3+
/build.xml export-ignore
4+
/Doxyfile export-ignore
5+
/phpcs.xml export-ignore
6+
/phpunit.xml export-ignore
7+
/TODO export-ignore
8+
/README export-ignore
9+
/README.rst export-ignore
10+
/.travis.yml export-ignore
11+
/.coveralls.yml export-ignore
12+
/data/i18n/*.pot export-ignore
13+
14+
/build export-ignore
15+
/docs export-ignore
16+
/tests export-ignore
17+
/.tx export-ignore
18+
/phing export-ignore
19+
/.travis export-ignore

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Ignore composer's vendor/ dir.
2+
/vendor
3+
4+
/docs/api
5+
/docs/coverage
6+
/docs/enduser
7+
8+
/build
9+
/*.tagfile.xml
10+
/*.svg

.travis.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
language: php
2+
3+
sudo: false
4+
5+
cache:
6+
directories:
7+
- vendor
8+
- $HOME/.composer/cache
9+
10+
php:
11+
- 5.3
12+
- 5.4
13+
- 5.5
14+
- 5.6
15+
- 7.0
16+
- 7.1
17+
- nightly
18+
- hhvm
19+
20+
addons:
21+
apt:
22+
packages:
23+
- util-linux
24+
25+
matrix:
26+
fast_finish: true
27+
allow_failures:
28+
- php: nightly
29+
- php: hhvm
30+
31+
notifications:
32+
email: false
33+
irc: "irc.iiens.net#Clicky"
34+
35+
before_script:
36+
- rm -rf vendor/
37+
- rm composer.lock
38+
- composer self-update -n
39+
- composer install -n
40+
41+
script:
42+
- vendor/bin/phpunit --coverage-clover clover.xml
43+
- vendor/bin/phpcs
44+
45+
after_success:
46+
- composer require --dev satooshi/php-coveralls
47+
- travis_retry vendor/bin/coveralls -n -v

Doxyfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@INCLUDE = vendor/erebot/buildenv/Doxyfile
2+
INPUT += vendor/fpoirotte/natives4doxygen/docs/
3+
INPUT += docs/src/
4+
# readthedocs generates intermediary files into docs/src/_build.
5+
EXCLUDE += docs/src/_build
6+
FILE_PATTERNS += *.dox
7+

README.rst

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
Cryptography Abstraction Layer
2+
==============================
3+
4+
Rationale
5+
---------
6+
7+
There are several extensions & libraries that provide cryptography primitives
8+
for PHP:
9+
10+
* the legacy `mcrypt <http://php.net/mcrypt>`_ extension
11+
* the `OpenSSL <http://php.net/openssl>`_ extension
12+
* the `libsodium <https://github.com/jedisct1/libsodium-php>`_ extension
13+
* my very own `tomcrypt <https://github.com/fpoirotte/tomcrypt>`_ extension
14+
* and probably others...
15+
16+
Although these extensions all provide roughtly the same features,
17+
the programmatic interface they expose is very different.
18+
19+
This project exists is comprised of a unified API (this package),
20+
which serves to abstract those differences away, and various packages
21+
that provide implementations for the unified interface
22+
(see `https://packagist.org/providers/psr/log-implementation`_ for a list
23+
of all available implementations).
24+
25+
26+
How to use it?
27+
--------------
28+
29+
First, add a requirement in your own project on either:
30+
31+
* ``fpoirotte/cryptal-implementation`` to let Composer select a compatible
32+
implementation automatically for your PHP installation.
33+
34+
* Or a specific implementation if you want to precisely control which
35+
implementation is used.
36+
Again, see `https://packagist.org/providers/psr/log-implementation`_
37+
for a list of available implementations.
38+
39+
Then, whenever you would like to apply some cryptographic operation,
40+
retrieve an instance of the implementation using the following snippet:
41+
42+
.. sourcecode:: php
43+
44+
<?php
45+
46+
// One of the CIPHER_* constants from \fpoirotte\Cryptal\CryptoInterface
47+
$cipher = CIPHER_AES;
48+
49+
// One of the MODE_* constants from \fpoirotte\Cryptal\CryptoInterface
50+
$cipher = MODE_CBC;
51+
52+
$impl = \fpoirotte\Cryptal\CryptoFactory::getImplementation($cipher, mode);
53+
54+
?>
55+
56+
Now, use whatever method you need to from the interface.
57+
For example:
58+
59+
.. sourcecode:: php
60+
61+
<?php
62+
63+
// Generate an appropriate Initialization Vector
64+
$iv = openssl_random_pseudo_bytes($impl->getIVSize(), true);
65+
66+
// Define a secret key of an appropriate size
67+
// for the cipher we're using.
68+
// Eg. 16 bytes for AES-128.
69+
$key = "Use a secret key";
70+
71+
// The plaintext's length should be a multiple of the cipher's block size.
72+
// Again, that's 16 bytes for AES.
73+
// Use $impl->getBlockSize() if necessary to retrieve the block size.
74+
$plaintext = "Some secret text";
75+
var_dump(bin2hex($plaintext));
76+
77+
$ciphertext = $impl->encrypt($iv, $key, $plaintext);
78+
var_dump(bin2hex($ciphertext));
79+
80+
$decoded = $impl->decrypt($iv, $key, $ciphertext);
81+
var_dump(bin2hex($decoded));
82+
83+
?>
84+
85+
86+
How to contribute a new implementation?
87+
---------------------------------------
88+
89+
New implementations MUST be delivered as Composer packages.
90+
Each such package MUST:
91+
92+
* Provide a concrete implementation for every interface in this package
93+
* Name the entry point for the implementation (the class that implements
94+
the ``\fpoirotte\Cryptal\CryptoInterface`` interface)
95+
``\fpoirotte\Cryptal\Implemenration``.
96+
* Add ``fpoirotte/cryptal`` to their requirements
97+
* Add ``fpoirotte/cryptal-implementation`` to their provides
98+
99+
100+

composer.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"prefer-stable": true,
3+
"name": "fpoirotte/cryptal",
4+
"description": "Cryptography Abstraction Layer",
5+
"keywords": ["crypto", "cryptography", "openssl", "mcrypt"],
6+
"homepage": "https://github.com/fpoirotte/cryptal",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "François Poirotte",
11+
"email": "[email protected]",
12+
"role": "lead"
13+
}
14+
],
15+
"support": {
16+
"issues": "https://github.com/fpoirotte/cryptal/issues",
17+
"irc": "irc://irc.iiens.net/Clicky",
18+
"source": "https://github.com/fpoirotte/cryptal"
19+
},
20+
"require": {
21+
"php": ">=5.3.3"
22+
},
23+
"require-dev": {
24+
"phpmd/phpmd": "*",
25+
"sebastian/phpcpd": "*",
26+
"phpunit/phpunit": "*",
27+
"squizlabs/php_codesniffer": "*",
28+
"erebot/buildenv": "^1.4.0",
29+
"fpoirotte/natives4doxygen": "*"
30+
},
31+
"autoload": {
32+
"psr-4": {
33+
"fpoirotte\\Cryptal\\": "src/"
34+
}
35+
},
36+
"extra": {
37+
"branch-alias": {
38+
"dev-develop": "1.0.x-dev"
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)