###----- Licensing notice ---------------------------------------------------
###
-### This program is free software; you can redistribute it and/or modify
+### This file is part of the distorted.org.uk key management suite.
+###
+### distorted-keys 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,
+### distorted-keys 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,
+### along with distorted-keys; if not, write to the Free Software Foundation,
### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from __future__ import with_statement
from cStringIO import StringIO
import optparse as OPT
+PACKAGE = '@PACKAGE@'
+VERSION = '@VERSION@'
+
###--------------------------------------------------------------------------
### Arithmetic in GF(2^8).
###
opts, args = op.parse_args(args[1:])
sub.func(gopts, opts, args)
-OPTPARSE = SubcommandOptionParser(description = """\
+def subcommand(name, usage, desc, opts = []):
+ def _(func):
+ OPTPARSE.add_subcommand(name, func, usage, desc, opts)
+ return func
+ return _
+
+OPTPARSE = SubcommandOptionParser(
+ usage = '%prog SUBCOMMAND [ARGS ...]',
+ version = '%%prog, %s version %s' % (PACKAGE, VERSION),
+ description = """\
Split and recombine secrets using Shamir's secret sharing system.
""")
raise ValueError, "no `/'"
return int(string[slash + 1:]), int(string[:slash])
+@subcommand('issue', '[-H HASHFN] THRESH/COUNT [SECRET-FILE]',
+ """\
+Issue shares of a secret. The secret (as a binary lump) is read from
+SECRET-FILE, or standard input if SECRET-FILE is omitted. COUNT + 1 lines
+are written to standard output: the first line contains the sharing
+parameters, and does not need to be kept especially secret (though it
+contains a hash of the secret, so it compromises the unconditional security
+of the secret sharing scheme); the remaining lines are the shares, one per
+line. All of the lines are plain text.""",
+ [OPT.make_option('-H', '--hash-function', type = 'string',
+ action = 'store', dest = 'hashfn', default = 'sha256',
+ help = 'Hash function for verifying the share.')])
def cmd_issue(gopts, opts, args):
if len(args) < 1 or len(args) > 2:
share = Share(i, ss.issue(i + 1))
print share.encode()
-OPTPARSE.add_subcommand(
- 'issue', cmd_issue,
- '[-H HASHFN] THRESH/COUNT [SECRET-FILE]',
- """\
-Issue shares of a secret. The secret (as a binary lump) is read from
-SECRET-FILE, or standard input if SECRET-FILE is omitted. COUNT + 1 lines
-are written to standard output: the first line contains the sharing
-parameters, and does not need to be kept especially secret (though it
-contains a hash of the secret, so it compromises the unconditional security
-of the secret sharing scheme); the remaining lines are the shares, one per
-line. All of the lines are plain text.""",
- [OPT.make_option('-H', '--hash-function', type = 'string',
- action = 'store', dest = 'hashfn', default = 'sha256',
- help = 'Hash function for verifying the share.')])
-
###--------------------------------------------------------------------------
### Recover a secret from shares.
+@subcommand('recover', '',
+ """\
+Standard input should contain a number of lines. The first line should
+contain the secret sharing parameters (the first line output by `issue');
+the remaining lines should contain shares. The shares may be supplied in
+any order. The secret is written to the OUTPUT file, or standard output.""",
+ [OPT.make_option('-o', '--output', action = 'store', type = 'string',
+ dest = 'file', default = '-',
+ help = 'Write the secret to FILE.')])
def cmd_recover(gopts, opts, args):
## Keep track of how well we've done so far. Report all of the things
with open(opts.file, 'wb') as f:
f.write(secret.secret)
-OPTPARSE.add_subcommand(
- 'recover', cmd_recover,
- '',
- """\
-Standard input should contain a number of lines. The first line should
-contain the secret sharing parameters (the first line output by `issue');
-the remaining lines should contain shares. The shares may be supplied in
-any order. The secret is written to the OUTPUT file, or standard output.""",
- [OPT.make_option('-o', '--output', action = 'store', type = 'string',
- dest = 'file', default = '-',
- help = 'Write the secret to FILE.')])
-
###----- That's all, folks --------------------------------------------------
if __name__ == '__main__':