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
18 B_DEPS[sunos]= libbsd4sol:single:standard
19 B_DEPS[linux]= libbsd:single:standard
23 cp ${FILESDIR}/* ${WRKSRC}/
25 [FILE:322:descriptions/desc.single]
26 The md5 and sha256 programs are command-line utilities originating with
27 FreeBSD. Their purpose is to generate message digests.
29 The core hash routines were implemented by Colin Percival based on the
30 published FIPS 180-2 standard. Matt Dillon modified them to use
31 OpenSSL/LibreSSL routines to avoid conflicts with libmd.
34 [FILE:18:manifests/plist.single]
40 [FILE:1031:files/Makefile]
41 # $FreeBSD: src/lib/libmd/Makefile,v 1.42 2005/03/09 19:23:04 cperciva Exp $
43 SRCS= md5c.c md5hl.c sha256hl.c
46 LIBS= ${PREFIX}/libressl/lib/libcrypto.a
47 CFLAGS= -I${PREFIX}/libressl/include
48 CFLAGS+= -I${PREFIX}/include -I.
50 .if "${OPSYS}" == "Linux"
51 LIBS+= ${PREFIX}/lib/libbsd.a
53 .if "${OPSYS}" == "SunOS"
54 LIBS+= ${PREFIX}/lib/libbsd.a
55 CFLAGS+= -I${PREFIX}/include/bsd
60 ${OBJS}: ${.TARGET:.o=.c}
61 ${CC} -c ${.ALLSRC} ${CFLAGS}
64 (echo '#define LENGTH 16'; \
65 sed -e 's/mdX/md5/g' -e 's/MDX/MD5/g' ${.ALLSRC}) > ${.TARGET}
68 (echo '#define LENGTH 32'; \
69 sed -e 's/mdX/sha256/g' -e 's/MDX/SHA256_/g' \
70 -e 's/SHA256__/SHA256_/g' \
71 ${.ALLSRC}) > ${.TARGET}
73 program: ${OBJS} main.c
74 ${CC} -o md5 main.c ${OBJS} ${CFLAGS} ${LIBS}
78 ${BSD_INSTALL_PROGRAM} md5 ${DESTDIR}${PREFIX}/bin/
79 ${BSD_INSTALL_PROGRAM} sha256 ${DESTDIR}${PREFIX}/bin/
82 rm -f md5hl.c sha256hl.c md5 sha256 ${OBJS}
85 [FILE:11665:files/main.c]
89 * MDDRIVER.C - test driver for MD2, MD4 and MD5
91 * $FreeBSD: src/sbin/md5/md5.c,v 1.35 2006/01/17 15:35:57 phk Exp $
95 * Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
98 * RSA Data Security, Inc. makes no representations concerning either
99 * the merchantability of this software or the suitability of this
100 * software for any particular purpose. It is provided "as is"
101 * without express or implied warranty of any kind.
103 * These notices must be retained in any copies of any part of this
104 * documentation and/or software.
108 #include <sys/types.h>
109 #include <sys/stat.h>
110 #include <sys/time.h>
111 #include <sys/resource.h>
113 #include <sys/mman.h>
119 #include <sysexits.h>
122 #include <bsd/stdlib.h>
132 * Length of test block, number of test blocks.
134 #define TEST_BLOCK_LEN 10000
135 #define TEST_BLOCK_COUNT 100000
136 #define MDTESTCOUNT 8
142 typedef void (DIGEST_Init)(void *);
143 typedef void (DIGEST_Update)(void *, const unsigned char *, size_t);
144 typedef char *(DIGEST_End)(void *, char *);
146 extern const char *MD5TestOutput[MDTESTCOUNT];
147 extern const char *SHA256_TestOutput[MDTESTCOUNT];
149 typedef struct Algorithm_t {
150 const char *progname;
152 const char *(*TestOutput)[MDTESTCOUNT];
154 DIGEST_Update *Update;
156 char *(*Data)(const void *, unsigned int, char *);
157 char *(*File)(const char *, char *);
160 static void MDString(Algorithm_t *, const char *);
161 static void MDTimeTrial(Algorithm_t *);
162 static void MDTestSuite(Algorithm_t *);
163 static void MDFilter(Algorithm_t *, int);
164 static void usage(int excode);
171 /* max(MD5_DIGEST_LENGTH, SHA_DIGEST_LENGTH,
172 SHA256_DIGEST_LENGTH, RIPEMD160_DIGEST_LENGTH)*2+1 */
173 #define HEX_DIGEST_LENGTH 65
175 /* algorithm function table */
177 struct Algorithm_t Algorithm[] = {
178 { "md5", "MD5", &MD5TestOutput, (DIGEST_Init*)&MD5Init,
179 (DIGEST_Update*)&MD5Update, (DIGEST_End*)&MD5End,
180 &MD5Data, &MD5File },
181 { "sha256", "SHA256", &SHA256_TestOutput, (DIGEST_Init*)&SHA256_Init,
182 (DIGEST_Update*)&SHA256_Update, (DIGEST_End*)&SHA256_End,
183 &SHA256_Data, &SHA256_File }
187 * There is no need to use a huge mmap, just pick something
190 #define MAXMMAP (32*1024*1024)
193 digestfile(const char *fname, char *buf, const Algorithm_t *alg,
194 off_t *beginp, off_t *endp)
202 off_t end = *endp, begin = *beginp;
205 fd = open(fname, O_RDONLY);
207 warn("can't open %s", fname);
211 if (fstat(fd, &st) == -1) {
212 warn("can't fstat %s after opening", fname);
216 /* Non-positive end means, it has to be counted from the back: */
219 /* Negative begin means, it has to be counted from the back: */
223 if (begin < 0 || end < 0 || begin > st.st_size || end > st.st_size) {
224 warnx("%s is %jd bytes long, not large enough for the "
225 "specified offsets [%jd-%jd]", fname,
226 (intmax_t)st.st_size,
227 (intmax_t)*beginp, (intmax_t)*endp);
231 warnx("%s is %jd bytes long. Begin-offset %jd (%jd) is "
232 "larger than end-offset %jd (%jd)",
233 fname, (intmax_t)st.st_size,
234 (intmax_t)begin, (intmax_t)*beginp,
235 (intmax_t)end, (intmax_t)*endp);
244 pagesize = getpagesize();
249 if (end - begin > MAXMMAP)
254 #if defined __linux__ || defined __sun__ || defined __APPLE__
255 map = mmap(NULL, size, PROT_READ, 0, fd, begin);
257 map = mmap(NULL, size, PROT_READ, MAP_NOCORE, fd, begin);
259 if (map == MAP_FAILED) {
260 warn("mmaping of %s between %jd and %jd ",
261 fname, (intmax_t)begin, (intmax_t)begin + size);
265 * Try to give kernel a hint. Not that it
266 * cares at the time of this writing :-(
269 madvise(map, size, MADV_SEQUENTIAL);
270 alg->Update(&context, map, size);
273 } while (begin < end);
275 result = alg->End(&context, buf);
283 parseint(const char *arg)
285 double result; /* Use double to allow things like 0.5Kb */
288 result = strtod(arg, &endp);
292 result *= 1024; /* FALLTHROUGH */
295 result *= 1024; /* FALLTHROUGH */
299 if (endp[1] == 'b' || endp[1] == 'B')
301 result *= 1024; /* FALLTHROUGH */
305 warnx("%c (%d): unrecognized suffix", endp[0], (int)endp[0]);
313 errx(EX_USAGE, "`%s' is not a valid offset.", arg);
318 Arguments (may be any combination):
319 -sstring - digests string
321 -x - runs test script
322 filename - digests file
323 (none) - digests standard input
326 main(int argc, char *argv[])
330 char buf[HEX_DIGEST_LENGTH];
331 int failed, useoffsets = 0;
332 off_t begin = 0, end = 0; /* To shut compiler warning */
334 const char* progname;
336 if ((progname = strrchr(argv[0], '/')) == NULL)
341 for (digest = 0; digest < sizeof(Algorithm)/sizeof(*Algorithm); digest++)
342 if (strcasecmp(Algorithm[digest].progname, progname) == 0)
345 if (digest == sizeof(Algorithm)/sizeof(*Algorithm))
349 while ((ch = getopt(argc, argv, "hb:e:pqrs:tx")) != -1) {
352 begin = parseint(optarg);
356 end = parseint(optarg);
360 MDFilter(&Algorithm[digest], 1);
370 MDString(&Algorithm[digest], optarg);
373 MDTimeTrial(&Algorithm[digest]);
376 MDTestSuite(&Algorithm[digest]);
390 p = digestfile(*argv, buf, Algorithm + digest,
393 p = Algorithm[digest].File(*argv, buf);
395 /* digestfile() outputs its own diagnostics */
404 printf("%s %s[%jd-%jd]\n",
411 } else if (useoffsets) {
412 printf("%s (%s[%jd-%jd]) = %s\n",
413 Algorithm[digest].name, *argv,
418 printf("%s (%s) = %s\n",
419 Algorithm[digest].name,
424 } else if (!sflag && (optind == 1 || qflag || rflag))
425 MDFilter(&Algorithm[digest], 0);
433 * Digests a string and prints the result.
436 MDString(Algorithm_t *alg, const char *string)
438 size_t len = strlen(string);
439 char buf[HEX_DIGEST_LENGTH];
442 printf("%s\n", alg->Data(string, len, buf));
444 printf("%s \"%s\"\n", alg->Data(string, len, buf), string);
446 printf("%s (\"%s\") = %s\n", alg->name, string, alg->Data(string, len, buf));
449 * Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte blocks.
452 MDTimeTrial(Algorithm_t *alg)
455 struct rusage before, after;
456 struct timeval total;
458 unsigned char block[TEST_BLOCK_LEN];
460 char *p, buf[HEX_DIGEST_LENGTH];
463 ("%s time trial. Digesting %d %d-byte blocks ...",
464 alg->name, TEST_BLOCK_COUNT, TEST_BLOCK_LEN);
467 /* Initialize block */
468 for (i = 0; i < TEST_BLOCK_LEN; i++)
469 block[i] = (unsigned char) (i & 0xff);
472 getrusage(0, &before);
476 for (i = 0; i < TEST_BLOCK_COUNT; i++)
477 alg->Update(&context, block, TEST_BLOCK_LEN);
478 p = alg->End(&context, buf);
481 getrusage(0, &after);
482 timersub(&after.ru_utime, &before.ru_utime, &total);
483 seconds = total.tv_sec + (float) total.tv_usec / 1000000;
486 printf("Digest = %s", p);
487 printf("\nTime = %f seconds\n", seconds);
489 ("Speed = %f bytes/second\n",
490 (float) TEST_BLOCK_LEN * (float) TEST_BLOCK_COUNT / seconds);
493 * Digests a reference suite of strings and prints the results.
496 const char *MDTestInput[MDTESTCOUNT] = {
501 "abcdefghijklmnopqrstuvwxyz",
502 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
503 "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
504 "MD5 has not yet (2001-09-03) been broken, but sufficient attacks have been made \
505 that its security is in some doubt"
508 const char *MD5TestOutput[MDTESTCOUNT] = {
509 "d41d8cd98f00b204e9800998ecf8427e",
510 "0cc175b9c0f1b6a831c399e269772661",
511 "900150983cd24fb0d6963f7d28e17f72",
512 "f96b697d7cb7938d525a2f31aaf161d0",
513 "c3fcd3d76192e4007dfb496cca67e13b",
514 "d174ab98d277d9f5a5611c2c9f419d9f",
515 "57edf4a22be3c955ac49da2e2107b67a",
516 "b50663f41d44d92171cb9976bc118538"
519 const char *SHA256_TestOutput[MDTESTCOUNT] = {
520 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
521 "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb",
522 "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
523 "f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650",
524 "71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73",
525 "db4bfcbd4da0cd85a60c3c37d3fbd8805c77f15fc6b1fdfe614ee0a7c8fdb4c0",
526 "f371bc4a311f2b009eef952dd83ca80e2b60026c8e935592d0f9c308453c813e",
527 "e6eae09f10ad4122a0e2a4075761d185a272ebd9f5aa489e998ff2f09cbfdd9f"
531 MDTestSuite(Algorithm_t *alg)
534 char buffer[HEX_DIGEST_LENGTH];
536 printf("%s test suite:\n", alg->name);
537 for (i = 0; i < MDTESTCOUNT; i++) {
538 (*alg->Data)(MDTestInput[i], strlen(MDTestInput[i]), buffer);
539 printf("%s (\"%s\") = %s", alg->name, MDTestInput[i], buffer);
540 if (strcmp(buffer, (*alg->TestOutput)[i]) == 0)
541 printf(" - verified correct\n");
543 printf(" - INCORRECT RESULT!\n");
548 * Digests the standard input and prints the result.
551 MDFilter(Algorithm_t *alg, int tee)
555 unsigned char buffer[BUFSIZ];
556 char buf[HEX_DIGEST_LENGTH];
559 while ((len = fread(buffer, 1, BUFSIZ, stdin))) {
560 if (tee && len != fwrite(buffer, 1, len, stdout))
562 alg->Update(&context, buffer, len);
564 printf("%s\n", alg->End(&context, buf));
570 fprintf(stderr, "usage:\n\t%s [-pqrtx] [-b offset] [-e offset] "
571 "[-s string] [files ...]\n", getprogname());
576 [FILE:2496:files/md5.h]
578 * Copyright (c) 2016 The DragonFly Project. All rights reserved.
580 * This code is derived from software contributed to The DragonFly Project
581 * by Matthew Dillon <dillon@backplane.com>
583 * Redistribution and use in source and binary forms, with or without
584 * modification, are permitted provided that the following conditions
587 * 1. Redistributions of source code must retain the above copyright
588 * notice, this list of conditions and the following disclaimer.
589 * 2. Redistributions in binary form must reproduce the above copyright
590 * notice, this list of conditions and the following disclaimer in
591 * the documentation and/or other materials provided with the
593 * 3. Neither the name of The DragonFly Project nor the names of its
594 * contributors may be used to endorse or promote products derived
595 * from this software without specific, prior written permission.
597 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
598 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
599 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
600 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
601 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
602 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
603 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
604 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
605 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
606 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
607 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
611 * libmd shims for openssl + non-conflicting old API functions.
618 #define u_int32_t uint32_t
620 #include <sys/cdefs.h>
621 #include <sys/types.h>
622 #include <openssl/md5.h>
624 #define MD5_BLOCK_LENGTH MD5_CBLOCK
625 #define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_LENGTH * 2 + 1)
628 int MD5Init (MD5_CTX *);
629 void MD5Update (MD5_CTX *, const void *, unsigned int);
630 void MD5Pad (MD5_CTX *);
631 void MD5Final (unsigned char [16], MD5_CTX *);
632 char *MD5End(MD5_CTX *, char *);
633 char *MD5File(const char *, char *);
634 char *MD5FileChunk(const char *, char *, off_t, off_t);
635 char *MD5Data(const void *, unsigned int, char *);
636 void MD5Transform (u_int32_t [4], const unsigned char [64]);
642 [FILE:9514:files/md5c.c]
644 * MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
646 * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
649 * License to copy and use this software is granted provided that it
650 * is identified as the "RSA Data Security, Inc. MD5 Message-Digest
651 * Algorithm" in all material mentioning or referencing this software
654 * License is also granted to make and use derivative works provided
655 * that such works are identified as "derived from the RSA Data
656 * Security, Inc. MD5 Message-Digest Algorithm" in all material
657 * mentioning or referencing the derived work.
659 * RSA Data Security, Inc. makes no representations concerning either
660 * the merchantability of this software or the suitability of this
661 * software for any particular purpose. It is provided "as is"
662 * without express or implied warranty of any kind.
664 * These notices must be retained in any copies of any part of this
665 * documentation and/or software.
667 * $FreeBSD: src/lib/libmd/md5c.c,v 1.17 2006/01/17 15:35:56 phk Exp $
669 * This code is the same as the code published by RSA Inc. It has been
670 * edited for clarity and style only.
673 #include <sys/types.h>
676 static unsigned char PADDING[64] = {
677 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
678 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
679 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
683 #include <sys/cdefs.h>
686 #elif defined __sun__
687 #define u_int32_t uint32_t
689 #include <machine/endian.h>
691 #include <sys/endian.h>
696 #if (BYTE_ORDER == LITTLE_ENDIAN)
697 #define Encode memcpy
698 #define Decode memcpy
702 * Encodes input (u_int32_t) into output (unsigned char). Assumes len is
707 Encode (unsigned char *output, u_int32_t *input, unsigned int len)
710 u_int32_t *op = (u_int32_t *)output;
712 for (i = 0; i < len / 4; i++)
713 op[i] = htole32(input[i]);
717 * Decodes input (unsigned char) into output (u_int32_t). Assumes len is
722 Decode (u_int32_t *output, const unsigned char *input, unsigned int len)
725 const u_int32_t *ip = (const u_int32_t *)input;
727 for (i = 0; i < len / 4; i++)
728 output[i] = le32toh(ip[i]);
732 /* F, G, H and I are basic MD5 functions. */
733 #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
734 #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
735 #define H(x, y, z) ((x) ^ (y) ^ (z))
736 #define I(x, y, z) ((y) ^ ((x) | (~z)))
738 /* ROTATE_LEFT rotates x left n bits. */
739 #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
742 * FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
743 * Rotation is separate from addition to prevent recomputation.
745 #define FF(a, b, c, d, x, s, ac) { \
746 (a) += F ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
747 (a) = ROTATE_LEFT ((a), (s)); \
750 #define GG(a, b, c, d, x, s, ac) { \
751 (a) += G ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
752 (a) = ROTATE_LEFT ((a), (s)); \
755 #define HH(a, b, c, d, x, s, ac) { \
756 (a) += H ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
757 (a) = ROTATE_LEFT ((a), (s)); \
760 #define II(a, b, c, d, x, s, ac) { \
761 (a) += I ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
762 (a) = ROTATE_LEFT ((a), (s)); \
766 /* MD5 initialization. Begins an MD5 operation, writing a new context. */
769 MD5Init (MD5_CTX *context)
772 context->Nl = context->Nh = 0;
774 /* Load magic initialization constants. */
775 context->A = 0x67452301;
776 context->B = 0xefcdab89;
777 context->C = 0x98badcfe;
778 context->D = 0x10325476;
783 * MD5 block update operation. Continues an MD5 message-digest
784 * operation, processing another message block, and updating the
789 MD5Update (MD5_CTX *context, const void *in, unsigned int inputLen)
791 unsigned int i, idx, partLen;
792 const unsigned char *input = in;
794 /* Compute number of bytes mod 64 */
795 idx = (unsigned int)((context->Nl >> 3) & 0x3F);
797 /* Update number of bits */
798 if ((context->Nl += ((u_int32_t)inputLen << 3))
799 < ((u_int32_t)inputLen << 3))
801 context->Nh += ((u_int32_t)inputLen >> 29);
805 /* Transform as many times as possible. */
806 if (inputLen >= partLen) {
807 memcpy(&((char *)context->data)[idx], (const void *)input,
809 MD5Transform (&context->A, (char *)context->data);
811 for (i = partLen; i + 63 < inputLen; i += 64)
812 MD5Transform (&context->A, &input[i]);
819 /* Buffer remaining input */
820 memcpy (&((char *)context->data)[idx], (const void *)&input[i],
825 * MD5 padding. Adds padding followed by original length.
829 MD5Pad (MD5_CTX *context)
831 unsigned char bits[8];
832 unsigned int idx, padLen;
834 /* Save number of bits */
835 Encode (bits, &context->Nl, 8);
837 /* Pad out to 56 mod 64. */
838 idx = (unsigned int)((context->Nl >> 3) & 0x3f);
839 padLen = (idx < 56) ? (56 - idx) : (120 - idx);
840 MD5Update (context, PADDING, padLen);
842 /* Append length (before padding) */
843 MD5Update (context, bits, 8);
847 * MD5 finalization. Ends an MD5 message-digest operation, writing the
848 * the message digest and zeroizing the context.
852 MD5Final (unsigned char digest[16], MD5_CTX *context)
857 /* Store state in digest */
858 Encode (digest, &context->A, 16);
860 /* Zeroize sensitive information. */
861 memset ((void *)context, 0, sizeof (*context));
864 /* MD5 basic transformation. Transforms state based on block. */
867 MD5Transform (u_int32_t *state, const unsigned char *block)
869 u_int32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16];
871 Decode (x, block, 64);
878 FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
879 FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
880 FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
881 FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
882 FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
883 FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
884 FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
885 FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
886 FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
887 FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
888 FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
889 FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
890 FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
891 FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
892 FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
893 FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
900 GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
901 GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
902 GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
903 GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
904 GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
905 GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
906 GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
907 GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
908 GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
909 GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
910 GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
911 GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
912 GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
913 GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
914 GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
915 GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
922 HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
923 HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
924 HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
925 HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
926 HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
927 HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
928 HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
929 HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
930 HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
931 HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
932 HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
933 HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
934 HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
935 HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
936 HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
937 HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
944 II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
945 II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
946 II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
947 II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
948 II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
949 II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
950 II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
951 II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
952 II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
953 II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
954 II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
955 II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
956 II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
957 II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
958 II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
959 II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
966 /* Zeroize sensitive information. */
967 memset ((void *)x, 0, sizeof (x));
971 [FILE:2120:files/mdXhl.c]
972 /* mdXhl.c * ----------------------------------------------------------------------------
973 * "THE BEER-WARE LICENSE" (Revision 42):
974 * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
975 * can do whatever you want with this stuff. If we meet some day, and you think
976 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
977 * ----------------------------------------------------------------------------
979 * $FreeBSD: src/lib/libmd/mdXhl.c,v 1.19 2006/01/17 15:35:56 phk Exp $
980 * $DragonFly: src/lib/libmd/mdXhl.c,v 1.3 2008/09/11 20:25:34 swildner Exp $
984 #include <sys/types.h>
985 #include <sys/stat.h>
996 MDXEnd(MDX_CTX *ctx, char *buf)
999 unsigned char digest[LENGTH];
1000 static const char hex[]="0123456789abcdef";
1003 buf = malloc(2*LENGTH + 1);
1006 MDXFinal(digest, ctx);
1007 for (i = 0; i < LENGTH; i++) {
1008 buf[i+i] = hex[digest[i] >> 4];
1009 buf[i+i+1] = hex[digest[i] & 0x0f];
1016 MDXFile(const char *filename, char *buf)
1018 return (MDXFileChunk(filename, buf, 0, 0));
1022 MDXFileChunk(const char *filename, char *buf, off_t ofs, off_t len)
1024 unsigned char buffer[8192];
1031 f = open(filename, O_RDONLY);
1034 if (fstat(f, &stbuf) < 0)
1036 if (ofs > stbuf.st_size)
1037 ofs = stbuf.st_size;
1038 if ((len == 0) || (len > stbuf.st_size - ofs))
1039 len = stbuf.st_size - ofs;
1040 if (lseek(f, ofs, SEEK_SET) < 0)
1045 if (n > sizeof(buffer))
1046 i = read(f, buffer, sizeof(buffer));
1048 i = read(f, buffer, n);
1051 MDXUpdate(&ctx, buffer, i);
1059 return (MDXEnd(&ctx, buf));
1063 MDXData (const void *data, unsigned int len, char *buf)
1068 MDXUpdate(&ctx,data,len);
1069 return (MDXEnd(&ctx, buf));
1073 [FILE:2136:files/sha256.h]
1075 * Copyright (c) 2016 The DragonFly Project. All rights reserved.
1077 * This code is derived from software contributed to The DragonFly Project
1078 * by Matthew Dillon <dillon@backplane.com>
1080 * Redistribution and use in source and binary forms, with or without
1081 * modification, are permitted provided that the following conditions
1084 * 1. Redistributions of source code must retain the above copyright
1085 * notice, this list of conditions and the following disclaimer.
1086 * 2. Redistributions in binary form must reproduce the above copyright
1087 * notice, this list of conditions and the following disclaimer in
1088 * the documentation and/or other materials provided with the
1090 * 3. Neither the name of The DragonFly Project nor the names of its
1091 * contributors may be used to endorse or promote products derived
1092 * from this software without specific, prior written permission.
1094 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1095 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1096 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
1097 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
1098 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
1099 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
1100 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1101 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
1102 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1103 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
1104 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1108 * libmd shims for openssl + non-conflicting old API functions.
1113 #include <sys/cdefs.h>
1114 #include <sys/types.h>
1115 #include <openssl/sha.h>
1118 char *SHA256_End(SHA256_CTX *, char *);
1119 char *SHA256_File(const char *, char *);
1120 char *SHA256_FileChunk(const char *, char *, off_t, off_t);
1121 char *SHA256_Data(const void *, unsigned int, char *);