diff options
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/Makefile.in | 5 | ||||
| -rw-r--r-- | lib-src/make-fingerprint.c | 113 |
2 files changed, 117 insertions, 1 deletions
diff --git a/lib-src/Makefile.in b/lib-src/Makefile.in index 9c74d8eee44..387a6e33249 100644 --- a/lib-src/Makefile.in +++ b/lib-src/Makefile.in | |||
| @@ -167,7 +167,7 @@ UTILITIES = profile${EXEEXT} hexl${EXEEXT} \ | |||
| 167 | $(if $(with_mailutils), , movemail${EXEEXT}) \ | 167 | $(if $(with_mailutils), , movemail${EXEEXT}) \ |
| 168 | $(and $(use_gamedir), update-game-score${EXEEXT}) | 168 | $(and $(use_gamedir), update-game-score${EXEEXT}) |
| 169 | 169 | ||
| 170 | DONT_INSTALL= make-docfile${EXEEXT} | 170 | DONT_INSTALL= make-docfile${EXEEXT} make-fingerprint${EXEEXT} |
| 171 | 171 | ||
| 172 | # Like UTILITIES, but they're not system-dependent, and should not be | 172 | # Like UTILITIES, but they're not system-dependent, and should not be |
| 173 | # deleted by the distclean target. | 173 | # deleted by the distclean target. |
| @@ -385,6 +385,9 @@ profile${EXEEXT}: ${srcdir}/profile.c $(NTLIB) $(config_h) | |||
| 385 | make-docfile${EXEEXT}: ${srcdir}/make-docfile.c $(NTLIB) $(config_h) | 385 | make-docfile${EXEEXT}: ${srcdir}/make-docfile.c $(NTLIB) $(config_h) |
| 386 | $(AM_V_CCLD)$(CC) ${ALL_CFLAGS} $< $(NTLIB) $(LOADLIBES) -o $@ | 386 | $(AM_V_CCLD)$(CC) ${ALL_CFLAGS} $< $(NTLIB) $(LOADLIBES) -o $@ |
| 387 | 387 | ||
| 388 | make-fingerprint${EXEEXT}: ${srcdir}/make-fingerprint.c $(NTLIB) $(config_h) | ||
| 389 | $(AM_V_CCLD)$(CC) ${ALL_CFLAGS} $< $(NTLIB) $(LOADLIBES) -o $@ | ||
| 390 | |||
| 388 | movemail${EXEEXT}: ${srcdir}/movemail.c pop.o $(NTLIB) $(config_h) | 391 | movemail${EXEEXT}: ${srcdir}/movemail.c pop.o $(NTLIB) $(config_h) |
| 389 | $(AM_V_CCLD)$(CC) ${ALL_CFLAGS} ${MOVE_FLAGS} $< pop.o \ | 392 | $(AM_V_CCLD)$(CC) ${ALL_CFLAGS} ${MOVE_FLAGS} $< pop.o \ |
| 390 | $(NTLIB) $(LOADLIBES) $(LIBS_MOVE) -o $@ | 393 | $(NTLIB) $(LOADLIBES) $(LIBS_MOVE) -o $@ |
diff --git a/lib-src/make-fingerprint.c b/lib-src/make-fingerprint.c new file mode 100644 index 00000000000..69558a818e2 --- /dev/null +++ b/lib-src/make-fingerprint.c | |||
| @@ -0,0 +1,113 @@ | |||
| 1 | /* Hash inputs and generate C file with the digest. | ||
| 2 | |||
| 3 | Copyright (C) 1985-1986, 1992-1994, 1997, 1999-2016 Free Software | ||
| 4 | Foundation, Inc. | ||
| 5 | |||
| 6 | This file is part of GNU Emacs. | ||
| 7 | |||
| 8 | GNU Emacs is free software: you can redistribute it and/or modify | ||
| 9 | it under the terms of the GNU General Public License as published by | ||
| 10 | the Free Software Foundation, either version 3 of the License, or (at | ||
| 11 | your option) any later version. | ||
| 12 | |||
| 13 | GNU Emacs is distributed in the hope that it will be useful, | ||
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | GNU General Public License for more details. | ||
| 17 | |||
| 18 | You should have received a copy of the GNU General Public License | ||
| 19 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 20 | |||
| 21 | |||
| 22 | /* The arguments given to this program are all the object files that | ||
| 23 | go into building GNU Emacs. There is no special search logic to find | ||
| 24 | the files. */ | ||
| 25 | |||
| 26 | #include <config.h> | ||
| 27 | |||
| 28 | #include <stdarg.h> | ||
| 29 | #include <stdint.h> | ||
| 30 | #include <stdio.h> | ||
| 31 | #include <stdlib.h> | ||
| 32 | #include <string.h> | ||
| 33 | #include <sysstdio.h> | ||
| 34 | #include <sha256.h> | ||
| 35 | #include <getopt.h> | ||
| 36 | |||
| 37 | #ifdef WINDOWSNT | ||
| 38 | /* Defined to be sys_fopen in ms-w32.h, but only #ifdef emacs, so this | ||
| 39 | is really just insurance. */ | ||
| 40 | #undef fopen | ||
| 41 | #include <direct.h> | ||
| 42 | #endif /* WINDOWSNT */ | ||
| 43 | |||
| 44 | int | ||
| 45 | main (int argc, char **argv) | ||
| 46 | { | ||
| 47 | int c; | ||
| 48 | bool raw = false; | ||
| 49 | while (0 <= (c = getopt (argc, argv, "rh"))) | ||
| 50 | { | ||
| 51 | switch (c) | ||
| 52 | { | ||
| 53 | case 'r': | ||
| 54 | raw = true; | ||
| 55 | break; | ||
| 56 | case 'h': | ||
| 57 | printf ("make-fingerprint [-r] FILES...: compute a hash\n"); | ||
| 58 | return 0; | ||
| 59 | default: | ||
| 60 | return 1; | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 64 | struct sha256_ctx ctx; | ||
| 65 | sha256_init_ctx (&ctx); | ||
| 66 | |||
| 67 | for (int i = optind; i < argc; ++i) | ||
| 68 | { | ||
| 69 | FILE *f = fopen (argv[i], "r" FOPEN_BINARY); | ||
| 70 | if (!f) | ||
| 71 | { | ||
| 72 | fprintf (stderr, "%s: Error: could not open %s\n", | ||
| 73 | argv[0], argv[i]); | ||
| 74 | return 1; | ||
| 75 | } | ||
| 76 | |||
| 77 | char buf[128*1024]; | ||
| 78 | do | ||
| 79 | { | ||
| 80 | size_t chunksz = fread (buf, 1, sizeof (buf), f); | ||
| 81 | if (ferror (f)) | ||
| 82 | { | ||
| 83 | fprintf (stderr, "%s: Error: could not read %s\n", | ||
| 84 | argv[0], argv[i]); | ||
| 85 | return 1; | ||
| 86 | } | ||
| 87 | sha256_process_bytes (buf, chunksz, &ctx); | ||
| 88 | } while (!feof (f)); | ||
| 89 | fclose (f); | ||
| 90 | } | ||
| 91 | |||
| 92 | uint8_t digest[32]; | ||
| 93 | sha256_finish_ctx (&ctx, digest); | ||
| 94 | |||
| 95 | if (raw) | ||
| 96 | { | ||
| 97 | for (int i = 0; i < 32; ++i) | ||
| 98 | printf ("%02X", digest[i]); | ||
| 99 | } | ||
| 100 | else | ||
| 101 | { | ||
| 102 | printf ("#include \"fingerprint.h\"\n"); | ||
| 103 | printf ("\n"); | ||
| 104 | printf ("const uint8_t fingerprint[32] = { "); | ||
| 105 | for (int i = 0; i < 32; ++i) | ||
| 106 | printf ("%s0x%02X", i ? ", " : "", digest[i]); | ||
| 107 | printf (" };\n"); | ||
| 108 | } | ||
| 109 | |||
| 110 | return EXIT_SUCCESS; | ||
| 111 | } | ||
| 112 | |||
| 113 | /* make-fingerprint.c ends here */ | ||