]> granicus.if.org Git - curl/commitdiff
des: Added Curl_des_set_odd_parity()
authorSteve Holme <steve_holme@hotmail.com>
Wed, 28 Jan 2015 20:43:32 +0000 (20:43 +0000)
committerSteve Holme <steve_holme@hotmail.com>
Wed, 28 Jan 2015 22:34:49 +0000 (22:34 +0000)
Added Curl_des_set_odd_parity() for use when cryptography engines
don't include this functionality.

lib/Makefile.inc
lib/Makefile.vc6
lib/curl_des.c [new file with mode: 0644]
lib/curl_des.h [new file with mode: 0644]
packages/Symbian/group/libcurl.mmp

index 8f9d16d8b9749379aed7b84e737631f2971c5cb9..4f81cd07b82c56ce654a541173d9ca53b0bcb106 100644 (file)
@@ -5,7 +5,7 @@
 #                            | (__| |_| |  _ <| |___
 #                             \___|\___/|_| \_\_____|
 #
-# Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
+# Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
 #
 # This software is licensed as described in the file COPYING, which
 # you should have received as part of this distribution. The terms
@@ -45,7 +45,8 @@ LIB_CFILES = file.c timeval.c base64.c hostip.c progress.c formdata.c   \
   asyn-thread.c curl_gssapi.c curl_ntlm.c curl_ntlm_wb.c                \
   curl_ntlm_core.c curl_ntlm_msgs.c curl_sasl.c curl_multibyte.c        \
   hostcheck.c bundles.c conncache.c pipeline.c dotdot.c x509asn1.c      \
-  http2.c curl_sasl_sspi.c smb.c curl_sasl_gssapi.c curl_endian.c
+  http2.c curl_sasl_sspi.c smb.c curl_sasl_gssapi.c curl_endian.c       \
+  curl_des.c
 
 LIB_HFILES = arpa_telnet.h netrc.h file.h timeval.h hostip.h progress.h \
   formdata.h cookie.h http.h sendf.h ftp.h url.h dict.h if2ip.h         \
@@ -63,7 +64,7 @@ LIB_HFILES = arpa_telnet.h netrc.h file.h timeval.h hostip.h progress.h \
   curl_ntlm.h curl_gssapi.h curl_ntlm_wb.h curl_ntlm_core.h             \
   curl_ntlm_msgs.h curl_sasl.h curl_multibyte.h hostcheck.h bundles.h   \
   conncache.h curl_setup_once.h multihandle.h setup-vms.h pipeline.h    \
-  dotdot.h x509asn1.h http2.h sigpipe.h smb.h curl_endian.h
+  dotdot.h x509asn1.h http2.h sigpipe.h smb.h curl_endian.h curl_des.h
 
 LIB_RCFILES = libcurl.rc
 
index ee20ebe123a25832a05b80d1552e90cf064d9ea4..8e0314604dbf9ba073d4d2bab95e4116d10515f9 100644 (file)
@@ -5,7 +5,7 @@
 #                            | (__| |_| |  _ <| |___\r
 #                             \___|\___/|_| \_\_____|\r
 #\r
-# Copyright (C) 1999 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.\r
+# Copyright (C) 1999 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.\r
 #\r
 # This software is licensed as described in the file COPYING, which\r
 # you should have received as part of this distribution. The terms\r
@@ -535,6 +535,7 @@ X_OBJS= \
        $(DIROBJ)\cookie.obj \\r
        $(DIROBJ)\curl_addrinfo.obj \\r
        $(DIROBJ)\curl_darwinssl.obj \\r
+       $(DIROBJ)\curl_des.obj \\r
        $(DIROBJ)\curl_endian.obj \\r
        $(DIROBJ)\curl_fnmatch.obj \\r
        $(DIROBJ)\curl_gethostname.obj \\r
diff --git a/lib/curl_des.c b/lib/curl_des.c
new file mode 100644 (file)
index 0000000..ba62496
--- /dev/null
@@ -0,0 +1,63 @@
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 2015, Steve Holme, <steve_holme@hotmail.com>.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+
+#include "curl_setup.h"
+
+#if defined(USE_NTLM) && (!defined(USE_SSLEAY) || defined(HAVE_BORINGSSL))
+
+#include "curl_des.h"
+
+/*
+ * Curl_des_set_odd_parity()
+ *
+ * This is used to apply odd parity to the given byte array. It is typically
+ * used by when a cryptography engines doesn't have it's own version.
+ *
+ * The function is a port of the Java based oddParity() function over at:
+ *
+ * http://davenport.sourceforge.net/ntlm.html
+ *
+ * Parameters:
+ *
+ * bytes       [in/out] - The data whose parity bits are to be adjusted for
+ *                        odd parity.
+ * len         [out]    - The length of the data.
+ */
+void Curl_des_set_odd_parity(unsigned char *bytes, size_t len)
+{
+  size_t i;
+
+  for(i = 0; i < len; i++) {
+    unsigned char b = bytes[i];
+
+    bool needs_parity = (((b >> 7) ^ (b >> 6) ^ (b >> 5) ^
+                          (b >> 4) ^ (b >> 3) ^ (b >> 2) ^
+                          (b >> 1)) & 0x01) == 0;
+
+    if(needs_parity)
+      bytes[i] |= 0x01;
+    else
+      bytes[i] &= 0xfe;
+  }
+}
+
+#endif /* USE_NTLM && (!USE_SSLEAY || HAVE_BORINGSSL) */
diff --git a/lib/curl_des.h b/lib/curl_des.h
new file mode 100644 (file)
index 0000000..11a2eca
--- /dev/null
@@ -0,0 +1,34 @@
+#ifndef HEADER_CURL_DES_H
+#define HEADER_CURL_DES_H
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 2015, Steve Holme, <steve_holme@hotmail.com>.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+
+#include "curl_setup.h"
+
+#if defined(USE_NTLM) && (!defined(USE_SSLEAY) || defined(HAVE_BORINGSSL))
+
+/* Applies odd parity to the given byte array */
+void Curl_des_set_odd_parity(unsigned char *bytes, size_t length);
+
+#endif /* USE_NTLM && (!USE_SSLEAY || HAVE_BORINGSSL) */
+
+#endif /* HEADER_CURL_DES_H */
index 2419c206cc7e7126daf5451e9a2d41bc719e0377..3b7303aea358242587661bb9221d03cc51346501 100644 (file)
@@ -40,7 +40,7 @@ SOURCE \
   curl_ntlm.c curl_ntlm_wb.c curl_ntlm_core.c curl_ntlm_msgs.c         \
   curl_sasl.c vtls/curl_schannel.c curl_multibyte.c                    \
   vtls/curl_darwinssl.c bundles.c conncache.c curl_sasl_sspi.c smb.c   \
-  curl_sasl_gssapi.c curl_endian.c
+  curl_sasl_gssapi.c curl_endian.c curl_des.c
 
 USERINCLUDE   ../../../lib ../../../include/curl
 #ifdef ENABLE_SSL