<commit_before>;;; -*- Gerbil -*-
;;; (C) vyzo at hackzen.org
;;; libcrypto DH key exchage
package: std/crypto

(import :gerbil/gambit/hvectors
        :std/crypto/libcrypto
        :std/crypto/etc)
(export
  (except-out #t with-null-check)
  (rename: DH_pub_key DH-pub-key))

(def (with-null-check makef)
  (or (makef)
      (error "error allocating key; NULL POINTER")))

(def (DH-get-1024-160)
  (with-null-check DH_get_1024_160))
(def (DH-get-2048-224)
  (with-null-check DH_get_2048_224))
(def (DH-get-2048-256)
  (with-null-check DH_get_2048_256))

(def (generate-key dh)
  (with-libcrypto-error
   (DH_generate_key dh)))

(def (compute-key dh bn)
  (let* ((len (DH_size dh))
         (secret (make-u8vector len))
         (count (DH_compute_key secret bn dh)))
    (if (fx< count len)
      (u8vector-shrink! secret count)
      secret)))

<commit_msg>crypto/dh: DH- prefix generate-key and compute-key<commit_after>;;; -*- Gerbil -*-
;;; (C) vyzo at hackzen.org
;;; libcrypto DH key exchage
package: std/crypto

(import :gerbil/gambit/hvectors
        :std/crypto/libcrypto
        :std/crypto/etc)
(export
  (except-out #t with-null-check)
  (rename: DH_pub_key DH-pub-key))

(def (with-null-check makef)
  (or (makef)
      (error "error allocating key; NULL POINTER")))

(def (DH-get-1024-160)
  (with-null-check DH_get_1024_160))
(def (DH-get-2048-224)
  (with-null-check DH_get_2048_224))
(def (DH-get-2048-256)
  (with-null-check DH_get_2048_256))

(def (DH-generate-key dh)
  (with-libcrypto-error
   (DH_generate_key dh)))

(def (DH-compute-key dh bn)
  (let* ((len (DH_size dh))
         (secret (make-u8vector len))
         (count (DH_compute_key secret bn dh)))
    (if (fx< count len)
      (u8vector-shrink! secret count)
      secret)))


{'fraction_non_alphanumeric': 0.16070414537194777, 'fraction_numerical': 0.04997160704145372, 'mean_word_length': 3.256038647342995, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1030769', 'n_tokens_mistral': 795, 'n_tokens_neox': 702, 'n_words': 157}