ssss-0.5/0002755000175100001440000000000010362426623013173 5ustar bertramusers00000000000000ssss-0.5/Makefile0000644000175100001440000000060310362426611014625 0ustar bertramusers00000000000000all: ssss-split ssss-combine ssss.1 ssss.1.html ssss-split: ssss.c $(CC) -W -Wall -O2 -lgmp -o ssss-split ssss.c strip ssss-split ssss-combine: ssss-split ln -f ssss-split ssss-combine ssss.1: ssss.manpage.xml xmltoman ssss.manpage.xml > ssss.1 ssss.1.html: ssss.manpage.xml xmlmantohtml ssss.manpage.xml > ssss.1.html clean: rm -rf ssss-split ssss-combine ssss.1 ssss.1.html ssss-0.5/ssss.c0000644000175100001440000004064510362426611014336 0ustar bertramusers00000000000000/* * ssss version 0.5 - Copyright 2005,2006 B. Poettering * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA */ /* * http://point-at-infinity.org/ssss/ * * This is an implementation of Shamir's Secret Sharing Scheme. See * the project's homepage http://point-at-infinity.org/ssss/ for more * information on this topic. * * This code links against the GNU multiprecision library "libgmp". * I compiled the code successfully with gmp 4.1.4. * You will need a system that has a /dev/random entropy source. * * Compile with * "gcc -O2 -lgmp -o ssss-split ssss.c && ln ssss-split ssss-combine" * * Compile with -DNOMLOCK to obtain a version without memory locking. * * Report bugs to: ssss AT point-at-infinity.org * */ #include #include #include #include #include #include #include #include #include #include #include #define VERSION "0.5" #define RANDOM_SOURCE "/dev/random" #define MAXDEGREE 1024 #define MAXTOKENLEN 128 #define MAXLINELEN (MAXTOKENLEN + 1 + 10 + 1 + MAXDEGREE / 4 + 10) /* coefficients of some irreducible polynomials over GF(2) */ static const unsigned char irred_coeff[] = { 4,3,1,5,3,1,4,3,1,7,3,2,5,4,3,5,3,2,7,4,2,4,3,1,10,9,3,9,4,2,7,6,2,10,9, 6,4,3,1,5,4,3,4,3,1,7,2,1,5,3,2,7,4,2,6,3,2,5,3,2,15,3,2,11,3,2,9,8,7,7, 2,1,5,3,2,9,3,1,7,3,1,9,8,3,9,4,2,8,5,3,15,14,10,10,5,2,9,6,2,9,3,2,9,5, 2,11,10,1,7,3,2,11,2,1,9,7,4,4,3,1,8,3,1,7,4,1,7,2,1,13,11,6,5,3,2,7,3,2, 8,7,5,12,3,2,13,10,6,5,3,2,5,3,2,9,5,2,9,7,2,13,4,3,4,3,1,11,6,4,18,9,6, 19,18,13,11,3,2,15,9,6,4,3,1,16,5,2,15,14,6,8,5,2,15,11,2,11,6,2,7,5,3,8, 3,1,19,16,9,11,9,6,15,7,6,13,4,3,14,13,3,13,6,3,9,5,2,19,13,6,19,10,3,11, 6,5,9,2,1,14,3,2,13,3,1,7,5,4,11,9,8,11,6,5,23,16,9,19,14,6,23,10,2,8,3, 2,5,4,3,9,6,4,4,3,2,13,8,6,13,11,1,13,10,3,11,6,5,19,17,4,15,14,7,13,9,6, 9,7,3,9,7,1,14,3,2,11,8,2,11,6,4,13,5,2,11,5,1,11,4,1,19,10,3,21,10,6,13, 3,1,15,7,5,19,18,10,7,5,3,12,7,2,7,5,1,14,9,6,10,3,2,15,13,12,12,11,9,16, 9,7,12,9,3,9,5,2,17,10,6,24,9,3,17,15,13,5,4,3,19,17,8,15,6,3,19,6,1 }; int opt_showversion = 0; int opt_help = 0; int opt_quiet = 0; int opt_QUIET = 0; int opt_hex = 0; int opt_diffusion = 1; int opt_security = 0; int opt_threshold = -1; int opt_number = -1; char *opt_token = NULL; unsigned int degree; mpz_t poly; int cprng; struct termios echo_orig, echo_off; #define mpz_lshift(A, B, l) mpz_mul_2exp(A, B, l) #define mpz_sizeinbits(A) (mpz_cmp_ui(A, 0) ? mpz_sizeinbase(A, 2) : 0) /* emergency abort and warning functions */ void fatal(char *msg) { tcsetattr(0, TCSANOW, &echo_orig); fprintf(stderr, "%sFATAL: %s.\n", isatty(2) ? "\a" : "", msg); exit(1); } void warning(char *msg) { if (! opt_QUIET) fprintf(stderr, "%sWARNING: %s.\n", isatty(2) ? "\a" : "", msg); } /* field arithmetic routines */ int field_size_valid(int deg) { return (deg >= 8) && (deg <= MAXDEGREE) && (deg % 8 == 0); } /* initialize 'poly' to a bitfield representing the coefficients of an irreducible polynomial of degree 'deg' */ void field_init(int deg) { assert(field_size_valid(deg)); mpz_init_set_ui(poly, 0); mpz_setbit(poly, deg); mpz_setbit(poly, irred_coeff[3 * (deg / 8 - 1) + 0]); mpz_setbit(poly, irred_coeff[3 * (deg / 8 - 1) + 1]); mpz_setbit(poly, irred_coeff[3 * (deg / 8 - 1) + 2]); mpz_setbit(poly, 0); degree = deg; } void field_deinit(void) { mpz_clear(poly); } /* I/O routines for GF(2^deg) field elements */ void field_import(mpz_t x, const char *s, int hexmode) { if (hexmode) { if (strlen(s) > degree / 4) fatal("input string too long"); if (strlen(s) < degree / 4) warning("input string too short, adding null padding on the left"); if (mpz_set_str(x, s, 16) || (mpz_cmp_ui(x, 0) < 0)) fatal("invalid syntax"); } else { int i; int warn = 0; if (strlen(s) > degree / 8) fatal("input string too long"); for(i = strlen(s) - 1; i >= 0; i--) warn = warn || (s[i] < 32) || (s[i] >= 127); if (warn) warning("binary data detected, use -x mode instead"); mpz_import(x, strlen(s), 1, 1, 0, 0, s); } } void field_print(FILE* stream, const mpz_t x, int hexmode) { int i; if (hexmode) { for(i = degree / 4 - mpz_sizeinbase(x, 16); i; i--) fprintf(stream, "0"); mpz_out_str(stream, 16, x); fprintf(stream, "\n"); } else { char buf[MAXDEGREE / 8 + 1]; size_t t; unsigned int i; int printable, warn = 0; memset(buf, degree / 8 + 1, 0); mpz_export(buf, &t, 1, 1, 0, 0, x); for(i = 0; i < t; i++) { printable = (buf[i] >= 32) && (buf[i] < 127); warn = warn || ! printable; fprintf(stream, "%c", printable ? buf[i] : '.'); } fprintf(stream, "\n"); if (warn) warning("binary data detected, use -x mode instead"); } } /* basic field arithmetic in GF(2^deg) */ void field_add(mpz_t z, const mpz_t x, const mpz_t y) { mpz_xor(z, x, y); } void field_mult(mpz_t z, const mpz_t x, const mpz_t y) { mpz_t b; unsigned int i; assert(z != y); mpz_init_set(b, x); if (mpz_tstbit(y, 0)) mpz_set(z, b); else mpz_set_ui(z, 0); for(i = 1; i < degree; i++) { mpz_lshift(b, b, 1); if (mpz_tstbit(b, degree)) mpz_xor(b, b, poly); if (mpz_tstbit(y, i)) mpz_xor(z, z, b); } mpz_clear(b); } void field_invert(mpz_t z, const mpz_t x) { mpz_t u, v, g, h; int i; assert(mpz_cmp_ui(x, 0)); mpz_init_set(u, x); mpz_init_set(v, poly); mpz_init_set_ui(g, 0); mpz_set_ui(z, 1); mpz_init(h); while (mpz_cmp_ui(u, 1)) { i = mpz_sizeinbits(u) - mpz_sizeinbits(v); if (i < 0) { mpz_swap(u, v); mpz_swap(z, g); i = -i; } mpz_lshift(h, v, i); mpz_xor(u, u, h); mpz_lshift(h, g, i); mpz_xor(z, z, h); } mpz_clear(u); mpz_clear(v); mpz_clear(g); mpz_clear(h); } /* routines for the random number generator */ void cprng_init(void) { if ((cprng = open(RANDOM_SOURCE, O_RDONLY)) < 0) fatal("couldn't open " RANDOM_SOURCE); } void cprng_deinit(void) { if (close(cprng) < 0) fatal("couldn't close " RANDOM_SOURCE); } void cprng_read(mpz_t x) { char buf[MAXDEGREE / 8]; unsigned int count; int i; for(count = 0; count < degree / 8; count += i) if ((i = read(cprng, buf + count, degree / 8 - count)) < 0) { close(cprng); fatal("couldn't read from " RANDOM_SOURCE); } mpz_import(x, degree / 8, 1, 1, 0, 0, buf); } /* a 64 bit pseudo random permutation (based on the XTEA cipher) */ void encipher_block(uint32_t *v) { uint32_t sum = 0, delta = 0x9E3779B9; int i; for(i = 0; i < 32; i++) { v[0] += (((v[1] << 4) ^ (v[1] >> 5)) + v[1]) ^ sum; sum += delta; v[1] += (((v[0] << 4) ^ (v[0] >> 5)) + v[0]) ^ sum; } } void decipher_block(uint32_t *v) { uint32_t sum = 0xC6EF3720, delta = 0x9E3779B9; int i; for(i = 0; i < 32; i++) { v[1] -= ((v[0] << 4 ^ v[0] >> 5) + v[0]) ^ sum; sum -= delta; v[0] -= ((v[1] << 4 ^ v[1] >> 5) + v[1]) ^ sum; } } void encode_slice(uint8_t *data, int idx, int len, void (*process_block)(uint32_t*)) { uint32_t v[2]; int i; for(i = 0; i < 2; i++) v[i] = data[(idx + 4 * i) % len] << 24 | data[(idx + 4 * i + 1) % len] << 16 | data[(idx + 4 * i + 2) % len] << 8 | data[(idx + 4 * i + 3) % len]; process_block(v); for(i = 0; i < 2; i++) { data[(idx + 4 * i + 0) % len] = v[i] >> 24; data[(idx + 4 * i + 1) % len] = (v[i] >> 16) & 0xff; data[(idx + 4 * i + 2) % len] = (v[i] >> 8) & 0xff; data[(idx + 4 * i + 3) % len] = v[i] & 0xff; } } enum encdec {ENCODE, DECODE}; void encode_mpz(mpz_t x, enum encdec encdecmode) { uint8_t v[(MAXDEGREE + 8) / 16 * 2]; size_t t; int i; memset(v, 0, (degree + 8) / 16 * 2); mpz_export(v, &t, -1, 2, 1, 0, x); if (degree % 16 == 8) v[degree / 8 - 1] = v[degree / 8]; if (encdecmode == ENCODE) /* 40 rounds are more than enough!*/ for(i = 0; i < 40 * ((int)degree / 8); i += 2) encode_slice(v, i, degree / 8, encipher_block); else for(i = 40 * (degree / 8) - 2; i >= 0; i -= 2) encode_slice(v, i, degree / 8, decipher_block); if (degree % 16 == 8) { v[degree / 8] = v[degree / 8 - 1]; v[degree / 8 - 1] = 0; } mpz_import(x, (degree + 8) / 16, -1, 2, 1, 0, v); assert(mpz_sizeinbits(x) <= degree); } /* evaluate polynomials efficiently */ void horner(int n, mpz_t y, const mpz_t x, const mpz_t coeff[]) { int i; mpz_set(y, x); for(i = n - 1; i; i--) { field_add(y, y, coeff[i]); field_mult(y, y, x); } field_add(y, y, coeff[0]); } /* calculate the secret from a set of shares solving a linear equation system */ #define MPZ_SWAP(A, B) \ do { mpz_set(h, A); mpz_set(A, B); mpz_set(B, h); } while(0) int restore_secret(int n, mpz_t (*A)[n], mpz_t b[]) { mpz_t (*AA)[n] = (mpz_t (*)[n])A; int i, j, k, found; mpz_t h; mpz_init(h); for(i = 0; i < n; i++) { if (! mpz_cmp_ui(AA[i][i], 0)) { for(found = 0, j = i + 1; j < n; j++) if (mpz_cmp_ui(AA[i][j], 0)) { found = 1; break; } if (! found) return -1; for(k = i; k < n; k++) MPZ_SWAP(AA[k][i], AA[k][j]); MPZ_SWAP(b[i], b[j]); } for(j = i + 1; j < n; j++) { if (mpz_cmp_ui(AA[i][j], 0)) { for(k = i + 1; k < n; k++) { field_mult(h, AA[k][i], AA[i][j]); field_mult(AA[k][j], AA[k][j], AA[i][i]); field_add(AA[k][j], AA[k][j], h); } field_mult(h, b[i], AA[i][j]); field_mult(b[j], b[j], AA[i][i]); field_add(b[j], b[j], h); } } } field_invert(h, AA[n - 1][n - 1]); field_mult(b[n - 1], b[n - 1], h); mpz_clear(h); return 0; } /* Prompt for a secret, generate shares for it */ void split(void) { unsigned int fmt_len; mpz_t x, y, coeff[opt_threshold]; char buf[MAXLINELEN]; int deg, i; for(fmt_len = 1, i = opt_number; i >= 10; i /= 10, fmt_len++); if (! opt_quiet) { printf("Generating shares using a (%d,%d) scheme with ", opt_threshold, opt_number); if (opt_security) printf("a %d bit", opt_security); else printf("dynamic"); printf(" security level.\n"); deg = opt_security ? opt_security : MAXDEGREE; fprintf(stderr, "Enter the secret, "); if (opt_hex) fprintf(stderr, "as most %d hex digits: ", deg / 4); else fprintf(stderr, "at most %d ASCII characters: ", deg / 8); } tcsetattr(0, TCSANOW, &echo_off); if (! fgets(buf, sizeof(buf), stdin)) fatal("I/O error while reading secret"); tcsetattr(0, TCSANOW, &echo_orig); buf[strcspn(buf, "\r\n")] = '\0'; if (! opt_security) { opt_security = opt_hex ? 4 * ((strlen(buf) + 1) & ~1): 8 * strlen(buf); if (! field_size_valid(opt_security)) fatal("security level invalid (secret too long?)"); if (! opt_quiet) fprintf(stderr, "Using a %d bit security level.\n", opt_security); } field_init(opt_security); mpz_init(coeff[0]); field_import(coeff[0], buf, opt_hex); if (opt_diffusion) { if (degree >= 64) encode_mpz(coeff[0], ENCODE); else warning("security level too small for the diffusion layer"); } cprng_init(); for(i = 1; i < opt_threshold; i++) { mpz_init(coeff[i]); cprng_read(coeff[i]); } cprng_deinit(); mpz_init(x); mpz_init(y); for(i = 0; i < opt_number; i++) { mpz_set_ui(x, i + 1); horner(opt_threshold, y, x, (const mpz_t*)coeff); if (opt_token) printf("%s-", opt_token); printf("%0*d-", fmt_len, i + 1); field_print(stdout, y, 1); } mpz_clear(x); mpz_clear(y); for(i = 0; i < opt_threshold; i++) mpz_clear(coeff[i]); field_deinit(); } /* Prompt for shares, calculate the secret */ void combine(void) { mpz_t A[opt_threshold][opt_threshold], y[opt_threshold], x; char buf[MAXLINELEN]; char *a, *b; int i, j; unsigned s = 0; mpz_init(x); if (! opt_quiet) printf("Enter %d shares separated by newlines:\n", opt_threshold); for (i = 0; i < opt_threshold; i++) { if (! opt_quiet) printf("Share [%d/%d]: ", i + 1, opt_threshold); if (! fgets(buf, sizeof(buf), stdin)) fatal("I/O error while reading shares"); buf[strcspn(buf, "\r\n")] = '\0'; if (! (a = strchr(buf, '-'))) fatal("invalid syntax"); *a++ = 0; if ((b = strchr(a, '-'))) *b++ = 0; else b = a, a = buf; if (! s) { s = 4 * strlen(b); if (! field_size_valid(s)) fatal("share has illegal length"); field_init(s); } else if (s != 4 * strlen(b)) fatal("shares have different security levels"); if (! (j = atoi(a))) fatal("invalid share"); mpz_set_ui(x, j); mpz_init_set_ui(A[opt_threshold - 1][i], 1); for(j = opt_threshold - 2; j >= 0; j--) { mpz_init(A[j][i]); field_mult(A[j][i], A[j + 1][i], x); } mpz_init(y[i]); field_import(y[i], b, 1); field_mult(x, x, A[0][i]); field_add(y[i], y[i], x); } mpz_clear(x); if (restore_secret(opt_threshold, A, y)) fatal("shares inconsistent. Perhaps a single share was used twice"); if (opt_diffusion) { if (degree >= 64) encode_mpz(y[opt_threshold - 1], DECODE); else warning("security level too small for the diffusion layer"); } if (! opt_quiet) fprintf(stderr, "Resulting secret: "); field_print(stderr, y[opt_threshold - 1], opt_hex); for (i = 0; i < opt_threshold; i++) { for (j = 0; j < opt_threshold; j++) mpz_clear(A[i][j]); mpz_clear(y[i]); } field_deinit(); } int main(int argc, char *argv[]) { char *name; int i; #if ! NOMLOCK if (mlockall(MCL_CURRENT | MCL_FUTURE) < 0) switch(errno) { case ENOMEM: warning("couldn't get memory lock (ENOMEM, try to adjust RLIMIT_MEMLOCK!)"); break; case EPERM: warning("couldn't get memory lock (EPERM, try UID 0!)"); break; case ENOSYS: warning("couldn't get memory lock (ENOSYS, kernel doesn't allow page locking)"); break; default: warning("couldn't get memory lock"); break; } #endif if (getuid() != geteuid()) seteuid(getuid()); tcgetattr(0, &echo_orig); echo_off = echo_orig; echo_off.c_lflag &= ~ECHO; opt_help = argc == 1; while((i = getopt(argc, argv, "vDhqQxs:t:n:w:")) != -1) switch(i) { case 'v': opt_showversion = 1; break; case 'h': opt_help = 1; break; case 'q': opt_quiet = 1; break; case 'Q': opt_QUIET = opt_quiet = 1; break; case 'x': opt_hex = 1; break; case 's': opt_security = atoi(optarg); break; case 't': opt_threshold = atoi(optarg); break; case 'n': opt_number = atoi(optarg); break; case 'w': opt_token = optarg; break; case 'D': opt_diffusion = 0; break; default: exit(1); } if (! opt_help && (argc != optind)) fatal("invalid argument"); if ((name = strrchr(argv[0], '/')) == NULL) name = argv[0]; if (strstr(name, "split")) { if (opt_help || opt_showversion) { puts("Split secrets using Shamir's Secret Sharing Scheme.\n" "\n" "ssss-split -t threshold -n shares [-w token] [-s level]" " [-x] [-q] [-Q] [-D] [-v]" ); if (opt_showversion) puts("\nVersion: " VERSION); exit(0); } if (opt_threshold < 2) fatal("invalid parameters: invalid threshold value"); if (opt_number < opt_threshold) fatal("invalid parameters: number of shares smaller than threshold"); if (opt_security && ! field_size_valid(opt_security)) fatal("invalid parameters: invalid security level"); if (opt_token && (strlen(opt_token) > MAXTOKENLEN)) fatal("invalid parameters: token too long"); split(); } else { if (opt_help || opt_showversion) { puts("Combine shares using Shamir's Secret Sharing Scheme.\n" "\n" "ssss-combine -t threshold [-x] [-q] [-Q] [-D] [-v]"); if (opt_showversion) puts("\nVersion: " VERSION); exit(0); } if (opt_threshold < 2) fatal("invalid parameters: invalid threshold value"); combine(); } return 0; } ssss-0.5/LICENSE0000444000175100001440000004313310362426611014175 0ustar bertramusers00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. ssss-0.5/HISTORY0000644000175100001440000000072210362426611014253 0ustar bertramusers00000000000000v0.5: (January 2006) - introduction of memory locking and tty echo suppression - a buffer overflow was fixed. It seems to be exploitable. v0.4: (October 2005) - the security level now can be chosen freely in the range 8..1024 bits in steps of 8. v0.3: (July 2005) - separation of ssss into ssss-split and ssss-combine - introduction of a man page v0.2: (June 2005) - introduction of the diffusion layer v0.1: (May 2005) - initial release ssss-0.5/ssss.manpage.xml0000644000175100001440000001114410362426611016313 0ustar bertramusers00000000000000 ssss-split -t threshold -n shares [-w token] [-s level] [-x] [-q] [-Q] [-D] [-v] ssss-combine -t threshold [-x] [-q] [-Q] [-D] [-v]

