28 #ifndef PTLIB_CYPHER_H
29 #define PTLIB_CYPHER_H
42 class PSASLString :
public PString
47 PSASLString(
const char * str) { AppendValidated(str); }
48 PSASLString(
const PString & str) { AppendValidated(str); }
49 PSASLString(
const PSASLString & str) :
PString(str) { }
52 PSASLString &
operator=(
wchar_t ch) {
MakeEmpty(); AppendValidated(ch);
return *
this; }
53 PSASLString &
operator=(
const char * str) {
MakeEmpty(); AppendValidated(str);
return *
this; }
57 PSASLString &
operator+=(
char ch) { AppendValidated(ch);
return *
this; }
58 PSASLString &
operator+=(
wchar_t ch) { AppendValidated(ch);
return *
this; }
59 PSASLString &
operator+=(
const char * str) { AppendValidated(str);
return *
this; }
60 PSASLString &
operator+=(
const PString & str) { AppendValidated(str);
return *
this; }
64 void AppendValidated(
const char * str);
65 void AppendValidated(
wchar_t ch);
116 Options options = e_CRLF,
122 Options options = e_CRLF,
126 const char * endOfLine,
132 ) { StartEncoding(useCRLFs ? e_CRLF : e_LF, width); }
135 void ProcessEncoding(
138 void ProcessEncoding(
141 void ProcessEncoding(
144 void ProcessEncoding(
145 const void * dataBlock,
168 Options options = e_LF,
173 const char * endOfLine,
178 Options options = e_LF,
183 const char * endOfLine,
188 Options options = e_LF,
193 const char * endOfLine,
197 const void * dataBlock,
199 Options options = e_LF,
203 const void * dataBlock,
205 const char * endOfLine,
210 void StartDecoding();
243 PBoolean IsDecodeOK() {
return m_perfectDecode; }
273 void OutputBase64(
const BYTE * data);
276 BYTE m_saveTriple[3];
279 PINDEX m_maxLineLength;
280 PINDEX m_currentLineLength;
281 const char * m_alphabet;
283 bool m_perfectDecode;
284 PINDEX m_quadPosition;
292 class PMessageDigest :
public PObject
302 virtual void PrintOn(ostream & strm)
const;
304 bool ConstantTimeCompare(
const Result & other)
const;
306 PString AsBase64(PBase64::Options options = PBase64::e_NoLF)
const {
return PBase64::Encode(*
this, options); }
311 void Start() { InternalStart(); }
314 const void * dataBlock,
341 ) { InternalCompleteDigest(result); }
344 virtual void InternalStart() = 0;
345 virtual void InternalProcess(
const void * dataBlock, PINDEX length) = 0;
346 virtual void InternalCompleteDigest(Result & result) = 0;
350 template <
class Digestor>
struct PMessageDigestStatics
360 PMessageDigest::Result & result
366 ) {
return Encode(cstr, (PINDEX)strlen(cstr)); }
371 PMessageDigest::Result & result
372 ) { Encode(cstr, (PINDEX)strlen(cstr), result); }
377 ) {
return Encode(data, data.
GetSize()); }
382 PMessageDigest::Result & result
383 ) { Encode(data, data.
GetSize(), result); }
387 const void * dataBlock,
390 PMessageDigest::Result result;
391 Encode(dataBlock, length, result);
392 return result.AsBase64();
398 const void * dataBlock,
400 PMessageDigest::Result & result
403 stomach.Process(dataBlock, length);
404 stomach.Complete(result);
417 void SetKey(
const char * key) { InitKey(key, strlen(key)); }
419 void SetKey(
const PBYTEArray & key) { InitKey((
const BYTE *)key, key.
GetSize()); }
420 void SetKey(
const BYTE * key, PINDEX len) { InitKey(key, len); }
422 PString Encode(
const void * data, PINDEX len, PBase64::Options options = PBase64::e_NoLF);
423 PString Encode(
const PBYTEArray & data, PBase64::Options options = PBase64::e_NoLF);
424 PString Encode(
const PString & str, PBase64::Options options = PBase64::e_NoLF);
426 typedef PMessageDigest::Result Result;
427 virtual void Process(
const void * data, PINDEX len, Result & result);
428 virtual void Process(
const PBYTEArray & data, Result & result);
429 virtual void Process(
const PString & str, Result & result);
432 virtual void InitKey(
const void * key, PINDEX len);
433 virtual void InternalProcess(
const void * data, PINDEX len, PHMAC::Result & result) = 0;
444 class PMessageDigest5 :
public PMessageDigest,
public PMessageDigestStatics<PMessageDigest5>
448 enum { DigestLength = 16 };
449 typedef PMessageDigest::Result Code;
455 virtual void InternalStart();
456 virtual void InternalProcess(
const void * dataBlock, PINDEX length);
457 virtual void InternalCompleteDigest(Result & result);
460 void Transform(
const BYTE * block);
473 class PHMAC_MD5 :
public PHMAC
477 enum { BlockSize = 64 };
480 virtual void InitKey(
const void * key, PINDEX len);
481 virtual void InternalProcess(
const void * data, PINDEX len, PHMAC::Result & result);
487 class PMessageDigestSHA :
public PMessageDigest
495 explicit PMessageDigestSHA(Context * context);
498 ~PMessageDigestSHA();
501 virtual
void InternalStart();
502 virtual
void InternalProcess(const
void * dataBlock, PINDEX length);
503 virtual
void InternalCompleteDigest(Result & result);
514 PMessageDigestSHA(
const PMessageDigestSHA &) : m_context(), m_state() { }
515 void operator=(
const PMessageDigestSHA &) { }
522 class PMessageDigestSHA1 :
public PMessageDigestSHA,
public PMessageDigestStatics<PMessageDigestSHA1>
524 PCLASSINFO(PMessageDigestSHA1, PMessageDigestSHA)
526 enum { DigestLength = 20 };
527 PMessageDigestSHA1();
534 class PMessageDigestSHA256 :
public PMessageDigestSHA,
public PMessageDigestStatics<PMessageDigestSHA256>
536 PCLASSINFO(PMessageDigestSHA256, PMessageDigestSHA)
538 PMessageDigestSHA256();
545 class PMessageDigestSHA384 : public PMessageDigestSHA, public PMessageDigestStatics<PMessageDigestSHA384>
547 PCLASSINFO(PMessageDigestSHA384, PMessageDigestSHA)
549 PMessageDigestSHA384();
556 class PMessageDigestSHA512 : public PMessageDigestSHA, public PMessageDigestStatics<PMessageDigestSHA512>
558 PCLASSINFO(PMessageDigestSHA512, PMessageDigestSHA)
560 PMessageDigestSHA512();
564 class PHMAC_SHA : public PHMAC
568 typedef struct evp_md_st const * Algorithm;
570 explicit PHMAC_SHA(Algorithm algo);
571 virtual
void InternalProcess(const
void * data, PINDEX len, PHMAC::Result & result);
573 Algorithm m_algorithm;
577 class PHMAC_SHA1 : public PHMAC_SHA
585 class PHMAC_SHA256 : public PHMAC_SHA
593 class PHMAC_SHA384 : public PHMAC_SHA
601 class PHMAC_SHA512 : public PHMAC_SHA
620 enum BlockChainMode {
622 ECB = ElectronicCodebook,
624 CBC = CypherBlockChaining,
626 OFB = OutputFeedback,
628 CFB = CypherFeedback,
725 BlockChainMode chainMode
728 const void * keyData,
731 BlockChainMode chainMode
736 virtual void Initialise(
741 virtual void EncodeBlock(
748 virtual void DecodeBlock(
759 BlockChainMode chainMode;
770 class PTEACypher :
public PCypher
784 BlockChainMode chainMode = ElectronicCodebook
788 BlockChainMode chainMode = ElectronicCodebook
804 static void GenerateKey(
811 virtual void Initialise(
816 virtual void EncodeBlock(
822 virtual void DecodeBlock(
828 DWORD k0, k1, k2, k3;
834 class PSecureConfig :
public PConfig
844 const PTEACypher::Key & productKey,
846 Source src = Application
849 const PTEACypher::Key & productKey,
850 const
char * const * securedKeyArray,
852 Source src = Application
864 const
PStringArray & GetSecuredKeys()
const {
return securedKeys; }
871 const PString & GetSecurityKey()
const {
return securityKey; }
878 const PString & GetExpiryDateKey()
const {
return expiryDateKey; }
885 const PString & GetOptionBitsKey()
const {
return optionBitsKey; }
892 const PString & GetPendingPrefix()
const {
return pendingPrefix; }
900 PTEACypher::Key & productKey
909 enum ValidationState {
916 ValidationState GetValidation()
const;
942 PTEACypher::Key productKey;
950 #endif // P_CONFIG_FILE
954 #endif // PTLIB_CYPHER_H
PString & operator=(const PString &str)
Assign the string to the current object.
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:2164
virtual PString & MakeEmpty()
Make the current string empty.
A class representing a configuration for the application.
Definition: config.h:62
This is an array collection class of PString objects.
Definition: pstring.h:2365
PString & operator+=(const PString &str)
Concatenate a string to another string, modifiying that string.
Array of unsigned characters.
Definition: array.h:605
virtual PINDEX GetSize() const
Get the current size of the container.
bool PBoolean
Definition: object.h:174
The character string class.
Definition: pstring.h:108
virtual PINDEX GetLength() const
Determine the length of the null terminated string.
Definition: pstring.h:595
virtual const char * GetPointer(PINDEX=0) const
Get a const pointer to the buffer contents This function overrides the ancestor function that returns...
Definition: pstring.h:1877
Ultimate parent class for all objects in the class library.
Definition: object.h:2204
virtual void PrintOn(ostream &strm) const
Output the contents of the object to the stream.