This document serves as a high level design document for the block cipher functions of dcrypt.
SALTinitialization vector generated withrandom_bytes.CIPHERthe chosen cipher method as a stringALGOthe chosen hmac algorithm as a stringKEYhigh entropy key selected for symmetric encryptionENCRINFOis the stringencryptionKey+|+CIPHERAUTHINFOis the stringauthenticationKey+|+CIPHERMTEXTthe plaintext message to be encryptedHKDFis the key derivation function supported by PHP (hash_hkdf) and defined as (RFC-5869). The parameters are:- hashing algo to use
- key to hash with
- info string parameter
HMACis a HMAC checksum function supported by PHP (hash_hmac). The parameters are:- input data to hash
- hashing algo to use
- key to hash with
OPENSSL_ENCRYPT. The parameters are:- input data to encrypt
- key to hash with
- iv
OPENSSL_DECRYPT. The parameters are:- input data to decrypt
- key to hash with
- iv
- tag
Providing a high quality key is essential to the security level it provides.
- Obtain a new
SALTof appropriate size for givenCIPHER - Test key for validity
- Derive authentication key
AKEY = HKDF(ALGO, KEY, AUTHINFO) - Derive encryption key
EKEY = HKDF(ALGO, KEY, ENCRINFO) - Encrypt the data as
CTEXT = OPENSSL_ENCRYPT(MTEXT, EKEY, SALT) - Generate a checksum where
CHECKSUM = HMAC(CTEXT, ALGO, AKEY) - Concatenate and return the following values
SALTCHECKSUMTAG(if required byCIPHER, otherwise skip)CTEXT
- Pop
SALToff front ofCTEXT - Same as step 3 from above
- Same as step 4 from above
- Pop
CHECKSUMfrom front ofCTEXT - Pop
TAGfrom front ofCTEXT - Generate a checksum where
COMPUTED = HMAC(CTEXT, ALGO, AKEY) - If
COMPUTED != CHECKSUMthrow an exception - Decrypt data as
MTEXT = OPENSSL_DECRYPT(CTEXT, EKEY, SALT, TAG) - Return
MTEXT