ssss is an implementation of Shamir's Secret Sharing Scheme. The program suite does both: the generation of shares for a known secret, and the reconstruction of a secret using user-provided shares.

ssss-split: prompt the user for a secret and generate a set of corresponding shares.

ssss-combine: read in a set of shares and reconstruct the secret.

In case you want to protect your login password with a set of ten shares in such a way that any three of them can reconstruct the password, you simply run the command

ssss-split -t 3 -n 10 -w passwd

To reconstruct the password pass three of the generated shares (in any order) to

ssss-combine -t 3

To protect a secret larger than 1024 bits a hybrid technique has to be applied: encrypt the secret with a block cipher and apply secret sharing to just the key. Among others openssl and gpg can do the encryption part:

openssl bf -e < file.plain > file.encrypted

gpg -c < file.plain > file.encrypted

ssss tries to lock its virtual address space into RAM for privacy reasons. But this may fail for two reasons: either the current uid doesn't permit page locking, or the RLIMIT_MEMLOCK is set too low. After printing a warning message ssss will run even without obtaining the desired mlock.

This software (v0.5) was written in 2006 by B. Poettering (ssss AT point-at-infinity.org). Find the newest version of ssss on the project's homepage: .
ssss-0.5/doc.html0000644000175100001440000001672710362426611014636 0ustar bertramusers00000000000000 ssss: Shamir's Secret Sharing Scheme The following text is licensed under the GNU General Public License. Copyright 2005, 2006 by B. Poettering.

