Crypto++
5.6.4
Free C++ class library of cryptographic schemes
|
Go to the documentation of this file.
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)
114 template <
typename ENUM_TYPE,
int VALUE>
117 static ENUM_TYPE ToEnum() {
return (ENUM_TYPE)VALUE;}
166 const char *
what()
const throw() {
return (m_what.c_str());}
168 const std::string &
GetWhat()
const {
return m_what;}
170 void SetWhat(
const std::string &s) {m_what = s;}
177 ErrorType m_errorType;
220 OS_Error(
ErrorType errorType,
const std::string &s,
const std::string& operation,
int errorCode)
221 :
Exception(errorType, s), m_operation(operation), m_errorCode(errorCode) {}
230 std::string m_operation;
261 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
262 operator size_t()
const {
return isValidCoding ? messageLength : 0;}
292 ValueTypeMismatch(
const std::string &name,
const std::type_info &stored,
const std::type_info &retrieving)
293 :
InvalidArgument(
"NameValuePairs: type mismatch for '" + name +
"', stored '" + stored.name() +
"', trying to retrieve '" + retrieving.name() +
"'")
294 , m_stored(stored), m_retrieving(retrieving) {}
305 const std::type_info &m_stored;
306 const std::type_info &m_retrieving;
315 return GetValue((std::string(
"ThisObject:")+
typeid(T).name()).c_str(),
object);
324 return GetValue((std::string(
"ThisPointer:")+
typeid(T).name()).c_str(), ptr);
337 return GetVoidValue(name,
typeid(T), &value);
351 bool result = GetValue(name, value);
353 if (result) {
return value;}
360 CRYPTOPP_DLL std::string GetValueNames()
const
361 {std::string result; GetValue(
"ValueNames", result);
return result;}
371 CRYPTOPP_DLL
bool GetIntValue(
const char *name,
int &value)
const
372 {
return GetValue(name, value);}
380 CRYPTOPP_DLL
int GetIntValueWithDefault(
const char *name,
int defaultValue)
const
381 {
return GetValueWithDefault(name, defaultValue);}
392 CRYPTOPP_DLL
static void CRYPTOPP_API ThrowIfTypeMismatch(
const char *name,
const std::type_info &stored,
const std::type_info &retrieving)
408 if (!GetValue(name, value))
409 throw InvalidArgument(std::string(className) +
": missing required parameter '" + name +
"'");
421 CRYPTOPP_DLL
void GetRequiredIntParameter(
const char *className,
const char *name,
int &value)
const
423 if (!GetIntValue(name, value))
424 throw InvalidArgument(std::string(className) +
": missing required parameter '" + name +
"'");
437 CRYPTOPP_DLL
virtual bool GetVoidValue(
const char *name,
const std::type_info &valueType,
void *pValue)
const =0;
440 #if CRYPTOPP_DOXYGEN_PROCESSING
449 DOCUMENTED_NAMESPACE_BEGIN(
Name)
451 DOCUMENTED_NAMESPACE_END
466 DOCUMENTED_NAMESPACE_BEGIN(
Weak)
468 DOCUMENTED_NAMESPACE_END
498 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
510 Algorithm(
bool checkSelfTestStatus =
true);
546 {
return keylength == GetValidKeyLength(keylength);}
563 void SetKeyWithRounds(
const byte *key,
size_t length,
int rounds);
573 void SetKeyWithIV(
const byte *key,
size_t length,
const byte *iv,
size_t ivLength);
583 {SetKeyWithIV(key, length, iv, IVSize());}
632 {
throw NotImplemented(GetAlgorithm().AlgorithmName() +
": this object doesn't support resynchronization");}
654 CRYPTOPP_UNUSED(iv); CRYPTOPP_UNUSED(ivLength);
655 throw NotImplemented(GetAlgorithm().AlgorithmName() +
": this object doesn't support resynchronization");
672 virtual const Algorithm & GetAlgorithm()
const =0;
679 virtual void UncheckedSetKey(
const byte *key,
unsigned int length,
const NameValuePairs ¶ms) =0;
684 void ThrowIfInvalidKeyLength(
size_t length);
691 void ThrowIfResynchronizable();
700 void ThrowIfInvalidIV(
const byte *iv);
705 size_t ThrowIfInvalidIVLength(
int length);
712 const byte * GetIVAndThrowIfInvalid(
const NameValuePairs ¶ms,
size_t &size);
716 inline void AssertValidKeyLength(
size_t length)
const
717 {CRYPTOPP_UNUSED(length); assert(IsValidKeyLength(length));}
728 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
752 {ProcessAndXorBlock(inBlock, NULL, outBlock);}
761 {ProcessAndXorBlock(inoutBlock, NULL, inoutBlock);}
769 virtual unsigned int OptimalDataAlignment()
const;
787 BT_InBlockIsCounter=1,
789 BT_DontIncrementInOutPointers=2,
793 BT_ReverseDirection=8,
795 BT_AllowParallel=16};
805 virtual size_t AdvancedProcessBlocks(
const byte *inBlocks,
const byte *xorBlocks,
byte *outBlocks,
size_t length, word32 flags)
const;
819 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
845 virtual unsigned int OptimalDataAlignment()
const;
852 virtual void ProcessData(
byte *outString,
const byte *inString,
size_t length) =0;
860 virtual void ProcessLastBlock(
byte *outString,
const byte *inString,
size_t length);
870 {ProcessData(inoutString, inoutString, length);}
877 inline void ProcessString(
byte *outString,
const byte *inString,
size_t length)
878 {ProcessData(outString, inString, length);}
884 {ProcessData(&input, &input, 1);
return input;}
897 CRYPTOPP_UNUSED(pos);
898 assert(!IsRandomAccess());
899 throw NotImplemented(
"StreamTransformation: this object doesn't support random access");
925 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
937 virtual void Update(
const byte *input,
size_t length) =0;
960 {TruncatedFinal(NULL, 0);}
986 virtual unsigned int OptimalDataAlignment()
const;
998 {Update(input, length); Final(digest);}
1010 {
return TruncatedVerify(digest,
DigestSize());}
1025 virtual bool VerifyDigest(
const byte *digest,
const byte *input,
size_t length)
1026 {Update(input, length);
return Verify(digest);}
1048 {Update(input, length); TruncatedFinal(digest, digestSize);}
1060 virtual bool TruncatedVerify(
const byte *digest,
size_t digestLength);
1077 {Update(input, length);
return TruncatedVerify(digest, digestLength);}
1084 void ThrowIfInvalidTruncatedSize(
size_t size)
const;
1094 const Algorithm & GetAlgorithm()
const {
return *
this;}
1102 const Algorithm & GetAlgorithm()
const {
return *
this;}
1110 const Algorithm & GetAlgorithm()
const {
return *
this;}
1120 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
1130 explicit BadState(
const std::string &name,
const char *message) :
Exception(OTHER_ERROR, name +
": " + message) {}
1131 explicit BadState(
const std::string &name,
const char *
function,
const char *state) :
Exception(OTHER_ERROR, name +
": " +
function +
" was called before " + state) {}
1152 void SpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength=0);
1157 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);
1162 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);
1174 virtual void UncheckedSpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength)
1175 {CRYPTOPP_UNUSED(headerLength); CRYPTOPP_UNUSED(messageLength); CRYPTOPP_UNUSED(footerLength);}
1178 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
1189 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
1203 CRYPTOPP_UNUSED(input); CRYPTOPP_UNUSED(length);
1204 throw NotImplemented(
"RandomNumberGenerator: IncorporateEntropy not implemented");
1216 virtual byte GenerateByte();
1223 virtual unsigned int GenerateBit();
1233 virtual word32 GenerateWord32(word32 min=0, word32 max=0xffffffffUL);
1242 virtual void GenerateBlock(
byte *output,
size_t size);
1254 virtual void GenerateIntoBufferedTransformation(
BufferedTransformation &target,
const std::string &channel, lword length);
1258 virtual void DiscardBytes(
size_t n);
1264 template <
class IT>
void Shuffle(IT begin, IT end)
1267 for (; begin != end; ++begin)
1268 std::iter_swap(begin, begin + GenerateWord32(0, end-begin-1));
1271 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
1272 byte GetByte() {
return GenerateByte();}
1273 unsigned int GetBit() {
return GenerateBit();}
1274 word32 GetLong(word32 a=0, word32 b=0xffffffffL) {
return GenerateWord32(a, b);}
1275 word16 GetShort(word16 a=0, word16 b=0xffff) {
return (word16)GenerateWord32(a, b);}
1276 void GetBlock(
byte *output,
size_t size) {GenerateBlock(output, size);}
1318 bool Wait(
unsigned long milliseconds,
CallStack const& callStack);
1327 extern CRYPTOPP_DLL
const std::string
AAD_CHANNEL;
1356 static const std::string &NULL_CHANNEL;
1358 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
1378 size_t Put(
byte inByte,
bool blocking=
true)
1379 {
return Put(&inByte, 1, blocking);}
1387 size_t Put(
const byte *inString,
size_t length,
bool blocking=
true)
1388 {
return Put2(inString, length, 0, blocking);}
1414 {size=0;
return NULL;}
1429 {
return PutModifiable2(inString, length, 0, blocking);}
1437 {
return !!Put2(NULL, 0, propagation < 0 ? -1 : propagation+1, blocking);}
1449 size_t PutMessageEnd(
const byte *inString,
size_t length,
int propagation=-1,
bool blocking=
true)
1450 {
return Put2(inString, length, propagation < 0 ? -1 : propagation+1, blocking);}
1458 virtual size_t Put2(
const byte *inString,
size_t length,
int messageEnd,
bool blocking) =0;
1466 virtual size_t PutModifiable2(
byte *inString,
size_t length,
int messageEnd,
bool blocking)
1467 {
return Put2(inString, length, messageEnd, blocking);}
1506 CRYPTOPP_UNUSED(parameters);
1507 throw NotImplemented(
"BufferedTransformation: this object can't be reinitialized");
1520 {CRYPTOPP_UNUSED(blocking);
return false;}
1546 virtual bool Flush(
bool hardFlush,
int propagation=-1,
bool blocking=
true);
1556 virtual bool MessageSeriesEnd(
int propagation=-1,
bool blocking=
true);
1563 {CRYPTOPP_UNUSED(propagation);}
1571 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
1572 void Close() {MessageEnd();}
1583 virtual lword MaxRetrievable()
const;
1587 virtual bool AnyRetrievable()
const;
1593 virtual size_t Get(
byte &outByte);
1600 virtual size_t Get(
byte *outString,
size_t getMax);
1607 virtual size_t Peek(
byte &outByte)
const;
1615 virtual size_t Peek(
byte *outString,
size_t peekMax)
const;
1657 {TransferTo2(target, transferMax, channel);
return transferMax;}
1669 virtual lword Skip(lword skipMax=LWORD_MAX);
1681 {
return CopyRangeTo(target, 0, copyMax, channel);}
1694 {lword i = position; CopyRangeTo2(target, i, i+copyMax, channel);
return i-position;}
1696 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
1697 unsigned long MaxRetrieveable()
const {
return MaxRetrievable();}
1706 virtual lword TotalBytesRetrievable()
const;
1712 virtual unsigned int NumberOfMessages()
const;
1717 virtual bool AnyMessages()
const;
1723 virtual bool GetNextMessage();
1730 virtual unsigned int SkipMessages(
unsigned int count=UINT_MAX);
1742 {TransferMessagesTo2(target, count, channel);
return count;}
1756 virtual void SkipAll();
1765 {TransferAllTo2(target, channel);}
1865 size_t ChannelPut(
const std::string &channel,
byte inByte,
bool blocking=
true)
1866 {
return ChannelPut(channel, &inByte, 1, blocking);}
1875 size_t ChannelPut(
const std::string &channel,
const byte *inString,
size_t length,
bool blocking=
true)
1876 {
return ChannelPut2(channel, inString, length, 0, blocking);}
1886 {
return ChannelPutModifiable2(channel, inString, length, 0, blocking);}
1895 size_t ChannelPutWord16(
const std::string &channel, word16 value,
ByteOrder order=
BIG_ENDIAN_ORDER,
bool blocking=
true);
1904 size_t ChannelPutWord32(
const std::string &channel, word32 value,
ByteOrder order=
BIG_ENDIAN_ORDER,
bool blocking=
true);
1915 {
return !!ChannelPut2(channel, NULL, 0, propagation < 0 ? -1 : propagation+1, blocking);}
1926 size_t ChannelPutMessageEnd(
const std::string &channel,
const byte *inString,
size_t length,
int propagation=-1,
bool blocking=
true)
1927 {
return ChannelPut2(channel, inString, length, propagation < 0 ? -1 : propagation+1, blocking);}
1940 virtual byte * ChannelCreatePutSpace(
const std::string &channel,
size_t &size);
1949 virtual size_t ChannelPut2(
const std::string &channel,
const byte *inString,
size_t length,
int messageEnd,
bool blocking);
1958 virtual size_t ChannelPutModifiable2(
const std::string &channel,
byte *inString,
size_t length,
int messageEnd,
bool blocking);
1968 virtual bool ChannelFlush(
const std::string &channel,
bool hardFlush,
int propagation=-1,
bool blocking=
true);
1979 virtual bool ChannelMessageSeriesEnd(
const std::string &channel,
int propagation=-1,
bool blocking=
true);
1984 virtual void SetRetrievalChannel(
const std::string &channel);
2018 CRYPTOPP_UNUSED(newAttachment); assert(!Attachable());
2019 throw NotImplemented(
"BufferedTransformation: this object is not attachable");
2030 static int DecrementPropagation(
int propagation)
2031 {
return propagation != 0 ? propagation - 1 : 0;}
2046 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
2084 {
if (!Validate(rng, level))
throw InvalidMaterial(
"CryptoMaterial: this object contains invalid values");}
2096 {CRYPTOPP_UNUSED(bt);
throw NotImplemented(
"CryptoMaterial: this object does not support saving");}
2113 {CRYPTOPP_UNUSED(bt);
throw NotImplemented(
"CryptoMaterial: this object does not support loading");}
2129 CRYPTOPP_UNUSED(precomputationStorage); assert(!SupportsPrecomputation());
2130 throw NotImplemented(
"CryptoMaterial: this object does not support precomputation");
2138 {CRYPTOPP_UNUSED(storedPrecomputation); assert(!SupportsPrecomputation());
throw NotImplemented(
"CryptoMaterial: this object does not support precomputation");}
2144 {CRYPTOPP_UNUSED(storedPrecomputation); assert(!SupportsPrecomputation());
throw NotImplemented(
"CryptoMaterial: this object does not support precomputation");}
2150 #if (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590)
2152 char m_sunCCworkaround;
2161 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
2172 CRYPTOPP_UNUSED(rng); CRYPTOPP_UNUSED(params);
2173 throw NotImplemented(
"GeneratableCryptoMaterial: this object does not support key/parameter generation");
2204 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
2220 {AccessMaterial().Load(bt);}
2226 {GetMaterial().Save(bt);}
2233 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
2242 {
return AccessPublicKey();}
2246 {
return GetPublicKey();}
2261 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
2284 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
2341 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
2342 size_t MaxPlainTextLength(
size_t cipherTextLength)
const {
return MaxPlaintextLength(cipherTextLength);}
2343 size_t CipherTextLength(
size_t plainTextLength)
const {
return CiphertextLength(plainTextLength);}
2370 const byte *plaintext,
size_t plaintextLength,
2388 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
2407 const byte *ciphertext,
size_t ciphertextLength,
2436 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
2529 {
throw NotImplemented(
"PK_MessageAccumulator: DigestSize() should not be called");}
2534 CRYPTOPP_UNUSED(digest); CRYPTOPP_UNUSED(digestSize);
2535 throw NotImplemented(
"PK_MessageAccumulator: TruncatedFinal() should not be called");
2544 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
2586 virtual size_t SignMessage(
RandomNumberGenerator &rng,
const byte *message,
size_t messageLen,
byte *signature)
const;
2597 virtual size_t SignMessageWithRecovery(
RandomNumberGenerator &rng,
const byte *recoverableMessage,
size_t recoverableMessageLength,
2598 const byte *nonrecoverableMessage,
size_t nonrecoverableMessageLength,
byte *signature)
const;
2611 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
2645 virtual bool VerifyMessage(
const byte *message,
size_t messageLen,
2646 const byte *signature,
size_t signatureLen)
const;
2673 const byte *nonrecoverableMessage,
size_t nonrecoverableMessageLength,
2674 const byte *signature,
size_t signatureLength)
const;
2685 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
2735 virtual bool Agree(
byte *agreedValue,
const byte *privateKey,
const byte *otherPublicKey,
bool validateOtherPublicKey=
true)
const =0;
2737 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
2750 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
2786 virtual void GenerateStaticKeyPair(
RandomNumberGenerator &rng,
byte *privateKey,
byte *publicKey)
const;
2814 virtual void GenerateEphemeralKeyPair(
RandomNumberGenerator &rng,
byte *privateKey,
byte *publicKey)
const;
2833 const byte *staticPrivateKey,
const byte *ephemeralPrivateKey,
2834 const byte *staticOtherPublicKey,
const byte *ephemeralOtherPublicKey,
2835 bool validateStaticOtherPublicKey=
true)
const =0;
2837 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
2866 class ProtocolSession
2873 ProtocolError(ErrorType errorType,
const std::string &s) :
Exception(errorType, s) {}
2878 class UnexpectedMethodCall :
public Exception
2881 UnexpectedMethodCall(
const std::string &s) :
Exception(OTHER_ERROR, s) {}
2884 ProtocolSession() : m_rng(NULL), m_throwOnProtocolError(true), m_validState(false) {}
2885 virtual ~ProtocolSession() {}
2889 bool GetThrowOnProtocolError()
const {
return m_throwOnProtocolError;}
2890 void SetThrowOnProtocolError(
bool throwOnProtocolError) {m_throwOnProtocolError = throwOnProtocolError;}
2892 bool HasValidState()
const {
return m_validState;}
2894 virtual bool OutgoingMessageAvailable()
const =0;
2895 virtual unsigned int GetOutgoingMessageLength()
const =0;
2896 virtual void GetOutgoingMessage(
byte *message) =0;
2898 virtual bool LastMessageProcessed()
const =0;
2899 virtual void ProcessIncomingMessage(
const byte *message,
unsigned int messageLength) =0;
2903 void CheckAndHandleInvalidState()
const;
2904 void SetValidState(
bool valid) {m_validState = valid;}
2909 bool m_throwOnProtocolError, m_validState;
2912 class KeyAgreementSession :
public ProtocolSession
2915 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
2916 virtual ~KeyAgreementSession() {}
2919 virtual unsigned int GetAgreedValueLength()
const =0;
2920 virtual void GetAgreedValue(
byte *agreedValue)
const =0;
2923 class PasswordAuthenticatedKeyAgreementSession :
public KeyAgreementSession
2926 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
2927 virtual ~PasswordAuthenticatedKeyAgreementSession() {}
2931 const byte *myId,
unsigned int myIdLength,
2932 const byte *counterPartyId,
unsigned int counterPartyIdLength,
2933 const byte *passwordOrVerifier,
unsigned int passwordOrVerifierLength);
2939 #ifndef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562
2940 virtual ~PasswordAuthenticatedKeyAgreementDomain() {}
2947 virtual unsigned int GetPasswordVerifierLength(
const byte *password,
unsigned int passwordLength)
const =0;
2948 virtual void GeneratePasswordVerifier(
RandomNumberGenerator &rng,
const byte *userId,
unsigned int userIdLength,
const byte *password,
unsigned int passwordLength,
byte *verifier)
const =0;
2950 enum RoleFlags {CLIENT=1, SERVER=2, INITIATOR=4, RESPONDER=8};
2952 virtual bool IsValidRole(
unsigned int role) =0;
2953 virtual PasswordAuthenticatedKeyAgreementSession * CreateProtocolSession(
unsigned int role)
const =0;
2991 #ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
2999 #if CRYPTOPP_MSC_VERSION
3000 # pragma warning(pop)
virtual void BEREncode(BufferedTransformation &bt) const
Encode this object into a BufferedTransformation.
Interface for asymmetric algorithms.
Interface for public-key encryptors.
virtual lword MaxHeaderLength() const =0
Provides the maximum length of AAD that can be input.
@ 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.
virtual const CryptoMaterial & GetMaterial() const =0
Retrieves a reference to CryptoMaterial.
virtual unsigned int PublicKeyLength() const =0
Provides the size of the public key.
Interface for private keys.
Converts a typename to an enumerated value.
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.
virtual unsigned int EphemeralPrivateKeyLength() const =0
Provides the size of ephemeral private key.
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.
virtual unsigned int AgreedValueLength() const =0
Provides the size of the agreed value.
The operating system reported an error.
@ BIG_ENDIAN_ORDER
byte order is big-endian
Interface for encoding and decoding ASN1 objects.
@ DECRYPTION
the cipher is performing decryption
const CryptoMaterial & GetMaterial() const
Retrieves a reference to a Private Key.
virtual unsigned int StaticPublicKeyLength() const =0
Provides the size of the static public key.
virtual std::string AlgorithmName() const =0
Provides the name of this algorithm.
const CryptoMaterial & GetMaterial() const
Retrieves a reference to Crypto Parameters.
virtual bool AllowNonrecoverablePart() const =0
Determines whether the non-recoverable message part can be signed.
void BERDecode(BufferedTransformation &bt)
Loads this object from a BufferedTransformation.
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 IV_Requirement IVRequirement() const =0
Minimal requirement for secure IVs.
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.
const char * DigestSize()
int, in bytes
Interface for cloning objects.
Exception thrown when trying to encrypt plaintext of invalid length.
virtual unsigned int MaxIVLength() const
Provides the maximum size of an IV.
virtual size_t MaxPlaintextLength(size_t ciphertextLength) const =0
Provides the maximum length of plaintext for a given ciphertext length.
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
void DEREncode(BufferedTransformation &bt) const
Saves this object to a BufferedTransformation.
Interface for public-key decryptors.
virtual void Precompute(unsigned int precomputationStorage)
Perform precomputation.
unsigned int GetByte(ByteOrder order, T value, unsigned int index)
Gets a byte from a value.
@ INVALID_DATA_FORMAT
Input data was received that did not conform to expected format.
@ ENCRYPTION
the cipher is performing encryption
virtual bool ParameterSupported(const char *name) const =0
Determines whether this object supports the use of a named parameter.
const std::string DEFAULT_CHANNEL
Default channel for BufferedTransformation.
virtual size_t DefaultKeyLength() const =0
Returns default (recommended) key length in bytes.
virtual size_t MinKeyLength() const =0
Returns smallest valid key length in bytes.
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.
@ 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.
virtual bool IsValidKeyLength(size_t keylength) const
Returns whether keylength is a valid key length.
virtual unsigned int StaticPrivateKeyLength() const =0
Provides the size of the static private key.
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.
Access a block of memory.
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.
virtual size_t MaxKeyLength() const =0
Returns largest valid key length in bytes.
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.
virtual void BERDecode(BufferedTransformation &bt)=0
Decode this object from a BufferedTransformation.
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.
ErrorType
Error types or categories.
void GetRequiredParameter(const char *className, const char *name, T &value) const
Retrieves a required name/value pair.
virtual CryptoParameters & AccessCryptoParameters()=0
Retrieves a reference to Crypto Parameters.
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.
virtual DecodingResult Decrypt(RandomNumberGenerator &rng, const byte *ciphertext, size_t ciphertextLength, byte *plaintext, const NameValuePairs ¶meters=g_nullNameValuePairs) const =0
Decrypt a byte string.
bool IsResynchronizable() const
Determines if the object can be resynchronized.
DecodingResult()
Constructs a DecodingResult.
@ INTERNALLY_GENERATED_IV
The IV is set by the object.
virtual PK_MessageAccumulator * NewSignatureAccumulator(RandomNumberGenerator &rng) const =0
Create a new HashTransformation to accumulate the message to be signed.
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 void InputRecoverableMessage(PK_MessageAccumulator &messageAccumulator, const byte *recoverableMessage, size_t recoverableMessageLength) const =0
Input a recoverable message to an accumulator.
virtual bool NeedsPrespecifiedDataLengths() const
Determines if data lengths must be specified prior to inputting data.
bool operator==(const DecodingResult &rhs) const
Compare two DecodingResult.
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.
virtual void Encrypt(RandomNumberGenerator &rng, const byte *plaintext, size_t plaintextLength, byte *ciphertext, const NameValuePairs ¶meters=g_nullNameValuePairs) const =0
Encrypt a byte string.
bool CanUsePredictableIVs() const
Determines if the object can use random but possibly predictable IVs.
virtual PK_MessageAccumulator * NewVerificationAccumulator() const =0
Create a new HashTransformation to accumulate the message to be verified.
virtual bool Agree(byte *agreedValue, const byte *staticPrivateKey, const byte *ephemeralPrivateKey, const byte *staticOtherPublicKey, const byte *ephemeralOtherPublicKey, bool validateStaticOtherPublicKey=true) const =0
Derive agreed value.
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.
virtual void GeneratePublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const =0
Generate a public key from a private key in this domain.
An invalid argument was detected.
bool CanUseStructuredIVs() const
Determines if the object can use structured IVs returns whether the object can use structured IVs,...
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 void GenerateStaticPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const =0
Generate static private key in this domain.
virtual unsigned int MinIVLength() const
Provides the minimum size of an IV.
virtual void AssignFrom(const NameValuePairs &source)=0
Assign values to this object.
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.
virtual size_t CiphertextLength(size_t plaintextLength) const =0
Calculate the length of ciphertext given length of plaintext.
virtual lword MaxFooterLength() const
Provides the the maximum length of AAD.
virtual void GenerateEphemeralPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const =0
Generate ephemeral public key.
virtual lword MaxMessageLength() const =0
Provides the maximum length of encrypted data.
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.
virtual bool VerifyAndRestart(PK_MessageAccumulator &messageAccumulator) const =0
Check whether messageAccumulator contains a valid signature and message, and restart messageAccumulat...
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 GenerateStaticPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const =0
Generate a static public key from a private key in this domain.
virtual void Save(BufferedTransformation &bt) const
Saves a key to a BufferedTransformation.
Interface for message authentication codes.
virtual CryptoMaterial & AccessMaterial()=0
Retrieves a reference to CryptoMaterial.
Exception thrown when an ASN.1 BER decoing error is encountered.
virtual void InputSignature(PK_MessageAccumulator &messageAccumulator, const byte *signature, size_t signatureLength) const =0
Input signature into a message accumulator.
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.
virtual DecodingResult RecoverAndRestart(byte *recoveredMessage, PK_MessageAccumulator &messageAccumulator) const =0
Recover a message from its signature.
virtual size_t GetValidKeyLength(size_t n) const =0
virtual bool Agree(byte *agreedValue, const byte *privateKey, const byte *otherPublicKey, bool validateOtherPublicKey=true) const =0
Derive agreed value.
container of wait objects
virtual unsigned int EphemeralPublicKeyLength() const =0
Provides the size of ephemeral public key.
virtual void DEREncode(BufferedTransformation &bt) const =0
Encode this object into a BufferedTransformation.
Namespace containing weak and wounded algorithms.
virtual void GenerateEphemeralPrivateKey(RandomNumberGenerator &rng, byte *privateKey) const =0
Generate ephemeral private key.
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.
virtual PublicKey & AccessPublicKey()=0
Retrieves a reference to a Public Key.
Interface for retrieving values given their names.
virtual void GeneratePrivateKey(RandomNumberGenerator &rng, byte *privateKey) const =0
Generate private key in this domain.
bool GetThisPointer(T *&ptr) const
Get a pointer to this object.
virtual unsigned int AgreedValueLength() const =0
Provides the size of the agreed value.
virtual size_t SignAndRestart(RandomNumberGenerator &rng, PK_MessageAccumulator &messageAccumulator, byte *signature, bool restart=true) const =0
Sign and restart messageAccumulator.
virtual unsigned int PrivateKeyLength() const =0
Provides the size of the private key.
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.
virtual PrivateKey & AccessPrivateKey()=0
Retrieves a reference to a Private Key.
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 one direction (encryption or decryption) of a stream cipher or block cipher mode with a...
A decryption filter encountered invalid ciphertext.