paragonie / pco_prototype

PCO - PHP Crypto Objects
Do What The F*ck You Want To Public License
12 stars 1 forks source link

Drivers and Supported Encryption Primitives #7

Open paragonie-scott opened 8 years ago

paragonie-scott commented 8 years ago

We should restrict which primitives can be used with each driver.

A proposed rough draft is below; this only affects the permitted primitives in the initial version of the library. All messages are version tagged.

riking commented 8 years ago

What is the interface for libsodium keygen and key loading/storage?

In my Golang program I store my libsodium keys as base64 in a .json config file as MyPrivate MyPublic TheirPublic, to provide a data point.

paragonie-scott commented 8 years ago

My own libsodium project does this: https://github.com/paragonie/halite/blob/master/src/KeyFactory.php#L412-L425

CodesInChaos commented 8 years ago

I don't see a KDF. Key exchange is pretty useless without a way for deriving symmetric keys from the shared secret.

paragonie-scott commented 8 years ago

Good point. I'm thinking:

CodesInChaos commented 8 years ago

I was mainly thinking about a key based KDF, namely HKDF-HMAC-SHA-2. I consider it an essential tool when designing not trivial crypto.

paragonie-scott commented 8 years ago

Oh yeah, I was going to use HKDF to split keys anyway. Let me make a quick edit to the original.

paragonie-scott commented 8 years ago

Updated the OP to remove CBC mode, add a line item for AEAD under OpenSSL, and spell out the different KDF methods that will be used.

Key splitting will generally be HKDF with a 256-bit salt (stored with the IV/nonce in the ciphertext, covered by the MAC).

paragonie-scott commented 8 years ago

Removing "2048-bit RSAES-OAEP with SHA256 + MGF1+SHA256, e = 65537" from the list in favor of DH-2048 then AES-CTR+HMAC-SHA2.

Reason: API simplicity. Libsodium uses X25519 then Xsalsa20+Poly1305, which is all of: sane, secure, simple, and easy to reason about.

Using RSA encryption means we'd have to use RSA keys in some instances as diffie hellman keys to keep a compatible interface. This is probably a bad idea. Also, RSA encryption means either forcing ECB mode or reinventing CBC mode, but certainly incurring massive performance penalties.

So, we'll still use RSA (or ECDSA, if openssl supports that) for signing, but encryption will just be DH+AES+HMAC.