cvs: /php4/ext/mhash mhash.c /php4/ext/mcrypt mcrypt.c

From: Date: Fri, 17 Sep 1999 09:40:52 +0000
Subject: cvs: /php4/ext/mhash mhash.c /php4/ext/mcrypt mcrypt.c
Groups: php.version4 
Request: Send a blank email to php-version4+get-4567@lists.php.net to get a copy of this message
sas Fri Sep 17 05:40:52 1999 EDT Modified files: /php4/ext/mhash mhash.c /php4/ext/mcrypt mcrypt.c Log: Use Ex API here as well. Index: php4/ext/mhash/mhash.c diff -u php4/ext/mhash/mhash.c:1.7 php4/ext/mhash/mhash.c:1.8 --- php4/ext/mhash/mhash.c:1.7 Tue Aug 17 13:31:27 1999 +++ php4/ext/mhash/mhash.c Fri Sep 17 05:40:51 1999 @@ -74,31 +74,31 @@ get the block size of hash */ PHP_FUNCTION(mhash_get_block_size) { - pval *hash; + pval **hash; - if(ARG_COUNT(ht) != 1 || getParameters(ht, 1, &hash) == FAILURE) { + if(ARG_COUNT(ht) != 1 || getParametersEx(1, &hash) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_long(hash); + convert_to_long_ex(hash); - RETURN_LONG(mhash_get_block_size(hash->value.lval)); + RETURN_LONG(mhash_get_block_size((*hash)->value.lval)); } /* proto mhash_get_hash_name(int hash) get the name of hash */ PHP_FUNCTION(mhash_get_hash_name) { - pval *hash; + pval **hash; char *name; - if(ARG_COUNT(ht) != 1 || getParameters(ht, 1, &hash) == FAILURE) { + if(ARG_COUNT(ht) != 1 || getParametersEx(1, &hash) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_long(hash); + convert_to_long_ex(hash); - name = mhash_get_hash_name(hash->value.lval); + name = mhash_get_hash_name((*hash)->value.lval); if(name) { RETVAL_STRING(name, 1); free(name); @@ -111,27 +111,26 @@ hash data with hash */ PHP_FUNCTION(mhash) { - pval *hash, *data; + pval **hash, **data; MHASH td; int bsize; unsigned char *hash_data; - int i; - if(ARG_COUNT(ht) != 2 || getParameters(ht, 2, &hash, &data) == FAILURE) { + if(ARG_COUNT(ht) != 2 || getParametersEx(2, &hash, &data) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_long(hash); - convert_to_string(data); + convert_to_long_ex(hash); + convert_to_string_ex(data); - bsize = mhash_get_block_size(hash->value.lval); - td = mhash_init(hash->value.lval); + bsize = mhash_get_block_size((*hash)->value.lval); + td = mhash_init((*hash)->value.lval); if(td == MHASH_FAILED) { php_error(E_WARNING, MHASH_FAILED_MSG); RETURN_FALSE; } - mhash(td, data->value.str.val, data->value.str.len); + mhash(td, (*data)->value.str.val, (*data)->value.str.len); hash_data = (unsigned char *) mhash_end(td); Index: php4/ext/mcrypt/mcrypt.c diff -u php4/ext/mcrypt/mcrypt.c:1.19 php4/ext/mcrypt/mcrypt.c:1.20 --- php4/ext/mcrypt/mcrypt.c:1.19 Mon Aug 2 15:16:45 1999 +++ php4/ext/mcrypt/mcrypt.c Fri Sep 17 05:40:51 1999 @@ -62,47 +62,49 @@ #endif -#define MCRYPT_ARGS2 \ - pval *cipher, *data, *key, *mode; \ - int td; \ - char *ndata; \ - size_t bsize; \ - size_t nr; \ +#define MCRYPT_ARGS2 \ + pval **cipher, **data, **key, **mode; \ + int td; \ + char *ndata; \ + size_t bsize; \ + size_t nr; \ size_t nsize -#define MCRYPT_ARGS MCRYPT_ARGS2; pval *iv - -#define MCRYPT_CONVERT \ - convert_to_long(cipher); \ - convert_to_long(mode); \ - convert_to_string(data); \ - convert_to_string(key) - -#define MCRYPT_SIZE \ - bsize = get_block_size(cipher->value.lval); \ - nr = (data->value.str.len + bsize - 1) / bsize; \ +#define MCRYPT_ARGS \ + MCRYPT_ARGS2; \ + pval **iv + +#define MCRYPT_CONVERT \ + convert_to_long_ex(cipher); \ + convert_to_long_ex(mode); \ + convert_to_string_ex(data); \ + convert_to_string_ex(key) + +#define MCRYPT_SIZE \ + bsize = get_block_size((*cipher)->value.lval); \ + nr = ((*data)->value.str.len + bsize - 1) / bsize; \ nsize = nr * bsize -#define MCRYPT_CHECK_TD_CPY \ - if(td == -1) { \ - php_error(E_WARNING, MCRYPT_FAILED); \ - RETURN_FALSE; \ - } \ - ndata = ecalloc(nr, bsize); \ - memcpy(ndata, data->value.str.val, data->value.str.len) - -#define MCRYPT_CHECK_IV \ - convert_to_string(iv); \ - if(iv->value.str.len != bsize) { \ - php_error(E_WARNING, MCRYPT_IV_WRONG_SIZE); \ - RETURN_FALSE; \ - } - -#define MCRYPT_ACTION(x) \ - if(mode->value.lval == 0) \ - mcrypt_##x(td, ndata, nsize); \ - else \ - mdecrypt_##x(td, ndata, nsize); \ +#define MCRYPT_CHECK_TD_CPY \ + if(td == -1) { \ + php_error(E_WARNING, MCRYPT_FAILED); \ + RETURN_FALSE; \ + } \ + ndata = ecalloc(nr, bsize); \ + memcpy(ndata, (*data)->value.str.val, (*data)->value.str.len) + +#define MCRYPT_CHECK_IV \ + convert_to_string_ex(iv); \ + if((*iv)->value.str.len != bsize) { \ + php_error(E_WARNING, MCRYPT_IV_WRONG_SIZE); \ + RETURN_FALSE; \ + } + +#define MCRYPT_ACTION(x) \ + if((*mode)->value.lval == 0) \ + mcrypt_##x(td, ndata, nsize); \ + else \ + mdecrypt_##x(td, ndata, nsize); \ end_mcrypt_##x(td) #define MCRYPT_IV_WRONG_SIZE "The IV paramater must be as long as the blocksize" @@ -165,20 +167,22 @@ create an initializing vector (IV) */ PHP_FUNCTION(mcrypt_create_iv) { - pval *size, *psource; + pval **size, **psource; char *iv; iv_source source; int i; + int n = 0; - if(ARG_COUNT(ht) != 2 || getParameters(ht, 2, &size, &psource) == FAILURE) { + if(ARG_COUNT(ht) != 2 || getParametersEx(2, &size, &psource) == FAILURE) { WRONG_PARAM_COUNT; } - - convert_to_long(size); - convert_to_long(psource); - source = psource->value.lval; - i = size->value.lval; + convert_to_long_ex(size); + convert_to_long_ex(psource); + + source = (*psource)->value.lval; + i = (*size)->value.lval; + if(i <= 0) { php_error(E_WARNING, "illegal size input parameter"); RETURN_FALSE; @@ -196,30 +200,31 @@ php_error(E_WARNING, "cannot open source device"); RETURN_FALSE; } - read(fd, iv, i); + n = read(fd, iv, i); close(fd); } else { while(i) { - iv[--i] = rand(); + iv[--i] = 255.0 * rand() / RAND_MAX; } + n = (*size)->value.lval; } - RETURN_STRINGL(iv, size->value.lval, 0); + RETURN_STRINGL(iv, n, 0); } /* proto mcrypt_get_cipher_name(int cipher) get the name of cipher */ PHP_FUNCTION(mcrypt_get_cipher_name) { - pval *cipher; + pval **cipher; char *str, *nstr; - if(ARG_COUNT(ht) != 1 || getParameters(ht, 1, &cipher) == FAILURE) { + if(ARG_COUNT(ht) != 1 || getParametersEx(1, &cipher) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_long(cipher); + convert_to_long_ex(cipher); - str = get_algorithms_name(cipher->value.lval); + str = get_algorithms_name((*cipher)->value.lval); nstr = estrdup(str); free(str); @@ -230,30 +235,30 @@ get the key size of cipher */ PHP_FUNCTION(mcrypt_get_key_size) { - pval *cipher; + pval **cipher; - if(ARG_COUNT(ht) != 1 || getParameters(ht, 1, &cipher) == FAILURE) { + if(ARG_COUNT(ht) != 1 || getParametersEx(1, &cipher) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_long(cipher); + convert_to_long_ex(cipher); - RETURN_LONG(get_key_size(cipher->value.lval)); + RETURN_LONG(get_key_size((*cipher)->value.lval)); } /* proto mcrypt_get_block_size(int cipher) get the block size of cipher */ PHP_FUNCTION(mcrypt_get_block_size) { - pval *cipher; + pval **cipher; - if(ARG_COUNT(ht) != 1 || getParameters(ht, 1, &cipher) == FAILURE) { + if(ARG_COUNT(ht) != 1 || getParametersEx(1, &cipher) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_long(cipher); + convert_to_long_ex(cipher); - RETURN_LONG(get_block_size(cipher->value.lval)); + RETURN_LONG(get_block_size((*cipher)->value.lval)); } /* proto mcrypt_ofb(int cipher, string key, string data, int mode, string iv) @@ -263,14 +268,14 @@ MCRYPT_ARGS; if(ARG_COUNT(ht) != 5 || - getParameters(ht, 5, &cipher, &key, &data, &mode, &iv) == FAILURE) { + getParametersEx(5, &cipher, &key, &data, &mode, &iv) == FAILURE) { WRONG_PARAM_COUNT; } MCRYPT_CONVERT; MCRYPT_SIZE; MCRYPT_CHECK_IV; - td = init_mcrypt_ofb(cipher->value.lval, key->value.str.val, key->value.str.len, iv->value.str.val); + td = init_mcrypt_ofb((*cipher)->value.lval, (*key)->value.str.val, (*key)->value.str.len, (*iv)->value.str.val); MCRYPT_CHECK_TD_CPY; MCRYPT_ACTION(ofb); @@ -284,14 +289,14 @@ MCRYPT_ARGS; if(ARG_COUNT(ht) != 5 || - getParameters(ht, 5, &cipher, &key, &data, &mode, &iv) == FAILURE) { + getParametersEx(5, &cipher, &key, &data, &mode, &iv) == FAILURE) { WRONG_PARAM_COUNT; } MCRYPT_CONVERT; MCRYPT_SIZE; MCRYPT_CHECK_IV; - td = init_mcrypt_cfb(cipher->value.lval, key->value.str.val, key->value.str.len, iv->value.str.val); + td = init_mcrypt_cfb((*cipher)->value.lval, (*key)->value.str.val, (*key)->value.str.len, (*iv)->value.str.val); MCRYPT_CHECK_TD_CPY; MCRYPT_ACTION(cfb); @@ -307,8 +312,7 @@ int ac = ARG_COUNT(ht); if(ac < 4 || ac > 5 || - getParameters(ht, ac, &cipher, &key, &data, &mode, &iv) == - FAILURE) { + getParametersEx(ac, &cipher, &key, &data, &mode, &iv) == FAILURE) { WRONG_PARAM_COUNT; } MCRYPT_CONVERT; @@ -317,11 +321,11 @@ MCRYPT_CHECK_IV; } - td = init_mcrypt_cbc(cipher->value.lval, key->value.str.val, key->value.str.len); + td = init_mcrypt_cbc((*cipher)->value.lval, (*key)->value.str.val, (*key)->value.str.len); MCRYPT_CHECK_TD_CPY; if(ac > 4) { - mcrypt(td, iv->value.str.val); + mcrypt(td, (*iv)->value.str.val); } MCRYPT_ACTION(cbc); @@ -336,13 +340,13 @@ MCRYPT_ARGS2; if(ARG_COUNT(ht) != 4 || - getParameters(ht, 4, &cipher, &key, &data, &mode) == FAILURE) { + getParametersEx(4, &cipher, &key, &data, &mode) == FAILURE) { WRONG_PARAM_COUNT; } MCRYPT_CONVERT; MCRYPT_SIZE; - td = init_mcrypt_ecb(cipher->value.lval, key->value.str.val, key->value.str.len); + td = init_mcrypt_ecb((*cipher)->value.lval, (*key)->value.str.val, (*key)->value.str.len); MCRYPT_CHECK_TD_CPY; MCRYPT_ACTION(ecb);

« previous php.version4 (#4567) next »