00001 /*************************************************************************** 00002 * _ _ ____ _ 00003 * Project ___| | | | _ \| | 00004 * / __| | | | |_) | | 00005 * | (__| |_| | _ <| |___ 00006 * \___|\___/|_| \_\_____| 00007 * 00008 * Copyright (C) 2015, Steve Holme, <steve_holme@hotmail.com>. 00009 * 00010 * This software is licensed as described in the file COPYING, which 00011 * you should have received as part of this distribution. The terms 00012 * are also available at https://curl.haxx.se/docs/copyright.html. 00013 * 00014 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 00015 * copies of the Software, and permit persons to whom the Software is 00016 * furnished to do so, under the terms of the COPYING file. 00017 * 00018 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 00019 * KIND, either express or implied. 00020 * 00021 ***************************************************************************/ 00022 00023 #include "curl_setup.h" 00024 00025 #if defined(USE_NTLM) && !defined(USE_OPENSSL) 00026 00027 #include "curl_des.h" 00028 00029 /* 00030 * Curl_des_set_odd_parity() 00031 * 00032 * This is used to apply odd parity to the given byte array. It is typically 00033 * used by when a cryptography engines doesn't have it's own version. 00034 * 00035 * The function is a port of the Java based oddParity() function over at: 00036 * 00037 * http://davenport.sourceforge.net/ntlm.html 00038 * 00039 * Parameters: 00040 * 00041 * bytes [in/out] - The data whose parity bits are to be adjusted for 00042 * odd parity. 00043 * len [out] - The length of the data. 00044 */ 00045 void Curl_des_set_odd_parity(unsigned char *bytes, size_t len) 00046 { 00047 size_t i; 00048 00049 for(i = 0; i < len; i++) { 00050 unsigned char b = bytes[i]; 00051 00052 bool needs_parity = (((b >> 7) ^ (b >> 6) ^ (b >> 5) ^ 00053 (b >> 4) ^ (b >> 3) ^ (b >> 2) ^ 00054 (b >> 1)) & 0x01) == 0; 00055 00056 if(needs_parity) 00057 bytes[i] |= 0x01; 00058 else 00059 bytes[i] &= 0xfe; 00060 } 00061 } 00062 00063 #endif /* USE_NTLM && !USE_OPENSSL */