X-Git-Url: http://git.openwrt.org/?p=openwrt%2Fstaging%2Fyousong.git;a=blobdiff_plain;f=package%2Futils%2Fpx5g-standalone%2Fsrc%2Fpx5g.c;fp=package%2Futils%2Fpx5g-standalone%2Fsrc%2Fpx5g.c;h=34ab34f32d914aba3d0d10bfb0d7c83eaad8ce29;hp=cf50ad28e2675630b3e17f1f2d8910357d0598d6;hb=9893f5f00e0bb677049dc851a76c050d2a64381a;hpb=6c6508d0e18a7573b08c1d8ca3c5cbacd4f7f70b diff --git a/package/utils/px5g-standalone/src/px5g.c b/package/utils/px5g-standalone/src/px5g.c index cf50ad28e2..34ab34f32d 100644 --- a/package/utils/px5g-standalone/src/px5g.c +++ b/package/utils/px5g-standalone/src/px5g.c @@ -23,7 +23,8 @@ #include #include #include -#include "polarssl/havege.h" +#include +#include #include "polarssl/bignum.h" #include "polarssl/x509.h" #include "polarssl/rsa.h" @@ -32,8 +33,17 @@ #define PX5G_COPY "Copyright (c) 2009 Steven Barth " #define PX5G_LICENSE "Licensed under the GNU Lesser General Public License v2.1" +static int urandom_fd; + +static int _urandom(void *ctx) +{ + int ret; + read(urandom_fd, &ret, sizeof(ret)); + return ret; +} + + int rsakey(char **arg) { - havege_state hs; rsa_context rsa; unsigned int ksize = 512; @@ -57,8 +67,7 @@ int rsakey(char **arg) { ksize = (unsigned int)atoi(*arg); } - havege_init(&hs); - rsa_init(&rsa, RSA_PKCS_V15, 0, havege_rand, &hs); + rsa_init(&rsa, RSA_PKCS_V15, 0, _urandom, NULL); fprintf(stderr, "Generating RSA private key, %i bit long modulus\n", ksize); if (rsa_gen_key(&rsa, ksize, exp)) { @@ -76,7 +85,6 @@ int rsakey(char **arg) { } int selfsigned(char **arg) { - havege_state hs; rsa_context rsa; x509_node node; @@ -139,8 +147,7 @@ int selfsigned(char **arg) { arg++; } - havege_init(&hs); - rsa_init(&rsa, RSA_PKCS_V15, 0, havege_rand, &hs); + rsa_init(&rsa, RSA_PKCS_V15, 0, _urandom, NULL); x509write_init_node(&node); fprintf(stderr, "Generating RSA private key, %i bit long modulus\n", ksize); if (rsa_gen_key(&rsa, ksize, exp)) { @@ -184,6 +191,12 @@ int selfsigned(char **arg) { } int main(int argc, char *argv[]) { + urandom_fd = open("/dev/urandom", O_RDONLY); + if (urandom_fd < 0) { + perror("open(/dev/urandom)"); + return 1; + } + if (!argv[1]) { //Usage } else if (!strcmp(argv[1], "rsakey")) {