1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.cobalt.crypto;
18 
19 import static java.nio.charset.StandardCharsets.UTF_8;
20 
21 /**
22  * Container for static keys/key data used in {@link HpkeEncrypter}.
23  *
24  * <p>The keys contain the raw key bytes extracted from Tink public keys as decimal values. Tink
25  * public key can be obtained with the Keyset API GetPublicKeysetHandle() and WriteNoSecret. Raw key
26  * material can be extracted from the Tink internal structure, hpke.proto which can be parsed from
27  * key data stored in Tink public key.
28  *
29  * <p>This output can be generated by doing something like: <code>
30  * StringBuilder sb = new StringBuilder();
31  * sb.append("new byte[] {");
32  * for (byte b : key.getSerializedKey().toByteArray()) {
33  *   sb.append(b).append(", ");
34  * }
35  * sb.setLength(sb.length() - 2);
36  * sb.append("};");
37  * </code>
38  */
39 final class PublicKeys {
40     static final int X25519_PUBLIC_VALUE_LEN = 32;
41 
42     static final byte[] SHUFFLER_KEY_PROD =
43             new byte[] {
44                 -111, -111, 86, 123, -6, -114, -109, 121, -84, -113, -92, -5, 50, 103, 22, -53, 103,
45                 -57, 97, 11, 80, -5, 105, -26, -122, 106, 65, 107, -32, -74, -23, 10
46             };
47     static final int SHUFFLER_KEY_INDEX_PROD = 11;
48 
49     static final byte[] SHUFFLER_KEY_DEV =
50             new byte[] {
51                 -90, -73, 32, -62, 119, -72, 48, -40, -127, -103, -7, -58, 35, -88, -4, 45, 33, 21,
52                 32, 48, 42, 43, 89, 33, -43, -81, -64, 111, 118, 76, 77, 32
53             };
54     static final int SHUFFLER_KEY_INDEX_DEV = 9;
55     static final byte[] SHUFFLER_CONTEXT_INFO_BYTES = "cobalt-1.0-shuffler".getBytes(UTF_8);
56 
57     static final byte[] ANALYZER_KEY_PROD =
58             new byte[] {
59                 75, -121, 55, -37, -24, -80, -119, -113, -64, 25, -91, 114, -56, -23, 108, 5, 90,
60                 -3, 24, -62, 1, 109, 51, 123, -88, 36, 36, 0, 51, 104, -37, 1
61             };
62     static final int ANALYZER_KEY_INDEX_PROD = 12;
63     static final byte[] ANALYZER_KEY_DEV =
64             new byte[] {
65                 -5, -81, 123, 9, -16, -83, -75, -106, 122, -13, 111, -106, 123, -65, -7, -78, 125,
66                 107, -23, 69, 120, -59, 40, 19, 6, 92, -119, 6, -58, 126, 125, 41
67             };
68     static final int ANALYZER_KEY_INDEX_DEV = 10;
69     static final byte[] ANALYZER_CONTEXT_INFO_BYTES = "cobalt-1.0-analyzer".getBytes(UTF_8);
70 }
71