libpurple/cipher.c

branch
next.minor
changeset 25888
d0fdd378a635
parent 25859
b42be7bb9dac
child 27383
cbb399c19d87
equal deleted inserted replaced
25887:6eac2f6c32e2 25888:d0fdd378a635
510 mctx->hash[3] = 0x10325476; 510 mctx->hash[3] = 0x10325476;
511 mctx->byte_count = 0; 511 mctx->byte_count = 0;
512 } 512 }
513 513
514 static void 514 static void
515 md4_append(PurpleCipherContext *context, const guchar *data, size_t len) 515 md4_append(PurpleCipherContext *context, const guchar *data, size_t len)
516 { 516 {
517 struct MD4_Context *mctx = purple_cipher_context_get_data(context); 517 struct MD4_Context *mctx = purple_cipher_context_get_data(context);
518 const guint32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f); 518 const guint32 avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f);
519 519
520 mctx->byte_count += len; 520 mctx->byte_count += len;
549 struct MD4_Context *mctx = purple_cipher_context_get_data(context); 549 struct MD4_Context *mctx = purple_cipher_context_get_data(context);
550 const unsigned int offset = mctx->byte_count & 0x3f; 550 const unsigned int offset = mctx->byte_count & 0x3f;
551 char *p = (char *)mctx->block + offset; 551 char *p = (char *)mctx->block + offset;
552 int padding = 56 - (offset + 1); 552 int padding = 56 - (offset + 1);
553 553
554 554
555 if(in_len<16) return FALSE; 555 if(in_len<16) return FALSE;
556 if(out_len) *out_len = 16; 556 if(out_len) *out_len = 16;
557 *p++ = 0x80; 557 *p++ = 0x80;
558 if (padding < 0) { 558 if (padding < 0) {
559 memset(p, 0x00, padding + sizeof (guint64)); 559 memset(p, 0x00, padding + sizeof (guint64));
682 682
683 return NULL; 683 return NULL;
684 } 684 }
685 685
686 static void 686 static void
687 hmac_append(PurpleCipherContext *context, const guchar *data, size_t len) 687 hmac_append(PurpleCipherContext *context, const guchar *data, size_t len)
688 { 688 {
689 struct HMAC_Context *hctx = purple_cipher_context_get_data(context); 689 struct HMAC_Context *hctx = purple_cipher_context_get_data(context);
690 690
691 g_return_if_fail(hctx->hash != NULL); 691 g_return_if_fail(hctx->hash != NULL);
692 692
776 hmac_set_key(PurpleCipherContext *context, const guchar * key) 776 hmac_set_key(PurpleCipherContext *context, const guchar * key)
777 { 777 {
778 hmac_set_key_with_len(context, key, strlen((char *)key)); 778 hmac_set_key_with_len(context, key, strlen((char *)key));
779 } 779 }
780 780
781 static size_t 781 static size_t
782 hmac_get_block_size(PurpleCipherContext *context) 782 hmac_get_block_size(PurpleCipherContext *context)
783 { 783 {
784 struct HMAC_Context *hctx = purple_cipher_context_get_data(context); 784 struct HMAC_Context *hctx = purple_cipher_context_get_data(context);
785 785
786 return hctx->blocksize; 786 return hctx->blocksize;
1020 /* 1020 /*
1021 * des_key_schedule(): Calculate 16 subkeys pairs (even/odd) for 1021 * des_key_schedule(): Calculate 16 subkeys pairs (even/odd) for
1022 * 16 encryption rounds. 1022 * 16 encryption rounds.
1023 * To calculate subkeys for decryption the caller 1023 * To calculate subkeys for decryption the caller
1024 * have to reorder the generated subkeys. 1024 * have to reorder the generated subkeys.
1025 * 1025 *
1026 * rawkey: 8 Bytes of key data 1026 * rawkey: 8 Bytes of key data
1027 * subkey: Array of at least 32 guint32s. Will be filled 1027 * subkey: Array of at least 32 guint32s. Will be filled
1028 * with calculated subkeys. 1028 * with calculated subkeys.
1029 * 1029 *
1030 **/ 1030 **/
1031 static void 1031 static void
1032 des_key_schedule (const guint8 * rawkey, guint32 * subkey) 1032 des_key_schedule (const guint8 * rawkey, guint32 * subkey)
1033 { 1033 {
1034 guint32 left, right, work; 1034 guint32 left, right, work;
1184 } 1184 }
1185 des_ecb_crypt(purple_cipher_context_get_data(context), 1185 des_ecb_crypt(purple_cipher_context_get_data(context),
1186 buf, 1186 buf,
1187 output+offset, 1187 output+offset,
1188 0); 1188 0);
1189 } 1189 }
1190 return 0; 1190 return 0;
1191 } 1191 }
1192 1192
1193 static gint 1193 static gint
1194 des_decrypt(PurpleCipherContext *context, const guchar data[], 1194 des_decrypt(PurpleCipherContext *context, const guchar data[],
1214 } 1214 }
1215 des_ecb_crypt(purple_cipher_context_get_data(context), 1215 des_ecb_crypt(purple_cipher_context_get_data(context),
1216 buf, 1216 buf,
1217 output+offset, 1217 output+offset,
1218 1); 1218 1);
1219 } 1219 }
1220 return 0; 1220 return 0;
1221 } 1221 }
1222 1222
1223 static void 1223 static void
1224 des_init(PurpleCipherContext *context, gpointer extra) { 1224 des_init(PurpleCipherContext *context, gpointer extra) {
1945 if(purple_strequal(name, "key_len")) { 1945 if(purple_strequal(name, "key_len")) {
1946 ctx->key_len = GPOINTER_TO_INT(value); 1946 ctx->key_len = GPOINTER_TO_INT(value);
1947 } 1947 }
1948 } 1948 }
1949 1949
1950 static size_t 1950 static size_t
1951 rc4_get_key_size (PurpleCipherContext *context) 1951 rc4_get_key_size (PurpleCipherContext *context)
1952 { 1952 {
1953 struct RC4Context *ctx; 1953 struct RC4Context *ctx;
1954 1954
1955 g_return_val_if_fail(context, -1); 1955 g_return_val_if_fail(context, -1);

mercurial