Add a custom 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
Provides FTP + SSL/TLS authentication through OpenSSL and implements secure data transmission.
Use OpenSSL to generate certificates in Linux
Use OpenSSL to sign multi-domain certificates
OpenSSL details: click here
OpenSSL: click here
This article permanently updates the link address: