md5.hh

00001 // Copyright (C) 2004  EPITA Research and Development Laboratory
00002 //
00003 // This file is part of the Olena Library.  This library is free
00004 // software; you can redistribute it and/or modify it under the terms
00005 // of the GNU General Public License version 2 as published by the
00006 // Free Software Foundation.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this library; see the file COPYING.  If not, write to
00015 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016 // Boston, MA 02110-1301, USA.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software library without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to
00022 // produce an executable, this file does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public
00024 // License.  This exception does not however invalidate any other
00025 // reasons why the executable file might be covered by the GNU General
00026 // Public License.
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           //      return z ^ (x & (y ^ z));
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   } // !utils
00238 } // !oln
00239 #endif // !OLENA_OLN_UTILS_MD5_HH

Generated on Tue Feb 20 20:20:07 2007 for Olena by  doxygen 1.5.1