Commit cb2badbd authored by Jon Grimm's avatar Jon Grimm

[SCTP] Remove some unused source modules.

We use crypto api.  Get rid of our own versions of hash code. 
parent 849214b4
/* SCTP reference Implementation
* Copyright (C) 1999 Cisco, Inc.
* Copyright (C) 1999 Motorola, Inc.
*
* This file originates from Randy Stewart's SCTP reference Implementation.
*
* The SCTP reference implementation is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
* ************************
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU CC; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Please send any bug reports or fixes you make to the
* email address(es):
* lksctp developers <lksctp-developers@lists.sourceforge.net>
*
* Or submit a bug report through the following website:
* http://www.sf.net/projects/lksctp
*
* Written or modified by:
* Randy Stewart <rstewar1@email.mot.com>
* Ken Morneau <kmorneau@cisco.com>
* Qiaobing Xie <qxie1@email.mot.com>
*/
#ifndef __SLA1_h__
#define __SLA1_h__
struct SLA_1_Context {
unsigned int A;
unsigned int B;
unsigned int C;
unsigned int D;
unsigned int E;
unsigned int H0;
unsigned int H1;
unsigned int H2;
unsigned int H3;
unsigned int H4;
unsigned int words[80];
unsigned int TEMP;
/* block I am collecting to process */
char SLAblock[64];
/* collected so far */
int howManyInBlock;
unsigned int runningTotal;
};
#define F1(B,C,D) (((B & C) | ((~B) & D))) /* 0 <= t <= 19 */
#define F2(B,C,D) (B ^ C ^ D) /* 20 <= t <= 39 */
#define F3(B,C,D) ((B & C) | (B & D) | (C & D)) /* 40 <= t <= 59 */
#define F4(B,C,D) (B ^ C ^ D) /*600 <= t <= 79 */
/* circular shift */
#define CSHIFT(A,B) ((B << A) | (B >> (32-A)))
#define K1 0x5a827999 /* 0 <= t <= 19 */
#define K2 0x6ed9eba1 /* 20 <= t <= 39 */
#define K3 0x8f1bbcdc /* 40 <= t <= 59 */
#define K4 0xca62c1d6 /* 60 <= t <= 79 */
#define H0INIT 0x67452301
#define H1INIT 0xefcdab89
#define H2INIT 0x98badcfe
#define H3INIT 0x10325476
#define H4INIT 0xc3d2e1f0
extern void SLA1_Init(struct SLA_1_Context *);
extern void SLA1_Process(struct SLA_1_Context *, const unsigned char *, int);
extern void SLA1_Final(struct SLA_1_Context *, unsigned char *);
#endif
...@@ -170,7 +170,7 @@ int sctp_add_bind_addr(struct sctp_bind_addr *bp, union sctp_addr *new, ...@@ -170,7 +170,7 @@ int sctp_add_bind_addr(struct sctp_bind_addr *bp, union sctp_addr *new,
if (!addr) if (!addr)
return -ENOMEM; return -ENOMEM;
addr->a = *new; memcpy(&addr->a, new, sizeof(*new));
/* Fix up the port if it has not yet been set. /* Fix up the port if it has not yet been set.
* Both v4 and v6 have the port at the same offset. * Both v4 and v6 have the port at the same offset.
......
/* SCTP reference Implementation Copyright (C) 1999 Cisco And Motorola
*
* This file origiantes from Randy Stewart's SCTP reference Implementation.
*
* The SCTP reference implementation is free software;
* you can redistribute it and/or modify it under the terms of
* the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* The SCTP reference implementation is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
* ************************
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU CC; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Please send any bug reports or fixes you make to the
* email address(es):
* lksctp developers <lksctp-developers@lists.sourceforge.net>
*
* Or submit a bug report through the following website:
* http://www.sf.net/projects/lksctp
*
* Written or modified by:
* Randy Stewart rstewar1@email.mot.com
* Ken Morneau kmorneau@cisco.com
* Qiaobing Xie qxie1@email.mot.com
*
* Any bugs reported given to us we will try to fix... any fixes shared will
* be incorperated into the next SCTP release.
*
* There are still LOTS of bugs in this code... I always run on the motto
* "it is a wonder any code ever works :)"
*/
#include <linux/types.h>
#include <asm/string.h>
#include <net/sctp/sctp.h>
#include <net/sctp/sla1.h>
/* SCTP Main driver.
* passing a two pointers and two lengths,
* returning a digest pointer filled. The md5 code
* was taken directly from the RFC (2104) so to understand it
* you may want to go look at the RFC referenced in the
* SCTP spec. We did modify this code to either user OUR
* implementation of SLA1 or the MD5 that comes from its
* RFC. SLA1 may have IPR issues so you need to check in
* to this if you wish to use it... Or at least that is
* what the FIP-180.1 web page says.
*/
void sctp_hash_digest(const char *key, const int in_key_len,
const char *text, const int text_len,
__u8 *digest)
{
int key_len = in_key_len;
struct SLA_1_Context context;
__u8 k_ipad[65]; /* inner padding -
* key XORd with ipad
*/
__u8 k_opad[65]; /* outer padding -
* key XORd with opad
*/
__u8 tk[20];
int i;
/* if key is longer than 64 bytes reset it to key=MD5(key) */
if (key_len > 64) {
struct SLA_1_Context tctx;
SLA1_Init(&tctx);
SLA1_Process(&tctx, key, key_len);
SLA1_Final(&tctx,tk);
key = tk;
key_len = 20;
}
/*
* the HMAC_MD5 transform looks like:
*
* MD5(K XOR opad, MD5(K XOR ipad, text))
*
* where K is an n byte key
* ipad is the byte 0x36 repeated 64 times
* opad is the byte 0x5c repeated 64 times
* and text is the data being protected
*/
/* start out by storing key in pads */
memset(k_ipad, 0, sizeof k_ipad);
memset(k_opad, 0, sizeof k_opad);
memcpy(k_ipad, key, key_len);
memcpy(k_opad, key, key_len);
/* XOR key with ipad and opad values */
for (i = 0; i < 64; i++) {
k_ipad[i] ^= 0x36;
k_opad[i] ^= 0x5c;
}
/* perform inner hash */
SLA1_Init(&context); /* init context for 1st
* pass
*/
SLA1_Process(&context, k_ipad, 64); /* start with inner pad */
SLA1_Process(&context, text, text_len); /* then text of datagram */
SLA1_Final(&context,digest); /* finish up 1st pass */
/*
* perform outer hash
*/
SLA1_Init(&context); /* init context for 2nd
* pass
*/
SLA1_Process(&context, k_opad, 64); /* start with outer pad */
SLA1_Process(&context, digest, 20); /* then results of 1st
* hash
*/
SLA1_Final(&context, digest); /* finish up 2nd pass */
}
/* SCTP kernel reference Implementation
* Copyright (c) 1999-2000 Cisco, Inc.
* Copyright (c) 1999-2001 Motorola, Inc.
*
* This file is part of the SCTP kernel reference Implementation
*
* (It's really SHA-1 but Hey I was tired when I created this
* file, and on a plane to France :-)
*
* The SCTP reference implementation is free software;
* you can redistribute it and/or modify it under the terms of
* the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* The SCTP reference implementation is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
* ************************
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU CC; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Please send any bug reports or fixes you make to the
* email address(es):
* lksctp developers <lksctp-developers@lists.sourceforge.net>
*
* Or submit a bug report through the following website:
* http://www.sf.net/projects/lksctp
*
* Written or modified by:
* Randall Stewart <rstewar1@email.mot.com>
* kmorneau@cisco.com
* qxie1@email.mot.com
*
* Based on:
* Randy Stewart, et al. SCTP Reference Implementation which is licenced
* under the GPL.
*
* Any bugs reported given to us we will try to fix... any fixes shared will
* be incorporated into the next SCTP release.
*/
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/fcntl.h>
#include <asm/string.h> /* for memcpy */
#include <linux/sched.h> /* dead chicken for in.h */
#include <linux/in.h> /* for htonl and ntohl */
#include <net/sctp/sla1.h>
void SLA1_Init(struct SLA_1_Context *ctx)
{
/* Init the SLA-1 context structure. */
ctx->A = 0;
ctx->B = 0;
ctx->C = 0;
ctx->D = 0;
ctx->E = 0;
ctx->H0 = H0INIT;
ctx->H1 = H1INIT;
ctx->H2 = H2INIT;
ctx->H3 = H3INIT;
ctx->H4 = H4INIT;
ctx->TEMP = 0;
memset(ctx->words, 0, sizeof(ctx->words));
ctx->howManyInBlock = 0;
ctx->runningTotal = 0;
}
void SLA1processABlock(struct SLA_1_Context *ctx,unsigned int *block)
{
int i;
/* init the W0-W15 to the block of words being
* hashed.
*/
/* step a) */
for (i = 0; i < 16; i++)
ctx->words[i] = ntohl(block[i]);
/* now init the rest based on the SLA-1 formula, step b) */
for (i = 16; i < 80; i++)
ctx->words[i] =
CSHIFT(1, ((ctx->words[(i-3)]) ^
(ctx->words[(i-8)]) ^
(ctx->words[(i-14)]) ^
(ctx->words[(i-16)])));
/* step c) */
ctx->A = ctx->H0;
ctx->B = ctx->H1;
ctx->C = ctx->H2;
ctx->D = ctx->H3;
ctx->E = ctx->H4;
/* step d) */
for (i = 0; i < 80; i++) {
if (i < 20) {
ctx->TEMP = ((CSHIFT(5, ctx->A)) +
(F1(ctx->B, ctx->C, ctx->D)) +
(ctx->E) +
ctx->words[i] +
K1
);
} else if (i < 40) {
ctx->TEMP = ((CSHIFT(5, ctx->A)) +
(F2(ctx->B, ctx->C, ctx->D)) +
(ctx->E) +
(ctx->words[i]) +
K2
);
} else if (i < 60) {
ctx->TEMP = ((CSHIFT(5, ctx->A)) +
(F3(ctx->B, ctx->C, ctx->D)) +
(ctx->E) +
(ctx->words[i]) +
K3
);
} else {
ctx->TEMP = ((CSHIFT(5, ctx->A)) +
(F4(ctx->B, ctx->C, ctx->D)) +
(ctx->E) +
(ctx->words[i]) +
K4
);
}
ctx->E = ctx->D;
ctx->D = ctx->C;
ctx->C = CSHIFT(30, ctx->B);
ctx->B = ctx->A;
ctx->A = ctx->TEMP;
}
/* step e) */
ctx->H0 = (ctx->H0) + (ctx->A);
ctx->H1 = (ctx->H1) + (ctx->B);
ctx->H2 = (ctx->H2) + (ctx->C);
ctx->H3 = (ctx->H3) + (ctx->D);
ctx->H4 = (ctx->H4) + (ctx->E);
}
void SLA1_Process(struct SLA_1_Context *ctx, const unsigned char *ptr, int siz)
{
int numberLeft, leftToFill;
numberLeft = siz;
while (numberLeft > 0) {
leftToFill = sizeof(ctx->SLAblock) - ctx->howManyInBlock;
if (leftToFill > numberLeft) {
/* can only partially fill up this one */
memcpy(&ctx->SLAblock[ctx->howManyInBlock],
ptr, numberLeft);
ctx->howManyInBlock += siz;
ctx->runningTotal += siz;
break;
} else {
/* block is now full, process it */
memcpy(&ctx->SLAblock[ctx->howManyInBlock],
ptr, leftToFill);
SLA1processABlock(ctx, (unsigned int *) ctx->SLAblock);
numberLeft -= leftToFill;
ctx->runningTotal += leftToFill;
ctx->howManyInBlock = 0;
}
}
}
void SLA1_Final(struct SLA_1_Context *ctx, unsigned char *digestBuf)
{
/* if any left in block fill with padding
* and process. Then transfer the digest to
* the pointer. At the last block some special
* rules need to apply. We must add a 1 bit
* following the message, then we pad with
* 0's. The total size is encoded as a 64 bit
* number at the end. Now if the last buffer has
* more than 55 octets in it we cannot fit
* the 64 bit number + 10000000 pad on the end
* and must add the 10000000 pad, pad the rest
* of the message with 0's and then create a
* all 0 message with just the 64 bit size
* at the end and run this block through by itself.
* Also the 64 bit int must be in network byte
* order.
*/
int i, leftToFill;
unsigned int *ptr;
if (ctx->howManyInBlock > 55) {
/* special case, we need to process two
* blocks here. One for the current stuff
* plus possibly the pad. The other for
* the size.
*/
leftToFill = sizeof(ctx->SLAblock) - ctx->howManyInBlock;
if (leftToFill == 0) {
/* Should not really happen but I am paranoid */
/* Not paranoid enough! It is possible for leftToFill
* to become negative! AAA!!!! This is another reason
* to pick MD5 :-)...
*/
SLA1processABlock(ctx, (unsigned int *) ctx->SLAblock);
/* init last block, a bit different then the rest :-) */
ctx->SLAblock[0] = 0x80;
for (i = 1; i < sizeof(ctx->SLAblock); i++) {
ctx->SLAblock[i] = 0x0;
}
} else if (leftToFill == 1) {
ctx->SLAblock[ctx->howManyInBlock] = 0x80;
SLA1processABlock(ctx, (unsigned int *) ctx->SLAblock);
/* init last block */
memset(ctx->SLAblock, 0, sizeof(ctx->SLAblock));
} else {
ctx->SLAblock[ctx->howManyInBlock] = 0x80;
for (i = (ctx->howManyInBlock + 1);
i < sizeof(ctx->SLAblock);
i++) {
ctx->SLAblock[i] = 0x0;
}
SLA1processABlock(ctx, (unsigned int *) ctx->SLAblock);
/* init last block */
memset(ctx->SLAblock, 0, sizeof(ctx->SLAblock));
}
/* This is in bits so multiply by 8 */
ctx->runningTotal *= 8;
ptr = (unsigned int *) &ctx->SLAblock[60];
*ptr = htonl(ctx->runningTotal);
SLA1processABlock(ctx, (unsigned int *) ctx->SLAblock);
} else {
/* easy case, we just pad this
* message to size - end with 0
* add the magic 0x80 to the next
* word and then put the network byte
* order size in the last spot and
* process the block.
*/
ctx->SLAblock[ctx->howManyInBlock] = 0x80;
for (i = (ctx->howManyInBlock + 1);
i < sizeof(ctx->SLAblock);
i++) {
ctx->SLAblock[i] = 0x0;
}
/* get last int spot */
ctx->runningTotal *= 8;
ptr = (unsigned int *) &ctx->SLAblock[60];
*ptr = htonl(ctx->runningTotal);
SLA1processABlock(ctx, (unsigned int *) ctx->SLAblock);
}
/* Now at this point all we need do is transfer the
* digest back to the user
*/
digestBuf[3] = (ctx->H0 & 0xff);
digestBuf[2] = ((ctx->H0 >> 8) & 0xff);
digestBuf[1] = ((ctx->H0 >> 16) & 0xff);
digestBuf[0] = ((ctx->H0 >> 24) & 0xff);
digestBuf[7] = (ctx->H1 & 0xff);
digestBuf[6] = ((ctx->H1 >> 8) & 0xff);
digestBuf[5] = ((ctx->H1 >> 16) & 0xff);
digestBuf[4] = ((ctx->H1 >> 24) & 0xff);
digestBuf[11] = (ctx->H2 & 0xff);
digestBuf[10] = ((ctx->H2 >> 8) & 0xff);
digestBuf[9] = ((ctx->H2 >> 16) & 0xff);
digestBuf[8] = ((ctx->H2 >> 24) & 0xff);
digestBuf[15] = (ctx->H3 & 0xff);
digestBuf[14] = ((ctx->H3 >> 8) & 0xff);
digestBuf[13] = ((ctx->H3 >> 16) & 0xff);
digestBuf[12] = ((ctx->H3 >> 24) & 0xff);
digestBuf[19] = (ctx->H4 & 0xff);
digestBuf[18] = ((ctx->H4 >> 8) & 0xff);
digestBuf[17] = ((ctx->H4 >> 16) & 0xff);
digestBuf[16] = ((ctx->H4 >> 24) & 0xff);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment