Browse Source

also authenticate the chunkid when using the AEAD ciphers (AES-OCB/CHACHA-POLY)

Thomas Waldmann 3 years ago
parent
commit
c50e1124b5
1 changed files with 2 additions and 2 deletions
  1. 2 2
      src/borg/crypto/key.py

+ 2 - 2
src/borg/crypto/key.py

@@ -739,7 +739,7 @@ class AEADKeyBase(KeyBase):
         iv = self.cipher.next_iv()
         iv = self.cipher.next_iv()
         iv_48bit = iv.to_bytes(6, 'big')
         iv_48bit = iv.to_bytes(6, 'big')
         header = self.TYPE_STR + reserved + iv_48bit + self.sessionid
         header = self.TYPE_STR + reserved + iv_48bit + self.sessionid
-        return self.cipher.encrypt(data, header=header, iv=iv)
+        return self.cipher.encrypt(data, header=header, iv=iv, aad=id)
 
 
     def decrypt(self, id, data, decompress=True):
     def decrypt(self, id, data, decompress=True):
         # to decrypt existing data, we need to get a cipher configured for the sessionid and iv from header
         # to decrypt existing data, we need to get a cipher configured for the sessionid and iv from header
@@ -749,7 +749,7 @@ class AEADKeyBase(KeyBase):
         iv = int.from_bytes(iv_48bit, 'big')
         iv = int.from_bytes(iv_48bit, 'big')
         cipher = self._get_cipher(sessionid, iv)
         cipher = self._get_cipher(sessionid, iv)
         try:
         try:
-            payload = cipher.decrypt(data)
+            payload = cipher.decrypt(data, aad=id)
         except IntegrityError as e:
         except IntegrityError as e:
             raise IntegrityError(f"Chunk {bin_to_hex(id)}: Could not decrypt [{str(e)}]")
             raise IntegrityError(f"Chunk {bin_to_hex(id)}: Could not decrypt [{str(e)}]")
         if not decompress:
         if not decompress: