POK
/home/jaouen/pok_official/pok/trunk/libpok/protocols/blowfish/blowfish.c
00001 /*
00002  *                               POK header
00003  * 
00004  * The following file is a part of the POK project. Any modification should
00005  * made according to the POK licence. You CANNOT use this file or a part of
00006  * this file is this part of a file for your own project
00007  *
00008  * For more information on the POK licence, please see our LICENCE FILE
00009  *
00010  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
00011  *
00012  *                                      Copyright (c) 2007-2009 POK team 
00013  *
00014  * Created by julien on Fri Dec 11 16:32:31 2009 
00015  */
00016 
00021 #ifdef POK_NEEDS_PROTOCOLS_BLOWFISH
00022 
00023 #include "blowfish.h"
00024 
00025 #include <types.h>
00026 #include <libc/string.h>
00027 #include <libc/stdio.h>
00028 
00029 #include <protocols/blowfish.h>
00030 
00031 static unsigned char cbc_key [16]=POK_BLOWFISH_KEY;
00032 
00033 /*
00034 static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
00035 #define MYIV {0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
00036 */
00037 
00038 
00039 
00040 void pok_protocols_blowfish_marshall (void* uncrypted_data, size_t uncrypted_size, void* crypted_data, size_t* crypted_size)
00041 {
00042    (void) uncrypted_size;
00043    BF_KEY key;
00044 /*   unsigned char iv[8] = POK_BLOWFISH_INIT; */
00045    BF_set_key(&key,16,cbc_key);
00046 
00047 /*   memcpy(iv,cbc_iv,8); */
00048    BF_ecb_encrypt(uncrypted_data,crypted_data,&key,BF_ENCRYPT);
00049 
00050    *crypted_size = 8;
00051 }
00052 
00053 void pok_protocols_blowfish_unmarshall (void* crypted_data, size_t crypted_size, void* uncrypted_data, size_t* uncrypted_size)
00054 {
00055 /*   unsigned char iv[8] = POK_BLOWFISH_INIT; */
00056    (void) crypted_size;
00057 
00058    BF_KEY key;
00059 
00060    BF_set_key(&key,16,cbc_key);
00061 
00062 /*   memcpy (iv,cbc_iv,8); */
00063 
00064    BF_ecb_encrypt(crypted_data,uncrypted_data, &key,BF_DECRYPT);
00065 
00066    *uncrypted_size = 8;
00067 }
00068 
00069 #endif