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.random.spec;
19
20 import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianSymKeySpec;
21 import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianSymKeySpecBuilder;
22 import io.github.tonywasher.joceanus.gordianknot.api.digest.spec.GordianDigestSpec;
23 import io.github.tonywasher.joceanus.gordianknot.api.digest.spec.GordianDigestSpecBuilder;
24
25 /**
26 * SecureRandom Specification Builder.
27 */
28 public interface GordianRandomSpecBuilder {
29 /**
30 * Define RandomType.
31 *
32 * @param pType the type
33 * @return the Builder
34 */
35 GordianRandomSpecBuilder withType(GordianRandomType pType);
36
37 /**
38 * Define digestSubSpec.
39 *
40 * @param pDigestSpec the digest subSpec
41 * @return the Builder
42 */
43 GordianRandomSpecBuilder withDigestSubSpec(GordianDigestSpec pDigestSpec);
44
45 /**
46 * Define symKeySubSpec.
47 *
48 * @param pSymKeySpec the symKeySpec subSpec
49 * @return the Builder
50 */
51 GordianRandomSpecBuilder withSymKeySubSpec(GordianSymKeySpec pSymKeySpec);
52
53 /**
54 * Use resistance.
55 *
56 * @return the Builder
57 */
58 GordianRandomSpecBuilder withResistance();
59
60 /**
61 * Access digestSpecBuilder.
62 *
63 * @return the digestSpec builder
64 */
65 GordianDigestSpecBuilder usingDigestSpecBuilder();
66
67 /**
68 * Access symKeySpecBuilder.
69 *
70 * @return the symKeySpec builder
71 */
72 GordianSymKeySpecBuilder usingSymKeySpecBuilder();
73
74 /**
75 * Build randomSpec.
76 *
77 * @return the randomSpec
78 */
79 GordianRandomSpec build();
80
81 /**
82 * Create hashSpec.
83 *
84 * @param pDigest the digestSpec
85 * @return the RandomSpec
86 */
87 default GordianRandomSpec hash(final GordianDigestSpec pDigest) {
88 return withType(GordianRandomType.HASH).withDigestSubSpec(pDigest).build();
89 }
90
91 /**
92 * Create prediction resistant hashSpec.
93 *
94 * @param pDigest the digestSpec
95 * @return the RandomSpec
96 */
97 default GordianRandomSpec hashResist(final GordianDigestSpec pDigest) {
98 return withType(GordianRandomType.HASH).withDigestSubSpec(pDigest).withResistance().build();
99 }
100
101 /**
102 * Create hMacSpec.
103 *
104 * @param pDigest the digestSpec
105 * @return the RandomSpec
106 */
107 default GordianRandomSpec hMac(final GordianDigestSpec pDigest) {
108 return withType(GordianRandomType.HMAC).withDigestSubSpec(pDigest).build();
109 }
110
111 /**
112 * Create prediction resistant hMacSpec.
113 *
114 * @param pDigest the digestSpec
115 * @return the RandomSpec
116 */
117 default GordianRandomSpec hMacResist(final GordianDigestSpec pDigest) {
118 return withType(GordianRandomType.HMAC).withDigestSubSpec(pDigest).withResistance().build();
119 }
120
121 /**
122 * Create ctrSpec.
123 *
124 * @param pSymKeySpec the symKeySpec
125 * @return the RandomSpec
126 */
127 default GordianRandomSpec ctr(final GordianSymKeySpec pSymKeySpec) {
128 return withType(GordianRandomType.CTR).withSymKeySubSpec(pSymKeySpec).build();
129 }
130
131 /**
132 * Create prediction resistant ctrSpec.
133 *
134 * @param pSymKeySpec the symKeySpec
135 * @return the RandomSpec
136 */
137 default GordianRandomSpec ctrResist(final GordianSymKeySpec pSymKeySpec) {
138 return withType(GordianRandomType.CTR).withSymKeySubSpec(pSymKeySpec).withResistance().build();
139 }
140
141 /**
142 * Create x931Spec.
143 *
144 * @param pSymKeySpec the symKeySpec
145 * @return the RandomSpec
146 */
147 default GordianRandomSpec x931(final GordianSymKeySpec pSymKeySpec) {
148 return withType(GordianRandomType.X931).withSymKeySubSpec(pSymKeySpec).build();
149 }
150
151 /**
152 * Create prediction resistant x931Spec.
153 *
154 * @param pSymKeySpec the symKeySpec
155 * @return the RandomSpec
156 */
157 default GordianRandomSpec x931Resist(final GordianSymKeySpec pSymKeySpec) {
158 return withType(GordianRandomType.X931).withSymKeySubSpec(pSymKeySpec).withResistance().build();
159 }
160 }