LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-17-2012, 02:06 AM   #16
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,557

Rep: Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092

The code you have written so far is rather short, and two of the statements is bad: you shouldn't overwrite your parameters (opt and dir). Fixed version:
Code:
/* cryptsec.c */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "cryptsec.h"

int cryptsec (
    int opt,                          /* set to zero, for now */
    int dir,                          /* 0 for encode, 1 for decode */
    const char *algorithm_name,       /* see the list */
    const void *key,                  /* key-length is algorithm-dependent */
    const void *data, size_t datalen, /* dir=0: plaintext; dir=1: cipher */
    void *out,  size_t outmaxlen, size_t *outlen /* dir=0: cipher; dir=0: plaintext; */
)
{
    fprintf (stderr, "cryptsec: Unimplemented yet\n");
    return 0;
}
Anyway, if you have your file cryptsec.c (more or less) complete, you can compile it (you have to have libtool installed on your system):

Code:
libtool --mode=compile gcc -g -W -Wall -Wextra -pedantic -o cryptsec.lo -c cryptsec.c
libtool --mode=link gcc -g -rpath ~/lib -version-number 0:0:0 -shared -o libcryptsec.la cryptsec.lo
mkdir ~/lib # just once
libtool --mode=install cp -f libcryptsec.la ~/lib
Now your libcryptsec shared lib is ready to use:

Code:
/* cstest.c */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "cryptsec.h"

int main (int argc, char **argv)
{
    char key [16] = "Some Binary Strn";
    char out [1024];
    size_t outlen;
    int i, rc;

    for (i=0; i<argc; ++i) {
        outlen= 0;
        rc= cryptsec (0, 0, "IDEA", key,
            argv[i], strlen (argv[i]),
            out, sizeof (out), &outlen);

        printf ("cryptsec(\"%s\") returned %d len=%u\n",
            argv[i], rc, (unsigned)outlen);
    }
    return 0;
}
try it:

Code:
gcc -g -W -Wall -Wextra -pedantic -o cstest.o -c cstest.c
libtool --mode=link gcc -g -o cstest cstest.o ~/lib/libcryptsec.la
./cstest "Some plaintext"
 
1 members found this post helpful.
Old 10-17-2012, 08:38 AM   #17
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170
What a strange place to find a rank-beginner's tutorial on C-programming and libraries ...

Most likely, you're barking up the wrong tree altogether. If you want to carry on secure communications, create a secure channel and send otherwise-unencrypted communications across it. If you want to write secure files, use a library that writes secure files.

There's a lot more to the overall issue of encryption than just "encryption algorithms," and packages such as GPG and SSL and SSH already cover these things quite thoroughly. The most likely outcome of "do it yourself" is that you will destroy the file such that even you cannot recover it. The second most likely outcome is "a false sense of security." The thorough and complete implementations of crypto in all of its respects have already been done.
 
1 members found this post helpful.
Old 10-17-2012, 08:59 AM   #18
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,557

Rep: Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092
As far as I remember, the OP didn't say anything about communication or files; they only said they want a simplified/unified program-interface to libcrypto. (Shared or non-shared doesn't matter methinks, but libtool handles that perfectly.
 
Old 10-18-2012, 01:50 AM   #19
vktafs
LQ Newbie
 
Registered: Oct 2012
Distribution: ubuntu 11.10
Posts: 17

Original Poster
Rep: Reputation: Disabled
now i am implementing what you have suggested

Last edited by vktafs; 10-18-2012 at 06:09 AM.
 
Old 10-18-2012, 02:28 AM   #20
vktafs
LQ Newbie
 
Registered: Oct 2012
Distribution: ubuntu 11.10
Posts: 17

Original Poster
Rep: Reputation: Disabled
Please check this site as all the algorithm present in openssl are given along with there API and details.
http://h71000.www7.hp.com/doc/83fina...0007/rn02.html
Suggest me something related to this.I want to use these given API in my Program to create simplified interface for cryptography.

Code:
#include <openssl/dh.h>
#include <openssl/engine.h>
DH * DH_new(void);
void DH_free(DH *dh);
int DH_size(const DH *dh);
DH * DH_generate_parameters(int prime_len, int generator,
void (*callback)(int, int, void *), void *cb_arg);
int DH_check(const DH *dh, int *codes);
int DH_generate_key(DH *dh);
int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh);
void DH_set_default_method(const DH_METHOD *meth);
const DH_METHOD *DH_get_default_method(void);
int DH_set_method(DH *dh, const DH_METHOD *meth);
DH *DH_new_method(ENGINE *engine);
const DH_METHOD *DH_OpenSSL(void);
int DH_get_ex_new_index(long argl, char *argp, int (*new_func)(),
int (*dup_func)(), void (*free_func)());
int DH_set_ex_data(DH *d, int idx, char *arg);
char *DH_get_ex_data(DH *d, int idx);
DH * d2i_DHparams(DH **a, unsigned char **pp, long length);
int i2d_DHparams(const DH *a, unsigned char **pp);
int DHparams_print_fp(FILE *fp, const DH *x);
int DHparams_print(BIO *bp, const DH *x);
 
