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, but
00009 // 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, 59  Temple Place - Suite 330, Boston,
00016 // MA 02111-1307, 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
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       }                         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   } // !utils
00229 } // !oln
00230 #endif // !OLENA_OLN_UTILS_MD5_HH

Generated on Thu Apr 15 20:13:13 2004 for Olena by doxygen 1.3.6-20040222