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
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 } F;
00155
00161 struct
00162 {
00163 storage_type operator()(const storage_type &x,
00164 const storage_type &y,
00165 const storage_type &z) const
00166 {
00167 return x & z | y & ~z;
00168 }
00169 } G;
00170
00176 struct
00177 {
00178 storage_type operator()(const storage_type &x,
00179 const storage_type &y,
00180 const storage_type &z) const
00181 {
00182 return x ^ y ^ z;
00183 }
00184 } H;
00185
00191 struct
00192 {
00193 storage_type operator()(const storage_type &x,
00194 const storage_type &y,
00195 const storage_type &z) const
00196 {
00197 return y ^ (x | ~z);
00198 }
00199 } I;
00200 };
00201
00202 #include <oln/utils/md5.hxx>
00203
00213 template <class I>
00214 key md5(const oln::abstract::non_vectorial_image<I> &im);
00215
00225 template <class I>
00226 key md5(const oln::abstract::vectorial_image<I> &im);
00227
00228 }
00229 }
00230 #endif // !OLENA_OLN_UTILS_MD5_HH