anchor.diff:                  (declare (type simple-octet-vector plaintext ciphertext))
                   (declare (type index ciphertext-start ciphertext-end plaintext-start))
                   (declare (ignorable handle-final-block))
  -                (let ,block-length-binding
  -                  (loop with iv of-type (simple-octet-vector ,(if (constantp `,block-length-expr)
  -                                                                  `,block-length-expr
  -                                                                  '*)) = (iv mode)
  -                     with iv-position of-type (integer 0 ,(if (constantp `,block-length-expr)
  -                                                              `(,block-length-expr)
  -                                                              '*)) = (iv-position mode)
  -                     with encrypt-function of-type function = (encrypt-function cipher)
  -                     for i of-type index from ciphertext-start below ciphertext-end
  -                     for j of-type index from plaintext-start
  -                     do (when (zerop iv-position)
  -                          (funcall encrypt-function cipher iv 0 iv 0))
  -                     (setf (aref plaintext j) (logxor (aref ciphertext i)
  -                                                      (aref iv iv-position)))
  -                     (setf iv-position (mod (1+ iv-position) ,block-length-expr))
  -                     finally (return-from decrypt-with-mode
  -                               (let ((n-bytes-decrypted (- ciphertext-end ciphertext-start)))
  -                                 (setf (iv-position mode) iv-position)
  -                                 (values n-bytes-decrypted n-bytes-decrypted)))))))
  -           (message-length (cipher-specializer block-length-binding
  -                                               block-length-expr)
  -             (declare (ignore block-length-binding block-length-expr))
  +                (loop with iv of-type (simple-octet-vector ,block-length-expr) = (iv mode)
  +                      with iv-position of-type (integer 0 (,block-length-expr)) = (iv-position mode)
  +                      with encrypt-function of-type function = (encrypt-function cipher)
  +                      for i of-type index from ciphertext-start below ciphertext-end
  +                      for j of-type index from plaintext-start
  +                      do (when (zerop iv-position)
  +                           (funcall encrypt-function cipher iv 0 iv 0))
  +                         (setf (aref plaintext j) (logxor (aref ciphertext i)
  +                                                          (aref iv iv-position)))
  +                         (setf iv-position (mod (1+ iv-position) ,block-length-expr))
  +                      finally (return-from decrypt-with-mode
  +                                (let ((n-bytes-decrypted (- ciphertext-end ciphertext-start)))
  +                                  (setf (iv-position mode) iv-position)
  +                                  (values n-bytes-decrypted n-bytes-decrypted))))))
  +           (message-length (cipher-specializer block-length-expr)
  +             (declare (ignore block-length-expr))
                `(defmethod encrypted-message-length ((cipher ,cipher-specializer)
                                                      (mode ofb-mode) length
                                                      &optional handle-final-block)
  
positive.code:                 (declare (type simple-octet-vector plaintext ciphertext))
                  (declare (type index ciphertext-start ciphertext-end plaintext-start))
                  (declare (ignorable handle-final-block))
                  (let ,block-length-binding
                    (let ((temp-block (make-array ,block-length-expr :element-type '(unsigned-byte 8))))
                      (declare (type (simple-octet-vector ,(if (constantp `,block-length-expr)
                                                               `,block-length-expr
                                                               '*)) temp-block))
                      (declare (dynamic-extent temp-block))
                      (loop with iv of-type (simple-octet-vector ,(if (constantp `,block-length-expr)
                                                                    `,block-length-expr
                                                                    '*)) = (iv mode)
                         with offset of-type index = ciphertext-start
                         with decrypt-function of-type function = (decrypt-function cipher)
                         while (<= offset (- ciphertext-end ,block-length-expr))
                         do (replace temp-block ciphertext :start1 0
                                     :end1 ,block-length-expr :start2 offset)
                         (funcall decrypt-function cipher ciphertext offset
                                  plaintext plaintext-start)
                         (xor-block ,block-length-expr iv plaintext plaintext-start
                                    plaintext plaintext-start)
                         (replace iv temp-block :end1 ,block-length-expr
                                  :end2 ,block-length-expr)
                         (incf offset ,block-length-expr)
                         (incf plaintext-start ,block-length-expr)
                         finally (return-from decrypt-with-mode
                                   (let ((n-bytes-decrypted (- offset ciphertext-start)))
                                     (values n-bytes-decrypted n-bytes-decrypted))))))))
             (message-length (cipher-specializer block-length-binding
                                                 block-length-expr)
               `(defmethod encrypted-message-length ((cipher ,cipher-specializer)
                                                     (mode cbc-mode) length
                                                     &optional handle-final-block)
                  (declare (ignore handle-final-block))
                  (let ,block-length-binding
                    (* (truncate length ,block-length-expr) ,block-length-expr)))))
    (define-mode-function encrypt decrypt message-length))
  
  
  ;;; CFB mode
  
  (macrolet ((encrypt (cipher-specializer block-length-binding
                                                  block-length-expr)
             `(defmethod encrypt-with-mode ((cipher ,cipher-specializer)
                                            (mode cfb-mode) plaintext ciphertext
                                            plaintext-start plaintext-end
  
negative.code:               (declare (type simple-octet-vector plaintext ciphertext))
                (declare (type index plaintext-start plaintext-end ciphertext-start))
                (declare (ignorable handle-final-block))
                (loop with iv of-type (simple-octet-vector ,(if (constantp `,block-length-expr)
                                                                `,block-length-expr
                                                                '*)) = (iv mode)
                      with iv-position of-type (integer 0 ,(if (constantp `,block-length-expr)
                                                               `(,block-length-expr)
                                                               '*)) = (iv-position mode)
                      with encrypt-function of-type function = (encrypt-function cipher)
                      for i of-type index from plaintext-start below plaintext-end
                      for j of-type index from ciphertext-start
                      do (when (zerop iv-position)
                           (funcall encrypt-function cipher iv 0 iv 0))
                         (let ((b (logxor (aref plaintext i) (aref iv iv-position))))
                           (setf (aref ciphertext j) b)
                           (setf (aref iv iv-position) b)
                           (setf iv-position (mod (1+ iv-position) ,block-length-expr)))
                      finally (return-from encrypt-with-mode
                                (let ((n-bytes-encrypted (- plaintext-end plaintext-start)))
                                  (setf (iv-position mode) iv-position)
                                  (values n-bytes-encrypted n-bytes-encrypted))))))
             (decrypt (cipher-specializer block-length-expr)
               `(defmethod decrypt-with-mode ((cipher ,cipher-specializer)
                                              (mode cfb-mode) ciphertext plaintext
                                              ciphertext-start ciphertext-end
  