 
 (defn ^:private chacha20poly1305-ietf-decrypt-detached-to-buf!
   [m nsec c mac ad npub k]
-  (b/call! chacha20poly1305-ietf-decrypt-detached m nsec c mac ad npub k)
-  c)
+  (let [res (b/call! chacha20poly1305-ietf-decrypt-detached m nsec c mac ad npub k)]
+    (if (zero? res)
+      c
+      (throw (RuntimeException. "Ciphertext verification failed")))))
 
 (defn chacha20poly1305-ietf-decrypt-detached
   [c mac ad npub k]


(defn ^:private chacha20poly1305-decrypt-to-buf!
  [m nsec c ad npub k]
  (b/call! chacha20poly1305-decrypt m nsec c ad npub k)
  c)

(defn chacha20poly1305-decrypt
  [c ad npub k]

    (bb/->bytes m)))

(defn ^:private chacha20poly1305-keygen-to-buf! [k]
  (b/call! chacha20poly1305-keygen k))

(defn chacha20poly1305-keygen
  "Generates a new random key."
  []
  (let [k (bb/alloc chacha20poly1305-keybytes)]
    (chacha20poly1305-keygen-to-buf! k)
    k))

(defn new-chacha20poly1305-nonce
