|
| 1 | +/* |
| 2 | + +----------------------------------------------------------------------+ |
| 3 | + | PHP HTML Embedded Scripting Language Version 3.0 | |
| 4 | + +----------------------------------------------------------------------+ |
| 5 | + | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | |
| 6 | + +----------------------------------------------------------------------+ |
| 7 | + | This program is free software; you can redistribute it and/or modify | |
| 8 | + | it under the terms of one of the following licenses: | |
| 9 | + | | |
| 10 | + | A) the GNU General Public License as published by the Free Software | |
| 11 | + | Foundation; either version 2 of the License, or (at your option) | |
| 12 | + | any later version. | |
| 13 | + | | |
| 14 | + | B) the PHP License as published by the PHP Development Team and | |
| 15 | + | included in the distribution in the file: LICENSE | |
| 16 | + | | |
| 17 | + | This program is distributed in the hope that it will be useful, | |
| 18 | + | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 19 | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 20 | + | GNU General Public License for more details. | |
| 21 | + | | |
| 22 | + | You should have received a copy of both licenses referred to here. | |
| 23 | + | If you did not, or have any questions about PHP licensing, please | |
| 24 | + | contact core@php.net. | |
| 25 | + +----------------------------------------------------------------------+ |
| 26 | + | Authors: Evan Klinger <evan715@sirius.com> | |
| 27 | + | Timothy Whitfield <timothy@ametro.net> | |
| 28 | + +----------------------------------------------------------------------+ |
| 29 | + */ |
| 30 | + |
| 31 | +#include "php.h" |
| 32 | + |
| 33 | +#if HAVE_MCK |
| 34 | +#include "cybercash.h" |
| 35 | +#include "mckcrypt.h" |
| 36 | + |
| 37 | +function_entry cybercash_functions[] = { |
| 38 | + PHP_FE(cybercash_encr, NULL) |
| 39 | + PHP_FE(cybercash_decr, NULL) |
| 40 | + PHP_FE(cybercash_base64_encode, NULL) |
| 41 | + PHP_FE(cybercash_base64_decode, NULL) |
| 42 | + {0} |
| 43 | + }; |
| 44 | + |
| 45 | +zend_module_entry cybercash_module_entry = { |
| 46 | + "CyberCash", |
| 47 | + cybercash_functions, |
| 48 | + NULL,NULL, |
| 49 | + NULL,NULL, |
| 50 | + NULL, |
| 51 | + STANDARD_MODULE_PROPERTIES, |
| 52 | +}; |
| 53 | + |
| 54 | +PHP_FUNCTION(cybercash_encr) |
| 55 | +{ |
| 56 | + pval **wmk, **sk, **inbuff; |
| 57 | + unsigned char *outbuff, *macbuff; |
| 58 | + unsigned int outAlloc, outLth; |
| 59 | + long errcode; |
| 60 | + |
| 61 | + if(ARG_COUNT(ht) != 3 || getParametersEx(3,&wmk,&sk,&inbuff) == FAILURE) { |
| 62 | + WRONG_PARAM_COUNT; |
| 63 | + } |
| 64 | + |
| 65 | + convert_to_string_ex(wmk); |
| 66 | + convert_to_string_ex(sk); |
| 67 | + convert_to_string_ex(inbuff); |
| 68 | + |
| 69 | + outAlloc = (*inbuff)->value.str.len + 10; |
| 70 | + |
| 71 | + outbuff = (unsigned char *)emalloc(outAlloc); |
| 72 | + macbuff = (unsigned char *)emalloc(20); |
| 73 | + |
| 74 | + errcode = mck_encr((*wmk)->value.str.val,(*sk)->value.str.val, |
| 75 | + (*inbuff)->value.str.len+1, |
| 76 | + (*inbuff)->value.str.val, |
| 77 | + outAlloc, |
| 78 | + outbuff, |
| 79 | + &outLth, |
| 80 | + macbuff); |
| 81 | + |
| 82 | + array_init(return_value); |
| 83 | + |
| 84 | + add_assoc_long(return_value,"errcode",errcode); |
| 85 | + |
| 86 | + if(!errcode) |
| 87 | + { |
| 88 | + add_assoc_stringl(return_value,"outbuff",outbuff,outLth,0); |
| 89 | + add_assoc_long(return_value,"outLth",outLth); |
| 90 | + add_assoc_stringl(return_value,"macbuff",macbuff,20,0); |
| 91 | + } |
| 92 | + else |
| 93 | + { |
| 94 | + efree(outbuff); |
| 95 | + efree(macbuff); |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +PHP_FUNCTION(cybercash_decr) |
| 100 | +{ |
| 101 | + pval **wmk,**sk,**inbuff; |
| 102 | + unsigned char *outbuff, *macbuff; |
| 103 | + unsigned int outAlloc, outLth; |
| 104 | + long errcode; |
| 105 | + |
| 106 | + |
| 107 | + if(ARG_COUNT(ht) != 3 || getParametersEx(3,&wmk,&sk,&inbuff) == FAILURE) |
| 108 | + { |
| 109 | + WRONG_PARAM_COUNT; |
| 110 | + } |
| 111 | + |
| 112 | + convert_to_string_ex(wmk); |
| 113 | + convert_to_string_ex(sk); |
| 114 | + convert_to_string_ex(inbuff); |
| 115 | + |
| 116 | + outAlloc=(*inbuff)->value.str.len; |
| 117 | + |
| 118 | + outbuff=(unsigned char *)emalloc(outAlloc); |
| 119 | + macbuff=(unsigned char *)emalloc(20); |
| 120 | + |
| 121 | + errcode=mck_decr((*wmk)->value.str.val, |
| 122 | + (*sk)->value.str.val, |
| 123 | + (*inbuff)->value.str.len, |
| 124 | + (*inbuff)->value.str.val, |
| 125 | + outAlloc, |
| 126 | + outbuff, |
| 127 | + &outLth, |
| 128 | + macbuff); |
| 129 | + |
| 130 | + array_init(return_value); |
| 131 | + |
| 132 | + add_assoc_long(return_value,"errcode",errcode); |
| 133 | + |
| 134 | + if(!errcode) { |
| 135 | + add_assoc_stringl(return_value,"outbuff",outbuff,outLth,0); |
| 136 | + add_assoc_long(return_value,"outLth",outLth); |
| 137 | + add_assoc_stringl(return_value,"macbuff",macbuff,20,0); |
| 138 | + } |
| 139 | + else |
| 140 | + { |
| 141 | + efree(outbuff); |
| 142 | + efree(macbuff); |
| 143 | + } |
| 144 | +} |
| 145 | + |
| 146 | +PHP_FUNCTION(cybercash_base64_encode) |
| 147 | +{ |
| 148 | + pval **inbuff; |
| 149 | + char *outbuff; |
| 150 | + long ret_length; |
| 151 | + |
| 152 | + if(ARG_COUNT(ht) != 1 || |
| 153 | + getParametersEx(1,&inbuff) == FAILURE) |
| 154 | + { |
| 155 | + WRONG_PARAM_COUNT; |
| 156 | + } |
| 157 | + |
| 158 | + convert_to_string_ex(inbuff); |
| 159 | + |
| 160 | + outbuff=(char *)emalloc( |
| 161 | + base64_enc_size((unsigned int)(*inbuff)->value.str.len)); |
| 162 | + |
| 163 | + ret_length=base64_encode(outbuff, |
| 164 | + (*inbuff)->value.str.val,(*inbuff)->value.str.len); |
| 165 | + |
| 166 | + return_value->value.str.val=outbuff; |
| 167 | + return_value->value.str.len=ret_length; |
| 168 | + return_value->type=IS_STRING; |
| 169 | + |
| 170 | +} |
| 171 | + |
| 172 | +PHP_FUNCTION(cybercash_base64_decode) |
| 173 | +{ |
| 174 | + pval **inbuff; |
| 175 | + char *outbuff; |
| 176 | + long ret_length; |
| 177 | + |
| 178 | + if(ARG_COUNT(ht) != 1 || |
| 179 | + getParametersEx(1,&inbuff) == FAILURE) |
| 180 | + { |
| 181 | + WRONG_PARAM_COUNT; |
| 182 | + } |
| 183 | + |
| 184 | + convert_to_string_ex(inbuff); |
| 185 | + |
| 186 | + outbuff=(char *)emalloc( |
| 187 | + base64_dec_size((unsigned int)(*inbuff)->value.str.len)); |
| 188 | + |
| 189 | + ret_length=base64_decode(outbuff, |
| 190 | + (*inbuff)->value.str.val,(*inbuff)->value.str.len); |
| 191 | + |
| 192 | + return_value->value.str.val=outbuff; |
| 193 | + return_value->value.str.len=ret_length; |
| 194 | + return_value->type=IS_STRING; |
| 195 | + |
| 196 | +} |
| 197 | +#endif |
0 commit comments