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.impl.ext.params;
18
19 import org.bouncycastle.crypto.CipherParameters;
20 import org.bouncycastle.util.Arrays;
21
22 /**
23 * Blake3 Parameters.
24 * Donated to BouncyCastle.
25 */
26 public class GordianBlake3Parameters
27 implements CipherParameters {
28 /**
29 * The key length.
30 */
31 private static final int KEYLEN = 32;
32
33 /**
34 * The key.
35 */
36 private byte[] theKey;
37
38 /**
39 * The context.
40 */
41 private byte[] theContext;
42
43 /**
44 * Create a key parameter.
45 *
46 * @param pContext the context
47 * @return the parameter
48 */
49 public static GordianBlake3Parameters context(final byte[] pContext) {
50 if (pContext == null) {
51 throw new IllegalArgumentException("Invalid context");
52 }
53 final GordianBlake3Parameters myParams = new GordianBlake3Parameters();
54 myParams.theContext = Arrays.clone(pContext);
55 return myParams;
56 }
57
58 /**
59 * Create a key parameter.
60 *
61 * @param pKey the key
62 * @return the parameter
63 */
64 public static GordianBlake3Parameters key(final byte[] pKey) {
65 if (pKey == null || pKey.length != KEYLEN) {
66 throw new IllegalArgumentException("Invalid keyLength");
67 }
68 final GordianBlake3Parameters myParams = new GordianBlake3Parameters();
69 myParams.theKey = Arrays.clone(pKey);
70 return myParams;
71 }
72
73 /**
74 * Obtain the key.
75 *
76 * @return the key
77 */
78 public byte[] getKey() {
79 return Arrays.clone(theKey);
80 }
81
82 /**
83 * Clear the key bytes.
84 */
85 public void clearKey() {
86 Arrays.fill(theKey, (byte) 0);
87 }
88
89 /**
90 * Obtain the salt.
91 *
92 * @return the salt
93 */
94 public byte[] getContext() {
95 return Arrays.clone(theContext);
96 }
97 }