mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-08-09 07:23:56 +08:00
update
This commit is contained in:
@@ -69,6 +69,8 @@ tests:
|
||||
lint:
|
||||
lint -DLINT $(INCLUDES) $(SRC)>fluff
|
||||
|
||||
update: depend
|
||||
|
||||
depend:
|
||||
@[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
|
||||
$(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
|
||||
@@ -95,5 +97,8 @@ c_ofb64.o: ../../e_os.h ../../include/openssl/cast.h
|
||||
c_ofb64.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
|
||||
c_ofb64.o: c_ofb64.c cast_lcl.h
|
||||
c_skey.o: ../../e_os.h ../../include/openssl/cast.h
|
||||
c_skey.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
|
||||
c_skey.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
|
||||
c_skey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
|
||||
c_skey.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
|
||||
c_skey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
|
||||
c_skey.o: c_skey.c cast_lcl.h cast_s.h
|
||||
|
||||
@@ -5,21 +5,21 @@
|
||||
* 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:
|
||||
@@ -34,10 +34,10 @@
|
||||
* 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
|
||||
* 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
|
||||
@@ -49,7 +49,7 @@
|
||||
* 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
|
||||
@@ -59,63 +59,65 @@
|
||||
#include <openssl/cast.h>
|
||||
#include "cast_lcl.h"
|
||||
|
||||
/* The input and output encrypted as though 64bit cfb mode is being
|
||||
* used. The extra state information to record how much of the
|
||||
* 64bit block we have used is contained in *num;
|
||||
/*
|
||||
* The input and output encrypted as though 64bit cfb mode is being used.
|
||||
* The extra state information to record how much of the 64bit block we have
|
||||
* used is contained in *num;
|
||||
*/
|
||||
|
||||
void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, const CAST_KEY *schedule, unsigned char *ivec,
|
||||
int *num, int enc)
|
||||
{
|
||||
register CAST_LONG v0,v1,t;
|
||||
register int n= *num;
|
||||
register long l=length;
|
||||
CAST_LONG ti[2];
|
||||
unsigned char *iv,c,cc;
|
||||
long length, const CAST_KEY *schedule,
|
||||
unsigned char *ivec, int *num, int enc)
|
||||
{
|
||||
register CAST_LONG v0, v1, t;
|
||||
register int n = *num;
|
||||
register long l = length;
|
||||
CAST_LONG ti[2];
|
||||
unsigned char *iv, c, cc;
|
||||
|
||||
iv=ivec;
|
||||
if (enc)
|
||||
{
|
||||
while (l--)
|
||||
{
|
||||
if (n == 0)
|
||||
{
|
||||
n2l(iv,v0); ti[0]=v0;
|
||||
n2l(iv,v1); ti[1]=v1;
|
||||
CAST_encrypt((CAST_LONG *)ti,schedule);
|
||||
iv=ivec;
|
||||
t=ti[0]; l2n(t,iv);
|
||||
t=ti[1]; l2n(t,iv);
|
||||
iv=ivec;
|
||||
}
|
||||
c= *(in++)^iv[n];
|
||||
*(out++)=c;
|
||||
iv[n]=c;
|
||||
n=(n+1)&0x07;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (l--)
|
||||
{
|
||||
if (n == 0)
|
||||
{
|
||||
n2l(iv,v0); ti[0]=v0;
|
||||
n2l(iv,v1); ti[1]=v1;
|
||||
CAST_encrypt((CAST_LONG *)ti,schedule);
|
||||
iv=ivec;
|
||||
t=ti[0]; l2n(t,iv);
|
||||
t=ti[1]; l2n(t,iv);
|
||||
iv=ivec;
|
||||
}
|
||||
cc= *(in++);
|
||||
c=iv[n];
|
||||
iv[n]=cc;
|
||||
*(out++)=c^cc;
|
||||
n=(n+1)&0x07;
|
||||
}
|
||||
}
|
||||
v0=v1=ti[0]=ti[1]=t=c=cc=0;
|
||||
*num=n;
|
||||
}
|
||||
iv = ivec;
|
||||
if (enc) {
|
||||
while (l--) {
|
||||
if (n == 0) {
|
||||
n2l(iv, v0);
|
||||
ti[0] = v0;
|
||||
n2l(iv, v1);
|
||||
ti[1] = v1;
|
||||
CAST_encrypt((CAST_LONG *)ti, schedule);
|
||||
iv = ivec;
|
||||
t = ti[0];
|
||||
l2n(t, iv);
|
||||
t = ti[1];
|
||||
l2n(t, iv);
|
||||
iv = ivec;
|
||||
}
|
||||
c = *(in++) ^ iv[n];
|
||||
*(out++) = c;
|
||||
iv[n] = c;
|
||||
n = (n + 1) & 0x07;
|
||||
}
|
||||
} else {
|
||||
while (l--) {
|
||||
if (n == 0) {
|
||||
n2l(iv, v0);
|
||||
ti[0] = v0;
|
||||
n2l(iv, v1);
|
||||
ti[1] = v1;
|
||||
CAST_encrypt((CAST_LONG *)ti, schedule);
|
||||
iv = ivec;
|
||||
t = ti[0];
|
||||
l2n(t, iv);
|
||||
t = ti[1];
|
||||
l2n(t, iv);
|
||||
iv = ivec;
|
||||
}
|
||||
cc = *(in++);
|
||||
c = iv[n];
|
||||
iv[n] = cc;
|
||||
*(out++) = c ^ cc;
|
||||
n = (n + 1) & 0x07;
|
||||
}
|
||||
}
|
||||
v0 = v1 = ti[0] = ti[1] = t = c = cc = 0;
|
||||
*num = n;
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -5,21 +5,21 @@
|
||||
* 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:
|
||||
@@ -34,10 +34,10 @@
|
||||
* 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
|
||||
* 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
|
||||
@@ -49,7 +49,7 @@
|
||||
* 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
|
||||
@@ -60,20 +60,24 @@
|
||||
#include "cast_lcl.h"
|
||||
#include <openssl/opensslv.h>
|
||||
|
||||
const char CAST_version[]="CAST" OPENSSL_VERSION_PTEXT;
|
||||
const char CAST_version[] = "CAST" OPENSSL_VERSION_PTEXT;
|
||||
|
||||
void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out,
|
||||
const CAST_KEY *ks, int enc)
|
||||
{
|
||||
CAST_LONG l,d[2];
|
||||
const CAST_KEY *ks, int enc)
|
||||
{
|
||||
CAST_LONG l, d[2];
|
||||
|
||||
n2l(in,l); d[0]=l;
|
||||
n2l(in,l); d[1]=l;
|
||||
if (enc)
|
||||
CAST_encrypt(d,ks);
|
||||
else
|
||||
CAST_decrypt(d,ks);
|
||||
l=d[0]; l2n(l,out);
|
||||
l=d[1]; l2n(l,out);
|
||||
l=d[0]=d[1]=0;
|
||||
}
|
||||
n2l(in, l);
|
||||
d[0] = l;
|
||||
n2l(in, l);
|
||||
d[1] = l;
|
||||
if (enc)
|
||||
CAST_encrypt(d, ks);
|
||||
else
|
||||
CAST_decrypt(d, ks);
|
||||
l = d[0];
|
||||
l2n(l, out);
|
||||
l = d[1];
|
||||
l2n(l, out);
|
||||
l = d[0] = d[1] = 0;
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -5,21 +5,21 @@
|
||||
* 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:
|
||||
@@ -34,10 +34,10 @@
|
||||
* 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
|
||||
* 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
|
||||
@@ -49,7 +49,7 @@
|
||||
* 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
|
||||
@@ -60,149 +60,141 @@
|
||||
#include "cast_lcl.h"
|
||||
|
||||
void CAST_encrypt(CAST_LONG *data, const CAST_KEY *key)
|
||||
{
|
||||
register CAST_LONG l,r,t;
|
||||
const register CAST_LONG *k;
|
||||
{
|
||||
register CAST_LONG l, r, t;
|
||||
const register CAST_LONG *k;
|
||||
|
||||
k= &(key->data[0]);
|
||||
l=data[0];
|
||||
r=data[1];
|
||||
k = &(key->data[0]);
|
||||
l = data[0];
|
||||
r = data[1];
|
||||
|
||||
E_CAST( 0,k,l,r,+,^,-);
|
||||
E_CAST( 1,k,r,l,^,-,+);
|
||||
E_CAST( 2,k,l,r,-,+,^);
|
||||
E_CAST( 3,k,r,l,+,^,-);
|
||||
E_CAST( 4,k,l,r,^,-,+);
|
||||
E_CAST( 5,k,r,l,-,+,^);
|
||||
E_CAST( 6,k,l,r,+,^,-);
|
||||
E_CAST( 7,k,r,l,^,-,+);
|
||||
E_CAST( 8,k,l,r,-,+,^);
|
||||
E_CAST( 9,k,r,l,+,^,-);
|
||||
E_CAST(10,k,l,r,^,-,+);
|
||||
E_CAST(11,k,r,l,-,+,^);
|
||||
if(!key->short_key)
|
||||
{
|
||||
E_CAST(12,k,l,r,+,^,-);
|
||||
E_CAST(13,k,r,l,^,-,+);
|
||||
E_CAST(14,k,l,r,-,+,^);
|
||||
E_CAST(15,k,r,l,+,^,-);
|
||||
}
|
||||
E_CAST(0, k, l, r, +, ^, -);
|
||||
E_CAST(1, k, r, l, ^, -, +);
|
||||
E_CAST(2, k, l, r, -, +, ^);
|
||||
E_CAST(3, k, r, l, +, ^, -);
|
||||
E_CAST(4, k, l, r, ^, -, +);
|
||||
E_CAST(5, k, r, l, -, +, ^);
|
||||
E_CAST(6, k, l, r, +, ^, -);
|
||||
E_CAST(7, k, r, l, ^, -, +);
|
||||
E_CAST(8, k, l, r, -, +, ^);
|
||||
E_CAST(9, k, r, l, +, ^, -);
|
||||
E_CAST(10, k, l, r, ^, -, +);
|
||||
E_CAST(11, k, r, l, -, +, ^);
|
||||
if (!key->short_key) {
|
||||
E_CAST(12, k, l, r, +, ^, -);
|
||||
E_CAST(13, k, r, l, ^, -, +);
|
||||
E_CAST(14, k, l, r, -, +, ^);
|
||||
E_CAST(15, k, r, l, +, ^, -);
|
||||
}
|
||||
|
||||
data[1]=l&0xffffffffL;
|
||||
data[0]=r&0xffffffffL;
|
||||
}
|
||||
data[1] = l & 0xffffffffL;
|
||||
data[0] = r & 0xffffffffL;
|
||||
}
|
||||
|
||||
void CAST_decrypt(CAST_LONG *data, const CAST_KEY *key)
|
||||
{
|
||||
register CAST_LONG l,r,t;
|
||||
const register CAST_LONG *k;
|
||||
{
|
||||
register CAST_LONG l, r, t;
|
||||
const register CAST_LONG *k;
|
||||
|
||||
k= &(key->data[0]);
|
||||
l=data[0];
|
||||
r=data[1];
|
||||
k = &(key->data[0]);
|
||||
l = data[0];
|
||||
r = data[1];
|
||||
|
||||
if(!key->short_key)
|
||||
{
|
||||
E_CAST(15,k,l,r,+,^,-);
|
||||
E_CAST(14,k,r,l,-,+,^);
|
||||
E_CAST(13,k,l,r,^,-,+);
|
||||
E_CAST(12,k,r,l,+,^,-);
|
||||
}
|
||||
E_CAST(11,k,l,r,-,+,^);
|
||||
E_CAST(10,k,r,l,^,-,+);
|
||||
E_CAST( 9,k,l,r,+,^,-);
|
||||
E_CAST( 8,k,r,l,-,+,^);
|
||||
E_CAST( 7,k,l,r,^,-,+);
|
||||
E_CAST( 6,k,r,l,+,^,-);
|
||||
E_CAST( 5,k,l,r,-,+,^);
|
||||
E_CAST( 4,k,r,l,^,-,+);
|
||||
E_CAST( 3,k,l,r,+,^,-);
|
||||
E_CAST( 2,k,r,l,-,+,^);
|
||||
E_CAST( 1,k,l,r,^,-,+);
|
||||
E_CAST( 0,k,r,l,+,^,-);
|
||||
if (!key->short_key) {
|
||||
E_CAST(15, k, l, r, +, ^, -);
|
||||
E_CAST(14, k, r, l, -, +, ^);
|
||||
E_CAST(13, k, l, r, ^, -, +);
|
||||
E_CAST(12, k, r, l, +, ^, -);
|
||||
}
|
||||
E_CAST(11, k, l, r, -, +, ^);
|
||||
E_CAST(10, k, r, l, ^, -, +);
|
||||
E_CAST(9, k, l, r, +, ^, -);
|
||||
E_CAST(8, k, r, l, -, +, ^);
|
||||
E_CAST(7, k, l, r, ^, -, +);
|
||||
E_CAST(6, k, r, l, +, ^, -);
|
||||
E_CAST(5, k, l, r, -, +, ^);
|
||||
E_CAST(4, k, r, l, ^, -, +);
|
||||
E_CAST(3, k, l, r, +, ^, -);
|
||||
E_CAST(2, k, r, l, -, +, ^);
|
||||
E_CAST(1, k, l, r, ^, -, +);
|
||||
E_CAST(0, k, r, l, +, ^, -);
|
||||
|
||||
data[1]=l&0xffffffffL;
|
||||
data[0]=r&0xffffffffL;
|
||||
}
|
||||
data[1] = l & 0xffffffffL;
|
||||
data[0] = r & 0xffffffffL;
|
||||
}
|
||||
|
||||
void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
|
||||
const CAST_KEY *ks, unsigned char *iv, int enc)
|
||||
{
|
||||
register CAST_LONG tin0,tin1;
|
||||
register CAST_LONG tout0,tout1,xor0,xor1;
|
||||
register long l=length;
|
||||
CAST_LONG tin[2];
|
||||
void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, const CAST_KEY *ks, unsigned char *iv,
|
||||
int enc)
|
||||
{
|
||||
register CAST_LONG tin0, tin1;
|
||||
register CAST_LONG tout0, tout1, xor0, xor1;
|
||||
register long l = length;
|
||||
CAST_LONG tin[2];
|
||||
|
||||
if (enc)
|
||||
{
|
||||
n2l(iv,tout0);
|
||||
n2l(iv,tout1);
|
||||
iv-=8;
|
||||
for (l-=8; l>=0; l-=8)
|
||||
{
|
||||
n2l(in,tin0);
|
||||
n2l(in,tin1);
|
||||
tin0^=tout0;
|
||||
tin1^=tout1;
|
||||
tin[0]=tin0;
|
||||
tin[1]=tin1;
|
||||
CAST_encrypt(tin,ks);
|
||||
tout0=tin[0];
|
||||
tout1=tin[1];
|
||||
l2n(tout0,out);
|
||||
l2n(tout1,out);
|
||||
}
|
||||
if (l != -8)
|
||||
{
|
||||
n2ln(in,tin0,tin1,l+8);
|
||||
tin0^=tout0;
|
||||
tin1^=tout1;
|
||||
tin[0]=tin0;
|
||||
tin[1]=tin1;
|
||||
CAST_encrypt(tin,ks);
|
||||
tout0=tin[0];
|
||||
tout1=tin[1];
|
||||
l2n(tout0,out);
|
||||
l2n(tout1,out);
|
||||
}
|
||||
l2n(tout0,iv);
|
||||
l2n(tout1,iv);
|
||||
}
|
||||
else
|
||||
{
|
||||
n2l(iv,xor0);
|
||||
n2l(iv,xor1);
|
||||
iv-=8;
|
||||
for (l-=8; l>=0; l-=8)
|
||||
{
|
||||
n2l(in,tin0);
|
||||
n2l(in,tin1);
|
||||
tin[0]=tin0;
|
||||
tin[1]=tin1;
|
||||
CAST_decrypt(tin,ks);
|
||||
tout0=tin[0]^xor0;
|
||||
tout1=tin[1]^xor1;
|
||||
l2n(tout0,out);
|
||||
l2n(tout1,out);
|
||||
xor0=tin0;
|
||||
xor1=tin1;
|
||||
}
|
||||
if (l != -8)
|
||||
{
|
||||
n2l(in,tin0);
|
||||
n2l(in,tin1);
|
||||
tin[0]=tin0;
|
||||
tin[1]=tin1;
|
||||
CAST_decrypt(tin,ks);
|
||||
tout0=tin[0]^xor0;
|
||||
tout1=tin[1]^xor1;
|
||||
l2nn(tout0,tout1,out,l+8);
|
||||
xor0=tin0;
|
||||
xor1=tin1;
|
||||
}
|
||||
l2n(xor0,iv);
|
||||
l2n(xor1,iv);
|
||||
}
|
||||
tin0=tin1=tout0=tout1=xor0=xor1=0;
|
||||
tin[0]=tin[1]=0;
|
||||
}
|
||||
if (enc) {
|
||||
n2l(iv, tout0);
|
||||
n2l(iv, tout1);
|
||||
iv -= 8;
|
||||
for (l -= 8; l >= 0; l -= 8) {
|
||||
n2l(in, tin0);
|
||||
n2l(in, tin1);
|
||||
tin0 ^= tout0;
|
||||
tin1 ^= tout1;
|
||||
tin[0] = tin0;
|
||||
tin[1] = tin1;
|
||||
CAST_encrypt(tin, ks);
|
||||
tout0 = tin[0];
|
||||
tout1 = tin[1];
|
||||
l2n(tout0, out);
|
||||
l2n(tout1, out);
|
||||
}
|
||||
if (l != -8) {
|
||||
n2ln(in, tin0, tin1, l + 8);
|
||||
tin0 ^= tout0;
|
||||
tin1 ^= tout1;
|
||||
tin[0] = tin0;
|
||||
tin[1] = tin1;
|
||||
CAST_encrypt(tin, ks);
|
||||
tout0 = tin[0];
|
||||
tout1 = tin[1];
|
||||
l2n(tout0, out);
|
||||
l2n(tout1, out);
|
||||
}
|
||||
l2n(tout0, iv);
|
||||
l2n(tout1, iv);
|
||||
} else {
|
||||
n2l(iv, xor0);
|
||||
n2l(iv, xor1);
|
||||
iv -= 8;
|
||||
for (l -= 8; l >= 0; l -= 8) {
|
||||
n2l(in, tin0);
|
||||
n2l(in, tin1);
|
||||
tin[0] = tin0;
|
||||
tin[1] = tin1;
|
||||
CAST_decrypt(tin, ks);
|
||||
tout0 = tin[0] ^ xor0;
|
||||
tout1 = tin[1] ^ xor1;
|
||||
l2n(tout0, out);
|
||||
l2n(tout1, out);
|
||||
xor0 = tin0;
|
||||
xor1 = tin1;
|
||||
}
|
||||
if (l != -8) {
|
||||
n2l(in, tin0);
|
||||
n2l(in, tin1);
|
||||
tin[0] = tin0;
|
||||
tin[1] = tin1;
|
||||
CAST_decrypt(tin, ks);
|
||||
tout0 = tin[0] ^ xor0;
|
||||
tout1 = tin[1] ^ xor1;
|
||||
l2nn(tout0, tout1, out, l + 8);
|
||||
xor0 = tin0;
|
||||
xor1 = tin1;
|
||||
}
|
||||
l2n(xor0, iv);
|
||||
l2n(xor1, iv);
|
||||
}
|
||||
tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0;
|
||||
tin[0] = tin[1] = 0;
|
||||
}
|
||||
|
||||
@@ -5,21 +5,21 @@
|
||||
* 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:
|
||||
@@ -34,10 +34,10 @@
|
||||
* 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
|
||||
* 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
|
||||
@@ -49,7 +49,7 @@
|
||||
* 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
|
||||
@@ -59,52 +59,52 @@
|
||||
#include <openssl/cast.h>
|
||||
#include "cast_lcl.h"
|
||||
|
||||
/* The input and output encrypted as though 64bit ofb mode is being
|
||||
* used. The extra state information to record how much of the
|
||||
* 64bit block we have used is contained in *num;
|
||||
/*
|
||||
* The input and output encrypted as though 64bit ofb mode is being used.
|
||||
* The extra state information to record how much of the 64bit block we have
|
||||
* used is contained in *num;
|
||||
*/
|
||||
void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, const CAST_KEY *schedule, unsigned char *ivec,
|
||||
int *num)
|
||||
{
|
||||
register CAST_LONG v0,v1,t;
|
||||
register int n= *num;
|
||||
register long l=length;
|
||||
unsigned char d[8];
|
||||
register char *dp;
|
||||
CAST_LONG ti[2];
|
||||
unsigned char *iv;
|
||||
int save=0;
|
||||
long length, const CAST_KEY *schedule,
|
||||
unsigned char *ivec, int *num)
|
||||
{
|
||||
register CAST_LONG v0, v1, t;
|
||||
register int n = *num;
|
||||
register long l = length;
|
||||
unsigned char d[8];
|
||||
register char *dp;
|
||||
CAST_LONG ti[2];
|
||||
unsigned char *iv;
|
||||
int save = 0;
|
||||
|
||||
iv=ivec;
|
||||
n2l(iv,v0);
|
||||
n2l(iv,v1);
|
||||
ti[0]=v0;
|
||||
ti[1]=v1;
|
||||
dp=(char *)d;
|
||||
l2n(v0,dp);
|
||||
l2n(v1,dp);
|
||||
while (l--)
|
||||
{
|
||||
if (n == 0)
|
||||
{
|
||||
CAST_encrypt((CAST_LONG *)ti,schedule);
|
||||
dp=(char *)d;
|
||||
t=ti[0]; l2n(t,dp);
|
||||
t=ti[1]; l2n(t,dp);
|
||||
save++;
|
||||
}
|
||||
*(out++)= *(in++)^d[n];
|
||||
n=(n+1)&0x07;
|
||||
}
|
||||
if (save)
|
||||
{
|
||||
v0=ti[0];
|
||||
v1=ti[1];
|
||||
iv=ivec;
|
||||
l2n(v0,iv);
|
||||
l2n(v1,iv);
|
||||
}
|
||||
t=v0=v1=ti[0]=ti[1]=0;
|
||||
*num=n;
|
||||
}
|
||||
iv = ivec;
|
||||
n2l(iv, v0);
|
||||
n2l(iv, v1);
|
||||
ti[0] = v0;
|
||||
ti[1] = v1;
|
||||
dp = (char *)d;
|
||||
l2n(v0, dp);
|
||||
l2n(v1, dp);
|
||||
while (l--) {
|
||||
if (n == 0) {
|
||||
CAST_encrypt((CAST_LONG *)ti, schedule);
|
||||
dp = (char *)d;
|
||||
t = ti[0];
|
||||
l2n(t, dp);
|
||||
t = ti[1];
|
||||
l2n(t, dp);
|
||||
save++;
|
||||
}
|
||||
*(out++) = *(in++) ^ d[n];
|
||||
n = (n + 1) & 0x07;
|
||||
}
|
||||
if (save) {
|
||||
v0 = ti[0];
|
||||
v1 = ti[1];
|
||||
iv = ivec;
|
||||
l2n(v0, iv);
|
||||
l2n(v1, iv);
|
||||
}
|
||||
t = v0 = v1 = ti[0] = ti[1] = 0;
|
||||
*num = n;
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -5,21 +5,21 @@
|
||||
* 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:
|
||||
@@ -34,10 +34,10 @@
|
||||
* 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
|
||||
* 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
|
||||
@@ -49,118 +49,127 @@
|
||||
* 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 <openssl/crypto.h>
|
||||
#include <openssl/cast.h>
|
||||
#include "cast_lcl.h"
|
||||
#include "cast_s.h"
|
||||
|
||||
#define CAST_exp(l,A,a,n) \
|
||||
A[n/4]=l; \
|
||||
a[n+3]=(l )&0xff; \
|
||||
a[n+2]=(l>> 8)&0xff; \
|
||||
a[n+1]=(l>>16)&0xff; \
|
||||
a[n+0]=(l>>24)&0xff;
|
||||
A[n/4]=l; \
|
||||
a[n+3]=(l )&0xff; \
|
||||
a[n+2]=(l>> 8)&0xff; \
|
||||
a[n+1]=(l>>16)&0xff; \
|
||||
a[n+0]=(l>>24)&0xff;
|
||||
|
||||
#define S4 CAST_S_table4
|
||||
#define S5 CAST_S_table5
|
||||
#define S6 CAST_S_table6
|
||||
#define S7 CAST_S_table7
|
||||
|
||||
void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data)
|
||||
{
|
||||
CAST_LONG x[16];
|
||||
CAST_LONG z[16];
|
||||
CAST_LONG k[32];
|
||||
CAST_LONG X[4],Z[4];
|
||||
CAST_LONG l,*K;
|
||||
int i;
|
||||
#ifdef OPENSSL_FIPS
|
||||
{
|
||||
fips_cipher_abort(CAST);
|
||||
private_CAST_set_key(key, len, data);
|
||||
}
|
||||
|
||||
for (i=0; i<16; i++) x[i]=0;
|
||||
if (len > 16) len=16;
|
||||
for (i=0; i<len; i++)
|
||||
x[i]=data[i];
|
||||
if(len <= 10)
|
||||
key->short_key=1;
|
||||
else
|
||||
key->short_key=0;
|
||||
void private_CAST_set_key(CAST_KEY *key, int len, const unsigned char *data)
|
||||
#endif
|
||||
{
|
||||
CAST_LONG x[16];
|
||||
CAST_LONG z[16];
|
||||
CAST_LONG k[32];
|
||||
CAST_LONG X[4], Z[4];
|
||||
CAST_LONG l, *K;
|
||||
int i;
|
||||
|
||||
K= &k[0];
|
||||
X[0]=((x[ 0]<<24)|(x[ 1]<<16)|(x[ 2]<<8)|x[ 3])&0xffffffffL;
|
||||
X[1]=((x[ 4]<<24)|(x[ 5]<<16)|(x[ 6]<<8)|x[ 7])&0xffffffffL;
|
||||
X[2]=((x[ 8]<<24)|(x[ 9]<<16)|(x[10]<<8)|x[11])&0xffffffffL;
|
||||
X[3]=((x[12]<<24)|(x[13]<<16)|(x[14]<<8)|x[15])&0xffffffffL;
|
||||
for (i = 0; i < 16; i++)
|
||||
x[i] = 0;
|
||||
if (len > 16)
|
||||
len = 16;
|
||||
for (i = 0; i < len; i++)
|
||||
x[i] = data[i];
|
||||
if (len <= 10)
|
||||
key->short_key = 1;
|
||||
else
|
||||
key->short_key = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
l=X[0]^S4[x[13]]^S5[x[15]]^S6[x[12]]^S7[x[14]]^S6[x[ 8]];
|
||||
CAST_exp(l,Z,z, 0);
|
||||
l=X[2]^S4[z[ 0]]^S5[z[ 2]]^S6[z[ 1]]^S7[z[ 3]]^S7[x[10]];
|
||||
CAST_exp(l,Z,z, 4);
|
||||
l=X[3]^S4[z[ 7]]^S5[z[ 6]]^S6[z[ 5]]^S7[z[ 4]]^S4[x[ 9]];
|
||||
CAST_exp(l,Z,z, 8);
|
||||
l=X[1]^S4[z[10]]^S5[z[ 9]]^S6[z[11]]^S7[z[ 8]]^S5[x[11]];
|
||||
CAST_exp(l,Z,z,12);
|
||||
K = &k[0];
|
||||
X[0] = ((x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3]) & 0xffffffffL;
|
||||
X[1] = ((x[4] << 24) | (x[5] << 16) | (x[6] << 8) | x[7]) & 0xffffffffL;
|
||||
X[2] = ((x[8] << 24) | (x[9] << 16) | (x[10] << 8) | x[11]) & 0xffffffffL;
|
||||
X[3] =
|
||||
((x[12] << 24) | (x[13] << 16) | (x[14] << 8) | x[15]) & 0xffffffffL;
|
||||
|
||||
K[ 0]= S4[z[ 8]]^S5[z[ 9]]^S6[z[ 7]]^S7[z[ 6]]^S4[z[ 2]];
|
||||
K[ 1]= S4[z[10]]^S5[z[11]]^S6[z[ 5]]^S7[z[ 4]]^S5[z[ 6]];
|
||||
K[ 2]= S4[z[12]]^S5[z[13]]^S6[z[ 3]]^S7[z[ 2]]^S6[z[ 9]];
|
||||
K[ 3]= S4[z[14]]^S5[z[15]]^S6[z[ 1]]^S7[z[ 0]]^S7[z[12]];
|
||||
for (;;) {
|
||||
l = X[0] ^ S4[x[13]] ^ S5[x[15]] ^ S6[x[12]] ^ S7[x[14]] ^ S6[x[8]];
|
||||
CAST_exp(l, Z, z, 0);
|
||||
l = X[2] ^ S4[z[0]] ^ S5[z[2]] ^ S6[z[1]] ^ S7[z[3]] ^ S7[x[10]];
|
||||
CAST_exp(l, Z, z, 4);
|
||||
l = X[3] ^ S4[z[7]] ^ S5[z[6]] ^ S6[z[5]] ^ S7[z[4]] ^ S4[x[9]];
|
||||
CAST_exp(l, Z, z, 8);
|
||||
l = X[1] ^ S4[z[10]] ^ S5[z[9]] ^ S6[z[11]] ^ S7[z[8]] ^ S5[x[11]];
|
||||
CAST_exp(l, Z, z, 12);
|
||||
|
||||
l=Z[2]^S4[z[ 5]]^S5[z[ 7]]^S6[z[ 4]]^S7[z[ 6]]^S6[z[ 0]];
|
||||
CAST_exp(l,X,x, 0);
|
||||
l=Z[0]^S4[x[ 0]]^S5[x[ 2]]^S6[x[ 1]]^S7[x[ 3]]^S7[z[ 2]];
|
||||
CAST_exp(l,X,x, 4);
|
||||
l=Z[1]^S4[x[ 7]]^S5[x[ 6]]^S6[x[ 5]]^S7[x[ 4]]^S4[z[ 1]];
|
||||
CAST_exp(l,X,x, 8);
|
||||
l=Z[3]^S4[x[10]]^S5[x[ 9]]^S6[x[11]]^S7[x[ 8]]^S5[z[ 3]];
|
||||
CAST_exp(l,X,x,12);
|
||||
K[0] = S4[z[8]] ^ S5[z[9]] ^ S6[z[7]] ^ S7[z[6]] ^ S4[z[2]];
|
||||
K[1] = S4[z[10]] ^ S5[z[11]] ^ S6[z[5]] ^ S7[z[4]] ^ S5[z[6]];
|
||||
K[2] = S4[z[12]] ^ S5[z[13]] ^ S6[z[3]] ^ S7[z[2]] ^ S6[z[9]];
|
||||
K[3] = S4[z[14]] ^ S5[z[15]] ^ S6[z[1]] ^ S7[z[0]] ^ S7[z[12]];
|
||||
|
||||
K[ 4]= S4[x[ 3]]^S5[x[ 2]]^S6[x[12]]^S7[x[13]]^S4[x[ 8]];
|
||||
K[ 5]= S4[x[ 1]]^S5[x[ 0]]^S6[x[14]]^S7[x[15]]^S5[x[13]];
|
||||
K[ 6]= S4[x[ 7]]^S5[x[ 6]]^S6[x[ 8]]^S7[x[ 9]]^S6[x[ 3]];
|
||||
K[ 7]= S4[x[ 5]]^S5[x[ 4]]^S6[x[10]]^S7[x[11]]^S7[x[ 7]];
|
||||
l = Z[2] ^ S4[z[5]] ^ S5[z[7]] ^ S6[z[4]] ^ S7[z[6]] ^ S6[z[0]];
|
||||
CAST_exp(l, X, x, 0);
|
||||
l = Z[0] ^ S4[x[0]] ^ S5[x[2]] ^ S6[x[1]] ^ S7[x[3]] ^ S7[z[2]];
|
||||
CAST_exp(l, X, x, 4);
|
||||
l = Z[1] ^ S4[x[7]] ^ S5[x[6]] ^ S6[x[5]] ^ S7[x[4]] ^ S4[z[1]];
|
||||
CAST_exp(l, X, x, 8);
|
||||
l = Z[3] ^ S4[x[10]] ^ S5[x[9]] ^ S6[x[11]] ^ S7[x[8]] ^ S5[z[3]];
|
||||
CAST_exp(l, X, x, 12);
|
||||
|
||||
l=X[0]^S4[x[13]]^S5[x[15]]^S6[x[12]]^S7[x[14]]^S6[x[ 8]];
|
||||
CAST_exp(l,Z,z, 0);
|
||||
l=X[2]^S4[z[ 0]]^S5[z[ 2]]^S6[z[ 1]]^S7[z[ 3]]^S7[x[10]];
|
||||
CAST_exp(l,Z,z, 4);
|
||||
l=X[3]^S4[z[ 7]]^S5[z[ 6]]^S6[z[ 5]]^S7[z[ 4]]^S4[x[ 9]];
|
||||
CAST_exp(l,Z,z, 8);
|
||||
l=X[1]^S4[z[10]]^S5[z[ 9]]^S6[z[11]]^S7[z[ 8]]^S5[x[11]];
|
||||
CAST_exp(l,Z,z,12);
|
||||
K[4] = S4[x[3]] ^ S5[x[2]] ^ S6[x[12]] ^ S7[x[13]] ^ S4[x[8]];
|
||||
K[5] = S4[x[1]] ^ S5[x[0]] ^ S6[x[14]] ^ S7[x[15]] ^ S5[x[13]];
|
||||
K[6] = S4[x[7]] ^ S5[x[6]] ^ S6[x[8]] ^ S7[x[9]] ^ S6[x[3]];
|
||||
K[7] = S4[x[5]] ^ S5[x[4]] ^ S6[x[10]] ^ S7[x[11]] ^ S7[x[7]];
|
||||
|
||||
K[ 8]= S4[z[ 3]]^S5[z[ 2]]^S6[z[12]]^S7[z[13]]^S4[z[ 9]];
|
||||
K[ 9]= S4[z[ 1]]^S5[z[ 0]]^S6[z[14]]^S7[z[15]]^S5[z[12]];
|
||||
K[10]= S4[z[ 7]]^S5[z[ 6]]^S6[z[ 8]]^S7[z[ 9]]^S6[z[ 2]];
|
||||
K[11]= S4[z[ 5]]^S5[z[ 4]]^S6[z[10]]^S7[z[11]]^S7[z[ 6]];
|
||||
l = X[0] ^ S4[x[13]] ^ S5[x[15]] ^ S6[x[12]] ^ S7[x[14]] ^ S6[x[8]];
|
||||
CAST_exp(l, Z, z, 0);
|
||||
l = X[2] ^ S4[z[0]] ^ S5[z[2]] ^ S6[z[1]] ^ S7[z[3]] ^ S7[x[10]];
|
||||
CAST_exp(l, Z, z, 4);
|
||||
l = X[3] ^ S4[z[7]] ^ S5[z[6]] ^ S6[z[5]] ^ S7[z[4]] ^ S4[x[9]];
|
||||
CAST_exp(l, Z, z, 8);
|
||||
l = X[1] ^ S4[z[10]] ^ S5[z[9]] ^ S6[z[11]] ^ S7[z[8]] ^ S5[x[11]];
|
||||
CAST_exp(l, Z, z, 12);
|
||||
|
||||
l=Z[2]^S4[z[ 5]]^S5[z[ 7]]^S6[z[ 4]]^S7[z[ 6]]^S6[z[ 0]];
|
||||
CAST_exp(l,X,x, 0);
|
||||
l=Z[0]^S4[x[ 0]]^S5[x[ 2]]^S6[x[ 1]]^S7[x[ 3]]^S7[z[ 2]];
|
||||
CAST_exp(l,X,x, 4);
|
||||
l=Z[1]^S4[x[ 7]]^S5[x[ 6]]^S6[x[ 5]]^S7[x[ 4]]^S4[z[ 1]];
|
||||
CAST_exp(l,X,x, 8);
|
||||
l=Z[3]^S4[x[10]]^S5[x[ 9]]^S6[x[11]]^S7[x[ 8]]^S5[z[ 3]];
|
||||
CAST_exp(l,X,x,12);
|
||||
K[8] = S4[z[3]] ^ S5[z[2]] ^ S6[z[12]] ^ S7[z[13]] ^ S4[z[9]];
|
||||
K[9] = S4[z[1]] ^ S5[z[0]] ^ S6[z[14]] ^ S7[z[15]] ^ S5[z[12]];
|
||||
K[10] = S4[z[7]] ^ S5[z[6]] ^ S6[z[8]] ^ S7[z[9]] ^ S6[z[2]];
|
||||
K[11] = S4[z[5]] ^ S5[z[4]] ^ S6[z[10]] ^ S7[z[11]] ^ S7[z[6]];
|
||||
|
||||
K[12]= S4[x[ 8]]^S5[x[ 9]]^S6[x[ 7]]^S7[x[ 6]]^S4[x[ 3]];
|
||||
K[13]= S4[x[10]]^S5[x[11]]^S6[x[ 5]]^S7[x[ 4]]^S5[x[ 7]];
|
||||
K[14]= S4[x[12]]^S5[x[13]]^S6[x[ 3]]^S7[x[ 2]]^S6[x[ 8]];
|
||||
K[15]= S4[x[14]]^S5[x[15]]^S6[x[ 1]]^S7[x[ 0]]^S7[x[13]];
|
||||
if (K != k) break;
|
||||
K+=16;
|
||||
}
|
||||
l = Z[2] ^ S4[z[5]] ^ S5[z[7]] ^ S6[z[4]] ^ S7[z[6]] ^ S6[z[0]];
|
||||
CAST_exp(l, X, x, 0);
|
||||
l = Z[0] ^ S4[x[0]] ^ S5[x[2]] ^ S6[x[1]] ^ S7[x[3]] ^ S7[z[2]];
|
||||
CAST_exp(l, X, x, 4);
|
||||
l = Z[1] ^ S4[x[7]] ^ S5[x[6]] ^ S6[x[5]] ^ S7[x[4]] ^ S4[z[1]];
|
||||
CAST_exp(l, X, x, 8);
|
||||
l = Z[3] ^ S4[x[10]] ^ S5[x[9]] ^ S6[x[11]] ^ S7[x[8]] ^ S5[z[3]];
|
||||
CAST_exp(l, X, x, 12);
|
||||
|
||||
for (i=0; i<16; i++)
|
||||
{
|
||||
key->data[i*2]=k[i];
|
||||
key->data[i*2+1]=((k[i+16])+16)&0x1f;
|
||||
}
|
||||
}
|
||||
K[12] = S4[x[8]] ^ S5[x[9]] ^ S6[x[7]] ^ S7[x[6]] ^ S4[x[3]];
|
||||
K[13] = S4[x[10]] ^ S5[x[11]] ^ S6[x[5]] ^ S7[x[4]] ^ S5[x[7]];
|
||||
K[14] = S4[x[12]] ^ S5[x[13]] ^ S6[x[3]] ^ S7[x[2]] ^ S6[x[8]];
|
||||
K[15] = S4[x[14]] ^ S5[x[15]] ^ S6[x[1]] ^ S7[x[0]] ^ S7[x[13]];
|
||||
if (K != k)
|
||||
break;
|
||||
K += 16;
|
||||
}
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
key->data[i * 2] = k[i];
|
||||
key->data[i * 2 + 1] = ((k[i + 16]) + 16) & 0x1f;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,929 +0,0 @@
|
||||
.file "cast-586.s"
|
||||
.text
|
||||
.globl _CAST_encrypt
|
||||
.align 4
|
||||
_CAST_encrypt:
|
||||
L_CAST_encrypt_begin:
|
||||
|
||||
pushl %ebp
|
||||
pushl %ebx
|
||||
movl 12(%esp),%ebx
|
||||
movl 16(%esp),%ebp
|
||||
pushl %esi
|
||||
pushl %edi
|
||||
# Load the 2 words
|
||||
movl (%ebx),%edi
|
||||
movl 4(%ebx),%esi
|
||||
# Get short key flag
|
||||
movl 128(%ebp),%eax
|
||||
pushl %eax
|
||||
xorl %eax,%eax
|
||||
# round 0
|
||||
movl (%ebp),%edx
|
||||
movl 4(%ebp),%ecx
|
||||
addl %esi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
xorl %ecx,%edi
|
||||
# round 1
|
||||
movl 8(%ebp),%edx
|
||||
movl 12(%ebp),%ecx
|
||||
xorl %edi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
xorl %ecx,%esi
|
||||
# round 2
|
||||
movl 16(%ebp),%edx
|
||||
movl 20(%ebp),%ecx
|
||||
subl %esi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
xorl %ecx,%edi
|
||||
# round 3
|
||||
movl 24(%ebp),%edx
|
||||
movl 28(%ebp),%ecx
|
||||
addl %edi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
xorl %ecx,%esi
|
||||
# round 4
|
||||
movl 32(%ebp),%edx
|
||||
movl 36(%ebp),%ecx
|
||||
xorl %esi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
xorl %ecx,%edi
|
||||
# round 5
|
||||
movl 40(%ebp),%edx
|
||||
movl 44(%ebp),%ecx
|
||||
subl %edi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
xorl %ecx,%esi
|
||||
# round 6
|
||||
movl 48(%ebp),%edx
|
||||
movl 52(%ebp),%ecx
|
||||
addl %esi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
xorl %ecx,%edi
|
||||
# round 7
|
||||
movl 56(%ebp),%edx
|
||||
movl 60(%ebp),%ecx
|
||||
xorl %edi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
xorl %ecx,%esi
|
||||
# round 8
|
||||
movl 64(%ebp),%edx
|
||||
movl 68(%ebp),%ecx
|
||||
subl %esi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
xorl %ecx,%edi
|
||||
# round 9
|
||||
movl 72(%ebp),%edx
|
||||
movl 76(%ebp),%ecx
|
||||
addl %edi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
xorl %ecx,%esi
|
||||
# round 10
|
||||
movl 80(%ebp),%edx
|
||||
movl 84(%ebp),%ecx
|
||||
xorl %esi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
xorl %ecx,%edi
|
||||
# round 11
|
||||
movl 88(%ebp),%edx
|
||||
movl 92(%ebp),%ecx
|
||||
subl %edi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
xorl %ecx,%esi
|
||||
# test short key flag
|
||||
popl %edx
|
||||
orl %edx,%edx
|
||||
jnz L000cast_enc_done
|
||||
# round 12
|
||||
movl 96(%ebp),%edx
|
||||
movl 100(%ebp),%ecx
|
||||
addl %esi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
xorl %ecx,%edi
|
||||
# round 13
|
||||
movl 104(%ebp),%edx
|
||||
movl 108(%ebp),%ecx
|
||||
xorl %edi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
xorl %ecx,%esi
|
||||
# round 14
|
||||
movl 112(%ebp),%edx
|
||||
movl 116(%ebp),%ecx
|
||||
subl %esi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
xorl %ecx,%edi
|
||||
# round 15
|
||||
movl 120(%ebp),%edx
|
||||
movl 124(%ebp),%ecx
|
||||
addl %edi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
xorl %ecx,%esi
|
||||
L000cast_enc_done:
|
||||
nop
|
||||
movl 20(%esp),%eax
|
||||
movl %edi,4(%eax)
|
||||
movl %esi,(%eax)
|
||||
popl %edi
|
||||
popl %esi
|
||||
popl %ebx
|
||||
popl %ebp
|
||||
ret
|
||||
.globl _CAST_decrypt
|
||||
.align 4
|
||||
_CAST_decrypt:
|
||||
L_CAST_decrypt_begin:
|
||||
|
||||
pushl %ebp
|
||||
pushl %ebx
|
||||
movl 12(%esp),%ebx
|
||||
movl 16(%esp),%ebp
|
||||
pushl %esi
|
||||
pushl %edi
|
||||
# Load the 2 words
|
||||
movl (%ebx),%edi
|
||||
movl 4(%ebx),%esi
|
||||
# Get short key flag
|
||||
movl 128(%ebp),%eax
|
||||
orl %eax,%eax
|
||||
jnz L001cast_dec_skip
|
||||
xorl %eax,%eax
|
||||
# round 15
|
||||
movl 120(%ebp),%edx
|
||||
movl 124(%ebp),%ecx
|
||||
addl %esi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
xorl %ecx,%edi
|
||||
# round 14
|
||||
movl 112(%ebp),%edx
|
||||
movl 116(%ebp),%ecx
|
||||
subl %edi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
xorl %ecx,%esi
|
||||
# round 13
|
||||
movl 104(%ebp),%edx
|
||||
movl 108(%ebp),%ecx
|
||||
xorl %esi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
xorl %ecx,%edi
|
||||
# round 12
|
||||
movl 96(%ebp),%edx
|
||||
movl 100(%ebp),%ecx
|
||||
addl %edi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
xorl %ecx,%esi
|
||||
L001cast_dec_skip:
|
||||
# round 11
|
||||
movl 88(%ebp),%edx
|
||||
movl 92(%ebp),%ecx
|
||||
subl %esi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
xorl %ecx,%edi
|
||||
# round 10
|
||||
movl 80(%ebp),%edx
|
||||
movl 84(%ebp),%ecx
|
||||
xorl %edi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
xorl %ecx,%esi
|
||||
# round 9
|
||||
movl 72(%ebp),%edx
|
||||
movl 76(%ebp),%ecx
|
||||
addl %esi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
xorl %ecx,%edi
|
||||
# round 8
|
||||
movl 64(%ebp),%edx
|
||||
movl 68(%ebp),%ecx
|
||||
subl %edi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
xorl %ecx,%esi
|
||||
# round 7
|
||||
movl 56(%ebp),%edx
|
||||
movl 60(%ebp),%ecx
|
||||
xorl %esi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
xorl %ecx,%edi
|
||||
# round 6
|
||||
movl 48(%ebp),%edx
|
||||
movl 52(%ebp),%ecx
|
||||
addl %edi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
xorl %ecx,%esi
|
||||
# round 5
|
||||
movl 40(%ebp),%edx
|
||||
movl 44(%ebp),%ecx
|
||||
subl %esi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
xorl %ecx,%edi
|
||||
# round 4
|
||||
movl 32(%ebp),%edx
|
||||
movl 36(%ebp),%ecx
|
||||
xorl %edi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
xorl %ecx,%esi
|
||||
# round 3
|
||||
movl 24(%ebp),%edx
|
||||
movl 28(%ebp),%ecx
|
||||
addl %esi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
xorl %ecx,%edi
|
||||
# round 2
|
||||
movl 16(%ebp),%edx
|
||||
movl 20(%ebp),%ecx
|
||||
subl %edi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
xorl %ecx,%esi
|
||||
# round 1
|
||||
movl 8(%ebp),%edx
|
||||
movl 12(%ebp),%ecx
|
||||
xorl %esi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
xorl %ecx,%edi
|
||||
# round 0
|
||||
movl (%ebp),%edx
|
||||
movl 4(%ebp),%ecx
|
||||
addl %edi,%edx
|
||||
roll %cl,%edx
|
||||
movl %edx,%ebx
|
||||
xorl %ecx,%ecx
|
||||
movb %dh,%cl
|
||||
andl $255,%ebx
|
||||
shrl $16,%edx
|
||||
xorl %eax,%eax
|
||||
movb %dh,%al
|
||||
andl $255,%edx
|
||||
movl _CAST_S_table0(,%ecx,4),%ecx
|
||||
movl _CAST_S_table1(,%ebx,4),%ebx
|
||||
xorl %ebx,%ecx
|
||||
movl _CAST_S_table2(,%eax,4),%ebx
|
||||
subl %ebx,%ecx
|
||||
movl _CAST_S_table3(,%edx,4),%ebx
|
||||
addl %ebx,%ecx
|
||||
xorl %ecx,%esi
|
||||
nop
|
||||
movl 20(%esp),%eax
|
||||
movl %edi,4(%eax)
|
||||
movl %esi,(%eax)
|
||||
popl %edi
|
||||
popl %esi
|
||||
popl %ebx
|
||||
popl %ebp
|
||||
ret
|
||||
.globl _CAST_cbc_encrypt
|
||||
.align 4
|
||||
_CAST_cbc_encrypt:
|
||||
L_CAST_cbc_encrypt_begin:
|
||||
|
||||
pushl %ebp
|
||||
pushl %ebx
|
||||
pushl %esi
|
||||
pushl %edi
|
||||
movl 28(%esp),%ebp
|
||||
# getting iv ptr from parameter 4
|
||||
movl 36(%esp),%ebx
|
||||
movl (%ebx),%esi
|
||||
movl 4(%ebx),%edi
|
||||
pushl %edi
|
||||
pushl %esi
|
||||
pushl %edi
|
||||
pushl %esi
|
||||
movl %esp,%ebx
|
||||
movl 36(%esp),%esi
|
||||
movl 40(%esp),%edi
|
||||
# getting encrypt flag from parameter 5
|
||||
movl 56(%esp),%ecx
|
||||
# get and push parameter 3
|
||||
movl 48(%esp),%eax
|
||||
pushl %eax
|
||||
pushl %ebx
|
||||
cmpl $0,%ecx
|
||||
jz L002decrypt
|
||||
andl $4294967288,%ebp
|
||||
movl 8(%esp),%eax
|
||||
movl 12(%esp),%ebx
|
||||
jz L003encrypt_finish
|
||||
L004encrypt_loop:
|
||||
movl (%esi),%ecx
|
||||
movl 4(%esi),%edx
|
||||
xorl %ecx,%eax
|
||||
xorl %edx,%ebx
|
||||
bswap %eax
|
||||
bswap %ebx
|
||||
movl %eax,8(%esp)
|
||||
movl %ebx,12(%esp)
|
||||
call L_CAST_encrypt_begin
|
||||
movl 8(%esp),%eax
|
||||
movl 12(%esp),%ebx
|
||||
bswap %eax
|
||||
bswap %ebx
|
||||
movl %eax,(%edi)
|
||||
movl %ebx,4(%edi)
|
||||
addl $8,%esi
|
||||
addl $8,%edi
|
||||
subl $8,%ebp
|
||||
jnz L004encrypt_loop
|
||||
L003encrypt_finish:
|
||||
movl 52(%esp),%ebp
|
||||
andl $7,%ebp
|
||||
jz L005finish
|
||||
call L006PIC_point
|
||||
L006PIC_point:
|
||||
popl %edx
|
||||
leal L007cbc_enc_jmp_table-L006PIC_point(%edx),%ecx
|
||||
movl (%ecx,%ebp,4),%ebp
|
||||
addl %edx,%ebp
|
||||
xorl %ecx,%ecx
|
||||
xorl %edx,%edx
|
||||
jmp *%ebp
|
||||
L008ej7:
|
||||
xorl %edx,%edx
|
||||
movb 6(%esi),%dh
|
||||
shll $8,%edx
|
||||
L009ej6:
|
||||
movb 5(%esi),%dh
|
||||
L010ej5:
|
||||
movb 4(%esi),%dl
|
||||
L011ej4:
|
||||
movl (%esi),%ecx
|
||||
jmp L012ejend
|
||||
L013ej3:
|
||||
movb 2(%esi),%ch
|
||||
xorl %ecx,%ecx
|
||||
shll $8,%ecx
|
||||
L014ej2:
|
||||
movb 1(%esi),%ch
|
||||
L015ej1:
|
||||
movb (%esi),%cl
|
||||
L012ejend:
|
||||
xorl %ecx,%eax
|
||||
xorl %edx,%ebx
|
||||
bswap %eax
|
||||
bswap %ebx
|
||||
movl %eax,8(%esp)
|
||||
movl %ebx,12(%esp)
|
||||
call L_CAST_encrypt_begin
|
||||
movl 8(%esp),%eax
|
||||
movl 12(%esp),%ebx
|
||||
bswap %eax
|
||||
bswap %ebx
|
||||
movl %eax,(%edi)
|
||||
movl %ebx,4(%edi)
|
||||
jmp L005finish
|
||||
L002decrypt:
|
||||
andl $4294967288,%ebp
|
||||
movl 16(%esp),%eax
|
||||
movl 20(%esp),%ebx
|
||||
jz L016decrypt_finish
|
||||
L017decrypt_loop:
|
||||
movl (%esi),%eax
|
||||
movl 4(%esi),%ebx
|
||||
bswap %eax
|
||||
bswap %ebx
|
||||
movl %eax,8(%esp)
|
||||
movl %ebx,12(%esp)
|
||||
call L_CAST_decrypt_begin
|
||||
movl 8(%esp),%eax
|
||||
movl 12(%esp),%ebx
|
||||
bswap %eax
|
||||
bswap %ebx
|
||||
movl 16(%esp),%ecx
|
||||
movl 20(%esp),%edx
|
||||
xorl %eax,%ecx
|
||||
xorl %ebx,%edx
|
||||
movl (%esi),%eax
|
||||
movl 4(%esi),%ebx
|
||||
movl %ecx,(%edi)
|
||||
movl %edx,4(%edi)
|
||||
movl %eax,16(%esp)
|
||||
movl %ebx,20(%esp)
|
||||
addl $8,%esi
|
||||
addl $8,%edi
|
||||
subl $8,%ebp
|
||||
jnz L017decrypt_loop
|
||||
L016decrypt_finish:
|
||||
movl 52(%esp),%ebp
|
||||
andl $7,%ebp
|
||||
jz L005finish
|
||||
movl (%esi),%eax
|
||||
movl 4(%esi),%ebx
|
||||
bswap %eax
|
||||
bswap %ebx
|
||||
movl %eax,8(%esp)
|
||||
movl %ebx,12(%esp)
|
||||
call L_CAST_decrypt_begin
|
||||
movl 8(%esp),%eax
|
||||
movl 12(%esp),%ebx
|
||||
bswap %eax
|
||||
bswap %ebx
|
||||
movl 16(%esp),%ecx
|
||||
movl 20(%esp),%edx
|
||||
xorl %eax,%ecx
|
||||
xorl %ebx,%edx
|
||||
movl (%esi),%eax
|
||||
movl 4(%esi),%ebx
|
||||
L018dj7:
|
||||
rorl $16,%edx
|
||||
movb %dl,6(%edi)
|
||||
shrl $16,%edx
|
||||
L019dj6:
|
||||
movb %dh,5(%edi)
|
||||
L020dj5:
|
||||
movb %dl,4(%edi)
|
||||
L021dj4:
|
||||
movl %ecx,(%edi)
|
||||
jmp L022djend
|
||||
L023dj3:
|
||||
rorl $16,%ecx
|
||||
movb %cl,2(%edi)
|
||||
shll $16,%ecx
|
||||
L024dj2:
|
||||
movb %ch,1(%esi)
|
||||
L025dj1:
|
||||
movb %cl,(%esi)
|
||||
L022djend:
|
||||
jmp L005finish
|
||||
L005finish:
|
||||
movl 60(%esp),%ecx
|
||||
addl $24,%esp
|
||||
movl %eax,(%ecx)
|
||||
movl %ebx,4(%ecx)
|
||||
popl %edi
|
||||
popl %esi
|
||||
popl %ebx
|
||||
popl %ebp
|
||||
ret
|
||||
.align 6,0x90
|
||||
L007cbc_enc_jmp_table:
|
||||
.long 0
|
||||
.long L015ej1-L006PIC_point
|
||||
.long L014ej2-L006PIC_point
|
||||
.long L013ej3-L006PIC_point
|
||||
.long L011ej4-L006PIC_point
|
||||
.long L010ej5-L006PIC_point
|
||||
.long L009ej6-L006PIC_point
|
||||
.long L008ej7-L006PIC_point
|
||||
.align 6,0x90
|
||||
@@ -5,21 +5,21 @@
|
||||
* 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:
|
||||
@@ -34,10 +34,10 @@
|
||||
* 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
|
||||
* 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
|
||||
@@ -49,7 +49,7 @@
|
||||
* 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
|
||||
@@ -57,46 +57,48 @@
|
||||
*/
|
||||
|
||||
#ifndef HEADER_CAST_H
|
||||
#define HEADER_CAST_H
|
||||
# define HEADER_CAST_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
# include <openssl/opensslconf.h>
|
||||
|
||||
#ifdef OPENSSL_NO_CAST
|
||||
#error CAST is disabled.
|
||||
#endif
|
||||
# ifdef OPENSSL_NO_CAST
|
||||
# error CAST is disabled.
|
||||
# endif
|
||||
|
||||
#define CAST_ENCRYPT 1
|
||||
#define CAST_DECRYPT 0
|
||||
# define CAST_ENCRYPT 1
|
||||
# define CAST_DECRYPT 0
|
||||
|
||||
#define CAST_LONG unsigned int
|
||||
# define CAST_LONG unsigned int
|
||||
|
||||
#define CAST_BLOCK 8
|
||||
#define CAST_KEY_LENGTH 16
|
||||
# define CAST_BLOCK 8
|
||||
# define CAST_KEY_LENGTH 16
|
||||
|
||||
typedef struct cast_key_st
|
||||
{
|
||||
CAST_LONG data[32];
|
||||
int short_key; /* Use reduced rounds for short key */
|
||||
} CAST_KEY;
|
||||
typedef struct cast_key_st {
|
||||
CAST_LONG data[32];
|
||||
int short_key; /* Use reduced rounds for short key */
|
||||
} CAST_KEY;
|
||||
|
||||
|
||||
# ifdef OPENSSL_FIPS
|
||||
void private_CAST_set_key(CAST_KEY *key, int len, const unsigned char *data);
|
||||
# endif
|
||||
void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data);
|
||||
void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out, const CAST_KEY *key,
|
||||
int enc);
|
||||
void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out,
|
||||
const CAST_KEY *key, int enc);
|
||||
void CAST_encrypt(CAST_LONG *data, const CAST_KEY *key);
|
||||
void CAST_decrypt(CAST_LONG *data, const CAST_KEY *key);
|
||||
void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
|
||||
const CAST_KEY *ks, unsigned char *iv, int enc);
|
||||
void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, const CAST_KEY *ks, unsigned char *iv,
|
||||
int enc);
|
||||
void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, const CAST_KEY *schedule, unsigned char *ivec,
|
||||
int *num, int enc);
|
||||
void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, const CAST_KEY *schedule, unsigned char *ivec,
|
||||
int *num);
|
||||
long length, const CAST_KEY *schedule,
|
||||
unsigned char *ivec, int *num, int enc);
|
||||
void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, const CAST_KEY *schedule,
|
||||
unsigned char *ivec, int *num);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -5,21 +5,21 @@
|
||||
* 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:
|
||||
@@ -34,10 +34,10 @@
|
||||
* 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
|
||||
* 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
|
||||
@@ -49,96 +49,94 @@
|
||||
* 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 "e_os.h"
|
||||
|
||||
#ifdef OPENSSL_SYS_WIN32
|
||||
#include <stdlib.h>
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
|
||||
|
||||
#undef c2l
|
||||
#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
|
||||
l|=((unsigned long)(*((c)++)))<< 8L, \
|
||||
l|=((unsigned long)(*((c)++)))<<16L, \
|
||||
l|=((unsigned long)(*((c)++)))<<24L)
|
||||
#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
|
||||
l|=((unsigned long)(*((c)++)))<< 8L, \
|
||||
l|=((unsigned long)(*((c)++)))<<16L, \
|
||||
l|=((unsigned long)(*((c)++)))<<24L)
|
||||
|
||||
/* NOTE - c is not incremented as per c2l */
|
||||
#undef c2ln
|
||||
#define c2ln(c,l1,l2,n) { \
|
||||
c+=n; \
|
||||
l1=l2=0; \
|
||||
switch (n) { \
|
||||
case 8: l2 =((unsigned long)(*(--(c))))<<24L; \
|
||||
case 7: l2|=((unsigned long)(*(--(c))))<<16L; \
|
||||
case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \
|
||||
case 5: l2|=((unsigned long)(*(--(c)))); \
|
||||
case 4: l1 =((unsigned long)(*(--(c))))<<24L; \
|
||||
case 3: l1|=((unsigned long)(*(--(c))))<<16L; \
|
||||
case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \
|
||||
case 1: l1|=((unsigned long)(*(--(c)))); \
|
||||
} \
|
||||
}
|
||||
#define c2ln(c,l1,l2,n) { \
|
||||
c+=n; \
|
||||
l1=l2=0; \
|
||||
switch (n) { \
|
||||
case 8: l2 =((unsigned long)(*(--(c))))<<24L; \
|
||||
case 7: l2|=((unsigned long)(*(--(c))))<<16L; \
|
||||
case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \
|
||||
case 5: l2|=((unsigned long)(*(--(c)))); \
|
||||
case 4: l1 =((unsigned long)(*(--(c))))<<24L; \
|
||||
case 3: l1|=((unsigned long)(*(--(c))))<<16L; \
|
||||
case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \
|
||||
case 1: l1|=((unsigned long)(*(--(c)))); \
|
||||
} \
|
||||
}
|
||||
|
||||
#undef l2c
|
||||
#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>>16L)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>>24L)&0xff))
|
||||
#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>>16L)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>>24L)&0xff))
|
||||
|
||||
/* NOTE - c is not incremented as per l2c */
|
||||
#undef l2cn
|
||||
#define l2cn(l1,l2,c,n) { \
|
||||
c+=n; \
|
||||
switch (n) { \
|
||||
case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
|
||||
case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
|
||||
case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
|
||||
case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
|
||||
case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
|
||||
case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
|
||||
case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
|
||||
case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
|
||||
} \
|
||||
}
|
||||
#define l2cn(l1,l2,c,n) { \
|
||||
c+=n; \
|
||||
switch (n) { \
|
||||
case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
|
||||
case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
|
||||
case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
|
||||
case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
|
||||
case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
|
||||
case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
|
||||
case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
|
||||
case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
|
||||
} \
|
||||
}
|
||||
|
||||
/* NOTE - c is not incremented as per n2l */
|
||||
#define n2ln(c,l1,l2,n) { \
|
||||
c+=n; \
|
||||
l1=l2=0; \
|
||||
switch (n) { \
|
||||
case 8: l2 =((unsigned long)(*(--(c)))) ; \
|
||||
case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
|
||||
case 6: l2|=((unsigned long)(*(--(c))))<<16; \
|
||||
case 5: l2|=((unsigned long)(*(--(c))))<<24; \
|
||||
case 4: l1 =((unsigned long)(*(--(c)))) ; \
|
||||
case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
|
||||
case 2: l1|=((unsigned long)(*(--(c))))<<16; \
|
||||
case 1: l1|=((unsigned long)(*(--(c))))<<24; \
|
||||
} \
|
||||
}
|
||||
#define n2ln(c,l1,l2,n) { \
|
||||
c+=n; \
|
||||
l1=l2=0; \
|
||||
switch (n) { \
|
||||
case 8: l2 =((unsigned long)(*(--(c)))) ; \
|
||||
case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
|
||||
case 6: l2|=((unsigned long)(*(--(c))))<<16; \
|
||||
case 5: l2|=((unsigned long)(*(--(c))))<<24; \
|
||||
case 4: l1 =((unsigned long)(*(--(c)))) ; \
|
||||
case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
|
||||
case 2: l1|=((unsigned long)(*(--(c))))<<16; \
|
||||
case 1: l1|=((unsigned long)(*(--(c))))<<24; \
|
||||
} \
|
||||
}
|
||||
|
||||
/* NOTE - c is not incremented as per l2n */
|
||||
#define l2nn(l1,l2,c,n) { \
|
||||
c+=n; \
|
||||
switch (n) { \
|
||||
case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
|
||||
case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
|
||||
case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
|
||||
case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
|
||||
case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
|
||||
case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
|
||||
case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
|
||||
case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
|
||||
} \
|
||||
}
|
||||
#define l2nn(l1,l2,c,n) { \
|
||||
c+=n; \
|
||||
switch (n) { \
|
||||
case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
|
||||
case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
|
||||
case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
|
||||
case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
|
||||
case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
|
||||
case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
|
||||
case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
|
||||
case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
|
||||
} \
|
||||
}
|
||||
|
||||
#undef n2l
|
||||
#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
|
||||
@@ -153,68 +151,70 @@
|
||||
*((c)++)=(unsigned char)(((l) )&0xff))
|
||||
|
||||
#if defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER)
|
||||
#define ROTL(a,n) (_lrotl(a,n))
|
||||
# define ROTL(a,n) (_lrotl(a,n))
|
||||
#elif defined(PEDANTIC)
|
||||
# define ROTL(a,n) ((((a)<<(n))&0xffffffffL)|((a)>>((32-(n))&31)))
|
||||
#else
|
||||
#define ROTL(a,n) ((((a)<<(n))&0xffffffffL)|((a)>>(32-(n))))
|
||||
# define ROTL(a,n) ((((a)<<(n))&0xffffffffL)|((a)>>(32-(n))))
|
||||
#endif
|
||||
|
||||
#define C_M 0x3fc
|
||||
#define C_0 22L
|
||||
#define C_1 14L
|
||||
#define C_2 6L
|
||||
#define C_3 2L /* left shift */
|
||||
#define C_3 2L /* left shift */
|
||||
|
||||
/* The rotate has an extra 16 added to it to help the x86 asm */
|
||||
#if defined(CAST_PTR)
|
||||
#define E_CAST(n,key,L,R,OP1,OP2,OP3) \
|
||||
{ \
|
||||
int i; \
|
||||
t=(key[n*2] OP1 R)&0xffffffffL; \
|
||||
i=key[n*2+1]; \
|
||||
t=ROTL(t,i); \
|
||||
L^= (((((*(CAST_LONG *)((unsigned char *) \
|
||||
CAST_S_table0+((t>>C_2)&C_M)) OP2 \
|
||||
*(CAST_LONG *)((unsigned char *) \
|
||||
CAST_S_table1+((t<<C_3)&C_M)))&0xffffffffL) OP3 \
|
||||
*(CAST_LONG *)((unsigned char *) \
|
||||
CAST_S_table2+((t>>C_0)&C_M)))&0xffffffffL) OP1 \
|
||||
*(CAST_LONG *)((unsigned char *) \
|
||||
CAST_S_table3+((t>>C_1)&C_M)))&0xffffffffL; \
|
||||
}
|
||||
# define E_CAST(n,key,L,R,OP1,OP2,OP3) \
|
||||
{ \
|
||||
int i; \
|
||||
t=(key[n*2] OP1 R)&0xffffffffL; \
|
||||
i=key[n*2+1]; \
|
||||
t=ROTL(t,i); \
|
||||
L^= (((((*(CAST_LONG *)((unsigned char *) \
|
||||
CAST_S_table0+((t>>C_2)&C_M)) OP2 \
|
||||
*(CAST_LONG *)((unsigned char *) \
|
||||
CAST_S_table1+((t<<C_3)&C_M)))&0xffffffffL) OP3 \
|
||||
*(CAST_LONG *)((unsigned char *) \
|
||||
CAST_S_table2+((t>>C_0)&C_M)))&0xffffffffL) OP1 \
|
||||
*(CAST_LONG *)((unsigned char *) \
|
||||
CAST_S_table3+((t>>C_1)&C_M)))&0xffffffffL; \
|
||||
}
|
||||
#elif defined(CAST_PTR2)
|
||||
#define E_CAST(n,key,L,R,OP1,OP2,OP3) \
|
||||
{ \
|
||||
int i; \
|
||||
CAST_LONG u,v,w; \
|
||||
w=(key[n*2] OP1 R)&0xffffffffL; \
|
||||
i=key[n*2+1]; \
|
||||
w=ROTL(w,i); \
|
||||
u=w>>C_2; \
|
||||
v=w<<C_3; \
|
||||
u&=C_M; \
|
||||
v&=C_M; \
|
||||
t= *(CAST_LONG *)((unsigned char *)CAST_S_table0+u); \
|
||||
u=w>>C_0; \
|
||||
t=(t OP2 *(CAST_LONG *)((unsigned char *)CAST_S_table1+v))&0xffffffffL;\
|
||||
v=w>>C_1; \
|
||||
u&=C_M; \
|
||||
v&=C_M; \
|
||||
t=(t OP3 *(CAST_LONG *)((unsigned char *)CAST_S_table2+u)&0xffffffffL);\
|
||||
t=(t OP1 *(CAST_LONG *)((unsigned char *)CAST_S_table3+v)&0xffffffffL);\
|
||||
L^=(t&0xffffffff); \
|
||||
}
|
||||
# define E_CAST(n,key,L,R,OP1,OP2,OP3) \
|
||||
{ \
|
||||
int i; \
|
||||
CAST_LONG u,v,w; \
|
||||
w=(key[n*2] OP1 R)&0xffffffffL; \
|
||||
i=key[n*2+1]; \
|
||||
w=ROTL(w,i); \
|
||||
u=w>>C_2; \
|
||||
v=w<<C_3; \
|
||||
u&=C_M; \
|
||||
v&=C_M; \
|
||||
t= *(CAST_LONG *)((unsigned char *)CAST_S_table0+u); \
|
||||
u=w>>C_0; \
|
||||
t=(t OP2 *(CAST_LONG *)((unsigned char *)CAST_S_table1+v))&0xffffffffL;\
|
||||
v=w>>C_1; \
|
||||
u&=C_M; \
|
||||
v&=C_M; \
|
||||
t=(t OP3 *(CAST_LONG *)((unsigned char *)CAST_S_table2+u)&0xffffffffL);\
|
||||
t=(t OP1 *(CAST_LONG *)((unsigned char *)CAST_S_table3+v)&0xffffffffL);\
|
||||
L^=(t&0xffffffff); \
|
||||
}
|
||||
#else
|
||||
#define E_CAST(n,key,L,R,OP1,OP2,OP3) \
|
||||
{ \
|
||||
CAST_LONG a,b,c,d; \
|
||||
t=(key[n*2] OP1 R)&0xffffffff; \
|
||||
t=ROTL(t,(key[n*2+1])); \
|
||||
a=CAST_S_table0[(t>> 8)&0xff]; \
|
||||
b=CAST_S_table1[(t )&0xff]; \
|
||||
c=CAST_S_table2[(t>>24)&0xff]; \
|
||||
d=CAST_S_table3[(t>>16)&0xff]; \
|
||||
L^=(((((a OP2 b)&0xffffffffL) OP3 c)&0xffffffffL) OP1 d)&0xffffffffL; \
|
||||
}
|
||||
# define E_CAST(n,key,L,R,OP1,OP2,OP3) \
|
||||
{ \
|
||||
CAST_LONG a,b,c,d; \
|
||||
t=(key[n*2] OP1 R)&0xffffffff; \
|
||||
t=ROTL(t,(key[n*2+1])); \
|
||||
a=CAST_S_table0[(t>> 8)&0xff]; \
|
||||
b=CAST_S_table1[(t )&0xff]; \
|
||||
c=CAST_S_table2[(t>>24)&0xff]; \
|
||||
d=CAST_S_table3[(t>>16)&0xff]; \
|
||||
L^=(((((a OP2 b)&0xffffffffL) OP3 c)&0xffffffffL) OP1 d)&0xffffffffL; \
|
||||
}
|
||||
#endif
|
||||
|
||||
extern const CAST_LONG CAST_S_table0[256];
|
||||
|
||||
1075
crypto/cast/cast_s.h
1075
crypto/cast/cast_s.h
File diff suppressed because it is too large
Load Diff
@@ -5,21 +5,21 @@
|
||||
* 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:
|
||||
@@ -34,10 +34,10 @@
|
||||
* 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
|
||||
* 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
|
||||
@@ -49,7 +49,7 @@
|
||||
* 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
|
||||
@@ -60,7 +60,7 @@
|
||||
/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
|
||||
|
||||
#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
|
||||
#define TIMES
|
||||
# define TIMES
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -68,211 +68,195 @@
|
||||
#include <openssl/e_os2.h>
|
||||
#include OPENSSL_UNISTD_IO
|
||||
OPENSSL_DECLARE_EXIT
|
||||
|
||||
#ifndef OPENSSL_SYS_NETWARE
|
||||
#include <signal.h>
|
||||
# include <signal.h>
|
||||
#endif
|
||||
|
||||
#ifndef _IRIX
|
||||
#include <time.h>
|
||||
# include <time.h>
|
||||
#endif
|
||||
#ifdef TIMES
|
||||
#include <sys/types.h>
|
||||
#include <sys/times.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/times.h>
|
||||
#endif
|
||||
|
||||
/* Depending on the VMS version, the tms structure is perhaps defined.
|
||||
The __TMS macro will show if it was. If it wasn't defined, we should
|
||||
undefine TIMES, since that tells the rest of the program how things
|
||||
should be handled. -- Richard Levitte */
|
||||
/*
|
||||
* Depending on the VMS version, the tms structure is perhaps defined.
|
||||
* The __TMS macro will show if it was. If it wasn't defined, we should
|
||||
* undefine TIMES, since that tells the rest of the program how things
|
||||
* should be handled. -- Richard Levitte
|
||||
*/
|
||||
#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
|
||||
#undef TIMES
|
||||
# undef TIMES
|
||||
#endif
|
||||
|
||||
#ifndef TIMES
|
||||
#include <sys/timeb.h>
|
||||
# include <sys/timeb.h>
|
||||
#endif
|
||||
|
||||
#if defined(sun) || defined(__ultrix)
|
||||
#define _POSIX_SOURCE
|
||||
#include <limits.h>
|
||||
#include <sys/param.h>
|
||||
# define _POSIX_SOURCE
|
||||
# include <limits.h>
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#include <openssl/cast.h>
|
||||
|
||||
/* The following if from times(3) man page. It may need to be changed */
|
||||
#ifndef HZ
|
||||
#ifndef CLK_TCK
|
||||
#define HZ 100.0
|
||||
#else /* CLK_TCK */
|
||||
#define HZ ((double)CLK_TCK)
|
||||
# ifndef CLK_TCK
|
||||
# define HZ 100.0
|
||||
# else /* CLK_TCK */
|
||||
# define HZ ((double)CLK_TCK)
|
||||
# endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define BUFSIZE ((long)1024)
|
||||
long run=0;
|
||||
#define BUFSIZE ((long)1024)
|
||||
long run = 0;
|
||||
|
||||
double Time_F(int s);
|
||||
#ifdef SIGALRM
|
||||
#if defined(__STDC__) || defined(sgi) || defined(_AIX)
|
||||
#define SIGRETTYPE void
|
||||
#else
|
||||
#define SIGRETTYPE int
|
||||
#endif
|
||||
# if defined(__STDC__) || defined(sgi) || defined(_AIX)
|
||||
# define SIGRETTYPE void
|
||||
# else
|
||||
# define SIGRETTYPE int
|
||||
# endif
|
||||
|
||||
SIGRETTYPE sig_done(int sig);
|
||||
SIGRETTYPE sig_done(int sig)
|
||||
{
|
||||
signal(SIGALRM,sig_done);
|
||||
run=0;
|
||||
#ifdef LINT
|
||||
sig=sig;
|
||||
#endif
|
||||
}
|
||||
{
|
||||
signal(SIGALRM, sig_done);
|
||||
run = 0;
|
||||
# ifdef LINT
|
||||
sig = sig;
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#define START 0
|
||||
#define STOP 1
|
||||
#define START 0
|
||||
#define STOP 1
|
||||
|
||||
double Time_F(int s)
|
||||
{
|
||||
double ret;
|
||||
{
|
||||
double ret;
|
||||
#ifdef TIMES
|
||||
static struct tms tstart,tend;
|
||||
static struct tms tstart, tend;
|
||||
|
||||
if (s == START)
|
||||
{
|
||||
times(&tstart);
|
||||
return(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
times(&tend);
|
||||
ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
|
||||
return((ret == 0.0)?1e-6:ret);
|
||||
}
|
||||
#else /* !times() */
|
||||
static struct timeb tstart,tend;
|
||||
long i;
|
||||
if (s == START) {
|
||||
times(&tstart);
|
||||
return (0);
|
||||
} else {
|
||||
times(&tend);
|
||||
ret = ((double)(tend.tms_utime - tstart.tms_utime)) / HZ;
|
||||
return ((ret == 0.0) ? 1e-6 : ret);
|
||||
}
|
||||
#else /* !times() */
|
||||
static struct timeb tstart, tend;
|
||||
long i;
|
||||
|
||||
if (s == START)
|
||||
{
|
||||
ftime(&tstart);
|
||||
return(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ftime(&tend);
|
||||
i=(long)tend.millitm-(long)tstart.millitm;
|
||||
ret=((double)(tend.time-tstart.time))+((double)i)/1e3;
|
||||
return((ret == 0.0)?1e-6:ret);
|
||||
}
|
||||
if (s == START) {
|
||||
ftime(&tstart);
|
||||
return (0);
|
||||
} else {
|
||||
ftime(&tend);
|
||||
i = (long)tend.millitm - (long)tstart.millitm;
|
||||
ret = ((double)(tend.time - tstart.time)) + ((double)i) / 1e3;
|
||||
return ((ret == 0.0) ? 1e-6 : ret);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
long count;
|
||||
static unsigned char buf[BUFSIZE];
|
||||
static unsigned char key[] ={
|
||||
0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
|
||||
0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,
|
||||
};
|
||||
CAST_KEY sch;
|
||||
double a,b,c,d;
|
||||
{
|
||||
long count;
|
||||
static unsigned char buf[BUFSIZE];
|
||||
static unsigned char key[] = {
|
||||
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
|
||||
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
|
||||
};
|
||||
CAST_KEY sch;
|
||||
double a, b, c, d;
|
||||
#ifndef SIGALRM
|
||||
long ca,cb,cc;
|
||||
long ca, cb, cc;
|
||||
#endif
|
||||
|
||||
#ifndef TIMES
|
||||
printf("To get the most accurate results, try to run this\n");
|
||||
printf("program when this computer is idle.\n");
|
||||
printf("To get the most accurate results, try to run this\n");
|
||||
printf("program when this computer is idle.\n");
|
||||
#endif
|
||||
|
||||
#ifndef SIGALRM
|
||||
printf("First we calculate the approximate speed ...\n");
|
||||
CAST_set_key(&sch,16,key);
|
||||
count=10;
|
||||
do {
|
||||
long i;
|
||||
CAST_LONG data[2];
|
||||
printf("First we calculate the approximate speed ...\n");
|
||||
CAST_set_key(&sch, 16, key);
|
||||
count = 10;
|
||||
do {
|
||||
long i;
|
||||
CAST_LONG data[2];
|
||||
|
||||
count*=2;
|
||||
Time_F(START);
|
||||
for (i=count; i; i--)
|
||||
CAST_encrypt(data,&sch);
|
||||
d=Time_F(STOP);
|
||||
} while (d < 3.0);
|
||||
ca=count/512;
|
||||
cb=count;
|
||||
cc=count*8/BUFSIZE+1;
|
||||
printf("Doing CAST_set_key %ld times\n",ca);
|
||||
#define COND(d) (count != (d))
|
||||
#define COUNT(d) (d)
|
||||
count *= 2;
|
||||
Time_F(START);
|
||||
for (i = count; i; i--)
|
||||
CAST_encrypt(data, &sch);
|
||||
d = Time_F(STOP);
|
||||
} while (d < 3.0);
|
||||
ca = count / 512;
|
||||
cb = count;
|
||||
cc = count * 8 / BUFSIZE + 1;
|
||||
printf("Doing CAST_set_key %ld times\n", ca);
|
||||
# define COND(d) (count != (d))
|
||||
# define COUNT(d) (d)
|
||||
#else
|
||||
#define COND(c) (run)
|
||||
#define COUNT(d) (count)
|
||||
signal(SIGALRM,sig_done);
|
||||
printf("Doing CAST_set_key for 10 seconds\n");
|
||||
alarm(10);
|
||||
# define COND(c) (run)
|
||||
# define COUNT(d) (count)
|
||||
signal(SIGALRM, sig_done);
|
||||
printf("Doing CAST_set_key for 10 seconds\n");
|
||||
alarm(10);
|
||||
#endif
|
||||
|
||||
Time_F(START);
|
||||
for (count=0,run=1; COND(ca); count+=4)
|
||||
{
|
||||
CAST_set_key(&sch,16,key);
|
||||
CAST_set_key(&sch,16,key);
|
||||
CAST_set_key(&sch,16,key);
|
||||
CAST_set_key(&sch,16,key);
|
||||
}
|
||||
d=Time_F(STOP);
|
||||
printf("%ld cast set_key's in %.2f seconds\n",count,d);
|
||||
a=((double)COUNT(ca))/d;
|
||||
Time_F(START);
|
||||
for (count = 0, run = 1; COND(ca); count += 4) {
|
||||
CAST_set_key(&sch, 16, key);
|
||||
CAST_set_key(&sch, 16, key);
|
||||
CAST_set_key(&sch, 16, key);
|
||||
CAST_set_key(&sch, 16, key);
|
||||
}
|
||||
d = Time_F(STOP);
|
||||
printf("%ld cast set_key's in %.2f seconds\n", count, d);
|
||||
a = ((double)COUNT(ca)) / d;
|
||||
|
||||
#ifdef SIGALRM
|
||||
printf("Doing CAST_encrypt's for 10 seconds\n");
|
||||
alarm(10);
|
||||
printf("Doing CAST_encrypt's for 10 seconds\n");
|
||||
alarm(10);
|
||||
#else
|
||||
printf("Doing CAST_encrypt %ld times\n",cb);
|
||||
printf("Doing CAST_encrypt %ld times\n", cb);
|
||||
#endif
|
||||
Time_F(START);
|
||||
for (count=0,run=1; COND(cb); count+=4)
|
||||
{
|
||||
CAST_LONG data[2];
|
||||
Time_F(START);
|
||||
for (count = 0, run = 1; COND(cb); count += 4) {
|
||||
CAST_LONG data[2];
|
||||
|
||||
CAST_encrypt(data,&sch);
|
||||
CAST_encrypt(data,&sch);
|
||||
CAST_encrypt(data,&sch);
|
||||
CAST_encrypt(data,&sch);
|
||||
}
|
||||
d=Time_F(STOP);
|
||||
printf("%ld CAST_encrypt's in %.2f second\n",count,d);
|
||||
b=((double)COUNT(cb)*8)/d;
|
||||
CAST_encrypt(data, &sch);
|
||||
CAST_encrypt(data, &sch);
|
||||
CAST_encrypt(data, &sch);
|
||||
CAST_encrypt(data, &sch);
|
||||
}
|
||||
d = Time_F(STOP);
|
||||
printf("%ld CAST_encrypt's in %.2f second\n", count, d);
|
||||
b = ((double)COUNT(cb) * 8) / d;
|
||||
|
||||
#ifdef SIGALRM
|
||||
printf("Doing CAST_cbc_encrypt on %ld byte blocks for 10 seconds\n",
|
||||
BUFSIZE);
|
||||
alarm(10);
|
||||
printf("Doing CAST_cbc_encrypt on %ld byte blocks for 10 seconds\n",
|
||||
BUFSIZE);
|
||||
alarm(10);
|
||||
#else
|
||||
printf("Doing CAST_cbc_encrypt %ld times on %ld byte blocks\n",cc,
|
||||
BUFSIZE);
|
||||
printf("Doing CAST_cbc_encrypt %ld times on %ld byte blocks\n", cc,
|
||||
BUFSIZE);
|
||||
#endif
|
||||
Time_F(START);
|
||||
for (count=0,run=1; COND(cc); count++)
|
||||
CAST_cbc_encrypt(buf,buf,BUFSIZE,&sch,
|
||||
&(key[0]),CAST_ENCRYPT);
|
||||
d=Time_F(STOP);
|
||||
printf("%ld CAST_cbc_encrypt's of %ld byte blocks in %.2f second\n",
|
||||
count,BUFSIZE,d);
|
||||
c=((double)COUNT(cc)*BUFSIZE)/d;
|
||||
Time_F(START);
|
||||
for (count = 0, run = 1; COND(cc); count++)
|
||||
CAST_cbc_encrypt(buf, buf, BUFSIZE, &sch, &(key[0]), CAST_ENCRYPT);
|
||||
d = Time_F(STOP);
|
||||
printf("%ld CAST_cbc_encrypt's of %ld byte blocks in %.2f second\n",
|
||||
count, BUFSIZE, d);
|
||||
c = ((double)COUNT(cc) * BUFSIZE) / d;
|
||||
|
||||
printf("CAST set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a);
|
||||
printf("CAST raw ecb bytes per sec = %12.2f (%9.3fuS)\n",b,8.0e6/b);
|
||||
printf("CAST cbc bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c);
|
||||
exit(0);
|
||||
printf("CAST set_key per sec = %12.2f (%9.3fuS)\n", a, 1.0e6 / a);
|
||||
printf("CAST raw ecb bytes per sec = %12.2f (%9.3fuS)\n", b, 8.0e6 / b);
|
||||
printf("CAST cbc bytes per sec = %12.2f (%9.3fuS)\n", c, 8.0e6 / c);
|
||||
exit(0);
|
||||
#if defined(LINT) || defined(OPENSSL_SYS_MSDOS)
|
||||
return(0);
|
||||
return (0);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,21 +5,21 @@
|
||||
* 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:
|
||||
@@ -34,10 +34,10 @@
|
||||
* 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
|
||||
* 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
|
||||
@@ -49,18 +49,20 @@
|
||||
* 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.]
|
||||
*/
|
||||
|
||||
/* define PART1, PART2, PART3 or PART4 to build only with a few of the options.
|
||||
* This is for machines with 64k code segment size restrictions. */
|
||||
/*
|
||||
* define PART1, PART2, PART3 or PART4 to build only with a few of the
|
||||
* options. This is for machines with 64k code segment size restrictions.
|
||||
*/
|
||||
|
||||
#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC))
|
||||
#define TIMES
|
||||
# define TIMES
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -68,48 +70,41 @@
|
||||
#include <openssl/e_os2.h>
|
||||
#include OPENSSL_UNISTD_IO
|
||||
OPENSSL_DECLARE_EXIT
|
||||
|
||||
#ifndef OPENSSL_SYS_NETWARE
|
||||
#include <signal.h>
|
||||
# include <signal.h>
|
||||
#endif
|
||||
|
||||
#ifndef _IRIX
|
||||
#include <time.h>
|
||||
# include <time.h>
|
||||
#endif
|
||||
#ifdef TIMES
|
||||
#include <sys/types.h>
|
||||
#include <sys/times.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/times.h>
|
||||
#endif
|
||||
|
||||
/* Depending on the VMS version, the tms structure is perhaps defined.
|
||||
The __TMS macro will show if it was. If it wasn't defined, we should
|
||||
undefine TIMES, since that tells the rest of the program how things
|
||||
should be handled. -- Richard Levitte */
|
||||
/*
|
||||
* Depending on the VMS version, the tms structure is perhaps defined.
|
||||
* The __TMS macro will show if it was. If it wasn't defined, we should
|
||||
* undefine TIMES, since that tells the rest of the program how things
|
||||
* should be handled. -- Richard Levitte
|
||||
*/
|
||||
#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
|
||||
#undef TIMES
|
||||
# undef TIMES
|
||||
#endif
|
||||
|
||||
#ifndef TIMES
|
||||
#include <sys/timeb.h>
|
||||
# include <sys/timeb.h>
|
||||
#endif
|
||||
|
||||
#if defined(sun) || defined(__ultrix)
|
||||
#define _POSIX_SOURCE
|
||||
#include <limits.h>
|
||||
#include <sys/param.h>
|
||||
# define _POSIX_SOURCE
|
||||
# include <limits.h>
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#include <openssl/cast.h>
|
||||
|
||||
#define CAST_DEFAULT_OPTIONS
|
||||
|
||||
#undef E_CAST
|
||||
#define CAST_encrypt CAST_encrypt_normal
|
||||
#define CAST_decrypt CAST_decrypt_normal
|
||||
#define CAST_cbc_encrypt CAST_cbc_encrypt_normal
|
||||
#undef HEADER_CAST_LOCL_H
|
||||
#include "c_enc.c"
|
||||
|
||||
#define CAST_PTR
|
||||
#undef CAST_PTR2
|
||||
#undef E_CAST
|
||||
@@ -121,7 +116,6 @@ OPENSSL_DECLARE_EXIT
|
||||
#define CAST_cbc_encrypt CAST_cbc_encrypt_ptr
|
||||
#undef HEADER_CAST_LOCL_H
|
||||
#include "c_enc.c"
|
||||
|
||||
#undef CAST_PTR
|
||||
#define CAST_PTR2
|
||||
#undef E_CAST
|
||||
@@ -133,210 +127,208 @@ OPENSSL_DECLARE_EXIT
|
||||
#define CAST_cbc_encrypt CAST_cbc_encrypt_ptr2
|
||||
#undef HEADER_CAST_LOCL_H
|
||||
#include "c_enc.c"
|
||||
|
||||
/* The following if from times(3) man page. It may need to be changed */
|
||||
#ifndef HZ
|
||||
# ifndef CLK_TCK
|
||||
# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
|
||||
# define HZ 100.0
|
||||
# else /* _BSD_CLK_TCK_ */
|
||||
# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
|
||||
# define HZ 100.0
|
||||
# else /* _BSD_CLK_TCK_ */
|
||||
# define HZ ((double)_BSD_CLK_TCK_)
|
||||
# endif
|
||||
# else /* CLK_TCK */
|
||||
# else /* CLK_TCK */
|
||||
# define HZ ((double)CLK_TCK)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define BUFSIZE ((long)1024)
|
||||
long run=0;
|
||||
#define BUFSIZE ((long)1024)
|
||||
long run = 0;
|
||||
|
||||
double Time_F(int s);
|
||||
#ifdef SIGALRM
|
||||
#if defined(__STDC__) || defined(sgi)
|
||||
#define SIGRETTYPE void
|
||||
#else
|
||||
#define SIGRETTYPE int
|
||||
#endif
|
||||
# if defined(__STDC__) || defined(sgi)
|
||||
# define SIGRETTYPE void
|
||||
# else
|
||||
# define SIGRETTYPE int
|
||||
# endif
|
||||
|
||||
SIGRETTYPE sig_done(int sig);
|
||||
SIGRETTYPE sig_done(int sig)
|
||||
{
|
||||
signal(SIGALRM,sig_done);
|
||||
run=0;
|
||||
#ifdef LINT
|
||||
sig=sig;
|
||||
#endif
|
||||
}
|
||||
{
|
||||
signal(SIGALRM, sig_done);
|
||||
run = 0;
|
||||
# ifdef LINT
|
||||
sig = sig;
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#define START 0
|
||||
#define STOP 1
|
||||
#define START 0
|
||||
#define STOP 1
|
||||
|
||||
double Time_F(int s)
|
||||
{
|
||||
double ret;
|
||||
{
|
||||
double ret;
|
||||
#ifdef TIMES
|
||||
static struct tms tstart,tend;
|
||||
static struct tms tstart, tend;
|
||||
|
||||
if (s == START)
|
||||
{
|
||||
times(&tstart);
|
||||
return(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
times(&tend);
|
||||
ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
|
||||
return((ret == 0.0)?1e-6:ret);
|
||||
}
|
||||
#else /* !times() */
|
||||
static struct timeb tstart,tend;
|
||||
long i;
|
||||
if (s == START) {
|
||||
times(&tstart);
|
||||
return (0);
|
||||
} else {
|
||||
times(&tend);
|
||||
ret = ((double)(tend.tms_utime - tstart.tms_utime)) / HZ;
|
||||
return ((ret == 0.0) ? 1e-6 : ret);
|
||||
}
|
||||
#else /* !times() */
|
||||
static struct timeb tstart, tend;
|
||||
long i;
|
||||
|
||||
if (s == START)
|
||||
{
|
||||
ftime(&tstart);
|
||||
return(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
ftime(&tend);
|
||||
i=(long)tend.millitm-(long)tstart.millitm;
|
||||
ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
|
||||
return((ret == 0.0)?1e-6:ret);
|
||||
}
|
||||
if (s == START) {
|
||||
ftime(&tstart);
|
||||
return (0);
|
||||
} else {
|
||||
ftime(&tend);
|
||||
i = (long)tend.millitm - (long)tstart.millitm;
|
||||
ret = ((double)(tend.time - tstart.time)) + ((double)i) / 1000.0;
|
||||
return ((ret == 0.0) ? 1e-6 : ret);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SIGALRM
|
||||
#define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10);
|
||||
# define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10);
|
||||
#else
|
||||
#define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb);
|
||||
# define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb);
|
||||
#endif
|
||||
|
||||
|
||||
#define time_it(func,name,index) \
|
||||
print_name(name); \
|
||||
Time_F(START); \
|
||||
for (count=0,run=1; COND(cb); count+=4) \
|
||||
{ \
|
||||
unsigned long d[2]; \
|
||||
func(d,&sch); \
|
||||
func(d,&sch); \
|
||||
func(d,&sch); \
|
||||
func(d,&sch); \
|
||||
} \
|
||||
tm[index]=Time_F(STOP); \
|
||||
fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \
|
||||
tm[index]=((double)COUNT(cb))/tm[index];
|
||||
print_name(name); \
|
||||
Time_F(START); \
|
||||
for (count=0,run=1; COND(cb); count+=4) \
|
||||
{ \
|
||||
unsigned long d[2]; \
|
||||
func(d,&sch); \
|
||||
func(d,&sch); \
|
||||
func(d,&sch); \
|
||||
func(d,&sch); \
|
||||
} \
|
||||
tm[index]=Time_F(STOP); \
|
||||
fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \
|
||||
tm[index]=((double)COUNT(cb))/tm[index];
|
||||
|
||||
#define print_it(name,index) \
|
||||
fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \
|
||||
tm[index]*8,1.0e6/tm[index]);
|
||||
fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \
|
||||
tm[index]*8,1.0e6/tm[index]);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
long count;
|
||||
static unsigned char buf[BUFSIZE];
|
||||
static char key[16]={ 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
|
||||
0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
|
||||
CAST_KEY sch;
|
||||
double d,tm[16],max=0;
|
||||
int rank[16];
|
||||
char *str[16];
|
||||
int max_idx=0,i,num=0,j;
|
||||
{
|
||||
long count;
|
||||
static unsigned char buf[BUFSIZE];
|
||||
static char key[16] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
|
||||
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0
|
||||
};
|
||||
CAST_KEY sch;
|
||||
double d, tm[16], max = 0;
|
||||
int rank[16];
|
||||
char *str[16];
|
||||
int max_idx = 0, i, num = 0, j;
|
||||
#ifndef SIGALARM
|
||||
long ca,cb,cc,cd,ce;
|
||||
long ca, cb, cc, cd, ce;
|
||||
#endif
|
||||
|
||||
for (i=0; i<12; i++)
|
||||
{
|
||||
tm[i]=0.0;
|
||||
rank[i]=0;
|
||||
}
|
||||
for (i = 0; i < 12; i++) {
|
||||
tm[i] = 0.0;
|
||||
rank[i] = 0;
|
||||
}
|
||||
|
||||
#ifndef TIMES
|
||||
fprintf(stderr,"To get the most accurate results, try to run this\n");
|
||||
fprintf(stderr,"program when this computer is idle.\n");
|
||||
fprintf(stderr, "To get the most accurate results, try to run this\n");
|
||||
fprintf(stderr, "program when this computer is idle.\n");
|
||||
#endif
|
||||
|
||||
CAST_set_key(&sch,16,key);
|
||||
CAST_set_key(&sch, 16, key);
|
||||
|
||||
#ifndef SIGALRM
|
||||
fprintf(stderr,"First we calculate the approximate speed ...\n");
|
||||
count=10;
|
||||
do {
|
||||
long i;
|
||||
unsigned long data[2];
|
||||
fprintf(stderr, "First we calculate the approximate speed ...\n");
|
||||
count = 10;
|
||||
do {
|
||||
long i;
|
||||
unsigned long data[2];
|
||||
|
||||
count*=2;
|
||||
Time_F(START);
|
||||
for (i=count; i; i--)
|
||||
CAST_encrypt(data,&sch);
|
||||
d=Time_F(STOP);
|
||||
} while (d < 3.0);
|
||||
ca=count;
|
||||
cb=count*3;
|
||||
cc=count*3*8/BUFSIZE+1;
|
||||
cd=count*8/BUFSIZE+1;
|
||||
count *= 2;
|
||||
Time_F(START);
|
||||
for (i = count; i; i--)
|
||||
CAST_encrypt(data, &sch);
|
||||
d = Time_F(STOP);
|
||||
} while (d < 3.0);
|
||||
ca = count;
|
||||
cb = count * 3;
|
||||
cc = count * 3 * 8 / BUFSIZE + 1;
|
||||
cd = count * 8 / BUFSIZE + 1;
|
||||
|
||||
ce=count/20+1;
|
||||
#define COND(d) (count != (d))
|
||||
#define COUNT(d) (d)
|
||||
ce = count / 20 + 1;
|
||||
# define COND(d) (count != (d))
|
||||
# define COUNT(d) (d)
|
||||
#else
|
||||
#define COND(c) (run)
|
||||
#define COUNT(d) (count)
|
||||
signal(SIGALRM,sig_done);
|
||||
alarm(10);
|
||||
# define COND(c) (run)
|
||||
# define COUNT(d) (count)
|
||||
signal(SIGALRM, sig_done);
|
||||
alarm(10);
|
||||
#endif
|
||||
|
||||
time_it(CAST_encrypt_normal, "CAST_encrypt_normal ", 0);
|
||||
time_it(CAST_encrypt_ptr, "CAST_encrypt_ptr ", 1);
|
||||
time_it(CAST_encrypt_ptr2, "CAST_encrypt_ptr2 ", 2);
|
||||
num+=3;
|
||||
time_it(CAST_encrypt_normal, "CAST_encrypt_normal ", 0);
|
||||
time_it(CAST_encrypt_ptr, "CAST_encrypt_ptr ", 1);
|
||||
time_it(CAST_encrypt_ptr2, "CAST_encrypt_ptr2 ", 2);
|
||||
num += 3;
|
||||
|
||||
str[0]="<nothing>";
|
||||
print_it("CAST_encrypt_normal ",0);
|
||||
max=tm[0];
|
||||
max_idx=0;
|
||||
str[1]="ptr ";
|
||||
print_it("CAST_encrypt_ptr ",1);
|
||||
if (max < tm[1]) { max=tm[1]; max_idx=1; }
|
||||
str[2]="ptr2 ";
|
||||
print_it("CAST_encrypt_ptr2 ",2);
|
||||
if (max < tm[2]) { max=tm[2]; max_idx=2; }
|
||||
str[0] = "<nothing>";
|
||||
print_it("CAST_encrypt_normal ", 0);
|
||||
max = tm[0];
|
||||
max_idx = 0;
|
||||
str[1] = "ptr ";
|
||||
print_it("CAST_encrypt_ptr ", 1);
|
||||
if (max < tm[1]) {
|
||||
max = tm[1];
|
||||
max_idx = 1;
|
||||
}
|
||||
str[2] = "ptr2 ";
|
||||
print_it("CAST_encrypt_ptr2 ", 2);
|
||||
if (max < tm[2]) {
|
||||
max = tm[2];
|
||||
max_idx = 2;
|
||||
}
|
||||
|
||||
printf("options CAST ecb/s\n");
|
||||
printf("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]);
|
||||
d=tm[max_idx];
|
||||
tm[max_idx]= -2.0;
|
||||
max= -1.0;
|
||||
for (;;)
|
||||
{
|
||||
for (i=0; i<3; i++)
|
||||
{
|
||||
if (max < tm[i]) { max=tm[i]; j=i; }
|
||||
}
|
||||
if (max < 0.0) break;
|
||||
printf("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0);
|
||||
tm[j]= -2.0;
|
||||
max= -1.0;
|
||||
}
|
||||
printf("options CAST ecb/s\n");
|
||||
printf("%s %12.2f 100.0%%\n", str[max_idx], tm[max_idx]);
|
||||
d = tm[max_idx];
|
||||
tm[max_idx] = -2.0;
|
||||
max = -1.0;
|
||||
for (;;) {
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (max < tm[i]) {
|
||||
max = tm[i];
|
||||
j = i;
|
||||
}
|
||||
}
|
||||
if (max < 0.0)
|
||||
break;
|
||||
printf("%s %12.2f %4.1f%%\n", str[j], tm[j], tm[j] / d * 100.0);
|
||||
tm[j] = -2.0;
|
||||
max = -1.0;
|
||||
}
|
||||
|
||||
switch (max_idx)
|
||||
{
|
||||
case 0:
|
||||
printf("-DCAST_DEFAULT_OPTIONS\n");
|
||||
break;
|
||||
case 1:
|
||||
printf("-DCAST_PTR\n");
|
||||
break;
|
||||
case 2:
|
||||
printf("-DCAST_PTR2\n");
|
||||
break;
|
||||
}
|
||||
exit(0);
|
||||
switch (max_idx) {
|
||||
case 0:
|
||||
printf("-DCAST_DEFAULT_OPTIONS\n");
|
||||
break;
|
||||
case 1:
|
||||
printf("-DCAST_PTR\n");
|
||||
break;
|
||||
case 2:
|
||||
printf("-DCAST_PTR2\n");
|
||||
break;
|
||||
}
|
||||
exit(0);
|
||||
#if defined(LINT) || defined(OPENSSL_SYS_MSDOS)
|
||||
return(0);
|
||||
return (0);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,21 +5,21 @@
|
||||
* 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:
|
||||
@@ -34,10 +34,10 @@
|
||||
* 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
|
||||
* 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
|
||||
@@ -49,7 +49,7 @@
|
||||
* 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
|
||||
@@ -67,167 +67,175 @@
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("No CAST support\n");
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
#include <openssl/cast.h>
|
||||
# include <openssl/cast.h>
|
||||
|
||||
#define FULL_TEST
|
||||
# define FULL_TEST
|
||||
|
||||
static unsigned char k[16]={
|
||||
0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
|
||||
0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A
|
||||
};
|
||||
static unsigned char k[16] = {
|
||||
0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78,
|
||||
0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9A
|
||||
};
|
||||
|
||||
static unsigned char in[8]={ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
|
||||
static unsigned char in[8] =
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
|
||||
|
||||
static int k_len[3] = { 16, 10, 5 };
|
||||
|
||||
static unsigned char c[3][8] = {
|
||||
{0x23, 0x8B, 0x4F, 0xE5, 0x84, 0x7E, 0x44, 0xB2},
|
||||
{0xEB, 0x6A, 0x71, 0x1A, 0x2C, 0x02, 0x27, 0x1B},
|
||||
{0x7A, 0xC8, 0x16, 0xD1, 0x6E, 0x9B, 0x30, 0x2E},
|
||||
};
|
||||
|
||||
static int k_len[3]={16,10,5};
|
||||
static unsigned char c[3][8]={
|
||||
{0x23,0x8B,0x4F,0xE5,0x84,0x7E,0x44,0xB2},
|
||||
{0xEB,0x6A,0x71,0x1A,0x2C,0x02,0x27,0x1B},
|
||||
{0x7A,0xC8,0x16,0xD1,0x6E,0x9B,0x30,0x2E},
|
||||
};
|
||||
static unsigned char out[80];
|
||||
|
||||
static unsigned char in_a[16]={
|
||||
0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
|
||||
0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A};
|
||||
static unsigned char in_b[16]={
|
||||
0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
|
||||
0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A};
|
||||
static unsigned char in_a[16] = {
|
||||
0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78,
|
||||
0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9A
|
||||
};
|
||||
|
||||
static unsigned char c_a[16]={
|
||||
0xEE,0xA9,0xD0,0xA2,0x49,0xFD,0x3B,0xA6,
|
||||
0xB3,0x43,0x6F,0xB8,0x9D,0x6D,0xCA,0x92};
|
||||
static unsigned char c_b[16]={
|
||||
0xB2,0xC9,0x5E,0xB0,0x0C,0x31,0xAD,0x71,
|
||||
0x80,0xAC,0x05,0xB8,0xE8,0x3D,0x69,0x6E};
|
||||
static unsigned char in_b[16] = {
|
||||
0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78,
|
||||
0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9A
|
||||
};
|
||||
|
||||
#if 0
|
||||
char *text="Hello to all people out there";
|
||||
static unsigned char c_a[16] = {
|
||||
0xEE, 0xA9, 0xD0, 0xA2, 0x49, 0xFD, 0x3B, 0xA6,
|
||||
0xB3, 0x43, 0x6F, 0xB8, 0x9D, 0x6D, 0xCA, 0x92
|
||||
};
|
||||
|
||||
static unsigned char cfb_key[16]={
|
||||
0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96,
|
||||
0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e,
|
||||
};
|
||||
static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd};
|
||||
static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8];
|
||||
#define CFB_TEST_SIZE 24
|
||||
static unsigned char plain[CFB_TEST_SIZE]=
|
||||
{
|
||||
0x4e,0x6f,0x77,0x20,0x69,0x73,
|
||||
0x20,0x74,0x68,0x65,0x20,0x74,
|
||||
0x69,0x6d,0x65,0x20,0x66,0x6f,
|
||||
0x72,0x20,0x61,0x6c,0x6c,0x20
|
||||
};
|
||||
static unsigned char cfb_cipher64[CFB_TEST_SIZE]={
|
||||
0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F,
|
||||
0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A,
|
||||
0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45
|
||||
static unsigned char c_b[16] = {
|
||||
0xB2, 0xC9, 0x5E, 0xB0, 0x0C, 0x31, 0xAD, 0x71,
|
||||
0x80, 0xAC, 0x05, 0xB8, 0xE8, 0x3D, 0x69, 0x6E
|
||||
};
|
||||
|
||||
/* 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38,
|
||||
0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9,
|
||||
0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/
|
||||
};
|
||||
#endif
|
||||
# if 0
|
||||
char *text = "Hello to all people out there";
|
||||
|
||||
static unsigned char cfb_key[16] = {
|
||||
0xe1, 0xf0, 0xc3, 0xd2, 0xa5, 0xb4, 0x87, 0x96,
|
||||
0x69, 0x78, 0x4b, 0x5a, 0x2d, 0x3c, 0x0f, 0x1e,
|
||||
};
|
||||
static unsigned char cfb_iv[80] =
|
||||
{ 0x34, 0x12, 0x78, 0x56, 0xab, 0x90, 0xef, 0xcd };
|
||||
static unsigned char cfb_buf1[40], cfb_buf2[40], cfb_tmp[8];
|
||||
# define CFB_TEST_SIZE 24
|
||||
static unsigned char plain[CFB_TEST_SIZE] = {
|
||||
0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73,
|
||||
0x20, 0x74, 0x68, 0x65, 0x20, 0x74,
|
||||
0x69, 0x6d, 0x65, 0x20, 0x66, 0x6f,
|
||||
0x72, 0x20, 0x61, 0x6c, 0x6c, 0x20
|
||||
};
|
||||
|
||||
static unsigned char cfb_cipher64[CFB_TEST_SIZE] = {
|
||||
0x59, 0xD8, 0xE2, 0x65, 0x00, 0x58, 0x6C, 0x3F,
|
||||
0x2C, 0x17, 0x25, 0xD0, 0x1A, 0x38, 0xB7, 0x2A,
|
||||
0x39, 0x61, 0x37, 0xDC, 0x79, 0xFB, 0x9F, 0x45
|
||||
/*- 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38,
|
||||
0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9,
|
||||
0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/
|
||||
};
|
||||
# endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#ifdef FULL_TEST
|
||||
{
|
||||
# ifdef FULL_TEST
|
||||
long l;
|
||||
CAST_KEY key_b;
|
||||
#endif
|
||||
int i,z,err=0;
|
||||
# endif
|
||||
int i, z, err = 0;
|
||||
CAST_KEY key;
|
||||
|
||||
for (z=0; z<3; z++)
|
||||
{
|
||||
CAST_set_key(&key,k_len[z],k);
|
||||
for (z = 0; z < 3; z++) {
|
||||
CAST_set_key(&key, k_len[z], k);
|
||||
|
||||
CAST_ecb_encrypt(in,out,&key,CAST_ENCRYPT);
|
||||
if (memcmp(out,&(c[z][0]),8) != 0)
|
||||
{
|
||||
printf("ecb cast error encrypting for keysize %d\n",k_len[z]*8);
|
||||
printf("got :");
|
||||
for (i=0; i<8; i++)
|
||||
printf("%02X ",out[i]);
|
||||
printf("\n");
|
||||
printf("expected:");
|
||||
for (i=0; i<8; i++)
|
||||
printf("%02X ",c[z][i]);
|
||||
err=20;
|
||||
printf("\n");
|
||||
}
|
||||
CAST_ecb_encrypt(in, out, &key, CAST_ENCRYPT);
|
||||
if (memcmp(out, &(c[z][0]), 8) != 0) {
|
||||
printf("ecb cast error encrypting for keysize %d\n",
|
||||
k_len[z] * 8);
|
||||
printf("got :");
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%02X ", out[i]);
|
||||
printf("\n");
|
||||
printf("expected:");
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%02X ", c[z][i]);
|
||||
err = 20;
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
CAST_ecb_encrypt(out,out,&key,CAST_DECRYPT);
|
||||
if (memcmp(out,in,8) != 0)
|
||||
{
|
||||
printf("ecb cast error decrypting for keysize %d\n",k_len[z]*8);
|
||||
printf("got :");
|
||||
for (i=0; i<8; i++)
|
||||
printf("%02X ",out[i]);
|
||||
printf("\n");
|
||||
printf("expected:");
|
||||
for (i=0; i<8; i++)
|
||||
printf("%02X ",in[i]);
|
||||
printf("\n");
|
||||
err=3;
|
||||
}
|
||||
}
|
||||
CAST_ecb_encrypt(out, out, &key, CAST_DECRYPT);
|
||||
if (memcmp(out, in, 8) != 0) {
|
||||
printf("ecb cast error decrypting for keysize %d\n",
|
||||
k_len[z] * 8);
|
||||
printf("got :");
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%02X ", out[i]);
|
||||
printf("\n");
|
||||
printf("expected:");
|
||||
for (i = 0; i < 8; i++)
|
||||
printf("%02X ", in[i]);
|
||||
printf("\n");
|
||||
err = 3;
|
||||
}
|
||||
}
|
||||
if (err == 0)
|
||||
printf("ecb cast5 ok\n");
|
||||
printf("ecb cast5 ok\n");
|
||||
|
||||
#ifdef FULL_TEST
|
||||
{
|
||||
unsigned char out_a[16],out_b[16];
|
||||
static char *hex="0123456789ABCDEF";
|
||||
|
||||
printf("This test will take some time....");
|
||||
fflush(stdout);
|
||||
memcpy(out_a,in_a,sizeof(in_a));
|
||||
memcpy(out_b,in_b,sizeof(in_b));
|
||||
i=1;
|
||||
# ifdef FULL_TEST
|
||||
{
|
||||
unsigned char out_a[16], out_b[16];
|
||||
static char *hex = "0123456789ABCDEF";
|
||||
|
||||
for (l=0; l<1000000L; l++)
|
||||
{
|
||||
CAST_set_key(&key_b,16,out_b);
|
||||
CAST_ecb_encrypt(&(out_a[0]),&(out_a[0]),&key_b,CAST_ENCRYPT);
|
||||
CAST_ecb_encrypt(&(out_a[8]),&(out_a[8]),&key_b,CAST_ENCRYPT);
|
||||
CAST_set_key(&key,16,out_a);
|
||||
CAST_ecb_encrypt(&(out_b[0]),&(out_b[0]),&key,CAST_ENCRYPT);
|
||||
CAST_ecb_encrypt(&(out_b[8]),&(out_b[8]),&key,CAST_ENCRYPT);
|
||||
if ((l & 0xffff) == 0xffff)
|
||||
{
|
||||
printf("%c",hex[i&0x0f]);
|
||||
fflush(stdout);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
printf("This test will take some time....");
|
||||
fflush(stdout);
|
||||
memcpy(out_a, in_a, sizeof(in_a));
|
||||
memcpy(out_b, in_b, sizeof(in_b));
|
||||
i = 1;
|
||||
|
||||
if ( (memcmp(out_a,c_a,sizeof(c_a)) != 0) ||
|
||||
(memcmp(out_b,c_b,sizeof(c_b)) != 0))
|
||||
{
|
||||
printf("\n");
|
||||
printf("Error\n");
|
||||
for (l = 0; l < 1000000L; l++) {
|
||||
CAST_set_key(&key_b, 16, out_b);
|
||||
CAST_ecb_encrypt(&(out_a[0]), &(out_a[0]), &key_b, CAST_ENCRYPT);
|
||||
CAST_ecb_encrypt(&(out_a[8]), &(out_a[8]), &key_b, CAST_ENCRYPT);
|
||||
CAST_set_key(&key, 16, out_a);
|
||||
CAST_ecb_encrypt(&(out_b[0]), &(out_b[0]), &key, CAST_ENCRYPT);
|
||||
CAST_ecb_encrypt(&(out_b[8]), &(out_b[8]), &key, CAST_ENCRYPT);
|
||||
if ((l & 0xffff) == 0xffff) {
|
||||
printf("%c", hex[i & 0x0f]);
|
||||
fflush(stdout);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
printf("A out =");
|
||||
for (i=0; i<16; i++) printf("%02X ",out_a[i]);
|
||||
printf("\nactual=");
|
||||
for (i=0; i<16; i++) printf("%02X ",c_a[i]);
|
||||
printf("\n");
|
||||
if ((memcmp(out_a, c_a, sizeof(c_a)) != 0) ||
|
||||
(memcmp(out_b, c_b, sizeof(c_b)) != 0)) {
|
||||
printf("\n");
|
||||
printf("Error\n");
|
||||
|
||||
printf("B out =");
|
||||
for (i=0; i<16; i++) printf("%02X ",out_b[i]);
|
||||
printf("\nactual=");
|
||||
for (i=0; i<16; i++) printf("%02X ",c_b[i]);
|
||||
printf("\n");
|
||||
}
|
||||
else
|
||||
printf(" ok\n");
|
||||
}
|
||||
#endif
|
||||
printf("A out =");
|
||||
for (i = 0; i < 16; i++)
|
||||
printf("%02X ", out_a[i]);
|
||||
printf("\nactual=");
|
||||
for (i = 0; i < 16; i++)
|
||||
printf("%02X ", c_a[i]);
|
||||
printf("\n");
|
||||
|
||||
printf("B out =");
|
||||
for (i = 0; i < 16; i++)
|
||||
printf("%02X ", out_b[i]);
|
||||
printf("\nactual=");
|
||||
for (i = 0; i < 16; i++)
|
||||
printf("%02X ", c_b[i]);
|
||||
printf("\n");
|
||||
} else
|
||||
printf(" ok\n");
|
||||
}
|
||||
# endif
|
||||
|
||||
EXIT(err);
|
||||
return(err);
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user