Skip to content

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

Open
srinivasjc wants to merge 1 commit into
pkkancharla:masterfrom
srinivasjc:rsa
Open

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

Conversation

@srinivasjc

Copy link
Copy Markdown

Example code for rsakeygen, pubkey, sign and verify

Comment thread rsa/genrsa.c
while( (opt=getopt(argc, argv, "o:s:h")) != -1) {
switch(opt) {
case 's':
rsabits = atoi(optarg);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use strtol

Comment thread rsa/genrsa.c
case 'h':
usage();
goto end;
break;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Break not required;

Comment thread rsa/genrsa.c
break;

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

Copy link
Copy Markdown

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().

Comment thread rsa/genrsa.c
}
}

bio_log = BIO_new_fp(stdout, BIO_NOCLOSE);

Copy link
Copy Markdown

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.

Comment thread rsa/genrsa.c
end:

if(prtkeyfile) {
OPENSSL_free(prtkeyfile);

Copy link
Copy Markdown

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.

Comment thread rsa/genrsa.c
}
}

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

Copy link
Copy Markdown

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?.

Comment thread rsa/genrsa.c
if (bn) {
BN_free(bn);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Need to free 'rsa'.

Comment thread rsa/Makefile
@@ -0,0 +1,13 @@
all:
gcc genrsa.c -L/opt/openssl/lib -lcrypto -o genrsa

Copy link
Copy Markdown

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.

Comment thread rsa/Makefile


clean:
rm genrsa -rf

Copy link
Copy Markdown

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 ' .

Comment thread rsa/genrsa.c

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

take rsabits as input.

Comment thread rsa/Makefile
@@ -0,0 +1,13 @@
all:

Copy link
Copy Markdown

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