83 #ifndef CRYPTOPP_CRYPTLIB_H 84 #define CRYPTOPP_CRYPTLIB_H 89 #if CRYPTOPP_MSC_VERSION 90 # pragma warning(push) 91 # pragma warning(disable: 4127 4189 4702) 109 template <
typename ENUM_TYPE,
int VALUE>
112 static ENUM_TYPE ToEnum() {
return (ENUM_TYPE)VALUE;}
116 enum ByteOrder {LITTLE_ENDIAN_ORDER = 0, BIG_ENDIAN_ORDER = 1};
150 const char *
what()
const throw() {
return (m_what.c_str());}
152 const std::string &
GetWhat()
const {
return m_what;}
154 void SetWhat(
const std::string &s) {m_what = s;}
204 OS_Error(
ErrorType errorType,
const std::string &s,
const std::string& operation,
int errorCode)
205 :
Exception(errorType, s), m_operation(operation), m_errorCode(errorCode) {}
214 std::string m_operation;
245 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 246 operator size_t()
const {
return isValidCoding ? messageLength : 0;}
276 ValueTypeMismatch(
const std::string &name,
const std::type_info &stored,
const std::type_info &retrieving)
277 :
InvalidArgument(
"NameValuePairs: type mismatch for '" + name +
"', stored '" + stored.name() +
"', trying to retrieve '" + retrieving.name() +
"'")
278 , m_stored(stored), m_retrieving(retrieving) {}
289 const std::type_info &m_stored;
290 const std::type_info &m_retrieving;
299 return GetValue((std::string(
"ThisObject:")+
typeid(T).name()).c_str(),
object);
308 return GetValue((std::string(
"ThisPointer:")+
typeid(T).name()).c_str(), ptr);
321 return GetVoidValue(name,
typeid(T), &value);
335 bool result = GetValue(name, value);
337 if (result) {
return value;}
345 {std::string result; GetValue(
"ValueNames", result);
return result;}
356 {
return GetValue(name, value);}
365 {
return GetValueWithDefault(name, defaultValue);}
376 CRYPTOPP_DLL
static void CRYPTOPP_API
ThrowIfTypeMismatch(
const char *name,
const std::type_info &stored,
const std::type_info &retrieving)
392 if (!GetValue(name, value))
393 throw InvalidArgument(std::string(className) +
": missing required parameter '" + name +
"'");
407 if (!GetIntValue(name, value))
408 throw InvalidArgument(std::string(className) +
": missing required parameter '" + name +
"'");
421 CRYPTOPP_DLL
virtual bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const =0;
424 #if CRYPTOPP_DOXYGEN_PROCESSING 433 DOCUMENTED_NAMESPACE_BEGIN(
Name)
435 DOCUMENTED_NAMESPACE_END
440 DOCUMENTED_NAMESPACE_BEGIN(
Weak)
442 DOCUMENTED_NAMESPACE_END
480 Algorithm(
bool checkSelfTestStatus =
true);
490 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 503 virtual size_t MinKeyLength()
const =0;
505 virtual size_t MaxKeyLength()
const =0;
507 virtual size_t DefaultKeyLength()
const =0;
511 virtual size_t GetValidKeyLength(
size_t n)
const =0;
516 {
return keylength == GetValidKeyLength(keylength);}
533 void SetKeyWithRounds(
const byte *key,
size_t length,
int rounds);
542 void SetKeyWithIV(
const byte *key,
size_t length,
const byte *iv,
size_t ivLength);
552 {SetKeyWithIV(key, length, iv, IVSize());}
584 {
throw NotImplemented(GetAlgorithm().AlgorithmName() +
": this object doesn't support resynchronization");}
593 CRYPTOPP_UNUSED(iv); CRYPTOPP_UNUSED(ivLength);
594 throw NotImplemented(GetAlgorithm().AlgorithmName() +
": this object doesn't support resynchronization");
610 virtual const Algorithm & GetAlgorithm()
const =0;
617 virtual void UncheckedSetKey(
const byte *key,
unsigned int length,
const NameValuePairs ¶ms) =0;
622 void ThrowIfInvalidKeyLength(
size_t length);
629 void ThrowIfResynchronizable();
638 void ThrowIfInvalidIV(
const byte *iv);
643 size_t ThrowIfInvalidIVLength(
int length);
650 const byte * GetIVAndThrowIfInvalid(
const NameValuePairs ¶ms,
size_t &size);
654 inline void AssertValidKeyLength(
size_t length)
const 655 {CRYPTOPP_UNUSED(length); assert(IsValidKeyLength(length));}
675 virtual void ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock, byte *outBlock)
const =0;
686 {ProcessAndXorBlock(inBlock, NULL, outBlock);}
695 {ProcessAndXorBlock(inoutBlock, NULL, inoutBlock);}
699 virtual unsigned int BlockSize()
const =0;
703 virtual unsigned int OptimalDataAlignment()
const;
711 virtual bool IsForwardTransformation()
const =0;
721 BT_InBlockIsCounter=1,
723 BT_DontIncrementInOutPointers=2,
727 BT_ReverseDirection=8,
729 BT_AllowParallel=16};
739 virtual size_t AdvancedProcessBlocks(
const byte *inBlocks,
const byte *xorBlocks, byte *outBlocks,
size_t length, word32 flags)
const;
744 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 777 virtual unsigned int OptimalDataAlignment()
const;
784 virtual void ProcessData(byte *outString,
const byte *inString,
size_t length) =0;
792 virtual void ProcessLastBlock(byte *outString,
const byte *inString,
size_t length);
802 {ProcessData(inoutString, inoutString, length);}
809 inline void ProcessString(byte *outString,
const byte *inString,
size_t length)
810 {ProcessData(outString, inString, length);}
816 {ProcessData(&input, &input, 1);
return input;}
820 virtual bool IsRandomAccess()
const =0;
829 CRYPTOPP_UNUSED(pos);
830 assert(!IsRandomAccess());
831 throw NotImplemented(
"StreamTransformation: this object doesn't support random access");
838 virtual bool IsSelfInverting()
const =0;
843 virtual bool IsForwardTransformation()
const =0;
845 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 869 virtual void Update(
const byte *input,
size_t length) =0;
891 {TruncatedFinal(NULL, 0);}
918 virtual unsigned int OptimalDataAlignment()
const;
928 {Update(input, length); Final(digest);}
939 {
return TruncatedVerify(digest,
DigestSize());}
952 virtual bool VerifyDigest(
const byte *digest,
const byte *input,
size_t length)
953 {Update(input, length);
return Verify(digest);}
960 virtual void TruncatedFinal(byte *digest,
size_t digestSize) =0;
971 {Update(input, length); TruncatedFinal(digest, digestSize);}
983 virtual bool TruncatedVerify(
const byte *digest,
size_t digestLength);
998 {Update(input, length);
return TruncatedVerify(digest, digestLength);}
1000 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 1006 void ThrowIfInvalidTruncatedSize(
size_t size)
const;
1016 const Algorithm & GetAlgorithm()
const {
return *
this;}
1023 const Algorithm & GetAlgorithm()
const {
return *
this;}
1030 const Algorithm & GetAlgorithm()
const {
return *
this;}
1043 explicit BadState(
const std::string &name,
const char *message) :
Exception(OTHER_ERROR, name +
": " + message) {}
1044 explicit BadState(
const std::string &name,
const char *
function,
const char *state) :
Exception(OTHER_ERROR, name +
": " +
function +
" was called before " + state) {}
1048 virtual lword MaxHeaderLength()
const =0;
1050 virtual lword MaxMessageLength()
const =0;
1057 void SpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength=0);
1059 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);
1061 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);
1064 virtual std::string AlgorithmName()
const =0;
1066 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 1073 virtual void UncheckedSpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength)
1074 {CRYPTOPP_UNUSED(headerLength); CRYPTOPP_UNUSED(messageLength); CRYPTOPP_UNUSED(footerLength);}
1077 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 1098 CRYPTOPP_UNUSED(input); CRYPTOPP_UNUSED(length);
1099 throw NotImplemented(
"RandomNumberGenerator: IncorporateEntropy not implemented");
1111 virtual byte GenerateByte();
1118 virtual unsigned int GenerateBit();
1128 virtual word32 GenerateWord32(word32 min=0, word32 max=0xffffffffUL);
1137 virtual void GenerateBlock(byte *output,
size_t size);
1149 virtual void GenerateIntoBufferedTransformation(
BufferedTransformation &target,
const std::string &channel, lword length);
1153 virtual void DiscardBytes(
size_t n);
1159 template <
class IT>
void Shuffle(IT begin, IT end)
1162 for (; begin != end; ++begin)
1163 std::iter_swap(begin, begin + GenerateWord32(0, end-begin-1));
1166 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 1170 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 1171 byte
GetByte() {
return GenerateByte();}
1172 unsigned int GetBit() {
return GenerateBit();}
1173 word32 GetLong(word32 a=0, word32 b=0xffffffffL) {
return GenerateWord32(a, b);}
1174 word16 GetShort(word16 a=0, word16 b=0xffff) {
return (word16)GenerateWord32(a, b);}
1175 void GetBlock(byte *output,
size_t size) {GenerateBlock(output, size);}
1199 virtual unsigned int GetMaxWaitObjectCount()
const =0;
1213 bool Wait(
unsigned long milliseconds,
CallStack const& callStack);
1222 extern CRYPTOPP_DLL
const std::string
AAD_CHANNEL;
1251 static const std::string &NULL_CHANNEL;
1268 size_t Put(byte inByte,
bool blocking=
true)
1269 {
return Put(&inByte, 1, blocking);}
1277 size_t Put(
const byte *inString,
size_t length,
bool blocking=
true)
1278 {
return Put2(inString, length, 0, blocking);}
1285 size_t PutWord16(word16 value,
ByteOrder order=BIG_ENDIAN_ORDER,
bool blocking=
true);
1292 size_t PutWord32(word32 value,
ByteOrder order=BIG_ENDIAN_ORDER,
bool blocking=
true);
1304 {size=0;
return NULL;}
1319 {
return PutModifiable2(inString, length, 0, blocking);}
1327 {
return !!Put2(NULL, 0, propagation < 0 ? -1 : propagation+1, blocking);}
1338 size_t PutMessageEnd(
const byte *inString,
size_t length,
int propagation=-1,
bool blocking=
true)
1339 {
return Put2(inString, length, propagation < 0 ? -1 : propagation+1, blocking);}
1347 virtual size_t Put2(
const byte *inString,
size_t length,
int messageEnd,
bool blocking) =0;
1355 virtual size_t PutModifiable2(byte *inString,
size_t length,
int messageEnd,
bool blocking)
1356 {
return Put2(inString, length, messageEnd, blocking);}
1366 unsigned int GetMaxWaitObjectCount()
const;
1394 CRYPTOPP_UNUSED(parameters);
1395 throw NotImplemented(
"BufferedTransformation: this object can't be reinitialized");
1402 virtual bool IsolatedFlush(
bool hardFlush,
bool blocking) =0;
1408 {CRYPTOPP_UNUSED(blocking);
return false;}
1435 virtual bool Flush(
bool hardFlush,
int propagation=-1,
bool blocking=
true);
1445 virtual bool MessageSeriesEnd(
int propagation=-1,
bool blocking=
true);
1452 {CRYPTOPP_UNUSED(propagation);}
1458 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 1459 void Close() {MessageEnd();}
1470 virtual lword MaxRetrievable()
const;
1474 virtual bool AnyRetrievable()
const;
1480 virtual size_t Get(byte &outByte);
1487 virtual size_t Get(byte *outString,
size_t getMax);
1494 virtual size_t Peek(byte &outByte)
const;
1502 virtual size_t Peek(byte *outString,
size_t peekMax)
const;
1509 size_t GetWord16(word16 &value,
ByteOrder order=BIG_ENDIAN_ORDER);
1516 size_t GetWord32(word32 &value,
ByteOrder order=BIG_ENDIAN_ORDER);
1524 size_t PeekWord16(word16 &value,
ByteOrder order=BIG_ENDIAN_ORDER)
const;
1532 size_t PeekWord32(word32 &value,
ByteOrder order=BIG_ENDIAN_ORDER)
const;
1544 {TransferTo2(target, transferMax, channel);
return transferMax;}
1549 virtual lword Skip(lword skipMax=LWORD_MAX);
1561 {
return CopyRangeTo(target, 0, copyMax, channel);}
1574 {lword i = position; CopyRangeTo2(target, i, i+copyMax, channel);
return i-position;}
1576 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 1577 unsigned long MaxRetrieveable()
const {
return MaxRetrievable();}
1586 virtual lword TotalBytesRetrievable()
const;
1592 virtual unsigned int NumberOfMessages()
const;
1597 virtual bool AnyMessages()
const;
1603 virtual bool GetNextMessage();
1610 virtual unsigned int SkipMessages(
unsigned int count=UINT_MAX);
1622 {TransferMessagesTo2(target, count, channel);
return count;}
1636 virtual void SkipAll();
1639 {TransferAllTo2(target, channel);}
1643 virtual bool GetNextMessageSeries() {
return false;}
1644 virtual unsigned int NumberOfMessagesInThisSeries()
const {
return NumberOfMessages();}
1645 virtual unsigned int NumberOfMessageSeries()
const {
return 0;}
1725 size_t ChannelPut(
const std::string &channel, byte inByte,
bool blocking=
true)
1726 {
return ChannelPut(channel, &inByte, 1, blocking);}
1735 size_t ChannelPut(
const std::string &channel,
const byte *inString,
size_t length,
bool blocking=
true)
1736 {
return ChannelPut2(channel, inString, length, 0, blocking);}
1746 {
return ChannelPutModifiable2(channel, inString, length, 0, blocking);}
1755 size_t ChannelPutWord16(
const std::string &channel, word16 value,
ByteOrder order=BIG_ENDIAN_ORDER,
bool blocking=
true);
1764 size_t ChannelPutWord32(
const std::string &channel, word32 value,
ByteOrder order=BIG_ENDIAN_ORDER,
bool blocking=
true);
1775 {
return !!ChannelPut2(channel, NULL, 0, propagation < 0 ? -1 : propagation+1, blocking);}
1787 size_t ChannelPutMessageEnd(
const std::string &channel,
const byte *inString,
size_t length,
int propagation=-1,
bool blocking=
true)
1788 {
return ChannelPut2(channel, inString, length, propagation < 0 ? -1 : propagation+1, blocking);}
1800 virtual byte * ChannelCreatePutSpace(
const std::string &channel,
size_t &size);
1808 virtual size_t ChannelPut2(
const std::string &channel,
const byte *inString,
size_t length,
int messageEnd,
bool blocking);
1816 virtual size_t ChannelPutModifiable2(
const std::string &channel, byte *inString,
size_t length,
int messageEnd,
bool blocking);
1825 virtual bool ChannelFlush(
const std::string &channel,
bool hardFlush,
int propagation=-1,
bool blocking=
true);
1836 virtual bool ChannelMessageSeriesEnd(
const std::string &channel,
int propagation=-1,
bool blocking=
true);
1841 virtual void SetRetrievalChannel(
const std::string &channel);
1873 CRYPTOPP_UNUSED(newAttachment); assert(!Attachable());
1874 throw NotImplemented(
"BufferedTransformation: this object is not attachable");
1883 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 1890 static int DecrementPropagation(
int propagation)
1891 {
return propagation != 0 ? propagation - 1 : 0;}
1939 {
if (!Validate(rng, level))
throw InvalidMaterial(
"CryptoMaterial: this object contains invalid values");}
1951 {CRYPTOPP_UNUSED(bt);
throw NotImplemented(
"CryptoMaterial: this object does not support saving");}
1968 {CRYPTOPP_UNUSED(bt);
throw NotImplemented(
"CryptoMaterial: this object does not support loading");}
1982 CRYPTOPP_UNUSED(precomputationStorage); assert(!SupportsPrecomputation());
1983 throw NotImplemented(
"CryptoMaterial: this object does not support precomputation");
1988 {CRYPTOPP_UNUSED(storedPrecomputation); assert(!SupportsPrecomputation());
throw NotImplemented(
"CryptoMaterial: this object does not support precomputation");}
1991 {CRYPTOPP_UNUSED(storedPrecomputation); assert(!SupportsPrecomputation());
throw NotImplemented(
"CryptoMaterial: this object does not support precomputation");}
1994 void DoQuickSanityCheck()
const {ThrowIfInvalid(
NullRNG(), 0);}
1996 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2000 #if (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590) 2002 char m_sunCCworkaround;
2019 CRYPTOPP_UNUSED(rng); CRYPTOPP_UNUSED(params);
2020 throw NotImplemented(
"GeneratableCryptoMaterial: this object does not support key/parameter generation");
2031 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2066 {AccessMaterial().Load(bt);}
2069 {GetMaterial().Save(bt);}
2071 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2085 virtual PublicKey & AccessPublicKey() =0;
2086 virtual const PublicKey & GetPublicKey()
const {
return const_cast<PublicKeyAlgorithm *
>(
this)->AccessPublicKey();}
2088 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2101 virtual PrivateKey & AccessPrivateKey() =0;
2102 virtual const PrivateKey & GetPrivateKey()
const {
return const_cast<PrivateKeyAlgorithm *
>(
this)->AccessPrivateKey();}
2104 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2117 virtual CryptoParameters & AccessCryptoParameters() =0;
2118 virtual const CryptoParameters & GetCryptoParameters()
const {
return const_cast<KeyAgreementAlgorithm *
>(
this)->AccessCryptoParameters();}
2120 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2137 virtual size_t MaxPlaintextLength(
size_t ciphertextLength)
const =0;
2141 virtual size_t CiphertextLength(
size_t plaintextLength)
const =0;
2145 virtual bool ParameterSupported(
const char *name)
const =0;
2155 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 2156 size_t MaxPlainTextLength(
size_t cipherTextLength)
const {
return MaxPlaintextLength(cipherTextLength);}
2157 size_t CipherTextLength(
size_t plainTextLength)
const {
return CiphertextLength(plainTextLength);}
2184 const byte *plaintext,
size_t plaintextLength,
2214 const byte *ciphertext,
size_t ciphertextLength,
2225 {
return Decrypt(rng, ciphertext, FixedCiphertextLength(), plaintext, parameters);}
2227 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2232 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 2263 virtual size_t SignatureLength()
const =0;
2267 {CRYPTOPP_UNUSED(recoverablePartLength);
return SignatureLength();}
2270 virtual size_t MaxRecoverableLength()
const =0;
2273 virtual size_t MaxRecoverableLengthFromSignatureLength(
size_t signatureLength)
const =0;
2277 virtual bool IsProbabilistic()
const =0;
2280 virtual bool AllowNonrecoverablePart()
const =0;
2286 virtual bool RecoverablePartFirst()
const =0;
2298 {
throw NotImplemented(
"PK_MessageAccumulator: DigestSize() should not be called");}
2303 CRYPTOPP_UNUSED(digest); CRYPTOPP_UNUSED(digestSize);
2304 throw NotImplemented(
"PK_MessageAccumulator: TruncatedFinal() should not be called");
2316 virtual void InputRecoverableMessage(
PK_MessageAccumulator &messageAccumulator,
const byte *recoverableMessage,
size_t recoverableMessageLength)
const =0;
2334 virtual size_t SignMessage(
RandomNumberGenerator &rng,
const byte *message,
size_t messageLen, byte *signature)
const;
2340 virtual size_t SignMessageWithRecovery(
RandomNumberGenerator &rng,
const byte *recoverableMessage,
size_t recoverableMessageLength,
2341 const byte *nonrecoverableMessage,
size_t nonrecoverableMessageLength, byte *signature)
const;
2343 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2362 virtual void InputSignature(
PK_MessageAccumulator &messageAccumulator,
const byte *signature,
size_t signatureLength)
const =0;
2371 virtual bool VerifyMessage(
const byte *message,
size_t messageLen,
2372 const byte *signature,
size_t signatureLength)
const;
2388 const byte *nonrecoverableMessage,
size_t nonrecoverableMessageLength,
2389 const byte *signature,
size_t signatureLength)
const;
2391 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2406 virtual unsigned int AgreedValueLength()
const =0;
2408 virtual unsigned int PrivateKeyLength()
const =0;
2410 virtual unsigned int PublicKeyLength()
const =0;
2416 virtual void GeneratePublicKey(
RandomNumberGenerator &rng,
const byte *privateKey, byte *publicKey)
const =0;
2426 virtual bool Agree(byte *agreedValue,
const byte *privateKey,
const byte *otherPublicKey,
bool validateOtherPublicKey=
true)
const =0;
2428 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2432 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 2434 {
return GetCryptoParameters().Validate(rng, 2);}
2448 virtual unsigned int AgreedValueLength()
const =0;
2451 virtual unsigned int StaticPrivateKeyLength()
const =0;
2453 virtual unsigned int StaticPublicKeyLength()
const =0;
2459 virtual void GenerateStaticPublicKey(
RandomNumberGenerator &rng,
const byte *privateKey, byte *publicKey)
const =0;
2462 virtual void GenerateStaticKeyPair(
RandomNumberGenerator &rng, byte *privateKey, byte *publicKey)
const;
2465 virtual unsigned int EphemeralPrivateKeyLength()
const =0;
2467 virtual unsigned int EphemeralPublicKeyLength()
const =0;
2473 virtual void GenerateEphemeralPublicKey(
RandomNumberGenerator &rng,
const byte *privateKey, byte *publicKey)
const =0;
2476 virtual void GenerateEphemeralKeyPair(
RandomNumberGenerator &rng, byte *privateKey, byte *publicKey)
const;
2487 virtual bool Agree(byte *agreedValue,
2488 const byte *staticPrivateKey,
const byte *ephemeralPrivateKey,
2489 const byte *staticOtherPublicKey,
const byte *ephemeralOtherPublicKey,
2490 bool validateStaticOtherPublicKey=
true)
const =0;
2492 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2496 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 2498 {
return GetCryptoParameters().Validate(rng, 2);}
2525 class ProtocolSession
2532 ProtocolError(ErrorType errorType,
const std::string &s) :
Exception(errorType, s) {}
2537 class UnexpectedMethodCall :
public Exception 2540 UnexpectedMethodCall(
const std::string &s) :
Exception(OTHER_ERROR, s) {}
2543 ProtocolSession() : m_rng(NULL), m_throwOnProtocolError(
true), m_validState(
false) {}
2544 virtual ~ProtocolSession() {}
2548 bool GetThrowOnProtocolError()
const {
return m_throwOnProtocolError;}
2549 void SetThrowOnProtocolError(
bool throwOnProtocolError) {m_throwOnProtocolError = throwOnProtocolError;}
2551 bool HasValidState()
const {
return m_validState;}
2553 virtual bool OutgoingMessageAvailable()
const =0;
2554 virtual unsigned int GetOutgoingMessageLength()
const =0;
2555 virtual void GetOutgoingMessage(byte *message) =0;
2557 virtual bool LastMessageProcessed()
const =0;
2558 virtual void ProcessIncomingMessage(
const byte *message,
unsigned int messageLength) =0;
2562 void CheckAndHandleInvalidState()
const;
2563 void SetValidState(
bool valid) {m_validState = valid;}
2568 bool m_throwOnProtocolError, m_validState;
2571 class KeyAgreementSession :
public ProtocolSession
2574 virtual unsigned int GetAgreedValueLength()
const =0;
2575 virtual void GetAgreedValue(byte *agreedValue)
const =0;
2577 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2578 virtual ~KeyAgreementSession() {}
2582 class PasswordAuthenticatedKeyAgreementSession :
public KeyAgreementSession
2586 const byte *myId,
unsigned int myIdLength,
2587 const byte *counterPartyId,
unsigned int counterPartyIdLength,
2588 const byte *passwordOrVerifier,
unsigned int passwordOrVerifierLength);
2590 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2591 virtual ~PasswordAuthenticatedKeyAgreementSession() {}
2600 {
return GetCryptoParameters().Validate(rng, 2);}
2602 virtual unsigned int GetPasswordVerifierLength(
const byte *password,
unsigned int passwordLength)
const =0;
2603 virtual void GeneratePasswordVerifier(
RandomNumberGenerator &rng,
const byte *userId,
unsigned int userIdLength,
const byte *password,
unsigned int passwordLength, byte *verifier)
const =0;
2605 enum RoleFlags {CLIENT=1, SERVER=2, INITIATOR=4, RESPONDER=8};
2607 virtual bool IsValidRole(
unsigned int role) =0;
2608 virtual PasswordAuthenticatedKeyAgreementSession * CreateProtocolSession(
unsigned int role)
const =0;
2610 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562 2611 virtual ~PasswordAuthenticatedKeyAgreementDomain() {}
2650 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY 2658 #if CRYPTOPP_MSC_VERSION 2659 # pragma warning(pop) Base class for all exceptions thrown by Crypto++.
exception thrown when invalid crypto material is detected
virtual void Precompute(unsigned int precomputationStorage)
Perform precomputation.
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.
bool GetThisObject(T &object) const
Get a copy of this object or subobject.
bool CanUseRandomIVs() const
returns whether the object can use random IVs (in addition to ones returned by GetNextIV) ...
const char * what() const
Retrieves a C-string describing the exception.
Interface for message authentication codes.
container of wait objects
virtual void SavePrecomputation(BufferedTransformation &storedPrecomputation) const
save precomputation for later use
Interface for asymmetric algorithms.
void GetRequiredParameter(const char *className, const char *name, T &value) const
Retrieves a required name/value pair.
Interface for public-key encryptors and decryptors.
ByteOrder
Provides the byte ordering.
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.
virtual void Load(BufferedTransformation &bt)
Loads a key from a BufferedTransformation.
Exception(ErrorType errorType, const std::string &s)
Construct a new Exception.
ErrorType GetErrorType() const
Retrieves the error type for the exception.
virtual bool NeedsPrespecifiedDataLengths() const
if this function returns true, SpecifyDataLengths() must be called before attempting to input data ...
bool operator!=(const DecodingResult &rhs) const
Compare two DecodingResult.
this indicates that a member function was called in the wrong state, for example trying to encrypt a ...
Interface for public-key signers.
virtual void ThrowIfInvalid(RandomNumberGenerator &rng, unsigned int level) const
Check this object for errors.
Interface for public-key encryptors.
Converts a typename to an enumerated value.
CipherDir
Specifies a direction for a cipher to operate.
void BERDecode(BufferedTransformation &bt)
for backwards compatibility, calls AccessMaterial().Load(bt)
Flush(true) was called but it can't completely flush its buffers.
virtual void Save(BufferedTransformation &bt) const
Saves a key to a BufferedTransformation.
Thrown when an unexpected type is encountered.
CryptoMaterial & AccessMaterial()
returns a reference to the crypto material used by this object
Interface for asymmetric algorithms using private keys.
BufferedTransformation & TheBitBucket()
An input discarding BufferedTransformation.
bool operator==(const DecodingResult &rhs) const
Compare two DecodingResult.
virtual bool SupportsPrecomputation() const
Determines whether the object supports precomputation.
const std::string & GetWhat() const
Retrieves a string describing the exception.
ValueTypeMismatch(const std::string &name, const std::type_info &stored, const std::type_info &retrieving)
Construct a ValueTypeMismatch.
Library configuration file.
virtual bool CanIncorporateEntropy() const
Determines if a generator can accept additional entropy.
std::string GetValueNames() const
Get a list of value names that can be retrieved.
Interface for random number generators.
size_t messageLength
Recovered message length if isValidCoding is true, undefined otherwise.
virtual lword MaxFooterLength() const
the maximum length of AAD that can be input after the encrypted data
Interface for private keys.
Interface for cloning objects.
virtual unsigned int MinIVLength() const
returns minimal length of IVs accepted by this object
const CryptoMaterial & GetMaterial() const
returns a const reference to the crypto material used by this object
const std::type_info & GetRetrievingTypeInfo() const
Provides the retrieveing type.
bool GetIntValue(const char *name, int &value) const
Get a named value with type int.
Data integerity check, such as CRC or MAC, failed.
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.
const std::string & GetOperation() const
Retrieve the operating system API that reported the error.
Interface for domains of simple key agreement protocols.
Returns a decoding results.
virtual void LoadPrecomputation(BufferedTransformation &storedPrecomputation)
retrieve previously saved precomputation
Exception thrown when trying to encrypt plaintext of invalid length.
bool CanUsePredictableIVs() const
returns whether the object can use random but possibly predictable IVs (in addition to ones returned ...
DecodingResult FixedLengthDecrypt(RandomNumberGenerator &rng, const byte *ciphertext, byte *plaintext, const NameValuePairs ¶meters=g_nullNameValuePairs) const
decrypt a fixed size ciphertext
Input data was received that did not conform to expected format.
bool GetValue(const char *name, T &value) const
Get a named value.
Interface for public-key decryptors.
bool GetThisPointer(T *&ptr) const
Get a pointer to this object.
int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
A method was called which was not implemented.
key too short exception, may be thrown by any function in this class if the private or public key is ...
virtual size_t FixedCiphertextLength() const
return fixed ciphertext length, if one exists, otherwise return 0
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
bool IsResynchronizable() const
returns whether the object can be resynchronized (i.e. supports initialization vectors) ...
const CryptoMaterial & GetMaterial() const
returns a const reference to the crypto material used by this object
const std::type_info & GetStoredTypeInfo() const
Provides the stored type.
Interface for encoding and decoding ASN1 objects.
virtual void Resynchronize(const byte *iv, int ivLength=-1)
resynchronize with an IV. ivLength=-1 means use IVSize()
virtual size_t MaxSignatureLength(size_t recoverablePartLength=0) const
maximum signature length produced for a given length of recoverable message part
DecodingResult()
Constructs a DecodingResult.
bool CanUseStructuredIVs() const
returns whether the object can use structured IVs, for example a counter (in addition to ones returne...
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.
invalid key exception, may be thrown by any function in this class if the private or public key has a...
Interface for algorithms that take byte strings as keys.
virtual std::string AlgorithmName() const
Provides the name of this algorithm.
Interface for asymmetric algorithms using public keys.
virtual size_t FixedMaxPlaintextLength() const
return maximum plaintext length given the fixed ciphertext length, if one exists, otherwise return 0 ...
const CryptoMaterial & GetMaterial() const
returns a const reference to the crypto material used by this object
const NameValuePairs & g_nullNameValuePairs
An empty set of name-value pairs.
unsigned int DigestSize() const
should not be called on PK_MessageAccumulator
void GetRequiredIntParameter(const char *className, const char *name, int &value) const
Retrieves a required name/value pair.
Interface for public-key signers and verifiers.
int GetErrorCode() const
Retrieve the error code returned by the operating system.
RandomNumberGenerator & NullRNG()
Random Number Generator that does not produce random numbers.
const char * BlockSize()
int, in bytes
const unsigned long INFINITE_TIME
Represents infinite time.
virtual unsigned int MaxIVLength() const
returns maximal length of IVs accepted by this object
Interface for all crypto algorithms.
unsigned int DefaultIVLength() const
returns default length of IVs accepted by this object
virtual bool IsValidKeyLength(size_t keylength) const
Returns whether keylength is a valid key length.
virtual void BEREncode(BufferedTransformation &bt) const
Encode this object into a BufferedTransformation.
Interface for accumulating messages to be signed or verified.
virtual Clonable * Clone() const
Copies this object.
A decryption filter encountered invalid ciphertext.
Interface for key agreement algorithms.
static void ThrowIfTypeMismatch(const char *name, const std::type_info &stored, const std::type_info &retrieving)
Ensures an expected name and type is present.
IV_Requirement
Provides IV requirements as an enumerated value.
CryptoMaterial & AccessMaterial()
returns a reference to the crypto material used by this object
Interface for public-key signature verifiers.
void Shuffle(IT begin, IT end)
Randomly shuffle the specified array.
virtual bool SignatureUpfront() const
if this function returns true, during verification you must input the signature before the message...
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.
void DEREncode(BufferedTransformation &bt) const
for backwards compatibility, calls GetMaterial().Save(bt)
CryptoMaterial & AccessMaterial()
returns a reference to the crypto material used by this object
An invalid argument was detected.
Interface for generatable crypto material, such as private keys and crypto parameters.
Interface for crypto prameters.
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.
The IV must be unpredictable.
Interface for domains of authenticated key agreement protocols.
void TruncatedFinal(byte *digest, size_t digestSize)
should not be called on PK_MessageAccumulator
A method was called which was not implemented.
const std::string AAD_CHANNEL
Channel for additional authenticated data.
Error reading from input device or writing to output device.
unsigned int GetByte(ByteOrder order, T value, unsigned int index)
Gets a byte from a value.
virtual unsigned int IVSize() const
Returns length of the IV accepted by this object.
Namespace containing weak and wounded algorithms.
virtual void IncorporateEntropy(const byte *input, size_t length)
Update RNG state with additional unpredictable values.
Interface for retrieving values given their names.
Exception thrown when an ASN1 BER decoing error is encountered.