POK
des.c
Go to the documentation of this file.
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 Mon Dec 7 15:16:48 2009
15  */
16 
17 
30 #include <protocols/des.h>
31 #include <libc/string.h>
32 #include <types.h>
33 #include "des.h"
34 
35 #ifdef POK_NEEDS_PROTOCOLS_DES
36 
37 unsigned char initVector[8] = POK_PROTOCOLS_DES_INIT;
38 
39 static unsigned char cbc_key [8]= POK_PROTOCOLS_DES_KEY;
40 
41 int pok_protocols_des_is_init = 0;
42 
43 void pok_protocols_des_init ()
44 {
45  if (pok_protocols_des_is_init == 1)
46  {
47  return;
48  }
49 
50  pok_protocols_des_is_init = 1;
51 
52 }
53 
54 void pok_protocols_des_marshall (void* uncrypted_data, pok_size_t uncrypted_size, void* crypted_data, size_t* crypted_size)
55 {
56  DES_cblock ivec;
57  DES_key_schedule schedule;
58 
59  DES_set_key_checked (&cbc_key, &schedule);
60 
61  memcpy(ivec,initVector,sizeof(initVector));
62 
63  DES_ncbc_encrypt(uncrypted_data, crypted_data, uncrypted_size, &schedule, &ivec, DES_ENCRYPT);
64  *crypted_size = 8;
65 }
66 
67 
68 void pok_protocols_des_unmarshall (void* crypted_data, pok_size_t crypted_size, void* uncrypted_data, size_t* uncrypted_size)
69 {
70  DES_cblock ivec;
71  DES_key_schedule schedule;
72 
73  DES_set_key_checked (&cbc_key, &schedule);
74 
75  memcpy(ivec,initVector,sizeof(initVector));
76  DES_ncbc_encrypt(crypted_data, uncrypted_data, crypted_size, &schedule, &ivec, DES_DECRYPT);
77 
78  *uncrypted_size = 8;
79 }
80 
81 #endif
82