Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use HKDF or any other key derivation function for derive one time encryption keys #25

Open
niwinz opened this issue Mar 19, 2015 · 0 comments

Comments

@niwinz
Copy link
Member

niwinz commented Mar 19, 2015

You are currently using the pbkdf2 algorithm for derive the encryption key (obviously for encrypt the message/token). PBKDF2 is a key derivartion function designed for use when the master key is not Cryptographically secure, such as passwords. Using it implies a lot of overhead in message encryption in a use case of this library. My recommendation is switch to other policy of deriving a encryption key.

This is my proposal:

General notes for master key management:

  • Add a master key validator for ensure that user sets a truly cryptographically secure master key (50-100 chars of random strings as example).
  • Derive a master key (string) to bytes using some hash function: sha512 or sha3-512 or arbitrary length hash functions like skein.
  • Use HKDF as key derivation function (instead of PBKDF2)

One time (per message) key derivation procedure:

  • Generate 32 or 64 bytes salt using CSRNG (using SecureRandom in java).
  • Create an instance of HKDF with your master key and the secure random salt previously generated.
  • Derive a 256bits (32bytes) encryption key.
  • Derive 128bits (16bytes) IV.
  • Encrypt the message using the previously derived encryption key and iv.
  • Build the final message with encrypted message and salt (the rest of information can be derived from master key and salt, so, iv can be simple omitted from final concatenation step making the message slightly shorter)

We can speak in the office about this if something is not clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants