mirror of
https://github.com/openbsd/src.git
synced 2024-12-22 16:42:56 -08:00
Hit rc2 with the loving mallet of knfmt.
ok tb@
This commit is contained in:
parent
5ebaba9d29
commit
aa1fb01650
@ -1,25 +1,25 @@
|
||||
/* $OpenBSD: rc2.h,v 1.11 2014/07/10 22:45:57 jsing Exp $ */
|
||||
/* $OpenBSD: rc2.h,v 1.12 2023/07/07 08:29:37 beck Exp $ */
|
||||
/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
@ -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
|
||||
@ -75,24 +75,23 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct rc2_key_st
|
||||
{
|
||||
typedef struct rc2_key_st {
|
||||
RC2_INT data[64];
|
||||
} RC2_KEY;
|
||||
} RC2_KEY;
|
||||
|
||||
void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data,int bits);
|
||||
void RC2_ecb_encrypt(const unsigned char *in,unsigned char *out,RC2_KEY *key,
|
||||
int enc);
|
||||
void RC2_encrypt(unsigned long *data,RC2_KEY *key);
|
||||
void RC2_decrypt(unsigned long *data,RC2_KEY *key);
|
||||
void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits);
|
||||
void RC2_ecb_encrypt(const unsigned char *in, unsigned char *out, RC2_KEY *key,
|
||||
int enc);
|
||||
void RC2_encrypt(unsigned long *data, RC2_KEY *key);
|
||||
void RC2_decrypt(unsigned long *data, RC2_KEY *key);
|
||||
void RC2_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
|
||||
RC2_KEY *ks, unsigned char *iv, int enc);
|
||||
RC2_KEY *ks, unsigned char *iv, int enc);
|
||||
void RC2_cfb64_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, RC2_KEY *schedule, unsigned char *ivec,
|
||||
int *num, int enc);
|
||||
long length, RC2_KEY *schedule, unsigned char *ivec,
|
||||
int *num, int enc);
|
||||
void RC2_ofb64_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, RC2_KEY *schedule, unsigned char *ivec,
|
||||
int *num);
|
||||
long length, RC2_KEY *schedule, unsigned char *ivec,
|
||||
int *num);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
/* $OpenBSD: rc2_cbc.c,v 1.6 2022/11/26 16:08:54 tb Exp $ */
|
||||
/* $OpenBSD: rc2_cbc.c,v 1.7 2023/07/07 08:29:37 beck Exp $ */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
@ -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,168 +59,175 @@
|
||||
#include <openssl/rc2.h>
|
||||
#include "rc2_local.h"
|
||||
|
||||
void RC2_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
|
||||
RC2_KEY *ks, unsigned char *iv, int encrypt)
|
||||
{
|
||||
unsigned long tin0,tin1;
|
||||
unsigned long tout0,tout1,xor0,xor1;
|
||||
long l=length;
|
||||
void
|
||||
RC2_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
|
||||
RC2_KEY *ks, unsigned char *iv, int encrypt)
|
||||
{
|
||||
unsigned long tin0, tin1;
|
||||
unsigned long tout0, tout1, xor0, xor1;
|
||||
long l = length;
|
||||
unsigned long tin[2];
|
||||
|
||||
if (encrypt)
|
||||
if (encrypt) {
|
||||
c2l(iv, tout0);
|
||||
c2l(iv, tout1);
|
||||
iv -= 8;
|
||||
for (l -= 8; l >= 0; l -= 8)
|
||||
{
|
||||
c2l(iv,tout0);
|
||||
c2l(iv,tout1);
|
||||
iv-=8;
|
||||
for (l-=8; l>=0; l-=8)
|
||||
{
|
||||
c2l(in,tin0);
|
||||
c2l(in,tin1);
|
||||
tin0^=tout0;
|
||||
tin1^=tout1;
|
||||
tin[0]=tin0;
|
||||
tin[1]=tin1;
|
||||
RC2_encrypt(tin,ks);
|
||||
tout0=tin[0]; l2c(tout0,out);
|
||||
tout1=tin[1]; l2c(tout1,out);
|
||||
}
|
||||
if (l != -8)
|
||||
{
|
||||
c2ln(in,tin0,tin1,l+8);
|
||||
tin0^=tout0;
|
||||
tin1^=tout1;
|
||||
tin[0]=tin0;
|
||||
tin[1]=tin1;
|
||||
RC2_encrypt(tin,ks);
|
||||
tout0=tin[0]; l2c(tout0,out);
|
||||
tout1=tin[1]; l2c(tout1,out);
|
||||
}
|
||||
l2c(tout0,iv);
|
||||
l2c(tout1,iv);
|
||||
c2l(in, tin0);
|
||||
c2l(in, tin1);
|
||||
tin0 ^= tout0;
|
||||
tin1 ^= tout1;
|
||||
tin[0] = tin0;
|
||||
tin[1] = tin1;
|
||||
RC2_encrypt(tin, ks);
|
||||
tout0 = tin[0];
|
||||
l2c(tout0, out);
|
||||
tout1 = tin[1];
|
||||
l2c(tout1, out);
|
||||
}
|
||||
else
|
||||
if (l != -8) {
|
||||
c2ln(in, tin0, tin1, l + 8);
|
||||
tin0 ^= tout0;
|
||||
tin1 ^= tout1;
|
||||
tin[0] = tin0;
|
||||
tin[1] = tin1;
|
||||
RC2_encrypt(tin, ks);
|
||||
tout0 = tin[0];
|
||||
l2c(tout0, out);
|
||||
tout1 = tin[1];
|
||||
l2c(tout1, out);
|
||||
}
|
||||
l2c(tout0, iv);
|
||||
l2c(tout1, iv);
|
||||
} else {
|
||||
c2l(iv, xor0);
|
||||
c2l(iv, xor1);
|
||||
iv -= 8;
|
||||
for (l -= 8; l >= 0; l -= 8)
|
||||
{
|
||||
c2l(iv,xor0);
|
||||
c2l(iv,xor1);
|
||||
iv-=8;
|
||||
for (l-=8; l>=0; l-=8)
|
||||
{
|
||||
c2l(in,tin0); tin[0]=tin0;
|
||||
c2l(in,tin1); tin[1]=tin1;
|
||||
RC2_decrypt(tin,ks);
|
||||
tout0=tin[0]^xor0;
|
||||
tout1=tin[1]^xor1;
|
||||
l2c(tout0,out);
|
||||
l2c(tout1,out);
|
||||
xor0=tin0;
|
||||
xor1=tin1;
|
||||
}
|
||||
if (l != -8)
|
||||
{
|
||||
c2l(in,tin0); tin[0]=tin0;
|
||||
c2l(in,tin1); tin[1]=tin1;
|
||||
RC2_decrypt(tin,ks);
|
||||
tout0=tin[0]^xor0;
|
||||
tout1=tin[1]^xor1;
|
||||
l2cn(tout0,tout1,out,l+8);
|
||||
xor0=tin0;
|
||||
xor1=tin1;
|
||||
}
|
||||
l2c(xor0,iv);
|
||||
l2c(xor1,iv);
|
||||
c2l(in, tin0);
|
||||
tin[0] = tin0;
|
||||
c2l(in, tin1);
|
||||
tin[1] = tin1;
|
||||
RC2_decrypt(tin, ks);
|
||||
tout0 = tin[0] ^ xor0;
|
||||
tout1 = tin[1] ^ xor1;
|
||||
l2c(tout0, out);
|
||||
l2c(tout1, out);
|
||||
xor0 = tin0;
|
||||
xor1 = tin1;
|
||||
}
|
||||
tin0=tin1=tout0=tout1=xor0=xor1=0;
|
||||
tin[0]=tin[1]=0;
|
||||
if (l != -8) {
|
||||
c2l(in, tin0);
|
||||
tin[0] = tin0;
|
||||
c2l(in, tin1);
|
||||
tin[1] = tin1;
|
||||
RC2_decrypt(tin, ks);
|
||||
tout0 = tin[0] ^ xor0;
|
||||
tout1 = tin[1] ^ xor1;
|
||||
l2cn(tout0, tout1, out, l + 8);
|
||||
xor0 = tin0;
|
||||
xor1 = tin1;
|
||||
}
|
||||
l2c(xor0, iv);
|
||||
l2c(xor1, iv);
|
||||
}
|
||||
tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0;
|
||||
tin[0] = tin[1] = 0;
|
||||
}
|
||||
|
||||
void RC2_encrypt(unsigned long *d, RC2_KEY *key)
|
||||
{
|
||||
int i,n;
|
||||
RC2_INT *p0,*p1;
|
||||
RC2_INT x0,x1,x2,x3,t;
|
||||
void
|
||||
RC2_encrypt(unsigned long *d, RC2_KEY *key)
|
||||
{
|
||||
int i, n;
|
||||
RC2_INT *p0, *p1;
|
||||
RC2_INT x0, x1, x2, x3, t;
|
||||
unsigned long l;
|
||||
|
||||
l=d[0];
|
||||
x0=(RC2_INT)l&0xffff;
|
||||
x1=(RC2_INT)(l>>16L);
|
||||
l=d[1];
|
||||
x2=(RC2_INT)l&0xffff;
|
||||
x3=(RC2_INT)(l>>16L);
|
||||
l = d[0];
|
||||
x0 = (RC2_INT)l & 0xffff;
|
||||
x1 = (RC2_INT)(l >> 16L);
|
||||
l = d[1];
|
||||
x2 = (RC2_INT)l & 0xffff;
|
||||
x3 = (RC2_INT)(l >> 16L);
|
||||
|
||||
n=3;
|
||||
i=5;
|
||||
n = 3;
|
||||
i = 5;
|
||||
|
||||
p0=p1= &(key->data[0]);
|
||||
for (;;)
|
||||
{
|
||||
t=(x0+(x1& ~x3)+(x2&x3)+ *(p0++))&0xffff;
|
||||
x0=(t<<1)|(t>>15);
|
||||
t=(x1+(x2& ~x0)+(x3&x0)+ *(p0++))&0xffff;
|
||||
x1=(t<<2)|(t>>14);
|
||||
t=(x2+(x3& ~x1)+(x0&x1)+ *(p0++))&0xffff;
|
||||
x2=(t<<3)|(t>>13);
|
||||
t=(x3+(x0& ~x2)+(x1&x2)+ *(p0++))&0xffff;
|
||||
x3=(t<<5)|(t>>11);
|
||||
p0 = p1 = &(key->data[0]);
|
||||
for (;;) {
|
||||
t = (x0 + (x1 & ~x3) + (x2 & x3) + *(p0++)) & 0xffff;
|
||||
x0 = (t << 1)|(t >> 15);
|
||||
t = (x1 + (x2 & ~x0) + (x3 & x0) + *(p0++)) & 0xffff;
|
||||
x1 = (t << 2)|(t >> 14);
|
||||
t = (x2 + (x3 & ~x1) + (x0 & x1) + *(p0++)) & 0xffff;
|
||||
x2 = (t << 3)|(t >> 13);
|
||||
t = (x3 + (x0 & ~x2) + (x1 & x2) + *(p0++)) & 0xffff;
|
||||
x3 = (t << 5)|(t >> 11);
|
||||
|
||||
if (--i == 0)
|
||||
{
|
||||
if (--n == 0) break;
|
||||
i=(n == 2)?6:5;
|
||||
if (--i == 0) {
|
||||
if (--n == 0)
|
||||
break;
|
||||
i = (n == 2) ? 6 : 5;
|
||||
|
||||
x0+=p1[x3&0x3f];
|
||||
x1+=p1[x0&0x3f];
|
||||
x2+=p1[x1&0x3f];
|
||||
x3+=p1[x2&0x3f];
|
||||
}
|
||||
x0 += p1[x3 & 0x3f];
|
||||
x1 += p1[x0 & 0x3f];
|
||||
x2 += p1[x1 & 0x3f];
|
||||
x3 += p1[x2 & 0x3f];
|
||||
}
|
||||
|
||||
d[0]=(unsigned long)(x0&0xffff)|((unsigned long)(x1&0xffff)<<16L);
|
||||
d[1]=(unsigned long)(x2&0xffff)|((unsigned long)(x3&0xffff)<<16L);
|
||||
}
|
||||
|
||||
void RC2_decrypt(unsigned long *d, RC2_KEY *key)
|
||||
{
|
||||
int i,n;
|
||||
RC2_INT *p0,*p1;
|
||||
RC2_INT x0,x1,x2,x3,t;
|
||||
d[0] = (unsigned long)(x0 & 0xffff)|((unsigned long)(x1 & 0xffff) <<
|
||||
16L);
|
||||
d[1] = (unsigned long)(x2 & 0xffff)|((unsigned long)(x3 & 0xffff) <<
|
||||
16L);
|
||||
}
|
||||
|
||||
void
|
||||
RC2_decrypt(unsigned long *d, RC2_KEY *key)
|
||||
{
|
||||
int i, n;
|
||||
RC2_INT *p0, *p1;
|
||||
RC2_INT x0, x1, x2, x3, t;
|
||||
unsigned long l;
|
||||
|
||||
l=d[0];
|
||||
x0=(RC2_INT)l&0xffff;
|
||||
x1=(RC2_INT)(l>>16L);
|
||||
l=d[1];
|
||||
x2=(RC2_INT)l&0xffff;
|
||||
x3=(RC2_INT)(l>>16L);
|
||||
l = d[0];
|
||||
x0 = (RC2_INT)l & 0xffff;
|
||||
x1 = (RC2_INT)(l >> 16L);
|
||||
l = d[1];
|
||||
x2 = (RC2_INT)l & 0xffff;
|
||||
x3 = (RC2_INT)(l >> 16L);
|
||||
|
||||
n=3;
|
||||
i=5;
|
||||
n = 3;
|
||||
i = 5;
|
||||
|
||||
p0= &(key->data[63]);
|
||||
p1= &(key->data[0]);
|
||||
for (;;)
|
||||
{
|
||||
t=((x3<<11)|(x3>>5))&0xffff;
|
||||
x3=(t-(x0& ~x2)-(x1&x2)- *(p0--))&0xffff;
|
||||
t=((x2<<13)|(x2>>3))&0xffff;
|
||||
x2=(t-(x3& ~x1)-(x0&x1)- *(p0--))&0xffff;
|
||||
t=((x1<<14)|(x1>>2))&0xffff;
|
||||
x1=(t-(x2& ~x0)-(x3&x0)- *(p0--))&0xffff;
|
||||
t=((x0<<15)|(x0>>1))&0xffff;
|
||||
x0=(t-(x1& ~x3)-(x2&x3)- *(p0--))&0xffff;
|
||||
p0 = &(key->data[63]);
|
||||
p1 = &(key->data[0]);
|
||||
for (;;) {
|
||||
t = ((x3 << 11)|(x3 >> 5)) & 0xffff;
|
||||
x3 = (t - (x0 & ~x2) - (x1 & x2) - *(p0--)) & 0xffff;
|
||||
t = ((x2 << 13)|(x2 >> 3)) & 0xffff;
|
||||
x2 = (t - (x3 & ~x1) - (x0 & x1) - *(p0--)) & 0xffff;
|
||||
t = ((x1 << 14)|(x1 >> 2)) & 0xffff;
|
||||
x1 = (t - (x2 & ~x0) - (x3 & x0) - *(p0--)) & 0xffff;
|
||||
t = ((x0 << 15)|(x0 >> 1)) & 0xffff;
|
||||
x0 = (t - (x1 & ~x3) - (x2 & x3) - *(p0--)) & 0xffff;
|
||||
|
||||
if (--i == 0)
|
||||
{
|
||||
if (--n == 0) break;
|
||||
i=(n == 2)?6:5;
|
||||
if (--i == 0) {
|
||||
if (--n == 0)
|
||||
break;
|
||||
i = (n == 2) ? 6 : 5;
|
||||
|
||||
x3=(x3-p1[x2&0x3f])&0xffff;
|
||||
x2=(x2-p1[x1&0x3f])&0xffff;
|
||||
x1=(x1-p1[x0&0x3f])&0xffff;
|
||||
x0=(x0-p1[x3&0x3f])&0xffff;
|
||||
}
|
||||
x3 = (x3 - p1[x2 & 0x3f]) & 0xffff;
|
||||
x2 = (x2 - p1[x1 & 0x3f]) & 0xffff;
|
||||
x1 = (x1 - p1[x0 & 0x3f]) & 0xffff;
|
||||
x0 = (x0 - p1[x3 & 0x3f]) & 0xffff;
|
||||
}
|
||||
|
||||
d[0]=(unsigned long)(x0&0xffff)|((unsigned long)(x1&0xffff)<<16L);
|
||||
d[1]=(unsigned long)(x2&0xffff)|((unsigned long)(x3&0xffff)<<16L);
|
||||
}
|
||||
|
||||
d[0] = (unsigned long)(x0 & 0xffff)|((unsigned long)(x1 & 0xffff) <<
|
||||
16L);
|
||||
d[1] = (unsigned long)(x2 & 0xffff)|((unsigned long)(x3 & 0xffff) <<
|
||||
16L);
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
/* $OpenBSD: rc2_ecb.c,v 1.7 2022/11/26 16:08:54 tb Exp $ */
|
||||
/* $OpenBSD: rc2_ecb.c,v 1.8 2023/07/07 08:29:37 beck Exp $ */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
@ -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
|
||||
@ -68,19 +68,23 @@
|
||||
* Date: 11 Feb 1996 06:45:03 GMT
|
||||
*/
|
||||
|
||||
void RC2_ecb_encrypt(const unsigned char *in, unsigned char *out, RC2_KEY *ks,
|
||||
int encrypt)
|
||||
{
|
||||
unsigned long l,d[2];
|
||||
void
|
||||
RC2_ecb_encrypt(const unsigned char *in, unsigned char *out, RC2_KEY *ks,
|
||||
int encrypt)
|
||||
{
|
||||
unsigned long l, d[2];
|
||||
|
||||
c2l(in,l); d[0]=l;
|
||||
c2l(in,l); d[1]=l;
|
||||
c2l(in, l);
|
||||
d[0] = l;
|
||||
c2l(in, l);
|
||||
d[1] = l;
|
||||
if (encrypt)
|
||||
RC2_encrypt(d,ks);
|
||||
RC2_encrypt(d, ks);
|
||||
else
|
||||
RC2_decrypt(d,ks);
|
||||
l=d[0]; l2c(l,out);
|
||||
l=d[1]; l2c(l,out);
|
||||
l=d[0]=d[1]=0;
|
||||
}
|
||||
|
||||
RC2_decrypt(d, ks);
|
||||
l = d[0];
|
||||
l2c(l, out);
|
||||
l = d[1];
|
||||
l2c(l, out);
|
||||
l = d[0] = d[1] = 0;
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
/* $OpenBSD: rc2_local.h,v 1.1 2022/11/26 16:08:54 tb Exp $ */
|
||||
/* $OpenBSD: rc2_local.h,v 1.2 2023/07/07 08:29:37 beck Exp $ */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
@ -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,100 +57,99 @@
|
||||
*/
|
||||
|
||||
#undef c2l
|
||||
#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
|
||||
l|=((unsigned long)(*((c)++)))<< 8L, \
|
||||
l|=((unsigned long)(*((c)++)))<<16L, \
|
||||
#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), \
|
||||
#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, \
|
||||
l|=((unsigned long)(*((c)++)))<<16L, \
|
||||
l|=((unsigned long)(*((c)++)))<< 8L, \
|
||||
#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
|
||||
l|=((unsigned long)(*((c)++)))<<16L, \
|
||||
l|=((unsigned long)(*((c)++)))<< 8L, \
|
||||
l|=((unsigned long)(*((c)++))))
|
||||
|
||||
#undef l2n
|
||||
#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>>16L)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
|
||||
#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>>16L)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
|
||||
*((c)++)=(unsigned char)(((l) )&0xff))
|
||||
|
||||
#define C_RC2(n) \
|
||||
t=(x0+(x1& ~x3)+(x2&x3)+ *(p0++))&0xffff; \
|
||||
x0=(t<<1)|(t>>15); \
|
||||
t=(x1+(x2& ~x0)+(x3&x0)+ *(p0++))&0xffff; \
|
||||
x1=(t<<2)|(t>>14); \
|
||||
t=(x2+(x3& ~x1)+(x0&x1)+ *(p0++))&0xffff; \
|
||||
x2=(t<<3)|(t>>13); \
|
||||
t=(x3+(x0& ~x2)+(x1&x2)+ *(p0++))&0xffff; \
|
||||
#define C_RC2(n) \
|
||||
t=(x0+(x1& ~x3)+(x2&x3)+ *(p0++))&0xffff; \
|
||||
x0=(t<<1)|(t>>15); \
|
||||
t=(x1+(x2& ~x0)+(x3&x0)+ *(p0++))&0xffff; \
|
||||
x1=(t<<2)|(t>>14); \
|
||||
t=(x2+(x3& ~x1)+(x0&x1)+ *(p0++))&0xffff; \
|
||||
x2=(t<<3)|(t>>13); \
|
||||
t=(x3+(x0& ~x2)+(x1&x2)+ *(p0++))&0xffff; \
|
||||
x3=(t<<5)|(t>>11);
|
||||
|
||||
|
@ -1,25 +1,25 @@
|
||||
/* $OpenBSD: rc2_skey.c,v 1.13 2022/11/26 16:08:54 tb Exp $ */
|
||||
/* $OpenBSD: rc2_skey.c,v 1.14 2023/07/07 08:29:37 beck Exp $ */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
@ -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
|
||||
@ -91,48 +91,51 @@ static const unsigned char key_table[256]={
|
||||
* BSAFE uses the 'retarded' version. What I previously shipped is
|
||||
* the same as specifying 1024 for the 'bits' parameter. Bsafe uses
|
||||
* a version where the bits parameter is the same as len*8 */
|
||||
void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits)
|
||||
{
|
||||
int i,j;
|
||||
void
|
||||
RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits)
|
||||
{
|
||||
int i, j;
|
||||
unsigned char *k;
|
||||
RC2_INT *ki;
|
||||
unsigned int c,d;
|
||||
unsigned int c, d;
|
||||
|
||||
k= (unsigned char *)&(key->data[0]);
|
||||
*k=0; /* for if there is a zero length key */
|
||||
k = (unsigned char *)&(key->data[0]);
|
||||
*k = 0; /* for if there is a zero length key */
|
||||
|
||||
if (len > 128) len=128;
|
||||
if (bits <= 0) bits=1024;
|
||||
if (bits > 1024) bits=1024;
|
||||
if (len > 128)
|
||||
len = 128;
|
||||
if (bits <= 0)
|
||||
bits = 1024;
|
||||
if (bits > 1024)
|
||||
bits = 1024;
|
||||
|
||||
for (i=0; i<len; i++)
|
||||
k[i]=data[i];
|
||||
for (i = 0; i < len; i++)
|
||||
k[i] = data[i];
|
||||
|
||||
/* expand table */
|
||||
d=k[len-1];
|
||||
j=0;
|
||||
for (i=len; i < 128; i++,j++)
|
||||
{
|
||||
d=key_table[(k[j]+d)&0xff];
|
||||
k[i]=d;
|
||||
}
|
||||
d = k[len - 1];
|
||||
j = 0;
|
||||
for (i = len; i < 128; i++, j++)
|
||||
{
|
||||
d = key_table[(k[j] + d) & 0xff];
|
||||
k[i] = d;
|
||||
}
|
||||
|
||||
/* hmm.... key reduction to 'bits' bits */
|
||||
|
||||
j=(bits+7)>>3;
|
||||
i=128-j;
|
||||
c= (0xff>>(-bits & 0x07));
|
||||
j = (bits + 7) >> 3;
|
||||
i = 128 - j;
|
||||
c = (0xff >> (-bits & 0x07));
|
||||
|
||||
d=key_table[k[i]&c];
|
||||
k[i]=d;
|
||||
while (i--)
|
||||
{
|
||||
d=key_table[k[i+j]^d];
|
||||
k[i]=d;
|
||||
}
|
||||
d = key_table[k[i] & c];
|
||||
k[i] = d;
|
||||
while (i--) {
|
||||
d = key_table[k[i + j] ^ d];
|
||||
k[i] = d;
|
||||
}
|
||||
|
||||
/* copy from bytes into RC2_INT's */
|
||||
ki= &(key->data[63]);
|
||||
for (i=127; i>=0; i-=2)
|
||||
*(ki--)=((k[i]<<8)|k[i-1])&0xffff;
|
||||
}
|
||||
ki = &(key->data[63]);
|
||||
for (i = 127; i >= 0; i -= 2)
|
||||
*(ki--) = ((k[i] << 8)|k[i - 1]) & 0xffff;
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
/* $OpenBSD: rc2cfb64.c,v 1.6 2022/11/26 16:08:54 tb Exp $ */
|
||||
/* $OpenBSD: rc2cfb64.c,v 1.7 2023/07/07 08:29:37 beck Exp $ */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
@ -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
|
||||
@ -64,59 +64,60 @@
|
||||
* 64bit block we have used is contained in *num;
|
||||
*/
|
||||
|
||||
void RC2_cfb64_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, RC2_KEY *schedule, unsigned char *ivec,
|
||||
int *num, int encrypt)
|
||||
{
|
||||
unsigned long v0,v1,t;
|
||||
int n= *num;
|
||||
long l=length;
|
||||
void
|
||||
RC2_cfb64_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, RC2_KEY *schedule, unsigned char *ivec,
|
||||
int *num, int encrypt)
|
||||
{
|
||||
unsigned long v0, v1, t;
|
||||
int n = *num;
|
||||
long l = length;
|
||||
unsigned long ti[2];
|
||||
unsigned char *iv,c,cc;
|
||||
unsigned char *iv, c, cc;
|
||||
|
||||
iv=(unsigned char *)ivec;
|
||||
if (encrypt)
|
||||
{
|
||||
while (l--)
|
||||
{
|
||||
if (n == 0)
|
||||
{
|
||||
c2l(iv,v0); ti[0]=v0;
|
||||
c2l(iv,v1); ti[1]=v1;
|
||||
RC2_encrypt((unsigned long *)ti,schedule);
|
||||
iv=(unsigned char *)ivec;
|
||||
t=ti[0]; l2c(t,iv);
|
||||
t=ti[1]; l2c(t,iv);
|
||||
iv=(unsigned char *)ivec;
|
||||
}
|
||||
c= *(in++)^iv[n];
|
||||
*(out++)=c;
|
||||
iv[n]=c;
|
||||
n=(n+1)&0x07;
|
||||
iv = (unsigned char *)ivec;
|
||||
if (encrypt) {
|
||||
while (l--) {
|
||||
if (n == 0) {
|
||||
c2l(iv, v0);
|
||||
ti[0] = v0;
|
||||
c2l(iv, v1);
|
||||
ti[1] = v1;
|
||||
RC2_encrypt((unsigned long *)ti, schedule);
|
||||
iv = (unsigned char *)ivec;
|
||||
t = ti[0];
|
||||
l2c(t, iv);
|
||||
t = ti[1];
|
||||
l2c(t, iv);
|
||||
iv = (unsigned char *)ivec;
|
||||
}
|
||||
c = *(in++) ^ iv[n];
|
||||
*(out++) = c;
|
||||
iv[n] = c;
|
||||
n = (n + 1) & 0x07;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (l--)
|
||||
{
|
||||
if (n == 0)
|
||||
{
|
||||
c2l(iv,v0); ti[0]=v0;
|
||||
c2l(iv,v1); ti[1]=v1;
|
||||
RC2_encrypt((unsigned long *)ti,schedule);
|
||||
iv=(unsigned char *)ivec;
|
||||
t=ti[0]; l2c(t,iv);
|
||||
t=ti[1]; l2c(t,iv);
|
||||
iv=(unsigned char *)ivec;
|
||||
}
|
||||
cc= *(in++);
|
||||
c=iv[n];
|
||||
iv[n]=cc;
|
||||
*(out++)=c^cc;
|
||||
n=(n+1)&0x07;
|
||||
} else {
|
||||
while (l--) {
|
||||
if (n == 0) {
|
||||
c2l(iv, v0);
|
||||
ti[0] = v0;
|
||||
c2l(iv, v1);
|
||||
ti[1] = v1;
|
||||
RC2_encrypt((unsigned long *)ti, schedule);
|
||||
iv = (unsigned char *)ivec;
|
||||
t = ti[0];
|
||||
l2c(t, iv);
|
||||
t = ti[1];
|
||||
l2c(t, iv);
|
||||
iv = (unsigned char *)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;
|
||||
}
|
||||
|
||||
v0 = v1 = ti[0] = ti[1] = t = c = cc = 0;
|
||||
*num = n;
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
/* $OpenBSD: rc2ofb64.c,v 1.6 2022/11/26 16:08:54 tb Exp $ */
|
||||
/* $OpenBSD: rc2ofb64.c,v 1.7 2023/07/07 08:29:37 beck Exp $ */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
@ -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
|
||||
@ -63,49 +63,48 @@
|
||||
* used. The extra state information to record how much of the
|
||||
* 64bit block we have used is contained in *num;
|
||||
*/
|
||||
void RC2_ofb64_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, RC2_KEY *schedule, unsigned char *ivec,
|
||||
int *num)
|
||||
{
|
||||
unsigned long v0,v1,t;
|
||||
int n= *num;
|
||||
long l=length;
|
||||
void
|
||||
RC2_ofb64_encrypt(const unsigned char *in, unsigned char *out,
|
||||
long length, RC2_KEY *schedule, unsigned char *ivec,
|
||||
int *num)
|
||||
{
|
||||
unsigned long v0, v1, t;
|
||||
int n = *num;
|
||||
long l = length;
|
||||
unsigned char d[8];
|
||||
char *dp;
|
||||
unsigned long ti[2];
|
||||
unsigned char *iv;
|
||||
int save=0;
|
||||
int save = 0;
|
||||
|
||||
iv=(unsigned char *)ivec;
|
||||
c2l(iv,v0);
|
||||
c2l(iv,v1);
|
||||
ti[0]=v0;
|
||||
ti[1]=v1;
|
||||
dp=(char *)d;
|
||||
l2c(v0,dp);
|
||||
l2c(v1,dp);
|
||||
while (l--)
|
||||
{
|
||||
if (n == 0)
|
||||
{
|
||||
RC2_encrypt((unsigned long *)ti,schedule);
|
||||
dp=(char *)d;
|
||||
t=ti[0]; l2c(t,dp);
|
||||
t=ti[1]; l2c(t,dp);
|
||||
iv = (unsigned char *)ivec;
|
||||
c2l(iv, v0);
|
||||
c2l(iv, v1);
|
||||
ti[0] = v0;
|
||||
ti[1] = v1;
|
||||
dp = (char *)d;
|
||||
l2c(v0, dp);
|
||||
l2c(v1, dp);
|
||||
while (l--) {
|
||||
if (n == 0) {
|
||||
RC2_encrypt((unsigned long *)ti, schedule);
|
||||
dp = (char *)d;
|
||||
t = ti[0];
|
||||
l2c(t, dp);
|
||||
t = ti[1];
|
||||
l2c(t, dp);
|
||||
save++;
|
||||
}
|
||||
*(out++)= *(in++)^d[n];
|
||||
n=(n+1)&0x07;
|
||||
}
|
||||
if (save)
|
||||
{
|
||||
v0=ti[0];
|
||||
v1=ti[1];
|
||||
iv=(unsigned char *)ivec;
|
||||
l2c(v0,iv);
|
||||
l2c(v1,iv);
|
||||
}
|
||||
t=v0=v1=ti[0]=ti[1]=0;
|
||||
*num=n;
|
||||
*(out++) = *(in++) ^ d[n];
|
||||
n = (n + 1) & 0x07;
|
||||
}
|
||||
|
||||
if (save) {
|
||||
v0 = ti[0];
|
||||
v1 = ti[1];
|
||||
iv = (unsigned char *)ivec;
|
||||
l2c(v0, iv);
|
||||
l2c(v1, iv);
|
||||
}
|
||||
t = v0 = v1 = ti[0] = ti[1] = 0;
|
||||
*num = n;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user