OLD | NEW |
1 #define IN_LIBEXSLT | 1 #define IN_LIBEXSLT |
2 #include "libexslt/libexslt.h" | 2 #include "libexslt/libexslt.h" |
3 | 3 |
4 #if defined(WIN32) && !defined (__CYGWIN__) && (!__MINGW32__) | 4 #if defined(WIN32) && !defined (__CYGWIN__) && (!__MINGW32__) |
5 #include <win32config.h> | 5 #include <win32config.h> |
6 #else | 6 #else |
7 #include "config.h" | 7 #include "config.h" |
8 #endif | 8 #endif |
9 | 9 |
10 #include <libxml/tree.h> | 10 #include <libxml/tree.h> |
11 #include <libxml/xpath.h> | 11 #include <libxml/xpath.h> |
12 #include <libxml/xpathInternals.h> | 12 #include <libxml/xpathInternals.h> |
13 #include <libxml/parser.h> | 13 #include <libxml/parser.h> |
14 #include <libxml/encoding.h> | 14 #include <libxml/encoding.h> |
15 #include <libxml/uri.h> | 15 #include <libxml/uri.h> |
16 | 16 |
17 #include <libxslt/xsltconfig.h> | 17 #include <libxslt/xsltconfig.h> |
18 #include <libxslt/xsltutils.h> | 18 #include <libxslt/xsltutils.h> |
19 #include <libxslt/xsltInternals.h> | 19 #include <libxslt/xsltInternals.h> |
20 #include <libxslt/extensions.h> | 20 #include <libxslt/extensions.h> |
21 | 21 |
22 #include "exslt.h" | 22 #include "exslt.h" |
23 | 23 |
24 #ifdef EXSLT_CRYPTO_ENABLED | 24 #ifdef EXSLT_CRYPTO_ENABLED |
25 | 25 |
26 #define HASH_DIGEST_LENGTH 32 | 26 #define HASH_DIGEST_LENGTH 32 |
27 #define MD5_DIGEST_LENGTH 16 | 27 #define MD5_DIGEST_LENGTH 16 |
28 #define SHA1_DIGEST_LENGTH 20 | 28 #define SHA1_DIGEST_LENGTH 20 |
29 | 29 |
30 /* gcrypt rc4 can do 256 bit keys, but cryptoapi limit | 30 /* gcrypt rc4 can do 256 bit keys, but cryptoapi limit |
31 seems to be 128 for the default provider */ | 31 seems to be 128 for the default provider */ |
32 #define RC4_KEY_LENGTH 128 | 32 #define RC4_KEY_LENGTH 128 |
33 | 33 |
34 /* The following routines have been declared static - this should be | 34 /* The following routines have been declared static - this should be |
35 reviewed to consider whether we want to expose them to the API | 35 reviewed to consider whether we want to expose them to the API |
36 exsltCryptoBin2Hex | 36 exsltCryptoBin2Hex |
37 exsltCryptoHex2Bin | 37 exsltCryptoHex2Bin |
38 exsltCryptoGcryptInit | 38 exsltCryptoGcryptInit |
39 exsltCryptoGcryptHash | 39 exsltCryptoGcryptHash |
40 exsltCryptoGcryptRc4Encrypt | 40 exsltCryptoGcryptRc4Encrypt |
41 exsltCryptoGcryptRC4Decrypt | 41 exsltCryptoGcryptRC4Decrypt |
42 */ | 42 */ |
43 | 43 |
44 /** | 44 /** |
45 * exsltCryptoBin2Hex: | 45 * exsltCryptoBin2Hex: |
46 * @bin: binary blob to convert | 46 * @bin: binary blob to convert |
47 * @binlen: length of binary blob | 47 * @binlen: length of binary blob |
48 * @hex: buffer to store hex version of blob | 48 * @hex: buffer to store hex version of blob |
49 * @hexlen: length of buffer to store hex version of blob | 49 * @hexlen: length of buffer to store hex version of blob |
50 * | 50 * |
51 * Helper function which encodes a binary blob as hex. | 51 * Helper function which encodes a binary blob as hex. |
52 */ | 52 */ |
53 static void | 53 static void |
54 exsltCryptoBin2Hex (const unsigned char *bin, int binlen, | 54 exsltCryptoBin2Hex (const unsigned char *bin, int binlen, |
55 unsigned char *hex, int hexlen) { | 55 unsigned char *hex, int hexlen) { |
56 static const char bin2hex[] = { '0', '1', '2', '3', | 56 static const char bin2hex[] = { '0', '1', '2', '3', |
57 '4', '5', '6', '7', | 57 '4', '5', '6', '7', |
58 '8', '9', 'a', 'b', | 58 '8', '9', 'a', 'b', |
59 'c', 'd', 'e', 'f' | 59 'c', 'd', 'e', 'f' |
60 }; | 60 }; |
61 | 61 |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 } | 350 } |
351 | 351 |
352 /** | 352 /** |
353 * exsltCryptoGcryptHash: | 353 * exsltCryptoGcryptHash: |
354 * @ctxt: an XPath parser context | 354 * @ctxt: an XPath parser context |
355 * @algorithm: hashing algorithm to use | 355 * @algorithm: hashing algorithm to use |
356 * @msg: text to be hashed | 356 * @msg: text to be hashed |
357 * @msglen: length of text to be hashed | 357 * @msglen: length of text to be hashed |
358 * @dest: buffer to place hash result | 358 * @dest: buffer to place hash result |
359 * | 359 * |
360 * Helper function which hashes a message using MD4, MD5, or SHA1. | 360 * Helper function which hashes a message using MD4, MD5, or SHA1. |
361 * using gcrypt | 361 * using gcrypt |
362 */ | 362 */ |
363 static void | 363 static void |
364 exsltCryptoGcryptHash (xmlXPathParserContextPtr ctxt ATTRIBUTE_UNUSED, | 364 exsltCryptoGcryptHash (xmlXPathParserContextPtr ctxt ATTRIBUTE_UNUSED, |
365 /* changed the enum to int */ | 365 /* changed the enum to int */ |
366 int algorithm, const char *msg, | 366 int algorithm, const char *msg, |
367 unsigned long msglen, | 367 unsigned long msglen, |
368 char dest[HASH_DIGEST_LENGTH]) { | 368 char dest[HASH_DIGEST_LENGTH]) { |
369 exsltCryptoGcryptInit (); | 369 exsltCryptoGcryptInit (); |
370 gcry_md_hash_buffer (algorithm, dest, msg, msglen); | 370 gcry_md_hash_buffer (algorithm, dest, msg, msglen); |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 if (bin == NULL) { | 745 if (bin == NULL) { |
746 xsltTransformError(tctxt, NULL, tctxt->inst, | 746 xsltTransformError(tctxt, NULL, tctxt->inst, |
747 "exsltCryptoRc4EncryptFunction: Failed to allocate string\n"); | 747 "exsltCryptoRc4EncryptFunction: Failed to allocate string\n"); |
748 tctxt->state = XSLT_STATE_STOPPED; | 748 tctxt->state = XSLT_STATE_STOPPED; |
749 xmlXPathReturnEmptyString (ctxt); | 749 xmlXPathReturnEmptyString (ctxt); |
750 goto done; | 750 goto done; |
751 } | 751 } |
752 ret_len = exsltCryptoHex2Bin (str, str_len, bin, bin_len); | 752 ret_len = exsltCryptoHex2Bin (str, str_len, bin, bin_len); |
753 | 753 |
754 /* decrypt the binary blob */ | 754 /* decrypt the binary blob */ |
755 ret = xmlMallocAtomic (ret_len); | 755 ret = xmlMallocAtomic (ret_len + 1); |
756 if (ret == NULL) { | 756 if (ret == NULL) { |
757 xsltTransformError(tctxt, NULL, tctxt->inst, | 757 xsltTransformError(tctxt, NULL, tctxt->inst, |
758 "exsltCryptoRc4EncryptFunction: Failed to allocate result\n"); | 758 "exsltCryptoRc4EncryptFunction: Failed to allocate result\n"); |
759 tctxt->state = XSLT_STATE_STOPPED; | 759 tctxt->state = XSLT_STATE_STOPPED; |
760 xmlXPathReturnEmptyString (ctxt); | 760 xmlXPathReturnEmptyString (ctxt); |
761 goto done; | 761 goto done; |
762 } | 762 } |
763 PLATFORM_RC4_DECRYPT (ctxt, padkey, bin, ret_len, ret, ret_len); | 763 PLATFORM_RC4_DECRYPT (ctxt, padkey, bin, ret_len, ret, ret_len); |
| 764 ret[ret_len] = 0; |
764 | 765 |
765 xmlXPathReturnString (ctxt, ret); | 766 xmlXPathReturnString (ctxt, ret); |
766 | 767 |
767 done: | 768 done: |
768 if (key != NULL) | 769 if (key != NULL) |
769 xmlFree (key); | 770 xmlFree (key); |
770 if (str != NULL) | 771 if (str != NULL) |
771 xmlFree (str); | 772 xmlFree (str); |
772 if (padkey != NULL) | 773 if (padkey != NULL) |
773 xmlFree (padkey); | 774 xmlFree (padkey); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 * | 807 * |
807 * Registers the EXSLT - Crypto module | 808 * Registers the EXSLT - Crypto module |
808 */ | 809 */ |
809 void | 810 void |
810 exsltCryptoRegister (void) { | 811 exsltCryptoRegister (void) { |
811 } | 812 } |
812 | 813 |
813 #endif /* defined(HAVE_CRYPTO) */ | 814 #endif /* defined(HAVE_CRYPTO) */ |
814 | 815 |
815 #endif /* EXSLT_CRYPTO_ENABLED */ | 816 #endif /* EXSLT_CRYPTO_ENABLED */ |
OLD | NEW |