Skip to content

Example code for rsakeygen, pubkey, sign and verify#4

Open
srinivasjc wants to merge 1 commit intopkkancharla:masterfrom
srinivasjc:rsa
Open

Example code for rsakeygen, pubkey, sign and verify#4
srinivasjc wants to merge 1 commit intopkkancharla:masterfrom
srinivasjc:rsa

Conversation

@srinivasjc
Copy link

Example code for rsakeygen, pubkey, sign and verify

while( (opt=getopt(argc, argv, "o:s:h")) != -1) {
switch(opt) {
case 's':
rsabits = atoi(optarg);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use strtol

case 'h':
usage();
goto end;
break;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Break not required;

break;

case 'o':
if((prtkeyfile = (char *) OPENSSL_malloc(strlen(optarg)+1)) == NULL) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why global variable prtkeyfile, just pass this as argument to generate_rsa().

}
}

bio_log = BIO_new_fp(stdout, BIO_NOCLOSE);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bio_log need not to be global.

end:

if(prtkeyfile) {
OPENSSL_free(prtkeyfile);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you don't use prtkeyfile as global we don't need this.

}
}

if (!PEM_write_bio_PrivateKey(prtbio, pkey, NULL, NULL, 0, NULL, NULL)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Output pem can be RSAPrivateKey(pkcs1?) or PrivateKey(pkcs8). The above one writes the key in pkcs8, what is our intention here whether to have pkcs1 or pkcs8, do you want to take an option from the user?.

if (bn) {
BN_free(bn);
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to free 'rsa'.

@@ -0,0 +1,13 @@
all:
gcc genrsa.c -L/opt/openssl/lib -lcrypto -o genrsa
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why /opt/openssl/lib, we have to remove this. And change make file to use Makefile constructs to compiles all c files at ones instead of compiling them individually.



clean:
rm genrsa -rf
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better make it 'rm -rf ' .


char *prtkeyfile=NULL;
BIO *bio_log=NULL;
unsigned int rsabits = 2048;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take rsabits as input.

@@ -0,0 +1,13 @@
all:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent -kr -4 -nut

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant