| 1 | /*- |
| 2 | * Copyright (c) 1998-1999 Whistle Communications, Inc. |
| 3 | * Copyright (c) 1998-1999 Archie Cobbs <[email protected]> |
| 4 | * Copyright (c) 2003 Michael Bretterklieber |
| 5 | * Copyright (c) 2017-2019 Björn Esser <[email protected]> |
| 6 | * Copyright (c) 2017-2019 Zack Weinberg <zackw at panix.com> |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Redistribution and use in source and binary forms, with or without |
| 10 | * modification, are permitted provided that the following conditions |
| 11 | * are met: |
| 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in the |
| 16 | * documentation and/or other materials provided with the distribution. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 28 | * SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include "crypt-port.h"cxx . . $ `<file>/lib/crypt-port.h`/ |
| 32 | |
| 33 | #if INCLUDE_ntcxx . . $ `crypt-hashes.h:15:9`! |
| 34 | |
| 35 | #include "alg-md4.h"cxx . . $ `<file>/lib/alg-md4.h`/ |
| 36 | |
| 37 | #include <errno.h> |
| 38 | #include <stdlib.h> |
| 39 | |
| 40 | #define MD4_HASHLENcxx . . $ `lib/crypt-nthash.c:40:9`! 16 |
| 41 | |
| 42 | typedef structcxx . . $ $anonymous_type_d098a5fd2deeb429_0# |
| 43 | { |
| 44 | MD4_CTXcxx . . $ MD4_CTX# ctxcxx . . $ $anonymous_type_d098a5fd2deeb429_0#ctx.; |
| 45 | uint8_tcxx . . $ uint8_t# unipwcxx . . $ $anonymous_type_d098a5fd2deeb429_0#unipw.[CRYPT_MAX_PASSPHRASE_SIZEcxx . . $ `crypt.h:36:9`! * 2]; |
| 46 | unsigned char hashcxx . . $ $anonymous_type_d098a5fd2deeb429_0#hash.[MD4_HASHLENcxx . . $ `lib/crypt-nthash.c:40:9`!]; |
| 47 | } crypt_nt_internal_tcxx . . $ crypt_nt_internal_t#; |
| 48 | |
| 49 | static_assertcxx . . $ `<external>/4398592474888995393/assert.h:210:10`! (sizeof (crypt_nt_internal_tcxx . . $ crypt_nt_internal_t#) <= ALG_SPECIFIC_SIZEcxx . . $ `lib/crypt-port.h:510:9`!, |
| 50 | "ALG_SPECIFIC_SIZE is too small for NTHASH."); |
| 51 | |
| 52 | /* |
| 53 | * NT HASH = md4(str2unicode(phrase)) |
| 54 | */ |
| 55 | |
| 56 | void |
| 57 | crypt_nt_rncxx . . $ `crypt-hashes.h:44:9`! (const char *phrase, size_t phr_size, |
| 58 | const char *setting, size_t ARG_UNUSEDcxx . . $ `lib/crypt-port.h:78:10`! (set_size), |
| 59 | uint8_tcxx . . $ uint8_t# *output, size_t out_size, |
| 60 | void *scratch, size_t scr_size) |
| 61 | { |
| 62 | static const char *magic = "$3$"; |
| 63 | static const uint8_tcxx . . $ uint8_t# *hexconvtab = (const uint8_tcxx . . $ uint8_t#*) "0123456789abcdef"; |
| 64 | |
| 65 | if ((out_size < strlencxx . . $ strlen(751346f8406fd082). (magic) + MD4_HASHLENcxx . . $ `lib/crypt-nthash.c:40:9`! * 2 + 1) || |
| 66 | (scr_size < sizeof (crypt_nt_internal_tcxx . . $ crypt_nt_internal_t#))) |
| 67 | { |
| 68 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = ERANGEcxx . . $ `<external>/8987895939074593727/errno-base.h:38:9`!; |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | if (strncmpcxx . . $ strncmp(fd278af2f295fa2e). (setting, magic, strlencxx . . $ strlen(751346f8406fd082). (magic))) |
| 73 | { |
| 74 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | crypt_nt_internal_tcxx . . $ crypt_nt_internal_t# *intbuf = scratch; |
| 79 | |
| 80 | /* Convert the input to UCS-2LE, blindly assuming that it was |
| 81 | IANA ISO_8859-1:1987 to begin with (i.e. 0x00 .. 0xFF |
| 82 | encode U+0000 .. U+FFFF; technically this is a superset |
| 83 | of the original ISO 8859.1). Note that this does not |
| 84 | U+0000-terminate intbuf->unipw. */ |
| 85 | for (size_t i = 0; i < phr_size; i++) |
| 86 | { |
| 87 | intbuf->unipwcxx . . $ $anonymous_type_d098a5fd2deeb429_0#unipw.[2*i ] = (uint8_tcxx . . $ uint8_t#)phrase[i]; |
| 88 | intbuf->unipwcxx . . $ $anonymous_type_d098a5fd2deeb429_0#unipw.[2*i + 1] = 0x00; |
| 89 | } |
| 90 | |
| 91 | /* Compute MD4 of Unicode password. */ |
| 92 | MD4_Initcxx . . $ `lib/crypt-port.h:344:9`! (&intbuf->ctxcxx . . $ $anonymous_type_d098a5fd2deeb429_0#ctx.); |
| 93 | MD4_Updatecxx . . $ `lib/crypt-port.h:345:9`! (&intbuf->ctxcxx . . $ $anonymous_type_d098a5fd2deeb429_0#ctx., intbuf->unipwcxx . . $ $anonymous_type_d098a5fd2deeb429_0#unipw., phr_size * 2); |
| 94 | MD4_Finalcxx . . $ `lib/crypt-port.h:346:9`! (intbuf->hashcxx . . $ $anonymous_type_d098a5fd2deeb429_0#hash., &intbuf->ctxcxx . . $ $anonymous_type_d098a5fd2deeb429_0#ctx.); |
| 95 | |
| 96 | /* Write the computed hash to the output buffer. */ |
| 97 | output += strcpy_or_abortcxx . . $ `lib/crypt-port.h:188:9`! (output, out_size, magic); |
| 98 | *output++ = '$'; |
| 99 | for (size_t i = 0; i < MD4_HASHLENcxx . . $ `lib/crypt-nthash.c:40:9`!; i++) |
| 100 | { |
| 101 | *output++ = hexconvtab[intbuf->hashcxx . . $ $anonymous_type_d098a5fd2deeb429_0#hash.[i] >> 4]; |
| 102 | *output++ = hexconvtab[intbuf->hashcxx . . $ $anonymous_type_d098a5fd2deeb429_0#hash.[i] & 0xf]; |
| 103 | } |
| 104 | *output = '\0'; |
| 105 | } |
| 106 | |
| 107 | /* This function simply returns the magic string '$3$', |
| 108 | so it can be used as SETTING for the crypt function. */ |
| 109 | void |
| 110 | gensalt_nt_rncxx . . $ `crypt-hashes.h:45:9`! (unsigned long count, |
| 111 | ARG_UNUSEDcxx . . $ `lib/crypt-port.h:78:10`!(const uint8_t *rbytes), |
| 112 | ARG_UNUSEDcxx . . $ `lib/crypt-port.h:78:10`!(size_t nrbytes), |
| 113 | uint8_tcxx . . $ uint8_t# *output, |
| 114 | size_t o_size) |
| 115 | { |
| 116 | const char *prefix = "$3$"; |
| 117 | |
| 118 | /* Minimal O_SIZE to store the prefix. */ |
| 119 | if (o_size < strlencxx . . $ strlen(751346f8406fd082). (prefix) + 1) |
| 120 | { |
| 121 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = ERANGEcxx . . $ `<external>/8987895939074593727/errno-base.h:38:9`!; |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | if (count != 0) |
| 126 | { |
| 127 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | strcpy_or_abortcxx . . $ `lib/crypt-port.h:188:9`! (output, o_size, prefix); |
| 132 | } |
| 133 | |
| 134 | #endif |