diff --git a/include/cryb/hash.h b/include/cryb/hash.h index ff294fa..f1103ad 100644 --- a/include/cryb/hash.h +++ b/include/cryb/hash.h @@ -42,6 +42,12 @@ const char *cryb_hash_version(void); #define fletcher16_hash cryb_fletcher16_hash #define fletcher32_hash cryb_fletcher32_hash #define fletcher64_hash cryb_fletcher64_hash +#define fnv0_32_hash cryb_fnv0_32_hash +#define fnv0_64_hash cryb_fnv0_64_hash +#define fnv1_32_hash cryb_fnv1_32_hash +#define fnv1_64_hash cryb_fnv1_64_hash +#define fnv1a_32_hash cryb_fnv1a_32_hash +#define fnv1a_64_hash cryb_fnv1a_64_hash #define murmur3_32_hash cryb_murmur3_32_hash #define pearson_hash cryb_pearson_hash #define pearson_hash_str cryb_pearson_hash_str @@ -50,6 +56,12 @@ uint32_t adler32_hash(const void *, size_t); uint16_t fletcher16_hash(const void *, size_t); uint32_t fletcher32_hash(const void *, size_t); uint64_t fletcher64_hash(const void *, size_t); +uint32_t fnv0_32_hash(const void *, size_t); +uint64_t fnv0_64_hash(const void *, size_t); +uint32_t fnv1_32_hash(const void *, size_t); +uint64_t fnv1_64_hash(const void *, size_t); +uint32_t fnv1a_32_hash(const void *, size_t); +uint64_t fnv1a_64_hash(const void *, size_t); uint32_t murmur3_32_hash(const void *, size_t, uint32_t); uint8_t pearson_hash(const void *, size_t); uint8_t pearson_hash_str(const char *); diff --git a/lib/digest/Makefile.am b/lib/digest/Makefile.am index a0d4c25..86e5cb0 100644 --- a/lib/digest/Makefile.am +++ b/lib/digest/Makefile.am @@ -15,11 +15,16 @@ libcryb_digest_la_SOURCES = \ cryb_digest.c dist_man3_MANS = \ + cryb_md2.3 \ + cryb_md4.3 \ + cryb_md5.3 \ cryb_sha1.3 \ cryb_sha224.3 \ cryb_sha256.3 \ cryb_sha384.3 \ - cryb_sha512.3 + cryb_sha512.3 \ + \ + cryb_digest.3 libcryb_digest_la_CFLAGS = \ $(CRYB_CORE_CFLAGS) diff --git a/lib/digest/cryb_digest.3 b/lib/digest/cryb_digest.3 new file mode 100644 index 0000000..e34a393 --- /dev/null +++ b/lib/digest/cryb_digest.3 @@ -0,0 +1,70 @@ +.\"- +.\" Copyright (c) 2022 Dag-Erling Smørgrav +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd May 15, 2022 +.Dt CRYB_DIGEST 3 +.Os +.Sh NAME +.Nm cryb_digest_version +.Nd cryptographic message digest library +.Sh LIBRARY +.Lb libcryb-digest +.Sh SYNOPSIS +.In stddef.h +.In stdint.h +.In cryb/digest.h +.Ft const char * +.Fn cryb_digest_version "void" +.Sh DESCRIPTION +The +.Fn cryb_digest_version +function returns a pointer to a string containing the specific version +of the +.Lb libcryb-digest +library. +.Pp +For descriptions of the other functions in this library, see their +respective manual pages. +.Sh SEE ALSO +.Xr cryb_md2 3 , +.Xr cryb_md4 3 , +.Xr cryb_md5 3 , +.Xr cryb_sha1 3 , +.Xr cryb_sha224 3 , +.Xr cryb_sha256 3 , +.Xr cryb_sha384 3 , +.Xr cryb_sha512 3 +.Sh AUTHORS +.An -nosplit +The +.Fn cryb_digest_version +function was written for the University of Oslo by +.An Dag-Erling Sm\(/orgrav Aq Mt d.e.smorgrav@usit.uio.no . +.Pp +This manual page was written by +.An Dag-Erling Sm\(/orgrav Aq Mt des@des.no . diff --git a/lib/digest/cryb_md2.3 b/lib/digest/cryb_md2.3 new file mode 100644 index 0000000..10b93bf --- /dev/null +++ b/lib/digest/cryb_md2.3 @@ -0,0 +1,125 @@ +.\"- +.\" Copyright (c) 2022 Dag-Erling Smørgrav +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd May 15, 2022 +.Dt CRYB_MD2 3 +.Os +.Sh NAME +.Nm cryb_md2_init , +.Nm cryb_md2_update , +.Nm cryb_md2_final , +.Nm cryb_md2_complete +.Nd Message-Digest Algorithm 2 +.Sh LIBRARY +.Lb libcryb-digest +.Sh SYNOPSIS +.In stddef.h +.In stdint.h +.In cryb/md2.h +.Ft void +.Fn cryb_md2_init "cryb_md2_ctx *context" +.Ft void +.Fn cryb_md2_update "cryb_md2_ctx *context" "const void *data" "size_t len" +.Ft void +.Fn cryb_md2_final "cryb_md2_ctx *context" "uint8_t *digest" +.Ft void +.Fn cryb_md2_complete "const void *data" "size_t len" "uint8_t *digest" +.Sh DESCRIPTION +The +.Nm cryb_md2 +family of functions implements the MD2 message digest algorithm as +described in RFC 1319. +.Pp +The +.Fn cryb_md2_init +function initializes the context structure pointed to by +.Va context . +It is the caller's responsibility to allocate this structure. +.Pp +The +.Fn cryb_md2_update +function hashes the next +.Va len +bytes of data pointed to by the +.Va data +pointer into the given hash context. +.Pp +The +.Fn cryb_md2_final +function finalizes the computation and writes the resulting message +digest to the caller-provided buffer pointed to by +.Va digest , +which must be at least +.Dv MD2_DIGEST_LEN +bytes long. +It is the caller's responsibility to dispose of the context structure +after calling +.Fn cryb_md2_final . +.Pp +The +.Fn cryb_md2_complete +function is a shortcut to calling +.Fn cryb_md2_init , +.Fn cryb_md2_update , +and +.Fn cryb_md2_final +when the entire message is available up front in a single contiguous +buffer. +.Sh IMPLEMENTATION NOTES +The +.In cryb/md2.h +header provides macros which allows these functions and the context +type to be referred to without their +.Dq Li cryb_ +prefix. +.Pp +The MD2 message digest algorithm has been proven to be vulnerable to +collision attacks and should not be used for cryptographic purposes. +.Sh SEE ALSO +.Xr cryb_digest 3 , +.Xr cryb_md4 3 , +.Xr cryb_md5 3 +.Sh REFERENCES +.Rs +.%A Kaliski, Burton S. +.%T The MD2 Message-Digest Algorithm +.%D April 1992 +.%O RFC 1319 +.%U https://datatracker.ietf.org/doc/html/rfc1319 +.Re +.Rs +.%A Turner, Sean +.%A Chen, Lily +.%T MD2 to Historic Status +.%D March 2011 +.%O RFC 6149 +.%U https://datatracker.ietf.org/doc/html/rfc6149 +.Re +.Sh AUTHORS +These functions and this manual page were written by +.An Dag-Erling Sm\(/orgrav Aq Mt des@des.no . diff --git a/lib/digest/cryb_md4.3 b/lib/digest/cryb_md4.3 new file mode 100644 index 0000000..83e185a --- /dev/null +++ b/lib/digest/cryb_md4.3 @@ -0,0 +1,125 @@ +.\"- +.\" Copyright (c) 2022 Dag-Erling Smørgrav +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd May 15, 2022 +.Dt CRYB_MD4 3 +.Os +.Sh NAME +.Nm cryb_md4_init , +.Nm cryb_md4_update , +.Nm cryb_md4_final , +.Nm cryb_md4_complete +.Nd Message-Digest Algorithm 2 +.Sh LIBRARY +.Lb libcryb-digest +.Sh SYNOPSIS +.In stddef.h +.In stdint.h +.In cryb/md4.h +.Ft void +.Fn cryb_md4_init "cryb_md4_ctx *context" +.Ft void +.Fn cryb_md4_update "cryb_md4_ctx *context" "const void *data" "size_t len" +.Ft void +.Fn cryb_md4_final "cryb_md4_ctx *context" "uint8_t *digest" +.Ft void +.Fn cryb_md4_complete "const void *data" "size_t len" "uint8_t *digest" +.Sh DESCRIPTION +The +.Nm cryb_md4 +family of functions implements the MD4 message digest algorithm as +described in RFC 1320. +.Pp +The +.Fn cryb_md4_init +function initializes the context structure pointed to by +.Va context . +It is the caller's responsibility to allocate this structure. +.Pp +The +.Fn cryb_md4_update +function hashes the next +.Va len +bytes of data pointed to by the +.Va data +pointer into the given hash context. +.Pp +The +.Fn cryb_md4_final +function finalizes the computation and writes the resulting message +digest to the caller-provided buffer pointed to by +.Va digest , +which must be at least +.Dv MD4_DIGEST_LEN +bytes long. +It is the caller's responsibility to dispose of the context structure +after calling +.Fn cryb_md4_final . +.Pp +The +.Fn cryb_md4_complete +function is a shortcut to calling +.Fn cryb_md4_init , +.Fn cryb_md4_update , +and +.Fn cryb_md4_final +when the entire message is available up front in a single contiguous +buffer. +.Sh IMPLEMENTATION NOTES +The +.In cryb/md4.h +header provides macros which allows these functions and the context +type to be referred to without their +.Dq Li cryb_ +prefix. +.Pp +The MD4 message digest algorithm has been proven to be vulnerable to +collision attacks and should not be used for cryptographic purposes. +.Sh SEE ALSO +.Xr cryb_digest 3 , +.Xr cryb_md2 3 , +.Xr cryb_md5 3 +.Sh REFERENCES +.Rs +.%A Rivest, Ronald +.%T The MD4 Message-Digest Algorithm +.%D April 1992 +.%O RFC 1320 +.%U https://datatracker.ietf.org/doc/html/rfc1320 +.Re +.Rs +.%A Turner, Sean +.%A Chen, Lily +.%T MD4 to Historic Status +.%D March 2011 +.%O RFC 6150 +.%U https://datatracker.ietf.org/doc/html/rfc6150 +.Re +.Sh AUTHORS +These functions and this manual page were written by +.An Dag-Erling Sm\(/orgrav Aq Mt des@des.no . diff --git a/lib/digest/cryb_md5.3 b/lib/digest/cryb_md5.3 new file mode 100644 index 0000000..f75d332 --- /dev/null +++ b/lib/digest/cryb_md5.3 @@ -0,0 +1,125 @@ +.\"- +.\" Copyright (c) 2022 Dag-Erling Smørgrav +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd May 15, 2022 +.Dt CRYB_MD5 3 +.Os +.Sh NAME +.Nm cryb_md5_init , +.Nm cryb_md5_update , +.Nm cryb_md5_final , +.Nm cryb_md5_complete +.Nd Message-Digest Algorithm 2 +.Sh LIBRARY +.Lb libcryb-digest +.Sh SYNOPSIS +.In stddef.h +.In stdint.h +.In cryb/md5.h +.Ft void +.Fn cryb_md5_init "cryb_md5_ctx *context" +.Ft void +.Fn cryb_md5_update "cryb_md5_ctx *context" "const void *data" "size_t len" +.Ft void +.Fn cryb_md5_final "cryb_md5_ctx *context" "uint8_t *digest" +.Ft void +.Fn cryb_md5_complete "const void *data" "size_t len" "uint8_t *digest" +.Sh DESCRIPTION +The +.Nm cryb_md5 +family of functions implements the MD5 message digest algorithm as +described in RFC 1321. +.Pp +The +.Fn cryb_md5_init +function initializes the context structure pointed to by +.Va context . +It is the caller's responsibility to allocate this structure. +.Pp +The +.Fn cryb_md5_update +function hashes the next +.Va len +bytes of data pointed to by the +.Va data +pointer into the given hash context. +.Pp +The +.Fn cryb_md5_final +function finalizes the computation and writes the resulting message +digest to the caller-provided buffer pointed to by +.Va digest , +which must be at least +.Dv MD5_DIGEST_LEN +bytes long. +It is the caller's responsibility to dispose of the context structure +after calling +.Fn cryb_md5_final . +.Pp +The +.Fn cryb_md5_complete +function is a shortcut to calling +.Fn cryb_md5_init , +.Fn cryb_md5_update , +and +.Fn cryb_md5_final +when the entire message is available up front in a single contiguous +buffer. +.Sh IMPLEMENTATION NOTES +The +.In cryb/md5.h +header provides macros which allows these functions and the context +type to be referred to without their +.Dq Li cryb_ +prefix. +.Pp +The MD5 message digest algorithm has been proven to be vulnerable to +collision attacks and should not be used for cryptographic purposes. +.Sh SEE ALSO +.Xr cryb_digest 3 , +.Xr cryb_md2 3 , +.Xr cryb_md4 3 +.Sh REFERENCES +.Rs +.%A Rivest, Ronald +.%T The MD5 Message-Digest Algorithm +.%D April 1992 +.%O RFC 1321 +.%U https://datatracker.ietf.org/doc/html/rfc1321 +.Re +.Rs +.%A Turner, Sean +.%A Chen, Lily +.%T Updated Security Considerations for the MD5 Message-Digest and the HMAC-MD5 Algorithms +.%D March 2011 +.%O RFC 6151 +.%U https://datatracker.ietf.org/doc/html/rfc6151 +.Re +.Sh AUTHORS +These functions and this manual page were written by +.An Dag-Erling Sm\(/orgrav Aq Mt des@des.no . diff --git a/lib/digest/cryb_sha1.3 b/lib/digest/cryb_sha1.3 index 110d74d..d9add32 100644 --- a/lib/digest/cryb_sha1.3 +++ b/lib/digest/cryb_sha1.3 @@ -1,6 +1,6 @@ .\"- .\" Copyright (c) 2015 The University of Oslo -.\" Copyright (c) 2016 Dag-Erling Smørgrav +.\" Copyright (c) 2016-2022 Dag-Erling Smørgrav .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -27,7 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd September 17, 2016 +.Dd May 15, 2022 .Dt CRYB_SHA1 3 .Os .Sh NAME @@ -86,7 +86,7 @@ The .Fn cryb_sha1_complete function is a shortcut to calling .Fn cryb_sha1_init , -.Fn cryb_sha1_update +.Fn cryb_sha1_update , and .Fn cryb_sha1_final when the entire message is available up front in a single contiguous @@ -114,6 +114,7 @@ collision attacks and should not be used for cryptographic purposes. .%D March 2012 .Re .Sh AUTHORS +.An -nosplit These functions and this manual page were written for the University of Oslo by .An Dag-Erling Sm\(/orgrav Aq Mt d.e.smorgrav@usit.uio.no . diff --git a/lib/digest/cryb_sha224.3 b/lib/digest/cryb_sha224.3 index e55aff5..d960b39 100644 --- a/lib/digest/cryb_sha224.3 +++ b/lib/digest/cryb_sha224.3 @@ -1,6 +1,6 @@ .\"- .\" Copyright (c) 2015 The University of Oslo -.\" Copyright (c) 2016 Dag-Erling Smørgrav +.\" Copyright (c) 2016-2022 Dag-Erling Smørgrav .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -27,7 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd September 17, 2016 +.Dd May 15, 2022 .Dt CRYB_SHA224 3 .Os .Sh NAME @@ -86,7 +86,7 @@ The .Fn cryb_sha224_complete function is a shortcut to calling .Fn cryb_sha224_init , -.Fn cryb_sha224_update +.Fn cryb_sha224_update , and .Fn cryb_sha224_final when the entire message is available up front in a single contiguous @@ -111,6 +111,7 @@ prefix. .%D March 2012 .Re .Sh AUTHORS +.An -nosplit These functions and this manual page were written for the University of Oslo by .An Dag-Erling Sm\(/orgrav Aq Mt d.e.smorgrav@usit.uio.no . diff --git a/lib/digest/cryb_sha256.3 b/lib/digest/cryb_sha256.3 index 19b236a..15976e7 100644 --- a/lib/digest/cryb_sha256.3 +++ b/lib/digest/cryb_sha256.3 @@ -1,6 +1,6 @@ .\"- .\" Copyright (c) 2015 The University of Oslo -.\" Copyright (c) 2016 Dag-Erling Smørgrav +.\" Copyright (c) 2016-2022 Dag-Erling Smørgrav .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -27,7 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd September 17, 2016 +.Dd May 15, 2022 .Dt CRYB_SHA256 3 .Os .Sh NAME @@ -86,7 +86,7 @@ The .Fn cryb_sha256_complete function is a shortcut to calling .Fn cryb_sha256_init , -.Fn cryb_sha256_update +.Fn cryb_sha256_update , and .Fn cryb_sha256_final when the entire message is available up front in a single contiguous @@ -111,6 +111,7 @@ prefix. .%D March 2012 .Re .Sh AUTHORS +.An -nosplit These functions and this manual page were written for the University of Oslo by .An Dag-Erling Sm\(/orgrav Aq Mt d.e.smorgrav@usit.uio.no . diff --git a/lib/digest/cryb_sha384.3 b/lib/digest/cryb_sha384.3 index 089bf9c..3d308ac 100644 --- a/lib/digest/cryb_sha384.3 +++ b/lib/digest/cryb_sha384.3 @@ -1,6 +1,6 @@ .\"- .\" Copyright (c) 2015 The University of Oslo -.\" Copyright (c) 2016 Dag-Erling Smørgrav +.\" Copyright (c) 2016-2022 Dag-Erling Smørgrav .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -27,7 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd September 17, 2016 +.Dd May 15, 2022 .Dt CRYB_SHA384 3 .Os .Sh NAME @@ -86,7 +86,7 @@ The .Fn cryb_sha384_complete function is a shortcut to calling .Fn cryb_sha384_init , -.Fn cryb_sha384_update +.Fn cryb_sha384_update , and .Fn cryb_sha384_final when the entire message is available up front in a single contiguous @@ -111,6 +111,7 @@ prefix. .%D March 2012 .Re .Sh AUTHORS +.An -nosplit These functions and this manual page were written for the University of Oslo by .An Dag-Erling Sm\(/orgrav Aq Mt d.e.smorgrav@usit.uio.no . diff --git a/lib/digest/cryb_sha512.3 b/lib/digest/cryb_sha512.3 index 976f469..868995b 100644 --- a/lib/digest/cryb_sha512.3 +++ b/lib/digest/cryb_sha512.3 @@ -1,6 +1,6 @@ .\"- .\" Copyright (c) 2015 The University of Oslo -.\" Copyright (c) 2016 Dag-Erling Smørgrav +.\" Copyright (c) 2016-2022 Dag-Erling Smørgrav .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -27,7 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd September 17, 2016 +.Dd May 15, 2022 .Dt CRYB_SHA512 3 .Os .Sh NAME @@ -86,7 +86,7 @@ The .Fn cryb_sha512_complete function is a shortcut to calling .Fn cryb_sha512_init , -.Fn cryb_sha512_update +.Fn cryb_sha512_update , and .Fn cryb_sha512_final when the entire message is available up front in a single contiguous @@ -111,6 +111,7 @@ prefix. .%D March 2012 .Re .Sh AUTHORS +.An -nosplit These functions and this manual page were written for the University of Oslo by .An Dag-Erling Sm\(/orgrav Aq Mt d.e.smorgrav@usit.uio.no . diff --git a/lib/enc/cryb_percent.3 b/lib/enc/cryb_percent.3 index cb51536..d069b23 100644 --- a/lib/enc/cryb_percent.3 +++ b/lib/enc/cryb_percent.3 @@ -1,5 +1,5 @@ .\"- -.\" Copyright (c) 2014-2016 Dag-Erling Smørgrav +.\" Copyright (c) 2014-2022 Dag-Erling Smørgrav .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -26,7 +26,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd January 10, 2016 +.Dd May 15, 2022 .Dt CRYB_PERCENT 3 .Os .Sh NAME @@ -129,14 +129,15 @@ prefix. .Xr cryb_base64 3 .Sh REFERENCES .Rs -.%A "Berners-Lee, T." -.%A "Fielding, R." -.%A "Masinter, L." -.%D "January 2005" -.%R "Uniform Resource Identifier (URI): Generic Syntax" -.%O "RFC 3968" +.%A Berners-Lee, T. +.%A Fielding, R. +.%A Masinter, L. +.%R Uniform Resource Identifier (URI): Generic Syntax +.%D January 2005 +.%O RFC 3968 .Re .Sh AUTHORS +.An -nosplit The .Fn cryb_percent_decode and diff --git a/lib/hash/Makefile.am b/lib/hash/Makefile.am index fd2d207..54a6c19 100644 --- a/lib/hash/Makefile.am +++ b/lib/hash/Makefile.am @@ -7,6 +7,7 @@ libcryb_hash_la_SOURCES = \ cryb_fletcher16.c \ cryb_fletcher32.c \ cryb_fletcher64.c \ + cryb_fnv.c \ cryb_murmur3_32.c \ cryb_pearson.c \ \ @@ -15,10 +16,15 @@ libcryb_hash_la_SOURCES = \ dist_man3_MANS = \ cryb_adler32.3 \ cryb_fletcher.3 \ + cryb_fnv.3 \ + cryb_murmur3.3 \ cryb_pearson.3 \ \ cryb_hash.3 +noinst_HEADERS = \ + cryb_fnv_impl.h + libcryb_hash_la_CFLAGS = \ $(CRYB_CORE_CFLAGS) diff --git a/lib/hash/cryb_adler32.3 b/lib/hash/cryb_adler32.3 index 0f3b3fb..941f36e 100644 --- a/lib/hash/cryb_adler32.3 +++ b/lib/hash/cryb_adler32.3 @@ -1,6 +1,5 @@ .\"- -.\" Copyright (c) 2015-2016 The University of Oslo -.\" Copyright (c) 2016 Dag-Erling Smørgrav +.\" Copyright (c) 2016-2022 Dag-Erling Smørgrav .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -27,12 +26,12 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd January 8, 2016 +.Dd May 15, 2022 .Dt CRYB_ADLER32 3 .Os .Sh NAME .Nm cryb_adler32_hash -.Nd hash functions +.Nd non-cryptographic hash functions .Sh LIBRARY .Lb libcryb-hash .Sh SYNOPSIS @@ -65,13 +64,14 @@ prefix. .Xr cryb_hash 3 .Sh REFERENCES .Rs -.%A "Deutsch, P." -.%A "Gailly, J.-L." -.%D "May 1996" -.%R "ZLIB Compressed Data Format Specification version 3.3" -.%O "RFC 1950" +.%A Deutsch, P. +.%A Gailly, J.-L. +.%D May 1996 +.%R ZLIB Compressed Data Format Specification version 3.3 +.%O RFC 1950 .Re .Sh AUTHORS +.An -nosplit The .Fn cryb_adler32_hash function and this manual page were written by diff --git a/lib/hash/cryb_fletcher.3 b/lib/hash/cryb_fletcher.3 index cfc3562..d4e2e09 100644 --- a/lib/hash/cryb_fletcher.3 +++ b/lib/hash/cryb_fletcher.3 @@ -33,7 +33,7 @@ .Nm cryb_fletcher16_hash , .Nm cryb_fletcher32_hash , .Nm cryb_fletcher64_hash -.Nd hash functions +.Nd non-cryptographic hash functions .Sh LIBRARY .Lb libcryb-hash .Sh SYNOPSIS @@ -41,11 +41,11 @@ .In stdint.h .In cryb/hash.h .Ft uint16_t -.Fn fletcher16_hash "const void *data" "size_t len" +.Fn cryb_fletcher16_hash "const void *data" "size_t len" .Ft uint32_t -.Fn fletcher32_hash "const void *data" "size_t len" +.Fn cryb_fletcher32_hash "const void *data" "size_t len" .Ft uint64_t -.Fn fletcher64_hash "const void *data" "size_t len" +.Fn cryb_fletcher64_hash "const void *data" "size_t len" .Sh DESCRIPTION The .Fn cryb_fletcher16_hash , @@ -75,16 +75,17 @@ argument before calling the checksum function. .Xr cryb_hash 3 .Sh STANDARDS .Rs -.%A "Fletcher, John G." -.%D "January 1982" -.%T "An Arithmetic Checksum for Serial Transmissions" -.%J "IEEE Transactions on Communications" -.%V "30" -.%N "1" -.%P "247-252" -.%O "doi:10.1109/tcom.1982.1095369" +.%A Fletcher, John G. +.%T An Arithmetic Checksum for Serial Transmissions +.%J IEEE Transactions on Communications +.%V 30 +.%N 1 +.%P 247-252 +.%D January 1982 +.%O doi:10.1109/tcom.1982.1095369 .Re .Sh AUTHORS +.An -nosplit The .Fn cryb_fletcher16 , .Fn cryb_fletcher32 diff --git a/lib/hash/cryb_fnv.3 b/lib/hash/cryb_fnv.3 new file mode 100644 index 0000000..d3d6512 --- /dev/null +++ b/lib/hash/cryb_fnv.3 @@ -0,0 +1,107 @@ +.\"- +.\" Copyright (c) 2022 Dag-Erling Smørgrav +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd May 15, 2022 +.Dt CRYB_FNV 3 +.Os +.Sh NAME +.Nm cryb_fnv0_32_hash , +.Nm cryb_fnv0_64_hash , +.Nm cryb_fnv1_32_hash , +.Nm cryb_fnv1_64_hash , +.Nm cryb_fnv1a_32_hash , +.Nm cryb_fnv1a_64_hash +.Nd non-cryptographic hash functions +.Sh LIBRARY +.Lb libcryb-hash +.Sh SYNOPSIS +.In stddef.h +.In stdint.h +.In cryb/hash.h +.Ft uint32_t +.Fn cryb_fnv0_32_hash "const void *data" "size_t len" +.Ft uint64_t +.Fn cryb_fnv0_64_hash "const void *data" "size_t len" +.Ft uint32_t +.Fn cryb_fnv1_32_hash "const void *data" "size_t len" +.Ft uint64_t +.Fn cryb_fnv1_64_hash "const void *data" "size_t len" +.Ft uint32_t +.Fn cryb_fnv1a_32_hash "const void *data" "size_t len" +.Ft uint64_t +.Fn cryb_fnv1a_64_hash "const void *data" "size_t len" +.Sh DESCRIPTION +The +.Fn cryb_fnv0_32_hash , +.Fn cryb_fnv1_32_hash , +and +.Fn cryb_fnv1a_32_hash , +functions return a 32-bit hash of the +.Va len +first bytes of the object pointed to by +.Va data +using the Fowler-Noll-Vo (FNV) 0, 1, and 1a algorithms respectively. +.Pp +The +.Fn cryb_fnv0_64_hash , +.Fn cryb_fnv1_64_hash , +and +.Fn cryb_fnv1a_64_hash , +functions return a 64-bit hash of the +.Va len +first bytes of the object pointed to by +.Va data +using the FNV 0, 1, and 1a algorithms respectively. +.Sh IMPLEMENTATION NOTES +The +.In cryb/hash.h +header provides macros which allows these functions to be referred to +without their +.Dq Li cryb_ +prefix. +.Sh SEE ALSO +.Xr cryb_hash 3 +.Sh STANDARDS +.Rs +.%A Fowler, Glenn +.%A Noll, Landon Curt +.%A Vo, Kiem-Phong +.%A Eastlake, Donald +.%A Hansen, Tony +.%T The FNV Non-Cryptographic Hash Algorithm +.%D May 29, 2019 +.%O draft-eastlake-fnv-17 +.%U https://datatracker.ietf.org/doc/html/draft-eastlake-fnv-17 +.Re +.Sh AUTHORS +The +.Fn cryb_pearson_hash +and +.Fn cryb_pearson_hash_str +functions and this manual page were written by +.An Dag-Erling Sm\(/orgrav Aq Mt des@des.no . diff --git a/lib/hash/cryb_fnv.c b/lib/hash/cryb_fnv.c new file mode 100644 index 0000000..362adad --- /dev/null +++ b/lib/hash/cryb_fnv.c @@ -0,0 +1,113 @@ +/*- + * Copyright (c) 2022 Dag-Erling Smørgrav + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "cryb/impl.h" + +#include +#include + +#include + +#include "cryb_fnv_impl.h" + +/* + * Implementations of the 32- and 64-bit Fowler-Noll-Vo (FNV) 0, 1, and 1a hashes. + */ + +uint32_t fnv0_32_hash(const void *data, size_t len) +{ + const uint8_t *p; + uint32_t h; + + for (p = data, h = 0; len > 0; ++p, --len) { + h *= FNV_32_PRIME; + h ^= *p; + } + return (h); +} + +uint64_t fnv0_64_hash(const void *data, size_t len) +{ + const uint8_t *p; + uint64_t h; + + for (p = data, h = 0; len > 0; ++p, --len) { + h *= FNV_64_PRIME; + h ^= *p; + } + return (h); +} + +uint32_t fnv1_32_hash(const void *data, size_t len) +{ + const uint8_t *p; + uint32_t h; + + for (p = data, h = FNV_32_OFFSET_BASIS; len > 0; ++p, --len) { + h *= FNV_32_PRIME; + h ^= *p; + } + return (h); +} + +uint64_t fnv1_64_hash(const void *data, size_t len) +{ + const uint8_t *p; + uint64_t h; + + for (p = data, h = FNV_64_OFFSET_BASIS; len > 0; ++p, --len) { + h *= FNV_64_PRIME; + h ^= *p; + } + return (h); +} + +uint32_t fnv1a_32_hash(const void *data, size_t len) +{ + const uint8_t *p; + uint32_t h; + + for (p = data, h = FNV_32_OFFSET_BASIS; len > 0; ++p, --len) { + h ^= *p; + h *= FNV_32_PRIME; + } + return (h); +} + +uint64_t fnv1a_64_hash(const void *data, size_t len) +{ + const uint8_t *p; + uint64_t h; + + for (p = data, h = FNV_64_OFFSET_BASIS; len > 0; ++p, --len) { + h ^= *p; + h *= FNV_64_PRIME; + } + return (h); +} diff --git a/lib/hash/cryb_fnv_impl.h b/lib/hash/cryb_fnv_impl.h new file mode 100644 index 0000000..e266c1a --- /dev/null +++ b/lib/hash/cryb_fnv_impl.h @@ -0,0 +1,36 @@ +/*- + * Copyright (c) 2022 Dag-Erling Smørgrav + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#define FNV_32_PRIME 0x01000193UL +#define FNV_32_OFFSET_BASIS 0x811c9dc5UL + +#define FNV_64_PRIME 0x00000100000001B3ULL +#define FNV_64_OFFSET_BASIS 0xcbf29ce484222325ULL + +#define FNV_SIGNATURE "chongo /\\../\\" diff --git a/lib/hash/cryb_hash.3 b/lib/hash/cryb_hash.3 index 063c4c1..ab571df 100644 --- a/lib/hash/cryb_hash.3 +++ b/lib/hash/cryb_hash.3 @@ -1,5 +1,5 @@ .\"- -.\" Copyright (c) 2016 Dag-Erling Smørgrav +.\" Copyright (c) 2022 Dag-Erling Smørgrav .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -26,18 +26,12 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd September 17, 2016 +.Dd May 15, 2022 .Dt CRYB_HASH 3 .Os .Sh NAME -.Nm cryb_hash_version , -.Nm cryb_adler32_hash , -.Nm cryb_fletcher16_hash , -.Nm cryb_fletcher32_hash , -.Nm cryb_fletcher64_hash , -.Nm cryb_pearson_hash , -.Nm cryb_pearson_hash_str -.Nd hash and checksum functions +.Nm cryb_hash_version +.Nd non-cryptographic hash function library .Sh LIBRARY .Lb libcryb-hash .Sh SYNOPSIS @@ -46,18 +40,6 @@ .In cryb/hash.h .Ft const char * .Fn cryb_hash_version "void" -.Ft uint32_t -.Fn cryb_adler32_hash "const void *data" "size_t len" -.Ft uint16_t -.Fn fletcher16_hash "const void *data" "size_t len" -.Ft uint32_t -.Fn fletcher32_hash "const void *data" "size_t len" -.Ft uint64_t -.Fn fletcher64_hash "const void *data" "size_t len" -.Ft uint8_t -.Fn cryb_pearson_hash "const void *data" "size_t len" -.Ft uint8_t -.Fn cryb_pearson_hash_str "const char *str" .Sh DESCRIPTION The .Fn cryb_hash_version @@ -71,22 +53,10 @@ respective manual pages. .Sh SEE ALSO .Xr cryb_adler32 3 , .Xr cryb_fletcher 3 , +.Xr cryb_fnv 3 , +.Xr cryb_murmur3 , .Xr cryb_pearson 3 .Sh AUTHORS -The -.Fn cryb_hash_version , -.Fn cryb_adler32_hash , -.Fn cryb_fletcher16 , -.Fn cryb_fletcher32 -and -.Fn cryb_fletcher64 -functions and corresponding manual pages were written by +.An -nosplit +This manual page was written by .An Dag-Erling Sm\(/orgrav Aq Mt des@des.no . -.Pp -The -.Fn cryb_pearson_hash -and -.Fn cryb_pearson_hash_str -functions and corresponding manual pages were written for the -University of Oslo by -.An Dag-Erling Sm\(/orgrav Aq Mt d.e.smorgrav@usit.uio.no . diff --git a/lib/hash/cryb_murmur3.3 b/lib/hash/cryb_murmur3.3 new file mode 100644 index 0000000..6693637 --- /dev/null +++ b/lib/hash/cryb_murmur3.3 @@ -0,0 +1,64 @@ +.\"- +.\" Copyright (c) 2022 Dag-Erling Smørgrav +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of the author may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd May 15, 2022 +.Dt CRYB_MURMUR3 3 +.Os +.Sh NAME +.Nm cryb_murmur3_32_hash +.Nd non-cryptographic hash function +.Sh LIBRARY +.Lb libcryb-hash +.Sh SYNOPSIS +.In stddef.h +.In stdint.h +.In cryb/hash.h +.Ft uint32_t +.Fn murmur3_32_hash "const void *data" "size_t len" "uint32_t seed" +.Sh DESCRIPTION +The +.Fn cryb_murmur3_32_hash +function returns a 32-bit hash of the +.Va len +first bytes of the object pointed to by +.Va data +using the 32-bit MurmurHash3 algorithm. +.Sh IMPLEMENTATION NOTES +The +.In cryb/hash.h +header provides macros which allows these functions to be referred to +without their +.Dq Li cryb_ +prefix. +.Sh SEE ALSO +.Xr cryb_hash 3 +.Sh AUTHORS +The +.Fn cryb_murmur3_32_hash +function and this manual page were written by +.An Dag-Erling Sm\(/orgrav Aq Mt des@des.no . diff --git a/lib/hash/cryb_pearson.3 b/lib/hash/cryb_pearson.3 index d82ba27..0b1b674 100644 --- a/lib/hash/cryb_pearson.3 +++ b/lib/hash/cryb_pearson.3 @@ -1,6 +1,6 @@ .\"- .\" Copyright (c) 2015-2016 The University of Oslo -.\" Copyright (c) 2016 Dag-Erling Smørgrav +.\" Copyright (c) 2016-2022 Dag-Erling Smørgrav .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -27,13 +27,13 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd September 17, 2016 -.Dt CRYB_PEARSON_HASH 3 +.Dd May 15, 2022 +.Dt CRYB_PEARSON 3 .Os .Sh NAME .Nm cryb_pearson_hash , .Nm cryb_pearson_hash_str -.Nd hash functions +.Nd non-cryptographic hash functions .Sh LIBRARY .Lb libcryb-hash .Sh SYNOPSIS @@ -71,16 +71,17 @@ prefix. .Xr cryb_hash 3 .Sh STANDARDS .Rs -.%A "Pearson, Peter K." -.%D "June 1990" -.%T "Fast Hashing of Variable-Length Text Strings" -.%J "Communications of the ACM" -.%V "33" -.%N "6" -.%P "677" -.%O "doi:10.1145/78973.78978" +.%A Pearson, Peter K. +.%T Fast Hashing of Variable-Length Text Strings +.%J Communications of the ACM +.%V 33 +.%N 6 +.%P 677 +.%D June 1990 +.%O doi:10.1145/78973.78978 .Re .Sh AUTHORS +.An -nosplit The .Fn cryb_pearson_hash and diff --git a/t/.gitignore b/t/.gitignore index fe24f7d..7cdeb9d 100644 --- a/t/.gitignore +++ b/t/.gitignore @@ -12,6 +12,7 @@ /t_endian /t_ffs_fls /t_fletcher +/t_fnv /t_hash /t_hmac_sha1 /t_hmac_sha1_openssl diff --git a/t/Makefile.am b/t/Makefile.am index bc7e5e8..fe8d80d 100644 --- a/t/Makefile.am +++ b/t/Makefile.am @@ -179,9 +179,11 @@ endif CRYB_ENC if CRYB_HASH TESTS += t_hash t_hash_LDADD = $(libt) $(libhash) -TESTS += t_adler t_fletcher t_murmur3_32 t_pearson +TESTS += t_adler t_fletcher t_fnv t_murmur3_32 t_pearson t_adler_LDADD = $(libt) $(libhash) t_fletcher_LDADD = $(libt) $(libhash) +t_fnv_CFLAGS = -I$(top_srcdir)/lib/hash +t_fnv_LDADD = $(libt) $(libhash) t_murmur3_32_LDADD = $(libt) $(libhash) t_pearson_LDADD = $(libt) $(libhash) endif CRYB_HASH diff --git a/t/t_fnv.c b/t/t_fnv.c new file mode 100644 index 0000000..2559bb8 --- /dev/null +++ b/t/t_fnv.c @@ -0,0 +1,151 @@ +/*- + * Copyright (c) 2014-2022 Dag-Erling Smørgrav + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "cryb/impl.h" + +#include +#include +#include +#include + +#include + +#include + +#include "cryb_fnv_impl.h" + +struct t_case { + const char *str; + uint32_t h0_32, h1_32, h1a_32; + uint64_t h0_64, h1_64, h1a_64; +}; + +/*************************************************************************** + * Test cases + */ + +/* + * Test vectors from the IETF draft, expanded to also cover FNV-0 and FNV-1. + */ +static struct t_case t_cases[] = { + { + .str = "", + .h0_32 = 0x00000000UL, + .h1_32 = 0x811c9dc5UL, + .h1a_32 = 0x811c9dc5UL, + .h0_64 = 0x0000000000000000ULL, + .h1_64 = 0xcbf29ce484222325ULL, + .h1a_64 = 0xcbf29ce484222325ULL, + }, + { + .str = "a", + .h0_32 = 0x00000061UL, + .h1_32 = 0x050c5d7eUL, + .h1a_32 = 0xe40c292cUL, + .h0_64 = 0x0000000000000061ULL, + .h1_64 = 0xaf63bd4c8601b7beULL, + .h1a_64 = 0xaf63dc4c8601ec8cULL, + }, + { + .str = "foobar", + .h0_32 = 0xb74bb5efUL, + .h1_32 = 0x31f0b262UL, + .h1a_32 = 0xbf9cf968UL, + .h0_64 = 0x0b91ae3f7ccdc5efULL, + .h1_64 = 0x340d8765a4dda9c2ULL, + .h1a_64 = 0x85944171f73967e8ULL, + }, +}; + +/* + * Test case for the 32- and 64-bit offset bases. + */ +static struct t_case t_offset_basis = { + .str = FNV_SIGNATURE, + .h0_32 = FNV_32_OFFSET_BASIS, + .h0_64 = FNV_64_OFFSET_BASIS, +}; + +/*************************************************************************** + * Test functions + */ +#define T_FNV(V, B) \ + static int \ + t_fnv##V##_##B(char **desc, void *arg) \ + { \ + struct t_case *t = arg; \ + uint##B##_t h; \ + \ + if (!**desc) { \ + (void)asprintf(desc, \ + "FNV-" #V "-" #B " \"%s\"", t->str); \ + } \ + h = fnv##V##_##B##_hash(t->str, strlen(t->str)); \ + return (t_compare_x##B(t->h##V##_##B, h)); \ + } + +T_FNV(0, 32) +T_FNV(0, 64) +T_FNV(1, 32) +T_FNV(1, 64) +T_FNV(1a, 32) +T_FNV(1a, 64) + + +/*************************************************************************** + * Boilerplate + */ + +static int +t_prepare(int argc, char *argv[]) +{ + int i, n; + + (void)argc; + (void)argv; + t_add_test(t_fnv0_32, &t_offset_basis, "FNV-32 offset basis"); + t_add_test(t_fnv0_64, &t_offset_basis, "FNV-64 offset basis"); + n = sizeof t_cases / sizeof t_cases[0]; + for (i = 0; i < n; ++i) { + t_add_test(t_fnv0_32, &t_cases[i], ""); + t_add_test(t_fnv0_64, &t_cases[i], ""); + t_add_test(t_fnv1_32, &t_cases[i], ""); + t_add_test(t_fnv1_64, &t_cases[i], ""); + t_add_test(t_fnv1a_32, &t_cases[i], ""); + t_add_test(t_fnv1a_64, &t_cases[i], ""); + } + return (0); +} + +int +main(int argc, char *argv[]) +{ + + t_main(t_prepare, NULL, argc, argv); +}