Mercurial > pidgin
comparison libpurple/ciphers/sha256.c @ 31221:2b041e31b825
Removed the "new" api I added by moving it to ciphers/gchecksum.c. Moved the gchecksum implements into gchecksum.c as a preproc macro, removed them from their individual files
author | Gary Kramlich <grim@reaperworld.com> |
---|---|
date | Thu, 17 Feb 2011 00:42:53 +0000 |
parents | 2d3c1197f930 |
children | ca94413ccd0e |
comparison
equal
deleted
inserted
replaced
31220:554ac1421c9c | 31221:2b041e31b825 |
---|---|
19 * along with this program; if not, write to the Free Software | 19 * along with this program; if not, write to the Free Software |
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA | 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
21 */ | 21 */ |
22 #include <cipher.h> | 22 #include <cipher.h> |
23 | 23 |
24 #if !GLIB_CHECK_VERSION(2,16,0) | |
25 | |
24 #define SHA256_HMAC_BLOCK_SIZE 64 | 26 #define SHA256_HMAC_BLOCK_SIZE 64 |
25 | |
26 static size_t | |
27 sha256_get_block_size(PurpleCipherContext *context) | |
28 { | |
29 /* This does not change (in this case) */ | |
30 return SHA256_HMAC_BLOCK_SIZE; | |
31 } | |
32 | |
33 #if GLIB_CHECK_VERSION(2,16,0) | |
34 | |
35 static void | |
36 sha256_init(PurpleCipherContext *context, void *extra) | |
37 { | |
38 purple_g_checksum_init(context, G_CHECKSUM_SHA256); | |
39 } | |
40 | |
41 static void | |
42 sha256_reset(PurpleCipherContext *context, void *extra) | |
43 { | |
44 purple_g_checksum_reset(context, G_CHECKSUM_SHA256); | |
45 } | |
46 | |
47 static gboolean | |
48 sha256_digest(PurpleCipherContext *context, gsize in_len, guchar digest[20], | |
49 gsize *out_len) | |
50 { | |
51 return purple_g_checksum_digest(context, G_CHECKSUM_SHA256, in_len, | |
52 digest, out_len); | |
53 } | |
54 | |
55 static PurpleCipherOps SHA256Ops = { | |
56 .init = sha256_init, | |
57 .reset = sha256_reset, | |
58 .uninit = purple_g_checksum_uninit, | |
59 .append = purple_g_checksum_append, | |
60 .digest = sha256_digest, | |
61 .get_block_size = sha256_get_block_size, | |
62 }; | |
63 | |
64 #else /* GLIB_CHECK_VERSION(2,16,0) */ | |
65 | |
66 #define SHA256_ROTR(X,n) ((((X) >> (n)) | ((X) << (32-(n)))) & 0xFFFFFFFF) | 27 #define SHA256_ROTR(X,n) ((((X) >> (n)) | ((X) << (32-(n)))) & 0xFFFFFFFF) |
67 | 28 |
68 static const guint32 sha256_K[64] = | 29 static const guint32 sha256_K[64] = |
69 { | 30 { |
70 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, | 31 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, |
84 gint lenW; | 45 gint lenW; |
85 | 46 |
86 guint32 sizeHi; | 47 guint32 sizeHi; |
87 guint32 sizeLo; | 48 guint32 sizeLo; |
88 }; | 49 }; |
50 | |
51 static size_t | |
52 sha256_get_block_size(PurpleCipherContext *context) | |
53 { | |
54 /* This does not change (in this case) */ | |
55 return SHA256_HMAC_BLOCK_SIZE; | |
56 } | |
89 | 57 |
90 static void | 58 static void |
91 sha256_hash_block(struct SHA256Context *sha256_ctx) { | 59 sha256_hash_block(struct SHA256Context *sha256_ctx) { |
92 gint i; | 60 gint i; |
93 guint32 A, B, C, D, E, F, G, H, T1, T2; | 61 guint32 A, B, C, D, E, F, G, H, T1, T2; |
294 .append = sha256_append, | 262 .append = sha256_append, |
295 .digest = sha256_digest, | 263 .digest = sha256_digest, |
296 .get_block_size = sha256_get_block_size, | 264 .get_block_size = sha256_get_block_size, |
297 }; | 265 }; |
298 | 266 |
299 #endif /* GLIB_CHECK_VERSION(2,16,0) */ | |
300 | |
301 PurpleCipherOps * | 267 PurpleCipherOps * |
302 purple_sha256_cipher_get_ops(void) { | 268 purple_sha256_cipher_get_ops(void) { |
303 return &SHA256Ops; | 269 return &SHA256Ops; |
304 } | 270 } |
305 | 271 |
272 #endif /* !GLIB_CHECK_VERSION(2,16,0) */ | |
273 |