Botan  1.11.15
src/lib/misc/tss/tss.h
Go to the documentation of this file.
00001 /*
00002 * RTSS (threshold secret sharing)
00003 * (C) 2009 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_RTSS_H__
00009 #define BOTAN_RTSS_H__
00010 
00011 #include <botan/secmem.h>
00012 #include <botan/hash.h>
00013 #include <botan/rng.h>
00014 #include <vector>
00015 
00016 namespace Botan {
00017 
00018 /**
00019 * A split secret, using the format from draft-mcgrew-tss-03
00020 */
00021 class BOTAN_DLL RTSS_Share
00022    {
00023    public:
00024       /**
00025       * @param M the number of shares needed to reconstruct
00026       * @param N the number of shares generated
00027       * @param secret the secret to split
00028       * @param secret_len the length of the secret
00029       * @param identifier the 16 byte share identifier
00030       * @param rng the random number generator to use
00031       */
00032       static std::vector<RTSS_Share>
00033          split(byte M, byte N,
00034                const byte secret[], u16bit secret_len,
00035                const byte identifier[16],
00036                RandomNumberGenerator& rng);
00037 
00038       /**
00039       * @param shares the list of shares
00040       */
00041       static secure_vector<byte>
00042         reconstruct(const std::vector<RTSS_Share>& shares);
00043 
00044       RTSS_Share() {}
00045 
00046       /**
00047       * @param hex_input the share encoded in hexadecimal
00048       */
00049       RTSS_Share(const std::string& hex_input);
00050 
00051       /**
00052       * @return hex representation
00053       */
00054       std::string to_string() const;
00055 
00056       /**
00057       * @return share identifier
00058       */
00059       byte share_id() const;
00060 
00061       /**
00062       * @return size of this share in bytes
00063       */
00064       size_t size() const { return contents.size(); }
00065 
00066       /**
00067       * @return if this TSS share was initialized or not
00068       */
00069       bool initialized() const { return (contents.size() > 0); }
00070    private:
00071       secure_vector<byte> contents;
00072    };
00073 
00074 }
00075 
00076 #endif