Mercurial > pidgin
comparison src/protocols/yahoo/crypt.c @ 11183:8dca96cbcd64
[gaim-migrate @ 13295]
I changed the cipher API to use guchar instead of guint8
This seems to be what gtk/glib uses for random bits of data
I don't know what got into me
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Wed, 03 Aug 2005 02:57:00 +0000 |
| parents | 923b78741964 |
| children |
comparison
equal
deleted
inserted
replaced
| 11182:5389d7d497ce | 11183:8dca96cbcd64 |
|---|---|
| 39 | 39 |
| 40 char *yahoo_crypt(const char *key, const char *salt) | 40 char *yahoo_crypt(const char *key, const char *salt) |
| 41 { | 41 { |
| 42 GaimCipher *cipher; | 42 GaimCipher *cipher; |
| 43 GaimCipherContext *context1, *context2; | 43 GaimCipherContext *context1, *context2; |
| 44 guint8 digest[16]; | 44 guchar digest[16]; |
| 45 static char *buffer = NULL; | 45 static char *buffer = NULL; |
| 46 static int buflen = 0; | 46 static int buflen = 0; |
| 47 int needed = 3 + strlen (salt) + 1 + 26 + 1; | 47 int needed = 3 + strlen (salt) + 1 + 26 + 1; |
| 48 | 48 |
| 49 size_t salt_len; | 49 size_t salt_len; |
| 71 | 71 |
| 72 salt_len = MIN (strcspn (salt, "$"), 8); | 72 salt_len = MIN (strcspn (salt, "$"), 8); |
| 73 key_len = strlen (key); | 73 key_len = strlen (key); |
| 74 | 74 |
| 75 /* Add the key string. */ | 75 /* Add the key string. */ |
| 76 gaim_cipher_context_append(context1, (const guint8 *)key, key_len); | 76 gaim_cipher_context_append(context1, (const guchar *)key, key_len); |
| 77 | 77 |
| 78 /* Because the SALT argument need not always have the salt prefix we | 78 /* Because the SALT argument need not always have the salt prefix we |
| 79 * add it separately. | 79 * add it separately. |
| 80 */ | 80 */ |
| 81 gaim_cipher_context_append(context1, (const guint8 *)md5_salt_prefix, | 81 gaim_cipher_context_append(context1, (const guchar *)md5_salt_prefix, |
| 82 sizeof(md5_salt_prefix) - 1); | 82 sizeof(md5_salt_prefix) - 1); |
| 83 | 83 |
| 84 /* The last part is the salt string. This must be at most 8 | 84 /* The last part is the salt string. This must be at most 8 |
| 85 * characters and it ends at the first `$' character (for | 85 * characters and it ends at the first `$' character (for |
| 86 * compatibility which existing solutions). | 86 * compatibility which existing solutions). |
| 87 */ | 87 */ |
| 88 gaim_cipher_context_append(context1, (const guint8 *)salt, salt_len); | 88 gaim_cipher_context_append(context1, (const guchar *)salt, salt_len); |
| 89 | 89 |
| 90 /* Compute alternate MD5 sum with input KEY, SALT, and KEY. The | 90 /* Compute alternate MD5 sum with input KEY, SALT, and KEY. The |
| 91 * final result will be added to the first context. | 91 * final result will be added to the first context. |
| 92 */ | 92 */ |
| 93 | 93 |
| 94 /* Add key. */ | 94 /* Add key. */ |
| 95 gaim_cipher_context_append(context2, (const guint8 *)key, key_len); | 95 gaim_cipher_context_append(context2, (const guchar *)key, key_len); |
| 96 | 96 |
| 97 /* Add salt. */ | 97 /* Add salt. */ |
| 98 gaim_cipher_context_append(context2, (const guint8 *)salt, salt_len); | 98 gaim_cipher_context_append(context2, (const guchar *)salt, salt_len); |
| 99 | 99 |
| 100 /* Add key again. */ | 100 /* Add key again. */ |
| 101 gaim_cipher_context_append(context2, (const guint8 *)key, key_len); | 101 gaim_cipher_context_append(context2, (const guchar *)key, key_len); |
| 102 | 102 |
| 103 /* Now get result of this (16 bytes) and add it to the other context. */ | 103 /* Now get result of this (16 bytes) and add it to the other context. */ |
| 104 gaim_cipher_context_digest(context2, sizeof(digest), digest, NULL); | 104 gaim_cipher_context_digest(context2, sizeof(digest), digest, NULL); |
| 105 | 105 |
| 106 /* Add for any character in the key one byte of the alternate sum. */ | 106 /* Add for any character in the key one byte of the alternate sum. */ |
| 116 * bit the first character of the key. This does not seem to be | 116 * bit the first character of the key. This does not seem to be |
| 117 * what was intended but we have to follow this to be compatible. | 117 * what was intended but we have to follow this to be compatible. |
| 118 */ | 118 */ |
| 119 for (cnt = key_len; cnt > 0; cnt >>= 1) | 119 for (cnt = key_len; cnt > 0; cnt >>= 1) |
| 120 gaim_cipher_context_append(context1, | 120 gaim_cipher_context_append(context1, |
| 121 (cnt & 1) != 0 ? digest : (guint8 *)key, 1); | 121 (cnt & 1) != 0 ? digest : (guchar *)key, 1); |
| 122 | 122 |
| 123 /* Create intermediate result. */ | 123 /* Create intermediate result. */ |
| 124 gaim_cipher_context_digest(context1, sizeof(digest), digest, NULL); | 124 gaim_cipher_context_digest(context1, sizeof(digest), digest, NULL); |
| 125 | 125 |
| 126 /* Now comes another weirdness. In fear of password crackers here | 126 /* Now comes another weirdness. In fear of password crackers here |
| 131 /* New context. */ | 131 /* New context. */ |
| 132 gaim_cipher_context_reset(context2, NULL); | 132 gaim_cipher_context_reset(context2, NULL); |
| 133 | 133 |
| 134 /* Add key or last result. */ | 134 /* Add key or last result. */ |
| 135 if ((cnt & 1) != 0) | 135 if ((cnt & 1) != 0) |
| 136 gaim_cipher_context_append(context2, (const guint8 *)key, key_len); | 136 gaim_cipher_context_append(context2, (const guchar *)key, key_len); |
| 137 else | 137 else |
| 138 gaim_cipher_context_append(context2, digest, 16); | 138 gaim_cipher_context_append(context2, digest, 16); |
| 139 | 139 |
| 140 /* Add salt for numbers not divisible by 3. */ | 140 /* Add salt for numbers not divisible by 3. */ |
| 141 if (cnt % 3 != 0) | 141 if (cnt % 3 != 0) |
| 142 gaim_cipher_context_append(context2, (const guint8 *)salt, salt_len); | 142 gaim_cipher_context_append(context2, (const guchar *)salt, salt_len); |
| 143 | 143 |
| 144 /* Add key for numbers not divisible by 7. */ | 144 /* Add key for numbers not divisible by 7. */ |
| 145 if (cnt % 7 != 0) | 145 if (cnt % 7 != 0) |
| 146 gaim_cipher_context_append(context2, (const guint8 *)key, key_len); | 146 gaim_cipher_context_append(context2, (const guchar *)key, key_len); |
| 147 | 147 |
| 148 /* Add key or last result. */ | 148 /* Add key or last result. */ |
| 149 if ((cnt & 1) != 0) | 149 if ((cnt & 1) != 0) |
| 150 gaim_cipher_context_append(context2, digest, 16); | 150 gaim_cipher_context_append(context2, digest, 16); |
| 151 else | 151 else |
| 152 gaim_cipher_context_append(context2, (const guint8 *)key, key_len); | 152 gaim_cipher_context_append(context2, (const guchar *)key, key_len); |
| 153 | 153 |
| 154 /* Create intermediate result. */ | 154 /* Create intermediate result. */ |
| 155 gaim_cipher_context_digest(context2, sizeof(digest), digest, NULL); | 155 gaim_cipher_context_digest(context2, sizeof(digest), digest, NULL); |
| 156 } | 156 } |
| 157 | 157 |
