LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-13-2012, 01:49 AM   #1
vktafs
LQ Newbie
 
Registered: Oct 2012
Distribution: ubuntu 11.10
Posts: 17

Rep: Reputation: Disabled
How to create a wrapper function which uses libcrypto.so for security?


libcrypto is present in /usr/lib64/libcrypto.so
 
Old 10-13-2012, 09:24 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,394
Blog Entries: 55

Rep: Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565Reputation: 3565
Moved: This thread is more suitable in the Programming Forum and has been moved accordingly to help your thread/question get the exposure it deserves.
*It might make sense to post what you have tried to find and what code you came up with so far*.
 
1 members found this post helpful.
Old 10-13-2012, 01:53 PM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,632

Rep: Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114
There is no point in making such functions, but here you go:

Code:
#include <openssl/md5.h>

unsigned char *W_MD5(const unsigned char *d, unsigned long n, unsigned char *md)
{
    return MD5(d, n, md);
}

int W_MD5_Init(MD5_CTX *c)
{
    return MD5_Init(c);
}

int W_MD5_Update(MD5_CTX *c, const void *data,
                  unsigned long len)
{
    return MD5_Update(c, data, len);
}

int W_MD5_Final(unsigned char *md, MD5_CTX *c);
{
    return MD5_Final(md, c);
}
 
1 members found this post helpful.
Old 10-15-2012, 12:52 AM   #4
vktafs
LQ Newbie
 
Registered: Oct 2012
Distribution: ubuntu 11.10
Posts: 17

Original Poster
Rep: Reputation: Disabled
I have just started this from my own and i am new to security also.....what i am thinking to make is a CAPI in which i can pass the algorithm,bit,data,key and return should be the encrypted data and vice-verse working for decryption.

apiname(algorithm,data,key,bits)

Last edited by vktafs; 11-01-2012 at 12:58 AM.
 
Old 10-15-2012, 03:35 AM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,632

Rep: Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114
So you mean a simplified interface for different cipher algorithms. Where did the project stop? Have you written any source-code yet?
 
1 members found this post helpful.
Old 10-15-2012, 05:17 AM   #6
vktafs
LQ Newbie
 
Registered: Oct 2012
Distribution: ubuntu 11.10
Posts: 17

Original Poster
Rep: Reputation: Disabled
yes,I want to make simplified interface which uses OpenSSL and performs the required task according to the filled arguments.
After understanding about security and different cryptographic methods i started with making shared library i.e .so file coz if anytime .so creating task comes i can make it done,after that i explored openssl in linux which comes default with linux ubuntu version.
Finally i installed OpenSSL in mine system with these steps -> make,make test,make install and ./config cmds but, now what should be the next step is not clicking in my mind.
I have not written any source code till now.
I also dont know how to make a wrapper function.

Last edited by vktafs; 10-15-2012 at 06:32 AM.
 
Old 10-15-2012, 07:14 AM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,632

Rep: Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114
For a start, create the header file with the prototype of your planned function(s).
 
1 members found this post helpful.
Old 10-15-2012, 08:18 AM   #8
vktafs
LQ Newbie
 
Registered: Oct 2012
Distribution: ubuntu 11.10
Posts: 17

Original Poster
Rep: Reputation: Disabled
//File name:"header.h"
//Simplified Interface name: "cryptsec"
//output will be held in the "output" named argument


#include<stdio.h>

void cryptsec(Algorithm Name,Data,Key,Bits,output);
 
Old 10-15-2012, 08:54 AM   #9
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,632

Rep: Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114
Prototype does include the type-specification of parameters.

Notes:
1. "header.h" isn't a good name
2. don't include stdio.h if you don't have a reason to
3. please use [code] and [/code] tags
 
1 members found this post helpful.
Old 10-15-2012, 11:51 PM   #10
vktafs
LQ Newbie
 
Registered: Oct 2012
Distribution: ubuntu 11.10
Posts: 17

Original Poster
Rep: Reputation: Disabled
Code:
/*File name: headcryptsec.h */
void cryptsec(Algorithm_Name,unsigned int Data,unsigned int Key,unsigned int Bits,output)

Last edited by vktafs; 10-18-2012 at 07:08 AM.
 
Old 10-16-2012, 03:30 AM   #11
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,632

Rep: Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114
That's what compiler is good for:
Code:
echo '#include "headcryptsec.h"' >headcryptsec.c
gcc -W -Wall -Wextra -c headcryptsec.c

In file included from headcryptsec.c:1:
headcryptsec.h:2: error: expected ')' before 'unsigned'
Meaning: missing data-type for 'Algorithm_Name' (and for 'output') plus Data and Key shouldn't be unsigned integers...
 
1 members found this post helpful.
Old 10-16-2012, 07:15 AM   #12
vktafs
LQ Newbie
 
Registered: Oct 2012
Distribution: ubuntu 11.10
Posts: 17

Original Poster
Rep: Reputation: Disabled
I think we can write here char * as it is a string and name of a algorithm.
and for output i am thinking to give it unsigned int only.
Code:
/*File name: headcryptsec.h */
void cryptsec(char * algorithm_name,unsigned int data,unsigned int key,unsigned int bits,unsigned int output)
after this what to do i have completed what you have suggested.
I passed the following cmd as to explore openssl and supported Diffie Hellman algorithm
cmd: locate openssl/dh.h
I got a header file but what to do next and how to use and implement shared library concept ...some .so file are also there in openssl library.
 
Old 10-16-2012, 07:46 AM   #13
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,632

Rep: Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114
Okay, let's try to fix it:

Code:
/* cryptsec.h */

#ifndef CRYPTSEC_H
#define CRYPTSEC_H

#include <stddef.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; */
);

/* list the possible algorothms: */
/* <insert list> */
/* return value: 0 for OK; everything else: error code */

#endif
Or something like this. Now it is your turn to actually implement this function. (Don't worry about shared vs static libraries right now. That will be a very little part when your program has been finished.)

Last edited by NevemTeve; 10-17-2012 at 02:46 AM. Reason: >>> syntax error fixed: not semicolon, comma after parameters
 
1 members found this post helpful.
Old 10-17-2012, 01:33 AM   #14
vktafs
LQ Newbie
 
Registered: Oct 2012
Distribution: ubuntu 11.10
Posts: 17

Original Poster
Rep: Reputation: Disabled
Code:
#include <stddef.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; */
)

/* list the possible algorothms: */
/* <insert list>
1.AES             Symmetric
2.Diffie Hellman  Asymmetric   
3.SHA-256         Messeage Digest
4.ECDSA           Digital Signature
*/
/* return value: 0 for OK; everything else: error code */

Last edited by vktafs; 10-18-2012 at 06:10 AM. Reason: This one is better i.e why...
 
Old 10-17-2012, 02:32 AM   #15
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);

Last edited by vktafs; 10-17-2012 at 02:40 AM.
 
  


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 06:20 PM
howto create GUI-graphical wrapper for command line program SaintDanBert Linux - Desktop 4 01-30-2011 09:24 PM
Trying To Create A Rox App Wrapper For XFWM4 Mark7 Linux - General 3 03-22-2008 08:49 AM
Sendmail wrapper to detected spammer (which domain is using PHP's mail function? stefaandk Programming 1 02-12-2007 01:13 AM

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

All times are GMT -5. The time now is 06:28 AM.

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