|
Packit Service |
4f68e0 |
/*
|
|
Packit Service |
4f68e0 |
* Copyright (c) 2009, Sun Microsystems, Inc.
|
|
Packit Service |
4f68e0 |
* All rights reserved.
|
|
Packit Service |
4f68e0 |
*
|
|
Packit Service |
4f68e0 |
* Redistribution and use in source and binary forms, with or without
|
|
Packit Service |
4f68e0 |
* modification, are permitted provided that the following conditions are met:
|
|
Packit Service |
4f68e0 |
* - Redistributions of source code must retain the above copyright notice,
|
|
Packit Service |
4f68e0 |
* this list of conditions and the following disclaimer.
|
|
Packit Service |
4f68e0 |
* - Redistributions in binary form must reproduce the above copyright notice,
|
|
Packit Service |
4f68e0 |
* this list of conditions and the following disclaimer in the documentation
|
|
Packit Service |
4f68e0 |
* and/or other materials provided with the distribution.
|
|
Packit Service |
4f68e0 |
* - Neither the name of Sun Microsystems, Inc. nor the names of its
|
|
Packit Service |
4f68e0 |
* contributors may be used to endorse or promote products derived
|
|
Packit Service |
4f68e0 |
* from this software without specific prior written permission.
|
|
Packit Service |
4f68e0 |
*
|
|
Packit Service |
4f68e0 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Packit Service |
4f68e0 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit Service |
4f68e0 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
Packit Service |
4f68e0 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
Packit Service |
4f68e0 |
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
Packit Service |
4f68e0 |
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
Packit Service |
4f68e0 |
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
Packit Service |
4f68e0 |
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
Packit Service |
4f68e0 |
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
Packit Service |
4f68e0 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
Packit Service |
4f68e0 |
* POSSIBILITY OF SUCH DAMAGE.
|
|
Packit Service |
4f68e0 |
*/
|
|
Packit Service |
4f68e0 |
/*
|
|
Packit Service |
4f68e0 |
* des_crypt.c, DES encryption library routines
|
|
Packit Service |
4f68e0 |
* Copyright (C) 1986, Sun Microsystems, Inc.
|
|
Packit Service |
4f68e0 |
*/
|
|
Packit Service |
4f68e0 |
|
|
Packit Service |
4f68e0 |
#include <sys/types.h>
|
|
Packit Service |
4f68e0 |
#include <rpc/types.h>
|
|
Packit Service |
4f68e0 |
#include <rpc/des_crypt.h>
|
|
Packit Service |
4f68e0 |
#include <rpc/des.h>
|
|
Packit Service |
4f68e0 |
#if 0
|
|
Packit Service |
4f68e0 |
#ifndef lint
|
|
Packit Service |
4f68e0 |
static char sccsid[] = "@(#)des_crypt.c 2.2 88/08/10 4.0 RPCSRC; from 1.13 88/02/08 SMI";
|
|
Packit Service |
4f68e0 |
#endif
|
|
Packit Service |
4f68e0 |
#endif
|
|
Packit Service |
4f68e0 |
|
|
Packit Service |
4f68e0 |
static int common_crypt( char *, char *, unsigned, unsigned, struct desparams * );
|
|
Packit Service |
4f68e0 |
/*
|
|
Packit Service |
4f68e0 |
* Copy 8 bytes
|
|
Packit Service |
4f68e0 |
*/
|
|
Packit Service |
4f68e0 |
#define COPY8(src, dst) { \
|
|
Packit Service |
4f68e0 |
char *a = (char *) dst; \
|
|
Packit Service |
4f68e0 |
char *b = (char *) src; \
|
|
Packit Service |
4f68e0 |
*a++ = *b++; *a++ = *b++; *a++ = *b++; *a++ = *b++; \
|
|
Packit Service |
4f68e0 |
*a++ = *b++; *a++ = *b++; *a++ = *b++; *a++ = *b++; \
|
|
Packit Service |
4f68e0 |
}
|
|
Packit Service |
4f68e0 |
|
|
Packit Service |
4f68e0 |
/*
|
|
Packit Service |
4f68e0 |
* Copy multiple of 8 bytes
|
|
Packit Service |
4f68e0 |
*/
|
|
Packit Service |
4f68e0 |
#define DESCOPY(src, dst, len) { \
|
|
Packit Service |
4f68e0 |
char *a = (char *) dst; \
|
|
Packit Service |
4f68e0 |
char *b = (char *) src; \
|
|
Packit Service |
4f68e0 |
int i; \
|
|
Packit Service |
4f68e0 |
for (i = (int) len; i > 0; i -= 8) { \
|
|
Packit Service |
4f68e0 |
*a++ = *b++; *a++ = *b++; *a++ = *b++; *a++ = *b++; \
|
|
Packit Service |
4f68e0 |
*a++ = *b++; *a++ = *b++; *a++ = *b++; *a++ = *b++; \
|
|
Packit Service |
4f68e0 |
} \
|
|
Packit Service |
4f68e0 |
}
|
|
Packit Service |
4f68e0 |
|
|
Packit Service |
4f68e0 |
/*
|
|
Packit Service |
4f68e0 |
* CBC mode encryption
|
|
Packit Service |
4f68e0 |
*/
|
|
Packit Service |
4f68e0 |
int
|
|
Packit Service |
4f68e0 |
cbc_crypt(key, buf, len, mode, ivec)
|
|
Packit Service |
4f68e0 |
char *key;
|
|
Packit Service |
4f68e0 |
char *buf;
|
|
Packit Service |
4f68e0 |
unsigned len;
|
|
Packit Service |
4f68e0 |
unsigned mode;
|
|
Packit Service |
4f68e0 |
char *ivec;
|
|
Packit Service |
4f68e0 |
{
|
|
Packit Service |
4f68e0 |
int err;
|
|
Packit Service |
4f68e0 |
struct desparams dp;
|
|
Packit Service |
4f68e0 |
|
|
Packit Service |
4f68e0 |
#ifdef BROKEN_DES
|
|
Packit Service |
4f68e0 |
dp.UDES.UDES_buf = buf;
|
|
Packit Service |
4f68e0 |
dp.des_mode = ECB;
|
|
Packit Service |
4f68e0 |
#else
|
|
Packit Service |
4f68e0 |
dp.des_mode = CBC;
|
|
Packit Service |
4f68e0 |
#endif
|
|
Packit Service |
4f68e0 |
COPY8(ivec, dp.des_ivec);
|
|
Packit Service |
4f68e0 |
err = common_crypt(key, buf, len, mode, &dp;;
|
|
Packit Service |
4f68e0 |
COPY8(dp.des_ivec, ivec);
|
|
Packit Service |
4f68e0 |
return(err);
|
|
Packit Service |
4f68e0 |
}
|
|
Packit Service |
4f68e0 |
|
|
Packit Service |
4f68e0 |
|
|
Packit Service |
4f68e0 |
/*
|
|
Packit Service |
4f68e0 |
* ECB mode encryption
|
|
Packit Service |
4f68e0 |
*/
|
|
Packit Service |
4f68e0 |
int
|
|
Packit Service |
4f68e0 |
ecb_crypt(key, buf, len, mode)
|
|
Packit Service |
4f68e0 |
char *key;
|
|
Packit Service |
4f68e0 |
char *buf;
|
|
Packit Service |
4f68e0 |
unsigned len;
|
|
Packit Service |
4f68e0 |
unsigned mode;
|
|
Packit Service |
4f68e0 |
{
|
|
Packit Service |
4f68e0 |
struct desparams dp;
|
|
Packit Service |
4f68e0 |
|
|
Packit Service |
4f68e0 |
#ifdef BROKEN_DES
|
|
Packit Service |
4f68e0 |
dp.UDES.UDES_buf = buf;
|
|
Packit Service |
4f68e0 |
dp.des_mode = CBC;
|
|
Packit Service |
4f68e0 |
#else
|
|
Packit Service |
4f68e0 |
dp.des_mode = ECB;
|
|
Packit Service |
4f68e0 |
#endif
|
|
Packit Service |
4f68e0 |
return(common_crypt(key, buf, len, mode, &dp));
|
|
Packit Service |
4f68e0 |
}
|
|
Packit Service |
4f68e0 |
|
|
Packit Service |
4f68e0 |
|
|
Packit Service |
4f68e0 |
|
|
Packit Service |
4f68e0 |
/*
|
|
Packit Service |
4f68e0 |
* Common code to cbc_crypt() & ecb_crypt()
|
|
Packit Service |
4f68e0 |
*/
|
|
Packit Service |
4f68e0 |
static int
|
|
Packit Service |
4f68e0 |
common_crypt(key, buf, len, mode, desp)
|
|
Packit Service |
4f68e0 |
char *key;
|
|
Packit Service |
4f68e0 |
char *buf;
|
|
Packit Service |
4f68e0 |
unsigned len;
|
|
Packit Service |
4f68e0 |
unsigned mode;
|
|
Packit Service |
4f68e0 |
struct desparams *desp;
|
|
Packit Service |
4f68e0 |
{
|
|
Packit Service |
4f68e0 |
int desdev;
|
|
Packit Service |
4f68e0 |
|
|
Packit Service |
4f68e0 |
if ((len % 8) != 0 || len > DES_MAXDATA) {
|
|
Packit Service |
4f68e0 |
return(DESERR_BADPARAM);
|
|
Packit Service |
4f68e0 |
}
|
|
Packit Service |
4f68e0 |
desp->des_dir =
|
|
Packit Service |
4f68e0 |
((mode & DES_DIRMASK) == DES_ENCRYPT) ? ENCRYPT : DECRYPT;
|
|
Packit Service |
4f68e0 |
|
|
Packit Service |
4f68e0 |
desdev = mode & DES_DEVMASK;
|
|
Packit Service |
4f68e0 |
COPY8(key, desp->des_key);
|
|
Packit Service |
4f68e0 |
/*
|
|
Packit Service |
4f68e0 |
* software
|
|
Packit Service |
4f68e0 |
*/
|
|
Packit Service |
4f68e0 |
if (!_des_crypt(buf, len, desp)) {
|
|
Packit Service |
4f68e0 |
return (DESERR_HWERROR);
|
|
Packit Service |
4f68e0 |
}
|
|
Packit Service |
4f68e0 |
|
|
Packit Service |
4f68e0 |
return(desdev == DES_SW ? DESERR_NONE : DESERR_NOHWDEVICE);
|
|
Packit Service |
4f68e0 |
}
|