prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  borgbackup build failure when using OpenSSL 1.1.0
  https://groups.google.com/d/msg/linux.debian.devel/53fq9S-Qpp4/V_0pPtdzBQAJ
  
  
  </issue>
  <code>
  [start of borg/testsuite/crypto.py]
  1 from binascii import hexlify
  2 
  3 from ..crypto import AES, bytes_to_long, bytes_to_int, long_to_bytes
  4 from . import BaseTestCase
  5 
  6 
  7 class CryptoTestCase(BaseTestCase):
  8 
  9     def test_bytes_to_int(self):
  10         self.assert_equal(bytes_to_int(b'\0\0\0\1'), 1)
  11 
  12     def test_bytes_to_long(self):
  13         self.assert_equal(bytes_to_long(b'\0\0\0\0\0\0\0\1'), 1)
  14         self.assert_equal(long_to_bytes(1), b'\0\0\0\0\0\0\0\1')
  15 
  16     def test_aes(self):
  17         key = b'X' * 32
  18         data = b'foo' * 10
  19         # encrypt
  20         aes = AES(is_encrypt=True, key=key)
  21         self.assert_equal(bytes_to_long(aes.iv, 8), 0)
  22         cdata = aes.encrypt(data)
  23         self.assert_equal(hexlify(cdata), b'c6efb702de12498f34a2c2bbc8149e759996d08bf6dc5c610aefc0c3a466')
  24         self.assert_equal(bytes_to_long(aes.iv, 8), 2)
  25         # decrypt
  26         aes = AES(is_encrypt=False, key=key)
  27         self.assert_equal(bytes_to_long(aes.iv, 8), 0)
  28         pdata = aes.decrypt(cdata)
  29         self.assert_equal(data, pdata)
  30         self.assert_equal(bytes_to_long(aes.iv, 8), 2)
  31
  [end of borg/testsuite/crypto.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/borg/testsuite/crypto.py b/borg/testsuite/crypto.py
  --- a/borg/testsuite/crypto.py
  +++ b/borg/testsuite/crypto.py
  @@ -1,6 +1,7 @@
   from binascii import hexlify
   
   from ..crypto import AES, bytes_to_long, bytes_to_int, long_to_bytes
  +from ..crypto import increment_iv, bytes16_to_int, int_to_bytes16
   from . import BaseTestCase
   
   
  @@ -13,6 +14,27 @@
           self.assert_equal(bytes_to_long(b'\0\0\0\0\0\0\0\1'), 1)
           self.assert_equal(long_to_bytes(1), b'\0\0\0\0\0\0\0\1')
   
  +    def test_bytes16_to_int(self):
  +        self.assert_equal(bytes16_to_int(b'\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1'), 1)
  +        self.assert_equal(int_to_bytes16(1), b'\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1')
  +        self.assert_equal(bytes16_to_int(b'\0\0\0\0\0\0\0\1\0\0\0\0\0\0\0\0'), 2 ** 64)
  +        self.assert_equal(int_to_bytes16(2 ** 64), b'\0\0\0\0\0\0\0\1\0\0\0\0\0\0\0\0')
  +
  +    def test_increment_iv(self):
  +        iv0 = b'\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0'
  +        iv1 = b'\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1'
  +        iv2 = b'\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\2'
  +        self.assert_equal(increment_iv(iv0, 0), iv0)
  +        self.assert_equal(increment_iv(iv0, 1), iv1)
  +        self.assert_equal(increment_iv(iv0, 2), iv2)
  +        iva = b'\0\0\0\0\0\0\0\0\xff\xff\xff\xff\xff\xff\xff\xff'
  +        ivb = b'\0\0\0\0\0\0\0\1\x00\x00\x00\x00\x00\x00\x00\x00'
  +        ivc = b'\0\0\0\0\0\0\0\1\x00\x00\x00\x00\x00\x00\x00\x01'
  +        self.assert_equal(increment_iv(iva, 0), iva)
  +        self.assert_equal(increment_iv(iva, 1), ivb)
  +        self.assert_equal(increment_iv(iva, 2), ivc)
  +        self.assert_equal(increment_iv(iv0, 2**64), ivb)
  +
       def test_aes(self):
           key = b'X' * 32
           data = b'foo' * 10
  
verification_info: {"golden_diff": "diff --git a/borg/testsuite/crypto.py b/borg/testsuite/crypto.py\n--- a/borg/testsuite/crypto.py\n+++ b/borg/testsuite/crypto.py\n@@ -1,6 +1,7 @@\n from binascii import hexlify\n \n from ..crypto import AES, bytes_to_long, bytes_to_int, long_to_bytes\n+from ..crypto import increment_iv, bytes16_to_int, int_to_bytes16\n from . import BaseTestCase\n \n \n@@ -13,6 +14,27 @@\n         self.assert_equal(bytes_to_long(b'\\0\\0\\0\\0\\0\\0\\0\\1'), 1)\n         self.assert_equal(long_to_bytes(1), b'\\0\\0\\0\\0\\0\\0\\0\\1')\n \n+    def test_bytes16_to_int(self):\n+        self.assert_equal(bytes16_to_int(b'\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\1'), 1)\n+        self.assert_equal(int_to_bytes16(1), b'\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\1')\n+        self.assert_equal(bytes16_to_int(b'\\0\\0\\0\\0\\0\\0\\0\\1\\0\\0\\0\\0\\0\\0\\0\\0'), 2 ** 64)\n+        self.assert_equal(int_to_bytes16(2 ** 64), b'\\0\\0\\0\\0\\0\\0\\0\\1\\0\\0\\0\\0\\0\\0\\0\\0')\n+\n+    def test_increment_iv(self):\n+        iv0 = b'\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0'\n+        iv1 = b'\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\1'\n+        iv2 = b'\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\2'\n+        self.assert_equal(increment_iv(iv0, 0), iv0)\n+        self.assert_equal(increment_iv(iv0, 1), iv1)\n+        self.assert_equal(increment_iv(iv0, 2), iv2)\n+        iva = b'\\0\\0\\0\\0\\0\\0\\0\\0\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff'\n+        ivb = b'\\0\\0\\0\\0\\0\\0\\0\\1\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'\n+        ivc = b'\\0\\0\\0\\0\\0\\0\\0\\1\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x01'\n+        self.assert_equal(increment_iv(iva, 0), iva)\n+        self.assert_equal(increment_iv(iva, 1), ivb)\n+        self.assert_equal(increment_iv(iva, 2), ivc)\n+        self.assert_equal(increment_iv(iv0, 2**64), ivb)\n+\n     def test_aes(self):\n         key = b'X' * 32\n         data = b'foo' * 10\n", "issue": "borgbackup build failure when using OpenSSL 1.1.0\nhttps://groups.google.com/d/msg/linux.debian.devel/53fq9S-Qpp4/V_0pPtdzBQAJ\n\n", "before_files": [{"content": "from binascii import hexlify\n\nfrom ..crypto import AES, bytes_to_long, bytes_to_int, long_to_bytes\nfrom . import BaseTestCase\n\n\nclass CryptoTestCase(BaseTestCase):\n\n    def test_bytes_to_int(self):\n        self.assert_equal(bytes_to_int(b'\\0\\0\\0\\1'), 1)\n\n    def test_bytes_to_long(self):\n        self.assert_equal(bytes_to_long(b'\\0\\0\\0\\0\\0\\0\\0\\1'), 1)\n        self.assert_equal(long_to_bytes(1), b'\\0\\0\\0\\0\\0\\0\\0\\1')\n\n    def test_aes(self):\n        key = b'X' * 32\n        data = b'foo' * 10\n        # encrypt\n        aes = AES(is_encrypt=True, key=key)\n        self.assert_equal(bytes_to_long(aes.iv, 8), 0)\n        cdata = aes.encrypt(data)\n        self.assert_equal(hexlify(cdata), b'c6efb702de12498f34a2c2bbc8149e759996d08bf6dc5c610aefc0c3a466')\n        self.assert_equal(bytes_to_long(aes.iv, 8), 2)\n        # decrypt\n        aes = AES(is_encrypt=False, key=key)\n        self.assert_equal(bytes_to_long(aes.iv, 8), 0)\n        pdata = aes.decrypt(cdata)\n        self.assert_equal(data, pdata)\n        self.assert_equal(bytes_to_long(aes.iv, 8), 2)\n", "path": "borg/testsuite/crypto.py"}]}