Home | History | Annotate | Line # | Download | only in hcrypto
      1 /*	$NetBSD: evp-hcrypto.c,v 1.3 2023/06/19 21:41:43 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2006 - 2008 Kungliga Tekniska Hgskolan
      5  * (Royal Institute of Technology, Stockholm, Sweden).
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  *
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  *
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * 3. Neither the name of the Institute nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  */
     35 
     36 #include <config.h>
     37 #include <krb5/roken.h>
     38 
     39 #define HC_DEPRECATED
     40 
     41 #include <assert.h>
     42 
     43 #include <evp.h>
     44 #include <evp-hcrypto.h>
     45 
     46 #include <krb5/krb5-types.h>
     47 
     48 #include <des.h>
     49 #include "camellia.h"
     50 #include <aes.h>
     51 
     52 #include <rc2.h>
     53 #include <rc4.h>
     54 
     55 #include <sha.h>
     56 #include <md4.h>
     57 #include <md5.h>
     58 
     59 /*
     60  *
     61  */
     62 
     63 static int
     64 aes_init(EVP_CIPHER_CTX *ctx,
     65 	 const unsigned char * key,
     66 	 const unsigned char * iv,
     67 	 int encp)
     68 {
     69     AES_KEY *k = ctx->cipher_data;
     70     if (ctx->encrypt || EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_CFB8_MODE)
     71 	AES_set_encrypt_key(key, ctx->cipher->key_len * 8, k);
     72     else
     73 	AES_set_decrypt_key(key, ctx->cipher->key_len * 8, k);
     74     return 1;
     75 }
     76 
     77 static int
     78 aes_do_cipher(EVP_CIPHER_CTX *ctx,
     79 	      unsigned char *out,
     80 	      const unsigned char *in,
     81 	      unsigned int size)
     82 {
     83     AES_KEY *k = ctx->cipher_data;
     84     if (EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_CFB8_MODE)
     85         AES_cfb8_encrypt(in, out, size, k, ctx->iv, ctx->encrypt);
     86     else
     87         AES_cbc_encrypt(in, out, size, k, ctx->iv, ctx->encrypt);
     88     return 1;
     89 }
     90 
     91 /**
     92  * The AES-128 cipher type (hcrypto)
     93  *
     94  * @return the AES-128 EVP_CIPHER pointer.
     95  *
     96  * @ingroup hcrypto_evp
     97  */
     98 
     99 const EVP_CIPHER *
    100 EVP_hcrypto_aes_128_cbc(void)
    101 {
    102     static const EVP_CIPHER aes_128_cbc = {
    103 	0,
    104 	16,
    105 	16,
    106 	16,
    107 	EVP_CIPH_CBC_MODE,
    108 	aes_init,
    109 	aes_do_cipher,
    110 	NULL,
    111 	sizeof(AES_KEY),
    112 	NULL,
    113 	NULL,
    114 	NULL,
    115 	NULL
    116     };
    117 
    118     return &aes_128_cbc;
    119 }
    120 
    121 /**
    122  * The AES-192 cipher type (hcrypto)
    123  *
    124  * @return the AES-192 EVP_CIPHER pointer.
    125  *
    126  * @ingroup hcrypto_evp
    127  */
    128 
    129 const EVP_CIPHER *
    130 EVP_hcrypto_aes_192_cbc(void)
    131 {
    132     static const EVP_CIPHER aes_192_cbc = {
    133 	0,
    134 	16,
    135 	24,
    136 	16,
    137 	EVP_CIPH_CBC_MODE,
    138 	aes_init,
    139 	aes_do_cipher,
    140 	NULL,
    141 	sizeof(AES_KEY),
    142 	NULL,
    143 	NULL,
    144 	NULL,
    145 	NULL
    146     };
    147     return &aes_192_cbc;
    148 }
    149 
    150 /**
    151  * The AES-256 cipher type (hcrypto)
    152  *
    153  * @return the AES-256 EVP_CIPHER pointer.
    154  *
    155  * @ingroup hcrypto_evp
    156  */
    157 
    158 const EVP_CIPHER *
    159 EVP_hcrypto_aes_256_cbc(void)
    160 {
    161     static const EVP_CIPHER aes_256_cbc = {
    162 	0,
    163 	16,
    164 	32,
    165 	16,
    166 	EVP_CIPH_CBC_MODE,
    167 	aes_init,
    168 	aes_do_cipher,
    169 	NULL,
    170 	sizeof(AES_KEY),
    171 	NULL,
    172 	NULL,
    173 	NULL,
    174 	NULL
    175     };
    176     return &aes_256_cbc;
    177 }
    178 
    179 /**
    180  * The AES-128 CFB8 cipher type (hcrypto)
    181  *
    182  * @return the AES-128 EVP_CIPHER pointer.
    183  *
    184  * @ingroup hcrypto_evp
    185  */
    186 
    187 const EVP_CIPHER *
    188 EVP_hcrypto_aes_128_cfb8(void)
    189 {
    190     static const EVP_CIPHER aes_128_cfb8 = {
    191 	0,
    192 	1,
    193 	16,
    194 	16,
    195 	EVP_CIPH_CFB8_MODE,
    196 	aes_init,
    197 	aes_do_cipher,
    198 	NULL,
    199 	sizeof(AES_KEY),
    200 	NULL,
    201 	NULL,
    202 	NULL,
    203 	NULL
    204     };
    205 
    206     return &aes_128_cfb8;
    207 }
    208 
    209 /**
    210  * The AES-192 CFB8 cipher type (hcrypto)
    211  *
    212  * @return the AES-192 EVP_CIPHER pointer.
    213  *
    214  * @ingroup hcrypto_evp
    215  */
    216 
    217 const EVP_CIPHER *
    218 EVP_hcrypto_aes_192_cfb8(void)
    219 {
    220     static const EVP_CIPHER aes_192_cfb8 = {
    221 	0,
    222 	1,
    223 	24,
    224 	16,
    225 	EVP_CIPH_CFB8_MODE,
    226 	aes_init,
    227 	aes_do_cipher,
    228 	NULL,
    229 	sizeof(AES_KEY),
    230 	NULL,
    231 	NULL,
    232 	NULL,
    233 	NULL
    234     };
    235     return &aes_192_cfb8;
    236 }
    237 
    238 /**
    239  * The AES-256 CFB8 cipher type (hcrypto)
    240  *
    241  * @return the AES-256 EVP_CIPHER pointer.
    242  *
    243  * @ingroup hcrypto_evp
    244  */
    245 
    246 const EVP_CIPHER *
    247 EVP_hcrypto_aes_256_cfb8(void)
    248 {
    249     static const EVP_CIPHER aes_256_cfb8 = {
    250 	0,
    251 	1,
    252 	32,
    253 	16,
    254 	EVP_CIPH_CFB8_MODE,
    255 	aes_init,
    256 	aes_do_cipher,
    257 	NULL,
    258 	sizeof(AES_KEY),
    259 	NULL,
    260 	NULL,
    261 	NULL,
    262 	NULL
    263     };
    264     return &aes_256_cfb8;
    265 }
    266 
    267 /**
    268  * The message digest SHA256 - hcrypto
    269  *
    270  * @return the message digest type.
    271  *
    272  * @ingroup hcrypto_evp
    273  */
    274 
    275 const EVP_MD *
    276 EVP_hcrypto_sha256(void)
    277 {
    278     static const struct hc_evp_md sha256 = {
    279 	32,
    280 	64,
    281 	sizeof(SHA256_CTX),
    282 	(hc_evp_md_init)SHA256_Init,
    283 	(hc_evp_md_update)SHA256_Update,
    284 	(hc_evp_md_final)SHA256_Final,
    285 	NULL
    286     };
    287     return &sha256;
    288 }
    289 
    290 /**
    291  * The message digest SHA384 - hcrypto
    292  *
    293  * @return the message digest type.
    294  *
    295  * @ingroup hcrypto_evp
    296  */
    297 
    298 const EVP_MD *
    299 EVP_hcrypto_sha384(void)
    300 {
    301     static const struct hc_evp_md sha384 = {
    302 	48,
    303 	128,
    304 	sizeof(SHA384_CTX),
    305 	(hc_evp_md_init)SHA384_Init,
    306 	(hc_evp_md_update)SHA384_Update,
    307 	(hc_evp_md_final)SHA384_Final,
    308 	NULL
    309     };
    310     return &sha384;
    311 }
    312 
    313 /**
    314  * The message digest SHA512 - hcrypto
    315  *
    316  * @return the message digest type.
    317  *
    318  * @ingroup hcrypto_evp
    319  */
    320 
    321 const EVP_MD *
    322 EVP_hcrypto_sha512(void)
    323 {
    324     static const struct hc_evp_md sha512 = {
    325 	64,
    326 	128,
    327 	sizeof(SHA512_CTX),
    328 	(hc_evp_md_init)SHA512_Init,
    329 	(hc_evp_md_update)SHA512_Update,
    330 	(hc_evp_md_final)SHA512_Final,
    331 	NULL
    332     };
    333     return &sha512;
    334 }
    335 
    336 /**
    337  * The message digest SHA1 - hcrypto
    338  *
    339  * @return the message digest type.
    340  *
    341  * @ingroup hcrypto_evp
    342  */
    343 
    344 const EVP_MD *
    345 EVP_hcrypto_sha1(void)
    346 {
    347     static const struct hc_evp_md sha1 = {
    348 	20,
    349 	64,
    350 	sizeof(SHA_CTX),
    351 	(hc_evp_md_init)SHA1_Init,
    352 	(hc_evp_md_update)SHA1_Update,
    353 	(hc_evp_md_final)SHA1_Final,
    354 	NULL
    355     };
    356     return &sha1;
    357 }
    358 
    359 /**
    360  * The message digest MD5 - hcrypto
    361  *
    362  * @return the message digest type.
    363  *
    364  * @ingroup hcrypto_evp
    365  */
    366 
    367 const EVP_MD *
    368 EVP_hcrypto_md5(void)
    369 {
    370     static const struct hc_evp_md md5 = {
    371 	16,
    372 	64,
    373 	sizeof(MD5_CTX),
    374 	(hc_evp_md_init)MD5_Init,
    375 	(hc_evp_md_update)MD5_Update,
    376 	(hc_evp_md_final)MD5_Final,
    377 	NULL
    378     };
    379     return &md5;
    380 }
    381 
    382 /**
    383  * The message digest MD4 - hcrypto
    384  *
    385  * @return the message digest type.
    386  *
    387  * @ingroup hcrypto_evp
    388  */
    389 
    390 const EVP_MD *
    391 EVP_hcrypto_md4(void)
    392 {
    393     static const struct hc_evp_md md4 = {
    394 	16,
    395 	64,
    396 	sizeof(MD4_CTX),
    397 	(hc_evp_md_init)MD4_Init,
    398 	(hc_evp_md_update)MD4_Update,
    399 	(hc_evp_md_final)MD4_Final,
    400 	NULL
    401     };
    402     return &md4;
    403 }
    404 
    405 
    406 /*
    407  *
    408  */
    409 
    410 static int
    411 des_cbc_init(EVP_CIPHER_CTX *ctx,
    412 	     const unsigned char * key,
    413 	     const unsigned char * iv,
    414 	     int encp)
    415 {
    416     DES_key_schedule *k = ctx->cipher_data;
    417     DES_cblock deskey;
    418     memcpy(&deskey, key, sizeof(deskey));
    419     DES_set_key_unchecked(&deskey, k);
    420     return 1;
    421 }
    422 
    423 static int
    424 des_cbc_do_cipher(EVP_CIPHER_CTX *ctx,
    425 		  unsigned char *out,
    426 		  const unsigned char *in,
    427 		  unsigned int size)
    428 {
    429     DES_key_schedule *k = ctx->cipher_data;
    430     DES_cbc_encrypt(in, out, size,
    431 		    k, (DES_cblock *)ctx->iv, ctx->encrypt);
    432     return 1;
    433 }
    434 
    435 /**
    436  * The DES cipher type
    437  *
    438  * @return the DES-CBC EVP_CIPHER pointer.
    439  *
    440  * @ingroup hcrypto_evp
    441  */
    442 
    443 const EVP_CIPHER *
    444 EVP_hcrypto_des_cbc(void)
    445 {
    446     static const EVP_CIPHER des_cbc = {
    447 	0,
    448 	8,
    449 	8,
    450 	8,
    451 	EVP_CIPH_CBC_MODE,
    452 	des_cbc_init,
    453 	des_cbc_do_cipher,
    454 	NULL,
    455 	sizeof(DES_key_schedule),
    456 	NULL,
    457 	NULL,
    458 	NULL,
    459 	NULL
    460     };
    461     return &des_cbc;
    462 }
    463 
    464 /*
    465  *
    466  */
    467 
    468 struct des_ede3_cbc {
    469     DES_key_schedule ks[3];
    470 };
    471 
    472 static int
    473 des_ede3_cbc_init(EVP_CIPHER_CTX *ctx,
    474 		  const unsigned char * key,
    475 		  const unsigned char * iv,
    476 		  int encp)
    477 {
    478     struct des_ede3_cbc *k = ctx->cipher_data;
    479     DES_cblock deskey;
    480 
    481     memcpy(&deskey, key, sizeof(deskey));
    482     DES_set_odd_parity(&deskey);
    483     DES_set_key_unchecked(&deskey, &k->ks[0]);
    484 
    485     memcpy(&deskey, key + 8, sizeof(deskey));
    486     DES_set_odd_parity(&deskey);
    487     DES_set_key_unchecked(&deskey, &k->ks[1]);
    488 
    489     memcpy(&deskey, key + 16, sizeof(deskey));
    490     DES_set_odd_parity(&deskey);
    491     DES_set_key_unchecked(&deskey, &k->ks[2]);
    492 
    493     return 1;
    494 }
    495 
    496 static int
    497 des_ede3_cbc_do_cipher(EVP_CIPHER_CTX *ctx,
    498 		       unsigned char *out,
    499 		       const unsigned char *in,
    500 		       unsigned int size)
    501 {
    502     struct des_ede3_cbc *k = ctx->cipher_data;
    503     DES_ede3_cbc_encrypt(in, out, size,
    504 			 &k->ks[0], &k->ks[1], &k->ks[2],
    505 			 (DES_cblock *)ctx->iv, ctx->encrypt);
    506     return 1;
    507 }
    508 
    509 /**
    510  * The triple DES cipher type - hcrypto
    511  *
    512  * @return the DES-EDE3-CBC EVP_CIPHER pointer.
    513  *
    514  * @ingroup hcrypto_evp
    515  */
    516 
    517 const EVP_CIPHER *
    518 EVP_hcrypto_des_ede3_cbc(void)
    519 {
    520     static const EVP_CIPHER des_ede3_cbc = {
    521 	0,
    522 	8,
    523 	24,
    524 	8,
    525 	EVP_CIPH_CBC_MODE,
    526 	des_ede3_cbc_init,
    527 	des_ede3_cbc_do_cipher,
    528 	NULL,
    529 	sizeof(struct des_ede3_cbc),
    530 	NULL,
    531 	NULL,
    532 	NULL,
    533 	NULL
    534     };
    535     return &des_ede3_cbc;
    536 }
    537 
    538 /*
    539  *
    540  */
    541 
    542 struct rc2_cbc {
    543     unsigned int maximum_effective_key;
    544     RC2_KEY key;
    545 };
    546 
    547 static int
    548 rc2_init(EVP_CIPHER_CTX *ctx,
    549 	 const unsigned char * key,
    550 	 const unsigned char * iv,
    551 	 int encp)
    552 {
    553     struct rc2_cbc *k = ctx->cipher_data;
    554     k->maximum_effective_key = EVP_CIPHER_CTX_key_length(ctx) * 8;
    555     RC2_set_key(&k->key,
    556 		EVP_CIPHER_CTX_key_length(ctx),
    557 		key,
    558 		k->maximum_effective_key);
    559     return 1;
    560 }
    561 
    562 static int
    563 rc2_do_cipher(EVP_CIPHER_CTX *ctx,
    564 	      unsigned char *out,
    565 	      const unsigned char *in,
    566 	      unsigned int size)
    567 {
    568     struct rc2_cbc *k = ctx->cipher_data;
    569     RC2_cbc_encrypt(in, out, size, &k->key, ctx->iv, ctx->encrypt);
    570     return 1;
    571 }
    572 
    573 /**
    574  * The RC2 cipher type - hcrypto
    575  *
    576  * @return the RC2 EVP_CIPHER pointer.
    577  *
    578  * @ingroup hcrypto_evp
    579  */
    580 
    581 const EVP_CIPHER *
    582 EVP_hcrypto_rc2_cbc(void)
    583 {
    584     static const EVP_CIPHER rc2_cbc = {
    585 	0,
    586 	RC2_BLOCK_SIZE,
    587 	RC2_KEY_LENGTH,
    588 	RC2_BLOCK_SIZE,
    589 	EVP_CIPH_CBC_MODE|EVP_CIPH_VARIABLE_LENGTH,
    590 	rc2_init,
    591 	rc2_do_cipher,
    592 	NULL,
    593 	sizeof(struct rc2_cbc),
    594 	NULL,
    595 	NULL,
    596 	NULL,
    597 	NULL
    598     };
    599     return &rc2_cbc;
    600 }
    601 
    602 /**
    603  * The RC2-40 cipher type
    604  *
    605  * @return the RC2-40 EVP_CIPHER pointer.
    606  *
    607  * @ingroup hcrypto_evp
    608  */
    609 
    610 const EVP_CIPHER *
    611 EVP_hcrypto_rc2_40_cbc(void)
    612 {
    613     static const EVP_CIPHER rc2_40_cbc = {
    614 	0,
    615 	RC2_BLOCK_SIZE,
    616 	5,
    617 	RC2_BLOCK_SIZE,
    618 	EVP_CIPH_CBC_MODE,
    619 	rc2_init,
    620 	rc2_do_cipher,
    621 	NULL,
    622 	sizeof(struct rc2_cbc),
    623 	NULL,
    624 	NULL,
    625 	NULL,
    626 	NULL
    627     };
    628     return &rc2_40_cbc;
    629 }
    630 
    631 /**
    632  * The RC2-64 cipher type
    633  *
    634  * @return the RC2-64 EVP_CIPHER pointer.
    635  *
    636  * @ingroup hcrypto_evp
    637  */
    638 
    639 const EVP_CIPHER *
    640 EVP_hcrypto_rc2_64_cbc(void)
    641 {
    642     static const EVP_CIPHER rc2_64_cbc = {
    643 	0,
    644 	RC2_BLOCK_SIZE,
    645 	8,
    646 	RC2_BLOCK_SIZE,
    647 	EVP_CIPH_CBC_MODE,
    648 	rc2_init,
    649 	rc2_do_cipher,
    650 	NULL,
    651 	sizeof(struct rc2_cbc),
    652 	NULL,
    653 	NULL,
    654 	NULL,
    655 	NULL
    656     };
    657     return &rc2_64_cbc;
    658 }
    659 
    660 static int
    661 camellia_init(EVP_CIPHER_CTX *ctx,
    662 	 const unsigned char * key,
    663 	 const unsigned char * iv,
    664 	 int encp)
    665 {
    666     CAMELLIA_KEY *k = ctx->cipher_data;
    667     k->bits = ctx->cipher->key_len * 8;
    668     CAMELLIA_set_key(key, ctx->cipher->key_len * 8, k);
    669     return 1;
    670 }
    671 
    672 static int
    673 camellia_do_cipher(EVP_CIPHER_CTX *ctx,
    674 	      unsigned char *out,
    675 	      const unsigned char *in,
    676 	      unsigned int size)
    677 {
    678     CAMELLIA_KEY *k = ctx->cipher_data;
    679     CAMELLIA_cbc_encrypt(in, out, size, k, ctx->iv, ctx->encrypt);
    680     return 1;
    681 }
    682 
    683 /**
    684  * The Camellia-128 cipher type - hcrypto
    685  *
    686  * @return the Camellia-128 EVP_CIPHER pointer.
    687  *
    688  * @ingroup hcrypto_evp
    689  */
    690 
    691 const EVP_CIPHER *
    692 EVP_hcrypto_camellia_128_cbc(void)
    693 {
    694     static const EVP_CIPHER cipher = {
    695 	0,
    696 	16,
    697 	16,
    698 	16,
    699 	EVP_CIPH_CBC_MODE,
    700 	camellia_init,
    701 	camellia_do_cipher,
    702 	NULL,
    703 	sizeof(CAMELLIA_KEY),
    704 	NULL,
    705 	NULL,
    706 	NULL,
    707 	NULL
    708     };
    709     return &cipher;
    710 }
    711 
    712 /**
    713  * The Camellia-198 cipher type - hcrypto
    714  *
    715  * @return the Camellia-198 EVP_CIPHER pointer.
    716  *
    717  * @ingroup hcrypto_evp
    718  */
    719 
    720 const EVP_CIPHER *
    721 EVP_hcrypto_camellia_192_cbc(void)
    722 {
    723     static const EVP_CIPHER cipher = {
    724 	0,
    725 	16,
    726 	24,
    727 	16,
    728 	EVP_CIPH_CBC_MODE,
    729 	camellia_init,
    730 	camellia_do_cipher,
    731 	NULL,
    732 	sizeof(CAMELLIA_KEY),
    733 	NULL,
    734 	NULL,
    735 	NULL,
    736 	NULL
    737     };
    738     return &cipher;
    739 }
    740 
    741 /**
    742  * The Camellia-256 cipher type - hcrypto
    743  *
    744  * @return the Camellia-256 EVP_CIPHER pointer.
    745  *
    746  * @ingroup hcrypto_evp
    747  */
    748 
    749 const EVP_CIPHER *
    750 EVP_hcrypto_camellia_256_cbc(void)
    751 {
    752     static const EVP_CIPHER cipher = {
    753 	0,
    754 	16,
    755 	32,
    756 	16,
    757 	EVP_CIPH_CBC_MODE,
    758 	camellia_init,
    759 	camellia_do_cipher,
    760 	NULL,
    761 	sizeof(CAMELLIA_KEY),
    762 	NULL,
    763 	NULL,
    764 	NULL,
    765 	NULL
    766     };
    767     return &cipher;
    768 }
    769 
    770 static int
    771 rc4_init(EVP_CIPHER_CTX *ctx,
    772 	 const unsigned char *key,
    773 	 const unsigned char *iv,
    774 	 int enc)
    775 {
    776     RC4_KEY *k = ctx->cipher_data;
    777     RC4_set_key(k, ctx->key_len, key);
    778     return 1;
    779 }
    780 
    781 static int
    782 rc4_do_cipher(EVP_CIPHER_CTX *ctx,
    783 	      unsigned char *out,
    784 	      const unsigned char *in,
    785 	      unsigned int size)
    786 {
    787     RC4_KEY *k = ctx->cipher_data;
    788     RC4(k, size, in, out);
    789     return 1;
    790 }
    791 
    792 const EVP_CIPHER *
    793 EVP_hcrypto_rc4(void)
    794 {
    795     static const EVP_CIPHER rc4 = {
    796 	0,
    797 	1,
    798 	16,
    799 	0,
    800 	EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH,
    801 	rc4_init,
    802 	rc4_do_cipher,
    803 	NULL,
    804 	sizeof(RC4_KEY),
    805 	NULL,
    806 	NULL,
    807 	NULL,
    808 	NULL
    809     };
    810     return &rc4;
    811 }
    812 
    813 
    814 const EVP_CIPHER *
    815 EVP_hcrypto_rc4_40(void)
    816 {
    817     static const EVP_CIPHER rc4_40 = {
    818 	0,
    819 	1,
    820 	5,
    821 	0,
    822 	EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH,
    823 	rc4_init,
    824 	rc4_do_cipher,
    825 	NULL,
    826 	sizeof(RC4_KEY),
    827 	NULL,
    828 	NULL,
    829 	NULL,
    830 	NULL
    831     };
    832     return &rc4_40;
    833 }
    834