Old 10-18-2012, 03:19 AM   #21
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,557

Rep: Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092
If I were you, I would start with DES: it is outdated, but it has documentation to start working with.
 
Old 10-18-2012, 04:28 AM   #22
vktafs
LQ Newbie
 
Registered: Oct 2012
Distribution: ubuntu 11.10
Posts: 17

Original Poster
Rep: Reputation: Disabled
This cmd is ok by this command one cryptsec.lo file is created in the same directory
Code:
libtool --mode=compile gcc -g -W -Wall -Wextra -pedantic -o cryptsec.lo -c cryptsec.c
but when i passed the below shown command then it shows error i.e -rpath not found and error that no version....how to resolve it.

Code:
libtool --mode=link gcc -g -rpath ~/lib -version-number 0:0:0 -shared -o libcryptsec.la cryptsec.lo
errors are
Code:
root@mdss03:/home/first_project# gcc --mode=link gcc -g -rpath ~/lib -version-number 0:0:0 -shared -o libcryptsec.la cryptsec.lo
gcc: error: gcc: No such file or directory
gcc: error: 0:0:0: No such file or directory
gcc: error: unrecognized option ‘--mode=link’
gcc: error: unrecognized option ‘-rpath’
gcc: error: unrecognized option ‘-version-number’
this cmd created a directory in same directory
Code:
mkdir ~/lib # just once
This cmd says libcrypt.la not found...
Code:
libtool --mode=install cp -f libcryptsec.la ~/lib

Last edited by vktafs; 10-18-2012 at 05:02 AM.
 
Old 10-18-2012, 04:34 AM   #23
vktafs
LQ Newbie
 
Registered: Oct 2012
Distribution: ubuntu 11.10
Posts: 17

Original Poster
Rep: Reputation: Disabled
I have downloaded the libtool suggested by you and installed it also by the following command
Code:
./configure && make && make install
 
Old 10-18-2012, 05:01 AM   #24
vktafs
LQ Newbie
 
Registered: Oct 2012
Distribution: ubuntu 11.10
Posts: 17

Original Poster
Rep: Reputation: Disabled
what to do next

Last edited by vktafs; 10-18-2012 at 05:02 AM.
 
Old 10-18-2012, 06:41 AM   #25
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,557

Rep: Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092
Please explain how are the following lines equal:

1) libtool --mode=link gcc -g -rpath ~/lib -version-number 0:0:0 -shared -o libcryptsec.la cryptsec.lo
2) gcc --mode=link gcc -g -rpath ~/lib -version-number 0:0:0 -shared -o libcryptsec.la cryptsec.lo

I suggested the first one, but you used the second. Believe me, they aren't the same.
 
Old 10-18-2012, 07:10 AM   #26
vktafs
LQ Newbie
 
Registered: Oct 2012
Distribution: ubuntu 11.10
Posts: 17

Original Poster
Rep: Reputation: Disabled
ok...........
 
Old 10-21-2012, 08:28 AM   #27
vktafs
LQ Newbie
 
Registered: Oct 2012
Distribution: ubuntu 11.10
Posts: 17

Original Poster
Rep: Reputation: Disabled
I have implemented the whatever is suggested above and now it is working.

but,now i want to remake a fucnction which uses openssl's crypto library to implement diffie hellman.
Code:
#include <stdio.h>

#include <stdlib.h>

#include <openssl/dh.h>

#include <openssl/engine.h>

#include <openssl/bn.h>

DH *dh_struct;

int main()

{

unsigned char str_p[] = "57503";
unsigned char str_g[] = "5";

unsigned char *string;

int num_byte,size,i;

dh_struct = DH_new();

dh_struct->p = BN_new();

dh_struct->g = BN_new();

dh_struct->priv_key = BN_new();

dh_struct->pub_key = BN_new();

num_byte = BN_dec2bn(dh_struct->p,str_p); 

num_byte = BN_dec2bn(dh_struct->p,str_g);

size = BN_num_bytes(dh_struct->p); 

string = BN_bn2dec(dh_struct->p);  

i=DH_generate_ket(dh_struct);  

}
I have copied the above source from some website to show you what i want to do.
 
Old 10-21-2012, 08:38 AM   #28
vktafs
LQ Newbie
 
Registered: Oct 2012
Distribution: ubuntu 11.10
Posts: 17

Original Poster
Rep: Reputation: Disabled
How to make function which uses openssl contained crypto library to implement diffie hellman.

some api are given in the source code like
Code:
#include <openssl/dh.h>
DH* DH_new(void);

void DH_free(DH *dh);
int DH_generate_key(DH *dh);
DH *DH_generate_parameters(int prime_len, int g,void (*callback)(int, int, void *), void *cb_arg);
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
wrapper function in c Anuradha12345 Programming 7 07-24-2012 05:20 PM
howto create GUI-graphical wrapper for command line program SaintDanBert Linux - Desktop 4 01-30-2011 08:24 PM
Trying To Create A Rox App Wrapper For XFWM4 Mark7 Linux - General 3 03-22-2008 07:49 AM
Sendmail wrapper to detected spammer (which domain is using PHP's mail function? stefaandk Programming 1 02-12-2007 12:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration