18dffb485Schristos /* SHA-1 thunks. 2*12989c96Schristos Copyright (C) 2019-2024 Free Software Foundation, Inc. 38dffb485Schristos 48dffb485Schristos This file is part of libctf. 58dffb485Schristos 68dffb485Schristos libctf is free software; you can redistribute it and/or modify it under 78dffb485Schristos the terms of the GNU General Public License as published by the Free 88dffb485Schristos Software Foundation; either version 3, or (at your option) any later 98dffb485Schristos version. 108dffb485Schristos 118dffb485Schristos This program is distributed in the hope that it will be useful, but 128dffb485Schristos WITHOUT ANY WARRANTY; without even the implied warranty of 138dffb485Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 148dffb485Schristos See the GNU General Public License for more details. 158dffb485Schristos 168dffb485Schristos You should have received a copy of the GNU General Public License 178dffb485Schristos along with this program; see the file COPYING. If not see 188dffb485Schristos <http://www.gnu.org/licenses/>. */ 198dffb485Schristos 208dffb485Schristos #include <ctf-impl.h> 218dffb485Schristos #include <ctf-sha1.h> 228dffb485Schristos 238dffb485Schristos static const char hex[] = "0123456789abcdef"; 248dffb485Schristos 258dffb485Schristos char * 268dffb485Schristos ctf_sha1_fini (ctf_sha1_t *sha1, char *buf) 278dffb485Schristos { 288dffb485Schristos size_t i; 298dffb485Schristos 308dffb485Schristos /* Alignment suitable for a uint32_t. */ 318dffb485Schristos union 328dffb485Schristos { 338dffb485Schristos uint32_t align; 348dffb485Schristos unsigned char digest[((CTF_SHA1_SIZE - 1) / 2) + 1]; 358dffb485Schristos } align; 368dffb485Schristos 378dffb485Schristos sha1_finish_ctx (sha1, align.digest); 388dffb485Schristos 398dffb485Schristos if (!buf) 408dffb485Schristos return NULL; 418dffb485Schristos 428dffb485Schristos buf[CTF_SHA1_SIZE - 1] = '\0'; 438dffb485Schristos 448dffb485Schristos for (i = 0; i < (CTF_SHA1_SIZE - 1) / 2; i++) 458dffb485Schristos { 468dffb485Schristos buf[2 * i] = hex[align.digest[i] >> 4]; 478dffb485Schristos buf[2 * i + 1] = hex[align.digest[i] & 0xf]; 488dffb485Schristos } 498dffb485Schristos return buf; 508dffb485Schristos } 51