1 /*
2 * GordianKnot: Security Suite
3 * Copyright 2012-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 package io.github.tonywasher.joceanus.gordianknot.api.random;
18
19 import io.github.tonywasher.joceanus.gordianknot.api.base.GordianException;
20 import io.github.tonywasher.joceanus.gordianknot.api.base.GordianLength;
21 import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianStreamKeySpec;
22 import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianSymKeySpec;
23 import io.github.tonywasher.joceanus.gordianknot.api.digest.GordianDigest;
24 import io.github.tonywasher.joceanus.gordianknot.api.key.GordianKey;
25 import io.github.tonywasher.joceanus.gordianknot.api.mac.GordianMac;
26 import io.github.tonywasher.joceanus.gordianknot.api.random.spec.GordianRandomSpec;
27 import io.github.tonywasher.joceanus.gordianknot.api.random.spec.GordianRandomSpecBuilder;
28 import io.github.tonywasher.joceanus.gordianknot.api.random.spec.GordianRandomType;
29
30 import java.security.SecureRandom;
31 import java.util.List;
32 import java.util.function.BiPredicate;
33 import java.util.function.Predicate;
34
35 /**
36 * GordianKnot Random Factory API.
37 */
38 public interface GordianRandomFactory {
39 /**
40 * create SecureRandom.
41 *
42 * @param pRandomSpec the randomSpec
43 * @return the new SecureRandom
44 * @throws GordianException on error
45 */
46 SecureRandom createRandom(GordianRandomSpec pRandomSpec) throws GordianException;
47
48 /**
49 * create CombinedRandom.
50 *
51 * @param pCtrSpec the ctrRandomSpec
52 * @param pHashSpec the hashRandomSpec
53 * @return the new SecureRandom
54 * @throws GordianException on error
55 */
56 SecureRandom createRandom(GordianRandomSpec pCtrSpec,
57 GordianRandomSpec pHashSpec) throws GordianException;
58
59 /**
60 * create new GordianRandomSpecBuilder.
61 *
62 * @return the new RandomSpecBuilder
63 */
64 GordianRandomSpecBuilder newRandomSpecBuilder();
65
66 /**
67 * Obtain predicate for supported randomSpecs.
68 *
69 * @return the predicate
70 */
71 Predicate<GordianRandomSpec> supportedRandomSpecs();
72
73 /**
74 * Obtain predicate for supported combined randomSpecs.
75 *
76 * @return the predicate
77 */
78 BiPredicate<GordianRandomSpec, GordianRandomSpec> supportedCombinedSpecs();
79
80 /**
81 * generate random GordianDigest.
82 *
83 * @param pLargeData only generate a digest that is suitable for processing large amounts of data
84 * @return the new Digest
85 * @throws GordianException on error
86 */
87 GordianDigest generateRandomDigest(boolean pLargeData) throws GordianException;
88
89 /**
90 * generate random GordianMac.
91 *
92 * @param pKeyLen the keyLength
93 * @param pLargeData only generate a Mac that is suitable for parsing large amounts of data
94 * @return the new MAC
95 * @throws GordianException on error
96 */
97 GordianMac generateRandomMac(GordianLength pKeyLen,
98 boolean pLargeData) throws GordianException;
99
100 /**
101 * generate random SymKey.
102 *
103 * @param pKeyLen the keyLength
104 * @return the new key
105 * @throws GordianException on error
106 */
107 GordianKey<GordianSymKeySpec> generateRandomSymKey(GordianLength pKeyLen) throws GordianException;
108
109 /**
110 * generate random GordianStreamKey.
111 *
112 * @param pKeyLen the keyLength
113 * @param pLargeData only generate a Mac that is suitable for parsing large amounts of data
114 * @return the new StreamKey
115 * @throws GordianException on error
116 */
117 GordianKey<GordianStreamKeySpec> generateRandomStreamKey(GordianLength pKeyLen,
118 boolean pLargeData) throws GordianException;
119
120 /**
121 * Obtain a list of supported randomSpecs.
122 *
123 * @return the list of supported randomSpecs.
124 */
125 List<GordianRandomSpec> listAllSupportedRandomSpecs();
126
127 /**
128 * Obtain a list of supported randomSpecs of a given type.
129 *
130 * @param pType the random type
131 * @return the list of supported randomSpecs.
132 */
133 List<GordianRandomSpec> listAllSupportedRandomSpecs(GordianRandomType pType);
134
135 /**
136 * Obtain a list of supported randomSpecs of a given type and keyLength.
137 * <p>Only valid for CTR And X931 types</p>
138 *
139 * @param pType the random type
140 * @param pKeyLen the keyLength
141 * @return the list of supported randomSpecs.
142 */
143 List<GordianRandomSpec> listAllSupportedRandomSpecs(GordianRandomType pType,
144 GordianLength pKeyLen);
145 }