From 93af56873184ab9ed9b17590da142eb4a90722d8 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Mon, 3 Aug 2020 13:02:41 +0200 Subject: Fixing sha1 by reversing bytes since it was designed for big endian --- src/utils.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/utils.c') diff --git a/src/utils.c b/src/utils.c index 2abadb6..db0c203 100644 --- a/src/utils.c +++ b/src/utils.c @@ -6,7 +6,7 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/08/01 15:00:16 by charles #+# #+# */ -/* Updated: 2020/08/01 19:24:41 by charles ### ########.fr */ +/* Updated: 2020/08/03 12:57:25 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,3 +41,31 @@ char *bytes_to_str(uint8_t *bytes, size_t size) } return (ret); } + +uint32_t reverse_bytes32(uint32_t x) +{ + return ( + (x & 0x000000ffu) << 24 | + (x & 0x0000ff00u) << 8 | + (x & 0x00ff0000u) >> 8 | + (x & 0xff000000u) >> 24 + ); +} + +/* +** from: +*/ + +uint64_t reverse_bytes64(uint64_t x) +{ + return ( + (x & 0x00000000000000ffull) << 56 | + (x & 0x000000000000ff00ull) << 40 | + (x & 0x0000000000ff0000ull) << 24 | + (x & 0x00000000ff000000ull) << 8 | + (x & 0x000000ff00000000ull) >> 8 | + (x & 0x0000ff0000000000ull) >> 24 | + (x & 0x00ff000000000000ull) >> 40 | + (x & 0xff00000000000000ull) >> 56 + ); +} -- cgit