| 130 void (*_purple_reserved4)(void); |
130 void (*_purple_reserved4)(void); |
| 131 }; |
131 }; |
| 132 |
132 |
| 133 G_BEGIN_DECLS |
133 G_BEGIN_DECLS |
| 134 |
134 |
| |
135 /*****************************************************************************/ |
| |
136 /** @name PurpleCipher API */ |
| |
137 /*****************************************************************************/ |
| |
138 /*@{*/ |
| |
139 |
| |
140 /** |
| |
141 * Returns the GType for the Cipher object. |
| |
142 */ |
| 135 GType purple_cipher_get_type(void); |
143 GType purple_cipher_get_type(void); |
| 136 |
144 |
| |
145 /** |
| |
146 * Gets a cipher's name |
| |
147 * |
| |
148 * @param cipher The cipher |
| |
149 * |
| |
150 * @return The cipher's name |
| |
151 */ |
| 137 const gchar *purple_cipher_get_name(PurpleCipher *cipher); |
152 const gchar *purple_cipher_get_name(PurpleCipher *cipher); |
| 138 |
153 |
| |
154 /** |
| |
155 * Resets a cipher to it's default value |
| |
156 * @note If you have set an IV you will have to set it after resetting |
| |
157 * |
| |
158 * @param cipher The cipher |
| |
159 */ |
| 139 void purple_cipher_reset(PurpleCipher *cipher); |
160 void purple_cipher_reset(PurpleCipher *cipher); |
| |
161 |
| |
162 /** |
| |
163 * Resets a cipher state to it's default value, but doesn't touch stateless |
| |
164 * configuration. |
| |
165 * |
| |
166 * That means, IV and digest will be wiped out, but keys, ops or salt |
| |
167 * will remain untouched. |
| |
168 * |
| |
169 * @param cipher The cipher |
| |
170 */ |
| 140 void purple_cipher_reset_state(PurpleCipher *cipher); |
171 void purple_cipher_reset_state(PurpleCipher *cipher); |
| |
172 |
| |
173 /** |
| |
174 * Sets the initialization vector for a cipher |
| |
175 * @note This should only be called right after a cipher is created or reset |
| |
176 * |
| |
177 * @param cipher The cipher |
| |
178 * @param iv The initialization vector to set |
| |
179 * @param len The len of the IV |
| |
180 */ |
| 141 void purple_cipher_set_iv(PurpleCipher *cipher, guchar *iv, size_t len); |
181 void purple_cipher_set_iv(PurpleCipher *cipher, guchar *iv, size_t len); |
| 142 |
182 |
| |
183 /** |
| |
184 * Appends data to the cipher context |
| |
185 * |
| |
186 * @param cipher The cipher |
| |
187 * @param data The data to append |
| |
188 * @param len The length of the data |
| |
189 */ |
| 143 void purple_cipher_append(PurpleCipher *cipher, const guchar *data, size_t len); |
190 void purple_cipher_append(PurpleCipher *cipher, const guchar *data, size_t len); |
| |
191 |
| |
192 /** |
| |
193 * Digests a cipher context |
| |
194 * |
| |
195 * @param cipher The cipher |
| |
196 * @param digest The return buffer for the digest |
| |
197 * @param len The length of the buffer |
| |
198 */ |
| 144 gboolean purple_cipher_digest(PurpleCipher *cipher, guchar digest[], size_t len); |
199 gboolean purple_cipher_digest(PurpleCipher *cipher, guchar digest[], size_t len); |
| |
200 |
| |
201 /** |
| |
202 * Converts a guchar digest into a hex string |
| |
203 * |
| |
204 * @param cipher The cipher |
| |
205 * @param digest_s The return buffer for the string digest |
| |
206 * @param len The length of the buffer |
| |
207 */ |
| 145 gboolean purple_cipher_digest_to_str(PurpleCipher *cipher, gchar digest_s[], size_t len); |
208 gboolean purple_cipher_digest_to_str(PurpleCipher *cipher, gchar digest_s[], size_t len); |
| |
209 |
| |
210 /** |
| |
211 * Gets the digest size of a cipher |
| |
212 * |
| |
213 * @param cipher The cipher whose digest size to get |
| |
214 * |
| |
215 * @return The digest size of the cipher |
| |
216 */ |
| 146 size_t purple_cipher_get_digest_size(PurpleCipher *cipher); |
217 size_t purple_cipher_get_digest_size(PurpleCipher *cipher); |
| 147 |
218 |
| |
219 /** |
| |
220 * Encrypts data using the cipher |
| |
221 * |
| |
222 * @param cipher The cipher |
| |
223 * @param input The data to encrypt |
| |
224 * @param in_len The length of the data |
| |
225 * @param output The output buffer |
| |
226 * @param out_size The size of the output buffer |
| |
227 * |
| |
228 * @return A length of data that was outputed or -1, if failed |
| |
229 */ |
| 148 ssize_t purple_cipher_encrypt(PurpleCipher *cipher, const guchar input[], size_t in_len, guchar output[], size_t out_size); |
230 ssize_t purple_cipher_encrypt(PurpleCipher *cipher, const guchar input[], size_t in_len, guchar output[], size_t out_size); |
| |
231 |
| |
232 /** |
| |
233 * Decrypts data using the cipher |
| |
234 * |
| |
235 * @param cipher The cipher |
| |
236 * @param input The data to encrypt |
| |
237 * @param in_len The length of the returned value |
| |
238 * @param output The output buffer |
| |
239 * @param out_size The size of the output buffer |
| |
240 * |
| |
241 * @return A length of data that was outputed or -1, if failed |
| |
242 */ |
| 149 ssize_t purple_cipher_decrypt(PurpleCipher *cipher, const guchar input[], size_t in_len, guchar output[], size_t out_size); |
243 ssize_t purple_cipher_decrypt(PurpleCipher *cipher, const guchar input[], size_t in_len, guchar output[], size_t out_size); |
| 150 |
244 |
| |
245 /** |
| |
246 * Sets the salt on a cipher |
| |
247 * |
| |
248 * @param cipher The cipher whose salt to set |
| |
249 * @param salt The salt |
| |
250 * @param len The length of the salt |
| |
251 */ |
| 151 void purple_cipher_set_salt(PurpleCipher *cipher, const guchar *salt, size_t len); |
252 void purple_cipher_set_salt(PurpleCipher *cipher, const guchar *salt, size_t len); |
| 152 |
253 |
| |
254 /** |
| |
255 * Sets the key on a cipher |
| |
256 * |
| |
257 * @param cipher The cipher whose key to set |
| |
258 * @param key The key |
| |
259 * @param len The size of the key |
| |
260 */ |
| 153 void purple_cipher_set_key(PurpleCipher *cipher, const guchar *key, size_t len); |
261 void purple_cipher_set_key(PurpleCipher *cipher, const guchar *key, size_t len); |
| |
262 |
| |
263 /** |
| |
264 * Gets the size of the key if the cipher supports it |
| |
265 * |
| |
266 * @param cipher The cipher whose key size to get |
| |
267 * |
| |
268 * @return The size of the key |
| |
269 */ |
| 154 size_t purple_cipher_get_key_size(PurpleCipher *cipher); |
270 size_t purple_cipher_get_key_size(PurpleCipher *cipher); |
| 155 |
271 |
| |
272 /** |
| |
273 * Sets the batch mode of a cipher |
| |
274 * |
| |
275 * @param cipher The cipher whose batch mode to set |
| |
276 * @param mode The batch mode under which the cipher should operate |
| |
277 * |
| |
278 */ |
| 156 void purple_cipher_set_batch_mode(PurpleCipher *cipher, PurpleCipherBatchMode mode); |
279 void purple_cipher_set_batch_mode(PurpleCipher *cipher, PurpleCipherBatchMode mode); |
| |
280 |
| |
281 /** |
| |
282 * Gets the batch mode of a cipher |
| |
283 * |
| |
284 * @param cipher The cipher whose batch mode to get |
| |
285 * |
| |
286 * @return The batch mode under which the cipher is operating |
| |
287 */ |
| 157 PurpleCipherBatchMode purple_cipher_get_batch_mode(PurpleCipher *cipher); |
288 PurpleCipherBatchMode purple_cipher_get_batch_mode(PurpleCipher *cipher); |
| 158 |
289 |
| |
290 /** |
| |
291 * Gets the block size of a cipher |
| |
292 * |
| |
293 * @param cipher The cipher whose block size to get |
| |
294 * |
| |
295 * @return The block size of the cipher |
| |
296 */ |
| 159 size_t purple_cipher_get_block_size(PurpleCipher *cipher); |
297 size_t purple_cipher_get_block_size(PurpleCipher *cipher); |
| 160 |
298 |
| |
299 /*@}*/ |
| |
300 |
| 161 G_END_DECLS |
301 G_END_DECLS |
| 162 |
302 |
| 163 #endif /* PURPLE_CIPHER_H */ |
303 #endif /* PURPLE_CIPHER_H */ |