• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without
7  * restriction, including without limitation the rights to use, copy,
8  * modify, merge, publish, distribute, sublicense, and/or sell copies
9  * of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
25 #ifndef ATAP_OPS_DELEGATE_H_
26 #define ATAP_OPS_DELEGATE_H_
27 
28 #include <libatap/libatap.h>
29 
30 namespace atap {
31 
32 // A delegate interface for ops callbacks.
33 //
34 // Implement this interface and use with AtapOpsProvider. The delegate will
35 // receive all calls to the AtapOps provided by AtapOpsProvider.
36 class AtapOpsDelegate {
37  public:
~AtapOpsDelegate()38   virtual ~AtapOpsDelegate() {}
39 
40   virtual AtapResult read_product_id(
41       uint8_t product_id[ATAP_PRODUCT_ID_LEN]) = 0;
42 
43   virtual AtapResult get_auth_key_type(AtapKeyType* key_type) = 0;
44 
45   virtual AtapResult read_auth_key_cert_chain(AtapCertChain* cert_chain) = 0;
46 
47   virtual AtapResult write_attestation_key(AtapKeyType key_type,
48                                            const AtapBlob* key,
49                                            const AtapCertChain* cert_chain) = 0;
50 
51   virtual AtapResult read_attestation_public_key(
52       AtapKeyType key_type,
53       uint8_t pubkey[ATAP_KEY_LEN_MAX],
54       uint32_t* pubkey_len) = 0;
55 
56   virtual AtapResult read_soc_global_key(
57       uint8_t global_key[ATAP_AES_128_KEY_LEN]) = 0;
58 
59   virtual AtapResult write_hex_uuid(const uint8_t uuid[ATAP_HEX_UUID_LEN]) = 0;
60 
61   virtual AtapResult get_random_bytes(uint8_t* buf, uint32_t buf_size) = 0;
62 
63   virtual AtapResult auth_key_sign(const uint8_t* nonce,
64                                    uint32_t nonce_len,
65                                    uint8_t sig[ATAP_SIGNATURE_LEN_MAX],
66                                    uint32_t* sig_len) = 0;
67 
68   virtual AtapResult ecdh_shared_secret_compute(
69       AtapCurveType curve,
70       const uint8_t other_public_key[ATAP_ECDH_KEY_LEN],
71       uint8_t public_key[ATAP_ECDH_KEY_LEN],
72       uint8_t shared_secret[ATAP_ECDH_KEY_LEN]) = 0;
73 
74   virtual AtapResult aes_gcm_128_encrypt(
75       const uint8_t* plaintext,
76       uint32_t len,
77       const uint8_t iv[ATAP_GCM_IV_LEN],
78       const uint8_t key[ATAP_AES_128_KEY_LEN],
79       uint8_t* ciphertext,
80       uint8_t tag[ATAP_GCM_TAG_LEN]) = 0;
81 
82   virtual AtapResult aes_gcm_128_decrypt(
83       const uint8_t* ciphertext,
84       uint32_t len,
85       const uint8_t iv[ATAP_GCM_IV_LEN],
86       const uint8_t key[ATAP_AES_128_KEY_LEN],
87       const uint8_t tag[ATAP_GCM_TAG_LEN],
88       uint8_t* plaintext) = 0;
89 
90   virtual AtapResult sha256(const uint8_t* plaintext,
91                             uint32_t plaintext_len,
92                             uint8_t hash[ATAP_SHA256_DIGEST_LEN]) = 0;
93 
94   virtual AtapResult hkdf_sha256(const uint8_t* salt,
95                                  uint32_t salt_len,
96                                  const uint8_t* ikm,
97                                  uint32_t ikm_len,
98                                  const uint8_t* info,
99                                  uint32_t info_len,
100                                  uint8_t* okm,
101                                  int32_t okm_len) = 0;
102 };
103 
104 }  // namespace atap
105 
106 #endif /* ATAP_OPS_DELEGATE_H_ */
107