         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")

        {:keys [c mac]} (aead/chacha20poly1305-encrypt-detached ptext ad nonce k)]
    (is (bb/bytes= ctext c))
    (is (bb/bytes= mtext mac))
    (is (bb/bytes= ptext (aead/chacha20poly1305-decrypt-detached ctext mac ad nonce k)))
    (is (thrown-with-msg?
         RuntimeException #"Ciphertext verification failed"
         (aead/chacha20poly1305-decrypt-detached (rand-bit-flip ctext) mac ad nonce k)))))

(deftest chacha20poly1305-keygen-test
  (let [ks (set (repeatedly 100 aead/chacha20poly1305-keygen))]
    (is (= 100 (count ks)))
    (doseq [^ByteBuffer k ks]
      (is (= aead/chacha20poly1305-keybytes (.limit k))))))

(def aead-xchacha20poly1305-ietf-vector
  (comp v/hex-resource (partial str "vectors/aead/xchacha20poly1305ietf/")))
