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.mac;
19  
20  import io.github.tonywasher.joceanus.gordianknot.api.key.GordianKey;
21  import io.github.tonywasher.joceanus.gordianknot.api.mac.spec.GordianMacSpec;
22  
23  /**
24   * MacParams Builder.
25   */
26  public interface GordianMacParamsBuilder {
27      /**
28       * Set the key.
29       *
30       * @param pKey the key
31       * @return the Builder
32       */
33      GordianMacParamsBuilder setKey(GordianKey<GordianMacSpec> pKey);
34  
35      /**
36       * Set the nonce.
37       *
38       * @param pNonce the nonce
39       * @return the Builder
40       */
41      GordianMacParamsBuilder setNonce(byte[] pNonce);
42  
43      /**
44       * Use random nonce.
45       *
46       * @return the Builder
47       */
48      GordianMacParamsBuilder withRandomNonce();
49  
50      /**
51       * Set the personalisation.
52       *
53       * @param pPersonal the personalisation
54       * @return the Builder
55       */
56      GordianMacParamsBuilder setPersonalisation(byte[] pPersonal);
57  
58      /**
59       * Set the output length.
60       *
61       * @param pOutLen the outputLen
62       * @return the Builder
63       */
64      GordianMacParamsBuilder setOutputLength(long pOutLen);
65  
66      /**
67       * Set the treeConfig.
68       *
69       * @param pFanOut   the fanout.
70       * @param pMaxDepth the maxDepth.
71       * @param pLeafLen  the leafLength.
72       * @return the Builder
73       */
74      GordianMacParamsBuilder setTreeConfig(int pFanOut,
75                                            int pMaxDepth,
76                                            int pLeafLen);
77  
78      /**
79       * Build the parameters.
80       *
81       * @return the parameters
82       */
83      GordianMacParams build();
84  
85      /**
86       * Generate keyOnly Parameters.
87       *
88       * @param pKey the key
89       * @return the macParameters
90       */
91      GordianMacParams key(GordianKey<GordianMacSpec> pKey);
92  
93      /**
94       * Obtain keyAndNonce Parameters.
95       *
96       * @param pKey   the key
97       * @param pNonce the nonce
98       * @return the macParameters
99       */
100     GordianMacParams keyAndNonce(GordianKey<GordianMacSpec> pKey,
101                                  byte[] pNonce);
102 
103     /**
104      * Obtain keyAndRandomNonce Parameters.
105      *
106      * @param pKey the key
107      * @return the macParameters
108      */
109     GordianMacParams keyWithRandomNonce(GordianKey<GordianMacSpec> pKey);
110 }