Monday, May 05, 2008

Magic-ssl and Change of basis matrix with its inverse made easy and O(1)

I have not posted long time ago, I've been busy with school and work, my life has had a big change, but well anything is fine, except that i need more time to dedicate to the things i like to do , but well...

here is something new... , I've been working in my elliptic curve library in my spare time , and is almost finished , It will be ready this summer, other little programs I made that may be interesting to you is a "magic-ssl" library with SSL state-save connection , just in the case you want to do a 'normal' client-tcp-ssl connection in C

here are the prototypes I explain it here because people says i do not document my stuff , and in fact is not documented so , read this if you are interested.

Magic-ssl library

If someone really like this little library write me and if just one asks ill put a formal documentation.

To compile , use the functions as ill explain here and then

gcc magic.c -I . -lssl main.c

where main.c is your file , or make a dynamic library

gcc magic.c -I . -lssl -fPIC -shared -o

It is important to put and not because

there's a in almost all unixes.

Magic ssl API

* This is my main opaque type , its used in all my functions , you dont need to know it
* because all is filled in the internals but well i present you this

typedef struct remote {
int fd; /* remote fd */
int ssl; /* has ssl ? */
struct sockaddr_in addr; /* remote address info */
SSL *active; /* this pointer tells if is active or not */
SSL_CTX *ctx; /* context of the ssl negotiation */
} remote_t;

/* this is the first function you will need to call to a remote_t
* to allocate all the stuff we need

void *magic_alloc(void);

/* This is the second function you will need to call
* arg1 = hostname or IP of the remote host
* arg2 = port number (it must be short but well , i put int)
* arg3 = SSL_ON or SSL_OFF (if you want to do a SSL handshake or just a normal socket
* arg4 = pointer to the remote_t we malloced before

int magic_tcpconnect(const char *,int,int,remote_t *);

/* Third function is for writing to socket
* the syntax is like write(2) , the difference is that
* arg1 = remote_t descriptor we created at the begining
* arg2 = pointer to bufdata we are going to write in socket
* arg3 = size of data to write

int magic_write (remote_t *, void *, int)

/* Fourth function is the dual of the above
* and is the same logic

int magic_read (remote_t *, void *, int);

/* Fifth function closes connection
* arg1=pointer to remote_t we used to create our context

void magic_close (remote_t *);

/* Sixth function free's the malloced area we created at the beginning
* arg1=pointer to remote_t we used to create our context

void magic_free(remote_t *);

/* other functions that are 'internal use' that you do not need to know about its existence */

/* creates a socket , first 3 args are same as socket(2)
* arg4 = SSL_ON or SSL_OFF
* arg4 = pointer to remote_t

int magic_socket (int, int, int, int,remote_t *);

/* Creates the SSL context and loads the most used algorithms , no arguments are required */

SSL_CTX *magic_initctx(void);

/* shows certificates currently in context */

void magic_showcerts(SSL *);

/* is like a poll() built from select() , this function is the reason
* that connections lag 0.5 seconds in the handshake , you can modify this
* in the variable in microseconds
* timeout.tv_usec = 500000;

int magic_sock_ready (remote_t *);

magic ssl can be found here

End of magic-ssl

Change of basis matrix and its inverse made easy and O(1)

Here's another program ill pase the comment of the program and the link

* This is a simple O(1) algorithm to calculate the change of basis matrix and its inverse
* using some basic theory and a lot of patience :p
* the purpose of this is to 'try' to implement an algorithm to compare two images
* using the vector algebra of the colors and the hausdorff distance , this algorithm
* will calculate the change of matrix of the 'interesting' points in the known image
* to the image that we do not know anything
* Eduardo Ruiz Duarte

Output is like this , i took a known basis from a book and then check with my program..
here's the output.
function that calculate both matrices take as arguments

/* arg1=first basis
* arg2=second basis
* arg3=array of two points that indicate the columns of the forward matrix (to allocate)
* arg4=same as arg3 but is the space to allocate the inverse matrix

R2_chbm (R2_base_t A, R2_base_t B, R2_point_t fwdmat[2], R2_point_t invmat[2])

check the main() to see an example.

[beck@dirichlet ~]$ ./cob
B1 = { (1.00,3.00) ; (2.00,1.00) } B2 = { (1.00,1.00) ; (2.00,-1.00) }
matriz de ida
0.20 -0.80
0.40 1.40
matriz de regreso
2.33 1.33
-0.67 0.33

No comments: