Mercurial > pidgin.yaz
annotate libpurple/ciphers/sha256.c @ 31666:3af51303d45c
Moved sha256 to the sub library
author | Gary Kramlich <grim@reaperworld.com> |
---|---|
date | Mon, 14 Feb 2011 06:20:59 +0000 |
parents | |
children | 2d3c1197f930 |
rev | line source |
---|---|
31666
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
1 /* |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
2 * purple |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
3 * |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
4 * Purple is the legal property of its developers, whose names are too numerous |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
6 * source distribution. |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
7 * |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
8 * This program is free software; you can redistribute it and/or modify |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
11 * (at your option) any later version. |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
12 * |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
16 * GNU General Public License for more details. |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
17 * |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
21 */ |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
22 #include <cipher.h> |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
23 #include <string.h> |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
24 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
25 #define SHA256_HMAC_BLOCK_SIZE 64 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
26 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
27 static size_t |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
28 sha256_get_block_size(PurpleCipherContext *context) |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
29 { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
30 /* This does not change (in this case) */ |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
31 return SHA256_HMAC_BLOCK_SIZE; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
32 } |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
33 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
34 #if GLIB_CHECK_VERSION(2,16,0) |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
35 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
36 static void |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
37 sha256_init(PurpleCipherContext *context, void *extra) |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
38 { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
39 purple_g_checksum_init(context, G_CHECKSUM_SHA256); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
40 } |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
41 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
42 static void |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
43 sha256_reset(PurpleCipherContext *context, void *extra) |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
44 { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
45 purple_g_checksum_reset(context, G_CHECKSUM_SHA256); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
46 } |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
47 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
48 static gboolean |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
49 sha256_digest(PurpleCipherContext *context, gsize in_len, guchar digest[20], |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
50 gsize *out_len) |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
51 { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
52 return purple_g_checksum_digest(context, G_CHECKSUM_SHA256, in_len, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
53 digest, out_len); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
54 } |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
55 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
56 static PurpleCipherOps SHA256Ops = { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
57 .init = sha256_init, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
58 .reset = sha256_reset, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
59 .uninit = purple_g_checksum_uninit, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
60 .append = purple_g_checksum_append, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
61 .digest = sha256_digest, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
62 .get_block_size = sha256_get_block_size, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
63 }; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
64 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
65 #else /* GLIB_CHECK_VERSION(2,16,0) */ |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
66 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
67 #define SHA256_ROTR(X,n) ((((X) >> (n)) | ((X) << (32-(n)))) & 0xFFFFFFFF) |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
68 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
69 static const guint32 sha256_K[64] = |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
70 { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
71 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
72 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
73 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
74 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
75 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
76 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
77 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
78 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
79 }; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
80 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
81 struct SHA256Context { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
82 guint32 H[8]; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
83 guint32 W[64]; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
84 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
85 gint lenW; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
86 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
87 guint32 sizeHi; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
88 guint32 sizeLo; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
89 }; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
90 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
91 static void |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
92 sha256_hash_block(struct SHA256Context *sha256_ctx) { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
93 gint i; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
94 guint32 A, B, C, D, E, F, G, H, T1, T2; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
95 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
96 for(i = 16; i < 64; i++) { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
97 sha256_ctx->W[i] = |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
98 (SHA256_ROTR(sha256_ctx->W[i-2], 17) ^ SHA256_ROTR(sha256_ctx->W[i-2], 19) ^ (sha256_ctx->W[i-2] >> 10)) |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
99 + sha256_ctx->W[i-7] |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
100 + (SHA256_ROTR(sha256_ctx->W[i-15], 7) ^ SHA256_ROTR(sha256_ctx->W[i-15], 18) ^ (sha256_ctx->W[i-15] >> 3)) |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
101 + sha256_ctx->W[i-16]; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
102 } |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
103 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
104 A = sha256_ctx->H[0]; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
105 B = sha256_ctx->H[1]; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
106 C = sha256_ctx->H[2]; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
107 D = sha256_ctx->H[3]; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
108 E = sha256_ctx->H[4]; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
109 F = sha256_ctx->H[5]; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
110 G = sha256_ctx->H[6]; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
111 H = sha256_ctx->H[7]; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
112 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
113 for(i = 0; i < 64; i++) { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
114 T1 = H |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
115 + (SHA256_ROTR(E, 6) ^ SHA256_ROTR(E, 11) ^ SHA256_ROTR(E, 25)) |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
116 + ((E & F) ^ ((~E) & G)) |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
117 + sha256_K[i] + sha256_ctx->W[i]; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
118 T2 = (SHA256_ROTR(A, 2) ^ SHA256_ROTR(A, 13) ^ SHA256_ROTR(A, 22)) |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
119 + ((A & B) ^ (A & C) ^ (B & C)); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
120 H = G; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
121 G = F; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
122 F = E; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
123 E = D + T1; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
124 D = C; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
125 C = B; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
126 B = A; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
127 A = T1 + T2; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
128 } |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
129 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
130 sha256_ctx->H[0] += A; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
131 sha256_ctx->H[1] += B; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
132 sha256_ctx->H[2] += C; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
133 sha256_ctx->H[3] += D; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
134 sha256_ctx->H[4] += E; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
135 sha256_ctx->H[5] += F; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
136 sha256_ctx->H[6] += G; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
137 sha256_ctx->H[7] += H; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
138 } |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
139 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
140 static void |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
141 sha256_set_opt(PurpleCipherContext *context, const gchar *name, void *value) { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
142 struct SHA256Context *ctx; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
143 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
144 ctx = purple_cipher_context_get_data(context); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
145 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
146 if(!strcmp(name, "sizeHi")) { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
147 ctx->sizeHi = GPOINTER_TO_INT(value); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
148 } else if(!strcmp(name, "sizeLo")) { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
149 ctx->sizeLo = GPOINTER_TO_INT(value); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
150 } else if(!strcmp(name, "lenW")) { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
151 ctx->lenW = GPOINTER_TO_INT(value); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
152 } |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
153 } |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
154 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
155 static void * |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
156 sha256_get_opt(PurpleCipherContext *context, const gchar *name) { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
157 struct SHA256Context *ctx; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
158 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
159 ctx = purple_cipher_context_get_data(context); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
160 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
161 if(!strcmp(name, "sizeHi")) { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
162 return GINT_TO_POINTER(ctx->sizeHi); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
163 } else if(!strcmp(name, "sizeLo")) { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
164 return GINT_TO_POINTER(ctx->sizeLo); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
165 } else if(!strcmp(name, "lenW")) { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
166 return GINT_TO_POINTER(ctx->lenW); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
167 } |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
168 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
169 return NULL; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
170 } |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
171 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
172 static void |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
173 sha256_init(PurpleCipherContext *context, void *extra) { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
174 struct SHA256Context *sha256_ctx; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
175 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
176 sha256_ctx = g_new0(struct SHA256Context, 1); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
177 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
178 purple_cipher_context_set_data(context, sha256_ctx); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
179 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
180 purple_cipher_context_reset(context, extra); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
181 } |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
182 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
183 static void |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
184 sha256_reset(PurpleCipherContext *context, void *extra) { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
185 struct SHA256Context *sha256_ctx; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
186 gint i; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
187 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
188 sha256_ctx = purple_cipher_context_get_data(context); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
189 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
190 g_return_if_fail(sha256_ctx); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
191 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
192 sha256_ctx->lenW = 0; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
193 sha256_ctx->sizeHi = 0; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
194 sha256_ctx->sizeLo = 0; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
195 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
196 sha256_ctx->H[0] = 0x6a09e667; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
197 sha256_ctx->H[1] = 0xbb67ae85; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
198 sha256_ctx->H[2] = 0x3c6ef372; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
199 sha256_ctx->H[3] = 0xa54ff53a; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
200 sha256_ctx->H[4] = 0x510e527f; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
201 sha256_ctx->H[5] = 0x9b05688c; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
202 sha256_ctx->H[6] = 0x1f83d9ab; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
203 sha256_ctx->H[7] = 0x5be0cd19; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
204 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
205 for(i = 0; i < 64; i++) |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
206 sha256_ctx->W[i] = 0; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
207 } |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
208 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
209 static void |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
210 sha256_uninit(PurpleCipherContext *context) { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
211 struct SHA256Context *sha256_ctx; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
212 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
213 purple_cipher_context_reset(context, NULL); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
214 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
215 sha256_ctx = purple_cipher_context_get_data(context); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
216 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
217 memset(sha256_ctx, 0, sizeof(struct SHA256Context)); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
218 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
219 g_free(sha256_ctx); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
220 sha256_ctx = NULL; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
221 } |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
222 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
223 static void |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
224 sha256_append(PurpleCipherContext *context, const guchar *data, size_t len) { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
225 struct SHA256Context *sha256_ctx; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
226 gint i; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
227 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
228 sha256_ctx = purple_cipher_context_get_data(context); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
229 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
230 g_return_if_fail(sha256_ctx); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
231 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
232 for(i = 0; i < len; i++) { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
233 sha256_ctx->W[sha256_ctx->lenW / 4] <<= 8; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
234 sha256_ctx->W[sha256_ctx->lenW / 4] |= data[i]; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
235 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
236 if((++sha256_ctx->lenW) % 64 == 0) { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
237 sha256_hash_block(sha256_ctx); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
238 sha256_ctx->lenW = 0; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
239 } |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
240 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
241 sha256_ctx->sizeLo += 8; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
242 sha256_ctx->sizeHi += (sha256_ctx->sizeLo < 8); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
243 } |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
244 } |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
245 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
246 static gboolean |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
247 sha256_digest(PurpleCipherContext *context, size_t in_len, guchar digest[32], |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
248 size_t *out_len) |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
249 { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
250 struct SHA256Context *sha256_ctx; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
251 guchar pad0x80 = 0x80, pad0x00 = 0x00; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
252 guchar padlen[8]; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
253 gint i; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
254 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
255 g_return_val_if_fail(in_len >= 32, FALSE); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
256 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
257 sha256_ctx = purple_cipher_context_get_data(context); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
258 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
259 g_return_val_if_fail(sha256_ctx, FALSE); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
260 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
261 padlen[0] = (guchar)((sha256_ctx->sizeHi >> 24) & 255); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
262 padlen[1] = (guchar)((sha256_ctx->sizeHi >> 16) & 255); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
263 padlen[2] = (guchar)((sha256_ctx->sizeHi >> 8) & 255); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
264 padlen[3] = (guchar)((sha256_ctx->sizeHi >> 0) & 255); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
265 padlen[4] = (guchar)((sha256_ctx->sizeLo >> 24) & 255); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
266 padlen[5] = (guchar)((sha256_ctx->sizeLo >> 16) & 255); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
267 padlen[6] = (guchar)((sha256_ctx->sizeLo >> 8) & 255); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
268 padlen[7] = (guchar)((sha256_ctx->sizeLo >> 0) & 255); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
269 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
270 /* pad with a 1, then zeroes, then length */ |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
271 purple_cipher_context_append(context, &pad0x80, 1); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
272 while(sha256_ctx->lenW != 56) |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
273 purple_cipher_context_append(context, &pad0x00, 1); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
274 purple_cipher_context_append(context, padlen, 8); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
275 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
276 for(i = 0; i < 32; i++) { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
277 digest[i] = (guchar)(sha256_ctx->H[i / 4] >> 24); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
278 sha256_ctx->H[i / 4] <<= 8; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
279 } |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
280 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
281 purple_cipher_context_reset(context, NULL); |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
282 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
283 if(out_len) |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
284 *out_len = 32; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
285 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
286 return TRUE; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
287 } |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
288 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
289 static PurpleCipherOps SHA256Ops = { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
290 .set_option = sha256_set_opt, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
291 .get_option = sha256_get_opt, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
292 .init = sha256_init, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
293 .reset = sha256_reset, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
294 .uninit = sha256_uninit, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
295 .append = sha256_append, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
296 .digest = sha256_digest, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
297 .get_block_size = sha256_get_block_size, |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
298 }; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
299 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
300 #endif /* GLIB_CHECK_VERSION(2,16,0) */ |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
301 |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
302 PurpleCipherOps * |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
303 purple_sha256_cipher_get_ops(void) { |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
304 return &SHA256Ops; |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
305 } |
3af51303d45c
Moved sha256 to the sub library
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
306 |