Make RSA_NO_PADDING really use no padding.
[openssl.git] / crypto / rsa / rsa_none.c
index 6385b556be83ef3a678d202d610c430f909b2e9b..e944f84bec39c6b9146b539b27329314c3ac207f 100644 (file)
@@ -68,13 +68,18 @@ int tlen;
 unsigned char *from;
 int flen;
        {
-       if (flen >= tlen)
+       if (flen > tlen)
                {
                RSAerr(RSA_F_RSA_PADDING_ADD_NONE,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
                return(0);
                }
+
+       if (flen < tlen)
+               {
+               RSAerr(RSA_F_RSA_PADDING_ADD_NONE,RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE);
+               return(0);
+               }
        
-       *(to++)=0;
        memcpy(to,from,(unsigned int)flen);
        return(1);
        }
@@ -86,25 +91,15 @@ unsigned char *from;
 int flen;
 int num;
        {
-       int j;
 
-       from++;
-       if (flen+1 > tlen)
+       if (flen > tlen)
                {
                RSAerr(RSA_F_RSA_PADDING_CHECK_NONE,RSA_R_DATA_TOO_LARGE);
                return(-1);
                }
-       if (flen+1 >= num)
-               {
-               RSAerr(RSA_F_RSA_PADDING_CHECK_NONE,RSA_R_BAD_ZERO_BYTE);
-               return(-1);
-               }
 
-       /* scan over padding data */
-       j=flen-1; /* one for type and one for the prepended 0. */
-       memset(to,0,tlen-j);
-       to+=(tlen-j);
-       memcpy(to,from,j);
-       return(j);
+       memset(to,0,tlen-flen);
+       memcpy(to+tlen-flen,from,flen);
+       return(tlen);
        }