What is "Secret Sharing"?

Citing from the Wikipedia article about Secret Sharing:

In cryptography, a secret sharing scheme is a method for distributing a secret amongst a group of participants, each of which is allocated a share of the secret. The secret can only be reconstructed when the shares are combined together; individual shares are of no use on their own.

More formally, in a secret sharing scheme there is one dealer and n players. The dealer gives a secret to the players, but only when specific conditions are fulfilled. The dealer accomplishes this by giving each player a share in such a way that any group of t (for threshold) or more players can together reconstruct the secret but no group of less than t players can. Such a system is called a (t,n)-threshold scheme.

A popular technique to implement threshold schemes uses polynomial interpolation ("Lagrange interpolation"). This method was invented by Adi Shamir in 1979. You can play around with a threshold scheme on the demo page.

Note that Shamir's scheme is provable secure, that means: in a (t,n) scheme one can prove that it makes no difference whether an attacker has t-1 valid shares at his disposal or none at all; as long as he has less than t shares, there is no better option than guessing to find out the secret.

Where is "Secret Sharing" used?

Some popular examples are:
  • Good passwords are hard to memorize. A clever user could use a secret sharing scheme to generate a set of shares for a given password and store one share in his address book, one in his bank deposit safe, leave one share with a friend, etc. If one day he forgets his password, he can reconstruct it easily. Of course, writing passwords directly into the address book would pose a security risk, as it could be stolen by an "enemy". If a secret sharing scheme is used, the attacker has to steal many shares from different places.
  • "A dealer could send t shares, all of which are necessary to recover the original secret, to a single recipient, using t different channels. An attacker would have to intercept all t shares to recover the secret, a task which may be more difficult than intercepting a single message" (Wikipedia).
  • The director of a bank could generate shares for the bank's vault unlocking code and hand them out to his employees. Even if the director is not available, the vault can be opened, but only, when a certain number of employees do it together. Here secret sharing schemes allow the employment of not fully trusted people.

