rsa_none.c revision 109998
11556Srgrimes/* crypto/rsa/rsa_none.c */ 21556Srgrimes/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 31556Srgrimes * All rights reserved. 41556Srgrimes * 51556Srgrimes * This package is an SSL implementation written 61556Srgrimes * by Eric Young (eay@cryptsoft.com). 71556Srgrimes * The implementation was written so as to conform with Netscapes SSL. 81556Srgrimes * 91556Srgrimes * This library is free for commercial and non-commercial use as long as 101556Srgrimes * the following conditions are aheared to. The following conditions 111556Srgrimes * apply to all code found in this distribution, be it the RC4, RSA, 121556Srgrimes * lhash, DES, etc., code; not just the SSL code. The SSL documentation 131556Srgrimes * included with this distribution is covered by the same copyright terms 141556Srgrimes * except that the holder is Tim Hudson (tjh@cryptsoft.com). 151556Srgrimes * 161556Srgrimes * Copyright remains Eric Young's, and as such any Copyright notices in 171556Srgrimes * the code are not to be removed. 181556Srgrimes * If this package is used in a product, Eric Young should be given attribution 191556Srgrimes * as the author of the parts of the library used. 201556Srgrimes * This can be in the form of a textual message at program startup or 211556Srgrimes * in documentation (online or textual) provided with the package. 221556Srgrimes * 231556Srgrimes * Redistribution and use in source and binary forms, with or without 241556Srgrimes * modification, are permitted provided that the following conditions 251556Srgrimes * are met: 261556Srgrimes * 1. Redistributions of source code must retain the copyright 271556Srgrimes * notice, this list of conditions and the following disclaimer. 281556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 291556Srgrimes * notice, this list of conditions and the following disclaimer in the 301556Srgrimes * documentation and/or other materials provided with the distribution. 311556Srgrimes * 3. All advertising materials mentioning features or use of this software 321556Srgrimes * must display the following acknowledgement: 331556Srgrimes * "This product includes cryptographic software written by 3436150Scharnier * Eric Young (eay@cryptsoft.com)" 3536150Scharnier * The word 'cryptographic' can be left out if the rouines from the library 3636150Scharnier * being used are not cryptographic related :-). 371556Srgrimes * 4. If you include any Windows specific code (or a derivative thereof) from 3899110Sobrien * the apps directory (application code) you must include an acknowledgement: 3999110Sobrien * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 401556Srgrimes * 4117987Speter * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42149017Sstefanf * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4317987Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 441556Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 451556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 461556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 471556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 481556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 491556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 501556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 511556Srgrimes * SUCH DAMAGE. 521556Srgrimes * 531556Srgrimes * The licence and distribution terms for any publically available version or 541556Srgrimes * derivative of this code cannot be changed. i.e. this code cannot simply be 551556Srgrimes * copied and put under another distribution licence 561556Srgrimes * [including the GNU Public Licence.] 5717987Speter */ 5859436Scracauer 5917987Speter#include <stdio.h> 601556Srgrimes#include "cryptlib.h" 6117987Speter#include <openssl/bn.h> 621556Srgrimes#include <openssl/rsa.h> 631556Srgrimes#include <openssl/rand.h> 641556Srgrimes 651556Srgrimesint RSA_padding_add_none(unsigned char *to, int tlen, 661556Srgrimes const unsigned char *from, int flen) 67142845Sobrien { 68142845Sobrien if (flen > tlen) 691556Srgrimes { 701556Srgrimes RSAerr(RSA_F_RSA_PADDING_ADD_NONE,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); 7117987Speter return(0); 721556Srgrimes } 731556Srgrimes 741556Srgrimes if (flen < tlen) 751556Srgrimes { 761556Srgrimes RSAerr(RSA_F_RSA_PADDING_ADD_NONE,RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE); 771556Srgrimes return(0); 781556Srgrimes } 791556Srgrimes 801556Srgrimes memcpy(to,from,(unsigned int)flen); 811556Srgrimes return(1); 821556Srgrimes } 831556Srgrimes 84117261Sddsint RSA_padding_check_none(unsigned char *to, int tlen, 85117261Sdds const unsigned char *from, int flen, int num) 86117261Sdds { 87117261Sdds 881556Srgrimes if (flen > tlen) 89117261Sdds { 901556Srgrimes RSAerr(RSA_F_RSA_PADDING_CHECK_NONE,RSA_R_DATA_TOO_LARGE); 91117261Sdds return(-1); 92117261Sdds } 93117261Sdds 94117261Sdds memset(to,0,tlen-flen); 95117261Sdds memcpy(to+tlen-flen,from,flen); 96179022Sstefanf return(tlen); 971556Srgrimes } 9818018Speter 9918018Speter