00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #ifndef CRYPTOPP_CRYPTLIB_H
00056 #define CRYPTOPP_CRYPTLIB_H
00057
00058 #include "cryptopp_config.h"
00059 #include <limits.h>
00060 #include <exception>
00061 #include <string>
00062 #include <typeinfo>
00063 #include <assert.h>
00064
00065 NAMESPACE_BEGIN(CryptoPP)
00066
00067
00068 class Integer;
00069
00070
00071 enum CipherDir {ENCRYPTION, DECRYPTION};
00072
00073
00074 const unsigned long INFINITE_TIME = ULONG_MAX;
00075
00076
00077 template <typename ENUM_TYPE, int VALUE>
00078 struct EnumToType
00079 {
00080 static ENUM_TYPE ToEnum() {return (ENUM_TYPE)VALUE;}
00081 };
00082
00083 enum ByteOrder {LITTLE_ENDIAN_ORDER = 0, BIG_ENDIAN_ORDER = 1};
00084 typedef EnumToType<ByteOrder, LITTLE_ENDIAN_ORDER> LittleEndian;
00085 typedef EnumToType<ByteOrder, BIG_ENDIAN_ORDER> BigEndian;
00086
00087
00088 class Exception : public std::exception
00089 {
00090 public:
00091
00092 enum ErrorType {
00093
00094 NOT_IMPLEMENTED,
00095
00096 INVALID_ARGUMENT,
00097
00098 CANNOT_FLUSH,
00099
00100 DATA_INTEGRITY_CHECK_FAILED,
00101
00102 INVALID_DATA_FORMAT,
00103
00104 IO_ERROR,
00105
00106 OTHER_ERROR
00107 };
00108
00109 explicit Exception(ErrorType errorType, const std::string &s) : m_errorType(errorType), m_what(s) {}
00110 virtual ~Exception() throw() {}
00111 const char *what() const throw() {return (m_what.c_str());}
00112 const std::string &GetWhat() const {return m_what;}
00113 void SetWhat(const std::string &s) {m_what = s;}
00114 ErrorType GetErrorType() const {return m_errorType;}
00115 void SetErrorType(ErrorType errorType) {m_errorType = errorType;}
00116
00117 private:
00118 ErrorType m_errorType;
00119 std::string m_what;
00120 };
00121
00122
00123 class InvalidArgument : public Exception
00124 {
00125 public:
00126 explicit InvalidArgument(const std::string &s) : Exception(INVALID_ARGUMENT, s) {}
00127 };
00128
00129
00130 class InvalidDataFormat : public Exception
00131 {
00132 public:
00133 explicit InvalidDataFormat(const std::string &s) : Exception(INVALID_DATA_FORMAT, s) {}
00134 };
00135
00136
00137 class InvalidCiphertext : public InvalidDataFormat
00138 {
00139 public:
00140 explicit InvalidCiphertext(const std::string &s) : InvalidDataFormat(s) {}
00141 };
00142
00143
00144 class NotImplemented : public Exception
00145 {
00146 public:
00147 explicit NotImplemented(const std::string &s) : Exception(NOT_IMPLEMENTED, s) {}
00148 };
00149
00150
00151 class CannotFlush : public Exception
00152 {
00153 public:
00154 explicit CannotFlush(const std::string &s) : Exception(CANNOT_FLUSH, s) {}
00155 };
00156
00157
00158 class OS_Error : public Exception
00159 {
00160 public:
00161 OS_Error(ErrorType errorType, const std::string s, const std::string& operation, int errorCode)
00162 : Exception(errorType, s), m_operation(operation), m_errorCode(errorCode) {}
00163 ~OS_Error() throw() {}
00164
00165
00166 const std::string & GetOperation() const {return m_operation;}
00167
00168 int GetErrorCode() const {return m_errorCode;}
00169
00170 protected:
00171 std::string m_operation;
00172 int m_errorCode;
00173 };
00174
00175
00176 struct DecodingResult
00177 {
00178 explicit DecodingResult() : isValidCoding(false), messageLength(0) {}
00179 explicit DecodingResult(unsigned int len) : isValidCoding(true), messageLength(len) {}
00180
00181 bool operator==(const DecodingResult &rhs) const {return isValidCoding == rhs.isValidCoding && messageLength == rhs.messageLength;}
00182 bool operator!=(const DecodingResult &rhs) const {return !operator==(rhs);}
00183
00184 bool isValidCoding;
00185 unsigned int messageLength;
00186
00187 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
00188 operator unsigned int() const {return isValidCoding ? messageLength : 0;}
00189 #endif
00190 };
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 class NameValuePairs
00202 {
00203 public:
00204 virtual ~NameValuePairs() {}
00205
00206
00207 class ValueTypeMismatch : public InvalidArgument
00208 {
00209 public:
00210 ValueTypeMismatch(std::string name, const std::type_info &stored, const std::type_info &retrieving)
00211 : InvalidArgument("NameValuePairs: type mismatch for '" + name + "', stored '" + stored.name() + "', trying to retrieve '" + retrieving.name() + "'")
00212 , m_stored(stored), m_retrieving(retrieving) {}
00213
00214 const std::type_info & GetStoredTypeInfo() const {return m_stored;}
00215 const std::type_info & GetRetrievingTypeInfo() const {return m_retrieving;}
00216
00217 private:
00218 const std::type_info &m_stored;
00219 const std::type_info &m_retrieving;
00220 };
00221
00222
00223 template <class T>
00224 bool GetThisObject(T &object) const
00225 {
00226 return GetValue((std::string("ThisObject:")+typeid(T).name()).c_str(), object);
00227 }
00228
00229
00230 template <class T>
00231 bool GetThisPointer(T *&p) const
00232 {
00233 return GetValue((std::string("ThisPointer:")+typeid(T).name()).c_str(), p);
00234 }
00235
00236
00237 template <class T>
00238 bool GetValue(const char *name, T &value) const
00239 {
00240 return GetVoidValue(name, typeid(T), &value);
00241 }
00242
00243
00244 template <class T>
00245 T GetValueWithDefault(const char *name, T defaultValue) const
00246 {
00247 GetValue(name, defaultValue);
00248 return defaultValue;
00249 }
00250
00251
00252 std::string GetValueNames() const
00253 {std::string result; GetValue("ValueNames", result); return result;}
00254
00255
00256
00257
00258 bool GetIntValue(const char *name, int &value) const
00259 {return GetValue(name, value);}
00260
00261
00262 int GetIntValueWithDefault(const char *name, int defaultValue) const
00263 {return GetValueWithDefault(name, defaultValue);}
00264
00265
00266 static void ThrowIfTypeMismatch(const char *name, const std::type_info &stored, const std::type_info &retrieving)
00267 {if (stored != retrieving) throw ValueTypeMismatch(name, stored, retrieving);}
00268
00269 template <class T>
00270 void GetRequiredParameter(const char *className, const char *name, T &value) const
00271 {
00272 if (!GetValue(name, value))
00273 throw InvalidArgument(std::string(className) + ": missing required parameter '" + name + "'");
00274 }
00275
00276 void GetRequiredIntParameter(const char *className, const char *name, int &value) const
00277 {
00278 if (!GetIntValue(name, value))
00279 throw InvalidArgument(std::string(className) + ": missing required parameter '" + name + "'");
00280 }
00281
00282
00283 virtual bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const =0;
00284 };
00285
00286
00287
00288
00289
00290
00291
00292 DOCUMENTED_NAMESPACE_BEGIN(Name)
00293
00294 DOCUMENTED_NAMESPACE_END
00295
00296
00297 class NullNameValuePairs : public NameValuePairs
00298 {
00299 public:
00300 bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const {return false;}
00301 };
00302
00303
00304 extern const NullNameValuePairs g_nullNameValuePairs;
00305
00306
00307
00308
00309 class Clonable
00310 {
00311 public:
00312 virtual ~Clonable() {}
00313
00314 virtual Clonable* Clone() const {throw NotImplemented("Clone() is not implemented yet.");}
00315 };
00316
00317
00318
00319 class Algorithm : public Clonable
00320 {
00321 public:
00322
00323
00324 Algorithm(bool checkSelfTestStatus = true);
00325
00326 virtual std::string AlgorithmName() const {return "unknown";}
00327 };
00328
00329
00330
00331 class SimpleKeyingInterface
00332 {
00333 public:
00334
00335 virtual unsigned int MinKeyLength() const =0;
00336
00337 virtual unsigned int MaxKeyLength() const =0;
00338
00339 virtual unsigned int DefaultKeyLength() const =0;
00340
00341
00342 virtual unsigned int GetValidKeyLength(unsigned int n) const =0;
00343
00344
00345 virtual bool IsValidKeyLength(unsigned int n) const
00346 {return n == GetValidKeyLength(n);}
00347
00348
00349
00350 virtual void SetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms = g_nullNameValuePairs) =0;
00351
00352
00353 void SetKeyWithRounds(const byte *key, unsigned int length, int rounds);
00354
00355
00356 void SetKeyWithIV(const byte *key, unsigned int length, const byte *iv);
00357
00358 enum IV_Requirement {STRUCTURED_IV = 0, RANDOM_IV, UNPREDICTABLE_RANDOM_IV, INTERNALLY_GENERATED_IV, NOT_RESYNCHRONIZABLE};
00359
00360 virtual IV_Requirement IVRequirement() const =0;
00361
00362
00363
00364 bool IsResynchronizable() const {return IVRequirement() < NOT_RESYNCHRONIZABLE;}
00365
00366 bool CanUseRandomIVs() const {return IVRequirement() <= UNPREDICTABLE_RANDOM_IV;}
00367
00368 bool CanUsePredictableIVs() const {return IVRequirement() <= RANDOM_IV;}
00369
00370 bool CanUseStructuredIVs() const {return IVRequirement() <= STRUCTURED_IV;}
00371
00372
00373 virtual unsigned int IVSize() const {throw NotImplemented("SimpleKeyingInterface: this object doesn't support resynchronization");}
00374
00375 virtual void Resynchronize(const byte *IV) {throw NotImplemented("SimpleKeyingInterface: this object doesn't support resynchronization");}
00376
00377
00378
00379
00380 virtual void GetNextIV(byte *IV) {throw NotImplemented("SimpleKeyingInterface: this object doesn't support GetNextIV()");}
00381
00382 protected:
00383 void ThrowIfInvalidKeyLength(const Algorithm &algorithm, unsigned int length);
00384
00385 inline void AssertValidKeyLength(unsigned int length) const
00386 {
00387 assert(IsValidKeyLength(length));
00388 }
00389 };
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399 class BlockTransformation : public Algorithm
00400 {
00401 public:
00402
00403 virtual void ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const =0;
00404
00405
00406
00407 void ProcessBlock(const byte *inBlock, byte *outBlock) const
00408 {ProcessAndXorBlock(inBlock, NULL, outBlock);}
00409
00410
00411 void ProcessBlock(byte *inoutBlock) const
00412 {ProcessAndXorBlock(inoutBlock, NULL, inoutBlock);}
00413
00414
00415 virtual unsigned int BlockSize() const =0;
00416
00417
00418 virtual unsigned int BlockAlignment() const {return 4;}
00419
00420
00421 virtual bool IsPermutation() const {return true;}
00422
00423
00424 virtual bool IsForwardTransformation() const =0;
00425
00426
00427 virtual unsigned int OptimalNumberOfParallelBlocks() const {return 1;}
00428
00429
00430 virtual void ProcessAndXorMultipleBlocks(const byte *inBlocks, const byte *xorBlocks, byte *outBlocks, unsigned int numberOfBlocks) const;
00431 };
00432
00433
00434
00435 class StreamTransformation : public Algorithm
00436 {
00437 public:
00438
00439
00440
00441 StreamTransformation& Ref() {return *this;}
00442
00443
00444 virtual unsigned int MandatoryBlockSize() const {return 1;}
00445
00446
00447
00448 virtual unsigned int OptimalBlockSize() const {return MandatoryBlockSize();}
00449
00450 virtual unsigned int GetOptimalBlockSizeUsed() const {return 0;}
00451
00452
00453 virtual unsigned int OptimalDataAlignment() const {return 1;}
00454
00455
00456
00457 virtual void ProcessData(byte *outString, const byte *inString, unsigned int length) =0;
00458
00459
00460
00461 virtual void ProcessLastBlock(byte *outString, const byte *inString, unsigned int length);
00462
00463 virtual unsigned int MinLastBlockSize() const {return 0;}
00464
00465
00466 inline void ProcessString(byte *inoutString, unsigned int length)
00467 {ProcessData(inoutString, inoutString, length);}
00468
00469 inline void ProcessString(byte *outString, const byte *inString, unsigned int length)
00470 {ProcessData(outString, inString, length);}
00471
00472 inline byte ProcessByte(byte input)
00473 {ProcessData(&input, &input, 1); return input;}
00474
00475
00476 virtual bool IsRandomAccess() const =0;
00477
00478 virtual void Seek(dword n)
00479 {
00480 assert(!IsRandomAccess());
00481 throw NotImplemented("StreamTransformation: this object doesn't support random access");
00482 }
00483
00484
00485 virtual bool IsSelfInverting() const =0;
00486
00487 virtual bool IsForwardTransformation() const =0;
00488 };
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498 class HashTransformation : public Algorithm
00499 {
00500 public:
00501
00502 virtual void Update(const byte *input, unsigned int length) =0;
00503
00504
00505 virtual byte * CreateUpdateSpace(unsigned int &size) {size=0; return NULL;}
00506
00507
00508
00509 virtual void Final(byte *digest)
00510 {TruncatedFinal(digest, DigestSize());}
00511
00512
00513 virtual void Restart()
00514 {TruncatedFinal(NULL, 0);}
00515
00516
00517 virtual unsigned int DigestSize() const =0;
00518
00519
00520 virtual unsigned int OptimalBlockSize() const {return 1;}
00521
00522
00523 virtual unsigned int OptimalDataAlignment() const {return 1;}
00524
00525
00526 virtual void CalculateDigest(byte *digest, const byte *input, unsigned int length)
00527 {Update(input, length); Final(digest);}
00528
00529
00530
00531
00532 virtual bool Verify(const byte *digest)
00533 {return TruncatedVerify(digest, DigestSize());}
00534
00535
00536 virtual bool VerifyDigest(const byte *digest, const byte *input, unsigned int length)
00537 {Update(input, length); return Verify(digest);}
00538
00539
00540 virtual void TruncatedFinal(byte *digest, unsigned int digestSize) =0;
00541
00542
00543 virtual void CalculateTruncatedDigest(byte *digest, unsigned int digestSize, const byte *input, unsigned int length)
00544 {Update(input, length); TruncatedFinal(digest, digestSize);}
00545
00546
00547 virtual bool TruncatedVerify(const byte *digest, unsigned int digestLength);
00548
00549
00550 virtual bool VerifyTruncatedDigest(const byte *digest, unsigned int digestLength, const byte *input, unsigned int length)
00551 {Update(input, length); return TruncatedVerify(digest, digestLength);}
00552
00553 protected:
00554 void ThrowIfInvalidTruncatedSize(unsigned int size) const;
00555 };
00556
00557
00558 template <class T>
00559 class SimpleKeyedTransformation : public T, public SimpleKeyingInterface
00560 {
00561 public:
00562 void ThrowIfInvalidKeyLength(unsigned int length)
00563 {SimpleKeyingInterface::ThrowIfInvalidKeyLength(*this, length);}
00564 };
00565
00566
00567 typedef HashTransformation HashFunction;
00568 #ifdef CRYPTOPP_DOXYGEN_PROCESSING
00569
00570 class BlockCipher : public BlockTransformation, public SimpleKeyingInterface {};
00571
00572 class SymmetricCipher : public StreamTransformation, public SimpleKeyingInterface {};
00573
00574 class MessageAuthenticationCode : public HashTransformation, public SimpleKeyingInterface {};
00575 #else
00576 typedef SimpleKeyedTransformation<BlockTransformation> BlockCipher;
00577 typedef SimpleKeyedTransformation<StreamTransformation> SymmetricCipher;
00578 typedef SimpleKeyedTransformation<HashTransformation> MessageAuthenticationCode;
00579 #endif
00580
00581 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
00582 typedef SymmetricCipher StreamCipher;
00583 #endif
00584
00585
00586
00587
00588 class RandomNumberGenerator : public Algorithm
00589 {
00590 public:
00591
00592 virtual byte GenerateByte() =0;
00593
00594
00595
00596 virtual unsigned int GenerateBit();
00597
00598
00599 virtual word32 GenerateWord32(word32 a=0, word32 b=0xffffffffL);
00600
00601
00602
00603 virtual void GenerateBlock(byte *output, unsigned int size);
00604
00605
00606
00607 virtual void DiscardBytes(unsigned int n);
00608
00609
00610 template <class IT> void Shuffle(IT begin, IT end)
00611 {
00612 for (; begin != end; ++begin)
00613 std::iter_swap(begin, begin + GenerateWord32(0, end-begin-1));
00614 }
00615
00616 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
00617 byte GetByte() {return GenerateByte();}
00618 unsigned int GetBit() {return GenerateBit();}
00619 word32 GetLong(word32 a=0, word32 b=0xffffffffL) {return GenerateWord32(a, b);}
00620 word16 GetShort(word16 a=0, word16 b=0xffff) {return (word16)GenerateWord32(a, b);}
00621 void GetBlock(byte *output, unsigned int size) {GenerateBlock(output, size);}
00622 #endif
00623 };
00624
00625
00626 RandomNumberGenerator & NullRNG();
00627
00628 class WaitObjectContainer;
00629
00630
00631
00632 class Waitable
00633 {
00634 public:
00635
00636 virtual unsigned int GetMaxWaitObjectCount() const =0;
00637
00638 virtual void GetWaitObjects(WaitObjectContainer &container) =0;
00639
00640
00641 bool Wait(unsigned long milliseconds);
00642 };
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670 class BufferedTransformation : public Algorithm, public Waitable
00671 {
00672 public:
00673
00674 static const std::string NULL_CHANNEL;
00675
00676 BufferedTransformation() : Algorithm(false) {}
00677
00678
00679
00680
00681 BufferedTransformation& Ref() {return *this;}
00682
00683
00684
00685
00686 unsigned int Put(byte inByte, bool blocking=true)
00687 {return Put(&inByte, 1, blocking);}
00688
00689 unsigned int Put(const byte *inString, unsigned int length, bool blocking=true)
00690 {return Put2(inString, length, 0, blocking);}
00691
00692
00693 unsigned int PutWord16(word16 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true);
00694
00695 unsigned int PutWord32(word32 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true);
00696
00697
00698
00699
00700 virtual byte * CreatePutSpace(unsigned int &size) {size=0; return NULL;}
00701
00702 virtual bool CanModifyInput() const {return false;}
00703
00704
00705 unsigned int PutModifiable(byte *inString, unsigned int length, bool blocking=true)
00706 {return PutModifiable2(inString, length, 0, blocking);}
00707
00708 bool MessageEnd(int propagation=-1, bool blocking=true)
00709 {return !!Put2(NULL, 0, propagation < 0 ? -1 : propagation+1, blocking);}
00710 unsigned int PutMessageEnd(const byte *inString, unsigned int length, int propagation=-1, bool blocking=true)
00711 {return Put2(inString, length, propagation < 0 ? -1 : propagation+1, blocking);}
00712
00713
00714
00715 virtual unsigned int Put2(const byte *inString, unsigned int length, int messageEnd, bool blocking) =0;
00716
00717
00718 virtual unsigned int PutModifiable2(byte *inString, unsigned int length, int messageEnd, bool blocking)
00719 {return Put2(inString, length, messageEnd, blocking);}
00720
00721
00722 struct BlockingInputOnly : public NotImplemented
00723 {BlockingInputOnly(const std::string &s) : NotImplemented(s + ": Nonblocking input is not implemented by this object.") {}};
00724
00725
00726
00727
00728 unsigned int GetMaxWaitObjectCount() const;
00729 void GetWaitObjects(WaitObjectContainer &container);
00730
00731
00732
00733
00734 virtual void IsolatedInitialize(const NameValuePairs ¶meters) {throw NotImplemented("BufferedTransformation: this object can't be reinitialized");}
00735 virtual bool IsolatedFlush(bool hardFlush, bool blocking) =0;
00736 virtual bool IsolatedMessageSeriesEnd(bool blocking) {return false;}
00737
00738
00739 virtual void Initialize(const NameValuePairs ¶meters=g_nullNameValuePairs, int propagation=-1);
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751 virtual bool Flush(bool hardFlush, int propagation=-1, bool blocking=true);
00752
00753
00754 virtual bool MessageSeriesEnd(int propagation=-1, bool blocking=true);
00755
00756
00757
00758 virtual void SetAutoSignalPropagation(int propagation) {}
00759
00760
00761 virtual int GetAutoSignalPropagation() const {return 0;}
00762 public:
00763
00764 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
00765 void Close() {MessageEnd();}
00766 #endif
00767
00768
00769
00770
00771
00772
00773
00774
00775 virtual unsigned long MaxRetrievable() const;
00776
00777
00778 virtual bool AnyRetrievable() const;
00779
00780
00781 virtual unsigned int Get(byte &outByte);
00782
00783 virtual unsigned int Get(byte *outString, unsigned int getMax);
00784
00785
00786 virtual unsigned int Peek(byte &outByte) const;
00787
00788 virtual unsigned int Peek(byte *outString, unsigned int peekMax) const;
00789
00790
00791 unsigned int GetWord16(word16 &value, ByteOrder order=BIG_ENDIAN_ORDER);
00792
00793 unsigned int GetWord32(word32 &value, ByteOrder order=BIG_ENDIAN_ORDER);
00794
00795
00796 unsigned int PeekWord16(word16 &value, ByteOrder order=BIG_ENDIAN_ORDER);
00797
00798 unsigned int PeekWord32(word32 &value, ByteOrder order=BIG_ENDIAN_ORDER);
00799
00800
00801 unsigned long TransferTo(BufferedTransformation &target, unsigned long transferMax=ULONG_MAX, const std::string &channel=NULL_CHANNEL)
00802 {TransferTo2(target, transferMax, channel); return transferMax;}
00803
00804
00805 virtual unsigned long Skip(unsigned long skipMax=ULONG_MAX);
00806
00807
00808 unsigned long CopyTo(BufferedTransformation &target, unsigned long copyMax=ULONG_MAX, const std::string &channel=NULL_CHANNEL) const
00809 {return CopyRangeTo(target, 0, copyMax, channel);}
00810
00811
00812 unsigned long CopyRangeTo(BufferedTransformation &target, unsigned long position, unsigned long copyMax=ULONG_MAX, const std::string &channel=NULL_CHANNEL) const
00813 {unsigned long i = position; CopyRangeTo2(target, i, i+copyMax, channel); return i-position;}
00814
00815 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
00816 unsigned long MaxRetrieveable() const {return MaxRetrievable();}
00817 #endif
00818
00819
00820
00821
00822
00823 virtual unsigned long TotalBytesRetrievable() const;
00824
00825 virtual unsigned int NumberOfMessages() const;
00826
00827 virtual bool AnyMessages() const;
00828
00829
00830
00831
00832
00833 virtual bool GetNextMessage();
00834
00835 virtual unsigned int SkipMessages(unsigned int count=UINT_MAX);
00836
00837 unsigned int TransferMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=NULL_CHANNEL)
00838 {TransferMessagesTo2(target, count, channel); return count;}
00839
00840 unsigned int CopyMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=NULL_CHANNEL) const;
00841
00842
00843 virtual void SkipAll();
00844
00845 void TransferAllTo(BufferedTransformation &target, const std::string &channel=NULL_CHANNEL)
00846 {TransferAllTo2(target, channel);}
00847
00848 void CopyAllTo(BufferedTransformation &target, const std::string &channel=NULL_CHANNEL) const;
00849
00850 virtual bool GetNextMessageSeries() {return false;}
00851 virtual unsigned int NumberOfMessagesInThisSeries() const {return NumberOfMessages();}
00852 virtual unsigned int NumberOfMessageSeries() const {return 0;}
00853
00854
00855
00856
00857
00858 virtual unsigned int TransferTo2(BufferedTransformation &target, unsigned long &byteCount, const std::string &channel=NULL_CHANNEL, bool blocking=true) =0;
00859 virtual unsigned int CopyRangeTo2(BufferedTransformation &target, unsigned long &begin, unsigned long end=ULONG_MAX, const std::string &channel=NULL_CHANNEL, bool blocking=true) const =0;
00860 unsigned int TransferMessagesTo2(BufferedTransformation &target, unsigned int &messageCount, const std::string &channel=NULL_CHANNEL, bool blocking=true);
00861 unsigned int TransferAllTo2(BufferedTransformation &target, const std::string &channel=NULL_CHANNEL, bool blocking=true);
00862
00863
00864
00865
00866 struct NoChannelSupport : public NotImplemented
00867 {NoChannelSupport() : NotImplemented("BufferedTransformation: this object doesn't support multiple channels") {}};
00868
00869 unsigned int ChannelPut(const std::string &channel, byte inByte, bool blocking=true)
00870 {return ChannelPut(channel, &inByte, 1, blocking);}
00871 unsigned int ChannelPut(const std::string &channel, const byte *inString, unsigned int length, bool blocking=true)
00872 {return ChannelPut2(channel, inString, length, 0, blocking);}
00873
00874 unsigned int ChannelPutModifiable(const std::string &channel, byte *inString, unsigned int length, bool blocking=true)
00875 {return ChannelPutModifiable2(channel, inString, length, 0, blocking);}
00876
00877 unsigned int ChannelPutWord16(const std::string &channel, word16 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true);
00878 unsigned int ChannelPutWord32(const std::string &channel, word32 value, ByteOrder order=BIG_ENDIAN_ORDER, bool blocking=true);
00879
00880 bool ChannelMessageEnd(const std::string &channel, int propagation=-1, bool blocking=true)
00881 {return !!ChannelPut2(channel, NULL, 0, propagation < 0 ? -1 : propagation+1, blocking);}
00882 unsigned int ChannelPutMessageEnd(const std::string &channel, const byte *inString, unsigned int length, int propagation=-1, bool blocking=true)
00883 {return ChannelPut2(channel, inString, length, propagation < 0 ? -1 : propagation+1, blocking);}
00884
00885 virtual byte * ChannelCreatePutSpace(const std::string &channel, unsigned int &size);
00886
00887 virtual unsigned int ChannelPut2(const std::string &channel, const byte *begin, unsigned int length, int messageEnd, bool blocking);
00888 virtual unsigned int ChannelPutModifiable2(const std::string &channel, byte *begin, unsigned int length, int messageEnd, bool blocking);
00889
00890 virtual void ChannelInitialize(const std::string &channel, const NameValuePairs ¶meters=g_nullNameValuePairs, int propagation=-1);
00891 virtual bool ChannelFlush(const std::string &channel, bool hardFlush, int propagation=-1, bool blocking=true);
00892 virtual bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true);
00893
00894 virtual void SetRetrievalChannel(const std::string &channel);
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906 virtual bool Attachable() {return false;}
00907
00908 virtual BufferedTransformation *AttachedTransformation() {assert(!Attachable()); return 0;}
00909
00910 virtual const BufferedTransformation *AttachedTransformation() const
00911 {return const_cast<BufferedTransformation *>(this)->AttachedTransformation();}
00912
00913 virtual void Detach(BufferedTransformation *newAttachment = 0)
00914 {assert(!Attachable()); throw NotImplemented("BufferedTransformation: this object is not attachable");}
00915
00916 virtual void Attach(BufferedTransformation *newAttachment);
00917
00918
00919 protected:
00920 static int DecrementPropagation(int propagation)
00921 {return propagation != 0 ? propagation - 1 : 0;}
00922 };
00923
00924
00925 BufferedTransformation & TheBitBucket();
00926
00927
00928
00929 class CryptoMaterial : public NameValuePairs
00930 {
00931 public:
00932
00933 class InvalidMaterial : public InvalidDataFormat
00934 {
00935 public:
00936 explicit InvalidMaterial(const std::string &s) : InvalidDataFormat(s) {}
00937 };
00938
00939
00940
00941 virtual void AssignFrom(const NameValuePairs &source) =0;
00942
00943
00944
00945
00946
00947
00948
00949
00950 virtual bool Validate(RandomNumberGenerator &rng, unsigned int level) const =0;
00951
00952
00953 virtual void ThrowIfInvalid(RandomNumberGenerator &rng, unsigned int level) const
00954 {if (!Validate(rng, level)) throw InvalidMaterial("CryptoMaterial: this object contains invalid values");}
00955
00956
00957
00958
00959 virtual void Save(BufferedTransformation &bt) const
00960 {throw NotImplemented("CryptoMaterial: this object does not support saving");}
00961
00962
00963
00964
00965
00966 virtual void Load(BufferedTransformation &bt)
00967 {throw NotImplemented("CryptoMaterial: this object does not support loading");}
00968
00969
00970 virtual bool SupportsPrecomputation() const {return false;}
00971
00972
00973
00974
00975 virtual void Precompute(unsigned int n)
00976 {assert(!SupportsPrecomputation()); throw NotImplemented("CryptoMaterial: this object does not support precomputation");}
00977
00978 virtual void LoadPrecomputation(BufferedTransformation &storedPrecomputation)
00979 {assert(!SupportsPrecomputation()); throw NotImplemented("CryptoMaterial: this object does not support precomputation");}
00980
00981 virtual void SavePrecomputation(BufferedTransformation &storedPrecomputation) const
00982 {assert(!SupportsPrecomputation()); throw NotImplemented("CryptoMaterial: this object does not support precomputation");}
00983
00984
00985 void DoQuickSanityCheck() const {ThrowIfInvalid(NullRNG(), 0);}
00986 };
00987
00988
00989
00990 class GeneratableCryptoMaterial : virtual public CryptoMaterial
00991 {
00992 public:
00993
00994
00995
00996 virtual void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs ¶ms = g_nullNameValuePairs)
00997 {throw NotImplemented("GeneratableCryptoMaterial: this object does not support key/parameter generation");}
00998
00999
01000 void GenerateRandomWithKeySize(RandomNumberGenerator &rng, unsigned int keySize);
01001 };
01002
01003
01004
01005 class PublicKey : virtual public CryptoMaterial
01006 {
01007 };
01008
01009
01010
01011 class PrivateKey : public GeneratableCryptoMaterial
01012 {
01013 };
01014
01015
01016
01017 class CryptoParameters : public GeneratableCryptoMaterial
01018 {
01019 };
01020
01021
01022
01023 class AsymmetricAlgorithm : public Algorithm
01024 {
01025 public:
01026
01027 virtual CryptoMaterial & AccessMaterial() =0;
01028
01029 virtual const CryptoMaterial & GetMaterial() const =0;
01030
01031
01032 void BERDecode(BufferedTransformation &bt)
01033 {AccessMaterial().Load(bt);}
01034
01035 void DEREncode(BufferedTransformation &bt) const
01036 {GetMaterial().Save(bt);}
01037 };
01038
01039
01040
01041 class PublicKeyAlgorithm : public AsymmetricAlgorithm
01042 {
01043 public:
01044
01045 CryptoMaterial & AccessMaterial() {return AccessPublicKey();}
01046 const CryptoMaterial & GetMaterial() const {return GetPublicKey();}
01047
01048 virtual PublicKey & AccessPublicKey() =0;
01049 virtual const PublicKey & GetPublicKey() const {return const_cast<PublicKeyAlgorithm *>(this)->AccessPublicKey();}
01050 };
01051
01052
01053
01054 class PrivateKeyAlgorithm : public AsymmetricAlgorithm
01055 {
01056 public:
01057 CryptoMaterial & AccessMaterial() {return AccessPrivateKey();}
01058 const CryptoMaterial & GetMaterial() const {return GetPrivateKey();}
01059
01060 virtual PrivateKey & AccessPrivateKey() =0;
01061 virtual const PrivateKey & GetPrivateKey() const {return const_cast<PrivateKeyAlgorithm *>(this)->AccessPrivateKey();}
01062 };
01063
01064
01065
01066 class KeyAgreementAlgorithm : public AsymmetricAlgorithm
01067 {
01068 public:
01069 CryptoMaterial & AccessMaterial() {return AccessCryptoParameters();}
01070 const CryptoMaterial & GetMaterial() const {return GetCryptoParameters();}
01071
01072 virtual CryptoParameters & AccessCryptoParameters() =0;
01073 virtual const CryptoParameters & GetCryptoParameters() const {return const_cast<KeyAgreementAlgorithm *>(this)->AccessCryptoParameters();}
01074 };
01075
01076
01077
01078
01079
01080
01081 class PK_CryptoSystem
01082 {
01083 public:
01084 virtual ~PK_CryptoSystem() {}
01085
01086
01087
01088 virtual unsigned int MaxPlaintextLength(unsigned int cipherTextLength) const =0;
01089
01090
01091
01092 virtual unsigned int CiphertextLength(unsigned int plainTextLength) const =0;
01093
01094 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
01095 unsigned int MaxPlainTextLength(unsigned int cipherTextLength) const {return MaxPlaintextLength(cipherTextLength);}
01096 unsigned int CipherTextLength(unsigned int plainTextLength) const {return CiphertextLength(plainTextLength);}
01097 #endif
01098 };
01099
01100
01101
01102 class PK_Encryptor : virtual public PK_CryptoSystem, public PublicKeyAlgorithm
01103 {
01104 public:
01105
01106 class InvalidPlaintextLength : public Exception
01107 {
01108 public:
01109 InvalidPlaintextLength() : Exception(OTHER_ERROR, "PK_Encryptor: invalid plaintext length") {}
01110 };
01111
01112
01113
01114
01115
01116 virtual void Encrypt(RandomNumberGenerator &rng, const byte *plainText, unsigned int plainTextLength, byte *cipherText) const =0;
01117
01118
01119
01120
01121 virtual BufferedTransformation * CreateEncryptionFilter(RandomNumberGenerator &rng, BufferedTransformation *attachment=NULL) const;
01122 };
01123
01124
01125
01126 class PK_Decryptor : virtual public PK_CryptoSystem, public PrivateKeyAlgorithm
01127 {
01128 public:
01129
01130
01131
01132
01133 virtual DecodingResult Decrypt(RandomNumberGenerator &rng, const byte *cipherText, unsigned int cipherTextLength, byte *plainText) const =0;
01134
01135
01136
01137
01138 virtual BufferedTransformation * CreateDecryptionFilter(RandomNumberGenerator &rng, BufferedTransformation *attachment=NULL) const;
01139 };
01140
01141
01142
01143
01144
01145
01146
01147 class PK_FixedLengthCryptoSystem : virtual public PK_CryptoSystem
01148 {
01149 public:
01150
01151 virtual unsigned int FixedMaxPlaintextLength() const =0;
01152
01153 virtual unsigned int FixedCiphertextLength() const =0;
01154
01155 unsigned int MaxPlaintextLength(unsigned int cipherTextLength) const;
01156 unsigned int CiphertextLength(unsigned int plainTextLength) const;
01157
01158 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
01159 unsigned int MaxPlainTextLength(unsigned int cipherTextLength) const {return MaxPlaintextLength(cipherTextLength);}
01160 unsigned int CipherTextLength(unsigned int plainTextLength) const {return CiphertextLength(plainTextLength);}
01161 unsigned int MaxPlainTextLength() const {return FixedMaxPlaintextLength();}
01162 unsigned int CipherTextLength() const {return FixedCiphertextLength();}
01163 #endif
01164 };
01165
01166
01167
01168 class PK_FixedLengthEncryptor : public PK_Encryptor, virtual public PK_FixedLengthCryptoSystem
01169 {
01170 };
01171
01172
01173
01174 class PK_FixedLengthDecryptor : public PK_Decryptor, virtual public PK_FixedLengthCryptoSystem
01175 {
01176 public:
01177
01178
01179
01180
01181
01182 virtual DecodingResult FixedLengthDecrypt(RandomNumberGenerator &rng, const byte *cipherText, byte *plainText) const =0;
01183
01184 DecodingResult Decrypt(RandomNumberGenerator &rng, const byte *cipherText, unsigned int cipherTextLength, byte *plainText) const;
01185 };
01186
01187
01188
01189
01190
01191
01192 class PK_SignatureScheme
01193 {
01194 public:
01195
01196 class InvalidKeyLength : public Exception
01197 {
01198 public:
01199 InvalidKeyLength(const std::string &message) : Exception(OTHER_ERROR, message) {}
01200 };
01201
01202
01203 class KeyTooShort : public InvalidKeyLength
01204 {
01205 public:
01206 KeyTooShort() : InvalidKeyLength("PK_Signer: key too short for this signature scheme") {}
01207 };
01208
01209 virtual ~PK_SignatureScheme() {}
01210
01211
01212 virtual unsigned int SignatureLength() const =0;
01213
01214
01215 virtual unsigned int MaxSignatureLength(unsigned int recoverablePartLength = 0) const {return SignatureLength();}
01216
01217
01218 virtual unsigned int MaxRecoverableLength() const =0;
01219
01220
01221 virtual unsigned int MaxRecoverableLengthFromSignatureLength(unsigned int signatureLength) const =0;
01222
01223
01224
01225 virtual bool IsProbabilistic() const =0;
01226
01227
01228 virtual bool AllowNonrecoverablePart() const =0;
01229
01230
01231 virtual bool SignatureUpfront() const {return false;}
01232
01233
01234 virtual bool RecoverablePartFirst() const =0;
01235 };
01236
01237
01238
01239
01240
01241 class PK_MessageAccumulator : public HashTransformation
01242 {
01243 public:
01244
01245 unsigned int DigestSize() const
01246 {throw NotImplemented("PK_MessageAccumulator: DigestSize() should not be called");}
01247
01248 void TruncatedFinal(byte *digest, unsigned int digestSize)
01249 {throw NotImplemented("PK_MessageAccumulator: TruncatedFinal() should not be called");}
01250 };
01251
01252
01253
01254 class PK_Signer : virtual public PK_SignatureScheme, public PrivateKeyAlgorithm
01255 {
01256 public:
01257
01258 virtual PK_MessageAccumulator * NewSignatureAccumulator(RandomNumberGenerator &rng = NullRNG()) const =0;
01259
01260 virtual void InputRecoverableMessage(PK_MessageAccumulator &messageAccumulator, const byte *recoverableMessage, unsigned int recoverableMessageLength) const =0;
01261
01262
01263
01264
01265
01266 virtual unsigned int Sign(RandomNumberGenerator &rng, PK_MessageAccumulator *messageAccumulator, byte *signature) const;
01267
01268
01269
01270
01271
01272 virtual unsigned int SignAndRestart(RandomNumberGenerator &rng, PK_MessageAccumulator &messageAccumulator, byte *signature, bool restart=true) const =0;
01273
01274
01275
01276
01277
01278 virtual unsigned int SignMessage(RandomNumberGenerator &rng, const byte *message, unsigned int messageLen, byte *signature) const;
01279
01280
01281
01282
01283
01284 virtual unsigned int SignMessageWithRecovery(RandomNumberGenerator &rng, const byte *recoverableMessage, unsigned int recoverableMessageLength,
01285 const byte *nonrecoverableMessage, unsigned int nonrecoverableMessageLength, byte *signature) const;
01286 };
01287
01288
01289
01290
01291
01292
01293
01294
01295 class PK_Verifier : virtual public PK_SignatureScheme, public PublicKeyAlgorithm
01296 {
01297 public:
01298
01299 virtual PK_MessageAccumulator * NewVerificationAccumulator() const =0;
01300
01301
01302 virtual void InputSignature(PK_MessageAccumulator &messageAccumulator, const byte *signature, unsigned int signatureLength) const =0;
01303
01304
01305 virtual bool Verify(PK_MessageAccumulator *messageAccumulator) const;
01306
01307
01308 virtual bool VerifyAndRestart(PK_MessageAccumulator &messageAccumulator) const =0;
01309
01310
01311 virtual bool VerifyMessage(const byte *message, unsigned int messageLen,
01312 const byte *signature, unsigned int signatureLength) const;
01313
01314
01315
01316
01317 virtual DecodingResult Recover(byte *recoveredMessage, PK_MessageAccumulator *messageAccumulator) const;
01318
01319
01320
01321
01322 virtual DecodingResult RecoverAndRestart(byte *recoveredMessage, PK_MessageAccumulator &messageAccumulator) const =0;
01323
01324
01325
01326
01327 virtual DecodingResult RecoverMessage(byte *recoveredMessage,
01328 const byte *nonrecoverableMessage, unsigned int nonrecoverableMessageLength,
01329 const byte *signature, unsigned int signatureLength) const;
01330 };
01331
01332
01333
01334
01335
01336
01337
01338 class SimpleKeyAgreementDomain : public KeyAgreementAlgorithm
01339 {
01340 public:
01341
01342 virtual unsigned int AgreedValueLength() const =0;
01343
01344 virtual unsigned int PrivateKeyLength() const =0;
01345
01346 virtual unsigned int PublicKeyLength() const =0;
01347
01348
01349 virtual void GeneratePrivateKey(RandomNumberGenerator &rng, byte *privateKey) const =0;
01350
01351
01352 virtual void GeneratePublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const =0;
01353
01354
01355 virtual void GenerateKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const;
01356
01357
01358
01359
01360
01361
01362 virtual bool Agree(byte *agreedValue, const byte *privateKey, const byte *otherPublicKey, bool validateOtherPublicKey=true) const =0;
01363
01364 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
01365 bool ValidateDomainParameters(RandomNumberGenerator &rng) const
01366 {return GetCryptoParameters().Validate(rng, 2);}
01367 #endif
01368 };
01369
01370
01371
01372
01373
01374
01375
01376 class AuthenticatedKeyAgreementDomain : public KeyAgreementAlgorithm
01377 {
01378 public:
01379
01380 virtual unsigned int AgreedValueLength() const =0;
01381
01382
01383 virtual unsigned int StaticPrivateKeyLength() const =0;
01384
01385 virtual unsigned int StaticPublicKeyLength() const =0;
01386
01387
01388 virtual void GenerateStaticPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const =0;
01389
01390
01391 virtual void GenerateStaticPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const =0;
01392
01393
01394 virtual void GenerateStaticKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const;
01395
01396
01397 virtual unsigned int EphemeralPrivateKeyLength() const =0;
01398
01399 virtual unsigned int EphemeralPublicKeyLength() const =0;
01400
01401
01402 virtual void GenerateEphemeralPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const =0;
01403
01404
01405 virtual void GenerateEphemeralPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const =0;
01406
01407
01408 virtual void GenerateEphemeralKeyPair(RandomNumberGenerator &rng, byte *privateKey, byte *publicKey) const;
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419 virtual bool Agree(byte *agreedValue,
01420 const byte *staticPrivateKey, const byte *ephemeralPrivateKey,
01421 const byte *staticOtherPublicKey, const byte *ephemeralOtherPublicKey,
01422 bool validateStaticOtherPublicKey=true) const =0;
01423
01424 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
01425 bool ValidateDomainParameters(RandomNumberGenerator &rng) const
01426 {return GetCryptoParameters().Validate(rng, 2);}
01427 #endif
01428 };
01429
01430
01431 #if 0
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453 class ProtocolSession
01454 {
01455 public:
01456
01457 class ProtocolError : public Exception
01458 {
01459 public:
01460 ProtocolError(ErrorType errorType, const std::string &s) : Exception(errorType, s) {}
01461 };
01462
01463
01464
01465 class UnexpectedMethodCall : public Exception
01466 {
01467 public:
01468 UnexpectedMethodCall(const std::string &s) : Exception(OTHER_ERROR, s) {}
01469 };
01470
01471 ProtocolSession() : m_rng(NULL), m_throwOnProtocolError(true), m_validState(false) {}
01472 virtual ~ProtocolSession() {}
01473
01474 virtual void InitializeSession(RandomNumberGenerator &rng, const NameValuePairs ¶meters) =0;
01475
01476 bool GetThrowOnProtocolError() const {return m_throwOnProtocolError;}
01477 void SetThrowOnProtocolError(bool throwOnProtocolError) {m_throwOnProtocolError = throwOnProtocolError;}
01478
01479 bool HasValidState() const {return m_validState;}
01480
01481 virtual bool OutgoingMessageAvailable() const =0;
01482 virtual unsigned int GetOutgoingMessageLength() const =0;
01483 virtual void GetOutgoingMessage(byte *message) =0;
01484
01485 virtual bool LastMessageProcessed() const =0;
01486 virtual void ProcessIncomingMessage(const byte *message, unsigned int messageLength) =0;
01487
01488 protected:
01489 void HandleProtocolError(Exception::ErrorType errorType, const std::string &s) const;
01490 void CheckAndHandleInvalidState() const;
01491 void SetValidState(bool valid) {m_validState = valid;}
01492
01493 RandomNumberGenerator *m_rng;
01494
01495 private:
01496 bool m_throwOnProtocolError, m_validState;
01497 };
01498
01499 class KeyAgreementSession : public ProtocolSession
01500 {
01501 public:
01502 virtual unsigned int GetAgreedValueLength() const =0;
01503 virtual void GetAgreedValue(byte *agreedValue) const =0;
01504 };
01505
01506 class PasswordAuthenticatedKeyAgreementSession : public KeyAgreementSession
01507 {
01508 public:
01509 void InitializePasswordAuthenticatedKeyAgreementSession(RandomNumberGenerator &rng,
01510 const byte *myId, unsigned int myIdLength,
01511 const byte *counterPartyId, unsigned int counterPartyIdLength,
01512 const byte *passwordOrVerifier, unsigned int passwordOrVerifierLength);
01513 };
01514
01515 class PasswordAuthenticatedKeyAgreementDomain : public KeyAgreementAlgorithm
01516 {
01517 public:
01518
01519 virtual bool ValidateDomainParameters(RandomNumberGenerator &rng) const
01520 {return GetCryptoParameters().Validate(rng, 2);}
01521
01522 virtual unsigned int GetPasswordVerifierLength(const byte *password, unsigned int passwordLength) const =0;
01523 virtual void GeneratePasswordVerifier(RandomNumberGenerator &rng, const byte *userId, unsigned int userIdLength, const byte *password, unsigned int passwordLength, byte *verifier) const =0;
01524
01525 enum RoleFlags {CLIENT=1, SERVER=2, INITIATOR=4, RESPONDER=8};
01526
01527 virtual bool IsValidRole(unsigned int role) =0;
01528 virtual PasswordAuthenticatedKeyAgreementSession * CreateProtocolSession(unsigned int role) const =0;
01529 };
01530 #endif
01531
01532
01533 class BERDecodeErr : public InvalidArgument
01534 {
01535 public:
01536 BERDecodeErr() : InvalidArgument("BER decode error") {}
01537 BERDecodeErr(const std::string &s) : InvalidArgument(s) {}
01538 };
01539
01540
01541 class ASN1Object
01542 {
01543 public:
01544 virtual ~ASN1Object() {}
01545
01546 virtual void BERDecode(BufferedTransformation &bt) =0;
01547
01548 virtual void DEREncode(BufferedTransformation &bt) const =0;
01549
01550
01551 virtual void BEREncode(BufferedTransformation &bt) const {DEREncode(bt);}
01552 };
01553
01554 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
01555 typedef PK_SignatureScheme PK_SignatureSystem
01556 typedef PK_SignatureSchemeWithRecovery PK_SignatureSystemWithRecovery
01557 typedef SimpleKeyAgreementDomain PK_SimpleKeyAgreementDomain
01558 typedef AuthenticatedKeyAgreementDomain PK_AuthenticatedKeyAgreementDomain
01559 typedef WithPrecomputation PK_WithPrecomputation
01560 #endif
01561
01562 NAMESPACE_END
01563
01564 #endif