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/workarea/stern/camera_raw/dng_sdk/source/dng_fingerprint.h#11 $ */ 00010 /* $DateTime: 2008/04/01 11:33:37 $ */ 00011 /* $Change: 439955 $ */ 00012 /* $Author: stern $ */ 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 #include <cstring> 00030 00031 /*****************************************************************************/ 00032 00034 00035 class dng_fingerprint 00036 { 00037 00038 public: 00039 00040 uint8 data [16]; 00041 00042 public: 00043 00044 dng_fingerprint (); 00045 00047 00048 bool IsNull () const; 00049 00051 00052 bool IsValid () const 00053 { 00054 return !IsNull (); 00055 } 00056 00058 00059 void Clear () 00060 { 00061 *this = dng_fingerprint (); 00062 } 00063 00065 00066 bool operator== (const dng_fingerprint &print) const; 00067 00069 00070 bool operator!= (const dng_fingerprint &print) const 00071 { 00072 return !(*this == print); 00073 } 00074 00076 00077 uint32 Collapse32 () const; 00078 00079 }; 00080 00081 /******************************************************************************/ 00082 00083 // Derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm 00084 00085 // Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All 00086 // rights reserved. 00087 // 00088 // License to copy and use this software is granted provided that it 00089 // is identified as the "RSA Data Security, Inc. MD5 Message-Digest 00090 // Algorithm" in all material mentioning or referencing this software 00091 // or this function. 00092 // 00093 // License is also granted to make and use derivative works provided 00094 // that such works are identified as "derived from the RSA Data 00095 // Security, Inc. MD5 Message-Digest Algorithm" in all material 00096 // mentioning or referencing the derived work. 00097 // 00098 // RSA Data Security, Inc. makes no representations concerning either 00099 // the merchantability of this software or the suitability of this 00100 // software for any particular purpose. It is provided "as is" 00101 // without express or implied warranty of any kind. 00102 // 00103 // These notices must be retained in any copies of any part of this 00104 // documentation and/or software. 00105 00106 class dng_md5_printer 00107 { 00108 00109 public: 00110 00111 dng_md5_printer (); 00112 00113 virtual ~dng_md5_printer () 00114 { 00115 } 00116 00117 void Reset (); 00118 00119 void Process (const void *data, 00120 uint32 inputLen); 00121 00122 void Process (const char *text) 00123 { 00124 00125 Process (text, (uint32)strlen (text)); 00126 00127 } 00128 00129 const dng_fingerprint & Result (); 00130 00131 private: 00132 00133 static void Encode (uint8 *output, 00134 const uint32 *input, 00135 uint32 len); 00136 00137 static void Decode (uint32 *output, 00138 const uint8 *input, 00139 uint32 len); 00140 00141 // F, G, H and I are basic MD5 functions. 00142 00143 static inline uint32 F (uint32 x, 00144 uint32 y, 00145 uint32 z) 00146 { 00147 return (x & y) | (~x & z); 00148 } 00149 00150 static inline uint32 G (uint32 x, 00151 uint32 y, 00152 uint32 z) 00153 { 00154 return (x & z) | (y & ~z); 00155 } 00156 00157 static inline uint32 H (uint32 x, 00158 uint32 y, 00159 uint32 z) 00160 { 00161 return x ^ y ^ z; 00162 } 00163 00164 static inline uint32 I (uint32 x, 00165 uint32 y, 00166 uint32 z) 00167 { 00168 return y ^ (x | ~z); 00169 } 00170 00171 // FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. 00172 00173 static inline void FF (uint32 &a, 00174 uint32 b, 00175 uint32 c, 00176 uint32 d, 00177 uint32 x, 00178 uint32 s, 00179 uint32 ac) 00180 { 00181 a += F (b, c, d) + x + ac; 00182 a = (a << s) | (a >> (32 - s)); 00183 a += b; 00184 } 00185 00186 static inline void GG (uint32 &a, 00187 uint32 b, 00188 uint32 c, 00189 uint32 d, 00190 uint32 x, 00191 uint32 s, 00192 uint32 ac) 00193 { 00194 a += G (b, c, d) + x + ac; 00195 a = (a << s) | (a >> (32 - s)); 00196 a += b; 00197 } 00198 00199 static inline void HH (uint32 &a, 00200 uint32 b, 00201 uint32 c, 00202 uint32 d, 00203 uint32 x, 00204 uint32 s, 00205 uint32 ac) 00206 { 00207 a += H (b, c, d) + x + ac; 00208 a = (a << s) | (a >> (32 - s)); 00209 a += b; 00210 } 00211 00212 static inline void II (uint32 &a, 00213 uint32 b, 00214 uint32 c, 00215 uint32 d, 00216 uint32 x, 00217 uint32 s, 00218 uint32 ac) 00219 { 00220 a += I (b, c, d) + x + ac; 00221 a = (a << s) | (a >> (32 - s)); 00222 a += b; 00223 } 00224 00225 static void MD5Transform (uint32 state [4], 00226 const uint8 block [64]); 00227 00228 private: 00229 00230 uint32 state [4]; 00231 00232 uint32 count [2]; 00233 00234 uint8 buffer [64]; 00235 00236 bool final; 00237 00238 dng_fingerprint result; 00239 00240 }; 00241 00242 /*****************************************************************************/ 00243 00244 // A dng_stream based interface to the MD5 printing logic. 00245 00246 class dng_md5_printer_stream : public dng_stream, dng_md5_printer 00247 { 00248 00249 private: 00250 00251 uint64 fNextOffset; 00252 00253 public: 00254 00255 dng_md5_printer_stream () 00256 00257 : fNextOffset (0) 00258 00259 { 00260 } 00261 00262 virtual uint64 DoGetLength () 00263 { 00264 00265 return fNextOffset; 00266 00267 } 00268 00269 virtual void DoRead (void * /* data */, 00270 uint32 /* count */, 00271 uint64 /* offset */) 00272 { 00273 00274 ThrowProgramError (); 00275 00276 } 00277 00278 virtual void DoSetLength (uint64 length) 00279 { 00280 00281 if (length != fNextOffset) 00282 { 00283 ThrowProgramError (); 00284 } 00285 00286 } 00287 00288 virtual void DoWrite (const void *data, 00289 uint32 count2, 00290 uint64 offset) 00291 { 00292 00293 if (offset != fNextOffset) 00294 { 00295 ThrowProgramError (); 00296 } 00297 00298 Process (data, count2); 00299 00300 fNextOffset += count2; 00301 00302 } 00303 00304 const dng_fingerprint & Result () 00305 { 00306 00307 Flush (); 00308 00309 return dng_md5_printer::Result (); 00310 00311 } 00312 00313 }; 00314 00315 /*****************************************************************************/ 00316 00317 #endif 00318 00319 /*****************************************************************************/ |