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 64struct cc_key { 65 CCCryptorRef href; 66}; 67 68static int 69cc_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 90static int 91cc_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 127static int 128cc_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 136static int 137init_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 157static int 158cc_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 177const EVP_CIPHER * 178EVP_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 207static int 208cc_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 226const EVP_CIPHER * 227EVP_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 256static int 257cc_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 275const EVP_CIPHER * 276EVP_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 308const EVP_CIPHER * 309EVP_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 341const EVP_CIPHER * 342EVP_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 371static int 372cc_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 392const EVP_CIPHER * 393EVP_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 425const EVP_CIPHER * 426EVP_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 458const EVP_CIPHER * 459EVP_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 488static int 489cc_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 508const EVP_CIPHER * 509EVP_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 542const EVP_CIPHER * 543EVP_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 577const EVP_CIPHER * 578EVP_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 608const EVP_MD * 609EVP_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 633const EVP_MD * 634EVP_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 658const EVP_MD * 659EVP_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 683const EVP_MD * 684EVP_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 708const EVP_MD * 709EVP_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 CommonCrypto sha384 provider 729 * 730 * @ingroup hcrypto_evp 731 */ 732 733const EVP_MD * 734EVP_cc_sha384(void) 735{ 736#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H 737 static const struct hc_evp_md sha384 = { 738 CC_SHA384_DIGEST_LENGTH, 739 CC_SHA384_BLOCK_BYTES, 740 sizeof(CC_SHA512_CTX), 741 (hc_evp_md_init)CC_SHA384_Init, 742 (hc_evp_md_update)CC_SHA384_Update, 743 (hc_evp_md_final)CC_SHA384_Final, 744 (hc_evp_md_cleanup)NULL 745 }; 746 return &sha384; 747#else 748 return NULL; 749#endif 750} 751 752/** 753 * The CommonCrypto sha512 provider 754 * 755 * @ingroup hcrypto_evp 756 */ 757 758const EVP_MD * 759EVP_cc_sha512(void) 760{ 761#ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H 762 static const struct hc_evp_md sha512 = { 763 CC_SHA512_DIGEST_LENGTH, 764 CC_SHA512_BLOCK_BYTES, 765 sizeof(CC_SHA512_CTX), 766 (hc_evp_md_init)CC_SHA512_Init, 767 (hc_evp_md_update)CC_SHA512_Update, 768 (hc_evp_md_final)CC_SHA512_Final, 769 (hc_evp_md_cleanup)NULL 770 }; 771 return &sha512; 772#else 773 return NULL; 774#endif 775} 776 777/** 778 * The Camellia-128 cipher type - CommonCrypto 779 * 780 * @return the Camellia-128 EVP_CIPHER pointer. 781 * 782 * @ingroup hcrypto_evp 783 */ 784 785const EVP_CIPHER * 786EVP_cc_camellia_128_cbc(void) 787{ 788 return NULL; 789} 790 791/** 792 * The Camellia-198 cipher type - CommonCrypto 793 * 794 * @return the Camellia-198 EVP_CIPHER pointer. 795 * 796 * @ingroup hcrypto_evp 797 */ 798 799const EVP_CIPHER * 800EVP_cc_camellia_192_cbc(void) 801{ 802 return NULL; 803} 804 805/** 806 * The Camellia-256 cipher type - CommonCrypto 807 * 808 * @return the Camellia-256 EVP_CIPHER pointer. 809 * 810 * @ingroup hcrypto_evp 811 */ 812 813const EVP_CIPHER * 814EVP_cc_camellia_256_cbc(void) 815{ 816 return NULL; 817} 818 819#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H 820 821/* 822 * 823 */ 824 825static int 826cc_rc4_init(EVP_CIPHER_CTX *ctx, 827 const unsigned char * key, 828 const unsigned char * iv, 829 int encp) 830{ 831 struct cc_key *cc = ctx->cipher_data; 832 return init_cc_key(encp, kCCAlgorithmRC4, 0, key, ctx->key_len, iv, &cc->href); 833} 834 835#endif 836 837/** 838 839 * The RC4 cipher type (Apple CommonCrypto provider) 840 * 841 * @return the RC4 EVP_CIPHER pointer. 842 * 843 * @ingroup hcrypto_evp 844 */ 845 846const EVP_CIPHER * 847EVP_cc_rc4(void) 848{ 849#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H 850 static const EVP_CIPHER rc4 = { 851 0, 852 1, 853 16, 854 0, 855 EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH, 856 cc_rc4_init, 857 cc_do_cipher, 858 cc_cleanup, 859 sizeof(struct cc_key), 860 NULL, 861 NULL, 862 NULL, 863 NULL 864 }; 865 return &rc4; 866#else 867 return NULL; 868#endif 869} 870 871 872/** 873 * The RC4-40 cipher type (Apple CommonCrypto provider) 874 * 875 * @return the RC4 EVP_CIPHER pointer. 876 * 877 * @ingroup hcrypto_evp 878 */ 879 880const EVP_CIPHER * 881EVP_cc_rc4_40(void) 882{ 883#ifdef HAVE_COMMONCRYPTO_COMMONCRYPTOR_H 884 static const EVP_CIPHER rc4_40 = { 885 0, 886 1, 887 5, 888 0, 889 EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH, 890 cc_rc4_init, 891 cc_do_cipher, 892 cc_cleanup, 893 sizeof(struct cc_key), 894 NULL, 895 NULL, 896 NULL, 897 NULL 898 }; 899 return &rc4_40; 900#else 901 return NULL; 902#endif 903} 904 905#endif /* __APPLE__ */ 906 907