• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.adservices.ohttp.algorithms;
18 
19 import com.android.adservices.ohttp.ObliviousHttpKeyConfig;
20 
21 import com.google.auto.value.AutoValue;
22 
23 /**
24  * Holds the HPKE cipher suite supported by the {@link
25  * com.android.adservices.ohttp.ObliviousHttpClient}
26  */
27 @AutoValue
28 public abstract class HpkeAlgorithmSpec {
29     /** Get the KEM algorithm from this HPKE algorithm suite */
kem()30     public abstract KemAlgorithmSpec kem();
31 
32     /** Get the KDF algorithm from this HPKE algorithm suite */
kdf()33     public abstract KdfAlgorithmSpec kdf();
34 
35     /** Get the AEAD algorithm from this HPKE algorithm suite */
aead()36     public abstract AeadAlgorithmSpec aead();
37 
create( KemAlgorithmSpec kem, KdfAlgorithmSpec kdf, AeadAlgorithmSpec aead)38     private static HpkeAlgorithmSpec create(
39             KemAlgorithmSpec kem, KdfAlgorithmSpec kdf, AeadAlgorithmSpec aead) {
40         return new AutoValue_HpkeAlgorithmSpec(kem, kdf, aead);
41     }
42 
43     /**
44      * Create a {@link HpkeAlgorithmSpec} from the keyConfig and throw {@link
45      * UnsupportedHpkeAlgorithmException} if any of the algorithms are not supported
46      */
fromKeyConfig(ObliviousHttpKeyConfig obliviousHttpKeyConfig)47     public static HpkeAlgorithmSpec fromKeyConfig(ObliviousHttpKeyConfig obliviousHttpKeyConfig)
48             throws UnsupportedHpkeAlgorithmException {
49         KemAlgorithmSpec kem = KemAlgorithmSpec.get(obliviousHttpKeyConfig.kemId());
50         KdfAlgorithmSpec kdf = KdfAlgorithmSpec.get(obliviousHttpKeyConfig.kdfId());
51         AeadAlgorithmSpec aead = AeadAlgorithmSpec.get(obliviousHttpKeyConfig.aeadId());
52         return create(kem, kdf, aead);
53     }
54 }
55