"Fossies" - the Fresh Open Source Software Archive

Member "libmcrypt-2.5.8/modules/modes/ecb.c" (15 Jan 2003, 3003 Bytes) of package /linux/privat/old/libmcrypt-2.5.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ecb.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) 1998,1999,2000,2001 Nikos Mavroyanopoulos
    3  * 
    4  * This library is free software; you can redistribute it and/or modify it 
    5  * under the terms of the GNU Library General Public License as published 
    6  * by the Free Software Foundation; either version 2 of the License, or 
    7  * (at your option) any later version.
    8  *
    9  * This library is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   12  * Library General Public License for more details.
   13  *
   14  * You should have received a copy of the GNU Library General Public
   15  * License along with this library; if not, write to the
   16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   17  * Boston, MA 02111-1307, USA.
   18  */
   19 
   20 #include <libdefs.h>
   21 #include <mcrypt_modules.h>
   22 
   23 /* EBC MODE */
   24 
   25 #define _mcrypt_set_state ecb_LTX__mcrypt_set_state
   26 #define _mcrypt_get_state ecb_LTX__mcrypt_get_state
   27 #define _init_mcrypt ecb_LTX__init_mcrypt
   28 #define _end_mcrypt ecb_LTX__end_mcrypt
   29 #define _mcrypt ecb_LTX__mcrypt
   30 #define _mdecrypt ecb_LTX__mdecrypt
   31 #define _has_iv ecb_LTX__has_iv
   32 #define _is_block_mode ecb_LTX__is_block_mode
   33 #define _is_block_algorithm_mode ecb_LTX__is_block_algorithm_mode
   34 #define _mcrypt_get_modes_name ecb_LTX__mcrypt_get_modes_name
   35 #define _mcrypt_mode_get_size ecb_LTX__mcrypt_mode_get_size
   36 #define _mcrypt_mode_version ecb_LTX__mcrypt_mode_version
   37 
   38 int _init_mcrypt( void* ign, void *key, int lenofkey, void *IV, int size)
   39 {
   40     return 0;
   41 
   42 }
   43 
   44 int _mcrypt_set_state( void* buf, void *IV, int size) { return -1; }
   45 int _mcrypt_get_state( void* buf, void *IV, int *size) { return -1; }
   46 
   47 int _end_mcrypt (void* buf) {return 0;}
   48 
   49 int _mcrypt( void* ign, void *plaintext, int len, int blocksize, void* akey, void (*func)(void*,void*), void (*func2)(void*,void*))
   50 {
   51     int j;
   52     char *plain = plaintext;
   53     void (*_mcrypt_block_encrypt) (void *, void *);
   54 
   55     _mcrypt_block_encrypt = func;
   56     
   57     for (j = 0; j < len / blocksize; j++) {
   58         _mcrypt_block_encrypt(akey, &plain[j * blocksize]);
   59     }
   60     if (j==0 && len!=0) return -1; /* no blocks were encrypted */
   61     return 0;
   62 }
   63 
   64 
   65 
   66 int _mdecrypt( void* ign, void *ciphertext, int len, int blocksize, void* akey, void (*func)(void*,void*), void (*func2)(void*,void*))
   67 {
   68     int j;
   69     char *cipher = ciphertext;
   70     void (*_mcrypt_block_decrypt) (void *, void *);
   71 
   72     _mcrypt_block_decrypt = func2;
   73     
   74     for (j = 0; j < len / blocksize; j++) {
   75         _mcrypt_block_decrypt(akey, &cipher[j * blocksize]);
   76     }
   77     if (j==0 && len!=0) return -1; /* no blocks were encrypted */
   78     return 0;
   79 }
   80 
   81 int _has_iv() { return 0; }
   82 int _is_block_mode() { return 1; }
   83 int _is_block_algorithm_mode() { return 1; }
   84 const char *_mcrypt_get_modes_name() { return "ECB";}
   85 int _mcrypt_mode_get_size () {return 0;}
   86 
   87 word32 _mcrypt_mode_version() {
   88     return 20010801;
   89 }
   90 
   91 #ifdef WIN32
   92 # ifdef USE_LTDL
   93 WIN32DLL_DEFINE int main (void)
   94 {
   95        /* empty main function to avoid linker error (see cygwin FAQ) */
   96 }
   97 # endif
   98 #endif