DocumentationOverviewBuilding ASL Documentation Library Wiki Docs Indices Browse Perforce More InfoRelease NotesWiki Site Search License Success Stories Contributors MediaDownloadPerforce Depots SupportASL SourceForge HomeMailing Lists Discussion Forums Report Bugs Suggest Features Contribute to ASL RSSShort-text newsFull-text news File releases Other Adobe ProjectsAdobe AirAdobe GIL Adobe Labs Adobe Media Gallery Adobe XMP Tamarin project (Mozilla Foundation) Other ResourcesBoostRIAForge SGI STL |
dng_fingerprint.hGo to the documentation of this file.00001 /*****************************************************************************/ 00002 // Copyright 2006-2007 Adobe Systems Incorporated 00003 // All Rights Reserved. 00004 // 00005 // NOTICE: Adobe permits you to use, modify, and distribute this file in 00006 // accordance with the terms of the Adobe license agreement accompanying it. 00007 /*****************************************************************************/ 00008 00009 /* $Id: //mondo/dng_sdk_1_2/dng_sdk/source/dng_fingerprint.h#1 $ */ 00010 /* $DateTime: 2008/03/09 14:29:54 $ */ 00011 /* $Change: 431850 $ */ 00012 /* $Author: tknoll $ */ 00013 00018 /*****************************************************************************/ 00019 00020 #ifndef __dng_fingerprint__ 00021 #define __dng_fingerprint__ 00022 00023 /*****************************************************************************/ 00024 00025 #include "dng_exceptions.h" 00026 #include "dng_types.h" 00027 #include "dng_stream.h" 00028 00029 /*****************************************************************************/ 00030 00032 00033 class dng_fingerprint 00034 { 00035 00036 public: 00037 00038 uint8 data [16]; 00039 00040 public: 00041 00042 dng_fingerprint (); 00043 00045 00046 bool IsNull () const; 00047 00049 00050 bool IsValid () const 00051 { 00052 return !IsNull (); 00053 } 00054 00056 00057 void Clear () 00058 { 00059 *this = dng_fingerprint (); 00060 } 00061 00063 00064 bool operator== (const dng_fingerprint &print) const; 00065 00067 00068 bool operator!= (const dng_fingerprint &print) const 00069 { 00070 return !(*this == print); 00071 } 00072 00074 00075 uint32 Collapse32 () const; 00076 00077 }; 00078 00079 /******************************************************************************/ 00080 00081 // Derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm 00082 00083 // Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All 00084 // rights reserved. 00085 // 00086 // License to copy and use this software is granted provided that it 00087 // is identified as the "RSA Data Security, Inc. MD5 Message-Digest 00088 // Algorithm" in all material mentioning or referencing this software 00089 // or this function. 00090 // 00091 // License is also granted to make and use derivative works provided 00092 // that such works are identified as "derived from the RSA Data 00093 // Security, Inc. MD5 Message-Digest Algorithm" in all material 00094 // mentioning or referencing the derived work. 00095 // 00096 // RSA Data Security, Inc. makes no representations concerning either 00097 // the merchantability of this software or the suitability of this 00098 // software for any particular purpose. It is provided "as is" 00099 // without express or implied warranty of any kind. 00100 // 00101 // These notices must be retained in any copies of any part of this 00102 // documentation and/or software. 00103 00104 class dng_md5_printer 00105 { 00106 00107 public: 00108 00109 dng_md5_printer (); 00110 00111 virtual ~dng_md5_printer () 00112 { 00113 } 00114 00115 void Reset (); 00116 00117 void Process (const void *data, 00118 uint32 inputLen); 00119 00120 const dng_fingerprint & Result (); 00121 00122 private: 00123 00124 static void Encode (uint8 *output, 00125 const uint32 *input, 00126 uint32 len); 00127 00128 static void Decode (uint32 *output, 00129 const uint8 *input, 00130 uint32 len); 00131 00132 // F, G, H and I are basic MD5 functions. 00133 00134 static inline uint32 F (uint32 x, 00135 uint32 y, 00136 uint32 z) 00137 { 00138 return (x & y) | (~x & z); 00139 } 00140 00141 static inline uint32 G (uint32 x, 00142 uint32 y, 00143 uint32 z) 00144 { 00145 return (x & z) | (y & ~z); 00146 } 00147 00148 static inline uint32 H (uint32 x, 00149 uint32 y, 00150 uint32 z) 00151 { 00152 return x ^ y ^ z; 00153 } 00154 00155 static inline uint32 I (uint32 x, 00156 uint32 y, 00157 uint32 z) 00158 { 00159 return y ^ (x | ~z); 00160 } 00161 00162 // FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 00163 00164 static inline void FF (uint32 &a, 00165 uint32 b, 00166 uint32 c, 00167 uint32 d, 00168 uint32 x, 00169 uint32 s, 00170 uint32 ac) 00171 { 00172 a += F (b, c, d) + x + ac; 00173 a = (a << s) | (a >> (32 - s)); 00174 a += b; 00175 } 00176 00177 static inline void GG (uint32 &a, 00178 uint32 b, 00179 uint32 c, 00180 uint32 d, 00181 uint32 x, 00182 uint32 s, 00183 uint32 ac) 00184 { 00185 a += G (b, c, d) + x + ac; 00186 a = (a << s) | (a >> (32 - s)); 00187 a += b; 00188 } 00189 00190 static inline void HH (uint32 &a, 00191 uint32 b, 00192 uint32 c, 00193 uint32 d, 00194 uint32 x, 00195 uint32 s, 00196 uint32 ac) 00197 { 00198 a += H (b, c, d) + x + ac; 00199 a = (a << s) | (a >> (32 - s)); 00200 a += b; 00201 } 00202 00203 static inline void II (uint32 &a, 00204 uint32 b, 00205 uint32 c, 00206 uint32 d, 00207 uint32 x, 00208 uint32 s, 00209 uint32 ac) 00210 { 00211 a += I (b, c, d) + x + ac; 00212 a = (a << s) | (a >> (32 - s)); 00213 a += b; 00214 } 00215 00216 static void MD5Transform (uint32 state [4], 00217 const uint8 block [64]); 00218 00219 private: 00220 00221 uint32 state [4]; 00222 00223 uint32 count [2]; 00224 00225 uint8 buffer [64]; 00226 00227 bool final; 00228 00229 dng_fingerprint result; 00230 00231 }; 00232 00233 /*****************************************************************************/ 00234 00235 // A dng_stream based interface to the MD5 printing logic. 00236 00237 class dng_md5_printer_stream : public dng_stream, dng_md5_printer 00238 { 00239 00240 private: 00241 00242 uint64 fNextOffset; 00243 00244 public: 00245 00246 dng_md5_printer_stream () 00247 00248 : fNextOffset (0) 00249 00250 { 00251 } 00252 00253 virtual uint64 DoGetLength () 00254 { 00255 00256 return fNextOffset; 00257 00258 } 00259 00260 virtual void DoRead (void * /* data */, 00261 uint32 /* count */, 00262 uint64 /* offset */) 00263 { 00264 00265 ThrowProgramError (); 00266 00267 } 00268 00269 virtual void DoSetLength (uint64 length) 00270 { 00271 00272 if (length != fNextOffset) 00273 { 00274 ThrowProgramError (); 00275 } 00276 00277 } 00278 00279 virtual void DoWrite (const void *data, 00280 uint32 count2, 00281 uint64 offset) 00282 { 00283 00284 if (offset != fNextOffset) 00285 { 00286 ThrowProgramError (); 00287 } 00288 00289 Process (data, count2); 00290 00291 fNextOffset += count2; 00292 00293 } 00294 00295 const dng_fingerprint & Result () 00296 { 00297 00298 Flush (); 00299 00300 return dng_md5_printer::Result (); 00301 00302 } 00303 00304 }; 00305 00306 /*****************************************************************************/ 00307 00308 #endif 00309 00310 /*****************************************************************************/ | |||
