Keith Mok | 690919a | 2023-04-12 15:44:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 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 | #pragma once |
| 18 | |
| 19 | #include <aidl/android/hardware/macsec/BnMacsecPskPlugin.h> |
| 20 | |
| 21 | #include <openssl/aes.h> |
| 22 | #include <openssl/cmac.h> |
| 23 | |
| 24 | namespace aidl::android::hardware::macsec { |
| 25 | |
| 26 | struct keys { |
| 27 | std::vector<uint8_t> keyId; |
| 28 | AES_KEY kekEncCtx; |
| 29 | AES_KEY kekDecCtx; |
| 30 | CMAC_CTX* ickCtx; |
| 31 | CMAC_CTX* cakCtx; |
| 32 | }; |
| 33 | |
| 34 | class MacsecPskPlugin : public BnMacsecPskPlugin { |
| 35 | public: |
| 36 | MacsecPskPlugin(); |
| 37 | ~MacsecPskPlugin(); |
| 38 | ndk::ScopedAStatus addTestKey(const std::vector<uint8_t>& keyId, |
| 39 | const std::vector<uint8_t>& CAK, |
| 40 | const std::vector<uint8_t>& CKN) override; |
| 41 | ndk::ScopedAStatus calcIcv(const std::vector<uint8_t>& keyId, const std::vector<uint8_t>& data, |
| 42 | std::vector<uint8_t>* out) override; |
| 43 | |
| 44 | ndk::ScopedAStatus generateSak(const std::vector<uint8_t>& keyId, |
| 45 | const std::vector<uint8_t>& data, const int sakLength, |
| 46 | std::vector<uint8_t>* out); |
| 47 | |
| 48 | ndk::ScopedAStatus wrapSak(const std::vector<uint8_t>& keyId, const std::vector<uint8_t>& sak, |
| 49 | std::vector<uint8_t>* out) override; |
| 50 | |
| 51 | ndk::ScopedAStatus unwrapSak(const std::vector<uint8_t>& keyId, const std::vector<uint8_t>& sak, |
| 52 | std::vector<uint8_t>* out) override; |
| 53 | |
| 54 | private: |
| 55 | std::vector<struct keys> mKeys; |
| 56 | }; |
| 57 | } // namespace aidl::android::hardware::macsec |