1/* 2 * Copyright (c) 2000-2001,2011,2014 Apple Inc. All Rights Reserved. 3 * 4 * The contents of this file constitute Original Code as defined in and are 5 * subject to the Apple Public Source License Version 1.2 (the 'License'). 6 * You may not use this file except in compliance with the License. Please obtain 7 * a copy of the License at http://www.apple.com/publicsource and read it before 8 * using this file. 9 * 10 * This Original Code and all software distributed under the License are 11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS 12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT 13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the 15 * specific language governing rights and limitations under the License. 16 */ 17 18 19/* rsa_null.c */ 20/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL 21 * project 1999. 22 */ 23/* ==================================================================== 24 * Copyright (c) 1999 The OpenSSL Project. All rights reserved. 25 * 26 * Redistribution and use in source and binary forms, with or without 27 * modification, are permitted provided that the following conditions 28 * are met: 29 * 30 * 1. Redistributions of source code must retain the above copyright 31 * notice, this list of conditions and the following disclaimer. 32 * 33 * 2. Redistributions in binary form must reproduce the above copyright 34 * notice, this list of conditions and the following disclaimer in 35 * the documentation and/or other materials provided with the 36 * distribution. 37 * 38 * 3. All advertising materials mentioning features or use of this 39 * software must display the following acknowledgment: 40 * "This product includes software developed by the OpenSSL Project 41 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 42 * 43 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 44 * endorse or promote products derived from this software without 45 * prior written permission. For written permission, please contact 46 * licensing@OpenSSL.org. 47 * 48 * 5. Products derived from this software may not be called "OpenSSL" 49 * nor may "OpenSSL" appear in their names without prior written 50 * permission of the OpenSSL Project. 51 * 52 * 6. Redistributions of any form whatsoever must retain the following 53 * acknowledgment: 54 * "This product includes software developed by the OpenSSL Project 55 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 56 * 57 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 58 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 60 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 61 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 62 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 63 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 64 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 66 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 67 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 68 * OF THE POSSIBILITY OF SUCH DAMAGE. 69 * ==================================================================== 70 * 71 * This product includes cryptographic software written by Eric Young 72 * (eay@cryptsoft.com). This product includes software written by Tim 73 * Hudson (tjh@cryptsoft.com). 74 * 75 */ 76 77#include <stdio.h> 78#include "cryptlib.h" 79#include <openssl/bn.h> 80#include <openssl/rsa.h> 81#include <openssl/rand.h> 82 83/* This is a dummy RSA implementation that just returns errors when called. 84 * It is designed to allow some RSA functions to work while stopping those 85 * covered by the RSA patent. That is RSA, encryption, decryption, signing 86 * and verify is not allowed but RSA key generation, key checking and other 87 * operations (like storing RSA keys) are permitted. 88 */ 89 90static int RSA_null_public_encrypt(int flen, unsigned char *from, 91 unsigned char *to, RSA *rsa,int padding); 92static int RSA_null_private_encrypt(int flen, unsigned char *from, 93 unsigned char *to, RSA *rsa,int padding); 94static int RSA_null_public_decrypt(int flen, unsigned char *from, 95 unsigned char *to, RSA *rsa,int padding); 96static int RSA_null_private_decrypt(int flen, unsigned char *from, 97 unsigned char *to, RSA *rsa,int padding); 98#if 0 /* not currently used */ 99static int RSA_null_mod_exp(BIGNUM *r0, BIGNUM *i, RSA *rsa); 100#endif 101static int RSA_null_init(RSA *rsa); 102static int RSA_null_finish(RSA *rsa); 103static const RSA_METHOD rsa_null_meth={ 104 "Null RSA", 105 RSA_null_public_encrypt, 106 RSA_null_public_decrypt, 107 RSA_null_private_encrypt, 108 RSA_null_private_decrypt, 109 NULL, NULL, 110 RSA_null_init, 111 RSA_null_finish, 112 0, 113 NULL, 114 }; 115 116const RSA_METHOD *RSA_null_method(void) 117 { 118 return(&rsa_null_meth); 119 } 120 121static int RSA_null_public_encrypt(int flen, unsigned char *from, 122 unsigned char *to, RSA *rsa, int padding) 123 { 124 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED); 125 return -1; 126 } 127 128static int RSA_null_private_encrypt(int flen, unsigned char *from, 129 unsigned char *to, RSA *rsa, int padding) 130 { 131 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED); 132 return -1; 133 } 134 135static int RSA_null_private_decrypt(int flen, unsigned char *from, 136 unsigned char *to, RSA *rsa, int padding) 137 { 138 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED); 139 return -1; 140 } 141 142static int RSA_null_public_decrypt(int flen, unsigned char *from, 143 unsigned char *to, RSA *rsa, int padding) 144 { 145 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED); 146 return -1; 147 } 148 149#if 0 /* not currently used */ 150static int RSA_null_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa) 151 { 152 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED); 153 return -1; 154 } 155#endif 156 157static int RSA_null_init(RSA *rsa) 158 { 159 return(1); 160 } 161 162static int RSA_null_finish(RSA *rsa) 163 { 164 return(1); 165 } 166 167 168