17d62b00eSchristos /* SHA-1 thunks. 2*6881a400Schristos Copyright (C) 2019-2022 Free Software Foundation, Inc. 37d62b00eSchristos 47d62b00eSchristos This file is part of libctf. 57d62b00eSchristos 67d62b00eSchristos libctf is free software; you can redistribute it and/or modify it under 77d62b00eSchristos the terms of the GNU General Public License as published by the Free 87d62b00eSchristos Software Foundation; either version 3, or (at your option) any later 97d62b00eSchristos version. 107d62b00eSchristos 117d62b00eSchristos This program is distributed in the hope that it will be useful, but 127d62b00eSchristos WITHOUT ANY WARRANTY; without even the implied warranty of 137d62b00eSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 147d62b00eSchristos See the GNU General Public License for more details. 157d62b00eSchristos 167d62b00eSchristos You should have received a copy of the GNU General Public License 177d62b00eSchristos along with this program; see the file COPYING. If not see 187d62b00eSchristos <http://www.gnu.org/licenses/>. */ 197d62b00eSchristos 207d62b00eSchristos #include <ctf-impl.h> 217d62b00eSchristos #include <ctf-sha1.h> 227d62b00eSchristos 237d62b00eSchristos static const char hex[] = "0123456789abcdef"; 247d62b00eSchristos 257d62b00eSchristos char * 267d62b00eSchristos ctf_sha1_fini (ctf_sha1_t *sha1, char *buf) 277d62b00eSchristos { 287d62b00eSchristos size_t i; 297d62b00eSchristos 307d62b00eSchristos /* Alignment suitable for a uint32_t. */ 317d62b00eSchristos union 327d62b00eSchristos { 337d62b00eSchristos uint32_t align; 347d62b00eSchristos unsigned char digest[((CTF_SHA1_SIZE - 1) / 2) + 1]; 357d62b00eSchristos } align; 367d62b00eSchristos 377d62b00eSchristos sha1_finish_ctx (sha1, align.digest); 387d62b00eSchristos 397d62b00eSchristos if (!buf) 407d62b00eSchristos return NULL; 417d62b00eSchristos 427d62b00eSchristos buf[CTF_SHA1_SIZE - 1] = '\0'; 437d62b00eSchristos 447d62b00eSchristos for (i = 0; i < (CTF_SHA1_SIZE - 1) / 2; i++) 457d62b00eSchristos { 467d62b00eSchristos buf[2 * i] = hex[align.digest[i] >> 4]; 477d62b00eSchristos buf[2 * i + 1] = hex[align.digest[i] & 0xf]; 487d62b00eSchristos } 497d62b00eSchristos return buf; 507d62b00eSchristos } 51