POK
|
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 Mon Dec 7 15:16:48 2009 00015 */ 00016 00017 00030 #include <protocols/des.h> 00031 #include <libc/string.h> 00032 #include <types.h> 00033 #include "des.h" 00034 00035 #ifdef POK_NEEDS_PROTOCOLS_DES 00036 00037 unsigned char initVector[8] = POK_PROTOCOLS_DES_INIT; 00038 00039 static unsigned char cbc_key [8]= POK_PROTOCOLS_DES_KEY; 00040 00041 int pok_protocols_des_is_init = 0; 00042 00043 void pok_protocols_des_init () 00044 { 00045 if (pok_protocols_des_is_init == 1) 00046 { 00047 return; 00048 } 00049 00050 pok_protocols_des_is_init = 1; 00051 00052 } 00053 00054 void pok_protocols_des_marshall (void* uncrypted_data, pok_size_t uncrypted_size, void* crypted_data, size_t* crypted_size) 00055 { 00056 DES_cblock ivec; 00057 DES_key_schedule schedule; 00058 00059 DES_set_key_checked (&cbc_key, &schedule); 00060 00061 memcpy(ivec,initVector,sizeof(initVector)); 00062 00063 DES_ncbc_encrypt(uncrypted_data, crypted_data, uncrypted_size, &schedule, &ivec, DES_ENCRYPT); 00064 *crypted_size = 8; 00065 } 00066 00067 00068 void pok_protocols_des_unmarshall (void* crypted_data, pok_size_t crypted_size, void* uncrypted_data, size_t* uncrypted_size) 00069 { 00070 DES_cblock ivec; 00071 DES_key_schedule schedule; 00072 00073 DES_set_key_checked (&cbc_key, &schedule); 00074 00075 memcpy(ivec,initVector,sizeof(initVector)); 00076 DES_ncbc_encrypt(crypted_data, uncrypted_data, crypted_size, &schedule, &ivec, DES_DECRYPT); 00077 00078 *uncrypted_size = 8; 00079 } 00080 00081 #endif 00082