• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 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 #ifndef SYSTEM_KEYMASTER_KEM_H_
18 #define SYSTEM_KEYMASTER_KEM_H_
19 
20 #include <keymaster/serializable.h>
21 
22 #include <keymaster/km_openssl/openssl_utils.h>
23 
24 namespace keymaster {
25 
26 // Kem is an abstract class that provides an interface to a key encapsulation
27 // mechansim primitive. A key encapsulation mechanism works just like a
28 // public-key encryption scheme, except that the encryption algorithm takes no
29 // input other than the recipient’s public key. Instead, the encryption algorithm
30 // generates a pair (K, C0), where K is a bit string of some specified length,
31 // and C0 is an encryption of K, that is, the decryption algorithm applied to C0
32 // yields K.
33 class Kem {
34   public:
~Kem()35     virtual ~Kem(){};
36 
37     // For a key encapsulation mechanism, the goal of encryption is to take the recipient's public
38     // key, and to generate a pair (K, C0), where K is a bit string of some specified length,
39     // and C0 is an encryption of K.
40     virtual bool Encrypt(const Buffer& peer_public_value, Buffer* output_clear_key,
41                          Buffer* output_encrypted_key) = 0;
42     virtual bool Encrypt(const uint8_t* peer_public_value, size_t peer_public_value_len,
43                          Buffer* output_clear_key, Buffer* output_encrypted_key) = 0;
44 
45     // Decrypt takes an encrypted key, and outputs its clear text.
46     // Decrypt takes ownership of \p private_key.
47     virtual bool Decrypt(EC_KEY* private_key, const Buffer& encrypted_key, Buffer* output_key) = 0;
48     virtual bool Decrypt(EC_KEY* private_key, const uint8_t* encrypted_key,
49                          size_t encrypted_key_len, Buffer* output_key) = 0;
50 };
51 
52 }  // namespace keymaster
53 
54 #endif  // SYSTEM_KEYMASTER_KEM_H_
55