83 #ifndef CRYPTOPP_CRYPTLIB_H 84 #define CRYPTOPP_CRYPTLIB_H 90 #if defined(CRYPTOPP_BSD_AVAILABLE) || defined(CRYPTOPP_UNIX_AVAILABLE) 94 #if CRYPTOPP_MSC_VERSION 95 # pragma warning(push) 96 # pragma warning(disable: 4127 4189 4702) 119 template <
typename ENUM_TYPE,
int VALUE>
122 static ENUM_TYPE ToEnum() {
return (ENUM_TYPE)VALUE;}
171 const char *
what()
const throw() {
return (m_what.c_str());}
173 const std::string &
GetWhat()
const {
return m_what;}
175 void SetWhat(
const std::string &s) {m_what = s;}
225 OS_Error(
ErrorType errorType,
const std::string &s,
const std::string& operation,
int errorCode)
226 :
Exception(errorType, s), m_operation(operation), m_errorCode(errorCode) {}
235 std::string m_operation;
266 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 267 operator size_t()
const {
return isValidCoding ? messageLength : 0;}
297 ValueTypeMismatch(
const std::string &name,
const std::type_info &stored,
const std::type_info &retrieving)
298 :
InvalidArgument(
"NameValuePairs: type mismatch for '" + name +
"', stored '" + stored.name() +
"', trying to retrieve '" + retrieving.name() +
"'")
299 , m_stored(stored), m_retrieving(retrieving) {}
310 const std::type_info &m_stored;
311 const std::type_info &m_retrieving;
320 return GetValue((std::string(
"ThisObject:")+
typeid(T).name()).c_str(),
object);
329 return GetValue((std::string(
"ThisPointer:")+
typeid(T).name()).c_str(), ptr);
342 return GetVoidValue(name,
typeid(T), &value);
356 bool result = GetValue(name, value);
358 if (result) {
return value;}
365 CRYPTOPP_DLL std::string GetValueNames()
const 366 {std::string result; GetValue(
"ValueNames", result);
return result;}
376 CRYPTOPP_DLL
bool GetIntValue(
const char *name,
int &value)
const 377 {
return GetValue(name, value);}
385 CRYPTOPP_DLL
int GetIntValueWithDefault(
const char *name,
int defaultValue)
const 386 {
return GetValueWithDefault(name, defaultValue);}
397 CRYPTOPP_DLL
static void CRYPTOPP_API ThrowIfTypeMismatch(
const char *name,
const std::type_info &stored,
const std::type_info &retrieving)
413 if (!GetValue(name, value))
414 throw InvalidArgument(std::string(className) +
": missing required parameter '" + name +
"'");
426 CRYPTOPP_DLL
void GetRequiredIntParameter(
const char *className,
const char *name,
int &value)
const 428 if (!GetIntValue(name, value))
429 throw InvalidArgument(std::string(className) +
": missing required parameter '" + name +
"'");
442 CRYPTOPP_DLL
virtual bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const =0;
445 #if CRYPTOPP_DOXYGEN_PROCESSING 454 DOCUMENTED_NAMESPACE_BEGIN(
Name)
456 DOCUMENTED_NAMESPACE_END
471 DOCUMENTED_NAMESPACE_BEGIN(
Weak)
473 DOCUMENTED_NAMESPACE_END
503 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 515 Algorithm(
bool checkSelfTestStatus =
true);
535 virtual size_t MinKeyLength()
const =0;
537 virtual size_t MaxKeyLength()
const =0;
539 virtual size_t DefaultKeyLength()
const =0;
544 virtual size_t GetValidKeyLength(
size_t n)
const =0;
551 {
return keylength == GetValidKeyLength(keylength);}
568 void SetKeyWithRounds(
const byte *key,
size_t length,
int rounds);
578 void SetKeyWithIV(
const byte *key,
size_t length,
const byte *iv,
size_t ivLength);
588 {SetKeyWithIV(key, length, iv, IVSize());}
638 {
throw NotImplemented(GetAlgorithm().AlgorithmName() +
": this object doesn't support resynchronization");}
660 CRYPTOPP_UNUSED(iv); CRYPTOPP_UNUSED(ivLength);
661 throw NotImplemented(GetAlgorithm().AlgorithmName() +
": this object doesn't support resynchronization");
678 virtual const Algorithm & GetAlgorithm()
const =0;
685 virtual void UncheckedSetKey(
const byte *key,
unsigned int length,
const NameValuePairs ¶ms) =0;
690 void ThrowIfInvalidKeyLength(
size_t length);
697 void ThrowIfResynchronizable();
706 void ThrowIfInvalidIV(
const byte *iv);
711 size_t ThrowIfInvalidIVLength(
int length);
718 const byte * GetIVAndThrowIfInvalid(
const NameValuePairs ¶ms,
size_t &size);
722 inline void AssertValidKeyLength(
size_t length)
const 734 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 747 virtual void ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const =0;
758 {ProcessAndXorBlock(inBlock, NULL, outBlock);}
767 {ProcessAndXorBlock(inoutBlock, NULL, inoutBlock);}
771 virtual unsigned int BlockSize()
const =0;
775 virtual unsigned int OptimalDataAlignment()
const;
783 virtual bool IsForwardTransformation()
const =0;
793 BT_InBlockIsCounter=1,
795 BT_DontIncrementInOutPointers=2,
799 BT_ReverseDirection=8,
801 BT_AllowParallel=16};
811 virtual size_t AdvancedProcessBlocks(
const byte *inBlocks,
const byte *xorBlocks, byte *outBlocks,
size_t length, word32 flags)
const;
825 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 851 virtual unsigned int OptimalDataAlignment()
const;
858 virtual void ProcessData(byte *outString,
const byte *inString,
size_t length) =0;
866 virtual void ProcessLastBlock(byte *outString,
const byte *inString,
size_t length);
879 {ProcessData(inoutString, inoutString, length);}
886 inline void ProcessString(byte *outString,
const byte *inString,
size_t length)
887 {ProcessData(outString, inString, length);}
893 {ProcessData(&input, &input, 1);
return input;}
897 virtual bool IsRandomAccess()
const =0;
906 CRYPTOPP_UNUSED(pos);
908 throw NotImplemented(
"StreamTransformation: this object doesn't support random access");
915 virtual bool IsSelfInverting()
const =0;
920 virtual bool IsForwardTransformation()
const =0;
934 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 946 virtual void Update(
const byte *input,
size_t length) =0;
969 {TruncatedFinal(NULL, 0);}
995 virtual unsigned int OptimalDataAlignment()
const;
1007 {Update(input, length); Final(digest);}
1019 {
return TruncatedVerify(digest,
DigestSize());}
1034 virtual bool VerifyDigest(
const byte *digest,
const byte *input,
size_t length)
1035 {Update(input, length);
return Verify(digest);}
1042 virtual void TruncatedFinal(byte *digest,
size_t digestSize) =0;
1055 {Update(input, length); TruncatedFinal(digest, digestSize);}
1067 virtual bool TruncatedVerify(
const byte *digest,
size_t digestLength);
1084 {Update(input, length);
return TruncatedVerify(digest, digestLength);}
1091 void ThrowIfInvalidTruncatedSize(
size_t size)
const;
1101 const Algorithm & GetAlgorithm()
const {
return *
this;}
1109 const Algorithm & GetAlgorithm()
const {
return *
this;}
1117 const Algorithm & GetAlgorithm()
const {
return *
this;}
1127 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 1137 explicit BadState(
const std::string &name,
const char *message) :
Exception(OTHER_ERROR, name +
": " + message) {}
1138 explicit BadState(
const std::string &name,
const char *
function,
const char *state) :
Exception(OTHER_ERROR, name +
": " +
function +
" was called before " + state) {}
1143 virtual lword MaxHeaderLength()
const =0;
1146 virtual lword MaxMessageLength()
const =0;
1159 void SpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength=0);
1164 virtual void EncryptAndAuthenticate(byte *ciphertext, byte *mac,
size_t macSize,
const byte *iv,
int ivLength,
const byte *header,
size_t headerLength,
const byte *message,
size_t messageLength);
1169 virtual bool DecryptAndVerify(byte *message,
const byte *mac,
size_t macLength,
const byte *iv,
int ivLength,
const byte *header,
size_t headerLength,
const byte *ciphertext,
size_t ciphertextLength);
1176 virtual std::string AlgorithmName()
const =0;
1181 virtual void UncheckedSpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength)
1182 {CRYPTOPP_UNUSED(headerLength); CRYPTOPP_UNUSED(messageLength); CRYPTOPP_UNUSED(footerLength);}
1185 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 1196 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 1210 CRYPTOPP_UNUSED(input); CRYPTOPP_UNUSED(length);
1211 throw NotImplemented(
"RandomNumberGenerator: IncorporateEntropy not implemented");
1223 virtual byte GenerateByte();
1230 virtual unsigned int GenerateBit();
1240 virtual word32 GenerateWord32(word32 min=0, word32 max=0xffffffffUL);
1249 virtual void GenerateBlock(byte *output,
size_t size);
1261 virtual void GenerateIntoBufferedTransformation(
BufferedTransformation &target,
const std::string &channel, lword length);
1265 virtual void DiscardBytes(
size_t n);
1271 template <
class IT>
void Shuffle(IT begin, IT end)
1274 for (; begin != end; ++begin)
1275 std::iter_swap(begin, begin + GenerateWord32(0, end-begin-1));
1278 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 1279 byte
GetByte() {
return GenerateByte();}
1280 unsigned int GetBit() {
return GenerateBit();}
1281 word32 GetLong(word32 a=0, word32 b=0xffffffffL) {
return GenerateWord32(a, b);}
1282 word16 GetShort(word16 a=0, word16 b=0xffff) {
return (word16)GenerateWord32(a, b);}
1283 void GetBlock(byte *output,
size_t size) {GenerateBlock(output, size);}
1309 virtual unsigned int GetMaxWaitObjectCount()
const =0;
1325 bool Wait(
unsigned long milliseconds,
CallStack const& callStack);
1334 extern CRYPTOPP_DLL
const std::string
AAD_CHANNEL;
1363 static const std::string &NULL_CHANNEL;
1365 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 1385 size_t Put(byte inByte,
bool blocking=
true)
1386 {
return Put(&inByte, 1, blocking);}
1394 size_t Put(
const byte *inString,
size_t length,
bool blocking=
true)
1395 {
return Put2(inString, length, 0, blocking);}
1421 {size=0;
return NULL;}
1436 {
return PutModifiable2(inString, length, 0, blocking);}
1444 {
return !!Put2(NULL, 0, propagation < 0 ? -1 : propagation+1, blocking);}
1456 size_t PutMessageEnd(
const byte *inString,
size_t length,
int propagation=-1,
bool blocking=
true)
1457 {
return Put2(inString, length, propagation < 0 ? -1 : propagation+1, blocking);}
1465 virtual size_t Put2(
const byte *inString,
size_t length,
int messageEnd,
bool blocking) =0;
1473 virtual size_t PutModifiable2(byte *inString,
size_t length,
int messageEnd,
bool blocking)
1474 {
return Put2(inString, length, messageEnd, blocking);}
1486 unsigned int GetMaxWaitObjectCount()
const;
1513 CRYPTOPP_UNUSED(parameters);
1514 throw NotImplemented(
"BufferedTransformation: this object can't be reinitialized");
1521 virtual bool IsolatedFlush(
bool hardFlush,
bool blocking) =0;
1527 {CRYPTOPP_UNUSED(blocking);
return false;}
1553 virtual bool Flush(
bool hardFlush,
int propagation=-1,
bool blocking=
true);
1563 virtual bool MessageSeriesEnd(
int propagation=-1,
bool blocking=
true);
1570 {CRYPTOPP_UNUSED(propagation);}
1578 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 1579 void Close() {MessageEnd();}
1590 virtual lword MaxRetrievable()
const;
1594 virtual bool AnyRetrievable()
const;
1600 virtual size_t Get(byte &outByte);
1607 virtual size_t Get(byte *outString,
size_t getMax);
1614 virtual size_t Peek(byte &outByte)
const;
1622 virtual size_t Peek(byte *outString,
size_t peekMax)
const;
1664 {TransferTo2(target, transferMax, channel);
return transferMax;}
1676 virtual lword Skip(lword skipMax=LWORD_MAX);
1688 {
return CopyRangeTo(target, 0, copyMax, channel);}
1701 {lword i = position; CopyRangeTo2(target, i, i+copyMax, channel);
return i-position;}
1703 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 1704 unsigned long MaxRetrieveable()
const {
return MaxRetrievable();}
1713 virtual lword TotalBytesRetrievable()
const;
1719 virtual unsigned int NumberOfMessages()
const;
1724 virtual bool AnyMessages()
const;
1730 virtual bool GetNextMessage();
1737 virtual unsigned int SkipMessages(
unsigned int count=UINT_MAX);
1749 {TransferMessagesTo2(target, count, channel);
return count;}
1763 virtual void SkipAll();
1772 {TransferAllTo2(target, channel);}
1872 size_t ChannelPut(
const std::string &channel, byte inByte,
bool blocking=
true)
1873 {
return ChannelPut(channel, &inByte, 1, blocking);}
1882 size_t ChannelPut(
const std::string &channel,
const byte *inString,
size_t length,
bool blocking=
true)
1883 {
return ChannelPut2(channel, inString, length, 0, blocking);}
1893 {
return ChannelPutModifiable2(channel, inString, length, 0, blocking);}
1902 size_t ChannelPutWord16(
const std::string &channel, word16 value,
ByteOrder order=
BIG_ENDIAN_ORDER,
bool blocking=
true);
1911 size_t ChannelPutWord32(
const std::string &channel, word32 value,
ByteOrder order=
BIG_ENDIAN_ORDER,
bool blocking=
true);
1922 {
return !!ChannelPut2(channel, NULL, 0, propagation < 0 ? -1 : propagation+1, blocking);}
1933 size_t ChannelPutMessageEnd(
const std::string &channel,
const byte *inString,
size_t length,
int propagation=-1,
bool blocking=
true)
1934 {
return ChannelPut2(channel, inString, length, propagation < 0 ? -1 : propagation+1, blocking);}
1947 virtual byte * ChannelCreatePutSpace(
const std::string &channel,
size_t &size);
1956 virtual size_t ChannelPut2(
const std::string &channel,
const byte *inString,
size_t length,
int messageEnd,
bool blocking);
1965 virtual size_t ChannelPutModifiable2(
const std::string &channel, byte *inString,
size_t length,
int messageEnd,
bool blocking);
1975 virtual bool ChannelFlush(
const std::string &channel,
bool hardFlush,
int propagation=-1,
bool blocking=
true);
1986 virtual bool ChannelMessageSeriesEnd(
const std::string &channel,
int propagation=-1,
bool blocking=
true);
1991 virtual void SetRetrievalChannel(
const std::string &channel);
2026 throw NotImplemented(
"BufferedTransformation: this object is not attachable");
2037 static int DecrementPropagation(
int propagation)
2038 {
return propagation != 0 ? propagation - 1 : 0;}
2053 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2091 {
if (!Validate(rng, level))
throw InvalidMaterial(
"CryptoMaterial: this object contains invalid values");}
2103 {CRYPTOPP_UNUSED(bt);
throw NotImplemented(
"CryptoMaterial: this object does not support saving");}
2120 {CRYPTOPP_UNUSED(bt);
throw NotImplemented(
"CryptoMaterial: this object does not support loading");}
2136 CRYPTOPP_UNUSED(precomputationStorage);
CRYPTOPP_ASSERT(!SupportsPrecomputation());
2137 throw NotImplemented(
"CryptoMaterial: this object does not support precomputation");
2145 {CRYPTOPP_UNUSED(storedPrecomputation);
CRYPTOPP_ASSERT(!SupportsPrecomputation());
throw NotImplemented(
"CryptoMaterial: this object does not support precomputation");}
2151 {CRYPTOPP_UNUSED(storedPrecomputation);
CRYPTOPP_ASSERT(!SupportsPrecomputation());
throw NotImplemented(
"CryptoMaterial: this object does not support precomputation");}
2157 #if (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590) 2159 char m_sunCCworkaround;
2168 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2179 CRYPTOPP_UNUSED(rng); CRYPTOPP_UNUSED(params);
2180 throw NotImplemented(
"GeneratableCryptoMaterial: this object does not support key/parameter generation");
2211 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2227 {AccessMaterial().Load(bt);}
2233 {GetMaterial().Save(bt);}
2240 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2249 {
return AccessPublicKey();}
2253 {
return GetPublicKey();}
2257 virtual PublicKey & AccessPublicKey() =0;
2268 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2281 virtual PrivateKey & AccessPrivateKey() =0;
2291 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2304 virtual CryptoParameters & AccessCryptoParameters() =0;
2321 virtual size_t MaxPlaintextLength(
size_t ciphertextLength)
const =0;
2326 virtual size_t CiphertextLength(
size_t plaintextLength)
const =0;
2333 virtual bool ParameterSupported(
const char *name)
const =0;
2348 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 2349 size_t MaxPlainTextLength(
size_t cipherTextLength)
const {
return MaxPlaintextLength(cipherTextLength);}
2350 size_t CipherTextLength(
size_t plainTextLength)
const {
return CiphertextLength(plainTextLength);}
2377 const byte *plaintext,
size_t plaintextLength,
2395 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2414 const byte *ciphertext,
size_t ciphertextLength,
2440 {
return Decrypt(rng, ciphertext, FixedCiphertextLength(), plaintext, parameters);}
2443 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 2480 virtual size_t SignatureLength()
const =0;
2488 {CRYPTOPP_UNUSED(recoverablePartLength);
return SignatureLength();}
2494 virtual size_t MaxRecoverableLength()
const =0;
2502 virtual size_t MaxRecoverableLengthFromSignatureLength(
size_t signatureLength)
const =0;
2508 virtual bool IsProbabilistic()
const =0;
2512 virtual bool AllowNonrecoverablePart()
const =0;
2524 virtual bool RecoverablePartFirst()
const =0;
2536 {
throw NotImplemented(
"PK_MessageAccumulator: DigestSize() should not be called");}
2541 CRYPTOPP_UNUSED(digest); CRYPTOPP_UNUSED(digestSize);
2542 throw NotImplemented(
"PK_MessageAccumulator: TruncatedFinal() should not be called");
2551 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2566 virtual void InputRecoverableMessage(
PK_MessageAccumulator &messageAccumulator,
const byte *recoverableMessage,
size_t recoverableMessageLength)
const =0;
2593 virtual size_t SignMessage(
RandomNumberGenerator &rng,
const byte *message,
size_t messageLen, byte *signature)
const;
2604 virtual size_t SignMessageWithRecovery(
RandomNumberGenerator &rng,
const byte *recoverableMessage,
size_t recoverableMessageLength,
2605 const byte *nonrecoverableMessage,
size_t nonrecoverableMessageLength, byte *signature)
const;
2618 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2632 virtual void InputSignature(
PK_MessageAccumulator &messageAccumulator,
const byte *signature,
size_t signatureLength)
const =0;
2652 virtual bool VerifyMessage(
const byte *message,
size_t messageLen,
2653 const byte *signature,
size_t signatureLen)
const;
2680 const byte *nonrecoverableMessage,
size_t nonrecoverableMessageLength,
2681 const byte *signature,
size_t signatureLength)
const;
2692 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2698 virtual unsigned int AgreedValueLength()
const =0;
2702 virtual unsigned int PrivateKeyLength()
const =0;
2706 virtual unsigned int PublicKeyLength()
const =0;
2719 virtual void GeneratePublicKey(
RandomNumberGenerator &rng,
const byte *privateKey, byte *publicKey)
const =0;
2742 virtual bool Agree(byte *agreedValue,
const byte *privateKey,
const byte *otherPublicKey,
bool validateOtherPublicKey=
true)
const =0;
2744 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 2746 {
return GetCryptoParameters().Validate(rng, 2);}
2757 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2763 virtual unsigned int AgreedValueLength()
const =0;
2767 virtual unsigned int StaticPrivateKeyLength()
const =0;
2771 virtual unsigned int StaticPublicKeyLength()
const =0;
2784 virtual void GenerateStaticPublicKey(
RandomNumberGenerator &rng,
const byte *privateKey, byte *publicKey)
const =0;
2793 virtual void GenerateStaticKeyPair(
RandomNumberGenerator &rng, byte *privateKey, byte *publicKey)
const;
2797 virtual unsigned int EphemeralPrivateKeyLength()
const =0;
2801 virtual unsigned int EphemeralPublicKeyLength()
const =0;
2814 virtual void GenerateEphemeralPublicKey(
RandomNumberGenerator &rng,
const byte *privateKey, byte *publicKey)
const =0;
2821 virtual void GenerateEphemeralKeyPair(
RandomNumberGenerator &rng, byte *privateKey, byte *publicKey)
const;
2839 virtual bool Agree(byte *agreedValue,
2840 const byte *staticPrivateKey,
const byte *ephemeralPrivateKey,
2841 const byte *staticOtherPublicKey,
const byte *ephemeralOtherPublicKey,
2842 bool validateStaticOtherPublicKey=
true)
const =0;
2844 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 2846 {
return GetCryptoParameters().Validate(rng, 2);}
2873 class ProtocolSession
2880 ProtocolError(ErrorType errorType,
const std::string &s) :
Exception(errorType, s) {}
2885 class UnexpectedMethodCall :
public Exception 2888 UnexpectedMethodCall(
const std::string &s) :
Exception(OTHER_ERROR, s) {}
2891 ProtocolSession() : m_rng(NULL), m_throwOnProtocolError(
true), m_validState(
false) {}
2892 virtual ~ProtocolSession() {}
2896 bool GetThrowOnProtocolError()
const {
return m_throwOnProtocolError;}
2897 void SetThrowOnProtocolError(
bool throwOnProtocolError) {m_throwOnProtocolError = throwOnProtocolError;}
2899 bool HasValidState()
const {
return m_validState;}
2901 virtual bool OutgoingMessageAvailable()
const =0;
2902 virtual unsigned int GetOutgoingMessageLength()
const =0;
2903 virtual void GetOutgoingMessage(byte *message) =0;
2905 virtual bool LastMessageProcessed()
const =0;
2906 virtual void ProcessIncomingMessage(
const byte *message,
unsigned int messageLength) =0;
2910 void CheckAndHandleInvalidState()
const;
2911 void SetValidState(
bool valid) {m_validState = valid;}
2916 bool m_throwOnProtocolError, m_validState;
2919 class KeyAgreementSession :
public ProtocolSession
2922 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2923 virtual ~KeyAgreementSession() {}
2926 virtual unsigned int GetAgreedValueLength()
const =0;
2927 virtual void GetAgreedValue(byte *agreedValue)
const =0;
2930 class PasswordAuthenticatedKeyAgreementSession :
public KeyAgreementSession
2933 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2934 virtual ~PasswordAuthenticatedKeyAgreementSession() {}
2938 const byte *myId,
unsigned int myIdLength,
2939 const byte *counterPartyId,
unsigned int counterPartyIdLength,
2940 const byte *passwordOrVerifier,
unsigned int passwordOrVerifierLength);
2946 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2947 virtual ~PasswordAuthenticatedKeyAgreementDomain() {}
2952 {
return GetCryptoParameters().Validate(rng, 2);}
2954 virtual unsigned int GetPasswordVerifierLength(
const byte *password,
unsigned int passwordLength)
const =0;
2955 virtual void GeneratePasswordVerifier(
RandomNumberGenerator &rng,
const byte *userId,
unsigned int userIdLength,
const byte *password,
unsigned int passwordLength, byte *verifier)
const =0;
2957 enum RoleFlags {CLIENT=1, SERVER=2, INITIATOR=4, RESPONDER=8};
2959 virtual bool IsValidRole(
unsigned int role) =0;
2960 virtual PasswordAuthenticatedKeyAgreementSession * CreateProtocolSession(
unsigned int role)
const =0;
2998 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 3006 #if CRYPTOPP_MSC_VERSION 3007 # pragma warning(pop)
Base class for all exceptions thrown by the library.
void DEREncode(BufferedTransformation &bt) const
Saves this object to a BufferedTransformation.
Exception thrown when invalid crypto material is detected.
virtual void Precompute(unsigned int precomputationStorage)
Perform precomputation.
the cipher is performing decryption
const char * DigestSize()
int, in bytes
An invalid argument was detected.
void SetKeyWithIV(const byte *key, size_t length, const byte *iv)
Sets or reset the key of this object.
Interface for message authentication codes.
ErrorType
Error types or categories.
container of wait objects
Interface for asymmetric algorithms.
virtual unsigned int MinIVLength() const
Provides the minimum size of an IV.
virtual bool NeedsPrespecifiedDataLengths() const
Determines if data lengths must be specified prior to inputting data.
Interface for public-key encryptors and decryptors.
ByteOrder
Provides the byte ordering.
const char * what() const
Retrieves a C-string describing the exception.
virtual void ThrowIfInvalid(RandomNumberGenerator &rng, unsigned int level) const
Check this object for errors.
The IV is set by the object.
The operating system reported an error.
Interface for one direction (encryption or decryption) of a stream cipher or block cipher mode with a...
T GetValueWithDefault(const char *name, T defaultValue) const
Get a named value.
const std::type_info & GetStoredTypeInfo() const
Provides the stored type.
virtual void Load(BufferedTransformation &bt)
Loads a key from a BufferedTransformation.
Exception(ErrorType errorType, const std::string &s)
Construct a new Exception.
Exception thrown when the object is in the wrong state for the operation.
const CryptoMaterial & GetMaterial() const
Retrieves a reference to Crypto Parameters.
Interface for public-key signers.
Interface for public-key encryptors.
Converts a typename to an enumerated value.
bool GetThisObject(T &object) const
Get a copy of this object or subobject.
bool CanUseRandomIVs() const
Determines if the object can use random IVs.
CipherDir
Specifies a direction for a cipher to operate.
void BERDecode(BufferedTransformation &bt)
Loads this object from a BufferedTransformation.
DecodingResult FixedLengthDecrypt(RandomNumberGenerator &rng, const byte *ciphertext, byte *plaintext, const NameValuePairs ¶meters=g_nullNameValuePairs) const
Decrypt a fixed size ciphertext.
Flush(true) was called but it can't completely flush its buffers.
Thrown when an unexpected type is encountered.
CryptoMaterial & AccessMaterial()
Retrieves a reference to a Private Key.
Interface for asymmetric algorithms using private keys.
BufferedTransformation & TheBitBucket()
An input discarding BufferedTransformation.
ValueTypeMismatch(const std::string &name, const std::type_info &stored, const std::type_info &retrieving)
Construct a ValueTypeMismatch.
virtual Clonable * Clone() const
Copies this object.
EnumToType< ByteOrder, LITTLE_ENDIAN_ORDER > LittleEndian
Provides a constant for LittleEndian.
Library configuration file.
Interface for random number generators.
size_t messageLength
Recovered message length if isValidCoding is true, undefined otherwise.
virtual const PublicKey & GetPublicKey() const
Retrieves a reference to a Public Key.
Interface for private keys.
Interface for cloning objects.
virtual size_t FixedCiphertextLength() const
Provides the fixed ciphertext length, if one exists.
bool operator==(const OID &lhs, const OID &rhs)
Compare two OIDs for equality.
Data integerity check, such as CRC or MAC, failed.
byte order is little-endian
Interface for one direction (encryption or decryption) of a block cipher.
void SetWhat(const std::string &s)
Sets the error string for the exception.
Interface for objects that can be waited on.
the cipher is performing encryption
virtual void SavePrecomputation(BufferedTransformation &storedPrecomputation) const
Save precomputation for later use.
const std::type_info & GetRetrievingTypeInfo() const
Provides the retrieveing type.
void DoQuickSanityCheck() const
Perform a quick sanity check.
Interface for domains of simple key agreement protocols.
const CryptoMaterial & GetMaterial() const
Retrieves a reference to a Private Key.
bool CanUsePredictableIVs() const
Determines if the object can use random but possibly predictable IVs.
Returns a decoding results.
virtual void LoadPrecomputation(BufferedTransformation &storedPrecomputation)
Retrieve previously saved precomputation.
Exception thrown when trying to encrypt plaintext of invalid length.
Input data was received that did not conform to expected format.
Interface for public-key decryptors.
A method was called which was not implemented.
Exception throw when the private or public key is too short to sign or verify.
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
bool operator!=(const DecodingResult &rhs) const
Compare two DecodingResult.
virtual unsigned int MaxIVLength() const
Provides the maximum size of an IV.
unsigned int DigestSize() const
virtual bool IsValidKeyLength(size_t keylength) const
Returns whether keylength is a valid key length.
Interface for encoding and decoding ASN1 objects.
virtual void Resynchronize(const byte *iv, int ivLength=-1)
Resynchronize with an IV.
DecodingResult()
Constructs a DecodingResult.
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode...
Multiple precision integer with arithmetic operations.
DecodingResult(size_t len)
Constructs a DecodingResult.
Exception throw when the private or public key has a length that can't be used.
Interface for algorithms that take byte strings as keys.
bool operator==(const DecodingResult &rhs) const
Compare two DecodingResult.
Interface for asymmetric algorithms using public keys.
virtual unsigned int IVSize() const
Returns length of the IV accepted by this object.
const NameValuePairs & g_nullNameValuePairs
An empty set of name-value pairs.
virtual bool CanIncorporateEntropy() const
Determines if a generator can accept additional entropy.
bool CanUseStructuredIVs() const
Determines if the object can use structured IVs.
Interface for public-key signers and verifiers.
const std::string & GetOperation() const
Retrieve the operating system API that reported the error.
virtual std::string AlgorithmName() const
Provides the name of this algorithm.
RandomNumberGenerator & NullRNG()
Random Number Generator that does not produce random numbers.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
int GetErrorCode() const
Retrieve the error code returned by the operating system.
const char * BlockSize()
int, in bytes
const unsigned long INFINITE_TIME
Represents infinite time.
ErrorType GetErrorType() const
Retrieves the error type for the exception.
void GetRequiredParameter(const char *className, const char *name, T &value) const
Retrieves a required name/value pair.
Interface for all crypto algorithms.
Interface for accumulating messages to be signed or verified.
unsigned int DefaultIVLength() const
Provides the default size of an IV.
A decryption filter encountered invalid ciphertext.
Interface for key agreement algorithms.
IV_Requirement
Secure IVs requirements as enumerated values.
CryptoMaterial & AccessMaterial()
Retrieves a reference to a Public Key.
virtual const CryptoParameters & GetCryptoParameters() const
Retrieves a reference to Crypto Parameters.
Interface for public-key signature verifiers.
void Shuffle(IT begin, IT end)
Randomly shuffle the specified array.
Debugging and diagnostic assertions.
Interface for crypto material, such as public and private keys, and crypto parameters.
virtual void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs ¶ms=g_nullNameValuePairs)
Generate a random key or crypto parameters.
Access a block of memory.
CryptoMaterial & AccessMaterial()
Retrieves a reference to Crypto Parameters.
An invalid argument was detected.
Interface for generatable crypto material, such as private keys and crypto parameters.
Interface for crypto prameters.
bool GetThisPointer(T *&ptr) const
Get a pointer to this object.
bool isValidCoding
Flag to indicate the decoding is valid.
Namespace containing value name definitions.
BufferedTransformation received a Flush(true) signal but can't flush buffers.
void SetErrorType(ErrorType errorType)
Sets the error type for the exceptions.
Interface for public keys.
Crypto++ library namespace.
bool GetValue(const char *name, T &value) const
Get a named value.
The IV must be random and unpredictable.
bool IsResynchronizable() const
Determines if the object can be resynchronized.
Interface for domains of authenticated key agreement protocols.
void TruncatedFinal(byte *digest, size_t digestSize)
A method was called which was not implemented.
const std::string AAD_CHANNEL
Channel for additional authenticated data.
virtual void BEREncode(BufferedTransformation &bt) const
Encode this object into a BufferedTransformation.
Error reading from input device or writing to output device.
virtual void Save(BufferedTransformation &bt) const
Saves a key to a BufferedTransformation.
virtual bool SupportsPrecomputation() const
Determines whether the object supports precomputation.
unsigned int GetByte(ByteOrder order, T value, unsigned int index)
Gets a byte from a value.
virtual lword MaxFooterLength() const
Provides the the maximum length of AAD.
virtual const PrivateKey & GetPrivateKey() const
Retrieves a reference to a Private Key.
const CryptoMaterial & GetMaterial() const
Retrieves a reference to a Public Key.
virtual size_t MaxSignatureLength(size_t recoverablePartLength=0) const
Provides the maximum signature length produced given the length of the recoverable message part...
EnumToType< ByteOrder, BIG_ENDIAN_ORDER > BigEndian
Provides a constant for BigEndian.
Namespace containing weak and wounded algorithms.
virtual bool SignatureUpfront() const
Determines whether the signature must be input before the message.
virtual void IncorporateEntropy(const byte *input, size_t length)
Update RNG state with additional unpredictable values.
virtual size_t FixedMaxPlaintextLength() const
Provides the maximum plaintext length given a fixed ciphertext length.
Interface for retrieving values given their names.
Exception thrown when an ASN.1 BER decoing error is encountered.
The IV must be random and possibly predictable.
const std::string & GetWhat() const
Retrieves a string describing the exception.