[PHP4BETA] CVS update: php4/ext/mcrypt
| From: | sas | Date: | Sun, 25 Apr 1999 21:09:07 +0000 |
| Subject: | [PHP4BETA] CVS update: php4/ext/mcrypt | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-525@lists.php.net to get a copy of this message | ||
Date: Sunday April 25, 1999 @ 17:09
Author: sas
Update of /repository/php4/ext/mcrypt
In directory php:/tmp/cvs-serv534
Modified Files:
mcrypt.c php_mcrypt.h
Log Message:
add mcrypt_create_iv()
Index: php4/ext/mcrypt/mcrypt.c
diff -u php4/ext/mcrypt/mcrypt.c:1.4 php4/ext/mcrypt/mcrypt.c:1.5
--- php4/ext/mcrypt/mcrypt.c:1.4 Sun Apr 25 16:44:52 1999
+++ php4/ext/mcrypt/mcrypt.c Sun Apr 25 17:09:07 1999
@@ -31,6 +31,8 @@
#if HAVE_LIBMCRYPT
+#include "fcntl.h"
+
#include "php_mcrypt.h"
#include "lcrypt.h"
@@ -41,6 +43,7 @@
PHP_FE(mcrypt_cfb, NULL)
PHP_FE(mcrypt_get_block_size, NULL)
PHP_FE(mcrypt_get_key_size, NULL)
+ PHP_FE(mcrypt_create_iv, NULL)
{0},
};
@@ -74,6 +77,16 @@
static int php3_minit_mcrypt(INIT_FUNC_ARGS)
{
+ /* modes for mcrypt_??? routines */
+ REGISTER_LONG_CONSTANT("MCRYPT_ENCODE", 0, 0);
+ REGISTER_LONG_CONSTANT("MCRYPT_DECODE", 1, 0);
+
+ /* sources for mcrypt_create_iv */
+ REGISTER_LONG_CONSTANT("MCRYPT_DEV_RANDOM", 0, 0);
+ REGISTER_LONG_CONSTANT("MCRYPT_DEV_URANDOM", 1, 0);
+ REGISTER_LONG_CONSTANT("MCRYPT_RAND", 2, 0);
+
+ /* ciphers */
MCRYPT_ENTRY(BLOWFISH);
MCRYPT_ENTRY(DES);
MCRYPT_ENTRY(TripleDES);
@@ -89,6 +102,52 @@
MCRYPT_ENTRY(CRYPT);
#endif
return SUCCESS;
+}
+
+typedef enum {
+ RANDOM = 0,
+ URANDOM,
+ RAND
+} iv_source;
+
+/* proto mcrypt_create_iv(int size, int source)
+ create an initializing vector (IV) */
+PHP_FUNCTION(mcrypt_create_iv)
+{
+ pval *size, *psource;
+ char *iv;
+ iv_source source;
+ int i;
+
+ if(ARG_COUNT(ht) != 2 || getParameters(ht, 2, &size, &psource) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_long(size);
+ convert_to_long(psource);
+ source = psource->value.lval;
+
+ i = size->value.lval;
+ iv = ecalloc(i, 1);
+
+ if(source == RANDOM || source == URANDOM) {
+ int fd;
+
+ fd = open(source == RANDOM ? "/dev/random" : "/dev/urandom",
+ O_RDONLY);
+ if(fd < 0) {
+ efree(iv);
+ php3_error(E_WARNING, "cannot open source device");
+ RETURN_FALSE;
+ }
+ read(fd, iv, i);
+ close(fd);
+ } else {
+ while(i--) {
+ iv[i] = rand();
+ }
+ }
+ RETURN_STRINGL(iv, size->value.lval, 0);
}
/* proto mcrypt_get_key_size(int cipher)
Index: php4/ext/mcrypt/php_mcrypt.h
diff -u php4/ext/mcrypt/php_mcrypt.h:1.4 php4/ext/mcrypt/php_mcrypt.h:1.5
--- php4/ext/mcrypt/php_mcrypt.h:1.4 Sun Apr 25 16:44:52 1999
+++ php4/ext/mcrypt/php_mcrypt.h Sun Apr 25 17:09:07 1999
@@ -11,6 +11,7 @@
PHP_FUNCTION(mcrypt_cfb);
PHP_FUNCTION(mcrypt_get_block_size);
PHP_FUNCTION(mcrypt_get_key_size);
+PHP_FUNCTION(mcrypt_create_iv);
#else
#define mcrypt_module_ptr NULL
--
PHP 4 Beta