What is "ssss"? Where can I download "ssss"?

ssss is an implementation of Shamir's secret sharing scheme for UNIX systems, especially developed for linux machines. The code is licensed under the GNU GPL. ssss does both: the generation of shares for a known secret and the reconstruction of a secret using user provided shares. The software was written in 2006 by B. Poettering, it links against the GNU libgmp multiprecision library (version 4.1.4 works well) and requires the /dev/random entropy source. Please send bug reports to ssss AT point-at-infinity.org.

There is a freshmeat page for ssss. A debian package is also available. If you are the lucky owner of a debian system just run apt-get update && apt-get install ssss to install ssss. Someone even ported (an outdated version of) ssss to Windows (but with a lightly too sloppy random number generation, in my opinion).

Download on the ssss homepage.

How is "ssss" used? Is there an online demonstration?

The generation of shares given a known secret is shown first. A (3,5)-threshold scheme is used, that is: 5 shares are generated, the secret can be reconstructed by any subset of size 3.

      % ssss-split -t 3 -n 5
      Generating shares using a (3,5) scheme with dynamic security level.
      Enter the secret, at most 128 ASCII characters: my secret root password
      Using a 184 bit security level.
      1-1c41ef496eccfbeba439714085df8437236298da8dd824
      2-fbc74a03a50e14ab406c225afb5f45c40ae11976d2b665
      3-fa1c3a9c6df8af0779c36de6c33f6e36e989d0e0b91309
      4-468de7d6eb36674c9cf008c8e8fc8c566537ad6301eb9e
      5-4756974923c0dce0a55f4774d09ca7a4865f64f56a4ee0
    
These shares can be combined to recreate the secret:
      % ssss-combine -t 3
      Enter 3 shares separated by newlines:
      Share [1/3]: 3-fa1c3a9c6df8af0779c36de6c33f6e36e989d0e0b91309
      Share [2/3]: 5-4756974923c0dce0a55f4774d09ca7a4865f64f56a4ee0
      Share [3/3]: 2-fbc74a03a50e14ab406c225afb5f45c40ae11976d2b665
      Resulting secret: my secret root password
    
You can try it out on the demo page.

If larger secrets are to be shared a hybrid technique has to be applied: encrypt the secret with a block cipher (using openssl, gpg, etc) and apply secret sharing to just the key. See the man page for more information about this topic.

Where is the manpage?

Read it as html or *roff!

If you like this software, think about donating some money via .


Last modified: Sun Jan 15 12:08:48 CET 2006 ssss-0.5/THANKS0000644000175100001440000000035310362426611014102 0ustar bertramusers00000000000000I would like to thank the following people for comments and code: Tamás Tevesz (documentation) Stefan Schlesinger, Daniel Bielefeldt (error reporting) Olaf Mersmann (memory locking, echo suppression) Alex Popov (windows port)