Tianjie Xu | a0a12cf | 2019-12-05 21:50:22 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 <stdint.h> |
| 20 | |
Tianjie Xu | a0a12cf | 2019-12-05 21:50:22 -0800 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
| 23 | namespace aidl { |
| 24 | namespace android { |
| 25 | namespace hardware { |
| 26 | namespace rebootescrow { |
| 27 | namespace hadamard { |
| 28 | |
Paul Crowley | c675b18 | 2019-12-18 16:09:24 -0800 | [diff] [blame] | 29 | constexpr auto BYTE_LENGTH = 8u; |
| 30 | constexpr auto CODEWORD_BYTES = 2u; // uint16_t |
| 31 | constexpr auto CODEWORD_BITS = CODEWORD_BYTES * BYTE_LENGTH; |
| 32 | constexpr uint32_t CODE_K = CODEWORD_BITS - 1; |
Tianjie Xu | a0a12cf | 2019-12-05 21:50:22 -0800 | [diff] [blame] | 33 | constexpr uint32_t ENCODE_LENGTH = 1u << CODE_K; |
Paul Crowley | 0080bde | 2019-12-23 12:00:28 -0800 | [diff] [blame] | 34 | constexpr auto KEY_CODEWORD_BYTES = 2u; // uint16_t (after transpose) |
| 35 | constexpr auto KEY_CODEWORDS = KEY_CODEWORD_BYTES * BYTE_LENGTH; |
Paul Crowley | c675b18 | 2019-12-18 16:09:24 -0800 | [diff] [blame] | 36 | constexpr auto KEY_SIZE_IN_BYTES = KEY_CODEWORDS * CODEWORD_BYTES; |
Paul Crowley | 0080bde | 2019-12-23 12:00:28 -0800 | [diff] [blame] | 37 | constexpr auto OUTPUT_SIZE_BYTES = ENCODE_LENGTH * KEY_CODEWORD_BYTES; |
Tianjie Xu | a0a12cf | 2019-12-05 21:50:22 -0800 | [diff] [blame] | 38 | |
| 39 | // Encodes a key that has a size of KEY_SIZE_IN_BYTES. Returns a byte array representation of the |
| 40 | // encoded bitset. So a 32 bytes key will expand to 16*(2^15) bits = 64KiB. |
| 41 | std::vector<uint8_t> EncodeKey(const std::vector<uint8_t>& input); |
| 42 | |
| 43 | // Given a byte array representation of the encoded keys, decodes it and return the result. |
| 44 | std::vector<uint8_t> DecodeKey(const std::vector<uint8_t>& encoded); |
| 45 | |
Tianjie Xu | a0a12cf | 2019-12-05 21:50:22 -0800 | [diff] [blame] | 46 | } // namespace hadamard |
| 47 | } // namespace rebootescrow |
| 48 | } // namespace hardware |
| 49 | } // namespace android |
| 50 | } // namespace aidl |