/********************************************************************** This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ************************************************************************ (c) 2004 by Paolo Ardoino < paolo.ardoino@gmail.com > ***********************************************************************/ #define _GNU_SOURCE #include #include #include #include #include void status() {} void print_prime(char *prime) { int i; for(i = 0; i < strlen(prime) && prime[i] == '0'; i++); for(; i < strlen(prime); i++) printf("%c", prime[i]); printf("\n"); } int main(int argc, char *argv[]) { char *prime; BIGNUM *num_tmp; long int num_bits = 0; if(argc >= 2 && argv[1]) num_bits = atol(argv[1]); else num_bits = 1024; printf("Prime generator by (c) 2004 Paolo Ardoino < paolo.ardoino@gmail.com >\n usage: ./genprimes [num_bits]\nGenerating %ld bits primes.\nWait...\n",num_bits); num_tmp = BN_new(); for (;;) { BN_generate_prime(num_tmp,num_bits,1,NULL,NULL,status,NULL); prime = (char *)malloc(BN_num_bytes(num_tmp)); prime = BN_bn2dec(num_tmp); print_prime(prime); free(prime); } BN_free(num_tmp); }