enc.c revision 9dc0df1bac950d6e491f9a7c7e4888f2b301cb15
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "apps.h"
#include <ctype.h>
#define SIZE (512)
{
static int n;
return;
if(++n == 3)
{
n=0;
}
else
}
int MAIN(int, char **);
{
#ifndef OPENSSL_NO_ENGINE
#endif
static const char magic[]="Salted__";
int nopad = 0;
unsigned char salt[PKCS5_SALT_LEN];
#define PROG_NAME_SIZE 39
#ifndef OPENSSL_NO_ENGINE
#endif
apps_startup();
goto end;
/* first check the program name */
base64=1;
{
goto bad;
}
argc--;
argv++;
while (argc >= 1)
{
enc=1;
{
}
{
}
{
}
#ifndef OPENSSL_NO_ENGINE
{
}
#endif
enc=0;
printkey=1;
verbose=1;
nopad=1;
nosalt=0;
nosalt=1;
debug=1;
printkey=2;
olb64=1;
base64=1;
base64=1;
{
}
{
}
{
static char buf[128];
char *file;
{
file);
goto bad;
}
buf[0]='\0';
if ((i > 0) &&
buf[--i]='\0';
if ((i > 0) &&
buf[--i]='\0';
if (i < 1)
{
goto bad;
}
}
{
}
{
}
{
}
{
}
else if ((argv[0][0] == '-') &&
{
cipher=c;
}
else
{
bad:
#ifndef OPENSSL_NO_ENGINE
#endif
bio_err);
goto end;
}
argc--;
argv++;
}
#ifndef OPENSSL_NO_ENGINE
#endif
{
goto end;
}
{
}
{
unsigned long n;
{
i= *bufsize;
if ((i <= '9') && (i >= '0'))
n=n*10+i-'0';
else if (i == 'k')
{
n*=1024;
bufsize++;
break;
}
}
if (*bufsize != '\0')
{
goto end;
}
/* It must be large enough for a base64 encoded line */
if (n < 80) n=80;
bsize=(int)n;
}
{
goto end;
}
{
goto end;
}
if (debug)
{
}
else
{
{
goto end;
}
}
goto end;
}
}
{
for (;;)
{
char buf[200];
strbuf[0]='\0';
if (i == 0)
{
if (strbuf[0] == '\0')
{
ret=1;
goto end;
}
break;
}
if (i < 0)
{
goto end;
}
}
}
{
#ifdef OPENSSL_SYS_VMS
{
}
#endif
}
else
{
{
goto end;
}
}
if (base64)
{
goto end;
if (debug)
{
}
if (olb64)
if (enc)
else
}
{
/* Note that str is NULL if a key was passed on the command
* line, so we get no salt in that case. Is this a bug?
*/
{
/* Salt handling: if encrypting generate a salt and
* write to output BIO. If decrypting read salt from
* input BIO.
*/
unsigned char *sptr;
else {
if(enc) {
if(hsalt) {
"invalid hex salt value\n");
goto end;
}
goto end;
/* If -P option then don't bother writing */
if((printkey != 2)
(char *)salt,
goto end;
}
(unsigned char *)salt,
goto end;
goto end;
}
}
(unsigned char *)str,
/* zero the complete buffer or the string
* passed from the command line
* bug picked up by
* Larry J. Hughes Jr. <hughes@indiana.edu> */
else
}
{
goto end;
}
{
/* No IV was explicitly set and no IV was generated
* during EVP_BytesToKey. Hence the IV is undefined,
* making correct decryption impossible. */
goto end;
}
{
goto end;
}
goto end;
/* Since we may be changing parameters work on the encryption
* context rather than calling BIO_set_cipher().
*/
{
goto end;
}
if (nopad)
{
goto end;
}
if (debug)
{
}
if (printkey)
{
if (!nosalt)
{
printf("salt=");
for (i=0; i<(int)sizeof(salt); i++)
printf("\n");
}
{
printf("key=");
printf("\n");
}
{
printf("iv =");
printf("\n");
}
if (printkey == 2)
{
ret=0;
goto end;
}
}
}
for (;;)
{
if (inl <= 0) break;
{
goto end;
}
}
{
goto end;
}
ret=0;
if (verbose)
{
}
end:
}
{
int i,n;
unsigned char j;
if (n > (size*2))
{
return(0);
}
for (i=0; i<n; i++)
{
j=(unsigned char)*in;
*(in++)='\0';
if (j == 0) break;
if ((j >= '0') && (j <= '9'))
j-='0';
else if ((j >= 'A') && (j <= 'F'))
j=j-'A'+10;
else if ((j >= 'a') && (j <= 'f'))
j=j-'a'+10;
else
{
return(0);
}
if (i&1)
out[i/2]|=j;
else
}
return(1);
}