         m1 (byte-array (range 10))
         m2 (byte-array (range 10 20))]
     (is (= s/noncebytes
-           (buflen (sn m1 k1))
-           (buflen (sn m2 k1))
-           (buflen (sn m1 k2))
-           (buflen (sn m2 k2))))
+           (bb/buflen (sn m1 k1))
+           (bb/buflen (sn m2 k1))
+           (bb/buflen (sn m1 k2))
+           (bb/buflen (sn m2 k2))))
     (is (u/array-eq (sn m1 k1) (sn m1 k1)))
     (is (not (u/array-eq (sn m1 k1) (sn m2 k1))))
     (is (not (u/array-eq (sn m1 k1) (sn m1 k2))))))

      (is (= (range s/noncebytes) (take s/noncebytes c1) (take s/noncebytes c2))))))

(deftest synthetic-nonce-test
  (is (= (buflen @#'ms/synthetic-personal)
         g/blake2b-personalbytes))
  (let [k1 (byte-array (reverse (range 32)))
        k2 (byte-array (reverse (range 32 64)))

  (let [a (#'ms/random-nonce!)
        b (#'ms/random-nonce!)]
    (is (not (u/array-eq a b)))
    (is (= s/noncebytes (bb/buflen a) (bb/buflen b)))))

(defn is-valid-magicnonce-ctext?
  "Does the given ctext decrypt properly?"
  [ctext]
  (let [ptextlen (bb/buflen st/ptext)]
    (is (= (+ s/noncebytes s/macbytes ptextlen)
           (bb/buflen ctext)))

    (let [out (byte-array ptextlen)]
      (ms/decrypt-to-buf! out st/secret-key ctext)
      (is (u/array-eq st/ptext out)))

    (let [out (bb/alloc ptextlen)
          forgery (bb/->indirect-byte-buf (r/randombytes (bb/buflen out)))]
      (is (thrown-with-msg?
           RuntimeException #"Ciphertext verification failed"
           (ms/decrypt-to-buf!
            out
            (bb/->indirect-byte-buf st/secret-key)
            forgery))))

    (is (u/array-eq st/ptext (ms/decrypt st/secret-key ctext)))

    (let [forgery (bb/->indirect-byte-buf (r/randombytes (bb/buflen ctext)))]
      (is (thrown-with-msg?
           RuntimeException #"Ciphertext verification failed"
           (ms/decrypt st/secret-key forgery))))

    (let [out (bb/alloc ptextlen)]
      (ms/open-to-buf!
       out
       (bb/->indirect-byte-buf ctext)
       (bb/->indirect-byte-buf st/secret-key))
      (is (u/array-eq st/ptext out)))

    (let [out (bb/alloc ptextlen)
          forgery (bb/->indirect-byte-buf (r/randombytes (bb/buflen out)))]
      (is (thrown-with-msg?
           RuntimeException #"Ciphertext verification failed"
           (ms/open-to-buf!
            out
            forgery
            (bb/->indirect-byte-buf st/secret-key)))))

    (is (u/array-eq st/ptext (ms/open ctext st/secret-key)))

    (let [forgery (r/randombytes (bb/buflen ctext))]
      (is (thrown-with-msg?
           RuntimeException #"Ciphertext verification failed"
           (ms/open forgery st/secret-key))))))
