diff options
author | midipix <writeonce@midipix.org> | 2015-12-17 05:35:22 -0500 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2016-11-11 00:22:29 -0500 |
commit | c19325c2855fc29fcf05c57e537e14ec342b179c (patch) | |
tree | d5db31c5a6cdb685844f1c258db3572a2f647aa6 /src/crc | |
parent | cde03b7121400bd61167e8db5303b3cd0ff03a0c (diff) | |
download | mdso-c19325c2855fc29fcf05c57e537e14ec342b179c.tar.bz2 mdso-c19325c2855fc29fcf05c57e537e14ec342b179c.tar.xz |
added low-level crc interfaces.
Diffstat (limited to 'src/crc')
-rw-r--r-- | src/crc/mdso_crc32.c | 32 | ||||
-rw-r--r-- | src/crc/mdso_crc64.c | 32 |
2 files changed, 64 insertions, 0 deletions
diff --git a/src/crc/mdso_crc32.c b/src/crc/mdso_crc32.c new file mode 100644 index 0000000..1e3f6f6 --- /dev/null +++ b/src/crc/mdso_crc32.c @@ -0,0 +1,32 @@ +/****************************************************************/ +/* mdso: midipix dso scavenger */ +/* Copyright (C) 2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */ +/****************************************************************/ + +#include <stdint.h> +#include <unistd.h> + +#include <mdso/mdso.h> +#include <mdso/mdso_crc32.h> + +static const uint32_t crc32_table[256] = MDSO_CRC32_TABLE; + +uint32_t mdso_crc32_mbstr(const unsigned char * str, size_t * symlen) +{ + const unsigned char * ch; + uint32_t crc32; + + crc32 = 0 ^ 0xFFFFFFFF; + ch = str; + + while (*ch) { + crc32 = (crc32 >> 8) ^ crc32_table[(crc32 ^ *ch) & 0xFF]; + ch++; + } + + if (symlen) + *symlen = ch - str; + + return (crc32 ^ 0xFFFFFFFF); +} diff --git a/src/crc/mdso_crc64.c b/src/crc/mdso_crc64.c new file mode 100644 index 0000000..893b87d --- /dev/null +++ b/src/crc/mdso_crc64.c @@ -0,0 +1,32 @@ +/****************************************************************/ +/* mdso: midipix dso scavenger */ +/* Copyright (C) 2015 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */ +/****************************************************************/ + +#include <stdint.h> +#include <unistd.h> + +#include <mdso/mdso.h> +#include <mdso/mdso_crc64.h> + +static const uint64_t crc64_table[256] = MDSO_CRC64_TABLE; + +uint64_t mdso_crc64_mbstr(const unsigned char * str, size_t * symlen) +{ + const unsigned char * ch; + uint64_t crc64; + + crc64 = 0 ^ 0xFFFFFFFFFFFFFFFF; + ch = str; + + while (*ch) { + crc64 = (crc64 >> 8) ^ crc64_table[(crc64 ^ *ch) & 0xFF]; + ch++; + } + + if (symlen) + *symlen = ch - str; + + return (crc64 ^ 0xFFFFFFFFFFFFFFFF); +} |