View Javadoc
1   /*
2    * GordianKnot: Security Suite
3    * Copyright 2026. Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License.  You may obtain a copy
7    * of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  
18  package io.github.tonywasher.joceanus.gordianknot.api.cipher.spec;
19  
20  import io.github.tonywasher.joceanus.gordianknot.api.base.GordianLength;
21  import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianStreamKeySubType.GordianChaCha20Key;
22  import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianStreamKeySubType.GordianElephantKey;
23  import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianStreamKeySubType.GordianISAPKey;
24  import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianStreamKeySubType.GordianRomulusKey;
25  import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianStreamKeySubType.GordianSalsa20Key;
26  import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianStreamKeySubType.GordianSkeinXofKey;
27  import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianStreamKeySubType.GordianSparkleKey;
28  import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianStreamKeySubType.GordianVMPCKey;
29  
30  /**
31   * GordianKnot StreamKeySpec Builder.
32   */
33  public interface GordianStreamKeySpecBuilder {
34      /**
35       * Define StreamKeyType.
36       *
37       * @param pType the type
38       * @return the Builder
39       */
40      GordianStreamKeySpecBuilder withType(GordianStreamKeyType pType);
41  
42      /**
43       * Define subType.
44       *
45       * @param pSubType the subType
46       * @return the Builder
47       */
48      GordianStreamKeySpecBuilder withSubType(GordianStreamKeySubType pSubType);
49  
50      /**
51       * Define KeyLength.
52       *
53       * @param pKeyLength the keyLength
54       * @return the Builder
55       */
56      GordianStreamKeySpecBuilder withKeyLength(GordianLength pKeyLength);
57  
58      /**
59       * Build streamKeySpec.
60       *
61       * @return the streamKeySpec
62       */
63      GordianStreamKeySpec build();
64  
65      /**
66       * Create generic.
67       *
68       * @param pKeyType   the keyType
69       * @param pKeyLength the keyLength
70       * @param pSubType   the subType
71       * @return the keySpec
72       */
73      default GordianStreamKeySpec streamKey(final GordianStreamKeyType pKeyType,
74                                             final GordianLength pKeyLength,
75                                             final GordianStreamKeySubType pSubType) {
76          return withType(pKeyType).withKeyLength(pKeyLength).withSubType(pSubType).build();
77      }
78  
79      /**
80       * Create hc.
81       *
82       * @param pKeyLength the keyLength
83       * @return the keySpec
84       */
85      default GordianStreamKeySpec hc(final GordianLength pKeyLength) {
86          return withType(GordianStreamKeyType.HC).withKeyLength(pKeyLength).build();
87      }
88  
89      /**
90       * Create chacha`.
91       *
92       * @param pKeyLength the keyLength
93       * @return the keySpec
94       */
95      default GordianStreamKeySpec chacha(final GordianLength pKeyLength) {
96          return withType(GordianStreamKeyType.CHACHA20).withKeyLength(pKeyLength).build();
97      }
98  
99      /**
100      * Create chacha7539.
101      *
102      * @param pKeyLength the keyLength
103      * @return the keySpec
104      */
105     default GordianStreamKeySpec chacha7539(final GordianLength pKeyLength) {
106         return withType(GordianStreamKeyType.CHACHA20).withSubType(GordianChaCha20Key.ISO7539).withKeyLength(pKeyLength).build();
107     }
108 
109     /**
110      * Create xchacha.
111      *
112      * @param pKeyLength the keyLength
113      * @return the keySpec
114      */
115     default GordianStreamKeySpec xchacha(final GordianLength pKeyLength) {
116         return withType(GordianStreamKeyType.CHACHA20).withSubType(GordianChaCha20Key.XCHACHA).withKeyLength(pKeyLength).build();
117     }
118 
119     /**
120      * Create salsa.
121      *
122      * @param pKeyLength the keyLength
123      * @return the keySpec
124      */
125     default GordianStreamKeySpec salsa(final GordianLength pKeyLength) {
126         return withType(GordianStreamKeyType.SALSA20).withKeyLength(pKeyLength).build();
127     }
128 
129     /**
130      * Create xsalsa.
131      *
132      * @param pKeyLength the keyLength
133      * @return the keySpec
134      */
135     default GordianStreamKeySpec xsalsa(final GordianLength pKeyLength) {
136         return withType(GordianStreamKeyType.SALSA20).withSubType(GordianSalsa20Key.XSALSA).withKeyLength(pKeyLength).build();
137     }
138 
139     /**
140      * Create isaac.
141      *
142      * @param pKeyLength the keyLength
143      * @return the keySpec
144      */
145     default GordianStreamKeySpec isaac(final GordianLength pKeyLength) {
146         return withType(GordianStreamKeyType.ISAAC).withKeyLength(pKeyLength).build();
147     }
148 
149     /**
150      * Create rc4c.
151      *
152      * @param pKeyLength the keyLength
153      * @return the keySpec
154      */
155     default GordianStreamKeySpec rc4(final GordianLength pKeyLength) {
156         return withType(GordianStreamKeyType.RC4).withKeyLength(pKeyLength).build();
157     }
158 
159     /**
160      * Create vmpc.
161      *
162      * @param pKeyLength the keyLength
163      * @return the keySpec
164      */
165     default GordianStreamKeySpec vmpc(final GordianLength pKeyLength) {
166         return withType(GordianStreamKeyType.VMPC).withKeyLength(pKeyLength).build();
167     }
168 
169     /**
170      * Create vmpcKSA.
171      *
172      * @param pKeyLength the keyLength
173      * @return the keySpec
174      */
175     default GordianStreamKeySpec vmpcKSA(final GordianLength pKeyLength) {
176         return withType(GordianStreamKeyType.VMPC).withSubType(GordianVMPCKey.KSA).withKeyLength(pKeyLength).build();
177     }
178 
179     /**
180      * Create grain.
181      *
182      * @param pKeyLength the keyLength
183      * @return the keySpec
184      */
185     default GordianStreamKeySpec grain(final GordianLength pKeyLength) {
186         return withType(GordianStreamKeyType.GRAIN).withKeyLength(pKeyLength).build();
187     }
188 
189     /**
190      * Create rabbit.
191      *
192      * @param pKeyLength the keyLength
193      * @return the keySpec
194      */
195     default GordianStreamKeySpec rabbit(final GordianLength pKeyLength) {
196         return withType(GordianStreamKeyType.RABBIT).withKeyLength(pKeyLength).build();
197     }
198 
199     /**
200      * Create sosemanuk.
201      *
202      * @param pKeyLength the keyLength
203      * @return the keySpec
204      */
205     default GordianStreamKeySpec sosemanuk(final GordianLength pKeyLength) {
206         return withType(GordianStreamKeyType.SOSEMANUK).withKeyLength(pKeyLength).build();
207     }
208 
209     /**
210      * Create snow3G.
211      *
212      * @param pKeyLength the keyLength
213      * @return the keySpec
214      */
215     default GordianStreamKeySpec snow3G(final GordianLength pKeyLength) {
216         return withType(GordianStreamKeyType.SNOW3G).withKeyLength(pKeyLength).build();
217     }
218 
219     /**
220      * Create zuc.
221      *
222      * @param pKeyLength the keyLength
223      * @return the keySpec
224      */
225     default GordianStreamKeySpec zuc(final GordianLength pKeyLength) {
226         return withType(GordianStreamKeyType.ZUC).withKeyLength(pKeyLength).build();
227     }
228 
229     /**
230      * Create skein.
231      *
232      * @param pKeyLength   the keyLength
233      * @param pStateLength the stateLength
234      * @return the keySpec
235      */
236     default GordianStreamKeySpec skeinXof(final GordianLength pKeyLength,
237                                           final GordianSkeinXofKey pStateLength) {
238         return withType(GordianStreamKeyType.SKEINXOF).withSubType(pStateLength).withKeyLength(pKeyLength).build();
239     }
240 
241     /**
242      * Create blake2X.
243      *
244      * @param pKeyLength the keyLength
245      * @return the keySpec
246      */
247     default GordianStreamKeySpec blake2Xof(final GordianLength pKeyLength) {
248         return withType(GordianStreamKeyType.BLAKE2XOF).withKeyLength(pKeyLength).build();
249     }
250 
251     /**
252      * Create blake3.
253      *
254      * @return the keySpec
255      */
256     default GordianStreamKeySpec blake3Xof() {
257         return withType(GordianStreamKeyType.BLAKE3XOF).build();
258     }
259 
260     /**
261      * Create ascon.
262      *
263      * @return the keySpec
264      */
265     default GordianStreamKeySpec ascon() {
266         return withType(GordianStreamKeyType.ASCON).build();
267     }
268 
269     /**
270      * Create elephant.
271      *
272      * @param pSubSpec the subSpec
273      * @return the keySpec
274      */
275     default GordianStreamKeySpec elephant(final GordianElephantKey pSubSpec) {
276         return withType(GordianStreamKeyType.ELEPHANT).withSubType(pSubSpec).build();
277     }
278 
279     /**
280      * Create isap.
281      *
282      * @param pSubSpec the subSpec
283      * @return the keySpec
284      */
285     default GordianStreamKeySpec isap(final GordianISAPKey pSubSpec) {
286         return withType(GordianStreamKeyType.ISAP).withSubType(pSubSpec).build();
287     }
288 
289     /**
290      * Create photonBeetle.
291      *
292      * @return the keySpec
293      */
294     default GordianStreamKeySpec photonBeetle() {
295         return withType(GordianStreamKeyType.PHOTONBEETLE).build();
296     }
297 
298     /**
299      * Create romulus.
300      *
301      * @param pSubSpec the subSpec
302      * @return the keySpec
303      */
304     default GordianStreamKeySpec romulus(final GordianRomulusKey pSubSpec) {
305         return withType(GordianStreamKeyType.ROMULUS).withSubType(pSubSpec).build();
306     }
307 
308     /**
309      * Create sparkle.
310      *
311      * @param pSubSpec the subSpec
312      * @return the keySpec
313      */
314     default GordianStreamKeySpec sparkle(final GordianSparkleKey pSubSpec) {
315         return withType(GordianStreamKeyType.SPARKLE).withSubType(pSubSpec).build();
316     }
317 
318     /**
319      * Create xoodyak.
320      *
321      * @return the keySpec
322      */
323     default GordianStreamKeySpec xoodyak() {
324         return withType(GordianStreamKeyType.XOODYAK).build();
325     }
326 }