Mercurial > pidgin.yaz
comparison libpurple/cipher.c @ 15823:32c366eeeb99
sed -ie 's/gaim/purple/g'
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 19 Mar 2007 07:01:17 +0000 |
parents | 5fe8042783c1 |
children | eca698c354d0 07cf49a0f404 |
comparison
equal
deleted
inserted
replaced
15822:84b0f9b23ede | 15823:32c366eeeb99 |
---|---|
1 /* | 1 /* |
2 * gaim | 2 * purple |
3 * | 3 * |
4 * Gaim is the legal property of its developers, whose names are too numerous | 4 * Purple is the legal property of its developers, whose names are too numerous |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | 5 * to list here. Please refer to the COPYRIGHT file distributed with this |
6 * source distribution. | 6 * source distribution. |
7 * | 7 * |
8 * Original md5 | 8 * Original md5 |
9 * Copyright (C) 2001-2003 Christophe Devine <c.devine@cr0.net> | 9 * Copyright (C) 2001-2003 Christophe Devine <c.devine@cr0.net> |
82 (b)[(i) + 2] = (guchar)((n) >> 16); \ | 82 (b)[(i) + 2] = (guchar)((n) >> 16); \ |
83 (b)[(i) + 3] = (guchar)((n) >> 24); \ | 83 (b)[(i) + 3] = (guchar)((n) >> 24); \ |
84 } | 84 } |
85 | 85 |
86 static void | 86 static void |
87 md5_init(GaimCipherContext *context, gpointer extra) { | 87 md5_init(PurpleCipherContext *context, gpointer extra) { |
88 struct MD5Context *md5_context; | 88 struct MD5Context *md5_context; |
89 | 89 |
90 md5_context = g_new0(struct MD5Context, 1); | 90 md5_context = g_new0(struct MD5Context, 1); |
91 | 91 |
92 gaim_cipher_context_set_data(context, md5_context); | 92 purple_cipher_context_set_data(context, md5_context); |
93 | 93 |
94 gaim_cipher_context_reset(context, extra); | 94 purple_cipher_context_reset(context, extra); |
95 } | 95 } |
96 | 96 |
97 static void | 97 static void |
98 md5_reset(GaimCipherContext *context, gpointer extra) { | 98 md5_reset(PurpleCipherContext *context, gpointer extra) { |
99 struct MD5Context *md5_context; | 99 struct MD5Context *md5_context; |
100 | 100 |
101 md5_context = gaim_cipher_context_get_data(context); | 101 md5_context = purple_cipher_context_get_data(context); |
102 | 102 |
103 md5_context->total[0] = 0; | 103 md5_context->total[0] = 0; |
104 md5_context->total[1] = 0; | 104 md5_context->total[1] = 0; |
105 | 105 |
106 md5_context->state[0] = 0x67452301; | 106 md5_context->state[0] = 0x67452301; |
110 | 110 |
111 memset(md5_context->buffer, 0, sizeof(md5_context->buffer)); | 111 memset(md5_context->buffer, 0, sizeof(md5_context->buffer)); |
112 } | 112 } |
113 | 113 |
114 static void | 114 static void |
115 md5_uninit(GaimCipherContext *context) { | 115 md5_uninit(PurpleCipherContext *context) { |
116 struct MD5Context *md5_context; | 116 struct MD5Context *md5_context; |
117 | 117 |
118 gaim_cipher_context_reset(context, NULL); | 118 purple_cipher_context_reset(context, NULL); |
119 | 119 |
120 md5_context = gaim_cipher_context_get_data(context); | 120 md5_context = purple_cipher_context_get_data(context); |
121 memset(md5_context, 0, sizeof(md5_context)); | 121 memset(md5_context, 0, sizeof(md5_context)); |
122 | 122 |
123 g_free(md5_context); | 123 g_free(md5_context); |
124 md5_context = NULL; | 124 md5_context = NULL; |
125 } | 125 } |
243 md5_context->state[2] += C; | 243 md5_context->state[2] += C; |
244 md5_context->state[3] += D; | 244 md5_context->state[3] += D; |
245 } | 245 } |
246 | 246 |
247 static void | 247 static void |
248 md5_append(GaimCipherContext *context, const guchar *data, size_t len) { | 248 md5_append(PurpleCipherContext *context, const guchar *data, size_t len) { |
249 struct MD5Context *md5_context = NULL; | 249 struct MD5Context *md5_context = NULL; |
250 guint32 left = 0, fill = 0; | 250 guint32 left = 0, fill = 0; |
251 | 251 |
252 g_return_if_fail(context != NULL); | 252 g_return_if_fail(context != NULL); |
253 | 253 |
254 md5_context = gaim_cipher_context_get_data(context); | 254 md5_context = purple_cipher_context_get_data(context); |
255 g_return_if_fail(md5_context != NULL); | 255 g_return_if_fail(md5_context != NULL); |
256 | 256 |
257 left = md5_context->total[0] & 0x3F; | 257 left = md5_context->total[0] & 0x3F; |
258 fill = 64 - left; | 258 fill = 64 - left; |
259 | 259 |
281 memcpy((md5_context->buffer + left), data, len); | 281 memcpy((md5_context->buffer + left), data, len); |
282 } | 282 } |
283 } | 283 } |
284 | 284 |
285 static gboolean | 285 static gboolean |
286 md5_digest(GaimCipherContext *context, size_t in_len, guchar digest[16], | 286 md5_digest(PurpleCipherContext *context, size_t in_len, guchar digest[16], |
287 size_t *out_len) | 287 size_t *out_len) |
288 { | 288 { |
289 struct MD5Context *md5_context = NULL; | 289 struct MD5Context *md5_context = NULL; |
290 guint32 last, pad; | 290 guint32 last, pad; |
291 guint32 high, low; | 291 guint32 high, low; |
297 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | 297 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
298 }; | 298 }; |
299 | 299 |
300 g_return_val_if_fail(in_len >= 16, FALSE); | 300 g_return_val_if_fail(in_len >= 16, FALSE); |
301 | 301 |
302 md5_context = gaim_cipher_context_get_data(context); | 302 md5_context = purple_cipher_context_get_data(context); |
303 | 303 |
304 high = (md5_context->total[0] >> 29) | 304 high = (md5_context->total[0] >> 29) |
305 | (md5_context->total[1] << 3); | 305 | (md5_context->total[1] << 3); |
306 low = (md5_context->total[0] << 3); | 306 low = (md5_context->total[0] << 3); |
307 | 307 |
323 *out_len = 16; | 323 *out_len = 16; |
324 | 324 |
325 return TRUE; | 325 return TRUE; |
326 } | 326 } |
327 | 327 |
328 static GaimCipherOps MD5Ops = { | 328 static PurpleCipherOps MD5Ops = { |
329 NULL, /* Set option */ | 329 NULL, /* Set option */ |
330 NULL, /* Get option */ | 330 NULL, /* Get option */ |
331 md5_init, /* init */ | 331 md5_init, /* init */ |
332 md5_reset, /* reset */ | 332 md5_reset, /* reset */ |
333 md5_uninit, /* uninit */ | 333 md5_uninit, /* uninit */ |
470 le32_to_cpu_array(ctx->block, sizeof(ctx->block) / sizeof(guint32)); | 470 le32_to_cpu_array(ctx->block, sizeof(ctx->block) / sizeof(guint32)); |
471 md4_transform(ctx->hash, ctx->block); | 471 md4_transform(ctx->hash, ctx->block); |
472 } | 472 } |
473 | 473 |
474 static void | 474 static void |
475 md4_init(GaimCipherContext *context, gpointer extra) { | 475 md4_init(PurpleCipherContext *context, gpointer extra) { |
476 struct MD4_Context *mctx; | 476 struct MD4_Context *mctx; |
477 mctx = g_new0(struct MD4_Context, 1); | 477 mctx = g_new0(struct MD4_Context, 1); |
478 gaim_cipher_context_set_data(context, mctx); | 478 purple_cipher_context_set_data(context, mctx); |
479 gaim_cipher_context_reset(context, extra); | 479 purple_cipher_context_reset(context, extra); |
480 | 480 |
481 mctx->hash[0] = 0x67452301; | 481 mctx->hash[0] = 0x67452301; |
482 mctx->hash[1] = 0xefcdab89; | 482 mctx->hash[1] = 0xefcdab89; |
483 mctx->hash[2] = 0x98badcfe; | 483 mctx->hash[2] = 0x98badcfe; |
484 mctx->hash[3] = 0x10325476; | 484 mctx->hash[3] = 0x10325476; |
485 mctx->byte_count = 0; | 485 mctx->byte_count = 0; |
486 } | 486 } |
487 | 487 |
488 static void | 488 static void |
489 md4_reset(GaimCipherContext *context, gpointer extra) { | 489 md4_reset(PurpleCipherContext *context, gpointer extra) { |
490 struct MD4_Context *mctx; | 490 struct MD4_Context *mctx; |
491 | 491 |
492 mctx = gaim_cipher_context_get_data(context); | 492 mctx = purple_cipher_context_get_data(context); |
493 | 493 |
494 mctx->hash[0] = 0x67452301; | 494 mctx->hash[0] = 0x67452301; |
495 mctx->hash[1] = 0xefcdab89; | 495 mctx->hash[1] = 0xefcdab89; |
496 mctx->hash[2] = 0x98badcfe; | 496 mctx->hash[2] = 0x98badcfe; |
497 mctx->hash[3] = 0x10325476; | 497 mctx->hash[3] = 0x10325476; |
498 mctx->byte_count = 0; | 498 mctx->byte_count = 0; |
499 } | 499 } |
500 | 500 |
501 static void | 501 static void |
502 md4_append(GaimCipherContext *context, const guchar *data, size_t len) | 502 md4_append(PurpleCipherContext *context, const guchar *data, size_t len) |
503 { | 503 { |
504 struct MD4_Context *mctx = gaim_cipher_context_get_data(context); | 504 struct MD4_Context *mctx = purple_cipher_context_get_data(context); |
505 const guint32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f); | 505 const guint32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f); |
506 | 506 |
507 mctx->byte_count += len; | 507 mctx->byte_count += len; |
508 | 508 |
509 if (avail > len) { | 509 if (avail > len) { |
528 | 528 |
529 memcpy(mctx->block, data, len); | 529 memcpy(mctx->block, data, len); |
530 } | 530 } |
531 | 531 |
532 static gboolean | 532 static gboolean |
533 md4_digest(GaimCipherContext *context, size_t in_len, guchar *out, | 533 md4_digest(PurpleCipherContext *context, size_t in_len, guchar *out, |
534 size_t *out_len) | 534 size_t *out_len) |
535 { | 535 { |
536 struct MD4_Context *mctx = gaim_cipher_context_get_data(context); | 536 struct MD4_Context *mctx = purple_cipher_context_get_data(context); |
537 const unsigned int offset = mctx->byte_count & 0x3f; | 537 const unsigned int offset = mctx->byte_count & 0x3f; |
538 char *p = (char *)mctx->block + offset; | 538 char *p = (char *)mctx->block + offset; |
539 int padding = 56 - (offset + 1); | 539 int padding = 56 - (offset + 1); |
540 | 540 |
541 | 541 |
560 memset(mctx, 0, sizeof(*mctx)); | 560 memset(mctx, 0, sizeof(*mctx)); |
561 return TRUE; | 561 return TRUE; |
562 } | 562 } |
563 | 563 |
564 static void | 564 static void |
565 md4_uninit(GaimCipherContext *context) { | 565 md4_uninit(PurpleCipherContext *context) { |
566 struct MD4_Context *md4_context; | 566 struct MD4_Context *md4_context; |
567 | 567 |
568 gaim_cipher_context_reset(context, NULL); | 568 purple_cipher_context_reset(context, NULL); |
569 | 569 |
570 md4_context = gaim_cipher_context_get_data(context); | 570 md4_context = purple_cipher_context_get_data(context); |
571 memset(md4_context, 0, sizeof(md4_context)); | 571 memset(md4_context, 0, sizeof(md4_context)); |
572 | 572 |
573 g_free(md4_context); | 573 g_free(md4_context); |
574 md4_context = NULL; | 574 md4_context = NULL; |
575 } | 575 } |
576 | 576 |
577 static GaimCipherOps MD4Ops = { | 577 static PurpleCipherOps MD4Ops = { |
578 NULL, /* Set option */ | 578 NULL, /* Set option */ |
579 NULL, /* Get option */ | 579 NULL, /* Get option */ |
580 md4_init, /* init */ | 580 md4_init, /* init */ |
581 md4_reset, /* reset */ | 581 md4_reset, /* reset */ |
582 md4_uninit, /* uninit */ | 582 md4_uninit, /* uninit */ |
896 * Fill a DES context with subkeys calculated from a 64bit key. | 896 * Fill a DES context with subkeys calculated from a 64bit key. |
897 * Does not check parity bits, but simply ignore them. | 897 * Does not check parity bits, but simply ignore them. |
898 * Does not check for weak keys. | 898 * Does not check for weak keys. |
899 **/ | 899 **/ |
900 static void | 900 static void |
901 des_set_key (GaimCipherContext *context, const guchar * key) | 901 des_set_key (PurpleCipherContext *context, const guchar * key) |
902 { | 902 { |
903 struct _des_ctx *ctx = gaim_cipher_context_get_data(context); | 903 struct _des_ctx *ctx = purple_cipher_context_get_data(context); |
904 int i; | 904 int i; |
905 | 905 |
906 des_key_schedule (key, ctx->encrypt_subkeys); | 906 des_key_schedule (key, ctx->encrypt_subkeys); |
907 | 907 |
908 for(i=0; i<32; i+=2) | 908 for(i=0; i<32; i+=2) |
943 | 943 |
944 return 0; | 944 return 0; |
945 } | 945 } |
946 | 946 |
947 static gint | 947 static gint |
948 des_encrypt(GaimCipherContext *context, const guchar data[], | 948 des_encrypt(PurpleCipherContext *context, const guchar data[], |
949 size_t len, guchar output[], size_t *outlen) { | 949 size_t len, guchar output[], size_t *outlen) { |
950 int offset = 0; | 950 int offset = 0; |
951 int i = 0; | 951 int i = 0; |
952 int tmp; | 952 int tmp; |
953 guint8 buf[8] = {0,0,0,0,0,0,0,0}; | 953 guint8 buf[8] = {0,0,0,0,0,0,0,0}; |
954 while(offset+8<=len) { | 954 while(offset+8<=len) { |
955 des_ecb_crypt(gaim_cipher_context_get_data(context), | 955 des_ecb_crypt(purple_cipher_context_get_data(context), |
956 data+offset, | 956 data+offset, |
957 output+offset, | 957 output+offset, |
958 0); | 958 0); |
959 offset+=8; | 959 offset+=8; |
960 } | 960 } |
964 tmp = offset; | 964 tmp = offset; |
965 while(tmp<len) { | 965 while(tmp<len) { |
966 buf[i++] = data[tmp]; | 966 buf[i++] = data[tmp]; |
967 tmp++; | 967 tmp++; |
968 } | 968 } |
969 des_ecb_crypt(gaim_cipher_context_get_data(context), | 969 des_ecb_crypt(purple_cipher_context_get_data(context), |
970 buf, | 970 buf, |
971 output+offset, | 971 output+offset, |
972 0); | 972 0); |
973 } | 973 } |
974 return 0; | 974 return 0; |
975 } | 975 } |
976 | 976 |
977 static void | 977 static void |
978 des_init(GaimCipherContext *context, gpointer extra) { | 978 des_init(PurpleCipherContext *context, gpointer extra) { |
979 struct _des_ctx *mctx; | 979 struct _des_ctx *mctx; |
980 mctx = g_new0(struct _des_ctx, 1); | 980 mctx = g_new0(struct _des_ctx, 1); |
981 gaim_cipher_context_set_data(context, mctx); | 981 purple_cipher_context_set_data(context, mctx); |
982 } | 982 } |
983 | 983 |
984 static void | 984 static void |
985 des_uninit(GaimCipherContext *context) { | 985 des_uninit(PurpleCipherContext *context) { |
986 struct _des_ctx *des_context; | 986 struct _des_ctx *des_context; |
987 | 987 |
988 des_context = gaim_cipher_context_get_data(context); | 988 des_context = purple_cipher_context_get_data(context); |
989 memset(des_context, 0, sizeof(des_context)); | 989 memset(des_context, 0, sizeof(des_context)); |
990 | 990 |
991 g_free(des_context); | 991 g_free(des_context); |
992 des_context = NULL; | 992 des_context = NULL; |
993 } | 993 } |
994 | 994 |
995 static GaimCipherOps DESOps = { | 995 static PurpleCipherOps DESOps = { |
996 NULL, /* Set option */ | 996 NULL, /* Set option */ |
997 NULL, /* Get option */ | 997 NULL, /* Get option */ |
998 des_init, /* init */ | 998 des_init, /* init */ |
999 NULL, /* reset */ | 999 NULL, /* reset */ |
1000 des_uninit, /* uninit */ | 1000 des_uninit, /* uninit */ |
1085 sha1_ctx->H[3] += D; | 1085 sha1_ctx->H[3] += D; |
1086 sha1_ctx->H[4] += E; | 1086 sha1_ctx->H[4] += E; |
1087 } | 1087 } |
1088 | 1088 |
1089 static void | 1089 static void |
1090 sha1_set_opt(GaimCipherContext *context, const gchar *name, void *value) { | 1090 sha1_set_opt(PurpleCipherContext *context, const gchar *name, void *value) { |
1091 struct SHA1Context *ctx; | 1091 struct SHA1Context *ctx; |
1092 | 1092 |
1093 ctx = gaim_cipher_context_get_data(context); | 1093 ctx = purple_cipher_context_get_data(context); |
1094 | 1094 |
1095 if(!strcmp(name, "sizeHi")) { | 1095 if(!strcmp(name, "sizeHi")) { |
1096 ctx->sizeHi = GPOINTER_TO_INT(value); | 1096 ctx->sizeHi = GPOINTER_TO_INT(value); |
1097 } else if(!strcmp(name, "sizeLo")) { | 1097 } else if(!strcmp(name, "sizeLo")) { |
1098 ctx->sizeLo = GPOINTER_TO_INT(value); | 1098 ctx->sizeLo = GPOINTER_TO_INT(value); |
1100 ctx->lenW = GPOINTER_TO_INT(value); | 1100 ctx->lenW = GPOINTER_TO_INT(value); |
1101 } | 1101 } |
1102 } | 1102 } |
1103 | 1103 |
1104 static void * | 1104 static void * |
1105 sha1_get_opt(GaimCipherContext *context, const gchar *name) { | 1105 sha1_get_opt(PurpleCipherContext *context, const gchar *name) { |
1106 struct SHA1Context *ctx; | 1106 struct SHA1Context *ctx; |
1107 | 1107 |
1108 ctx = gaim_cipher_context_get_data(context); | 1108 ctx = purple_cipher_context_get_data(context); |
1109 | 1109 |
1110 if(!strcmp(name, "sizeHi")) { | 1110 if(!strcmp(name, "sizeHi")) { |
1111 return GINT_TO_POINTER(ctx->sizeHi); | 1111 return GINT_TO_POINTER(ctx->sizeHi); |
1112 } else if(!strcmp(name, "sizeLo")) { | 1112 } else if(!strcmp(name, "sizeLo")) { |
1113 return GINT_TO_POINTER(ctx->sizeLo); | 1113 return GINT_TO_POINTER(ctx->sizeLo); |
1117 | 1117 |
1118 return NULL; | 1118 return NULL; |
1119 } | 1119 } |
1120 | 1120 |
1121 static void | 1121 static void |
1122 sha1_init(GaimCipherContext *context, void *extra) { | 1122 sha1_init(PurpleCipherContext *context, void *extra) { |
1123 struct SHA1Context *sha1_ctx; | 1123 struct SHA1Context *sha1_ctx; |
1124 | 1124 |
1125 sha1_ctx = g_new0(struct SHA1Context, 1); | 1125 sha1_ctx = g_new0(struct SHA1Context, 1); |
1126 | 1126 |
1127 gaim_cipher_context_set_data(context, sha1_ctx); | 1127 purple_cipher_context_set_data(context, sha1_ctx); |
1128 | 1128 |
1129 gaim_cipher_context_reset(context, extra); | 1129 purple_cipher_context_reset(context, extra); |
1130 } | 1130 } |
1131 | 1131 |
1132 static void | 1132 static void |
1133 sha1_reset(GaimCipherContext *context, void *extra) { | 1133 sha1_reset(PurpleCipherContext *context, void *extra) { |
1134 struct SHA1Context *sha1_ctx; | 1134 struct SHA1Context *sha1_ctx; |
1135 gint i; | 1135 gint i; |
1136 | 1136 |
1137 sha1_ctx = gaim_cipher_context_get_data(context); | 1137 sha1_ctx = purple_cipher_context_get_data(context); |
1138 | 1138 |
1139 g_return_if_fail(sha1_ctx); | 1139 g_return_if_fail(sha1_ctx); |
1140 | 1140 |
1141 sha1_ctx->lenW = 0; | 1141 sha1_ctx->lenW = 0; |
1142 sha1_ctx->sizeHi = 0; | 1142 sha1_ctx->sizeHi = 0; |
1151 for(i = 0; i < 80; i++) | 1151 for(i = 0; i < 80; i++) |
1152 sha1_ctx->W[i] = 0; | 1152 sha1_ctx->W[i] = 0; |
1153 } | 1153 } |
1154 | 1154 |
1155 static void | 1155 static void |
1156 sha1_uninit(GaimCipherContext *context) { | 1156 sha1_uninit(PurpleCipherContext *context) { |
1157 struct SHA1Context *sha1_ctx; | 1157 struct SHA1Context *sha1_ctx; |
1158 | 1158 |
1159 gaim_cipher_context_reset(context, NULL); | 1159 purple_cipher_context_reset(context, NULL); |
1160 | 1160 |
1161 sha1_ctx = gaim_cipher_context_get_data(context); | 1161 sha1_ctx = purple_cipher_context_get_data(context); |
1162 | 1162 |
1163 memset(sha1_ctx, 0, sizeof(struct SHA1Context)); | 1163 memset(sha1_ctx, 0, sizeof(struct SHA1Context)); |
1164 | 1164 |
1165 g_free(sha1_ctx); | 1165 g_free(sha1_ctx); |
1166 sha1_ctx = NULL; | 1166 sha1_ctx = NULL; |
1167 } | 1167 } |
1168 | 1168 |
1169 | 1169 |
1170 static void | 1170 static void |
1171 sha1_append(GaimCipherContext *context, const guchar *data, size_t len) { | 1171 sha1_append(PurpleCipherContext *context, const guchar *data, size_t len) { |
1172 struct SHA1Context *sha1_ctx; | 1172 struct SHA1Context *sha1_ctx; |
1173 gint i; | 1173 gint i; |
1174 | 1174 |
1175 sha1_ctx = gaim_cipher_context_get_data(context); | 1175 sha1_ctx = purple_cipher_context_get_data(context); |
1176 | 1176 |
1177 g_return_if_fail(sha1_ctx); | 1177 g_return_if_fail(sha1_ctx); |
1178 | 1178 |
1179 for(i = 0; i < len; i++) { | 1179 for(i = 0; i < len; i++) { |
1180 sha1_ctx->W[sha1_ctx->lenW / 4] <<= 8; | 1180 sha1_ctx->W[sha1_ctx->lenW / 4] <<= 8; |
1189 sha1_ctx->sizeHi += (sha1_ctx->sizeLo < 8); | 1189 sha1_ctx->sizeHi += (sha1_ctx->sizeLo < 8); |
1190 } | 1190 } |
1191 } | 1191 } |
1192 | 1192 |
1193 static gboolean | 1193 static gboolean |
1194 sha1_digest(GaimCipherContext *context, size_t in_len, guchar digest[20], | 1194 sha1_digest(PurpleCipherContext *context, size_t in_len, guchar digest[20], |
1195 size_t *out_len) | 1195 size_t *out_len) |
1196 { | 1196 { |
1197 struct SHA1Context *sha1_ctx; | 1197 struct SHA1Context *sha1_ctx; |
1198 guchar pad0x80 = 0x80, pad0x00 = 0x00; | 1198 guchar pad0x80 = 0x80, pad0x00 = 0x00; |
1199 guchar padlen[8]; | 1199 guchar padlen[8]; |
1200 gint i; | 1200 gint i; |
1201 | 1201 |
1202 g_return_val_if_fail(in_len >= 20, FALSE); | 1202 g_return_val_if_fail(in_len >= 20, FALSE); |
1203 | 1203 |
1204 sha1_ctx = gaim_cipher_context_get_data(context); | 1204 sha1_ctx = purple_cipher_context_get_data(context); |
1205 | 1205 |
1206 g_return_val_if_fail(sha1_ctx, FALSE); | 1206 g_return_val_if_fail(sha1_ctx, FALSE); |
1207 | 1207 |
1208 padlen[0] = (guchar)((sha1_ctx->sizeHi >> 24) & 255); | 1208 padlen[0] = (guchar)((sha1_ctx->sizeHi >> 24) & 255); |
1209 padlen[1] = (guchar)((sha1_ctx->sizeHi >> 16) & 255); | 1209 padlen[1] = (guchar)((sha1_ctx->sizeHi >> 16) & 255); |
1213 padlen[5] = (guchar)((sha1_ctx->sizeLo >> 16) & 255); | 1213 padlen[5] = (guchar)((sha1_ctx->sizeLo >> 16) & 255); |
1214 padlen[6] = (guchar)((sha1_ctx->sizeLo >> 8) & 255); | 1214 padlen[6] = (guchar)((sha1_ctx->sizeLo >> 8) & 255); |
1215 padlen[7] = (guchar)((sha1_ctx->sizeLo >> 0) & 255); | 1215 padlen[7] = (guchar)((sha1_ctx->sizeLo >> 0) & 255); |
1216 | 1216 |
1217 /* pad with a 1, then zeroes, then length */ | 1217 /* pad with a 1, then zeroes, then length */ |
1218 gaim_cipher_context_append(context, &pad0x80, 1); | 1218 purple_cipher_context_append(context, &pad0x80, 1); |
1219 while(sha1_ctx->lenW != 56) | 1219 while(sha1_ctx->lenW != 56) |
1220 gaim_cipher_context_append(context, &pad0x00, 1); | 1220 purple_cipher_context_append(context, &pad0x00, 1); |
1221 gaim_cipher_context_append(context, padlen, 8); | 1221 purple_cipher_context_append(context, padlen, 8); |
1222 | 1222 |
1223 for(i = 0; i < 20; i++) { | 1223 for(i = 0; i < 20; i++) { |
1224 digest[i] = (guchar)(sha1_ctx->H[i / 4] >> 24); | 1224 digest[i] = (guchar)(sha1_ctx->H[i / 4] >> 24); |
1225 sha1_ctx->H[i / 4] <<= 8; | 1225 sha1_ctx->H[i / 4] <<= 8; |
1226 } | 1226 } |
1227 | 1227 |
1228 gaim_cipher_context_reset(context, NULL); | 1228 purple_cipher_context_reset(context, NULL); |
1229 | 1229 |
1230 if(out_len) | 1230 if(out_len) |
1231 *out_len = 20; | 1231 *out_len = 20; |
1232 | 1232 |
1233 return TRUE; | 1233 return TRUE; |
1234 } | 1234 } |
1235 | 1235 |
1236 static GaimCipherOps SHA1Ops = { | 1236 static PurpleCipherOps SHA1Ops = { |
1237 sha1_set_opt, /* Set Option */ | 1237 sha1_set_opt, /* Set Option */ |
1238 sha1_get_opt, /* Get Option */ | 1238 sha1_get_opt, /* Get Option */ |
1239 sha1_init, /* init */ | 1239 sha1_init, /* init */ |
1240 sha1_reset, /* reset */ | 1240 sha1_reset, /* reset */ |
1241 sha1_uninit, /* uninit */ | 1241 sha1_uninit, /* uninit */ |
1251 }; | 1251 }; |
1252 | 1252 |
1253 /******************************************************************************* | 1253 /******************************************************************************* |
1254 * Structs | 1254 * Structs |
1255 ******************************************************************************/ | 1255 ******************************************************************************/ |
1256 struct _GaimCipher { | 1256 struct _PurpleCipher { |
1257 gchar *name; | 1257 gchar *name; |
1258 GaimCipherOps *ops; | 1258 PurpleCipherOps *ops; |
1259 guint ref; | 1259 guint ref; |
1260 }; | 1260 }; |
1261 | 1261 |
1262 struct _GaimCipherContext { | 1262 struct _PurpleCipherContext { |
1263 GaimCipher *cipher; | 1263 PurpleCipher *cipher; |
1264 gpointer data; | 1264 gpointer data; |
1265 }; | 1265 }; |
1266 | 1266 |
1267 /****************************************************************************** | 1267 /****************************************************************************** |
1268 * Globals | 1268 * Globals |
1269 *****************************************************************************/ | 1269 *****************************************************************************/ |
1270 static GList *ciphers = NULL; | 1270 static GList *ciphers = NULL; |
1271 | 1271 |
1272 /****************************************************************************** | 1272 /****************************************************************************** |
1273 * GaimCipher API | 1273 * PurpleCipher API |
1274 *****************************************************************************/ | 1274 *****************************************************************************/ |
1275 const gchar * | 1275 const gchar * |
1276 gaim_cipher_get_name(GaimCipher *cipher) { | 1276 purple_cipher_get_name(PurpleCipher *cipher) { |
1277 g_return_val_if_fail(cipher, NULL); | 1277 g_return_val_if_fail(cipher, NULL); |
1278 | 1278 |
1279 return cipher->name; | 1279 return cipher->name; |
1280 } | 1280 } |
1281 | 1281 |
1282 guint | 1282 guint |
1283 gaim_cipher_get_capabilities(GaimCipher *cipher) { | 1283 purple_cipher_get_capabilities(PurpleCipher *cipher) { |
1284 GaimCipherOps *ops = NULL; | 1284 PurpleCipherOps *ops = NULL; |
1285 guint caps = 0; | 1285 guint caps = 0; |
1286 | 1286 |
1287 g_return_val_if_fail(cipher, 0); | 1287 g_return_val_if_fail(cipher, 0); |
1288 | 1288 |
1289 ops = cipher->ops; | 1289 ops = cipher->ops; |
1290 g_return_val_if_fail(ops, 0); | 1290 g_return_val_if_fail(ops, 0); |
1291 | 1291 |
1292 if(ops->set_option) | 1292 if(ops->set_option) |
1293 caps |= GAIM_CIPHER_CAPS_SET_OPT; | 1293 caps |= PURPLE_CIPHER_CAPS_SET_OPT; |
1294 if(ops->get_option) | 1294 if(ops->get_option) |
1295 caps |= GAIM_CIPHER_CAPS_GET_OPT; | 1295 caps |= PURPLE_CIPHER_CAPS_GET_OPT; |
1296 if(ops->init) | 1296 if(ops->init) |
1297 caps |= GAIM_CIPHER_CAPS_INIT; | 1297 caps |= PURPLE_CIPHER_CAPS_INIT; |
1298 if(ops->reset) | 1298 if(ops->reset) |
1299 caps |= GAIM_CIPHER_CAPS_RESET; | 1299 caps |= PURPLE_CIPHER_CAPS_RESET; |
1300 if(ops->uninit) | 1300 if(ops->uninit) |
1301 caps |= GAIM_CIPHER_CAPS_UNINIT; | 1301 caps |= PURPLE_CIPHER_CAPS_UNINIT; |
1302 if(ops->set_iv) | 1302 if(ops->set_iv) |
1303 caps |= GAIM_CIPHER_CAPS_SET_IV; | 1303 caps |= PURPLE_CIPHER_CAPS_SET_IV; |
1304 if(ops->append) | 1304 if(ops->append) |
1305 caps |= GAIM_CIPHER_CAPS_APPEND; | 1305 caps |= PURPLE_CIPHER_CAPS_APPEND; |
1306 if(ops->digest) | 1306 if(ops->digest) |
1307 caps |= GAIM_CIPHER_CAPS_DIGEST; | 1307 caps |= PURPLE_CIPHER_CAPS_DIGEST; |
1308 if(ops->encrypt) | 1308 if(ops->encrypt) |
1309 caps |= GAIM_CIPHER_CAPS_ENCRYPT; | 1309 caps |= PURPLE_CIPHER_CAPS_ENCRYPT; |
1310 if(ops->decrypt) | 1310 if(ops->decrypt) |
1311 caps |= GAIM_CIPHER_CAPS_DECRYPT; | 1311 caps |= PURPLE_CIPHER_CAPS_DECRYPT; |
1312 if(ops->set_salt) | 1312 if(ops->set_salt) |
1313 caps |= GAIM_CIPHER_CAPS_SET_SALT; | 1313 caps |= PURPLE_CIPHER_CAPS_SET_SALT; |
1314 if(ops->get_salt_size) | 1314 if(ops->get_salt_size) |
1315 caps |= GAIM_CIPHER_CAPS_GET_SALT_SIZE; | 1315 caps |= PURPLE_CIPHER_CAPS_GET_SALT_SIZE; |
1316 if(ops->set_key) | 1316 if(ops->set_key) |
1317 caps |= GAIM_CIPHER_CAPS_SET_KEY; | 1317 caps |= PURPLE_CIPHER_CAPS_SET_KEY; |
1318 if(ops->get_key_size) | 1318 if(ops->get_key_size) |
1319 caps |= GAIM_CIPHER_CAPS_GET_KEY_SIZE; | 1319 caps |= PURPLE_CIPHER_CAPS_GET_KEY_SIZE; |
1320 | 1320 |
1321 return caps; | 1321 return caps; |
1322 } | 1322 } |
1323 | 1323 |
1324 gboolean | 1324 gboolean |
1325 gaim_cipher_digest_region(const gchar *name, const guchar *data, | 1325 purple_cipher_digest_region(const gchar *name, const guchar *data, |
1326 size_t data_len, size_t in_len, | 1326 size_t data_len, size_t in_len, |
1327 guchar digest[], size_t *out_len) | 1327 guchar digest[], size_t *out_len) |
1328 { | 1328 { |
1329 GaimCipher *cipher; | 1329 PurpleCipher *cipher; |
1330 GaimCipherContext *context; | 1330 PurpleCipherContext *context; |
1331 gboolean ret = FALSE; | 1331 gboolean ret = FALSE; |
1332 | 1332 |
1333 g_return_val_if_fail(name, FALSE); | 1333 g_return_val_if_fail(name, FALSE); |
1334 g_return_val_if_fail(data, FALSE); | 1334 g_return_val_if_fail(data, FALSE); |
1335 | 1335 |
1336 cipher = gaim_ciphers_find_cipher(name); | 1336 cipher = purple_ciphers_find_cipher(name); |
1337 | 1337 |
1338 g_return_val_if_fail(cipher, FALSE); | 1338 g_return_val_if_fail(cipher, FALSE); |
1339 | 1339 |
1340 if(!cipher->ops->append || !cipher->ops->digest) { | 1340 if(!cipher->ops->append || !cipher->ops->digest) { |
1341 gaim_debug_info("cipher", "gaim_cipher_region failed: " | 1341 purple_debug_info("cipher", "purple_cipher_region failed: " |
1342 "the %s cipher does not support appending and or " | 1342 "the %s cipher does not support appending and or " |
1343 "digesting.", cipher->name); | 1343 "digesting.", cipher->name); |
1344 return FALSE; | 1344 return FALSE; |
1345 } | 1345 } |
1346 | 1346 |
1347 context = gaim_cipher_context_new(cipher, NULL); | 1347 context = purple_cipher_context_new(cipher, NULL); |
1348 gaim_cipher_context_append(context, data, data_len); | 1348 purple_cipher_context_append(context, data, data_len); |
1349 ret = gaim_cipher_context_digest(context, in_len, digest, out_len); | 1349 ret = purple_cipher_context_digest(context, in_len, digest, out_len); |
1350 gaim_cipher_context_destroy(context); | 1350 purple_cipher_context_destroy(context); |
1351 | 1351 |
1352 return ret; | 1352 return ret; |
1353 } | 1353 } |
1354 | 1354 |
1355 /****************************************************************************** | 1355 /****************************************************************************** |
1356 * GaimCiphers API | 1356 * PurpleCiphers API |
1357 *****************************************************************************/ | 1357 *****************************************************************************/ |
1358 GaimCipher * | 1358 PurpleCipher * |
1359 gaim_ciphers_find_cipher(const gchar *name) { | 1359 purple_ciphers_find_cipher(const gchar *name) { |
1360 GaimCipher *cipher; | 1360 PurpleCipher *cipher; |
1361 GList *l; | 1361 GList *l; |
1362 | 1362 |
1363 g_return_val_if_fail(name, NULL); | 1363 g_return_val_if_fail(name, NULL); |
1364 | 1364 |
1365 for(l = ciphers; l; l = l->next) { | 1365 for(l = ciphers; l; l = l->next) { |
1366 cipher = GAIM_CIPHER(l->data); | 1366 cipher = PURPLE_CIPHER(l->data); |
1367 | 1367 |
1368 if(!g_ascii_strcasecmp(cipher->name, name)) | 1368 if(!g_ascii_strcasecmp(cipher->name, name)) |
1369 return cipher; | 1369 return cipher; |
1370 } | 1370 } |
1371 | 1371 |
1372 return NULL; | 1372 return NULL; |
1373 } | 1373 } |
1374 | 1374 |
1375 GaimCipher * | 1375 PurpleCipher * |
1376 gaim_ciphers_register_cipher(const gchar *name, GaimCipherOps *ops) { | 1376 purple_ciphers_register_cipher(const gchar *name, PurpleCipherOps *ops) { |
1377 GaimCipher *cipher = NULL; | 1377 PurpleCipher *cipher = NULL; |
1378 | 1378 |
1379 g_return_val_if_fail(name, NULL); | 1379 g_return_val_if_fail(name, NULL); |
1380 g_return_val_if_fail(ops, NULL); | 1380 g_return_val_if_fail(ops, NULL); |
1381 g_return_val_if_fail(!gaim_ciphers_find_cipher(name), NULL); | 1381 g_return_val_if_fail(!purple_ciphers_find_cipher(name), NULL); |
1382 | 1382 |
1383 cipher = g_new0(GaimCipher, 1); | 1383 cipher = g_new0(PurpleCipher, 1); |
1384 GAIM_DBUS_REGISTER_POINTER(cipher, GaimCipher); | 1384 PURPLE_DBUS_REGISTER_POINTER(cipher, PurpleCipher); |
1385 | 1385 |
1386 cipher->name = g_strdup(name); | 1386 cipher->name = g_strdup(name); |
1387 cipher->ops = ops; | 1387 cipher->ops = ops; |
1388 | 1388 |
1389 ciphers = g_list_append(ciphers, cipher); | 1389 ciphers = g_list_append(ciphers, cipher); |
1390 | 1390 |
1391 gaim_signal_emit(gaim_ciphers_get_handle(), "cipher-added", cipher); | 1391 purple_signal_emit(purple_ciphers_get_handle(), "cipher-added", cipher); |
1392 | 1392 |
1393 return cipher; | 1393 return cipher; |
1394 } | 1394 } |
1395 | 1395 |
1396 gboolean | 1396 gboolean |
1397 gaim_ciphers_unregister_cipher(GaimCipher *cipher) { | 1397 purple_ciphers_unregister_cipher(PurpleCipher *cipher) { |
1398 g_return_val_if_fail(cipher, FALSE); | 1398 g_return_val_if_fail(cipher, FALSE); |
1399 g_return_val_if_fail(cipher->ref == 0, FALSE); | 1399 g_return_val_if_fail(cipher->ref == 0, FALSE); |
1400 | 1400 |
1401 gaim_signal_emit(gaim_ciphers_get_handle(), "cipher-removed", cipher); | 1401 purple_signal_emit(purple_ciphers_get_handle(), "cipher-removed", cipher); |
1402 | 1402 |
1403 ciphers = g_list_remove(ciphers, cipher); | 1403 ciphers = g_list_remove(ciphers, cipher); |
1404 | 1404 |
1405 g_free(cipher->name); | 1405 g_free(cipher->name); |
1406 | 1406 |
1407 GAIM_DBUS_UNREGISTER_POINTER(cipher); | 1407 PURPLE_DBUS_UNREGISTER_POINTER(cipher); |
1408 g_free(cipher); | 1408 g_free(cipher); |
1409 | 1409 |
1410 return TRUE; | 1410 return TRUE; |
1411 } | 1411 } |
1412 | 1412 |
1413 GList * | 1413 GList * |
1414 gaim_ciphers_get_ciphers() { | 1414 purple_ciphers_get_ciphers() { |
1415 return ciphers; | 1415 return ciphers; |
1416 } | 1416 } |
1417 | 1417 |
1418 /****************************************************************************** | 1418 /****************************************************************************** |
1419 * GaimCipher Subsystem API | 1419 * PurpleCipher Subsystem API |
1420 *****************************************************************************/ | 1420 *****************************************************************************/ |
1421 gpointer | 1421 gpointer |
1422 gaim_ciphers_get_handle() { | 1422 purple_ciphers_get_handle() { |
1423 static gint handle; | 1423 static gint handle; |
1424 | 1424 |
1425 return &handle; | 1425 return &handle; |
1426 } | 1426 } |
1427 | 1427 |
1428 void | 1428 void |
1429 gaim_ciphers_init() { | 1429 purple_ciphers_init() { |
1430 gpointer handle; | 1430 gpointer handle; |
1431 | 1431 |
1432 handle = gaim_ciphers_get_handle(); | 1432 handle = purple_ciphers_get_handle(); |
1433 | 1433 |
1434 gaim_signal_register(handle, "cipher-added", | 1434 purple_signal_register(handle, "cipher-added", |
1435 gaim_marshal_VOID__POINTER, NULL, 1, | 1435 purple_marshal_VOID__POINTER, NULL, 1, |
1436 gaim_value_new(GAIM_TYPE_SUBTYPE, | 1436 purple_value_new(PURPLE_TYPE_SUBTYPE, |
1437 GAIM_SUBTYPE_CIPHER)); | 1437 PURPLE_SUBTYPE_CIPHER)); |
1438 gaim_signal_register(handle, "cipher-removed", | 1438 purple_signal_register(handle, "cipher-removed", |
1439 gaim_marshal_VOID__POINTER, NULL, 1, | 1439 purple_marshal_VOID__POINTER, NULL, 1, |
1440 gaim_value_new(GAIM_TYPE_SUBTYPE, | 1440 purple_value_new(PURPLE_TYPE_SUBTYPE, |
1441 GAIM_SUBTYPE_CIPHER)); | 1441 PURPLE_SUBTYPE_CIPHER)); |
1442 | 1442 |
1443 gaim_ciphers_register_cipher("md5", &MD5Ops); | 1443 purple_ciphers_register_cipher("md5", &MD5Ops); |
1444 gaim_ciphers_register_cipher("sha1", &SHA1Ops); | 1444 purple_ciphers_register_cipher("sha1", &SHA1Ops); |
1445 gaim_ciphers_register_cipher("md4", &MD4Ops); | 1445 purple_ciphers_register_cipher("md4", &MD4Ops); |
1446 gaim_ciphers_register_cipher("des", &DESOps); | 1446 purple_ciphers_register_cipher("des", &DESOps); |
1447 } | 1447 } |
1448 | 1448 |
1449 void | 1449 void |
1450 gaim_ciphers_uninit() { | 1450 purple_ciphers_uninit() { |
1451 GaimCipher *cipher; | 1451 PurpleCipher *cipher; |
1452 GList *l, *ll; | 1452 GList *l, *ll; |
1453 | 1453 |
1454 for(l = ciphers; l; l = ll) { | 1454 for(l = ciphers; l; l = ll) { |
1455 ll = l->next; | 1455 ll = l->next; |
1456 | 1456 |
1457 cipher = GAIM_CIPHER(l->data); | 1457 cipher = PURPLE_CIPHER(l->data); |
1458 gaim_ciphers_unregister_cipher(cipher); | 1458 purple_ciphers_unregister_cipher(cipher); |
1459 | 1459 |
1460 ciphers = g_list_remove(ciphers, cipher); | 1460 ciphers = g_list_remove(ciphers, cipher); |
1461 } | 1461 } |
1462 | 1462 |
1463 g_list_free(ciphers); | 1463 g_list_free(ciphers); |
1464 | 1464 |
1465 gaim_signals_unregister_by_instance(gaim_ciphers_get_handle()); | 1465 purple_signals_unregister_by_instance(purple_ciphers_get_handle()); |
1466 } | 1466 } |
1467 /****************************************************************************** | 1467 /****************************************************************************** |
1468 * GaimCipherContext API | 1468 * PurpleCipherContext API |
1469 *****************************************************************************/ | 1469 *****************************************************************************/ |
1470 void | 1470 void |
1471 gaim_cipher_context_set_option(GaimCipherContext *context, const gchar *name, | 1471 purple_cipher_context_set_option(PurpleCipherContext *context, const gchar *name, |
1472 gpointer value) | 1472 gpointer value) |
1473 { | 1473 { |
1474 GaimCipher *cipher = NULL; | 1474 PurpleCipher *cipher = NULL; |
1475 | 1475 |
1476 g_return_if_fail(context); | 1476 g_return_if_fail(context); |
1477 g_return_if_fail(name); | 1477 g_return_if_fail(name); |
1478 | 1478 |
1479 cipher = context->cipher; | 1479 cipher = context->cipher; |
1480 g_return_if_fail(cipher); | 1480 g_return_if_fail(cipher); |
1481 | 1481 |
1482 if(cipher->ops && cipher->ops->set_option) | 1482 if(cipher->ops && cipher->ops->set_option) |
1483 cipher->ops->set_option(context, name, value); | 1483 cipher->ops->set_option(context, name, value); |
1484 else | 1484 else |
1485 gaim_debug_info("cipher", "the %s cipher does not support the " | 1485 purple_debug_info("cipher", "the %s cipher does not support the " |
1486 "set_option operation\n", cipher->name); | 1486 "set_option operation\n", cipher->name); |
1487 } | 1487 } |
1488 | 1488 |
1489 gpointer | 1489 gpointer |
1490 gaim_cipher_context_get_option(GaimCipherContext *context, const gchar *name) { | 1490 purple_cipher_context_get_option(PurpleCipherContext *context, const gchar *name) { |
1491 GaimCipher *cipher = NULL; | 1491 PurpleCipher *cipher = NULL; |
1492 | 1492 |
1493 g_return_val_if_fail(context, NULL); | 1493 g_return_val_if_fail(context, NULL); |
1494 g_return_val_if_fail(name, NULL); | 1494 g_return_val_if_fail(name, NULL); |
1495 | 1495 |
1496 cipher = context->cipher; | 1496 cipher = context->cipher; |
1497 g_return_val_if_fail(cipher, NULL); | 1497 g_return_val_if_fail(cipher, NULL); |
1498 | 1498 |
1499 if(cipher->ops && cipher->ops->get_option) | 1499 if(cipher->ops && cipher->ops->get_option) |
1500 return cipher->ops->get_option(context, name); | 1500 return cipher->ops->get_option(context, name); |
1501 else { | 1501 else { |
1502 gaim_debug_info("cipher", "the %s cipher does not support the " | 1502 purple_debug_info("cipher", "the %s cipher does not support the " |
1503 "get_option operation\n", cipher->name); | 1503 "get_option operation\n", cipher->name); |
1504 | 1504 |
1505 return NULL; | 1505 return NULL; |
1506 } | 1506 } |
1507 } | 1507 } |
1508 | 1508 |
1509 GaimCipherContext * | 1509 PurpleCipherContext * |
1510 gaim_cipher_context_new(GaimCipher *cipher, void *extra) { | 1510 purple_cipher_context_new(PurpleCipher *cipher, void *extra) { |
1511 GaimCipherContext *context = NULL; | 1511 PurpleCipherContext *context = NULL; |
1512 | 1512 |
1513 g_return_val_if_fail(cipher, NULL); | 1513 g_return_val_if_fail(cipher, NULL); |
1514 | 1514 |
1515 cipher->ref++; | 1515 cipher->ref++; |
1516 | 1516 |
1517 context = g_new0(GaimCipherContext, 1); | 1517 context = g_new0(PurpleCipherContext, 1); |
1518 context->cipher = cipher; | 1518 context->cipher = cipher; |
1519 | 1519 |
1520 if(cipher->ops->init) | 1520 if(cipher->ops->init) |
1521 cipher->ops->init(context, extra); | 1521 cipher->ops->init(context, extra); |
1522 | 1522 |
1523 return context; | 1523 return context; |
1524 } | 1524 } |
1525 | 1525 |
1526 GaimCipherContext * | 1526 PurpleCipherContext * |
1527 gaim_cipher_context_new_by_name(const gchar *name, void *extra) { | 1527 purple_cipher_context_new_by_name(const gchar *name, void *extra) { |
1528 GaimCipher *cipher; | 1528 PurpleCipher *cipher; |
1529 | 1529 |
1530 g_return_val_if_fail(name, NULL); | 1530 g_return_val_if_fail(name, NULL); |
1531 | 1531 |
1532 cipher = gaim_ciphers_find_cipher(name); | 1532 cipher = purple_ciphers_find_cipher(name); |
1533 | 1533 |
1534 g_return_val_if_fail(cipher, NULL); | 1534 g_return_val_if_fail(cipher, NULL); |
1535 | 1535 |
1536 return gaim_cipher_context_new(cipher, extra); | 1536 return purple_cipher_context_new(cipher, extra); |
1537 } | 1537 } |
1538 | 1538 |
1539 void | 1539 void |
1540 gaim_cipher_context_reset(GaimCipherContext *context, void *extra) { | 1540 purple_cipher_context_reset(PurpleCipherContext *context, void *extra) { |
1541 GaimCipher *cipher = NULL; | 1541 PurpleCipher *cipher = NULL; |
1542 | 1542 |
1543 g_return_if_fail(context); | 1543 g_return_if_fail(context); |
1544 | 1544 |
1545 cipher = context->cipher; | 1545 cipher = context->cipher; |
1546 g_return_if_fail(cipher); | 1546 g_return_if_fail(cipher); |
1548 if(cipher->ops && cipher->ops->reset) | 1548 if(cipher->ops && cipher->ops->reset) |
1549 context->cipher->ops->reset(context, extra); | 1549 context->cipher->ops->reset(context, extra); |
1550 } | 1550 } |
1551 | 1551 |
1552 void | 1552 void |
1553 gaim_cipher_context_destroy(GaimCipherContext *context) { | 1553 purple_cipher_context_destroy(PurpleCipherContext *context) { |
1554 GaimCipher *cipher = NULL; | 1554 PurpleCipher *cipher = NULL; |
1555 | 1555 |
1556 g_return_if_fail(context); | 1556 g_return_if_fail(context); |
1557 | 1557 |
1558 cipher = context->cipher; | 1558 cipher = context->cipher; |
1559 g_return_if_fail(cipher); | 1559 g_return_if_fail(cipher); |
1567 g_free(context); | 1567 g_free(context); |
1568 context = NULL; | 1568 context = NULL; |
1569 } | 1569 } |
1570 | 1570 |
1571 void | 1571 void |
1572 gaim_cipher_context_set_iv(GaimCipherContext *context, guchar *iv, size_t len) | 1572 purple_cipher_context_set_iv(PurpleCipherContext *context, guchar *iv, size_t len) |
1573 { | 1573 { |
1574 GaimCipher *cipher = NULL; | 1574 PurpleCipher *cipher = NULL; |
1575 | 1575 |
1576 g_return_if_fail(context); | 1576 g_return_if_fail(context); |
1577 g_return_if_fail(iv); | 1577 g_return_if_fail(iv); |
1578 | 1578 |
1579 cipher = context->cipher; | 1579 cipher = context->cipher; |
1580 g_return_if_fail(cipher); | 1580 g_return_if_fail(cipher); |
1581 | 1581 |
1582 if(cipher->ops && cipher->ops->set_iv) | 1582 if(cipher->ops && cipher->ops->set_iv) |
1583 cipher->ops->set_iv(context, iv, len); | 1583 cipher->ops->set_iv(context, iv, len); |
1584 else | 1584 else |
1585 gaim_debug_info("cipher", "the %s cipher does not support the set" | 1585 purple_debug_info("cipher", "the %s cipher does not support the set" |
1586 "initialization vector operation\n", cipher->name); | 1586 "initialization vector operation\n", cipher->name); |
1587 } | 1587 } |
1588 | 1588 |
1589 void | 1589 void |
1590 gaim_cipher_context_append(GaimCipherContext *context, const guchar *data, | 1590 purple_cipher_context_append(PurpleCipherContext *context, const guchar *data, |
1591 size_t len) | 1591 size_t len) |
1592 { | 1592 { |
1593 GaimCipher *cipher = NULL; | 1593 PurpleCipher *cipher = NULL; |
1594 | 1594 |
1595 g_return_if_fail(context); | 1595 g_return_if_fail(context); |
1596 | 1596 |
1597 cipher = context->cipher; | 1597 cipher = context->cipher; |
1598 g_return_if_fail(cipher); | 1598 g_return_if_fail(cipher); |
1599 | 1599 |
1600 if(cipher->ops && cipher->ops->append) | 1600 if(cipher->ops && cipher->ops->append) |
1601 cipher->ops->append(context, data, len); | 1601 cipher->ops->append(context, data, len); |
1602 else | 1602 else |
1603 gaim_debug_info("cipher", "the %s cipher does not support the append " | 1603 purple_debug_info("cipher", "the %s cipher does not support the append " |
1604 "operation\n", cipher->name); | 1604 "operation\n", cipher->name); |
1605 } | 1605 } |
1606 | 1606 |
1607 gboolean | 1607 gboolean |
1608 gaim_cipher_context_digest(GaimCipherContext *context, size_t in_len, | 1608 purple_cipher_context_digest(PurpleCipherContext *context, size_t in_len, |
1609 guchar digest[], size_t *out_len) | 1609 guchar digest[], size_t *out_len) |
1610 { | 1610 { |
1611 GaimCipher *cipher = NULL; | 1611 PurpleCipher *cipher = NULL; |
1612 | 1612 |
1613 g_return_val_if_fail(context, FALSE); | 1613 g_return_val_if_fail(context, FALSE); |
1614 | 1614 |
1615 cipher = context->cipher; | 1615 cipher = context->cipher; |
1616 g_return_val_if_fail(context, FALSE); | 1616 g_return_val_if_fail(context, FALSE); |
1617 | 1617 |
1618 if(cipher->ops && cipher->ops->digest) | 1618 if(cipher->ops && cipher->ops->digest) |
1619 return cipher->ops->digest(context, in_len, digest, out_len); | 1619 return cipher->ops->digest(context, in_len, digest, out_len); |
1620 else { | 1620 else { |
1621 gaim_debug_info("cipher", "the %s cipher does not support the digest " | 1621 purple_debug_info("cipher", "the %s cipher does not support the digest " |
1622 "operation\n", cipher->name); | 1622 "operation\n", cipher->name); |
1623 return FALSE; | 1623 return FALSE; |
1624 } | 1624 } |
1625 } | 1625 } |
1626 | 1626 |
1627 gboolean | 1627 gboolean |
1628 gaim_cipher_context_digest_to_str(GaimCipherContext *context, size_t in_len, | 1628 purple_cipher_context_digest_to_str(PurpleCipherContext *context, size_t in_len, |
1629 gchar digest_s[], size_t *out_len) | 1629 gchar digest_s[], size_t *out_len) |
1630 { | 1630 { |
1631 /* 8k is a bit excessive, will tweak later. */ | 1631 /* 8k is a bit excessive, will tweak later. */ |
1632 guchar digest[BUF_LEN * 4]; | 1632 guchar digest[BUF_LEN * 4]; |
1633 gint n = 0; | 1633 gint n = 0; |
1634 size_t dlen = 0; | 1634 size_t dlen = 0; |
1635 | 1635 |
1636 g_return_val_if_fail(context, FALSE); | 1636 g_return_val_if_fail(context, FALSE); |
1637 g_return_val_if_fail(digest_s, FALSE); | 1637 g_return_val_if_fail(digest_s, FALSE); |
1638 | 1638 |
1639 if(!gaim_cipher_context_digest(context, sizeof(digest), digest, &dlen)) | 1639 if(!purple_cipher_context_digest(context, sizeof(digest), digest, &dlen)) |
1640 return FALSE; | 1640 return FALSE; |
1641 | 1641 |
1642 /* in_len must be greater than dlen * 2 so we have room for the NUL. */ | 1642 /* in_len must be greater than dlen * 2 so we have room for the NUL. */ |
1643 if(in_len <= dlen * 2) | 1643 if(in_len <= dlen * 2) |
1644 return FALSE; | 1644 return FALSE; |
1653 | 1653 |
1654 return TRUE; | 1654 return TRUE; |
1655 } | 1655 } |
1656 | 1656 |
1657 gint | 1657 gint |
1658 gaim_cipher_context_encrypt(GaimCipherContext *context, const guchar data[], | 1658 purple_cipher_context_encrypt(PurpleCipherContext *context, const guchar data[], |
1659 size_t len, guchar output[], size_t *outlen) | 1659 size_t len, guchar output[], size_t *outlen) |
1660 { | 1660 { |
1661 GaimCipher *cipher = NULL; | 1661 PurpleCipher *cipher = NULL; |
1662 | 1662 |
1663 g_return_val_if_fail(context, -1); | 1663 g_return_val_if_fail(context, -1); |
1664 | 1664 |
1665 cipher = context->cipher; | 1665 cipher = context->cipher; |
1666 g_return_val_if_fail(cipher, -1); | 1666 g_return_val_if_fail(cipher, -1); |
1667 | 1667 |
1668 if(cipher->ops && cipher->ops->encrypt) | 1668 if(cipher->ops && cipher->ops->encrypt) |
1669 return cipher->ops->encrypt(context, data, len, output, outlen); | 1669 return cipher->ops->encrypt(context, data, len, output, outlen); |
1670 else { | 1670 else { |
1671 gaim_debug_info("cipher", "the %s cipher does not support the encrypt" | 1671 purple_debug_info("cipher", "the %s cipher does not support the encrypt" |
1672 "operation\n", cipher->name); | 1672 "operation\n", cipher->name); |
1673 | 1673 |
1674 if(outlen) | 1674 if(outlen) |
1675 *outlen = -1; | 1675 *outlen = -1; |
1676 | 1676 |
1677 return -1; | 1677 return -1; |
1678 } | 1678 } |
1679 } | 1679 } |
1680 | 1680 |
1681 gint | 1681 gint |
1682 gaim_cipher_context_decrypt(GaimCipherContext *context, const guchar data[], | 1682 purple_cipher_context_decrypt(PurpleCipherContext *context, const guchar data[], |
1683 size_t len, guchar output[], size_t *outlen) | 1683 size_t len, guchar output[], size_t *outlen) |
1684 { | 1684 { |
1685 GaimCipher *cipher = NULL; | 1685 PurpleCipher *cipher = NULL; |
1686 | 1686 |
1687 g_return_val_if_fail(context, -1); | 1687 g_return_val_if_fail(context, -1); |
1688 | 1688 |
1689 cipher = context->cipher; | 1689 cipher = context->cipher; |
1690 g_return_val_if_fail(cipher, -1); | 1690 g_return_val_if_fail(cipher, -1); |
1691 | 1691 |
1692 if(cipher->ops && cipher->ops->decrypt) | 1692 if(cipher->ops && cipher->ops->decrypt) |
1693 return cipher->ops->decrypt(context, data, len, output, outlen); | 1693 return cipher->ops->decrypt(context, data, len, output, outlen); |
1694 else { | 1694 else { |
1695 gaim_debug_info("cipher", "the %s cipher does not support the decrypt" | 1695 purple_debug_info("cipher", "the %s cipher does not support the decrypt" |
1696 "operation\n", cipher->name); | 1696 "operation\n", cipher->name); |
1697 | 1697 |
1698 if(outlen) | 1698 if(outlen) |
1699 *outlen = -1; | 1699 *outlen = -1; |
1700 | 1700 |
1701 return -1; | 1701 return -1; |
1702 } | 1702 } |
1703 } | 1703 } |
1704 | 1704 |
1705 void | 1705 void |
1706 gaim_cipher_context_set_salt(GaimCipherContext *context, guchar *salt) { | 1706 purple_cipher_context_set_salt(PurpleCipherContext *context, guchar *salt) { |
1707 GaimCipher *cipher = NULL; | 1707 PurpleCipher *cipher = NULL; |
1708 | 1708 |
1709 g_return_if_fail(context); | 1709 g_return_if_fail(context); |
1710 | 1710 |
1711 cipher = context->cipher; | 1711 cipher = context->cipher; |
1712 g_return_if_fail(cipher); | 1712 g_return_if_fail(cipher); |
1713 | 1713 |
1714 if(cipher->ops && cipher->ops->set_salt) | 1714 if(cipher->ops && cipher->ops->set_salt) |
1715 cipher->ops->set_salt(context, salt); | 1715 cipher->ops->set_salt(context, salt); |
1716 else | 1716 else |
1717 gaim_debug_info("cipher", "the %s cipher does not support the " | 1717 purple_debug_info("cipher", "the %s cipher does not support the " |
1718 "set_salt operation\n", cipher->name); | 1718 "set_salt operation\n", cipher->name); |
1719 } | 1719 } |
1720 | 1720 |
1721 size_t | 1721 size_t |
1722 gaim_cipher_context_get_salt_size(GaimCipherContext *context) { | 1722 purple_cipher_context_get_salt_size(PurpleCipherContext *context) { |
1723 GaimCipher *cipher = NULL; | 1723 PurpleCipher *cipher = NULL; |
1724 | 1724 |
1725 g_return_val_if_fail(context, -1); | 1725 g_return_val_if_fail(context, -1); |
1726 | 1726 |
1727 cipher = context->cipher; | 1727 cipher = context->cipher; |
1728 g_return_val_if_fail(cipher, -1); | 1728 g_return_val_if_fail(cipher, -1); |
1729 | 1729 |
1730 if(cipher->ops && cipher->ops->get_salt_size) | 1730 if(cipher->ops && cipher->ops->get_salt_size) |
1731 return cipher->ops->get_salt_size(context); | 1731 return cipher->ops->get_salt_size(context); |
1732 else { | 1732 else { |
1733 gaim_debug_info("cipher", "the %s cipher does not support the " | 1733 purple_debug_info("cipher", "the %s cipher does not support the " |
1734 "get_salt_size operation\n", cipher->name); | 1734 "get_salt_size operation\n", cipher->name); |
1735 | 1735 |
1736 return -1; | 1736 return -1; |
1737 } | 1737 } |
1738 } | 1738 } |
1739 | 1739 |
1740 void | 1740 void |
1741 gaim_cipher_context_set_key(GaimCipherContext *context, const guchar *key) { | 1741 purple_cipher_context_set_key(PurpleCipherContext *context, const guchar *key) { |
1742 GaimCipher *cipher = NULL; | 1742 PurpleCipher *cipher = NULL; |
1743 | 1743 |
1744 g_return_if_fail(context); | 1744 g_return_if_fail(context); |
1745 | 1745 |
1746 cipher = context->cipher; | 1746 cipher = context->cipher; |
1747 g_return_if_fail(cipher); | 1747 g_return_if_fail(cipher); |
1748 | 1748 |
1749 if(cipher->ops && cipher->ops->set_key) | 1749 if(cipher->ops && cipher->ops->set_key) |
1750 cipher->ops->set_key(context, key); | 1750 cipher->ops->set_key(context, key); |
1751 else | 1751 else |
1752 gaim_debug_info("cipher", "the %s cipher does not support the " | 1752 purple_debug_info("cipher", "the %s cipher does not support the " |
1753 "set_key operation\n", cipher->name); | 1753 "set_key operation\n", cipher->name); |
1754 } | 1754 } |
1755 | 1755 |
1756 size_t | 1756 size_t |
1757 gaim_cipher_context_get_key_size(GaimCipherContext *context) { | 1757 purple_cipher_context_get_key_size(PurpleCipherContext *context) { |
1758 GaimCipher *cipher = NULL; | 1758 PurpleCipher *cipher = NULL; |
1759 | 1759 |
1760 g_return_val_if_fail(context, -1); | 1760 g_return_val_if_fail(context, -1); |
1761 | 1761 |
1762 cipher = context->cipher; | 1762 cipher = context->cipher; |
1763 g_return_val_if_fail(cipher, -1); | 1763 g_return_val_if_fail(cipher, -1); |
1764 | 1764 |
1765 if(cipher->ops && cipher->ops->get_key_size) | 1765 if(cipher->ops && cipher->ops->get_key_size) |
1766 return cipher->ops->get_key_size(context); | 1766 return cipher->ops->get_key_size(context); |
1767 else { | 1767 else { |
1768 gaim_debug_info("cipher", "the %s cipher does not support the " | 1768 purple_debug_info("cipher", "the %s cipher does not support the " |
1769 "get_key_size operation\n", cipher->name); | 1769 "get_key_size operation\n", cipher->name); |
1770 | 1770 |
1771 return -1; | 1771 return -1; |
1772 } | 1772 } |
1773 } | 1773 } |
1774 | 1774 |
1775 void | 1775 void |
1776 gaim_cipher_context_set_data(GaimCipherContext *context, gpointer data) { | 1776 purple_cipher_context_set_data(PurpleCipherContext *context, gpointer data) { |
1777 g_return_if_fail(context); | 1777 g_return_if_fail(context); |
1778 | 1778 |
1779 context->data = data; | 1779 context->data = data; |
1780 } | 1780 } |
1781 | 1781 |
1782 gpointer | 1782 gpointer |
1783 gaim_cipher_context_get_data(GaimCipherContext *context) { | 1783 purple_cipher_context_get_data(PurpleCipherContext *context) { |
1784 g_return_val_if_fail(context, NULL); | 1784 g_return_val_if_fail(context, NULL); |
1785 | 1785 |
1786 return context->data; | 1786 return context->data; |
1787 } | 1787 } |
1788 | 1788 |
1789 gchar *gaim_cipher_http_digest_calculate_session_key( | 1789 gchar *purple_cipher_http_digest_calculate_session_key( |
1790 const gchar *algorithm, | 1790 const gchar *algorithm, |
1791 const gchar *username, | 1791 const gchar *username, |
1792 const gchar *realm, | 1792 const gchar *realm, |
1793 const gchar *password, | 1793 const gchar *password, |
1794 const gchar *nonce, | 1794 const gchar *nonce, |
1795 const gchar *client_nonce) | 1795 const gchar *client_nonce) |
1796 { | 1796 { |
1797 GaimCipher *cipher; | 1797 PurpleCipher *cipher; |
1798 GaimCipherContext *context; | 1798 PurpleCipherContext *context; |
1799 gchar hash[33]; /* We only support MD5. */ | 1799 gchar hash[33]; /* We only support MD5. */ |
1800 | 1800 |
1801 g_return_val_if_fail(username != NULL, NULL); | 1801 g_return_val_if_fail(username != NULL, NULL); |
1802 g_return_val_if_fail(realm != NULL, NULL); | 1802 g_return_val_if_fail(realm != NULL, NULL); |
1803 g_return_val_if_fail(password != NULL, NULL); | 1803 g_return_val_if_fail(password != NULL, NULL); |
1807 g_return_val_if_fail(algorithm == NULL || | 1807 g_return_val_if_fail(algorithm == NULL || |
1808 *algorithm == '\0' || | 1808 *algorithm == '\0' || |
1809 strcasecmp(algorithm, "MD5") || | 1809 strcasecmp(algorithm, "MD5") || |
1810 strcasecmp(algorithm, "MD5-sess"), NULL); | 1810 strcasecmp(algorithm, "MD5-sess"), NULL); |
1811 | 1811 |
1812 cipher = gaim_ciphers_find_cipher("md5"); | 1812 cipher = purple_ciphers_find_cipher("md5"); |
1813 g_return_val_if_fail(cipher != NULL, NULL); | 1813 g_return_val_if_fail(cipher != NULL, NULL); |
1814 | 1814 |
1815 context = gaim_cipher_context_new(cipher, NULL); | 1815 context = purple_cipher_context_new(cipher, NULL); |
1816 | 1816 |
1817 gaim_cipher_context_append(context, (guchar *)username, strlen(username)); | 1817 purple_cipher_context_append(context, (guchar *)username, strlen(username)); |
1818 gaim_cipher_context_append(context, (guchar *)":", 1); | 1818 purple_cipher_context_append(context, (guchar *)":", 1); |
1819 gaim_cipher_context_append(context, (guchar *)realm, strlen(realm)); | 1819 purple_cipher_context_append(context, (guchar *)realm, strlen(realm)); |
1820 gaim_cipher_context_append(context, (guchar *)":", 1); | 1820 purple_cipher_context_append(context, (guchar *)":", 1); |
1821 gaim_cipher_context_append(context, (guchar *)password, strlen(password)); | 1821 purple_cipher_context_append(context, (guchar *)password, strlen(password)); |
1822 | 1822 |
1823 if (algorithm != NULL && !strcasecmp(algorithm, "MD5-sess")) | 1823 if (algorithm != NULL && !strcasecmp(algorithm, "MD5-sess")) |
1824 { | 1824 { |
1825 guchar digest[16]; | 1825 guchar digest[16]; |
1826 | 1826 |
1827 if (client_nonce == NULL) | 1827 if (client_nonce == NULL) |
1828 { | 1828 { |
1829 gaim_cipher_context_destroy(context); | 1829 purple_cipher_context_destroy(context); |
1830 gaim_debug_error("cipher", "Required client_nonce missing for MD5-sess digest calculation."); | 1830 purple_debug_error("cipher", "Required client_nonce missing for MD5-sess digest calculation."); |
1831 return NULL; | 1831 return NULL; |
1832 } | 1832 } |
1833 | 1833 |
1834 gaim_cipher_context_digest(context, sizeof(digest), digest, NULL); | 1834 purple_cipher_context_digest(context, sizeof(digest), digest, NULL); |
1835 gaim_cipher_context_destroy(context); | 1835 purple_cipher_context_destroy(context); |
1836 | 1836 |
1837 context = gaim_cipher_context_new(cipher, NULL); | 1837 context = purple_cipher_context_new(cipher, NULL); |
1838 gaim_cipher_context_append(context, digest, sizeof(digest)); | 1838 purple_cipher_context_append(context, digest, sizeof(digest)); |
1839 gaim_cipher_context_append(context, (guchar *)":", 1); | 1839 purple_cipher_context_append(context, (guchar *)":", 1); |
1840 gaim_cipher_context_append(context, (guchar *)nonce, strlen(nonce)); | 1840 purple_cipher_context_append(context, (guchar *)nonce, strlen(nonce)); |
1841 gaim_cipher_context_append(context, (guchar *)":", 1); | 1841 purple_cipher_context_append(context, (guchar *)":", 1); |
1842 gaim_cipher_context_append(context, (guchar *)client_nonce, strlen(client_nonce)); | 1842 purple_cipher_context_append(context, (guchar *)client_nonce, strlen(client_nonce)); |
1843 } | 1843 } |
1844 | 1844 |
1845 gaim_cipher_context_digest_to_str(context, sizeof(hash), hash, NULL); | 1845 purple_cipher_context_digest_to_str(context, sizeof(hash), hash, NULL); |
1846 gaim_cipher_context_destroy(context); | 1846 purple_cipher_context_destroy(context); |
1847 | 1847 |
1848 return g_strdup(hash); | 1848 return g_strdup(hash); |
1849 } | 1849 } |
1850 | 1850 |
1851 gchar *gaim_cipher_http_digest_calculate_response( | 1851 gchar *purple_cipher_http_digest_calculate_response( |
1852 const gchar *algorithm, | 1852 const gchar *algorithm, |
1853 const gchar *method, | 1853 const gchar *method, |
1854 const gchar *digest_uri, | 1854 const gchar *digest_uri, |
1855 const gchar *qop, | 1855 const gchar *qop, |
1856 const gchar *entity, | 1856 const gchar *entity, |
1857 const gchar *nonce, | 1857 const gchar *nonce, |
1858 const gchar *nonce_count, | 1858 const gchar *nonce_count, |
1859 const gchar *client_nonce, | 1859 const gchar *client_nonce, |
1860 const gchar *session_key) | 1860 const gchar *session_key) |
1861 { | 1861 { |
1862 GaimCipher *cipher; | 1862 PurpleCipher *cipher; |
1863 GaimCipherContext *context; | 1863 PurpleCipherContext *context; |
1864 static gchar hash2[33]; /* We only support MD5. */ | 1864 static gchar hash2[33]; /* We only support MD5. */ |
1865 | 1865 |
1866 g_return_val_if_fail(method != NULL, NULL); | 1866 g_return_val_if_fail(method != NULL, NULL); |
1867 g_return_val_if_fail(digest_uri != NULL, NULL); | 1867 g_return_val_if_fail(digest_uri != NULL, NULL); |
1868 g_return_val_if_fail(nonce != NULL, NULL); | 1868 g_return_val_if_fail(nonce != NULL, NULL); |
1878 g_return_val_if_fail(qop == NULL || | 1878 g_return_val_if_fail(qop == NULL || |
1879 *qop == '\0' || | 1879 *qop == '\0' || |
1880 strcasecmp(qop, "auth") || | 1880 strcasecmp(qop, "auth") || |
1881 strcasecmp(qop, "auth-int"), NULL); | 1881 strcasecmp(qop, "auth-int"), NULL); |
1882 | 1882 |
1883 cipher = gaim_ciphers_find_cipher("md5"); | 1883 cipher = purple_ciphers_find_cipher("md5"); |
1884 g_return_val_if_fail(cipher != NULL, NULL); | 1884 g_return_val_if_fail(cipher != NULL, NULL); |
1885 | 1885 |
1886 context = gaim_cipher_context_new(cipher, NULL); | 1886 context = purple_cipher_context_new(cipher, NULL); |
1887 | 1887 |
1888 gaim_cipher_context_append(context, (guchar *)method, strlen(method)); | 1888 purple_cipher_context_append(context, (guchar *)method, strlen(method)); |
1889 gaim_cipher_context_append(context, (guchar *)":", 1); | 1889 purple_cipher_context_append(context, (guchar *)":", 1); |
1890 gaim_cipher_context_append(context, (guchar *)digest_uri, strlen(digest_uri)); | 1890 purple_cipher_context_append(context, (guchar *)digest_uri, strlen(digest_uri)); |
1891 | 1891 |
1892 if (qop != NULL && !strcasecmp(qop, "auth-int")) | 1892 if (qop != NULL && !strcasecmp(qop, "auth-int")) |
1893 { | 1893 { |
1894 GaimCipherContext *context2; | 1894 PurpleCipherContext *context2; |
1895 gchar entity_hash[33]; | 1895 gchar entity_hash[33]; |
1896 | 1896 |
1897 if (entity == NULL) | 1897 if (entity == NULL) |
1898 { | 1898 { |
1899 gaim_cipher_context_destroy(context); | 1899 purple_cipher_context_destroy(context); |
1900 gaim_debug_error("cipher", "Required entity missing for auth-int digest calculation."); | 1900 purple_debug_error("cipher", "Required entity missing for auth-int digest calculation."); |
1901 return NULL; | 1901 return NULL; |
1902 } | 1902 } |
1903 | 1903 |
1904 context2 = gaim_cipher_context_new(cipher, NULL); | 1904 context2 = purple_cipher_context_new(cipher, NULL); |
1905 gaim_cipher_context_append(context2, (guchar *)entity, strlen(entity)); | 1905 purple_cipher_context_append(context2, (guchar *)entity, strlen(entity)); |
1906 gaim_cipher_context_digest_to_str(context2, sizeof(entity_hash), entity_hash, NULL); | 1906 purple_cipher_context_digest_to_str(context2, sizeof(entity_hash), entity_hash, NULL); |
1907 gaim_cipher_context_destroy(context2); | 1907 purple_cipher_context_destroy(context2); |
1908 | 1908 |
1909 gaim_cipher_context_append(context, (guchar *)":", 1); | 1909 purple_cipher_context_append(context, (guchar *)":", 1); |
1910 gaim_cipher_context_append(context, (guchar *)entity_hash, strlen(entity_hash)); | 1910 purple_cipher_context_append(context, (guchar *)entity_hash, strlen(entity_hash)); |
1911 } | 1911 } |
1912 | 1912 |
1913 gaim_cipher_context_digest_to_str(context, sizeof(hash2), hash2, NULL); | 1913 purple_cipher_context_digest_to_str(context, sizeof(hash2), hash2, NULL); |
1914 gaim_cipher_context_destroy(context); | 1914 purple_cipher_context_destroy(context); |
1915 | 1915 |
1916 context = gaim_cipher_context_new(cipher, NULL); | 1916 context = purple_cipher_context_new(cipher, NULL); |
1917 gaim_cipher_context_append(context, (guchar *)session_key, strlen(session_key)); | 1917 purple_cipher_context_append(context, (guchar *)session_key, strlen(session_key)); |
1918 gaim_cipher_context_append(context, (guchar *)":", 1); | 1918 purple_cipher_context_append(context, (guchar *)":", 1); |
1919 gaim_cipher_context_append(context, (guchar *)nonce, strlen(nonce)); | 1919 purple_cipher_context_append(context, (guchar *)nonce, strlen(nonce)); |
1920 gaim_cipher_context_append(context, (guchar *)":", 1); | 1920 purple_cipher_context_append(context, (guchar *)":", 1); |
1921 | 1921 |
1922 if (qop != NULL && *qop != '\0') | 1922 if (qop != NULL && *qop != '\0') |
1923 { | 1923 { |
1924 if (nonce_count == NULL) | 1924 if (nonce_count == NULL) |
1925 { | 1925 { |
1926 gaim_cipher_context_destroy(context); | 1926 purple_cipher_context_destroy(context); |
1927 gaim_debug_error("cipher", "Required nonce_count missing for digest calculation."); | 1927 purple_debug_error("cipher", "Required nonce_count missing for digest calculation."); |
1928 return NULL; | 1928 return NULL; |
1929 } | 1929 } |
1930 | 1930 |
1931 if (client_nonce == NULL) | 1931 if (client_nonce == NULL) |
1932 { | 1932 { |
1933 gaim_cipher_context_destroy(context); | 1933 purple_cipher_context_destroy(context); |
1934 gaim_debug_error("cipher", "Required client_nonce missing for digest calculation."); | 1934 purple_debug_error("cipher", "Required client_nonce missing for digest calculation."); |
1935 return NULL; | 1935 return NULL; |
1936 } | 1936 } |
1937 | 1937 |
1938 gaim_cipher_context_append(context, (guchar *)nonce_count, strlen(nonce_count)); | 1938 purple_cipher_context_append(context, (guchar *)nonce_count, strlen(nonce_count)); |
1939 gaim_cipher_context_append(context, (guchar *)":", 1); | 1939 purple_cipher_context_append(context, (guchar *)":", 1); |
1940 gaim_cipher_context_append(context, (guchar *)client_nonce, strlen(client_nonce)); | 1940 purple_cipher_context_append(context, (guchar *)client_nonce, strlen(client_nonce)); |
1941 gaim_cipher_context_append(context, (guchar *)":", 1); | 1941 purple_cipher_context_append(context, (guchar *)":", 1); |
1942 | 1942 |
1943 gaim_cipher_context_append(context, (guchar *)qop, strlen(qop)); | 1943 purple_cipher_context_append(context, (guchar *)qop, strlen(qop)); |
1944 | 1944 |
1945 gaim_cipher_context_append(context, (guchar *)":", 1); | 1945 purple_cipher_context_append(context, (guchar *)":", 1); |
1946 } | 1946 } |
1947 | 1947 |
1948 gaim_cipher_context_append(context, (guchar *)hash2, strlen(hash2)); | 1948 purple_cipher_context_append(context, (guchar *)hash2, strlen(hash2)); |
1949 gaim_cipher_context_digest_to_str(context, sizeof(hash2), hash2, NULL); | 1949 purple_cipher_context_digest_to_str(context, sizeof(hash2), hash2, NULL); |
1950 gaim_cipher_context_destroy(context); | 1950 purple_cipher_context_destroy(context); |
1951 | 1951 |
1952 return g_strdup(hash2); | 1952 return g_strdup(hash2); |
1953 } | 1953 } |