2 #include "TransformFactory.h"
4 #include <CommonCrypto/CommonDigest.h>
5 #include <CommonCrypto/CommonHMAC.h>
8 // set up an abstraction for digest. We have to do this because
9 // CommonCrypto doesn't support a unified digest model
14 CFStringRef mDigestType
;
18 Digest(CFStringRef digestType
, size_t digestLength
);
22 virtual void Update(const void* buffer
, size_t length
) = 0;
23 virtual size_t DigestLength() = 0;
24 virtual const void* Finalize() = 0;
26 virtual CFDictionaryRef
CopyState();
28 static int LengthForType(CFStringRef type
);
33 class MD2Digest
: public Digest
37 u_int8_t mDigestBuffer
[CC_MD2_DIGEST_LENGTH
];
42 void Update(const void* buffer
, size_t length
);
43 size_t DigestLength();
44 const void* Finalize();
49 class MD4Digest
: public Digest
53 u_int8_t mDigestBuffer
[CC_MD4_DIGEST_LENGTH
];
58 void Update(const void* buffer
, size_t length
);
59 size_t DigestLength();
60 const void* Finalize();
65 class MD5Digest
: public Digest
69 u_int8_t mDigestBuffer
[CC_MD5_DIGEST_LENGTH
];
74 void Update(const void* buffer
, size_t length
);
75 size_t DigestLength();
76 const void* Finalize();
81 class SHA1Digest
: public Digest
85 u_int8_t mDigestBuffer
[CC_SHA1_DIGEST_LENGTH
];
90 void Update(const void* buffer
, size_t length
);
91 size_t DigestLength();
92 const void* Finalize();
97 class SHA256Digest
: public Digest
100 CC_SHA256_CTX mContext
;
101 u_int8_t mDigestBuffer
[CC_SHA256_DIGEST_LENGTH
];
106 void Update(const void* buffer
, size_t length
);
107 size_t DigestLength();
108 const void* Finalize();
113 class SHA224Digest
: public Digest
116 CC_SHA256_CTX mContext
;
117 u_int8_t mDigestBuffer
[CC_SHA256_DIGEST_LENGTH
];
122 void Update(const void* buffer
, size_t length
);
123 size_t DigestLength();
124 const void* Finalize();
129 class SHA512Digest
: public Digest
132 CC_SHA512_CTX mContext
;
133 u_int8_t mDigestBuffer
[CC_SHA512_DIGEST_LENGTH
];
138 void Update(const void* buffer
, size_t length
);
139 size_t DigestLength();
140 const void* Finalize();
145 class SHA384Digest
: public Digest
148 CC_SHA512_CTX mContext
;
149 u_int8_t mDigestBuffer
[CC_SHA512_DIGEST_LENGTH
];
154 void Update(const void* buffer
, size_t length
);
155 size_t DigestLength();
156 const void* Finalize();
161 class Hmac
: public Digest
165 CCHmacContext mHMACContext
;
166 u_int8_t
*mDigestBuffer
;
168 Transform
* mParentTransform
;
169 CCHmacAlgorithm mAlg
;
174 Hmac(Transform
* parentTransform
, CFStringRef digestType
, CCHmacAlgorithm alg
, size_t length
);
176 void Update(const void* buffer
, size_t length
);
177 size_t DigestLength();
178 const void* Finalize();
182 class DigestTransform
: public Transform
190 static CFTypeRef
Make() CF_RETURNS_RETAINED
;
191 virtual ~DigestTransform();
193 CFErrorRef
Setup(CFTypeRef digestType
, CFIndex length
);
195 virtual void AttributeChanged(CFStringRef name
, CFTypeRef value
);
197 static TransformFactory
* MakeTransformFactory();
199 CFDictionaryRef
CopyState();
200 void RestoreState(CFDictionaryRef state
);
201 static CFTypeID
GetCFTypeID();