blob: 85e635f2de6c966f43ff665b64e0582e96f61f21 [file] [log] [blame]
Tianjie Xua0a12cf2019-12-05 21:50:22 -08001/*
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 Xua0a12cf2019-12-05 21:50:22 -080021#include <vector>
22
23namespace aidl {
24namespace android {
25namespace hardware {
26namespace rebootescrow {
27namespace hadamard {
28
Paul Crowleyc675b182019-12-18 16:09:24 -080029constexpr auto BYTE_LENGTH = 8u;
30constexpr auto CODEWORD_BYTES = 2u; // uint16_t
31constexpr auto CODEWORD_BITS = CODEWORD_BYTES * BYTE_LENGTH;
32constexpr uint32_t CODE_K = CODEWORD_BITS - 1;
Tianjie Xua0a12cf2019-12-05 21:50:22 -080033constexpr uint32_t ENCODE_LENGTH = 1u << CODE_K;
Paul Crowleyc675b182019-12-18 16:09:24 -080034constexpr auto KEY_CODEWORDS = 16u;
35constexpr auto KEY_SIZE_IN_BYTES = KEY_CODEWORDS * CODEWORD_BYTES;
36constexpr auto OUTPUT_SIZE_BYTES = KEY_CODEWORDS * ENCODE_LENGTH / BYTE_LENGTH;
Tianjie Xua0a12cf2019-12-05 21:50:22 -080037
38// Encodes a key that has a size of KEY_SIZE_IN_BYTES. Returns a byte array representation of the
39// encoded bitset. So a 32 bytes key will expand to 16*(2^15) bits = 64KiB.
40std::vector<uint8_t> EncodeKey(const std::vector<uint8_t>& input);
41
42// Given a byte array representation of the encoded keys, decodes it and return the result.
43std::vector<uint8_t> DecodeKey(const std::vector<uint8_t>& encoded);
44
Tianjie Xua0a12cf2019-12-05 21:50:22 -080045} // namespace hadamard
46} // namespace rebootescrow
47} // namespace hardware
48} // namespace android
49} // namespace aidl