rfc:php71-crypto

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:php71-crypto [2016/01/10 03:34] sarciszewskirfc:php71-crypto [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +
 ====== PHP RFC: Simple Cryptography Library ====== ====== PHP RFC: Simple Cryptography Library ======
   * Version: 0.1   * Version: 0.1
Line 25: Line 26:
   * ''KeyPair''   * ''KeyPair''
  
-Users would primarily be interested in the ''Crypto'' classes, and the methods of the ''KeyFactory'' class. For example:+Users would primarily be interested in the ''Crypto'' classes, and the methods of the ''KeyFactory'' class. 
 + 
 +For example:
  
     $keypair = \Php\Crypto\KeyFactory::generateEncryptionKeyPair('openssl');      $keypair = \Php\Crypto\KeyFactory::generateEncryptionKeyPair('openssl'); 
Line 49: Line 52:
 The ''Asymmetric\Crypto'' interface would look like this: The ''Asymmetric\Crypto'' interface would look like this:
      
-  * ''encrypt( string, EncryptionSecretKey, EncryptionPublicKey )'' +  * ''string'' ''encrypt( string, EncryptionSecretKey, EncryptionPublicKey )'' 
-  * ''decrypt( string, EncryptionSecretKey, EncryptionPublicKey )'' +  * ''string'' ''decrypt( string, EncryptionSecretKey, EncryptionPublicKey )'' 
-  * ''seal( string, EncryptionPublicKey )'' +  * ''string'' ''seal( string, EncryptionPublicKey )'' 
-  * ''unseal( string, EncryptionSecretKey )'' +  * ''string'' ''unseal( string, EncryptionSecretKey )'' 
-  * ''sign( string, SignatureSecretKey )'' +  * ''string'' ''sign( string, SignatureSecretKey )'' 
-  * ''verify( string, SignaturePublicKey, string )''+  * ''bool' ''verify( string, SignaturePublicKey, string )''
  
 The ''Symmetric\Crypto'' interface would look like this: The ''Symmetric\Crypto'' interface would look like this:
  
-  * ''auth( string, AuthenticationKey )'' +  * ''string'' ''auth( string, AuthenticationKey )'' 
-  * ''verify( string, AuthenticationKey )'' +  * ''bool'' ''verify( string, AuthenticationKey )'' 
-  * ''encrypt( string, EncryptionKey )'' +  * ''string'' ''aeadEncrypt( string, EncryptionKey, string )'' 
-  * ''decrypt( string, EncryptionKey )''+  * ''string'' ''aeadDecrypt( string, EncryptionKey, string )'' 
 +  * ''string'' ''encrypt( string, EncryptionKey )'' 
 +  * ''string'' ''decrypt( string, EncryptionKey )''
  
 +All decryption (including unseal()) operations will throw a typed exception (e.g. ''\Php\Crypto\CryptoException'') if the MAC doesn't validate.
  
 +===== Drivers, Configurations, and Defaults =====
 +
 +This API will act similar to PDO in the sense that it can, behind the scenes, support multiple drivers. As of the day we ship PHP 7.1.0, we MUST support at least two:
 +
 +  * ''libsodium''
 +  * ''openssl''
 +
 +Which driver and which primitives can be supplied at the time a Crypto object is created, but the valid choices will be limited.
 +
 +  * Libsodium (not configurable)
 +    * Cipher: Xsalsa20
 +    * Hash/HMAC: HMAC-SHA-512/256
 +    * Public keys: X25519
 +    * Signatures: Ed25519
 +    * HKDF: BLAKE2b
 +    * Password-Based Key Derivation: Argon2i
 +  * OpenSSL (configurable):
 +      * Cipher: AES-128, AES-192, AES-256
 +      * Hash/HMAC: SHA256, SHA384, SHA512, SHA3-356, SHA3-384, SHA3-512
 +      * Public keys: ECDH over NIST P-256
 +      * Signatures: ECDSA over NIST P-256
 +      * HKDF: (See hash function above)
 +      * Password-Based Key Derivation: PBKDF2-(hash function above) with 86,000 rounds
 +
 +If both drivers are installed, both ''Crypto'' classes will default to libsodium (reason: secure defaults) unless otherwise specified.
 +
 +If you only specify a driver, OpenSSL will default to: AES-256 and SHA-384. Only CTR mode is supported regardless of cipher, except for aeadEncrypt() and aeadDecrypt(), which should only allow GCM mode.
 +
 +===== Ciphertext Message Format =====
 +
 +The first four bytes of any message are a header that indicates the version of the library and various other information.
 +
 +  * First byte: Major version of this interface (e.g. ''01'')
 +  * Second byte: Minor version of this interface (e.g. ''05'')
 +  * Third byte: Driver ID
 +  * Fourth byte: A checksum (''Byte0 ^ Byte1 ^ Byte2'') to detect corruption
 +
 +Driver-specific metadata can follow this four-byte header, but it is not required.
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
Line 72: Line 116:
  
 ==== To Existing Extensions ==== ==== To Existing Extensions ====
- 
  
 ===== Unaffected PHP Functionality ===== ===== Unaffected PHP Functionality =====
Line 79: Line 122:
  
 ===== Future Scope ===== ===== Future Scope =====
- 
- 
  
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
rfc/php71-crypto.1452396851.txt.gz · Last modified: 2017/09/22 13:28 (external edit)