POK
blowfish.c
1 /*
2  * POK header
3  *
4  * The following file is a part of the POK project. Any modification should
5  * made according to the POK licence. You CANNOT use this file or a part of
6  * this file is this part of a file for your own project
7  *
8  * For more information on the POK licence, please see our LICENCE FILE
9  *
10  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
11  *
12  * Copyright (c) 2007-2009 POK team
13  *
14  * Created by julien on Fri Dec 11 16:32:31 2009
15  */
16 
21 #ifdef POK_NEEDS_PROTOCOLS_BLOWFISH
22 
23 #include "blowfish.h"
24 
25 #include <types.h>
26 #include <libc/string.h>
27 #include <libc/stdio.h>
28 
29 #include <protocols/blowfish.h>
30 
31 static unsigned char cbc_key [16]=POK_BLOWFISH_KEY;
32 
33 /*
34 static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
35 #define MYIV {0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
36 */
37 
38 
39 
40 void pok_protocols_blowfish_marshall (void* uncrypted_data, size_t uncrypted_size, void* crypted_data, size_t* crypted_size)
41 {
42  (void) uncrypted_size;
43  BF_KEY key;
44 /* unsigned char iv[8] = POK_BLOWFISH_INIT; */
45  BF_set_key(&key,16,cbc_key);
46 
47 /* memcpy(iv,cbc_iv,8); */
48  BF_ecb_encrypt(uncrypted_data,crypted_data,&key,BF_ENCRYPT);
49 
50  *crypted_size = 8;
51 }
52 
53 void pok_protocols_blowfish_unmarshall (void* crypted_data, size_t crypted_size, void* uncrypted_data, size_t* uncrypted_size)
54 {
55 /* unsigned char iv[8] = POK_BLOWFISH_INIT; */
56  (void) crypted_size;
57 
58  BF_KEY key;
59 
60  BF_set_key(&key,16,cbc_key);
61 
62 /* memcpy (iv,cbc_iv,8); */
63 
64  BF_ecb_encrypt(crypted_data,uncrypted_data, &key,BF_DECRYPT);
65 
66  *uncrypted_size = 8;
67 }
68 
69 #endif