浏览代码

Remove OpenSSL

Use a GPL-compatible SHA1 implementation.
Richard Laager 9 年之前
父节点
当前提交
2f063ff7af
共有 8 个文件被更改,包括 207 次插入13 次删除
  1. 1 1
      README.md
  2. 0 2
      build_setup.nsi.in
  3. 2 2
      src/Makefile.am
  4. 1 1
      src/docsis.c
  5. 0 4
      src/md5.c
  6. 1 3
      src/md5.h
  7. 151 0
      src/sha1.c
  8. 51 0
      src/sha1.h

+ 1 - 1
README.md

@@ -48,7 +48,7 @@ Tested and working under Cygwin 2.0.2
 
 Packages needed:
 
-    automake libtool net-snmp-utils net-snmp-devel bison make gcc-g++ flex libglib2.0-devel openssl-devel
+    automake libtool net-snmp-utils net-snmp-devel bison make gcc-g++ flex libglib2.0-devel
   
 
 Installation steps

+ 0 - 2
build_setup.nsi.in

@@ -37,7 +37,6 @@ Section "Base DOCSIS kit" SEC01
   File "@CYGWIN_BUILDROOT@\src\docsis.exe"
   CreateShortCut "$DESKTOP\docsis.lnk" "$INSTDIR\docsis.exe"
   File "@CYGWIN_BUILDROOT@\License.txt"
-  File "C:\cygwin\bin\cygcrypto-0.9.7.dll"
   File "C:\cygwin\bin\cygwin1.dll"
   File "@CYGWIN_BUILDROOT@\README"
 
@@ -209,7 +208,6 @@ FunctionEnd
 Section Uninstall
   Delete "$INSTDIR\docsis.exe"
   Delete "$INSTDIR\License.txt"
-  Delete "$INSTDIR\cygcrypto-0.9.7.dll"
   Delete "$INSTDIR\cygwin1.dll"
   Delete "$INSTDIR\README"
   Delete "$INSTDIR\docsis.bat"

+ 2 - 2
src/Makefile.am

@@ -1,12 +1,12 @@
 bin_PROGRAMS = docsis
-docsis_SOURCES = docsis.c ethermac.c md5.c docsis_encode.c docsis_decode.c docsis_snmp.c docsis_yy.y docsis_lex.l hmac_md5.c
+docsis_SOURCES = docsis.c ethermac.c md5.c docsis_encode.c docsis_decode.c docsis_snmp.c docsis_yy.y docsis_lex.l hmac_md5.c sha1.c
 
 # set the include path found by configure
 AM_CPPFLAGS = $(all_includes) $(NETSNMP_CFLAGS)
 
 # the library search path.
 docsis_LDADD = $(all_libraries) $(NETSNMP_LIBS) $(LEXLIB) $(LIBM)
-noinst_HEADERS = ethermac.h md5.h docsis.h docsis_common.h docsis_decode.h docsis_encode.h docsis_symtable.h docsis_snmp.h docsis_globals.h
+noinst_HEADERS = ethermac.h md5.h docsis.h docsis_common.h docsis_decode.h docsis_encode.h docsis_symtable.h docsis_snmp.h docsis_globals.h sha1.h
 EXTRA_DIST=docsis_yy.h
 CLEANFILES=docsis_yy.c docsis_yy.h docsis_yy.output docsis_lex.c
 DISTCLEANFILES=Makefile

+ 1 - 1
src/docsis.c

@@ -42,7 +42,7 @@
 #include "docsis_symtable.h"
 #include "ethermac.h"
 #include "md5.h"
-#include <openssl/sha.h>
+#include "sha1.h"
 
 struct tlv *global_tlvtree_head;
 symbol_type *global_symtable;

+ 0 - 4
src/md5.c

@@ -35,8 +35,6 @@
  * compile-time configuration.
  */
 
-#ifndef HAVE_OPENSSL
-
 #include <string.h>
 
 #include "md5.h"
