/***************************************************************************1* _ _ ____ _2* Project ___| | | | _ \| |3* / __| | | | |_) | |4* | (__| |_| | _ <| |___5* \___|\___/|_| \_\_____|6*7* Copyright (C) Steve Holme, <[email protected]>.8*9* This software is licensed as described in the file COPYING, which10* you should have received as part of this distribution. The terms11* are also available at https://curl.se/docs/copyright.html.12*13* You may opt to use, copy, modify, merge, publish, distribute and/or sell14* copies of the Software, and permit persons to whom the Software is15* furnished to do so, under the terms of the COPYING file.16*17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY18* KIND, either express or implied.19*20* SPDX-License-Identifier: curl21*22***************************************************************************/2324#include "curl_setup.h"2526#if defined(USE_CURL_NTLM_CORE) && \27(defined(USE_GNUTLS) || \28defined(USE_SECTRANSP) || \29defined(USE_OS400CRYPTO) || \30defined(USE_WIN32_CRYPTO))3132#include "curl_des.h"3334/*35* Curl_des_set_odd_parity()36*37* This is used to apply odd parity to the given byte array. It is typically38* used by when a cryptography engine does not have its own version.39*40* The function is a port of the Java based oddParity() function over at:41*42* https://davenport.sourceforge.net/ntlm.html43*44* Parameters:45*46* bytes [in/out] - The data whose parity bits are to be adjusted for47* odd parity.48* len [out] - The length of the data.49*/50void Curl_des_set_odd_parity(unsigned char *bytes, size_t len)51{52size_t i;5354for(i = 0; i < len; i++) {55unsigned char b = bytes[i];5657bool needs_parity = (((b >> 7) ^ (b >> 6) ^ (b >> 5) ^58(b >> 4) ^ (b >> 3) ^ (b >> 2) ^59(b >> 1)) & 0x01) == 0;6061if(needs_parity)62bytes[i] |= 0x01;63else64bytes[i] &= 0xfe;65}66}6768#endif697071