summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorGuillem Jover <guillem@hadrons.org>2021-02-07 00:09:30 +0100
committerGuillem Jover <guillem@hadrons.org>2021-02-07 01:28:27 +0100
commit847e682f8de452d5f0038458f06ae68ae3959b3a (patch)
tree5c7f97fc9c4b131801f088cd947bc93e26599bc8 /include
parent68f980c90d914e5fd6f7512e00dec334dbb71bed (diff)
Use libmd hashing function implementations instead of embedding our own
This splits the implementation responsibilities, and reduces embedded code copies, which was one of the driving points with this project to start with, so it's nice to give a good example.
Diffstat (limited to 'include')
-rw-r--r--include/bsd/md5.h75
1 files changed, 24 insertions, 51 deletions
diff --git a/include/bsd/md5.h b/include/bsd/md5.h
index bf36a30..5bd58d8 100644
--- a/include/bsd/md5.h
+++ b/include/bsd/md5.h
@@ -1,58 +1,31 @@
-/* $OpenBSD: md5.h,v 1.16 2004/06/22 01:57:30 jfb Exp $ */
-
/*
- * This code implements the MD5 message-digest algorithm.
- * The algorithm is due to Ron Rivest. This code was
- * written by Colin Plumb in 1993, no copyright is claimed.
- * This code is in the public domain; do with it what you wish.
+ * Copyright © 2021 Guillem Jover <guillem@hadrons.org>
+ *
+ * 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.
*
- * Equivalent code is available from RSA Data Security, Inc.
- * This code has been tested against that, and is equivalent,
- * except that you don't need to include two pages of legalese
- * with every copy.
+ * THIS SOFTWARE IS PROVIDED ``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 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.
*/
-#ifndef LIBBSD_MD5_H
-#define LIBBSD_MD5_H
-
-#include <stdint.h>
-
-#define MD5_BLOCK_LENGTH 64
-#define MD5_DIGEST_LENGTH 16
-#define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_LENGTH * 2 + 1)
-
-typedef struct MD5Context {
- uint32_t state[4]; /* state */
- uint64_t count; /* number of bits, mod 2^64 */
- uint8_t buffer[MD5_BLOCK_LENGTH]; /* input buffer */
-} MD5_CTX;
-
#ifdef LIBBSD_OVERLAY
-#include <sys/cdefs.h>
+#include_next <md5.h>
#else
-#include <bsd/sys/cdefs.h>
+#include <md5.h>
#endif
-#include <sys/types.h>
-
-__BEGIN_DECLS
-void MD5Init(MD5_CTX *);
-void MD5Update(MD5_CTX *, const uint8_t *, size_t)
- __attribute__((__bounded__(__string__,2,3)));
-void MD5Pad(MD5_CTX *);
-void MD5Final(uint8_t [MD5_DIGEST_LENGTH], MD5_CTX *)
- __attribute__((__bounded__(__minbytes__,1,MD5_DIGEST_LENGTH)));
-void MD5Transform(uint32_t [4], const uint8_t [MD5_BLOCK_LENGTH])
- __attribute__((__bounded__(__minbytes__,1,4)))
- __attribute__((__bounded__(__minbytes__,2,MD5_BLOCK_LENGTH)));
-char *MD5End(MD5_CTX *, char *)
- __attribute__((__bounded__(__minbytes__,2,MD5_DIGEST_STRING_LENGTH)));
-char *MD5File(const char *, char *)
- __attribute__((__bounded__(__minbytes__,2,MD5_DIGEST_STRING_LENGTH)));
-char *MD5FileChunk(const char *, char *, off_t, off_t)
- __attribute__((__bounded__(__minbytes__,2,MD5_DIGEST_STRING_LENGTH)));
-char *MD5Data(const uint8_t *, size_t, char *)
- __attribute__((__bounded__(__string__,1,2)))
- __attribute__((__bounded__(__minbytes__,3,MD5_DIGEST_STRING_LENGTH)));
-__END_DECLS
-
-#endif /* LIBBSD_MD5_H */