@@ -292,5 +290,3 @@ void MD5_Final(unsigned char *result, MD5_CTX *ctx)
 
 	memset(ctx, 0, sizeof(*ctx));
 }
-
-#endif

+ 1 - 3
src/md5.h

@@ -23,9 +23,7 @@
  * See md5.c for more information.
  */
 
-#ifdef HAVE_OPENSSL
-#include <openssl/md5.h>
-#elif !defined(_MD5_H)
+#if !defined(_MD5_H)
 #define _MD5_H
 
 /* Any 32-bit or wider unsigned integer data type will do */

+ 151 - 0
src/sha1.c

@@ -0,0 +1,151 @@
+/*
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * The Original Code is SHA 180-1 Reference Implementation (Compact version)
+ *
+ * The Initial Developer of the Original Code is Paul Kocher of
+ * Cryptography Research.  Portions created by Paul Kocher are
+ * Copyright (C) 1995-9 by Cryptography Research, Inc.  All
+ * Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ *     Paul Kocher
+ *
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU General Public License Version 2 or later (the
+ * "GPL"), in which case the provisions of the GPL are applicable
+ * instead of those above.  If you wish to allow use of your
+ * version of this file only under the terms of the GPL and not to
+ * allow others to use your version of this file under the MPL,
+ * indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by
+ * the GPL.  If you do not delete the provisions above, a recipient
+ * may use your version of this file under either the MPL or the
+ * GPL.
+ */
+
+#include "sha1.h"
+
+static void shaHashBlock(SHA_CTX *ctx);
+
+void SHA1_Init(SHA_CTX *ctx) {
+  int i;
+
+  ctx->lenW = 0;
+  ctx->sizeHi = ctx->sizeLo = 0;
+
+  /* Initialize H with the magic constants (see FIPS180 for constants)
+   */
+  ctx->H[0] = 0x67452301;
+  ctx->H[1] = 0xefcdab89;
+  ctx->H[2] = 0x98badcfe;
+  ctx->H[3] = 0x10325476;
+  ctx->H[4] = 0xc3d2e1f0;
+
+  for (i = 0; i < 80; i++)
+    ctx->W[i] = 0;
+}
+
+
+void SHA1_Update(SHA_CTX *ctx, const void *_dataIn, int len) {
+  const unsigned char *dataIn = _dataIn;
+  int i;
+
+  /* Read the data into W and process blocks as they get full
+   */
+  for (i = 0; i < len; i++) {
+    ctx->W[ctx->lenW / 4] <<= 8;
+    ctx->W[ctx->lenW / 4] |= (unsigned int)dataIn[i];
+    if ((++ctx->lenW) % 64 == 0) {
+      shaHashBlock(ctx);
+      ctx->lenW = 0;
+    }
+    ctx->sizeLo += 8;
+    ctx->sizeHi += (ctx->sizeLo < 8);
+  }
+}
+
+
+void SHA1_Final(unsigned char hashout[20], SHA_CTX *ctx) {
+  unsigned char pad0x80 = 0x80;
+  unsigned char pad0x00 = 0x00;
+  unsigned char padlen[8];
+  int i;
+
+  /* Pad with a binary 1 (e.g. 0x80), then zeroes, then length
+   */
+  padlen[0] = (unsigned char)((ctx->sizeHi >> 24) & 255);
+  padlen[1] = (unsigned char)((ctx->sizeHi >> 16) & 255);
+  padlen[2] = (unsigned char)((ctx->sizeHi >> 8) & 255);
+  padlen[3] = (unsigned char)((ctx->sizeHi >> 0) & 255);
+  padlen[4] = (unsigned char)((ctx->sizeLo >> 24) & 255);
+  padlen[5] = (unsigned char)((ctx->sizeLo >> 16) & 255);
+  padlen[6] = (unsigned char)((ctx->sizeLo >> 8) & 255);
+  padlen[7] = (unsigned char)((ctx->sizeLo >> 0) & 255);
+  SHA1_Update(ctx, &pad0x80, 1);
+  while (ctx->lenW != 56)
+    SHA1_Update(ctx, &pad0x00, 1);
+  SHA1_Update(ctx, padlen, 8);
+
+  /* Output hash
+   */
+  for (i = 0; i < 20; i++) {
+    hashout[i] = (unsigned char)(ctx->H[i / 4] >> 24);
+    ctx->H[i / 4] <<= 8;
+  }
+
+  /*
+   *  Re-initialize the context (also zeroizes contents)
+   */
+  SHA1_Init(ctx);
+}
+
+
+#define SHA_ROT(X,n) (((X) << (n)) | ((X) >> (32-(n))))
+
+static void shaHashBlock(SHA_CTX *ctx) {
+  int t;
+  unsigned int A,B,C,D,E,TEMP;
+
+  for (t = 16; t <= 79; t++)
+    ctx->W[t] =
+      SHA_ROT(ctx->W[t-3] ^ ctx->W[t-8] ^ ctx->W[t-14] ^ ctx->W[t-16], 1);
+
+  A = ctx->H[0];
+  B = ctx->H[1];
+  C = ctx->H[2];
+  D = ctx->H[3];
+  E = ctx->H[4];
+
+  for (t = 0; t <= 19; t++) {
+    TEMP = SHA_ROT(A,5) + (((C^D)&B)^D)     + E + ctx->W[t] + 0x5a827999;
+    E = D; D = C; C = SHA_ROT(B, 30); B = A; A = TEMP;
+  }
+  for (t = 20; t <= 39; t++) {
+    TEMP = SHA_ROT(A,5) + (B^C^D)           + E + ctx->W[t] + 0x6ed9eba1;
+    E = D; D = C; C = SHA_ROT(B, 30); B = A; A = TEMP;
+  }
+  for (t = 40; t <= 59; t++) {
+    TEMP = SHA_ROT(A,5) + ((B&C)|(D&(B|C))) + E + ctx->W[t] + 0x8f1bbcdc;
+    E = D; D = C; C = SHA_ROT(B, 30); B = A; A = TEMP;
+  }
+  for (t = 60; t <= 79; t++) {
+    TEMP = SHA_ROT(A,5) + (B^C^D)           + E + ctx->W[t] + 0xca62c1d6;
+    E = D; D = C; C = SHA_ROT(B, 30); B = A; A = TEMP;
+  }
+
+  ctx->H[0] += A;
+  ctx->H[1] += B;
+  ctx->H[2] += C;
+  ctx->H[3] += D;
+  ctx->H[4] += E;
+}

