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