blob: e04f7d57200a40f2cb9c145662e5fbb3e15c017c [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 Crowley0080bde2019-12-23 12:00:28 -080034constexpr auto KEY_CODEWORD_BYTES = 2u; // uint16_t (after transpose)
35constexpr auto KEY_CODEWORDS = KEY_CODEWORD_BYTES * BYTE_LENGTH;
Paul Crowleyc675b182019-12-18 16:09:24 -080036constexpr auto KEY_SIZE_IN_BYTES = KEY_CODEWORDS * CODEWORD_BYTES;
Paul Crowley0080bde2019-12-23 12:00:28 -080037constexpr auto OUTPUT_SIZE_BYTES = ENCODE_LENGTH * KEY_CODEWORD_BYTES;
Tianjie Xua0a12cf2019-12-05 21:50:22 -080038
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.
41std::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.
44std::vector<uint8_t> DecodeKey(const std::vector<uint8_t>& encoded);
45
Tianjie Xua0a12cf2019-12-05 21:50:22 -080046} // namespace hadamard
47} // namespace rebootescrow
48} // namespace hardware
49} // namespace android
50} // namespace aidl