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 /**
21 * The SymCipherSpec Builder class.
22 */
23 public interface GordianSymCipherSpecBuilder {
24 /**
25 * Define SymKeySpec.
26 *
27 * @param pSpec the spec
28 * @return the Builder
29 */
30 GordianSymCipherSpecBuilder withKeySpec(GordianSymKeySpec pSpec);
31
32 /**
33 * Define cipher mode.
34 *
35 * @param pMode the cipher mode
36 * @return the Builder
37 */
38 GordianSymCipherSpecBuilder withMode(GordianCipherMode pMode);
39
40 /**
41 * Define cipher padding.
42 *
43 * @param pPadding the padding
44 * @return the Builder
45 */
46 GordianSymCipherSpecBuilder withPadding(GordianPadding pPadding);
47
48 /**
49 * Access symKeySpecBuilder.
50 *
51 * @return the symKeySpec builder
52 */
53 GordianSymKeySpecBuilder usingSymKeySpecBuilder();
54
55 /**
56 * Build symCipherSpec.
57 *
58 * @return the symCipherSpec
59 */
60 GordianSymCipherSpec build();
61
62 /**
63 * Create a generic symKey cipherSpec.
64 *
65 * @param pKeySpec the keySpec
66 * @param pMode the mode
67 * @param pPadding the padding
68 * @return the cipherSpec
69 */
70 default GordianSymCipherSpec symCipher(final GordianSymKeySpec pKeySpec,
71 final GordianCipherMode pMode,
72 final GordianPadding pPadding) {
73 return withKeySpec(pKeySpec).withMode(pMode).withPadding(pPadding).build();
74 }
75
76 /**
77 * Create an ECB symKey cipherSpec.
78 *
79 * @param pKeySpec the keySpec
80 * @param pPadding the padding
81 * @return the cipherSpec
82 */
83 default GordianSymCipherSpec ecb(final GordianSymKeySpec pKeySpec,
84 final GordianPadding pPadding) {
85 return withKeySpec(pKeySpec).withMode(GordianCipherMode.ECB).withPadding(pPadding).build();
86 }
87
88 /**
89 * Create a CBC symKey cipherSpec.
90 *
91 * @param pKeySpec the keySpec
92 * @param pPadding the padding
93 * @return the cipherSpec
94 */
95 default GordianSymCipherSpec cbc(final GordianSymKeySpec pKeySpec,
96 final GordianPadding pPadding) {
97 return withKeySpec(pKeySpec).withMode(GordianCipherMode.CBC).withPadding(pPadding).build();
98 }
99
100 /**
101 * Create a CFB symKey cipherSpec.
102 *
103 * @param pKeySpec the keySpec
104 * @return the cipherSpec
105 */
106 default GordianSymCipherSpec cfb(final GordianSymKeySpec pKeySpec) {
107 return withKeySpec(pKeySpec).withMode(GordianCipherMode.CFB).build();
108 }
109
110 /**
111 * Create a GCFB symKey cipherSpec.
112 *
113 * @param pKeySpec the keySpec
114 * @return the cipherSpec
115 */
116 default GordianSymCipherSpec gcfb(final GordianSymKeySpec pKeySpec) {
117 return withKeySpec(pKeySpec).withMode(GordianCipherMode.GCFB).build();
118 }
119
120 /**
121 * Create a OFB symKey cipherSpec.
122 *
123 * @param pKeySpec the keySpec
124 * @return the cipherSpec
125 */
126 default GordianSymCipherSpec ofb(final GordianSymKeySpec pKeySpec) {
127 return withKeySpec(pKeySpec).withMode(GordianCipherMode.OFB).build();
128 }
129
130 /**
131 * Create a GOFB symKey cipherSpec.
132 *
133 * @param pKeySpec the keySpec
134 * @return the cipherSpec
135 */
136 default GordianSymCipherSpec gofb(final GordianSymKeySpec pKeySpec) {
137 return withKeySpec(pKeySpec).withMode(GordianCipherMode.GOFB).build();
138 }
139
140 /**
141 * Create a SIC symKey cipherSpec.
142 *
143 * @param pKeySpec the keySpec
144 * @return the cipherSpec
145 */
146 default GordianSymCipherSpec sic(final GordianSymKeySpec pKeySpec) {
147 return withKeySpec(pKeySpec).withMode(GordianCipherMode.SIC).build();
148 }
149
150 /**
151 * Create a KCTR symKey cipherSpec.
152 *
153 * @param pKeySpec the keySpec
154 * @return the cipherSpec
155 */
156 default GordianSymCipherSpec kctr(final GordianSymKeySpec pKeySpec) {
157 return withKeySpec(pKeySpec).withMode(GordianCipherMode.KCTR).build();
158 }
159
160 /**
161 * Create a CCM symKey cipherSpec.
162 *
163 * @param pKeySpec the keySpec
164 * @return the cipherSpec
165 */
166 default GordianSymCipherSpec ccm(final GordianSymKeySpec pKeySpec) {
167 return withKeySpec(pKeySpec).withMode(GordianCipherMode.CCM).build();
168 }
169
170 /**
171 * Create a KCCM symKey cipherSpec.
172 *
173 * @param pKeySpec the keySpec
174 * @return the cipherSpec
175 */
176 default GordianSymCipherSpec kccm(final GordianSymKeySpec pKeySpec) {
177 return withKeySpec(pKeySpec).withMode(GordianCipherMode.KCCM).build();
178 }
179
180 /**
181 * Create a GCM symKey cipherSpec.
182 *
183 * @param pKeySpec the keySpec
184 * @return the cipherSpec
185 */
186 default GordianSymCipherSpec gcm(final GordianSymKeySpec pKeySpec) {
187 return withKeySpec(pKeySpec).withMode(GordianCipherMode.GCM).build();
188 }
189
190 /**
191 * Create a KGCM symKey cipherSpec.
192 *
193 * @param pKeySpec the keySpec
194 * @return the cipherSpec
195 */
196 default GordianSymCipherSpec kgcm(final GordianSymKeySpec pKeySpec) {
197 return withKeySpec(pKeySpec).withMode(GordianCipherMode.KGCM).build();
198 }
199
200 /**
201 * Create an EAX symKey cipherSpec.
202 *
203 * @param pKeySpec the keySpec
204 * @return the cipherSpec
205 */
206 default GordianSymCipherSpec eax(final GordianSymKeySpec pKeySpec) {
207 return withKeySpec(pKeySpec).withMode(GordianCipherMode.EAX).build();
208 }
209
210 /**
211 * Create an OCB symKey cipherSpec.
212 *
213 * @param pKeySpec the keySpec
214 * @return the cipherSpec
215 */
216 default GordianSymCipherSpec ocb(final GordianSymKeySpec pKeySpec) {
217 return withKeySpec(pKeySpec).withMode(GordianCipherMode.OCB).build();
218 }
219 }