         ad (aead-xchacha20poly1305-ietf-vector "ad")
         nonce (aead/new-xchacha20poly1305-ietf-nonce)
         {:keys [c mac]} (aead/xchacha20poly1305-ietf-encrypt-detached ptext ad nonce k)]
-    (is (bb/bytes= ptext (aead/xchacha20poly1305-ietf-decrypt-detached c mac ad nonce k)))))
+    (is (bb/bytes= ptext (aead/xchacha20poly1305-ietf-decrypt-detached c mac ad nonce k)))
+    (is (thrown-with-msg?
+         RuntimeException #"Ciphertext verification failed"
+         (aead/xchacha20poly1305-ietf-decrypt-detached (rand-bit-flip c) mac ad nonce k)))))
+
+(deftest xchacha20poly1305-ietf-keygen-test
+  (let [ks (set (repeatedly 100 aead/xchacha20poly1305-ietf-keygen))]
+    (is (= 100 (count ks)))
+    (doseq [^ByteBuffer k ks]
+      (is (= aead/xchacha20poly1305-ietf-keybytes (.limit k))))))

        ptext (aead-xchacha20poly1305-ietf-vector "plaintext")
        ad (aead-xchacha20poly1305-ietf-vector "ad")
        nonce (aead/new-xchacha20poly1305-ietf-nonce)
        generated-key (aead/xchacha20poly1305-ietf-keygen)]
    (is (bb/bytes= ptext (aead/xchacha20poly1305-ietf-decrypt
                          (aead/xchacha20poly1305-ietf-encrypt ptext ad nonce k) ad nonce k)))
    (is (bb/bytes= ptext (aead/xchacha20poly1305-ietf-decrypt
                          (aead/xchacha20poly1305-ietf-encrypt ptext ad nonce generated-key) ad nonce generated-key)))))

(deftest xchacha20poly1305-ietf-encrypt-decrypt-detached-test
  (let [k (aead-xchacha20poly1305-ietf-vector "key")

            [caesium.test-utils :refer [const-test]]
            [caesium.vectors :as v]
            [clojure.test :refer [is deftest]]
            [caesium.byte-bufs :as bb])
  (:import (java.nio ByteBuffer)))

(const-test
 aead/chacha20poly1305-ietf-keybytes 32
