summaryrefslogtreecommitdiff
path: root/src/orkeygen
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2002-06-26 22:45:49 +0000
committerRoger Dingledine <arma@torproject.org>2002-06-26 22:45:49 +0000
commit9a928eeb1215f0d7c9b6d0bb9e4571d0a16ed79a (patch)
treefac560bf2dce8a8d2b82e296b71ff24f59ab1a7a /src/orkeygen
parent766a465a6043ac4e643c398feb14f708fd0d863f (diff)
downloadtor-9a928eeb1215f0d7c9b6d0bb9e4571d0a16ed79a.tar.gz
tor-9a928eeb1215f0d7c9b6d0bb9e4571d0a16ed79a.zip
Initial revision
svn:r2
Diffstat (limited to 'src/orkeygen')
-rw-r--r--src/orkeygen/Makefile58
-rw-r--r--src/orkeygen/orkeygen.c119
2 files changed, 177 insertions, 0 deletions
diff --git a/src/orkeygen/Makefile b/src/orkeygen/Makefile
new file mode 100644
index 0000000000..20c65c4571
--- /dev/null
+++ b/src/orkeygen/Makefile
@@ -0,0 +1,58 @@
+SRC=orkeygen.c
+OBJ=${SRC:.c=.o}
+PROGS=orkeygen
+LIB=-L/usr/local/ssl/lib
+LIBS=-lcrypto
+INCLUDE=-I/usr/local/ssl/include
+
+CFLAGS= $(INCLUDE)
+LDFLAGS = $(LIB) ${LIBS}
+
+all: ${PROGS}
+
+clean:
+ rm -f *.o ${PROGS}
+
+depend:
+ makedepend -- ${CFLAGS} -- ${SRC}
+
+${PROGS}: ${OBJ}
+ $(LINK.c) -o $@ $(OBJ)
+
+# DO NOT DELETE
+
+
+orkeygen.o: /usr/include/alloca.h /usr/include/asm/errno.h
+orkeygen.o: /usr/include/bits/endian.h /usr/include/bits/errno.h
+orkeygen.o: /usr/include/bits/pthreadtypes.h /usr/include/bits/sched.h
+orkeygen.o: /usr/include/bits/select.h /usr/include/bits/sigset.h
+orkeygen.o: /usr/include/bits/stdio_lim.h /usr/include/bits/time.h
+orkeygen.o: /usr/include/bits/types.h /usr/include/bits/waitflags.h
+orkeygen.o: /usr/include/bits/waitstatus.h /usr/include/bits/wchar.h
+orkeygen.o: /usr/include/endian.h /usr/include/errno.h /usr/include/features.h
+orkeygen.o: /usr/include/_G_config.h /usr/include/gconv.h
+orkeygen.o: /usr/include/gnu/stubs.h /usr/include/libio.h
+orkeygen.o: /usr/include/linux/errno.h /usr/include/openssl/asn1.h
+orkeygen.o: /usr/include/openssl/bio.h /usr/include/openssl/blowfish.h
+orkeygen.o: /usr/include/openssl/bn.h /usr/include/openssl/buffer.h
+orkeygen.o: /usr/include/openssl/cast.h /usr/include/openssl/crypto.h
+orkeygen.o: /usr/include/openssl/des.h /usr/include/openssl/dh.h
+orkeygen.o: /usr/include/openssl/dsa.h /usr/include/openssl/e_os2.h
+orkeygen.o: /usr/include/openssl/err.h /usr/include/openssl/evp.h
+orkeygen.o: /usr/include/openssl/lhash.h /usr/include/openssl/md2.h
+orkeygen.o: /usr/include/openssl/md4.h /usr/include/openssl/md5.h
+orkeygen.o: /usr/include/openssl/objects.h /usr/include/openssl/obj_mac.h
+orkeygen.o: /usr/include/openssl/opensslconf.h /usr/include/openssl/opensslv.h
+orkeygen.o: /usr/include/openssl/pem2.h /usr/include/openssl/pem.h
+orkeygen.o: /usr/include/openssl/pkcs7.h /usr/include/openssl/rc2.h
+orkeygen.o: /usr/include/openssl/rc4.h /usr/include/openssl/ripemd.h
+orkeygen.o: /usr/include/openssl/rsa.h /usr/include/openssl/safestack.h
+orkeygen.o: /usr/include/openssl/sha.h /usr/include/openssl/stack.h
+orkeygen.o: /usr/include/openssl/symhacks.h /usr/include/openssl/x509.h
+orkeygen.o: /usr/include/openssl/x509_vfy.h /usr/include/stdio.h
+orkeygen.o: /usr/include/stdlib.h /usr/include/sys/cdefs.h
+orkeygen.o: /usr/include/sys/select.h /usr/include/sys/sysmacros.h
+orkeygen.o: /usr/include/sys/types.h /usr/include/time.h /usr/include/wchar.h
+orkeygen.o: /usr/include/xlocale.h
+orkeygen.o: /usr/lib/gcc-lib/i386-redhat-linux/2.96/include/stdarg.h
+orkeygen.o: /usr/lib/gcc-lib/i386-redhat-linux/2.96/include/stddef.h
diff --git a/src/orkeygen/orkeygen.c b/src/orkeygen/orkeygen.c
new file mode 100644
index 0000000000..718f888f47
--- /dev/null
+++ b/src/orkeygen/orkeygen.c
@@ -0,0 +1,119 @@
+/**
+ * orkeygen.c
+ * Key generation utility.
+ *
+ * Matej Pfajfar <mp292@cam.ac.uk>
+ */
+
+/*
+ * Changes :
+ * $Log$
+ * Revision 1.1 2002/06/26 22:45:50 arma
+ * Initial revision
+ *
+ * Revision 1.1 2002/01/04 07:19:27 badbytes
+ * Key generation utility.
+ *
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <openssl/rsa.h>
+#include <openssl/err.h>
+#include <openssl/pem.h>
+
+int main(int argc, char *argv[])
+{
+
+ char *file_pr = argv[1];
+ char *file_pu = argv[2];
+
+ FILE *f_pr = NULL;
+ FILE *f_pu = NULL;
+
+ RSA *rsa_key = NULL;
+
+ int retval = 0;
+
+
+ if (argc < 3)
+ {
+ printf("Need two files, for private and public key in that order.\n");
+ exit(1);
+ }
+
+ /* generate the key */
+ rsa_key = RSA_generate_key(1024,65535,NULL,NULL);
+ if (!rsa_key) /* error has occured */
+ {
+ printf("%s",ERR_reason_error_string(ERR_get_error()));
+ exit(1);
+ }
+ else /* keys generated */
+ {
+ retval = RSA_check_key(rsa_key);
+ if (retval == 1)
+ {
+ printf("Generated key seems to be valid.\n");
+ /* open the output files */
+ f_pr = fopen(file_pr,"w");
+ if (!f_pr)
+ {
+ perror("fopen");
+ RSA_free(rsa_key);
+ exit(1);
+ }
+
+ f_pu = fopen(file_pu,"w");
+ if (!f_pu)
+ {
+ perror("fopen");
+ RSA_free(rsa_key);
+ exit(1);
+ }
+
+ /* write the private key */
+ retval = PEM_write_RSAPrivateKey(f_pr,rsa_key,NULL,NULL,0,0,NULL);
+ if (retval == 0)
+ {
+ printf("%s",ERR_reason_error_string(ERR_get_error()));
+ fclose(f_pr);
+ fclose(f_pu);
+ RSA_free(rsa_key);
+ exit(1);
+ }
+
+ /* write the public key */
+ retval = PEM_write_RSAPublicKey(f_pu,rsa_key);
+ if (retval == 0)
+ {
+ printf("%s",ERR_reason_error_string(ERR_get_error()));
+ fclose(f_pr);
+ fclose(f_pu);
+ RSA_free(rsa_key);
+ exit(1);
+ }
+
+ printf("Keys written to files %s (public) and %s (private).\n",file_pu,file_pr);
+ }
+ else if (retval == 0)
+ {
+ printf("Generated key seems to be invalid. Exiting.\n");
+ RSA_free(rsa_key);
+ exit(1);
+ }
+ else if (retval == -1)
+ {
+ printf("%s",ERR_reason_error_string(ERR_get_error()));
+ RSA_free(rsa_key);
+ exit(1);
+ }
+ }
+
+ RSA_free(rsa_key);
+ fclose(f_pu);
+ fclose(f_pr);
+ exit(0);
+
+ }