POK
ceasar.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 Mon Dec 7 15:16:48 2009
15  */
16 
24 #include <protocols/ceasar.h>
25 #include <libc/string.h>
26 #include <types.h>
27 
28 #ifdef POK_NEEDS_PROTOCOLS_CEASAR
29 
34 void pok_protocols_ceasar_marshall (void* uncrypted_data, pok_size_t uncrypted_size, void* crypted_data, size_t* crypted_size)
35 {
36  uint8_t* uncrypted;
37  uint8_t* crypted;
38  size_t tmp;
39 
40  uncrypted = (uint8_t*) uncrypted_data;
41  crypted = (uint8_t*) crypted_data;
42 
43  for (tmp = 0 ; tmp < uncrypted_size ; tmp++)
44  {
45  crypted[tmp] = (uncrypted[tmp] + 4) % 255;
46  }
47 
48  *crypted_size = uncrypted_size;
49 }
50 
51 
56 void pok_protocols_ceasar_unmarshall (void* crypted_data, pok_size_t crypted_size, void* uncrypted_data, size_t* uncrypted_size)
57 {
58  uint8_t* uncrypted;
59  uint8_t* crypted;
60  size_t tmp;
61 
62  uncrypted = (uint8_t*) uncrypted_data;
63  crypted = (uint8_t*) crypted_data;
64 
65  for (tmp = 0 ; tmp < crypted_size ; tmp++)
66  {
67  uncrypted[tmp] = (crypted[tmp] - 4) % 255;
68  }
69 
70  *uncrypted_size = crypted_size;
71 }
72 
73 #endif
74