+ 51 - 0
src/sha1.h

@@ -0,0 +1,51 @@
+/*
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * The Original Code is SHA 180-1 Header File
+ *
+ * The Initial Developer of the Original Code is Paul Kocher of
+ * Cryptography Research.  Portions created by Paul Kocher are
+ * Copyright (C) 1995-9 by Cryptography Research, Inc.  All
+ * Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ *     Paul Kocher
+ *
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU General Public License Version 2 or later (the
+ * "GPL"), in which case the provisions of the GPL are applicable
+ * instead of those above.  If you wish to allow use of your
+ * version of this file only under the terms of the GPL and not to
+ * allow others to use your version of this file under the MPL,
+ * indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by
+ * the GPL.  If you do not delete the provisions above, a recipient
+ * may use your version of this file under either the MPL or the
+ * GPL.
+ */
+
+#if !defined(_SHA1_H)
+#define _SHA1_H
+
+#define SHA_DIGEST_LENGTH 20
+
+typedef struct {
+  unsigned int H[5];
+  unsigned int W[80];
+  int lenW;
+  unsigned int sizeHi,sizeLo;
+} SHA_CTX;
+
+void SHA1_Init(SHA_CTX *ctx);
+void SHA1_Update(SHA_CTX *ctx, const void *dataIn, int len);
+void SHA1_Final(unsigned char hashout[20], SHA_CTX *ctx);
+#endif