How to create a wrapper function which uses libcrypto.so for security?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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):
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.
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.
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);
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.