Crypto++
8.2
Free C++ class library of cryptographic schemes
|
Go to the documentation of this file.
102 #ifndef CRYPTOPP_CRYPTLIB_H
103 #define CRYPTOPP_CRYPTLIB_H
109 #if CRYPTOPP_MSC_VERSION
110 # pragma warning(push)
111 # pragma warning(disable: 4127 4189 4505 4702)
134 template <
typename ENUM_TYPE,
int VALUE>
137 static ENUM_TYPE ToEnum() {
return static_cast<ENUM_TYPE
>(VALUE);}
186 const char *
what()
const throw() {
return (m_what.c_str());}
188 const std::string &
GetWhat()
const {
return m_what;}
190 void SetWhat(
const std::string &s) {m_what = s;}
197 ErrorType m_errorType;
241 OS_Error(
ErrorType errorType,
const std::string &s,
const std::string& operation,
int errorCode)
242 :
Exception(errorType, s), m_operation(operation), m_errorCode(errorCode) {}
250 std::string m_operation;
307 ValueTypeMismatch(
const std::string &name,
const std::type_info &stored,
const std::type_info &retrieving)
308 :
InvalidArgument(
"NameValuePairs: type mismatch for '" + name +
"', stored '" + stored.name() +
"', trying to retrieve '" + retrieving.name() +
"'")
309 , m_stored(stored), m_retrieving(retrieving) {}
320 const std::type_info &m_stored;
321 const std::type_info &m_retrieving;
330 return GetValue((std::string(
"ThisObject:")+
typeid(T).name()).c_str(),
object);
339 return GetValue((std::string(
"ThisPointer:")+
typeid(T).name()).c_str(), ptr);
366 bool result =
GetValue(name, value);
368 if (result) {
return value;}
376 {std::string result;
GetValue(
"ValueNames", result);
return result;}
425 CRYPTOPP_DLL
static void CRYPTOPP_API
ThrowIfTypeMismatch(
const char *name,
const std::type_info &stored,
const std::type_info &retrieving)
442 throw InvalidArgument(std::string(className) +
": missing required parameter '" + name +
"'");
457 throw InvalidArgument(std::string(className) +
": missing required parameter '" + name +
"'");
470 CRYPTOPP_DLL
virtual bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const =0;
474 #if CRYPTOPP_DOXYGEN_PROCESSING
509 #if CRYPTOPP_DOXYGEN_PROCESSING
517 DOCUMENTED_NAMESPACE_BEGIN(
Name)
519 DOCUMENTED_NAMESPACE_END
533 DOCUMENTED_NAMESPACE_BEGIN(
Weak)
535 DOCUMENTED_NAMESPACE_END
540 DOCUMENTED_NAMESPACE_BEGIN(
NaCl)
542 DOCUMENTED_NAMESPACE_END
547 DOCUMENTED_NAMESPACE_BEGIN(
Test)
549 DOCUMENTED_NAMESPACE_END
583 Algorithm(
bool checkSelfTestStatus =
true);
620 virtual size_t MinKeyLength()
const =0;
624 virtual size_t MaxKeyLength()
const =0;
628 virtual size_t DefaultKeyLength()
const =0;
638 virtual size_t GetValidKeyLength(
size_t keylength)
const =0;
645 {
return keylength == GetValidKeyLength(keylength);}
661 void SetKeyWithRounds(
const byte *key,
size_t length,
int rounds);
671 void SetKeyWithIV(
const byte *key,
size_t length,
const byte *iv,
size_t ivLength);
681 {SetKeyWithIV(key, length, iv, IVSize());}
706 virtual IV_Requirement IVRequirement()
const =0;
734 {
throw NotImplemented(GetAlgorithm().AlgorithmName() +
": this object doesn't support resynchronization");}
756 CRYPTOPP_UNUSED(iv); CRYPTOPP_UNUSED(ivLength);
757 throw NotImplemented(GetAlgorithm().AlgorithmName() +
": this object doesn't support resynchronization");
774 virtual const Algorithm & GetAlgorithm()
const =0;
781 virtual void UncheckedSetKey(
const byte *key,
unsigned int length,
const NameValuePairs ¶ms) =0;
786 void ThrowIfInvalidKeyLength(
size_t length);
793 void ThrowIfResynchronizable();
802 void ThrowIfInvalidIV(
const byte *iv);
807 size_t ThrowIfInvalidIVLength(
int length);
814 const byte * GetIVAndThrowIfInvalid(
const NameValuePairs ¶ms,
size_t &size);
818 inline void AssertValidKeyLength(
size_t length)
const
841 virtual void ProcessAndXorBlock(
const byte *inBlock,
const byte *xorBlock,
byte *outBlock)
const =0;
852 {ProcessAndXorBlock(inBlock, NULLPTR, outBlock);}
861 {ProcessAndXorBlock(inoutBlock, NULLPTR, inoutBlock);}
865 virtual unsigned int BlockSize()
const =0;
870 virtual unsigned int OptimalDataAlignment()
const;
879 virtual bool IsForwardTransformation()
const =0;
889 BT_InBlockIsCounter=1,
891 BT_DontIncrementInOutPointers=2,
895 BT_ReverseDirection=8,
897 BT_AllowParallel=16};
907 virtual size_t AdvancedProcessBlocks(
const byte *inBlocks,
const byte *xorBlocks,
byte *outBlocks,
size_t length, word32 flags)
const;
953 virtual unsigned int OptimalDataAlignment()
const;
962 virtual void ProcessData(
byte *outString,
const byte *inString,
size_t length) =0;
976 virtual size_t ProcessLastBlock(
byte *outString,
size_t outLength,
const byte *inString,
size_t inLength);
1033 {ProcessData(inoutString, inoutString, length);}
1041 {ProcessData(outString, inString, length);}
1047 {ProcessData(&input, &input, 1);
return input;}
1051 virtual bool IsRandomAccess()
const =0;
1060 CRYPTOPP_UNUSED(pos);
1062 throw NotImplemented(
"StreamTransformation: this object doesn't support random access");
1069 virtual bool IsSelfInverting()
const =0;
1074 virtual bool IsForwardTransformation()
const =0;
1097 virtual void Update(
const byte *input,
size_t length) =0;
1115 {TruncatedFinal(digest, DigestSize());}
1120 {TruncatedFinal(NULLPTR, 0);}
1124 virtual unsigned int DigestSize()
const =0;
1129 unsigned int TagSize()
const {
return DigestSize();}
1149 virtual unsigned int OptimalDataAlignment()
const;
1161 {Update(input, length); Final(digest);}
1173 {
return TruncatedVerify(digest, DigestSize());}
1188 virtual bool VerifyDigest(
const byte *digest,
const byte *input,
size_t length)
1189 {Update(input, length);
return Verify(digest);}
1196 virtual void TruncatedFinal(
byte *digest,
size_t digestSize) =0;
1209 {Update(input, length); TruncatedFinal(digest, digestSize);}
1221 virtual bool TruncatedVerify(
const byte *digest,
size_t digestLength);
1238 {Update(input, length);
return TruncatedVerify(digest, digestLength);}
1245 void ThrowIfInvalidTruncatedSize(
size_t size)
const;
1253 const Algorithm & GetAlgorithm()
const {
return *
this;}
1261 const Algorithm & GetAlgorithm()
const {
return *
this;}
1269 const Algorithm & GetAlgorithm()
const {
return *
this;}
1299 explicit BadState(
const std::string &name,
const char *message) :
Exception(OTHER_ERROR, name +
": " + message) {}
1300 explicit BadState(
const std::string &name,
const char *
function,
const char *state) :
Exception(OTHER_ERROR, name +
": " +
function +
" was called before " + state) {}
1305 virtual lword MaxHeaderLength()
const =0;
1309 virtual lword MaxMessageLength()
const =0;
1331 void SpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength=0);
1345 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);
1362 virtual bool DecryptAndVerify(
byte *message,
const byte *mac,
size_t macSize,
const byte *iv,
int ivLength,
const byte *header,
size_t headerLength,
const byte *ciphertext,
size_t ciphertextLength);
1374 virtual void UncheckedSpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength)
1375 {CRYPTOPP_UNUSED(headerLength); CRYPTOPP_UNUSED(messageLength); CRYPTOPP_UNUSED(footerLength);}
1398 CRYPTOPP_UNUSED(input); CRYPTOPP_UNUSED(length);
1399 throw NotImplemented(
"RandomNumberGenerator: IncorporateEntropy not implemented");
1411 virtual byte GenerateByte();
1418 virtual unsigned int GenerateBit();
1428 virtual word32 GenerateWord32(word32 min=0, word32 max=0xffffffffUL);
1437 virtual void GenerateBlock(
byte *output,
size_t size);
1449 virtual void GenerateIntoBufferedTransformation(
BufferedTransformation &target,
const std::string &channel, lword length);
1453 virtual void DiscardBytes(
size_t n);
1459 template <
class IT>
void Shuffle(IT begin, IT end)
1462 for (; begin != end; ++begin)
1463 std::iter_swap(begin, begin + GenerateWord32(0,
static_cast<word32
>(end-begin-1)));
1480 virtual size_t MinDerivedLength()
const;
1484 virtual size_t MaxDerivedLength()
const;
1489 virtual size_t GetValidDerivedLength(
size_t keylength)
const =0;
1496 return keylength == GetValidDerivedLength(keylength);
1523 virtual const Algorithm & GetAlgorithm()
const =0;
1528 void ThrowIfInvalidDerivedLength(
size_t length)
const;
1545 class WaitObjectContainer;
1556 virtual unsigned int GetMaxWaitObjectCount()
const =0;
1566 virtual void GetWaitObjects(WaitObjectContainer &container, CallStack
const& callStack) =0;
1572 bool Wait(
unsigned long milliseconds, CallStack
const& callStack);
1620 size_t Put(
byte inByte,
bool blocking=
true)
1621 {
return Put(&inByte, 1, blocking);}
1630 size_t Put(
const byte *inString,
size_t length,
bool blocking=
true)
1631 {
return Put2(inString, length, 0, blocking);}
1660 {size=0;
return NULLPTR;}
1675 {
return PutModifiable2(inString, length, 0, blocking);}
1683 {
return !!Put2(NULLPTR, 0, propagation < 0 ? -1 : propagation+1, blocking);}
1696 size_t PutMessageEnd(
const byte *inString,
size_t length,
int propagation=-1,
bool blocking=
true)
1697 {
return Put2(inString, length, propagation < 0 ? -1 : propagation+1, blocking);}
1707 virtual size_t Put2(
const byte *inString,
size_t length,
int messageEnd,
bool blocking) =0;
1717 virtual size_t PutModifiable2(
byte *inString,
size_t length,
int messageEnd,
bool blocking)
1718 {
return Put2(inString, length, messageEnd, blocking);}
1739 void GetWaitObjects(WaitObjectContainer &container, CallStack
const& callStack);
1756 CRYPTOPP_UNUSED(parameters);
1757 throw NotImplemented(
"BufferedTransformation: this object can't be reinitialized");
1764 virtual bool IsolatedFlush(
bool hardFlush,
bool blocking) =0;
1770 {CRYPTOPP_UNUSED(blocking);
return false;}
1796 virtual bool Flush(
bool hardFlush,
int propagation=-1,
bool blocking=
true);
1806 virtual bool MessageSeriesEnd(
int propagation=-1,
bool blocking=
true);
1813 {CRYPTOPP_UNUSED(propagation);}
1828 virtual lword MaxRetrievable()
const;
1832 virtual bool AnyRetrievable()
const;
1838 virtual size_t Get(
byte &outByte);
1845 virtual size_t Get(
byte *outString,
size_t getMax);
1852 virtual size_t Peek(
byte &outByte)
const;
1860 virtual size_t Peek(
byte *outString,
size_t peekMax)
const;
1902 {TransferTo2(target, transferMax, channel);
return transferMax;}
1915 virtual lword Skip(lword skipMax=LWORD_MAX);
1927 {
return CopyRangeTo(target, 0, copyMax, channel);}
1940 {lword i = position; CopyRangeTo2(target, i, i+copyMax, channel);
return i-position;}
1948 virtual lword TotalBytesRetrievable()
const;
1954 virtual unsigned int NumberOfMessages()
const;
1959 virtual bool AnyMessages()
const;
1965 virtual bool GetNextMessage();
1972 virtual unsigned int SkipMessages(
unsigned int count=UINT_MAX);
1984 {TransferMessagesTo2(target, count, channel);
return count;}
1998 virtual void SkipAll();
2006 {TransferAllTo2(target, channel);}
2106 size_t ChannelPut(
const std::string &channel,
byte inByte,
bool blocking=
true)
2107 {
return ChannelPut(channel, &inByte, 1, blocking);}
2116 size_t ChannelPut(
const std::string &channel,
const byte *inString,
size_t length,
bool blocking=
true)
2117 {
return ChannelPut2(channel, inString, length, 0, blocking);}
2127 {
return ChannelPutModifiable2(channel, inString, length, 0, blocking);}
2136 size_t ChannelPutWord16(
const std::string &channel, word16 value,
ByteOrder order=
BIG_ENDIAN_ORDER,
bool blocking=
true);
2145 size_t ChannelPutWord32(
const std::string &channel, word32 value,
ByteOrder order=
BIG_ENDIAN_ORDER,
bool blocking=
true);
2156 {
return !!ChannelPut2(channel, NULLPTR, 0, propagation < 0 ? -1 : propagation+1, blocking);}
2167 size_t ChannelPutMessageEnd(
const std::string &channel,
const byte *inString,
size_t length,
int propagation=-1,
bool blocking=
true)
2168 {
return ChannelPut2(channel, inString, length, propagation < 0 ? -1 : propagation+1, blocking);}
2181 virtual byte * ChannelCreatePutSpace(
const std::string &channel,
size_t &size);
2190 virtual size_t ChannelPut2(
const std::string &channel,
const byte *inString,
size_t length,
int messageEnd,
bool blocking);
2199 virtual size_t ChannelPutModifiable2(
const std::string &channel,
byte *inString,
size_t length,
int messageEnd,
bool blocking);
2209 virtual bool ChannelFlush(
const std::string &channel,
bool hardFlush,
int propagation=-1,
bool blocking=
true);
2220 virtual bool ChannelMessageSeriesEnd(
const std::string &channel,
int propagation=-1,
bool blocking=
true);
2225 virtual void SetRetrievalChannel(
const std::string &channel);
2260 throw NotImplemented(
"BufferedTransformation: this object is not attachable");
2271 static int DecrementPropagation(
int propagation)
2272 {
return propagation != 0 ? propagation - 1 : 0;}
2322 {
if (!Validate(rng, level))
throw InvalidMaterial(
"CryptoMaterial: this object contains invalid values");}
2334 {CRYPTOPP_UNUSED(bt);
throw NotImplemented(
"CryptoMaterial: this object does not support saving");}
2351 {CRYPTOPP_UNUSED(bt);
throw NotImplemented(
"CryptoMaterial: this object does not support loading");}
2367 CRYPTOPP_UNUSED(precomputationStorage);
CRYPTOPP_ASSERT(!SupportsPrecomputation());
2368 throw NotImplemented(
"CryptoMaterial: this object does not support precomputation");
2376 {CRYPTOPP_UNUSED(storedPrecomputation);
CRYPTOPP_ASSERT(!SupportsPrecomputation());
throw NotImplemented(
"CryptoMaterial: this object does not support precomputation");}
2383 {CRYPTOPP_UNUSED(storedPrecomputation);
CRYPTOPP_ASSERT(!SupportsPrecomputation());
throw NotImplemented(
"CryptoMaterial: this object does not support precomputation");}
2389 #if defined(__SUNPRO_CC)
2394 char m_sunCCworkaround;
2411 CRYPTOPP_UNUSED(rng); CRYPTOPP_UNUSED(params);
2412 throw NotImplemented(
"GeneratableCryptoMaterial: this object does not support key/parameter generation");
2463 {AccessMaterial().
Load(bt);}
2470 {GetMaterial().Save(bt);}
2485 {
return AccessPublicKey();}
2489 {
return GetPublicKey();}
2493 virtual PublicKey & AccessPublicKey() =0;
2553 virtual size_t MaxPlaintextLength(
size_t ciphertextLength)
const =0;
2558 virtual size_t CiphertextLength(
size_t plaintextLength)
const =0;
2565 virtual bool ParameterSupported(
const char *name)
const =0;
2603 const byte *plaintext,
size_t plaintextLength,
2637 const byte *ciphertext,
size_t ciphertextLength,
2750 {
throw NotImplemented(
"PK_MessageAccumulator: DigestSize() should not be called");}
2755 CRYPTOPP_UNUSED(digest); CRYPTOPP_UNUSED(digestSize);
2756 throw NotImplemented(
"PK_MessageAccumulator: TruncatedFinal() should not be called");
2777 virtual void InputRecoverableMessage(
PK_MessageAccumulator &messageAccumulator,
const byte *recoverableMessage,
size_t recoverableMessageLength)
const =0;
2804 virtual size_t SignMessage(
RandomNumberGenerator &rng,
const byte *message,
size_t messageLen,
byte *signature)
const;
2815 virtual size_t SignMessageWithRecovery(
RandomNumberGenerator &rng,
const byte *recoverableMessage,
size_t recoverableMessageLength,
2816 const byte *nonrecoverableMessage,
size_t nonrecoverableMessageLength,
byte *signature)
const;
2840 virtual void InputSignature(
PK_MessageAccumulator &messageAccumulator,
const byte *signature,
size_t signatureLength)
const =0;
2860 virtual bool VerifyMessage(
const byte *message,
size_t messageLen,
2861 const byte *signature,
size_t signatureLen)
const;
2888 const byte *nonrecoverableMessage,
size_t nonrecoverableMessageLength,
2889 const byte *signature,
size_t signatureLength)
const;
2904 virtual unsigned int AgreedValueLength()
const =0;
2908 virtual unsigned int PrivateKeyLength()
const =0;
2912 virtual unsigned int PublicKeyLength()
const =0;
2925 virtual void GeneratePublicKey(
RandomNumberGenerator &rng,
const byte *privateKey,
byte *publicKey)
const =0;
2948 virtual bool Agree(
byte *agreedValue,
const byte *privateKey,
const byte *otherPublicKey,
bool validateOtherPublicKey=
true)
const =0;
2963 virtual unsigned int AgreedValueLength()
const =0;
2967 virtual unsigned int StaticPrivateKeyLength()
const =0;
2971 virtual unsigned int StaticPublicKeyLength()
const =0;
2984 virtual void GenerateStaticPublicKey(
RandomNumberGenerator &rng,
const byte *privateKey,
byte *publicKey)
const =0;
2993 virtual void GenerateStaticKeyPair(
RandomNumberGenerator &rng,
byte *privateKey,
byte *publicKey)
const;
2997 virtual unsigned int EphemeralPrivateKeyLength()
const =0;
3001 virtual unsigned int EphemeralPublicKeyLength()
const =0;
3014 virtual void GenerateEphemeralPublicKey(
RandomNumberGenerator &rng,
const byte *privateKey,
byte *publicKey)
const =0;
3021 virtual void GenerateEphemeralKeyPair(
RandomNumberGenerator &rng,
byte *privateKey,
byte *publicKey)
const;
3039 virtual bool Agree(
byte *agreedValue,
3040 const byte *staticPrivateKey,
const byte *ephemeralPrivateKey,
3041 const byte *staticOtherPublicKey,
const byte *ephemeralOtherPublicKey,
3042 bool validateStaticOtherPublicKey=
true)
const =0;
3068 class ProtocolSession
3075 ProtocolError(ErrorType errorType,
const std::string &s) :
Exception(errorType, s) {}
3080 class UnexpectedMethodCall :
public Exception
3083 UnexpectedMethodCall(
const std::string &s) :
Exception(OTHER_ERROR, s) {}
3086 virtual ~ProtocolSession() {}
3088 ProtocolSession() : m_rng(NULLPTR), m_throwOnProtocolError(true), m_validState(false) {}
3092 bool GetThrowOnProtocolError()
const {
return m_throwOnProtocolError;}
3093 void SetThrowOnProtocolError(
bool throwOnProtocolError) {m_throwOnProtocolError = throwOnProtocolError;}
3095 bool HasValidState()
const {
return m_validState;}
3097 virtual bool OutgoingMessageAvailable()
const =0;
3098 virtual unsigned int GetOutgoingMessageLength()
const =0;
3099 virtual void GetOutgoingMessage(
byte *message) =0;
3101 virtual bool LastMessageProcessed()
const =0;
3102 virtual void ProcessIncomingMessage(
const byte *message,
unsigned int messageLength) =0;
3106 void CheckAndHandleInvalidState()
const;
3107 void SetValidState(
bool valid) {m_validState = valid;}
3112 bool m_throwOnProtocolError, m_validState;
3115 class KeyAgreementSession :
public ProtocolSession
3118 virtual ~KeyAgreementSession() {}
3120 virtual unsigned int GetAgreedValueLength()
const =0;
3121 virtual void GetAgreedValue(
byte *agreedValue)
const =0;
3124 class PasswordAuthenticatedKeyAgreementSession :
public KeyAgreementSession
3127 virtual ~PasswordAuthenticatedKeyAgreementSession() {}
3130 const byte *myId,
unsigned int myIdLength,
3131 const byte *counterPartyId,
unsigned int counterPartyIdLength,
3132 const byte *passwordOrVerifier,
unsigned int passwordOrVerifierLength);
3140 virtual ~PasswordAuthenticatedKeyAgreementDomain() {}
3146 virtual unsigned int GetPasswordVerifierLength(
const byte *password,
unsigned int passwordLength)
const =0;
3147 virtual void GeneratePasswordVerifier(
RandomNumberGenerator &rng,
const byte *userId,
unsigned int userIdLength,
const byte *password,
unsigned int passwordLength,
byte *verifier)
const =0;
3149 enum RoleFlags {CLIENT=1, SERVER=2, INITIATOR=4, RESPONDER=8};
3151 virtual bool IsValidRole(
unsigned int role) =0;
3152 virtual PasswordAuthenticatedKeyAgreementSession * CreateProtocolSession(
unsigned int role)
const =0;
3256 return CRYPTOPP_VERSION;
3262 #if CRYPTOPP_MSC_VERSION
3263 # pragma warning(pop)
virtual void BEREncode(BufferedTransformation &bt) const
Encode this object into a BufferedTransformation.
Interface for asymmetric algorithms.
Interface for public-key encryptors.
@ UNPREDICTABLE_RANDOM_IV
The IV must be random and unpredictable.
bool GetThisObject(T &object) const
Get a copy of this object or subobject.
virtual size_t FixedMaxPlaintextLength() const
Provides the maximum plaintext length given a fixed ciphertext length.
Interface for private keys.
Converts an enumeration to a type suitable for use as a template parameter.
Interface for public-key encryptors and decryptors.
T GetValueWithDefault(const char *name, T defaultValue) const
Get a named value.
virtual std::string AlgorithmName() const
Provides the name of this algorithm.
A method was called which was not implemented.
Interface for public-key signers and verifiers.
const std::type_info & GetStoredTypeInfo() const
Provides the stored type.
ErrorType GetErrorType() const
Retrieves the error type for the exception.
Interface for crypto prameters.
Interface for domains of simple key agreement protocols.
The operating system reported an error.
@ BIG_ENDIAN_ORDER
byte order is big-endian
std::string GetValueNames() const
Get a list of value names that can be retrieved.
Debugging and diagnostic assertions.
Interface for encoding and decoding ASN1 objects.
@ DECRYPTION
the cipher is performing decryption
const CryptoMaterial & GetMaterial() const
Retrieves a reference to a Private Key.
const CryptoMaterial & GetMaterial() const
Retrieves a reference to Crypto Parameters.
int GetIntValueWithDefault(const char *name, int defaultValue) const
Get a named value with type int, with default.
virtual bool AllowNonrecoverablePart() const =0
Determines whether the non-recoverable message part can be signed.
const unsigned long INFINITE_TIME
Represents infinite time.
Interface for all crypto algorithms.
CryptoMaterial & AccessMaterial()
Retrieves a reference to a Private Key.
Exception thrown when the object is in the wrong state for the operation.
virtual void ThrowIfInvalid(RandomNumberGenerator &rng, unsigned int level) const
Check this object for errors.
virtual size_t SignatureLength() const =0
Provides the signature length if it only depends on the key.
Interface for one direction (encryption or decryption) of a stream cipher or cipher mode.
Interface for algorithms that take byte strings as keys.
Interface for cloning objects.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
Exception thrown when trying to encrypt plaintext of invalid length.
virtual unsigned int MaxIVLength() const
Provides the maximum size of an IV.
const char * what() const
Retrieves a C-string describing the exception.
ValueTypeMismatch(const std::string &name, const std::type_info &stored, const std::type_info &retrieving)
Construct a ValueTypeMismatch.
virtual bool IsProbabilistic() const =0
Determines whether a signature scheme requires a random number generator.
unsigned int DigestSize() const
void TruncatedFinal(byte *digest, size_t digestSize)
@ LITTLE_ENDIAN_ORDER
byte order is little-endian
Interface for public-key decryptors.
virtual void Precompute(unsigned int precomputationStorage)
Perform precomputation.
@ INVALID_DATA_FORMAT
Input data was received that did not conform to expected format.
@ ENCRYPTION
the cipher is performing encryption
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
Interface for objects that can be waited on.
virtual void GetWaitObjects(WaitObjectContainer &container, CallStack const &callStack)=0
Retrieves waitable objects.
Exception throw when the private or public key is too short to sign or verify.
void DoQuickSanityCheck() const
Perform a quick sanity check.
Interface for domains of authenticated key agreement protocols.
virtual bool CanIncorporateEntropy() const
Determines if a generator can accept additional entropy.
int LibraryVersion(...)
Specifies the build-time version of the library.
@ INVALID_ARGUMENT
An invalid argument was detected.
virtual void LoadPrecomputation(BufferedTransformation &storedPrecomputation)
Retrieve previously saved precomputation.
const std::string AAD_CHANNEL
Channel for additional authenticated data.
word64 GetWord64ValueWithDefault(const char *name, word64 defaultValue) const
Get a named value with type word64, with default.
virtual bool IsValidKeyLength(size_t keylength) const
Returns whether keylength is a valid key length.
virtual Clonable * Clone() const
Copies this object.
Interface for random number generators.
CipherDir
Specifies a direction for a cipher to operate.
void SetErrorType(ErrorType errorType)
Sets the error type for the exceptions.
const std::type_info & GetRetrievingTypeInfo() const
Provides the retrieveing type.
IV_Requirement
Secure IVs requirements as enumerated values.
Exception throw when the private or public key has a length that can't be used.
virtual bool Validate(RandomNumberGenerator &rng, unsigned int level) const =0
Check this object for errors.
size_t messageLength
Recovered message length if isValidCoding is true, undefined otherwise.
virtual size_t MaxRecoverableLength() const =0
Provides the length of longest message that can be recovered.
Interface for public-key signers.
virtual void Resynchronize(const byte *iv, int ivLength=-1)
Resynchronize with an IV.
Thrown when an unexpected type is encountered.
Interface for key agreement algorithms.
Base class for all exceptions thrown by the library.
bool operator==(const OID &lhs, const OID &rhs)
Compare two OIDs for equality.
RandomNumberGenerator & NullRNG()
Random Number Generator that does not produce random numbers.
Interface for asymmetric algorithms using private keys.
virtual void SavePrecomputation(BufferedTransformation &storedPrecomputation) const
Save precomputation for later use.
int HeaderVersion()
Specifies the runtime version of the library.
ErrorType
Error types or categories.
void GetRequiredParameter(const char *className, const char *name, T &value) const
Retrieves a required name/value pair.
virtual bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const =0
Get a named value.
EnumToType< ByteOrder, BIG_ENDIAN_ORDER > BigEndian
Provides a constant for BigEndian.
const CryptoMaterial & GetMaterial() const
Retrieves a reference to a Public Key.
virtual size_t MaxRecoverableLengthFromSignatureLength(size_t signatureLength) const =0
Provides the length of longest message that can be recovered from a signature of given length.
Interface for public keys.
Interface for accumulating messages to be signed or verified.
virtual bool SupportsPrecomputation() const
Determines whether the object supports precomputation.
Returns a decoding results.
bool IsResynchronizable() const
Determines if the object can be resynchronized.
DecodingResult()
Constructs a DecodingResult.
@ INTERNALLY_GENERATED_IV
The IV is set by the object.
Namespace containing NaCl library functions.
virtual unsigned int IVSize() const
Returns length of the IV accepted by this object.
@ DATA_INTEGRITY_CHECK_FAILED
Data integerity check, such as CRC or MAC, failed.
ByteOrder
Provides the byte ordering.
DecodingResult(size_t len)
Constructs a DecodingResult.
virtual size_t FixedCiphertextLength() const
Provides the fixed ciphertext length, if one exists.
virtual bool NeedsPrespecifiedDataLengths() const
Determines if data lengths must be specified prior to inputting data.
bool operator==(const DecodingResult &rhs) const
Compare two DecodingResult.
Namespace containing testing and benchmark classes.
bool GetWord64Value(const char *name, word64 &value) const
Get a named value with type word64.
bool operator!=(const DecodingResult &rhs) const
Compare two DecodingResult.
CryptoMaterial & AccessMaterial()
Retrieves a reference to Crypto Parameters.
DecodingResult FixedLengthDecrypt(RandomNumberGenerator &rng, const byte *ciphertext, byte *plaintext, const NameValuePairs ¶meters=g_nullNameValuePairs) const
Decrypt a fixed size ciphertext.
const std::string & GetWhat() const
Retrieves a string describing the exception.
int GetErrorCode() const
Retrieve the error code returned by the operating system.
CryptoMaterial & AccessMaterial()
Retrieves a reference to a Public Key.
static void ThrowIfTypeMismatch(const char *name, const std::type_info &stored, const std::type_info &retrieving)
Ensures an expected name and type is present.
bool CanUsePredictableIVs() const
Determines if the object can use random but possibly predictable IVs.
virtual bool IsValidDerivedLength(size_t keylength) const
Returns whether keylength is a valid key length.
void Shuffle(IT begin, IT end)
Randomly shuffle the specified array.
virtual void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs ¶ms=g_nullNameValuePairs)
Generate a random key or crypto parameters.
EnumToType< ByteOrder, LITTLE_ENDIAN_ORDER > LittleEndian
Provides a constant for LittleEndian.
Interface for asymmetric algorithms using public keys.
@ CANNOT_FLUSH
BufferedTransformation received a Flush(true) signal but can't flush buffers.
virtual const CryptoParameters & GetCryptoParameters() const
Retrieves a reference to Crypto Parameters.
An invalid argument was detected.
bool CanUseStructuredIVs() const
Determines if the object can use structured IVs.
Interface for key derivation functions.
virtual void IncorporateEntropy(const byte *input, size_t length)
Update RNG state with additional unpredictable values.
Interface for generatable crypto material, such as private keys and crypto parameters.
virtual unsigned int MinIVLength() const
Provides the minimum size of an IV.
virtual const PublicKey & GetPublicKey() const
Retrieves a reference to a Public Key.
virtual bool RecoverablePartFirst() const =0
Determines whether the recoverable part must be input before the non-recoverable part.
Interface for public-key signature verifiers.
@ IO_ERROR
Error reading from input device or writing to output device.
const std::string & GetOperation() const
Retrieve the operating system API that reported the error.
BufferedTransformation & TheBitBucket()
An input discarding BufferedTransformation.
const NameValuePairs & g_nullNameValuePairs
An empty set of name-value pairs.
Namespace containing value name definitions.
Crypto++ library namespace.
unsigned int DefaultIVLength() const
Provides the default size of an IV.
void GetRequiredIntParameter(const char *className, const char *name, int &value) const
Retrieves a required name/value pair.
virtual lword MaxFooterLength() const
Provides the the maximum length of AAD.
bool GetValue(const char *name, T &value) const
Get a named value.
void SetWhat(const std::string &s)
Sets the error string for the exception.
@ NOT_IMPLEMENTED
A method was called which was not implemented.
Interface for crypto material, such as public and private keys, and crypto parameters.
Library configuration file.
bool GetIntValue(const char *name, int &value) const
Get a named value with type int.
Interface for one direction (encryption or decryption) of a block cipher.
virtual const PrivateKey & GetPrivateKey() const
Retrieves a reference to a Private Key.
virtual void Load(BufferedTransformation &bt)
Loads a key from a BufferedTransformation.
bool isValidCoding
Flag to indicate the decoding is valid.
Exception thrown when invalid crypto material is detected.
virtual void Save(BufferedTransformation &bt) const
Saves a key to a BufferedTransformation.
Interface for message authentication codes.
Exception thrown when an ASN.1 BER decoing error is encountered.
virtual std::string AlgorithmProvider() const
Retrieve the provider of this algorithm.
Exception(ErrorType errorType, const std::string &s)
Construct a new Exception.
virtual unsigned int GetMaxWaitObjectCount() const =0
Maximum number of wait objects that this object can return.
Namespace containing weak and wounded algorithms.
virtual bool SignatureUpfront() const
Determines whether the signature must be input before the message.
bool CanUseRandomIVs() const
Determines if the object can use random IVs.
void SetKeyWithIV(const byte *key, size_t length, const byte *iv)
Sets or reset the key of this object.
Interface for retrieving values given their names.
bool GetThisPointer(T *&ptr) const
Get a pointer to this object.
Multiple precision integer with arithmetic operations.
@ RANDOM_IV
The IV must be random and possibly predictable.
Flush(true) was called but it can't completely flush its buffers.
Interface for password based key derivation functions.
virtual size_t MaxSignatureLength(size_t recoverablePartLength=0) const
Provides the maximum signature length produced given the length of the recoverable message part.
Interface for authenticated encryption modes of operation.
A decryption filter encountered invalid ciphertext.