Bonjour à tous,

dans mon programme j'ai 2 fonctions

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
 
void file_utils_lion_encrypt(char *in, char *out, size_t blklen, const char *key) 
//et
void file_utils_lion_decrypt(char *in, char *out, size_t blklen, const char *key)
ces 2 fonctions servent à chiffrer/déchiffrer les données, in contient les données à chiffrer/déchiffrer , out recoit le resultat après chiffrement/déchiffrement, blklen est la taille du bloc à chiffrer/déchiffrer et key est la clé de chiffrement c'est cette même clé qui me cause un problème.

quand j'utilise une constante chaine de caractères comme ceci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
 
const char *macle = "chiffrement";
file_utils_lion_encrypt(plaintext, ciphertext,block_size, macle);
//et puis
file_utils_lion_decrypt( ciphertext,plaintext,block_size, macle);
après les données ne sont plus les même.
mais quand je passe à ces deux fonctions une constante macro( #define) comme ca
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
#define macroCle "chiffrement" 
file_utils_lion_encrypt(plaintext, ciphertext,block_size, macroCle);
//et puis
file_utils_lion_decrypt( ciphertext,plaintext,block_size, macroCle);
je retrouve mes données comme avant le dechiffrement;

quelqu'un comprend pour quoi ? car moi je suis largué.
merci.
pour plus d'info voici l'implèmentation de ces fonctions


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 
 
#define HASH_SZ   20
#define NUM_WORDS (HASH_SZ / sizeof(int))
 
 
void file_utils_lion_encrypt(char *in, char *out, size_t blklen, const char *key) 
{
	int     i, tmp[NUM_WORDS];
  	RC4_KEY k;
 
  	/* Round 1: R = R ^ RC4(L ^ K1) */
  	for (i = 0;  i < NUM_WORDS;  i++)
    	tmp[i] = ((int *)in)[i] ^ ((int *)key)[i];
 
	RC4_set_key(&k, HASH_SZ, (char *)tmp);
  	RC4(&k, blklen - HASH_SZ, in + HASH_SZ, out + HASH_SZ);
 
  	/* Round 2: L = L ^ SHA1(R) */
  	SHA1(out + HASH_SZ, blklen - HASH_SZ, out);
  	for (i = 0;  i < NUM_WORDS; i++)
    	((int *)out)[i] ^= ((int *)in)[i];
 
  	/* Round 3: R = R ^ RC4(L ^ K2) */
  	for (i = 0;  i < NUM_WORDS;  i++)
    	tmp[i] = ((int *)out)[i] ^ ((int *)key)[i + NUM_WORDS];
  	RC4_set_key(&k, HASH_SZ, (char *)tmp);
  	RC4(&k, blklen - HASH_SZ, out + HASH_SZ, out + HASH_SZ);
}
 
void file_utils_lion_decrypt(char *in, char *out, size_t blklen, const char *key)
{
  	int     i, tmp[NUM_WORDS];
  	RC4_KEY k;
 
  	for (i = 0;  i < NUM_WORDS;  i++)
    	tmp[i] = ((int *)in)[i] ^ ((int *)key)[i + NUM_WORDS];
  	RC4_set_key(&k, HASH_SZ, (char *)tmp);
  	RC4(&k, blklen - HASH_SZ, in + HASH_SZ, out + HASH_SZ);
 
  	SHA1(out + HASH_SZ, blklen - HASH_SZ, out);
  	for (i = 0;  i < NUM_WORDS;  i++) 
	{
    	((int *)out)[i] ^= ((int *)in)[i];
    	tmp[i] = ((int *)out)[i] ^ ((int *)key)[i];
  	}
  	RC4_set_key(&k, HASH_SZ, (char *)tmp);
  	RC4(&k, blklen - HASH_SZ, out + HASH_SZ, out + HASH_SZ);
}