1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package io.github.tonywasher.joceanus.gordianknot.api.mac.spec;
19
20 import io.github.tonywasher.joceanus.gordianknot.api.base.GordianLength;
21 import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianSymKeySpec;
22 import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianSymKeySpecBuilder;
23 import io.github.tonywasher.joceanus.gordianknot.api.digest.spec.GordianDigestSpec;
24 import io.github.tonywasher.joceanus.gordianknot.api.digest.spec.GordianDigestSpecBuilder;
25 import io.github.tonywasher.joceanus.gordianknot.api.digest.spec.GordianDigestSubSpec.GordianDigestState;
26 import io.github.tonywasher.joceanus.gordianknot.api.digest.spec.GordianDigestType;
27
28
29
30
31 public interface GordianMacSpecBuilder {
32
33
34
35
36
37
38 GordianMacSpecBuilder withType(GordianMacType pType);
39
40
41
42
43
44
45
46 GordianMacSpecBuilder withKeyLength(GordianLength pLength);
47
48
49
50
51
52
53
54 GordianMacSpecBuilder withDigestSubSpec(GordianDigestSpec pDigestSpec);
55
56
57
58
59
60
61
62 GordianMacSpecBuilder withSymKeySubSpec(GordianSymKeySpec pSymKeySpec);
63
64
65
66
67
68
69
70 GordianMacSpecBuilder withSipHashSubSpec(GordianSipHashType pSipHashSpec);
71
72
73
74
75
76
77
78 GordianMacSpecBuilder withLengthSubSpec(GordianLength pLength);
79
80
81
82
83
84
85 GordianDigestSpecBuilder usingDigestSpecBuilder();
86
87
88
89
90
91
92 GordianSymKeySpecBuilder usingSymKeySpecBuilder();
93
94
95
96
97
98
99 GordianMacSpec build();
100
101
102
103
104
105
106
107
108 default GordianMacSpec mac(final GordianMacType pMacType,
109 final GordianLength pKeyLength) {
110 return withType(pMacType).withKeyLength(pKeyLength).build();
111 }
112
113
114
115
116
117
118
119
120 default GordianMacSpec mac(final GordianMacType pMacType,
121 final GordianSymKeySpec pSymKeySpec) {
122 return withType(pMacType).withSymKeySubSpec(pSymKeySpec).build();
123 }
124
125
126
127
128
129
130
131 default GordianMacSpec hMac(final GordianDigestType pDigestType) {
132 return hMac(pDigestType, GordianLength.LEN_128);
133 }
134
135
136
137
138
139
140
141
142 default GordianMacSpec hMac(final GordianDigestType pDigestType,
143 final GordianLength pKeyLength) {
144 return hMac(usingDigestSpecBuilder().withType(pDigestType).build(), pKeyLength);
145 }
146
147
148
149
150
151
152
153 default GordianMacSpec hMac(final GordianDigestSpec pDigest) {
154 return hMac(pDigest, pDigest.getDigestLength());
155 }
156
157
158
159
160
161
162
163
164 default GordianMacSpec hMac(final GordianDigestSpec pDigestSpec,
165 final GordianLength pKeyLength) {
166 return withType(GordianMacType.HMAC).withDigestSubSpec(pDigestSpec).withKeyLength(pKeyLength).build();
167 }
168
169
170
171
172
173
174
175 default GordianMacSpec gMac(final GordianSymKeySpec pSymKeySpec) {
176 return withType(GordianMacType.GMAC).withSymKeySubSpec(pSymKeySpec).build();
177 }
178
179
180
181
182
183
184
185 default GordianMacSpec cMac(final GordianSymKeySpec pSymKeySpec) {
186 return withType(GordianMacType.CMAC).withSymKeySubSpec(pSymKeySpec).build();
187 }
188
189
190
191
192
193
194
195 default GordianMacSpec kMac(final GordianLength pKeyLength) {
196 return kMac(pKeyLength, usingDigestSpecBuilder().shake128());
197 }
198
199
200
201
202
203
204
205
206 default GordianMacSpec kMac(final GordianLength pKeyLength,
207 final GordianDigestSpec pSpec) {
208 return withType(GordianMacType.KMAC).withKeyLength(pKeyLength).withDigestSubSpec(pSpec).build();
209 }
210
211
212
213
214
215
216 default GordianMacSpec poly1305Mac() {
217 return withType(GordianMacType.POLY1305).withKeyLength(GordianLength.LEN_256).build();
218 }
219
220
221
222
223
224
225
226 default GordianMacSpec poly1305Mac(final GordianSymKeySpec pSymKeySpec) {
227 return withType(GordianMacType.POLY1305).withSymKeySubSpec(pSymKeySpec).build();
228 }
229
230
231
232
233
234
235
236 default GordianMacSpec skeinMac(final GordianLength pKeyLength) {
237 return skeinMac(pKeyLength, GordianLength.LEN_256);
238 }
239
240
241
242
243
244
245
246
247 default GordianMacSpec skeinMac(final GordianLength pKeyLength,
248 final GordianLength pLength) {
249 return skeinMac(pKeyLength, usingDigestSpecBuilder().skein(pLength));
250 }
251
252
253
254
255
256
257
258
259
260 default GordianMacSpec skeinMac(final GordianLength pKeyLength,
261 final GordianDigestState pState,
262 final GordianLength pLength) {
263 return skeinMac(pKeyLength, usingDigestSpecBuilder().skein(pState, pLength));
264 }
265
266
267
268
269
270
271
272
273 default GordianMacSpec skeinMac(final GordianLength pKeyLength,
274 final GordianDigestSpec pSpec) {
275 return withType(GordianMacType.SKEIN).withKeyLength(pKeyLength).withDigestSubSpec(pSpec).build();
276 }
277
278
279
280
281
282
283
284
285 default GordianMacSpec skeinXMac(final GordianLength pKeyLength,
286 final GordianDigestState pState) {
287 return skeinMac(pKeyLength, usingDigestSpecBuilder().skeinX(pState));
288 }
289
290
291
292
293
294
295
296
297 default GordianMacSpec blake2sMac(final GordianLength pKeyLength,
298 final GordianLength pLength) {
299 return blake2Mac(pKeyLength, usingDigestSpecBuilder().blake2s(pLength));
300 }
301
302
303
304
305
306
307
308
309 default GordianMacSpec blake2bMac(final GordianLength pKeyLength,
310 final GordianLength pLength) {
311 return blake2Mac(pKeyLength, usingDigestSpecBuilder().blake2b(pLength));
312 }
313
314
315
316
317
318
319
320
321 default GordianMacSpec blake2Mac(final GordianLength pKeyLength,
322 final GordianDigestSpec pSpec) {
323 return withType(GordianMacType.BLAKE2).withKeyLength(pKeyLength).withDigestSubSpec(pSpec).build();
324 }
325
326
327
328
329
330
331
332
333 default GordianMacSpec blake2XMac(final GordianLength pKeyLength,
334 final GordianDigestState pState) {
335 return withType(GordianMacType.BLAKE2).withKeyLength(pKeyLength)
336 .withDigestSubSpec(usingDigestSpecBuilder().blake2X(pState)).build();
337 }
338
339
340
341
342
343
344
345 default GordianMacSpec blake3Mac(final GordianLength pMacLength) {
346 return withType(GordianMacType.BLAKE3).withKeyLength(GordianLength.LEN_256)
347 .withDigestSubSpec(usingDigestSpecBuilder().blake3(pMacLength)).build();
348 }
349
350
351
352
353
354
355
356 default GordianMacSpec kalynaMac(final GordianSymKeySpec pKeySpec) {
357 return withType(GordianMacType.KALYNA).withSymKeySubSpec(pKeySpec).build();
358 }
359
360
361
362
363
364
365
366 default GordianMacSpec kupynaMac(final GordianLength pKeyLength) {
367 return kupynaMac(pKeyLength, GordianLength.LEN_256);
368 }
369
370
371
372
373
374
375
376
377 default GordianMacSpec kupynaMac(final GordianLength pKeyLength,
378 final GordianLength pLength) {
379 return withType(GordianMacType.KUPYNA).withKeyLength(pKeyLength)
380 .withDigestSubSpec(usingDigestSpecBuilder().kupyna(pLength)).build();
381 }
382
383
384
385
386
387
388
389 default GordianMacSpec vmpcMac(final GordianLength pKeyLength) {
390 return withType(GordianMacType.VMPC).withKeyLength(pKeyLength).build();
391 }
392
393
394
395
396
397
398 default GordianMacSpec gostMac() {
399 return withType(GordianMacType.GOST).withKeyLength(GordianLength.LEN_256).build();
400 }
401
402
403
404
405
406
407
408 default GordianMacSpec sipHash(final GordianSipHashType pSpec) {
409 return withType(GordianMacType.SIPHASH).withSipHashSubSpec(pSpec).build();
410 }
411
412
413
414
415
416
417
418 default GordianMacSpec cbcMac(final GordianSymKeySpec pSymKeySpec) {
419 return withType(GordianMacType.CBCMAC).withSymKeySubSpec(pSymKeySpec).build();
420 }
421
422
423
424
425
426
427
428 default GordianMacSpec cfbMac(final GordianSymKeySpec pSymKeySpec) {
429 return withType(GordianMacType.CFBMAC).withSymKeySubSpec(pSymKeySpec).build();
430 }
431
432
433
434
435
436
437
438
439 default GordianMacSpec zucMac(final GordianLength pKeyLength,
440 final GordianLength pLength) {
441 return withType(GordianMacType.ZUC).withKeyLength(pKeyLength).withLengthSubSpec(pLength).build();
442 }
443 }