/[mldonkey]/mldonkey/src/networks/fasttrack/fst_crypt_ml.c
ViewVC logotype

Diff of /mldonkey/src/networks/fasttrack/fst_crypt_ml.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by simon_mld, Fri Nov 21 23:17:58 2003 UTC revision 1.6 by mldonkey, Mon Nov 1 11:23:01 2004 UTC
# Line 39  value ml_apply_cipher(value cipher_v, va Line 39  value ml_apply_cipher(value cipher_v, va
39    return Val_unit;    return Val_unit;
40  }  }
41    
42  value ml_init_cipher(value cipher_v, value seed_v, value encode_v)  value ml_init_cipher(value cipher_v)
43  {  {
44    FSTCipher* cipher = (FSTCipher*) cipher_v;    FSTCipher* cipher = (FSTCipher*) cipher_v;
45    unsigned int seed = Int32_val(seed_v);    fst_cipher_init(cipher, cipher->seed, cipher->enc_type);
   unsigned int encode = Int_val(encode_v);  
   
   fst_cipher_init(cipher, seed, encode);  
46    
47    return Val_unit;    return Val_unit;
48  }  }
# Line 64  value ml_set_cipher(value cipher_v, valu Line 61  value ml_set_cipher(value cipher_v, valu
61    return Val_unit;    return Val_unit;
62  }  }
63    
64  value ml_cipher_packet_get(value s_v, value pos_v,  value ml_cipher_packet_get(value s_v, value pos_v, value in_cipher_v)
   value in_cipher_v, value out_cipher_v)  
65  {  {
66    FSTCipher* in_cipher = (FSTCipher*) in_cipher_v;    FSTCipher* in_cipher = (FSTCipher*) in_cipher_v;
   FSTCipher* out_cipher = (FSTCipher*) out_cipher_v;  
67    char *s = String_val(s_v);    char *s = String_val(s_v);
68    int pos = Int_val(pos_v);    int pos = Int_val(pos_v);
69    unsigned int seed;    unsigned int seed;
# Line 84  value ml_cipher_packet_get(value s_v, va Line 79  value ml_cipher_packet_get(value s_v, va
79    enc_type = htonl (((unsigned int*)(s+pos+4))[0]);    enc_type = htonl (((unsigned int*)(s+pos+4))[0]);
80    enc_type = fst_cipher_decode_enc_type (seed, enc_type);    enc_type = fst_cipher_decode_enc_type (seed, enc_type);
81    
82      in_cipher->seed = seed;
83      in_cipher->enc_type = enc_type;
84  /*  printf("in seed:%X enc_type: %X\n", seed, out_cipher->enc_type);  */  /*  printf("in seed:%X enc_type: %X\n", seed, out_cipher->enc_type);  */
85    
86    if(enc_type > 0x29)    failwith ("ERROR: unsupported encryption");  /*  if(enc_type > 0x29)    failwith ("ERROR: unsupported encryption"); */
87    
88      return Val_unit;
89    }
90    
91    value ml_xor_ciphers(value out_cipher_v, value in_cipher_v){
92      FSTCipher* in_cipher = (FSTCipher*) in_cipher_v;
93      FSTCipher* out_cipher = (FSTCipher*) out_cipher_v;
94    
95      out_cipher->seed ^= in_cipher->seed; /* xor send cipher with received seed */
96    
97      return Val_unit;
98    }
99    
100    out_cipher->seed ^= seed; /* xor send cipher with received seed */  value ml_xor_ciphers2(value out_cipher_v, value in_cipher_v){
101      FSTCipher* in_cipher = (FSTCipher*) in_cipher_v;
102      FSTCipher* out_cipher = (FSTCipher*) out_cipher_v;
103      unsigned int seed = out_cipher->seed;
104    
105      out_cipher->seed ^= in_cipher->seed; /* xor send cipher with received seed */
106      in_cipher->seed ^= seed;
107    fst_cipher_init(out_cipher, out_cipher->seed, out_cipher->enc_type);    fst_cipher_init(out_cipher, out_cipher->seed, out_cipher->enc_type);
   fst_cipher_init(in_cipher, seed, enc_type);  
108    
109    return Val_unit;    return Val_unit;
110  }  }
111    
112    
113  value ml_cipher_packet_set(value cipher_v, value s_v, value pos_v)  value ml_cipher_packet_set(value cipher_v, value s_v, value pos_v)
114  {  {
115    FSTCipher* cipher = (FSTCipher*) cipher_v;    FSTCipher* cipher = (FSTCipher*) cipher_v;
116    char *s = String_val(s_v);    char *s = String_val(s_v);
117    int pos = Int_val(pos_v);    int pos = Int_val(pos_v);
118    
119  /*    ((unsigned int*)(s+pos))[0] = htonl(cipher->seed);
120    printf("ml_cipher_packet_set %X seed:%X enc_type:%X\n", cipher,    ((unsigned int*)(s+pos+4))[0] = htonl(
121      cipher->seed, cipher->enc_type      fst_cipher_encode_enc_type(cipher->seed, cipher->enc_type));
122    );  
123  */    return Val_unit;
124    }
125    
126    value ml_cipher_enc_type(value cipher_v)
127    {
128      FSTCipher* cipher = (FSTCipher*) cipher_v;
129    
130  /* in OCAML: "\250\000\182\043" */    return Val_int(cipher->enc_type);
131    /* ((unsigned int*)(s+pos))[0] = 0x02BB600FA; random number? */  }
132    s[pos] = 250;  
133    s[pos+1] = 0;  value ml_cipher_packet_set_xored(value cipher_v, value s_v, value pos_v, value xor_cipher_v)
134    s[pos+2] = 182;  {
135    s[pos+3] = 43;    FSTCipher* cipher = (FSTCipher*) cipher_v;
136    ((unsigned int*)(s+pos+4))[0] = htonl(cipher->seed);    FSTCipher* xor_cipher = (FSTCipher*) xor_cipher_v;
137    ((unsigned int*)(s+pos+8))[0] = htonl(    char *s = String_val(s_v);
138      int pos = Int_val(pos_v);
139      unsigned int seed = cipher->seed;
140    
141      seed ^= xor_cipher->seed;
142      ((unsigned int*)(s+pos))[0] = htonl(seed);
143      ((unsigned int*)(s+pos+4))[0] = htonl(
144      fst_cipher_encode_enc_type(cipher->seed, cipher->enc_type));      fst_cipher_encode_enc_type(cipher->seed, cipher->enc_type));
145    
146    return Val_unit;    return Val_unit;
147  }  }
148    
149    
150  value ml_cipher_free(value cipher_v)  value ml_cipher_free(value cipher_v)
151  {  {
152    FSTCipher* cipher = (FSTCipher*) cipher_v;    FSTCipher* cipher = (FSTCipher*) cipher_v;

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26