[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[or-cvs] Updated to use crypto.h instead of OpenSSL.



Update of /home/or/cvsroot/src/orkeygen
In directory moria.seul.org:/tmp/cvs-serv23710

Modified Files:
	Makefile.am orkeygen.c 
Log Message:
Updated to use crypto.h instead of OpenSSL.


Index: Makefile.am
===================================================================
RCS file: /home/or/cvsroot/src/orkeygen/Makefile.am,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Makefile.am	28 Jun 2002 23:26:42 -0000	1.1
+++ Makefile.am	25 Jul 2002 08:18:05 -0000	1.2
@@ -2,3 +2,5 @@
 bin_PROGRAMS = orkeygen
 
 orkeygen_SOURCES = orkeygen.c
+
+orkeygen_LDADD = -L../common -lor

Index: orkeygen.c
===================================================================
RCS file: /home/or/cvsroot/src/orkeygen/orkeygen.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- orkeygen.c	26 Jun 2002 22:45:50 -0000	1.1.1.1
+++ orkeygen.c	25 Jul 2002 08:18:05 -0000	1.2
@@ -8,6 +8,9 @@
 /*
  * Changes :
  * $Log$
+ * Revision 1.2  2002/07/25 08:18:05  badbytes
+ * Updated to use crypto.h instead of OpenSSL.
+ *
  * Revision 1.1.1.1  2002/06/26 22:45:50  arma
  * initial commit: current code
  *
@@ -19,9 +22,8 @@
 
 #include <stdlib.h>
 #include <stdio.h>
-#include <openssl/rsa.h>
-#include <openssl/err.h>
-#include <openssl/pem.h>
+
+#include "../common/crypto.h"
 
 int main(int argc, char *argv[])
 {
@@ -32,7 +34,7 @@
   FILE *f_pr = NULL;
   FILE *f_pu = NULL;
   
-  RSA *rsa_key = NULL;
+  crypto_pk_env_t *env;
  
   int retval = 0;
   
@@ -43,16 +45,24 @@
     exit(1);
   }
   
+  crypto_global_init();
+  
+  env = crypto_new_pk_env(CRYPTO_PK_RSA);
+  if (!env)
+  {
+    printf("Could not create a crypto environment.");
+    exit(1);
+  }
+  
   /* generate the key */
-  rsa_key = RSA_generate_key(1024,65535,NULL,NULL);
-  if (!rsa_key) /* error has occured */
+  if (crypto_pk_generate_key(env)) /* error has occured */
   {
-    printf("%s",ERR_reason_error_string(ERR_get_error()));
+    printf("%s",crypto_perror());
     exit(1);
   }
   else /* keys generated */
   {
-    retval = RSA_check_key(rsa_key);
+    retval = crypto_pk_check_key(env);
     if (retval == 1)
     {
       printf("Generated key seems to be valid.\n");
@@ -61,7 +71,7 @@
       if (!f_pr)
       {
 	perror("fopen");
-	RSA_free(rsa_key);
+	crypto_free_pk_env(env);
 	exit(1);
       }
       
@@ -69,29 +79,27 @@
       if (!f_pu)
       {
 	perror("fopen");
-	RSA_free(rsa_key);
+	crypto_free_pk_env(env);
 	exit(1);
       }
       
       /* write the private key */
-      retval = PEM_write_RSAPrivateKey(f_pr,rsa_key,NULL,NULL,0,0,NULL);
-      if (retval == 0)
+      if (crypto_pk_write_private_key(env, f_pr) == -1)
       {
-	printf("%s",ERR_reason_error_string(ERR_get_error()));
+	printf("%s",crypto_perror());
 	fclose(f_pr);
 	fclose(f_pu);
-	RSA_free(rsa_key);
+        crypto_free_pk_env(env);
 	exit(1);
       }
       
       /* write the public key */
-      retval = PEM_write_RSAPublicKey(f_pu,rsa_key);
-      if (retval == 0)
+      if (crypto_pk_write_public_key(env, f_pu) == -1)
       {
-	printf("%s",ERR_reason_error_string(ERR_get_error()));
+	printf("%s",crypto_perror());
 	fclose(f_pr);
 	fclose(f_pu);
-	RSA_free(rsa_key);
+        crypto_free_pk_env(env);
 	exit(1);
       }
       
@@ -100,18 +108,19 @@
     else if (retval == 0)
     {
       printf("Generated key seems to be invalid. Exiting.\n");
-      RSA_free(rsa_key);
+      crypto_free_pk_env(env);
       exit(1);
     }
     else if (retval == -1)
     {
-      printf("%s",ERR_reason_error_string(ERR_get_error()));
-      RSA_free(rsa_key);
+      printf("%s",crypto_perror());
+      crypto_free_pk_env(env);
       exit(1);
     }
   }
      
-  RSA_free(rsa_key);
+  crypto_free_pk_env(env);
+  crypto_global_cleanup();
   fclose(f_pu);
   fclose(f_pr);
   exit(0);