1 # Buildsheet autogenerated by ravenadm tool -- Do not edit.
7 SDESC[standard]= MD5 and SHA-256 digest tools from DragonFly
9 CONTACT= John_Marino[draco@marino.st]
12 SPKGS[standard]= single
14 OPTIONS_AVAILABLE= none
15 OPTIONS_STANDARD= none
17 BUILD_DEPENDS= libressl:single:static
21 cp ${FILESDIR}/* ${WRKSRC}/
23 [FILE:322:descriptions/desc.single]
24 The md5 and sha256 programs are command-line utilities originating with
25 FreeBSD. Their purpose is to generate message digests.
27 The core hash routines were implemented by Colin Percival based on the
28 published FIPS 180-2 standard. Matt Dillon modified them to use
29 OpenSSL/LibreSSL routines to avoid conflicts with libmd.
32 [FILE:18:manifests/plist.single]
38 [FILE:887:files/Makefile]
39 # $FreeBSD: src/lib/libmd/Makefile,v 1.42 2005/03/09 19:23:04 cperciva Exp $
41 SRCS= md5c.c md5hl.c sha256hl.c
44 LIBS= ${PREFIX}/lib/libcrypto.a
45 CFLAGS= -I${PREFIX}/include -I.
47 .if "${OPSYS}" == "Linux"
48 LIBS+= ${PREFIX}/lib/libbsd.a
53 ${OBJS}: ${.TARGET:.o=.c}
54 ${CC} -c ${.ALLSRC} ${CFLAGS}
57 (echo '#define LENGTH 16'; \
58 sed -e 's/mdX/md5/g' -e 's/MDX/MD5/g' ${.ALLSRC}) > ${.TARGET}
61 (echo '#define LENGTH 32'; \
62 sed -e 's/mdX/sha256/g' -e 's/MDX/SHA256_/g' \
63 -e 's/SHA256__/SHA256_/g' \
64 ${.ALLSRC}) > ${.TARGET}
66 program: ${OBJS} main.c
67 ${CC} -o md5 main.c ${OBJS} ${CFLAGS} ${LIBS}
71 ${BSD_INSTALL_PROGRAM} md5 ${DESTDIR}${PREFIX}/bin/
72 ${BSD_INSTALL_PROGRAM} sha256 ${DESTDIR}${PREFIX}/bin/
75 rm -f md5hl.c sha256hl.c md5 sha256 ${OBJS}
78 [FILE:11594:files/main.c]
82 * MDDRIVER.C - test driver for MD2, MD4 and MD5
84 * $FreeBSD: src/sbin/md5/md5.c,v 1.35 2006/01/17 15:35:57 phk Exp $
88 * Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
91 * RSA Data Security, Inc. makes no representations concerning either
92 * the merchantability of this software or the suitability of this
93 * software for any particular purpose. It is provided "as is"
94 * without express or implied warranty of any kind.
96 * These notices must be retained in any copies of any part of this
97 * documentation and/or software.
101 #include <sys/types.h>
102 #include <sys/stat.h>
103 #include <sys/time.h>
104 #include <sys/resource.h>
106 #include <sys/mman.h>
112 #include <sysexits.h>
115 #include <bsd/stdlib.h>
116 #endif /* __linux__ */
122 * Length of test block, number of test blocks.
124 #define TEST_BLOCK_LEN 10000
125 #define TEST_BLOCK_COUNT 100000
126 #define MDTESTCOUNT 8
132 typedef void (DIGEST_Init)(void *);
133 typedef void (DIGEST_Update)(void *, const unsigned char *, size_t);
134 typedef char *(DIGEST_End)(void *, char *);
136 extern const char *MD5TestOutput[MDTESTCOUNT];
137 extern const char *SHA256_TestOutput[MDTESTCOUNT];
139 typedef struct Algorithm_t {
140 const char *progname;
142 const char *(*TestOutput)[MDTESTCOUNT];
144 DIGEST_Update *Update;
146 char *(*Data)(const void *, unsigned int, char *);
147 char *(*File)(const char *, char *);
150 static void MDString(Algorithm_t *, const char *);
151 static void MDTimeTrial(Algorithm_t *);
152 static void MDTestSuite(Algorithm_t *);
153 static void MDFilter(Algorithm_t *, int);
154 static void usage(int excode);
161 /* max(MD5_DIGEST_LENGTH, SHA_DIGEST_LENGTH,
162 SHA256_DIGEST_LENGTH, RIPEMD160_DIGEST_LENGTH)*2+1 */
163 #define HEX_DIGEST_LENGTH 65
165 /* algorithm function table */
167 struct Algorithm_t Algorithm[] = {
168 { "md5", "MD5", &MD5TestOutput, (DIGEST_Init*)&MD5Init,
169 (DIGEST_Update*)&MD5Update, (DIGEST_End*)&MD5End,
170 &MD5Data, &MD5File },
171 { "sha256", "SHA256", &SHA256_TestOutput, (DIGEST_Init*)&SHA256_Init,
172 (DIGEST_Update*)&SHA256_Update, (DIGEST_End*)&SHA256_End,
173 &SHA256_Data, &SHA256_File }
177 * There is no need to use a huge mmap, just pick something
180 #define MAXMMAP (32*1024*1024)
183 digestfile(const char *fname, char *buf, const Algorithm_t *alg,
184 off_t *beginp, off_t *endp)
192 off_t end = *endp, begin = *beginp;
195 fd = open(fname, O_RDONLY);
197 warn("can't open %s", fname);
201 if (fstat(fd, &st) == -1) {
202 warn("can't fstat %s after opening", fname);
206 /* Non-positive end means, it has to be counted from the back: */
209 /* Negative begin means, it has to be counted from the back: */
213 if (begin < 0 || end < 0 || begin > st.st_size || end > st.st_size) {
214 warnx("%s is %jd bytes long, not large enough for the "
215 "specified offsets [%jd-%jd]", fname,
216 (intmax_t)st.st_size,
217 (intmax_t)*beginp, (intmax_t)*endp);
221 warnx("%s is %jd bytes long. Begin-offset %jd (%jd) is "
222 "larger than end-offset %jd (%jd)",
223 fname, (intmax_t)st.st_size,
224 (intmax_t)begin, (intmax_t)*beginp,
225 (intmax_t)end, (intmax_t)*endp);
234 pagesize = getpagesize();
239 if (end - begin > MAXMMAP)
245 map = mmap(NULL, size, PROT_READ, 0, fd, begin);
247 map = mmap(NULL, size, PROT_READ, MAP_NOCORE, fd, begin);
249 if (map == MAP_FAILED) {
250 warn("mmaping of %s between %jd and %jd ",
251 fname, (intmax_t)begin, (intmax_t)begin + size);
255 * Try to give kernel a hint. Not that it
256 * cares at the time of this writing :-(
259 madvise(map, size, MADV_SEQUENTIAL);
260 alg->Update(&context, map, size);
263 } while (begin < end);
265 result = alg->End(&context, buf);
273 parseint(const char *arg)
275 double result; /* Use double to allow things like 0.5Kb */
278 result = strtod(arg, &endp);
282 result *= 1024; /* FALLTHROUGH */
285 result *= 1024; /* FALLTHROUGH */
289 if (endp[1] == 'b' || endp[1] == 'B')
291 result *= 1024; /* FALLTHROUGH */
295 warnx("%c (%d): unrecognized suffix", endp[0], (int)endp[0]);
303 errx(EX_USAGE, "`%s' is not a valid offset.", arg);
308 Arguments (may be any combination):
309 -sstring - digests string
311 -x - runs test script
312 filename - digests file
313 (none) - digests standard input
316 main(int argc, char *argv[])
320 char buf[HEX_DIGEST_LENGTH];
321 int failed, useoffsets = 0;
322 off_t begin = 0, end = 0; /* To shut compiler warning */
324 const char* progname;
326 if ((progname = strrchr(argv[0], '/')) == NULL)
331 for (digest = 0; digest < sizeof(Algorithm)/sizeof(*Algorithm); digest++)
332 if (strcasecmp(Algorithm[digest].progname, progname) == 0)
335 if (digest == sizeof(Algorithm)/sizeof(*Algorithm))
339 while ((ch = getopt(argc, argv, "hb:e:pqrs:tx")) != -1) {
342 begin = parseint(optarg);
346 end = parseint(optarg);
350 MDFilter(&Algorithm[digest], 1);
360 MDString(&Algorithm[digest], optarg);
363 MDTimeTrial(&Algorithm[digest]);
366 MDTestSuite(&Algorithm[digest]);
380 p = digestfile(*argv, buf, Algorithm + digest,
383 p = Algorithm[digest].File(*argv, buf);
385 /* digestfile() outputs its own diagnostics */
394 printf("%s %s[%jd-%jd]\n",
401 } else if (useoffsets) {
402 printf("%s (%s[%jd-%jd]) = %s\n",
403 Algorithm[digest].name, *argv,
408 printf("%s (%s) = %s\n",
409 Algorithm[digest].name,
414 } else if (!sflag && (optind == 1 || qflag || rflag))
415 MDFilter(&Algorithm[digest], 0);
423 * Digests a string and prints the result.
426 MDString(Algorithm_t *alg, const char *string)
428 size_t len = strlen(string);
429 char buf[HEX_DIGEST_LENGTH];
432 printf("%s\n", alg->Data(string, len, buf));
434 printf("%s \"%s\"\n", alg->Data(string, len, buf), string);
436 printf("%s (\"%s\") = %s\n", alg->name, string, alg->Data(string, len, buf));
439 * Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte blocks.
442 MDTimeTrial(Algorithm_t *alg)
445 struct rusage before, after;
446 struct timeval total;
448 unsigned char block[TEST_BLOCK_LEN];
450 char *p, buf[HEX_DIGEST_LENGTH];
453 ("%s time trial. Digesting %d %d-byte blocks ...",
454 alg->name, TEST_BLOCK_COUNT, TEST_BLOCK_LEN);
457 /* Initialize block */
458 for (i = 0; i < TEST_BLOCK_LEN; i++)
459 block[i] = (unsigned char) (i & 0xff);
462 getrusage(0, &before);
466 for (i = 0; i < TEST_BLOCK_COUNT; i++)
467 alg->Update(&context, block, TEST_BLOCK_LEN);
468 p = alg->End(&context, buf);
471 getrusage(0, &after);
472 timersub(&after.ru_utime, &before.ru_utime, &total);
473 seconds = total.tv_sec + (float) total.tv_usec / 1000000;
476 printf("Digest = %s", p);
477 printf("\nTime = %f seconds\n", seconds);
479 ("Speed = %f bytes/second\n",
480 (float) TEST_BLOCK_LEN * (float) TEST_BLOCK_COUNT / seconds);
483 * Digests a reference suite of strings and prints the results.
486 const char *MDTestInput[MDTESTCOUNT] = {
491 "abcdefghijklmnopqrstuvwxyz",
492 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
493 "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
494 "MD5 has not yet (2001-09-03) been broken, but sufficient attacks have been made \
495 that its security is in some doubt"
498 const char *MD5TestOutput[MDTESTCOUNT] = {
499 "d41d8cd98f00b204e9800998ecf8427e",
500 "0cc175b9c0f1b6a831c399e269772661",
501 "900150983cd24fb0d6963f7d28e17f72",
502 "f96b697d7cb7938d525a2f31aaf161d0",
503 "c3fcd3d76192e4007dfb496cca67e13b",
504 "d174ab98d277d9f5a5611c2c9f419d9f",
505 "57edf4a22be3c955ac49da2e2107b67a",
506 "b50663f41d44d92171cb9976bc118538"
509 const char *SHA256_TestOutput[MDTESTCOUNT] = {
510 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
511 "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb",
512 "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
513 "f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650",
514 "71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73",
515 "db4bfcbd4da0cd85a60c3c37d3fbd8805c77f15fc6b1fdfe614ee0a7c8fdb4c0",
516 "f371bc4a311f2b009eef952dd83ca80e2b60026c8e935592d0f9c308453c813e",
517 "e6eae09f10ad4122a0e2a4075761d185a272ebd9f5aa489e998ff2f09cbfdd9f"
521 MDTestSuite(Algorithm_t *alg)
524 char buffer[HEX_DIGEST_LENGTH];
526 printf("%s test suite:\n", alg->name);
527 for (i = 0; i < MDTESTCOUNT; i++) {
528 (*alg->Data)(MDTestInput[i], strlen(MDTestInput[i]), buffer);
529 printf("%s (\"%s\") = %s", alg->name, MDTestInput[i], buffer);
530 if (strcmp(buffer, (*alg->TestOutput)[i]) == 0)
531 printf(" - verified correct\n");
533 printf(" - INCORRECT RESULT!\n");
538 * Digests the standard input and prints the result.
541 MDFilter(Algorithm_t *alg, int tee)
545 unsigned char buffer[BUFSIZ];
546 char buf[HEX_DIGEST_LENGTH];
549 while ((len = fread(buffer, 1, BUFSIZ, stdin))) {
550 if (tee && len != fwrite(buffer, 1, len, stdout))
552 alg->Update(&context, buffer, len);
554 printf("%s\n", alg->End(&context, buf));
560 fprintf(stderr, "usage:\n\t%s [-pqrtx] [-b offset] [-e offset] "
561 "[-s string] [files ...]\n", getprogname());
566 [FILE:2424:files/md5.h]
568 * Copyright (c) 2016 The DragonFly Project. All rights reserved.
570 * This code is derived from software contributed to The DragonFly Project
571 * by Matthew Dillon <dillon@backplane.com>
573 * Redistribution and use in source and binary forms, with or without
574 * modification, are permitted provided that the following conditions
577 * 1. Redistributions of source code must retain the above copyright
578 * notice, this list of conditions and the following disclaimer.
579 * 2. Redistributions in binary form must reproduce the above copyright
580 * notice, this list of conditions and the following disclaimer in
581 * the documentation and/or other materials provided with the
583 * 3. Neither the name of The DragonFly Project nor the names of its
584 * contributors may be used to endorse or promote products derived
585 * from this software without specific, prior written permission.
587 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
588 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
589 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
590 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
591 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
592 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
593 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
594 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
595 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
596 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
597 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
601 * libmd shims for openssl + non-conflicting old API functions.
607 #include <sys/types.h>
608 #include <openssl/md5.h>
610 #define MD5_BLOCK_LENGTH MD5_CBLOCK
611 #define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_LENGTH * 2 + 1)
614 int MD5Init (MD5_CTX *);
615 void MD5Update (MD5_CTX *, const void *, unsigned int);
616 void MD5Pad (MD5_CTX *);
617 void MD5Final (unsigned char [16], MD5_CTX *);
618 char *MD5End(MD5_CTX *, char *);
619 char *MD5File(const char *, char *);
620 char *MD5FileChunk(const char *, char *, off_t, off_t);
621 char *MD5Data(const void *, unsigned int, char *);
622 void MD5Transform (u_int32_t [4], const unsigned char [64]);
628 [FILE:9435:files/md5c.c]
630 * MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
632 * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
635 * License to copy and use this software is granted provided that it
636 * is identified as the "RSA Data Security, Inc. MD5 Message-Digest
637 * Algorithm" in all material mentioning or referencing this software
640 * License is also granted to make and use derivative works provided
641 * that such works are identified as "derived from the RSA Data
642 * Security, Inc. MD5 Message-Digest Algorithm" in all material
643 * mentioning or referencing the derived work.
645 * RSA Data Security, Inc. makes no representations concerning either
646 * the merchantability of this software or the suitability of this
647 * software for any particular purpose. It is provided "as is"
648 * without express or implied warranty of any kind.
650 * These notices must be retained in any copies of any part of this
651 * documentation and/or software.
653 * $FreeBSD: src/lib/libmd/md5c.c,v 1.17 2006/01/17 15:35:56 phk Exp $
655 * This code is the same as the code published by RSA Inc. It has been
656 * edited for clarity and style only.
659 #include <sys/types.h>
666 #include <machine/endian.h>
667 #include <sys/endian.h>
671 #if (BYTE_ORDER == LITTLE_ENDIAN)
672 #define Encode memcpy
673 #define Decode memcpy
677 * Encodes input (u_int32_t) into output (unsigned char). Assumes len is
682 Encode (unsigned char *output, u_int32_t *input, unsigned int len)
685 u_int32_t *op = (u_int32_t *)output;
687 for (i = 0; i < len / 4; i++)
688 op[i] = htole32(input[i]);
692 * Decodes input (unsigned char) into output (u_int32_t). Assumes len is
697 Decode (u_int32_t *output, const unsigned char *input, unsigned int len)
700 const u_int32_t *ip = (const u_int32_t *)input;
702 for (i = 0; i < len / 4; i++)
703 output[i] = le32toh(ip[i]);
707 static unsigned char PADDING[64] = {
708 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
709 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
710 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
713 /* F, G, H and I are basic MD5 functions. */
714 #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
715 #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
716 #define H(x, y, z) ((x) ^ (y) ^ (z))
717 #define I(x, y, z) ((y) ^ ((x) | (~z)))
719 /* ROTATE_LEFT rotates x left n bits. */
720 #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
723 * FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
724 * Rotation is separate from addition to prevent recomputation.
726 #define FF(a, b, c, d, x, s, ac) { \
727 (a) += F ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
728 (a) = ROTATE_LEFT ((a), (s)); \
731 #define GG(a, b, c, d, x, s, ac) { \
732 (a) += G ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
733 (a) = ROTATE_LEFT ((a), (s)); \
736 #define HH(a, b, c, d, x, s, ac) { \
737 (a) += H ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
738 (a) = ROTATE_LEFT ((a), (s)); \
741 #define II(a, b, c, d, x, s, ac) { \
742 (a) += I ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
743 (a) = ROTATE_LEFT ((a), (s)); \
747 /* MD5 initialization. Begins an MD5 operation, writing a new context. */
750 MD5Init (MD5_CTX *context)
753 context->Nl = context->Nh = 0;
755 /* Load magic initialization constants. */
756 context->A = 0x67452301;
757 context->B = 0xefcdab89;
758 context->C = 0x98badcfe;
759 context->D = 0x10325476;
764 * MD5 block update operation. Continues an MD5 message-digest
765 * operation, processing another message block, and updating the
770 MD5Update (MD5_CTX *context, const void *in, unsigned int inputLen)
772 unsigned int i, idx, partLen;
773 const unsigned char *input = in;
775 /* Compute number of bytes mod 64 */
776 idx = (unsigned int)((context->Nl >> 3) & 0x3F);
778 /* Update number of bits */
779 if ((context->Nl += ((u_int32_t)inputLen << 3))
780 < ((u_int32_t)inputLen << 3))
782 context->Nh += ((u_int32_t)inputLen >> 29);
786 /* Transform as many times as possible. */
787 if (inputLen >= partLen) {
788 memcpy(&((char *)context->data)[idx], (const void *)input,
790 MD5Transform (&context->A, (char *)context->data);
792 for (i = partLen; i + 63 < inputLen; i += 64)
793 MD5Transform (&context->A, &input[i]);
800 /* Buffer remaining input */
801 memcpy (&((char *)context->data)[idx], (const void *)&input[i],
806 * MD5 padding. Adds padding followed by original length.
810 MD5Pad (MD5_CTX *context)
812 unsigned char bits[8];
813 unsigned int idx, padLen;
815 /* Save number of bits */
816 Encode (bits, &context->Nl, 8);
818 /* Pad out to 56 mod 64. */
819 idx = (unsigned int)((context->Nl >> 3) & 0x3f);
820 padLen = (idx < 56) ? (56 - idx) : (120 - idx);
821 MD5Update (context, PADDING, padLen);
823 /* Append length (before padding) */
824 MD5Update (context, bits, 8);
828 * MD5 finalization. Ends an MD5 message-digest operation, writing the
829 * the message digest and zeroizing the context.
833 MD5Final (unsigned char digest[16], MD5_CTX *context)
838 /* Store state in digest */
839 Encode (digest, &context->A, 16);
841 /* Zeroize sensitive information. */
842 memset ((void *)context, 0, sizeof (*context));
845 /* MD5 basic transformation. Transforms state based on block. */
848 MD5Transform (u_int32_t *state, const unsigned char *block)
850 u_int32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16];
852 Decode (x, block, 64);
859 FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
860 FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
861 FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
862 FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
863 FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
864 FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
865 FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
866 FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
867 FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
868 FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
869 FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
870 FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
871 FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
872 FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
873 FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
874 FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
881 GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
882 GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
883 GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
884 GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
885 GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
886 GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
887 GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
888 GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
889 GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
890 GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
891 GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
892 GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
893 GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
894 GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
895 GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
896 GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
903 HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
904 HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
905 HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
906 HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
907 HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
908 HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
909 HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
910 HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
911 HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
912 HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
913 HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
914 HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
915 HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
916 HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
917 HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
918 HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
925 II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
926 II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
927 II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
928 II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
929 II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
930 II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
931 II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
932 II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
933 II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
934 II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
935 II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
936 II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
937 II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
938 II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
939 II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
940 II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
947 /* Zeroize sensitive information. */
948 memset ((void *)x, 0, sizeof (x));
952 [FILE:2120:files/mdXhl.c]
953 /* mdXhl.c * ----------------------------------------------------------------------------
954 * "THE BEER-WARE LICENSE" (Revision 42):
955 * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
956 * can do whatever you want with this stuff. If we meet some day, and you think
957 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
958 * ----------------------------------------------------------------------------
960 * $FreeBSD: src/lib/libmd/mdXhl.c,v 1.19 2006/01/17 15:35:56 phk Exp $
961 * $DragonFly: src/lib/libmd/mdXhl.c,v 1.3 2008/09/11 20:25:34 swildner Exp $
965 #include <sys/types.h>
966 #include <sys/stat.h>
977 MDXEnd(MDX_CTX *ctx, char *buf)
980 unsigned char digest[LENGTH];
981 static const char hex[]="0123456789abcdef";
984 buf = malloc(2*LENGTH + 1);
987 MDXFinal(digest, ctx);
988 for (i = 0; i < LENGTH; i++) {
989 buf[i+i] = hex[digest[i] >> 4];
990 buf[i+i+1] = hex[digest[i] & 0x0f];
997 MDXFile(const char *filename, char *buf)
999 return (MDXFileChunk(filename, buf, 0, 0));
1003 MDXFileChunk(const char *filename, char *buf, off_t ofs, off_t len)
1005 unsigned char buffer[8192];
1012 f = open(filename, O_RDONLY);
1015 if (fstat(f, &stbuf) < 0)
1017 if (ofs > stbuf.st_size)
1018 ofs = stbuf.st_size;
1019 if ((len == 0) || (len > stbuf.st_size - ofs))
1020 len = stbuf.st_size - ofs;
1021 if (lseek(f, ofs, SEEK_SET) < 0)
1026 if (n > sizeof(buffer))
1027 i = read(f, buffer, sizeof(buffer));
1029 i = read(f, buffer, n);
1032 MDXUpdate(&ctx, buffer, i);
1040 return (MDXEnd(&ctx, buf));
1044 MDXData (const void *data, unsigned int len, char *buf)
1049 MDXUpdate(&ctx,data,len);
1050 return (MDXEnd(&ctx, buf));
1054 [FILE:2113:files/sha256.h]
1056 * Copyright (c) 2016 The DragonFly Project. All rights reserved.
1058 * This code is derived from software contributed to The DragonFly Project
1059 * by Matthew Dillon <dillon@backplane.com>
1061 * Redistribution and use in source and binary forms, with or without
1062 * modification, are permitted provided that the following conditions
1065 * 1. Redistributions of source code must retain the above copyright
1066 * notice, this list of conditions and the following disclaimer.
1067 * 2. Redistributions in binary form must reproduce the above copyright
1068 * notice, this list of conditions and the following disclaimer in
1069 * the documentation and/or other materials provided with the
1071 * 3. Neither the name of The DragonFly Project nor the names of its
1072 * contributors may be used to endorse or promote products derived
1073 * from this software without specific, prior written permission.
1075 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1076 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1077 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
1078 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
1079 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
1080 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
1081 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1082 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
1083 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1084 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
1085 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1089 * libmd shims for openssl + non-conflicting old API functions.
1094 #include <sys/types.h>
1095 #include <openssl/sha.h>
1098 char *SHA256_End(SHA256_CTX *, char *);
1099 char *SHA256_File(const char *, char *);
1100 char *SHA256_FileChunk(const char *, char *, off_t, off_t);
1101 char *SHA256_Data(const void *, unsigned int, char *);