1 /******************************************************************************
2  *
3  *  The original Work has been changed by NXP.
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy 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,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *  Copyright 2022-2023 NXP
18  *
19  ******************************************************************************/
20 #pragma once
21 
22 #include "CborConverter.h"
23 #include "JavacardSecureElement.h"
24 
25 #include <aidl/android/hardware/security/sharedsecret/BnSharedSecret.h>
26 #include <aidl/android/hardware/security/sharedsecret/SharedSecretParameters.h>
27 #include <memory>
28 #include <vector>
29 
30 namespace aidl::android::hardware::security::sharedsecret {
31 using ::keymint::javacard::CborConverter;
32 using ::keymint::javacard::JavacardSecureElement;
33 using ndk::ScopedAStatus;
34 using std::optional;
35 using std::shared_ptr;
36 using std::vector;
37 
38 class JavacardSharedSecret : public BnSharedSecret {
39   public:
JavacardSharedSecret(shared_ptr<JavacardSecureElement> card)40     explicit JavacardSharedSecret(shared_ptr<JavacardSecureElement> card)
41         : card_(std::move(card)) {}
~JavacardSharedSecret()42     virtual ~JavacardSharedSecret() {}
43 
44     // Methods from ::ndk::ICInterface follow.
45     binder_status_t dump(int fd, const char** args, uint32_t num_args) override;
46 
47     ScopedAStatus getSharedSecretParameters(SharedSecretParameters* params) override;
48 
49     ScopedAStatus computeSharedSecret(const std::vector<SharedSecretParameters>& params,
50                                       std::vector<uint8_t>* secret) override;
51 
52   private:
53     shared_ptr<JavacardSecureElement> card_;
54     CborConverter cbor_;
55 };
56 
57 }  // namespace aidl::android::hardware::security::sharedsecret
58