]> granicus.if.org Git - php/commitdiff
make code more compact
authorSascha Schumann <sas@php.net>
Sun, 25 Apr 1999 21:32:52 +0000 (21:32 +0000)
committerSascha Schumann <sas@php.net>
Sun, 25 Apr 1999 21:32:52 +0000 (21:32 +0000)
ext/mcrypt/mcrypt.c

index fef990cf5e409fd6f73f670da141989df6fc50d3..14e99ca944d11ca7be5ee878c2f507a126c8423b 100644 (file)
@@ -71,6 +71,22 @@ static mcrypt_global_struct mcryptg;
 
 #endif
 
+#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; \
@@ -212,22 +228,13 @@ PHP_FUNCTION(mcrypt_get_block_size)
    OFB crypt/decrypt data using key key with cipher cipher starting with iv */
 PHP_FUNCTION(mcrypt_ofb)
 {
-       pval *cipher, *data, *key, *mode, *iv;
-       int td;
-       char *ndata;
-       size_t bsize;
-       size_t nr;
-       size_t nsize;
-
+       MCRYPT_ARGS;
+       
        if(ARG_COUNT(ht) != 5 || 
                        getParameters(ht, 5, &cipher, &key, &data, &mode, &iv) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
-       convert_to_long(cipher);
-       convert_to_long(mode);
-       convert_to_string(data);
-       convert_to_string(key);
-
+       MCRYPT_CONVERT;
        MCRYPT_SIZE;
        MCRYPT_CHECK_IV;
 
@@ -242,22 +249,13 @@ PHP_FUNCTION(mcrypt_ofb)
    CFB crypt/decrypt data using key key with cipher cipher starting with iv */
 PHP_FUNCTION(mcrypt_cfb)
 {
-       pval *cipher, *data, *key, *mode, *iv;
-       int td;
-       char *ndata;
-       size_t bsize;
-       size_t nr;
-       size_t nsize;
+       MCRYPT_ARGS;
 
        if(ARG_COUNT(ht) != 5 || 
                        getParameters(ht, 5, &cipher, &key, &data, &mode, &iv) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
-       convert_to_long(cipher);
-       convert_to_long(mode);
-       convert_to_string(data);
-       convert_to_string(key);
-       
+       MCRYPT_CONVERT;
        MCRYPT_SIZE;
        MCRYPT_CHECK_IV;
 
@@ -273,24 +271,15 @@ PHP_FUNCTION(mcrypt_cfb)
    CBC crypt/decrypt data using key key with cipher cipher using optional iv */
 PHP_FUNCTION(mcrypt_cbc)
 {
-       pval *cipher, *data, *key, *mode, *iv;
-       int td;
+       MCRYPT_ARGS;
        int ac = ARG_COUNT(ht);
-       char *ndata;
-       size_t bsize;
-       size_t nr;
-       size_t nsize;
 
        if(ac < 4 || ac > 5 || 
                        getParameters(ht, ac, &cipher, &key, &data, &mode, &iv) == 
                        FAILURE) {
                WRONG_PARAM_COUNT;
        }
-       convert_to_long(cipher);
-       convert_to_long(mode);
-       convert_to_string(data);
-       convert_to_string(key);
-               
+       MCRYPT_CONVERT;
        MCRYPT_SIZE;
        if(ac > 4 && mode == 0) {
                MCRYPT_CHECK_IV;
@@ -313,22 +302,13 @@ PHP_FUNCTION(mcrypt_cbc)
    ECB crypt/decrypt data using key key with cipher cipher */
 PHP_FUNCTION(mcrypt_ecb)
 {
-       pval *cipher, *data, *key, *mode;
-       int td;
-       char *ndata;
-       size_t bsize;
-       size_t nr;
-       size_t nsize;
+       MCRYPT_ARGS2;
 
        if(ARG_COUNT(ht) != 4 || 
                        getParameters(ht, 4, &cipher, &key, &data, &mode) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
-       convert_to_long(cipher);
-       convert_to_long(mode);
-       convert_to_string(data);
-       convert_to_string(key);
-       
+       MCRYPT_CONVERT;
        MCRYPT_SIZE;
        
        td = init_mcrypt_ecb(cipher->value.lval, key->value.str.val, key->value.str.len);