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