Skip to content

Commit

Permalink
docs: update security docs about new one-step KDF
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWaldmann committed Dec 2, 2023
1 parent a4602c6 commit 74c34ba
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
Binary file modified docs/internals/encryption-aead.odg
Binary file not shown.
Binary file modified docs/internals/encryption-aead.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 7 additions & 10 deletions docs/internals/security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,17 @@ The chunk ID is derived via a MAC over the plaintext (mac key taken from borg ke
For each borg invocation, a new session id is generated by `os.urandom`_.

From that session id, the initial key material (ikm, taken from the borg key)
and an application and cipher specific salt, borg derives a session key via HKDF.
and an application and cipher specific salt, borg derives a session key using a
"one-step KDF" based on just sha256.

For each session key, IVs (nonces) are generated by a counter which increments for
each encrypted message.

Session::

sessionid = os.urandom(24)
ikm = crypt_key
salt = "borg-session-key-CIPHERNAME"
sessionkey = HKDF(ikm, sessionid, salt)
domain = "borg-session-key-CIPHERNAME"
sessionkey = sha256(crypt_key + sessionid + domain)
message_iv = 0

Encryption::
Expand All @@ -155,7 +155,9 @@ Decryption::

ASSERT(type-byte is correct)

past_key = HKDF(ikm, past_sessionid, salt)
domain = "borg-session-key-CIPHERNAME"
past_key = sha256(crypt_key + past_sessionid + domain)

decrypted = AEAD_decrypt(past_key, past_message_iv, authenticated)

decompressed = decompress(decrypted)
Expand Down Expand Up @@ -229,12 +231,7 @@ on widely used libraries providing them:
- HMAC and a constant-time comparison from Python's hmac_ standard library module are used.
- argon2 is used via argon2-cffi.

Implemented cryptographic constructions are:

- HKDF_-SHA-512 (using ``hmac.digest`` from Python's hmac_ standard library module)

.. _Horton principle: https://en.wikipedia.org/wiki/Horton_Principle
.. _HKDF: https://tools.ietf.org/html/rfc5869
.. _length extension: https://en.wikipedia.org/wiki/Length_extension_attack
.. _hashlib: https://docs.python.org/3/library/hashlib.html
.. _hmac: https://docs.python.org/3/library/hmac.html
Expand Down

0 comments on commit 74c34ba

Please sign in to comment.