Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / external / heimdal / hcrypto / evp-cc.c
1 /*
2 * Copyright (c) 2008 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Portions Copyright (c) 2009 Apple Inc. 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 /* CommonCrypto provider */
37
38 #ifdef __APPLE__
39
40 #include "config.h"
41
42 #include <sys/types.h>
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <string.h>
46 #include <assert.h>
47
48 #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
49 #include <CommonCrypto/CommonDigest.h>
50 #endif
51 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
52 #include <CommonCrypto/CommonCryptor.h>
53 #endif
54
55 #include <evp.h>
56 #include <evp-cc.h>
57
58 /*
59 *
60 */
61
62 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
63
64 struct cc_key {
65 CCCryptorRef href;
66 };
67
68 static int
69 cc_do_cipher(EVP_CIPHER_CTX *ctx,
70 unsigned char *out,
71 const unsigned char *in,
72 unsigned int size)
73 {
74 struct cc_key *cc = ctx->cipher_data;
75 CCCryptorStatus ret;
76 size_t moved;
77
78 memcpy(out, in, size);
79
80 ret = CCCryptorUpdate(cc->href, in, size, out, size, &moved);
81 if (ret)
82 return 0;
83
84 if (moved != size)
85 return 0;
86
87 return 1;
88 }
89
90 static int
91 cc_do_cfb8_cipher(EVP_CIPHER_CTX *ctx,
92 unsigned char *out,
93 const unsigned char *in,
94 unsigned int size)
95 {
96 struct cc_key *cc = ctx->cipher_data;
97 CCCryptorStatus ret;
98 size_t moved;
99 unsigned int i;
100
101 for (i = 0; i < size; i++) {
102 unsigned char oiv[EVP_MAX_IV_LENGTH + 1];
103
104 assert(ctx->cipher->iv_len + 1 <= sizeof(oiv));
105 memcpy(oiv, ctx->iv, ctx->cipher->iv_len);
106
107 ret = CCCryptorUpdate(cc->href, ctx->iv, ctx->cipher->iv_len,
108 ctx->iv, ctx->cipher->iv_len, &moved);
109 if (ret)
110 return 0;
111
112 if (moved != ctx->cipher->iv_len)
113 return 0;
114
115 if (!ctx->encrypt)
116 oiv[ctx->cipher->iv_len] = in[i];
117 out[i] = in[i] ^ ctx->iv[0];
118 if (ctx->encrypt)
119 oiv[ctx->cipher->iv_len] = out[i];
120
121 memcpy(ctx->iv, &oiv[1], ctx->cipher->iv_len);
122 }
123
124 return 1;
125 }
126
127 static int
128 cc_cleanup(EVP_CIPHER_CTX *ctx)
129 {
130 struct cc_key *cc = ctx->cipher_data;
131 if (cc->href)
132 CCCryptorRelease(cc->href);
133 return 1;
134 }
135
136 static int
137 init_cc_key(int encp, CCAlgorithm alg, CCOptions opts, const void *key,
138 size_t keylen, const void *iv, CCCryptorRef *ref)
139 {
140 CCOperation op = encp ? kCCEncrypt : kCCDecrypt;
141 CCCryptorStatus ret;
142
143 if (*ref) {
144 if (key == NULL && iv) {
145 CCCryptorReset(*ref, iv);
146 return 1;
147 }
148 CCCryptorRelease(*ref);
149 }
150
151 ret = CCCryptorCreate(op, alg, opts, key, keylen, iv, ref);
152 if (ret)
153 return 0;
154 return 1;
155 }
156
157 static int
158 cc_des_ede3_cbc_init(EVP_CIPHER_CTX *ctx,
159 const unsigned char * key,
160 const unsigned char * iv,
161 int encp)
162 {
163 struct cc_key *cc = ctx->cipher_data;
164 return init_cc_key(encp, kCCAlgorithm3DES, 0, key, kCCKeySize3DES, iv, &cc->href);
165 }
166
167 #endif /* HAVE_COMMONCRYPTO_COMMONCRYPTOR_H */
168
169 /**
170 * The tripple DES cipher type (Apple CommonCrypto provider)
171 *
172 * @return the DES-EDE3-CBC EVP_CIPHER pointer.
173 *
174 * @ingroup hcrypto_evp
175 */
176
177 const EVP_CIPHER *
178 EVP_cc_des_ede3_cbc(void)
179 {
180 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
181 static const EVP_CIPHER des_ede3_cbc = {
182 0,
183 8,
184 24,
185 8,
186 EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
187 cc_des_ede3_cbc_init,
188 cc_do_cipher,
189 cc_cleanup,
190 sizeof(struct cc_key),
191 NULL,
192 NULL,
193 NULL,
194 NULL
195 };
196 return &des_ede3_cbc;
197 #else
198 return NULL;
199 #endif
200 }
201
202 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
203 /*
204 *
205 */
206
207 static int
208 cc_des_cbc_init(EVP_CIPHER_CTX *ctx,
209 const unsigned char * key,
210 const unsigned char * iv,
211 int encp)
212 {
213 struct cc_key *cc = ctx->cipher_data;
214 return init_cc_key(encp, kCCAlgorithmDES, 0, key, kCCBlockSizeDES, iv, &cc->href);
215 }
216 #endif
217
218 /**
219 * The DES cipher type (Apple CommonCrypto provider)
220 *
221 * @return the DES-CBC EVP_CIPHER pointer.
222 *
223 * @ingroup hcrypto_evp
224 */
225
226 const EVP_CIPHER *
227 EVP_cc_des_cbc(void)
228 {
229 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
230 static const EVP_CIPHER des_ede3_cbc = {
231 0,
232 kCCBlockSizeDES,
233 kCCBlockSizeDES,
234 kCCBlockSizeDES,
235 EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
236 cc_des_cbc_init,
237 cc_do_cipher,
238 cc_cleanup,
239 sizeof(struct cc_key),
240 NULL,
241 NULL,
242 NULL,
243 NULL
244 };
245 return &des_ede3_cbc;
246 #else
247 return NULL;
248 #endif
249 }
250
251 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
252 /*
253 *
254 */
255
256 static int
257 cc_aes_cbc_init(EVP_CIPHER_CTX *ctx,
258 const unsigned char * key,
259 const unsigned char * iv,
260 int encp)
261 {
262 struct cc_key *cc = ctx->cipher_data;
263 return init_cc_key(encp, kCCAlgorithmAES128, 0, key, ctx->cipher->key_len, iv, &cc->href);
264 }
265 #endif
266
267 /**
268 * The AES-128 cipher type (Apple CommonCrypto provider)
269 *
270 * @return the AES-128-CBC EVP_CIPHER pointer.
271 *
272 * @ingroup hcrypto_evp
273 */
274
275 const EVP_CIPHER *
276 EVP_cc_aes_128_cbc(void)
277 {
278 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
279 static const EVP_CIPHER c = {
280 0,
281 kCCBlockSizeAES128,
282 kCCKeySizeAES128,
283 kCCBlockSizeAES128,
284 EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
285 cc_aes_cbc_init,
286 cc_do_cipher,
287 cc_cleanup,
288 sizeof(struct cc_key),
289 NULL,
290 NULL,
291 NULL,
292 NULL
293 };
294 return &c;
295 #else
296 return NULL;
297 #endif
298 }
299
300 /**
301 * The AES-192 cipher type (Apple CommonCrypto provider)
302 *
303 * @return the AES-192-CBC EVP_CIPHER pointer.
304 *
305 * @ingroup hcrypto_evp
306 */
307
308 const EVP_CIPHER *
309 EVP_cc_aes_192_cbc(void)
310 {
311 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
312 static const EVP_CIPHER c = {
313 0,
314 kCCBlockSizeAES128,
315 kCCKeySizeAES192,
316 kCCBlockSizeAES128,
317 EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
318 cc_aes_cbc_init,
319 cc_do_cipher,
320 cc_cleanup,
321 sizeof(struct cc_key),
322 NULL,
323 NULL,
324 NULL,
325 NULL
326 };
327 return &c;
328 #else
329 return NULL;
330 #endif
331 }
332
333 /**
334 * The AES-256 cipher type (Apple CommonCrypto provider)
335 *
336 * @return the AES-256-CBC EVP_CIPHER pointer.
337 *
338 * @ingroup hcrypto_evp
339 */
340
341 const EVP_CIPHER *
342 EVP_cc_aes_256_cbc(void)
343 {
344 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
345 static const EVP_CIPHER c = {
346 0,
347 kCCBlockSizeAES128,
348 kCCKeySizeAES256,
349 kCCBlockSizeAES128,
350 EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
351 cc_aes_cbc_init,
352 cc_do_cipher,
353 cc_cleanup,
354 sizeof(struct cc_key),
355 NULL,
356 NULL,
357 NULL,
358 NULL
359 };
360 return &c;
361 #else
362 return NULL;
363 #endif
364 }
365
366 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
367 /*
368 *
369 */
370
371 static int
372 cc_aes_cfb8_init(EVP_CIPHER_CTX *ctx,
373 const unsigned char * key,
374 const unsigned char * iv,
375 int encp)
376 {
377 struct cc_key *cc = ctx->cipher_data;
378 memcpy(ctx->iv, iv, ctx->cipher->iv_len);
379 return init_cc_key(1, kCCAlgorithmAES128, kCCOptionECBMode,
380 key, ctx->cipher->key_len, NULL, &cc->href);
381 }
382 #endif
383
384 /**
385 * The AES-128 CFB8 cipher type (Apple CommonCrypto provider)
386 *
387 * @return the AES-128-CFB8 EVP_CIPHER pointer.
388 *
389 * @ingroup hcrypto_evp
390 */
391
392 const EVP_CIPHER *
393 EVP_cc_aes_128_cfb8(void)
394 {
395 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
396 static const EVP_CIPHER c = {
397 0,
398 1,
399 kCCKeySizeAES128,
400 kCCBlockSizeAES128,
401 EVP_CIPH_CFB8_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
402 cc_aes_cfb8_init,
403 cc_do_cfb8_cipher,
404 cc_cleanup,
405 sizeof(struct cc_key),
406 NULL,
407 NULL,
408 NULL,
409 NULL
410 };
411 return &c;
412 #else
413 return NULL;
414 #endif
415 }
416
417 /**
418 * The AES-192 CFB8 cipher type (Apple CommonCrypto provider)
419 *
420 * @return the AES-192-CFB8 EVP_CIPHER pointer.
421 *
422 * @ingroup hcrypto_evp
423 */
424
425 const EVP_CIPHER *
426 EVP_cc_aes_192_cfb8(void)
427 {
428 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
429 static const EVP_CIPHER c = {
430 0,
431 1,
432 kCCKeySizeAES192,
433 kCCBlockSizeAES128,
434 EVP_CIPH_CFB8_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
435 cc_aes_cfb8_init,
436 cc_do_cfb8_cipher,
437 cc_cleanup,
438 sizeof(struct cc_key),
439 NULL,
440 NULL,
441 NULL,
442 NULL
443 };
444 return &c;
445 #else
446 return NULL;
447 #endif
448 }
449
450 /**
451 * The AES-256 CFB8 cipher type (Apple CommonCrypto provider)
452 *
453 * @return the AES-256-CFB8 EVP_CIPHER pointer.
454 *
455 * @ingroup hcrypto_evp
456 */
457
458 const EVP_CIPHER *
459 EVP_cc_aes_256_cfb8(void)
460 {
461 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
462 static const EVP_CIPHER c = {
463 0,
464 kCCBlockSizeAES128,
465 kCCKeySizeAES256,
466 kCCBlockSizeAES128,
467 EVP_CIPH_CFB8_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
468 cc_aes_cfb8_init,
469 cc_do_cfb8_cipher,
470 cc_cleanup,
471 sizeof(struct cc_key),
472 NULL,
473 NULL,
474 NULL,
475 NULL
476 };
477 return &c;
478 #else
479 return NULL;
480 #endif
481 }
482
483 /*
484 *
485 */
486
487 #ifdef COMMONCRYPTO_SUPPORTS_RC2
488 static int
489 cc_rc2_cbc_init(EVP_CIPHER_CTX *ctx,
490 const unsigned char * key,
491 const unsigned char * iv,
492 int encp)
493 {
494 struct cc_key *cc = ctx->cipher_data;
495 return init_cc_key(encp, kCCAlgorithmRC2, 0, key, ctx->cipher->key_len, iv, &cc->href);
496 }
497 #endif
498
499 /**
500 * The RC2 cipher type - common crypto
501 *
502 * @return the RC2 EVP_CIPHER pointer.
503 *
504 * @ingroup hcrypto_evp
505 */
506
507
508 const EVP_CIPHER *
509 EVP_cc_rc2_cbc(void)
510 {
511 #ifdef COMMONCRYPTO_SUPPORTS_RC2
512 static const EVP_CIPHER rc2_cbc = {
513 0,
514 kCCBlockSizeRC2,
515 16,
516 kCCBlockSizeRC2,
517 EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
518 cc_rc2_cbc_init,
519 cc_do_cipher,
520 cc_cleanup,
521 sizeof(struct cc_key),
522 NULL,
523 NULL,
524 NULL,
525 NULL
526 };
527 return &rc2_cbc;
528 #else
529 return NULL;
530 #endif
531 }
532
533 /**
534 * The RC2-40 cipher type - common crypto
535 *
536 * @return the RC2-40 EVP_CIPHER pointer.
537 *
538 * @ingroup hcrypto_evp
539 */
540
541
542 const EVP_CIPHER *
543 EVP_cc_rc2_40_cbc(void)
544 {
545 #ifdef COMMONCRYPTO_SUPPORTS_RC2
546 static const EVP_CIPHER rc2_40_cbc = {
547 0,
548 kCCBlockSizeRC2,
549 5,
550 kCCBlockSizeRC2,
551 EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
552 cc_rc2_cbc_init,
553 cc_do_cipher,
554 cc_cleanup,
555 sizeof(struct cc_key),
556 NULL,
557 NULL,
558 NULL,
559 NULL
560 };
561 return &rc2_40_cbc;
562 #else
563 return NULL;
564 #endif
565 }
566
567
568 /**
569 * The RC2-64 cipher type - common crypto
570 *
571 * @return the RC2-64 EVP_CIPHER pointer.
572 *
573 * @ingroup hcrypto_evp
574 */
575
576
577 const EVP_CIPHER *
578 EVP_cc_rc2_64_cbc(void)
579 {
580 #ifdef COMMONCRYPTO_SUPPORTS_RC2
581 static const EVP_CIPHER rc2_64_cbc = {
582 0,
583 kCCBlockSizeRC2,
584 8,
585 kCCBlockSizeRC2,
586 EVP_CIPH_CBC_MODE|EVP_CIPH_ALWAYS_CALL_INIT,
587 cc_rc2_cbc_init,
588 cc_do_cipher,
589 cc_cleanup,
590 sizeof(struct cc_key),
591 NULL,
592 NULL,
593 NULL,
594 NULL
595 };
596 return &rc2_64_cbc;
597 #else
598 return NULL;
599 #endif
600 }
601
602 /**
603 * The CommonCrypto md2 provider
604 *
605 * @ingroup hcrypto_evp
606 */
607
608 const EVP_MD *
609 EVP_cc_md2(void)
610 {
611 #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
612 static const struct hc_evp_md md2 = {
613 CC_MD2_DIGEST_LENGTH,
614 CC_MD2_BLOCK_BYTES,
615 sizeof(CC_MD2_CTX),
616 (hc_evp_md_init)CC_MD2_Init,
617 (hc_evp_md_update)CC_MD2_Update,
618 (hc_evp_md_final)CC_MD2_Final,
619 (hc_evp_md_cleanup)NULL
620 };
621 return &md2;
622 #else
623 return NULL;
624 #endif
625 }
626
627 /**
628 * The CommonCrypto md4 provider
629 *
630 * @ingroup hcrypto_evp
631 */
632
633 const EVP_MD *
634 EVP_cc_md4(void)
635 {
636 #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
637 static const struct hc_evp_md md4 = {
638 CC_MD4_DIGEST_LENGTH,
639 CC_MD4_BLOCK_BYTES,
640 sizeof(CC_MD4_CTX),
641 (hc_evp_md_init)CC_MD4_Init,
642 (hc_evp_md_update)CC_MD4_Update,
643 (hc_evp_md_final)CC_MD4_Final,
644 (hc_evp_md_cleanup)NULL
645 };
646 return &md4;
647 #else
648 return NULL;
649 #endif
650 }
651
652 /**
653 * The CommonCrypto md5 provider
654 *
655 * @ingroup hcrypto_evp
656 */
657
658 const EVP_MD *
659 EVP_cc_md5(void)
660 {
661 #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
662 static const struct hc_evp_md md5 = {
663 CC_MD5_DIGEST_LENGTH,
664 CC_MD5_BLOCK_BYTES,
665 sizeof(CC_MD5_CTX),
666 (hc_evp_md_init)CC_MD5_Init,
667 (hc_evp_md_update)CC_MD5_Update,
668 (hc_evp_md_final)CC_MD5_Final,
669 (hc_evp_md_cleanup)NULL
670 };
671 return &md5;
672 #else
673 return NULL;
674 #endif
675 }
676
677 /**
678 * The CommonCrypto sha1 provider
679 *
680 * @ingroup hcrypto_evp
681 */
682
683 const EVP_MD *
684 EVP_cc_sha1(void)
685 {
686 #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
687 static const struct hc_evp_md sha1 = {
688 CC_SHA1_DIGEST_LENGTH,
689 CC_SHA1_BLOCK_BYTES,
690 sizeof(CC_SHA1_CTX),
691 (hc_evp_md_init)CC_SHA1_Init,
692 (hc_evp_md_update)CC_SHA1_Update,
693 (hc_evp_md_final)CC_SHA1_Final,
694 (hc_evp_md_cleanup)NULL
695 };
696 return &sha1;
697 #else
698 return NULL;
699 #endif
700 }
701
702 /**
703 * The CommonCrypto sha256 provider
704 *
705 * @ingroup hcrypto_evp
706 */
707
708 const EVP_MD *
709 EVP_cc_sha256(void)
710 {
711 #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
712 static const struct hc_evp_md sha256 = {
713 CC_SHA256_DIGEST_LENGTH,
714 CC_SHA256_BLOCK_BYTES,
715 sizeof(CC_SHA256_CTX),
716 (hc_evp_md_init)CC_SHA256_Init,
717 (hc_evp_md_update)CC_SHA256_Update,
718 (hc_evp_md_final)CC_SHA256_Final,
719 (hc_evp_md_cleanup)NULL
720 };
721 return &sha256;
722 #else
723 return NULL;
724 #endif
725 }
726
727 /**
728 * The Camellia-128 cipher type - CommonCrypto
729 *
730 * @return the Camellia-128 EVP_CIPHER pointer.
731 *
732 * @ingroup hcrypto_evp
733 */
734
735 const EVP_CIPHER *
736 EVP_cc_camellia_128_cbc(void)
737 {
738 return NULL;
739 }
740
741 /**
742 * The Camellia-198 cipher type - CommonCrypto
743 *
744 * @return the Camellia-198 EVP_CIPHER pointer.
745 *
746 * @ingroup hcrypto_evp
747 */
748
749 const EVP_CIPHER *
750 EVP_cc_camellia_192_cbc(void)
751 {
752 return NULL;
753 }
754
755 /**
756 * The Camellia-256 cipher type - CommonCrypto
757 *
758 * @return the Camellia-256 EVP_CIPHER pointer.
759 *
760 * @ingroup hcrypto_evp
761 */
762
763 const EVP_CIPHER *
764 EVP_cc_camellia_256_cbc(void)
765 {
766 return NULL;
767 }
768
769 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
770
771 /*
772 *
773 */
774
775 static int
776 cc_rc4_init(EVP_CIPHER_CTX *ctx,
777 const unsigned char * key,
778 const unsigned char * iv,
779 int encp)
780 {
781 struct cc_key *cc = ctx->cipher_data;
782 return init_cc_key(encp, kCCAlgorithmRC4, 0, key, ctx->key_len, iv, &cc->href);
783 }
784
785 #endif
786
787 /**
788
789 * The RC4 cipher type (Apple CommonCrypto provider)
790 *
791 * @return the RC4 EVP_CIPHER pointer.
792 *
793 * @ingroup hcrypto_evp
794 */
795
796 const EVP_CIPHER *
797 EVP_cc_rc4(void)
798 {
799 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
800 static const EVP_CIPHER rc4 = {
801 0,
802 1,
803 16,
804 0,
805 EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH,
806 cc_rc4_init,
807 cc_do_cipher,
808 cc_cleanup,
809 sizeof(struct cc_key),
810 NULL,
811 NULL,
812 NULL,
813 NULL
814 };
815 return &rc4;
816 #else
817 return NULL;
818 #endif
819 }
820
821
822 /**
823 * The RC4-40 cipher type (Apple CommonCrypto provider)
824 *
825 * @return the RC4 EVP_CIPHER pointer.
826 *
827 * @ingroup hcrypto_evp
828 */
829
830 const EVP_CIPHER *
831 EVP_cc_rc4_40(void)
832 {
833 #ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H
834 static const EVP_CIPHER rc4_40 = {
835 0,
836 1,
837 5,
838 0,
839 EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH,
840 cc_rc4_init,
841 cc_do_cipher,
842 cc_cleanup,
843 sizeof(struct cc_key),
844 NULL,
845 NULL,
846 NULL,
847 NULL
848 };
849 return &rc4_40;
850 #else
851 return NULL;
852 #endif
853 }
854
855 #endif /* __APPLE__ */