6 * Copyright (C) 2010 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "sipe-crypt.h"
28 void sipe_crypt_des(const guchar
*key
,
29 const guchar
*plaintext
, gsize plaintext_length
,
30 guchar
*encrypted_text
)
33 PurpleCipherContext
*context
= purple_cipher_context_new_by_name("des", NULL
);
34 purple_cipher_context_set_key(context
, key
);
35 purple_cipher_context_encrypt(context
, plaintext
, plaintext_length
, encrypted_text
, &dummy
);
36 purple_cipher_context_destroy(context
);
39 void sipe_crypt_rc4(const guchar
*key
, gsize key_length
,
40 const guchar
*plaintext
, gsize plaintext_length
,
41 guchar
*encrypted_text
)
44 PurpleCipherContext
*context
= purple_cipher_context_new_by_name("rc4", NULL
);
45 purple_cipher_context_set_option(context
, "key_len", (gpointer
)key_length
);
46 purple_cipher_context_set_key(context
, key
);
47 purple_cipher_context_encrypt(context
, plaintext
, plaintext_length
, encrypted_text
, &dummy
);
48 purple_cipher_context_destroy(context
);
51 /* Stream RC4 cipher for file transfer */
52 gpointer
sipe_crypt_ft_start(const guchar
*key
)
54 PurpleCipherContext
*context
= purple_cipher_context_new_by_name("rc4", NULL
);
55 /* only use first 16 characters of the key */
56 purple_cipher_context_set_option(context
, "key_len", (gpointer
)16);
57 purple_cipher_context_set_key(context
, key
);
61 void sipe_crypt_ft_stream(gpointer context
,
62 const guchar
*in
, gsize length
,
65 purple_cipher_context_encrypt(context
, in
, length
, out
, NULL
);
68 void sipe_crypt_ft_destroy(gpointer context
)
70 purple_cipher_context_destroy(context
);