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:984: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}/lib/libcrypto.a
47 CFLAGS= -I${PREFIX}/include -I.
49 .if "${OPSYS}" == "Linux"
50 LIBS+= ${PREFIX}/lib/libbsd.a
52 .if "${OPSYS}" == "SunOS"
53 LIBS+= ${PREFIX}/lib/libbsd.a
54 CFLAGS+= -I${PREFIX}/include/bsd
59 ${OBJS}: ${.TARGET:.o=.c}
60 ${CC} -c ${.ALLSRC} ${CFLAGS}
63 (echo '#define LENGTH 16'; \
64 sed -e 's/mdX/md5/g' -e 's/MDX/MD5/g' ${.ALLSRC}) > ${.TARGET}
67 (echo '#define LENGTH 32'; \
68 sed -e 's/mdX/sha256/g' -e 's/MDX/SHA256_/g' \
69 -e 's/SHA256__/SHA256_/g' \
70 ${.ALLSRC}) > ${.TARGET}
72 program: ${OBJS} main.c
73 ${CC} -o md5 main.c ${OBJS} ${CFLAGS} ${LIBS}
77 ${BSD_INSTALL_PROGRAM} md5 ${DESTDIR}${PREFIX}/bin/
78 ${BSD_INSTALL_PROGRAM} sha256 ${DESTDIR}${PREFIX}/bin/
81 rm -f md5hl.c sha256hl.c md5 sha256 ${OBJS}
84 [FILE:11644:files/main.c]
88 * MDDRIVER.C - test driver for MD2, MD4 and MD5
90 * $FreeBSD: src/sbin/md5/md5.c,v 1.35 2006/01/17 15:35:57 phk Exp $
94 * Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
97 * RSA Data Security, Inc. makes no representations concerning either
98 * the merchantability of this software or the suitability of this
99 * software for any particular purpose. It is provided "as is"
100 * without express or implied warranty of any kind.
102 * These notices must be retained in any copies of any part of this
103 * documentation and/or software.
107 #include <sys/types.h>
108 #include <sys/stat.h>
109 #include <sys/time.h>
110 #include <sys/resource.h>
112 #include <sys/mman.h>
118 #include <sysexits.h>
121 #include <bsd/stdlib.h>
131 * Length of test block, number of test blocks.
133 #define TEST_BLOCK_LEN 10000
134 #define TEST_BLOCK_COUNT 100000
135 #define MDTESTCOUNT 8
141 typedef void (DIGEST_Init)(void *);
142 typedef void (DIGEST_Update)(void *, const unsigned char *, size_t);
143 typedef char *(DIGEST_End)(void *, char *);
145 extern const char *MD5TestOutput[MDTESTCOUNT];
146 extern const char *SHA256_TestOutput[MDTESTCOUNT];
148 typedef struct Algorithm_t {
149 const char *progname;
151 const char *(*TestOutput)[MDTESTCOUNT];
153 DIGEST_Update *Update;
155 char *(*Data)(const void *, unsigned int, char *);
156 char *(*File)(const char *, char *);
159 static void MDString(Algorithm_t *, const char *);
160 static void MDTimeTrial(Algorithm_t *);
161 static void MDTestSuite(Algorithm_t *);
162 static void MDFilter(Algorithm_t *, int);
163 static void usage(int excode);
170 /* max(MD5_DIGEST_LENGTH, SHA_DIGEST_LENGTH,
171 SHA256_DIGEST_LENGTH, RIPEMD160_DIGEST_LENGTH)*2+1 */
172 #define HEX_DIGEST_LENGTH 65
174 /* algorithm function table */
176 struct Algorithm_t Algorithm[] = {
177 { "md5", "MD5", &MD5TestOutput, (DIGEST_Init*)&MD5Init,
178 (DIGEST_Update*)&MD5Update, (DIGEST_End*)&MD5End,
179 &MD5Data, &MD5File },
180 { "sha256", "SHA256", &SHA256_TestOutput, (DIGEST_Init*)&SHA256_Init,
181 (DIGEST_Update*)&SHA256_Update, (DIGEST_End*)&SHA256_End,
182 &SHA256_Data, &SHA256_File }
186 * There is no need to use a huge mmap, just pick something
189 #define MAXMMAP (32*1024*1024)
192 digestfile(const char *fname, char *buf, const Algorithm_t *alg,
193 off_t *beginp, off_t *endp)
201 off_t end = *endp, begin = *beginp;
204 fd = open(fname, O_RDONLY);
206 warn("can't open %s", fname);
210 if (fstat(fd, &st) == -1) {
211 warn("can't fstat %s after opening", fname);
215 /* Non-positive end means, it has to be counted from the back: */
218 /* Negative begin means, it has to be counted from the back: */
222 if (begin < 0 || end < 0 || begin > st.st_size || end > st.st_size) {
223 warnx("%s is %jd bytes long, not large enough for the "
224 "specified offsets [%jd-%jd]", fname,
225 (intmax_t)st.st_size,
226 (intmax_t)*beginp, (intmax_t)*endp);
230 warnx("%s is %jd bytes long. Begin-offset %jd (%jd) is "
231 "larger than end-offset %jd (%jd)",
232 fname, (intmax_t)st.st_size,
233 (intmax_t)begin, (intmax_t)*beginp,
234 (intmax_t)end, (intmax_t)*endp);
243 pagesize = getpagesize();
248 if (end - begin > MAXMMAP)
253 #if defined __linux__ || defined __sun__
254 map = mmap(NULL, size, PROT_READ, 0, fd, begin);
256 map = mmap(NULL, size, PROT_READ, MAP_NOCORE, fd, begin);
258 if (map == MAP_FAILED) {
259 warn("mmaping of %s between %jd and %jd ",
260 fname, (intmax_t)begin, (intmax_t)begin + size);
264 * Try to give kernel a hint. Not that it
265 * cares at the time of this writing :-(
268 madvise(map, size, MADV_SEQUENTIAL);
269 alg->Update(&context, map, size);
272 } while (begin < end);
274 result = alg->End(&context, buf);
282 parseint(const char *arg)
284 double result; /* Use double to allow things like 0.5Kb */
287 result = strtod(arg, &endp);
291 result *= 1024; /* FALLTHROUGH */
294 result *= 1024; /* FALLTHROUGH */
298 if (endp[1] == 'b' || endp[1] == 'B')
300 result *= 1024; /* FALLTHROUGH */
304 warnx("%c (%d): unrecognized suffix", endp[0], (int)endp[0]);
312 errx(EX_USAGE, "`%s' is not a valid offset.", arg);
317 Arguments (may be any combination):
318 -sstring - digests string
320 -x - runs test script
321 filename - digests file
322 (none) - digests standard input
325 main(int argc, char *argv[])
329 char buf[HEX_DIGEST_LENGTH];
330 int failed, useoffsets = 0;
331 off_t begin = 0, end = 0; /* To shut compiler warning */
333 const char* progname;
335 if ((progname = strrchr(argv[0], '/')) == NULL)
340 for (digest = 0; digest < sizeof(Algorithm)/sizeof(*Algorithm); digest++)
341 if (strcasecmp(Algorithm[digest].progname, progname) == 0)
344 if (digest == sizeof(Algorithm)/sizeof(*Algorithm))
348 while ((ch = getopt(argc, argv, "hb:e:pqrs:tx")) != -1) {
351 begin = parseint(optarg);
355 end = parseint(optarg);
359 MDFilter(&Algorithm[digest], 1);
369 MDString(&Algorithm[digest], optarg);
372 MDTimeTrial(&Algorithm[digest]);
375 MDTestSuite(&Algorithm[digest]);
389 p = digestfile(*argv, buf, Algorithm + digest,
392 p = Algorithm[digest].File(*argv, buf);
394 /* digestfile() outputs its own diagnostics */
403 printf("%s %s[%jd-%jd]\n",
410 } else if (useoffsets) {
411 printf("%s (%s[%jd-%jd]) = %s\n",
412 Algorithm[digest].name, *argv,
417 printf("%s (%s) = %s\n",
418 Algorithm[digest].name,
423 } else if (!sflag && (optind == 1 || qflag || rflag))
424 MDFilter(&Algorithm[digest], 0);
432 * Digests a string and prints the result.
435 MDString(Algorithm_t *alg, const char *string)
437 size_t len = strlen(string);
438 char buf[HEX_DIGEST_LENGTH];
441 printf("%s\n", alg->Data(string, len, buf));
443 printf("%s \"%s\"\n", alg->Data(string, len, buf), string);
445 printf("%s (\"%s\") = %s\n", alg->name, string, alg->Data(string, len, buf));
448 * Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte blocks.
451 MDTimeTrial(Algorithm_t *alg)
454 struct rusage before, after;
455 struct timeval total;
457 unsigned char block[TEST_BLOCK_LEN];
459 char *p, buf[HEX_DIGEST_LENGTH];
462 ("%s time trial. Digesting %d %d-byte blocks ...",
463 alg->name, TEST_BLOCK_COUNT, TEST_BLOCK_LEN);
466 /* Initialize block */
467 for (i = 0; i < TEST_BLOCK_LEN; i++)
468 block[i] = (unsigned char) (i & 0xff);
471 getrusage(0, &before);
475 for (i = 0; i < TEST_BLOCK_COUNT; i++)
476 alg->Update(&context, block, TEST_BLOCK_LEN);
477 p = alg->End(&context, buf);
480 getrusage(0, &after);
481 timersub(&after.ru_utime, &before.ru_utime, &total);
482 seconds = total.tv_sec + (float) total.tv_usec / 1000000;
485 printf("Digest = %s", p);
486 printf("\nTime = %f seconds\n", seconds);
488 ("Speed = %f bytes/second\n",
489 (float) TEST_BLOCK_LEN * (float) TEST_BLOCK_COUNT / seconds);
492 * Digests a reference suite of strings and prints the results.
495 const char *MDTestInput[MDTESTCOUNT] = {
500 "abcdefghijklmnopqrstuvwxyz",
501 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
502 "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
503 "MD5 has not yet (2001-09-03) been broken, but sufficient attacks have been made \
504 that its security is in some doubt"
507 const char *MD5TestOutput[MDTESTCOUNT] = {
508 "d41d8cd98f00b204e9800998ecf8427e",
509 "0cc175b9c0f1b6a831c399e269772661",
510 "900150983cd24fb0d6963f7d28e17f72",
511 "f96b697d7cb7938d525a2f31aaf161d0",
512 "c3fcd3d76192e4007dfb496cca67e13b",
513 "d174ab98d277d9f5a5611c2c9f419d9f",
514 "57edf4a22be3c955ac49da2e2107b67a",
515 "b50663f41d44d92171cb9976bc118538"
518 const char *SHA256_TestOutput[MDTESTCOUNT] = {
519 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
520 "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb",
521 "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
522 "f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650",
523 "71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73",
524 "db4bfcbd4da0cd85a60c3c37d3fbd8805c77f15fc6b1fdfe614ee0a7c8fdb4c0",
525 "f371bc4a311f2b009eef952dd83ca80e2b60026c8e935592d0f9c308453c813e",
526 "e6eae09f10ad4122a0e2a4075761d185a272ebd9f5aa489e998ff2f09cbfdd9f"
530 MDTestSuite(Algorithm_t *alg)
533 char buffer[HEX_DIGEST_LENGTH];
535 printf("%s test suite:\n", alg->name);
536 for (i = 0; i < MDTESTCOUNT; i++) {
537 (*alg->Data)(MDTestInput[i], strlen(MDTestInput[i]), buffer);
538 printf("%s (\"%s\") = %s", alg->name, MDTestInput[i], buffer);
539 if (strcmp(buffer, (*alg->TestOutput)[i]) == 0)
540 printf(" - verified correct\n");
542 printf(" - INCORRECT RESULT!\n");
547 * Digests the standard input and prints the result.
550 MDFilter(Algorithm_t *alg, int tee)
554 unsigned char buffer[BUFSIZ];
555 char buf[HEX_DIGEST_LENGTH];
558 while ((len = fread(buffer, 1, BUFSIZ, stdin))) {
559 if (tee && len != fwrite(buffer, 1, len, stdout))
561 alg->Update(&context, buffer, len);
563 printf("%s\n", alg->End(&context, buf));
569 fprintf(stderr, "usage:\n\t%s [-pqrtx] [-b offset] [-e offset] "
570 "[-s string] [files ...]\n", getprogname());
575 [FILE:2496:files/md5.h]
577 * Copyright (c) 2016 The DragonFly Project. All rights reserved.
579 * This code is derived from software contributed to The DragonFly Project
580 * by Matthew Dillon <dillon@backplane.com>
582 * Redistribution and use in source and binary forms, with or without
583 * modification, are permitted provided that the following conditions
586 * 1. Redistributions of source code must retain the above copyright
587 * notice, this list of conditions and the following disclaimer.
588 * 2. Redistributions in binary form must reproduce the above copyright
589 * notice, this list of conditions and the following disclaimer in
590 * the documentation and/or other materials provided with the
592 * 3. Neither the name of The DragonFly Project nor the names of its
593 * contributors may be used to endorse or promote products derived
594 * from this software without specific, prior written permission.
596 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
597 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
598 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
599 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
600 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
601 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
602 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
603 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
604 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
605 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
606 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
610 * libmd shims for openssl + non-conflicting old API functions.
617 #define u_int32_t uint32_t
619 #include <sys/cdefs.h>
620 #include <sys/types.h>
621 #include <openssl/md5.h>
623 #define MD5_BLOCK_LENGTH MD5_CBLOCK
624 #define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_LENGTH * 2 + 1)
627 int MD5Init (MD5_CTX *);
628 void MD5Update (MD5_CTX *, const void *, unsigned int);
629 void MD5Pad (MD5_CTX *);
630 void MD5Final (unsigned char [16], MD5_CTX *);
631 char *MD5End(MD5_CTX *, char *);
632 char *MD5File(const char *, char *);
633 char *MD5FileChunk(const char *, char *, off_t, off_t);
634 char *MD5Data(const void *, unsigned int, char *);
635 void MD5Transform (u_int32_t [4], const unsigned char [64]);
641 [FILE:9487:files/md5c.c]
643 * MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
645 * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
648 * License to copy and use this software is granted provided that it
649 * is identified as the "RSA Data Security, Inc. MD5 Message-Digest
650 * Algorithm" in all material mentioning or referencing this software
653 * License is also granted to make and use derivative works provided
654 * that such works are identified as "derived from the RSA Data
655 * Security, Inc. MD5 Message-Digest Algorithm" in all material
656 * mentioning or referencing the derived work.
658 * RSA Data Security, Inc. makes no representations concerning either
659 * the merchantability of this software or the suitability of this
660 * software for any particular purpose. It is provided "as is"
661 * without express or implied warranty of any kind.
663 * These notices must be retained in any copies of any part of this
664 * documentation and/or software.
666 * $FreeBSD: src/lib/libmd/md5c.c,v 1.17 2006/01/17 15:35:56 phk Exp $
668 * This code is the same as the code published by RSA Inc. It has been
669 * edited for clarity and style only.
672 #include <sys/types.h>
675 static unsigned char PADDING[64] = {
676 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
677 0, 0, 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
682 #include <sys/cdefs.h>
685 #elif defined __sun__
686 #define u_int32_t uint32_t
688 #include <machine/endian.h>
689 #include <sys/endian.h>
693 #if (BYTE_ORDER == LITTLE_ENDIAN)
694 #define Encode memcpy
695 #define Decode memcpy
699 * Encodes input (u_int32_t) into output (unsigned char). Assumes len is
704 Encode (unsigned char *output, u_int32_t *input, unsigned int len)
707 u_int32_t *op = (u_int32_t *)output;
709 for (i = 0; i < len / 4; i++)
710 op[i] = htole32(input[i]);
714 * Decodes input (unsigned char) into output (u_int32_t). Assumes len is
719 Decode (u_int32_t *output, const unsigned char *input, unsigned int len)
722 const u_int32_t *ip = (const u_int32_t *)input;
724 for (i = 0; i < len / 4; i++)
725 output[i] = le32toh(ip[i]);
729 /* F, G, H and I are basic MD5 functions. */
730 #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
731 #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
732 #define H(x, y, z) ((x) ^ (y) ^ (z))
733 #define I(x, y, z) ((y) ^ ((x) | (~z)))
735 /* ROTATE_LEFT rotates x left n bits. */
736 #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
739 * FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
740 * Rotation is separate from addition to prevent recomputation.
742 #define FF(a, b, c, d, x, s, ac) { \
743 (a) += F ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
744 (a) = ROTATE_LEFT ((a), (s)); \
747 #define GG(a, b, c, d, x, s, ac) { \
748 (a) += G ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
749 (a) = ROTATE_LEFT ((a), (s)); \
752 #define HH(a, b, c, d, x, s, ac) { \
753 (a) += H ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
754 (a) = ROTATE_LEFT ((a), (s)); \
757 #define II(a, b, c, d, x, s, ac) { \
758 (a) += I ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
759 (a) = ROTATE_LEFT ((a), (s)); \
763 /* MD5 initialization. Begins an MD5 operation, writing a new context. */
766 MD5Init (MD5_CTX *context)
769 context->Nl = context->Nh = 0;
771 /* Load magic initialization constants. */
772 context->A = 0x67452301;
773 context->B = 0xefcdab89;
774 context->C = 0x98badcfe;
775 context->D = 0x10325476;
780 * MD5 block update operation. Continues an MD5 message-digest
781 * operation, processing another message block, and updating the
786 MD5Update (MD5_CTX *context, const void *in, unsigned int inputLen)
788 unsigned int i, idx, partLen;
789 const unsigned char *input = in;
791 /* Compute number of bytes mod 64 */
792 idx = (unsigned int)((context->Nl >> 3) & 0x3F);
794 /* Update number of bits */
795 if ((context->Nl += ((u_int32_t)inputLen << 3))
796 < ((u_int32_t)inputLen << 3))
798 context->Nh += ((u_int32_t)inputLen >> 29);
802 /* Transform as many times as possible. */
803 if (inputLen >= partLen) {
804 memcpy(&((char *)context->data)[idx], (const void *)input,
806 MD5Transform (&context->A, (char *)context->data);
808 for (i = partLen; i + 63 < inputLen; i += 64)
809 MD5Transform (&context->A, &input[i]);
816 /* Buffer remaining input */
817 memcpy (&((char *)context->data)[idx], (const void *)&input[i],
822 * MD5 padding. Adds padding followed by original length.
826 MD5Pad (MD5_CTX *context)
828 unsigned char bits[8];
829 unsigned int idx, padLen;
831 /* Save number of bits */
832 Encode (bits, &context->Nl, 8);
834 /* Pad out to 56 mod 64. */
835 idx = (unsigned int)((context->Nl >> 3) & 0x3f);
836 padLen = (idx < 56) ? (56 - idx) : (120 - idx);
837 MD5Update (context, PADDING, padLen);
839 /* Append length (before padding) */
840 MD5Update (context, bits, 8);
844 * MD5 finalization. Ends an MD5 message-digest operation, writing the
845 * the message digest and zeroizing the context.
849 MD5Final (unsigned char digest[16], MD5_CTX *context)
854 /* Store state in digest */
855 Encode (digest, &context->A, 16);
857 /* Zeroize sensitive information. */
858 memset ((void *)context, 0, sizeof (*context));
861 /* MD5 basic transformation. Transforms state based on block. */
864 MD5Transform (u_int32_t *state, const unsigned char *block)
866 u_int32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16];
868 Decode (x, block, 64);
875 FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
876 FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
877 FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
878 FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
879 FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
880 FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
881 FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
882 FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
883 FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
884 FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
885 FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
886 FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
887 FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
888 FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
889 FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
890 FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
897 GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
898 GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
899 GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
900 GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
901 GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
902 GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
903 GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
904 GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
905 GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
906 GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
907 GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
908 GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
909 GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
910 GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
911 GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
912 GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
919 HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
920 HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
921 HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
922 HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
923 HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
924 HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
925 HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
926 HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
927 HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
928 HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
929 HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
930 HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
931 HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
932 HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
933 HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
934 HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
941 II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
942 II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
943 II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
944 II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
945 II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
946 II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
947 II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
948 II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
949 II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
950 II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
951 II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
952 II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
953 II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
954 II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
955 II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
956 II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
963 /* Zeroize sensitive information. */
964 memset ((void *)x, 0, sizeof (x));
968 [FILE:2120:files/mdXhl.c]
969 /* mdXhl.c * ----------------------------------------------------------------------------
970 * "THE BEER-WARE LICENSE" (Revision 42):
971 * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
972 * can do whatever you want with this stuff. If we meet some day, and you think
973 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
974 * ----------------------------------------------------------------------------
976 * $FreeBSD: src/lib/libmd/mdXhl.c,v 1.19 2006/01/17 15:35:56 phk Exp $
977 * $DragonFly: src/lib/libmd/mdXhl.c,v 1.3 2008/09/11 20:25:34 swildner Exp $
981 #include <sys/types.h>
982 #include <sys/stat.h>
993 MDXEnd(MDX_CTX *ctx, char *buf)
996 unsigned char digest[LENGTH];
997 static const char hex[]="0123456789abcdef";
1000 buf = malloc(2*LENGTH + 1);
1003 MDXFinal(digest, ctx);
1004 for (i = 0; i < LENGTH; i++) {
1005 buf[i+i] = hex[digest[i] >> 4];
1006 buf[i+i+1] = hex[digest[i] & 0x0f];
1013 MDXFile(const char *filename, char *buf)
1015 return (MDXFileChunk(filename, buf, 0, 0));
1019 MDXFileChunk(const char *filename, char *buf, off_t ofs, off_t len)
1021 unsigned char buffer[8192];
1028 f = open(filename, O_RDONLY);
1031 if (fstat(f, &stbuf) < 0)
1033 if (ofs > stbuf.st_size)
1034 ofs = stbuf.st_size;
1035 if ((len == 0) || (len > stbuf.st_size - ofs))
1036 len = stbuf.st_size - ofs;
1037 if (lseek(f, ofs, SEEK_SET) < 0)
1042 if (n > sizeof(buffer))
1043 i = read(f, buffer, sizeof(buffer));
1045 i = read(f, buffer, n);
1048 MDXUpdate(&ctx, buffer, i);
1056 return (MDXEnd(&ctx, buf));
1060 MDXData (const void *data, unsigned int len, char *buf)
1065 MDXUpdate(&ctx,data,len);
1066 return (MDXEnd(&ctx, buf));
1070 [FILE:2136:files/sha256.h]
1072 * Copyright (c) 2016 The DragonFly Project. All rights reserved.
1074 * This code is derived from software contributed to The DragonFly Project
1075 * by Matthew Dillon <dillon@backplane.com>
1077 * Redistribution and use in source and binary forms, with or without
1078 * modification, are permitted provided that the following conditions
1081 * 1. Redistributions of source code must retain the above copyright
1082 * notice, this list of conditions and the following disclaimer.
1083 * 2. Redistributions in binary form must reproduce the above copyright
1084 * notice, this list of conditions and the following disclaimer in
1085 * the documentation and/or other materials provided with the
1087 * 3. Neither the name of The DragonFly Project nor the names of its
1088 * contributors may be used to endorse or promote products derived
1089 * from this software without specific, prior written permission.
1091 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1092 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1093 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
1094 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
1095 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
1096 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
1097 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1098 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
1099 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1100 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
1101 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1105 * libmd shims for openssl + non-conflicting old API functions.
1110 #include <sys/cdefs.h>
1111 #include <sys/types.h>
1112 #include <openssl/sha.h>
1115 char *SHA256_End(SHA256_CTX *, char *);
1116 char *SHA256_File(const char *, char *);
1117 char *SHA256_FileChunk(const char *, char *, off_t, off_t);
1118 char *SHA256_Data(const void *, unsigned int, char *);