Add a custom encryption algorithm and OpenSSL encryption algorithm to openssl.

Source: Internet
Author: User

Add a custom encryption algorithm and OpenSSL encryption algorithm to openssl.

I. Introduction

This document introduces how to add a custom encryption algorithm to OpenSSL by taking the custom algorithm EVP_ssf33 as an example.

 

Step 2

1. Modify crypto/object/objects.txt and register the algorithm OID as follows:

rsadsi 3 255    : SSF33     : ssf33

2. Go to the directory: crypto/object/and run the following command to generate the algorithm declaration.

perl objects.pl objects.txt obj_mac.num obj_mac.h

3. Add e_ssf33.c under crypto/evp/. The content is as follows:

#include <stdio.h>#include "cryptlib.h"#ifndef OPENSSL_NO_RC4    #include <openssl/evp.h>    #include <openssl/objects.h>    #include <openssl/rc4.h>        /* FIXME: surely this is available elsewhere? */    #define EVP_SSF33_KEY_SIZE      16        typedef struct    {        RC4_KEY ks; /* working key */    } EVP_SSF33_KEY;        #define data(ctx) ((EVP_SSF33_KEY *)(ctx)->cipher_data)        static int ssf33_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv,int enc);        static int ssf33_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl);        static const EVP_CIPHER ssf33_evp_cipher=    {        NID_ssf33,        1,        EVP_SSF33_KEY_SIZE,        0,        EVP_CIPH_VARIABLE_LENGTH,        ssf33_init_key,        ssf33_cipher,        NULL,        sizeof(EVP_SSF33_KEY),        NULL,        NULL,        NULL,        NULL    };        const EVP_CIPHER *EVP_ssf33(void)    {        return(&ssf33_evp_cipher);    }        static int ssf33_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc)    {        RC4_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx), key);            return 1;    }        static int ssf33_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl)    {        RC4(&data(ctx)->ks,inl,in,out);            return 1;    }#endif
4. Modify crypto/evp. h and add the algorithm declaration as follows:
const EVP_CIPHER *EVP_ssf33(void);
5. Modify crypto/evp/c_allc.c and use EVP_add_cipher to register the encryption function in the OpenSSL_add_all_ciphers function, as shown below:
EVP_add_cipher(EVP_ssf33());

6. Modify crypto/evp/Makefile as follows:

7. Complete

 

Reference: http://blog.csdn.net/force_eagle/article/details/794856

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.