blob: 4ba1bcee34744a730184a1aa3de8bb3ead8b5994 [file] [log] [blame]
Darren Krahn0762a2e2021-02-05 15:41:20 -08001// Copyright 2020 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
15#include "dice/utils.h"
16
17#include <stdint.h>
18
19void DiceHexEncode(const uint8_t* in, size_t num_bytes, void* out,
20 size_t out_size) {
21 const uint8_t kHexMap[16] = "0123456789abcdef";
22 size_t in_pos = 0;
23 size_t out_pos = 0;
24 uint8_t* out_bytes = out;
25 for (in_pos = 0; in_pos < num_bytes && out_pos < out_size; ++in_pos) {
26 out_bytes[out_pos++] = kHexMap[(in[in_pos] >> 4)];
27 if (out_pos < out_size) {
28 out_bytes[out_pos++] = kHexMap[in[in_pos] & 0xF];
29 }
30 }
31}