<commit_before>(ns caesium.crypto.shorthash-test
  (:require [caesium.crypto.shorthash :as sh]
            [clojure.test :refer [is testing deftest]]
            [caesium.test-utils :refer [const-test]]
            [caesium.byte-bufs :as bb]
            [caesium.vectors :as v]))

(const-test
 sh/keybytes 16
 sh/bytes 8
 sh/primitive "siphash24")

(def max-len 64)

(def shorthash-vectors (v/hex-resources "vectors/shorthash/shorthash.txt"))

(deftest shorthash-kat-test
  "Tests and test vectors from:
  https://github.com/jedisct1/libsodium/blob/master/test/default/shorthash.c
  https://github.com/jedisct1/libsodium/blob/master/test/default/shorthash.exp"
  (let [k (->> (iterate inc 0)
               (take sh/keybytes)
               (byte-array))
        full-range (range 64)
        test-vals (for [r full-range]
                    (->> full-range
                         (take r)
                         (byte-array)))
        test-answers (map #(sh/shorthash % k) test-vals)]
    (dorun (map (fn [x y]
                  (is (bb/bytes= x y)))
                test-answers
                shorthash-vectors))))
<commit_msg>added basic test for shorthash keygen<commit_after>(ns caesium.crypto.shorthash-test
  (:require [caesium.crypto.shorthash :as sh]
            [clojure.test :refer [is testing deftest]]
            [caesium.test-utils :refer [const-test]]
            [caesium.byte-bufs :as bb]
            [caesium.vectors :as v]))

(const-test
 sh/keybytes 16
 sh/bytes 8
 sh/primitive "siphash24")

(def max-len 64)

(def shorthash-vectors (v/hex-resources "vectors/shorthash/shorthash.txt"))

(deftest shorthash-kat-test
  "Tests and test vectors from:
  https://github.com/jedisct1/libsodium/blob/master/test/default/shorthash.c
  https://github.com/jedisct1/libsodium/blob/master/test/default/shorthash.exp"
  (let [k (->> (iterate inc 0)
               (take sh/keybytes)
               (byte-array))
        full-range (range 64)
        test-vals (for [r full-range]
                    (->> full-range
                         (take r)
                         (byte-array)))
        test-answers (map #(sh/shorthash % k) test-vals)]
    (dorun (map (fn [x y]
                  (is (bb/bytes= x y)))
                test-answers
                shorthash-vectors))))

(deftest keygen!-test
  (let [[f & rs] (repeatedly 10 sh/keygen!)]
    (doseq [r rs]
      (is (not (bb/bytes= f r))))))

{'fraction_non_alphanumeric': 0.1393713813068652, 'fraction_numerical': 0.010752688172043012, 'mean_word_length': 1.9827373612823675, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 4, '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': '353072', 'n_tokens_mistral': 885, 'n_tokens_neox': 816, 'n_words': 177}