00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef OLENA_OLN_UTILS_MD5_HH
00029 # define OLENA_OLN_UTILS_MD5_HH
00030
00031 # include <ntg/all.hh>
00032 # include <vector>
00033
00034 # include <oln/core/abstract/image_with_type_with_dim.hh>
00035
00036 # include <oln/utils/key.hh>
00037 # include <oln/utils/buffer.hh>
00038
00039 namespace oln {
00040 namespace utils {
00044 class MD5
00045 {
00046 public:
00047 typedef ntg::int_u32 value_type;
00048 typedef ntg_storage_type_(value_type) storage_type;
00049
00057 explicit MD5(buffer b);
00058
00062 key execute();
00063
00069 key gen_key();
00070
00071 protected:
00075 void sav();
00076
00080 void round1();
00081
00085 void round2();
00086
00090 void round3();
00091
00095 void round4();
00096
00100 void step();
00101
00105 template <class Fun>
00106 void sub_step(const Fun &fun,
00107 storage_type &a,
00108 const storage_type &b,
00109 const storage_type &c,
00110 const storage_type &d,
00111 unsigned k,
00112 unsigned s,
00113 unsigned i);
00114
00122 void gen_sub_key(std::vector<key::value_type> &v,
00123 storage_type x,
00124 unsigned base);
00125
00126
00127 buffer buffer_;
00128 std::vector<storage_type> X;
00129 std::vector<storage_type> T;
00130 unsigned current_;
00131 storage_type aa;
00132 storage_type bb;
00133 storage_type cc;
00134 storage_type dd;
00135 storage_type a;
00136 storage_type b;
00137 storage_type c;
00138 storage_type d;
00139
00145 struct F_
00146 {
00147 storage_type operator()(const storage_type &x,
00148 const storage_type &y,
00149 const storage_type &z) const
00150 {
00151
00152 return x & y | ~x & z;
00153 }
00154 };
00155
00156 F_ F;
00157
00163 struct G_
00164 {
00165 storage_type operator()(const storage_type &x,
00166 const storage_type &y,
00167 const storage_type &z) const
00168 {
00169 return x & z | y & ~z;
00170 }
00171 };
00172
00173 G_ G;
00174
00180 struct H_
00181 {
00182 storage_type operator()(const storage_type &x,
00183 const storage_type &y,
00184 const storage_type &z) const
00185 {
00186 return x ^ y ^ z;
00187 }
00188 };
00189
00190 H_ H;
00191
00197 struct I_
00198 {
00199 storage_type operator()(const storage_type &x,
00200 const storage_type &y,
00201 const storage_type &z) const
00202 {
00203 return y ^ (x | ~z);
00204 }
00205 };
00206
00207 I_ I;
00208
00209 };
00210
00211 #include <oln/utils/md5.hxx>
00212
00222 template <class I>
00223 key md5(const oln::abstract::non_vectorial_image<I> &im);
00224
00234 template <class I>
00235 key md5(const oln::abstract::vectorial_image<I> &im);
00236
00237 }
00238 }
00239 #endif // !OLENA_OLN_UTILS_MD5_HH