Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Commit eb80122

Browse files
author
Yannick Scherer
committed
Extend supported algorithms
Updated based on latest BouncyCastle provider. TODO: Examine availability of HMAC variants.
1 parent 76657f2 commit eb80122

File tree

2 files changed

+125
-21
lines changed

2 files changed

+125
-21
lines changed

src/pandect/codegen.clj

Lines changed: 75 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,54 @@
99
[signature-generator :refer [signature-generator]]]))
1010

1111
(def ^:private algorithms-names
12-
(-> '{gost "GOST3411"
13-
whirlpool "Whirlpool"
14-
adler32 "ADLER-32"
15-
crc32 "CRC-32"
16-
tiger "Tiger"
17-
siphash "Siphash-2-4"
18-
siphash48 "Siphash-4-8"}
12+
(-> '{gost "GOST3411"
13+
whirlpool "Whirlpool"
14+
adler32 "ADLER-32"
15+
crc32 "CRC-32"
16+
tiger "Tiger"
17+
parallelhash128-256 "PARALLELHASH128-256"
18+
parallelhash256-512 "PARALLELHASH256-512"
19+
siphash "Siphash-2-4"
20+
siphash48 "Siphash-4-8"
21+
shake128-256 "SHAKE128-256"
22+
shake256-512 "SHAKE256-512"
23+
sm3 "SM3"
24+
tuplehash128-256 "TUPLEHASH128-256"
25+
tuplehash256-512 "TUPLEHASH256-512"
26+
}
27+
28+
;; BLAKE2B
29+
(into
30+
(for [length [160 256 384 512]]
31+
[(as-sym 'blake2b- length) (str "BLAKE2B-" length)]))
32+
33+
;; BLAKE2S
34+
(into
35+
(for [length [128 160 224 256]]
36+
[(as-sym 'blake2s- length) (str "BLAKE2S-" length)]))
37+
38+
;; BLAKE3
39+
(into
40+
(for [length [256]]
41+
[(as-sym 'blake3- length) (str "BLAKE3-" length)]))
42+
43+
;; HARAKA
44+
(into
45+
(for [length [256 512]]
46+
[(as-sym 'haraka- length) (str "HARAKA-" length)]))
1947

2048
;; KECCAK
2149
(into
22-
(for [length [224 256 384 512]]
50+
(for [length [224 256 288 384 512]]
2351
[(as-sym 'keccak- length) (str "Keccak-" length)]))
2452

25-
;; BLAKE2B
53+
;; KUPYNA
2654
(into
27-
(for [length [160 256 384 512]]
28-
[(as-sym 'blake2b- length) (str "BLAKE2B-" length)]))
55+
(for [length [256 384 512]]
56+
[(as-sym 'kupyna- length) (str "DSTU7564-" length)]))
57+
(into
58+
(for [length [256 384 512]]
59+
[(as-sym 'dstu7464- length) (str "DSTU7564-" length)]))
2960

3061
;; MDx
3162
(into
@@ -45,7 +76,38 @@
4576
;; SHA-3
4677
(into
4778
(for [length [224 256 384 512]]
48-
[(as-sym 'sha3- length) (str "SHA3-" length)]))))
79+
[(as-sym 'sha3- length) (str "SHA3-" length)]))
80+
81+
;; SHA-512
82+
(into
83+
(for [length [224 256]]
84+
[(as-sym 'sha512- length) (str "SHA-512/" length)]))
85+
86+
;; SKEIN-256
87+
(into
88+
(for [length [128 160 224 256]]
89+
[(as-sym 'skein256- length) (str "SKEIN-256-" length)]))
90+
91+
;; SKEIN-512
92+
(into
93+
(for [length [128 160 224 256 384 512]]
94+
[(as-sym 'skein512- length) (str "SKEIN-512-" length)]))
95+
96+
;; SKEIN-1024
97+
(into
98+
(for [length [384 512 1024]]
99+
[(as-sym 'skein1024- length) (str "SKEIN-1024-" length)]))))
100+
101+
102+
(defn missing-algorithms
103+
[]
104+
(->> (java.security.Security/getAlgorithms "MessageDigest")
105+
(remove #(re-matches #"^.*\d\.\d.+" %))
106+
(remove (comp (set (sort (map clojure.string/lower-case (vals algorithms-names))))
107+
clojure.string/lower-case))
108+
(sort)))
109+
110+
(missing-algorithms)
49111

50112
(def ^:private generators
51113
[hash-generator
@@ -85,7 +147,7 @@
85147
(fn [[sym algorithm]]
86148
(let [filename (.replace (format "%s.clj" sym) \- \_)]
87149
(locking *out*
88-
(println "[codegen] *" algorithm))
150+
(println "[codegen] *" sym '-> algorithm))
89151
(doto (file base "pandect" "algo" filename)
90152
(-> .getParentFile .mkdirs)
91153
(write-source! sym algorithm)))))

src/pandect/impl/bouncy_castle.clj

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,74 @@
1212
(vector
1313
["GOST3411" "Hmac-GOST3411"]
1414
["MD4" "Hmac-MD4"]
15+
["PARALLELHASH128-256"]
16+
["PARALLELHASH256-512"]
1517
["SHA-224" "Hmac-SHA224"]
18+
["SHAKE128-256"]
19+
["SHAKE256-512"]
20+
["SM3"]
1621
["Tiger" "Hmac-Tiger"]
17-
["Whirlpool" "Hmac-Whirlpool"])
18-
19-
;; KECCAK
20-
(for [length [224 256 384 512]]
21-
[(str "Keccak-" length) (str "Hmac-Keccak" length)])
22+
["TUPLEHASH128-256"]
23+
["TUPLEHASH256-512"]
24+
["Whirlpool" "Hmac-Whirlpool"]
25+
)
2226

2327
;; BLAKE2B
2428
(for [length [160 256 384 512]]
2529
[(str "BLAKE2B-" length)])
2630

31+
;; BLAKE2S
32+
(for [length [128 160 224 256]]
33+
[(str "BLAKE2S-" length)])
34+
35+
;; BLAKE3
36+
(for [length [256]]
37+
[(str "BLAKE3-" length)])
38+
39+
;; DSTU7564
40+
(for [length [256 384 512]]
41+
[(str "DSTU7564-" length)])
42+
43+
;; HARAKA-256
44+
(for [length [256 512]]
45+
[(str "HARAKA-" length)])
46+
47+
;; KECCAK
48+
(for [length [224 256 288 384 512]]
49+
[(str "Keccak-" length) (str "Hmac-Keccak" length)])
50+
2751
;; RipeMD
2852
(for [rmd-length [128 160 256 320]]
2953
[(str "RipeMD" rmd-length) (str "Hmac-RipeMD" rmd-length)])
3054

3155
;; SHA-3
3256
(for [sha3-length [224 256 384 512]]
33-
[(str "SHA3-" sha3-length)])))
57+
[(str "SHA3-" sha3-length)])
58+
59+
;; SHA-512
60+
(for [length [224 256]]
61+
[(str "SHA-512/" length)])
62+
63+
;; SKEIN-256
64+
(for [length [128 160 224 256]]
65+
[(str "SKEIN-256-" length)])
66+
67+
;; SKEIN-512
68+
(for [length [128 160 224 256 384 512]]
69+
[(str "SKEIN-512-" length)])
70+
71+
;; SKEIN-1024
72+
(for [length [384 512 1024]]
73+
[(str "SKEIN-1024-" length)])
74+
75+
))
3476

3577
(doseq [[hash-algorithm
3678
hmac-algorithm] MD_ALGORITHMS]
3779
(gen/register-algorithm!
3880
{:name hash-algorithm
3981
:requires '(pandect.utils.bouncy-castle-provider)
40-
:docstring "(requires `org.bouncycastle/bcprov-jdk15on` to be on the classpath)"}
82+
:docstring "(requires `org.bouncycastle/bcprov-jdk18on` to be on the classpath)"}
4183
(hash/make hash-algorithm)
4284
(hmac/make hmac-algorithm)))
4385

@@ -52,5 +94,5 @@
5294
(gen/register-algorithm!
5395
{:name hmac-algorithm
5496
:requires '(pandect.utils.bouncy-castle-provider)
55-
:docstring "(requires `org.bouncycastle/bcprov-jdk15on` to be on the classpath)"}
97+
:docstring "(requires `org.bouncycastle/bcprov-jdk18on` to be on the classpath)"}
5698
(hmac/make-exclusive hmac-algorithm)))

0 commit comments

Comments
 (0)