Home | History | Annotate | Download | only in tests
      1 /*
      2  * Test program for ms_funcs
      3  * Copyright (c) 2003-2006, Jouni Malinen <j (at) w1.fi>
      4  *
      5  * This program is free software; you can redistribute it and/or modify
      6  * it under the terms of the GNU General Public License version 2 as
      7  * published by the Free Software Foundation.
      8  *
      9  * Alternatively, this software may be distributed under the terms of BSD
     10  * license.
     11  *
     12  * See README and COPYING for more details.
     13  */
     14 
     15 #include "ms_funcs.c"
     16 
     17 
     18 int main(int argc, char *argv[])
     19 {
     20 	/* Test vector from RFC2759 example */
     21 	u8 *username = "User";
     22 	u8 *password = "clientPass";
     23 	u8 auth_challenge[] = {
     24 		0x5B, 0x5D, 0x7C, 0x7D, 0x7B, 0x3F, 0x2F, 0x3E,
     25 		0x3C, 0x2C, 0x60, 0x21, 0x32, 0x26, 0x26, 0x28
     26 	};
     27 	u8 peer_challenge[] = {
     28 		0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A,
     29 		0x28, 0x29, 0x5F, 0x2B, 0x3A, 0x33, 0x7C, 0x7E
     30 	};
     31 	u8 challenge[] = { 0xD0, 0x2E, 0x43, 0x86, 0xBC, 0xE9, 0x12, 0x26 };
     32 	u8 password_hash[] = {
     33 		0x44, 0xEB, 0xBA, 0x8D, 0x53, 0x12, 0xB8, 0xD6,
     34 		0x11, 0x47, 0x44, 0x11, 0xF5, 0x69, 0x89, 0xAE
     35 	};
     36 	u8 nt_response[] = {
     37 		0x82, 0x30, 0x9E, 0xCD, 0x8D, 0x70, 0x8B, 0x5E,
     38 		0xA0, 0x8F, 0xAA, 0x39, 0x81, 0xCD, 0x83, 0x54,
     39 		0x42, 0x33, 0x11, 0x4A, 0x3D, 0x85, 0xD6, 0xDF
     40 	};
     41 	u8 password_hash_hash[] = {
     42 		0x41, 0xC0, 0x0C, 0x58, 0x4B, 0xD2, 0xD9, 0x1C,
     43 		0x40, 0x17, 0xA2, 0xA1, 0x2F, 0xA5, 0x9F, 0x3F
     44 	};
     45 	u8 authenticator_response[] = {
     46 		0x40, 0x7A, 0x55, 0x89, 0x11, 0x5F, 0xD0, 0xD6,
     47 		0x20, 0x9F, 0x51, 0x0F, 0xE9, 0xC0, 0x45, 0x66,
     48 		0x93, 0x2C, 0xDA, 0x56
     49 	};
     50 	u8 master_key[] = {
     51 		0xFD, 0xEC, 0xE3, 0x71, 0x7A, 0x8C, 0x83, 0x8C,
     52 		0xB3, 0x88, 0xE5, 0x27, 0xAE, 0x3C, 0xDD, 0x31
     53 	};
     54 	u8 send_start_key[] = {
     55 		0x8B, 0x7C, 0xDC, 0x14, 0x9B, 0x99, 0x3A, 0x1B,
     56 		0xA1, 0x18, 0xCB, 0x15, 0x3F, 0x56, 0xDC, 0xCB
     57 	};
     58 	u8 buf[32];
     59 
     60 	int errors = 0;
     61 
     62 	printf("Testing ms_funcs.c\n");
     63 
     64 	challenge_hash(peer_challenge, auth_challenge,
     65 		       username, strlen(username),
     66 		       buf);
     67 	if (memcmp(challenge, buf, sizeof(challenge)) != 0) {
     68 		printf("challenge_hash failed\n");
     69 		errors++;
     70 	}
     71 
     72 	nt_password_hash(password, strlen(password), buf);
     73 	if (memcmp(password_hash, buf, sizeof(password_hash)) != 0) {
     74 		printf("nt_password_hash failed\n");
     75 		errors++;
     76 	}
     77 
     78 	generate_nt_response(auth_challenge, peer_challenge,
     79 			     username, strlen(username),
     80 			     password, strlen(password),
     81 			     buf);
     82 	if (memcmp(nt_response, buf, sizeof(nt_response)) != 0) {
     83 		printf("generate_nt_response failed\n");
     84 		errors++;
     85 	}
     86 
     87 	hash_nt_password_hash(password_hash, buf);
     88 	if (memcmp(password_hash_hash, buf, sizeof(password_hash_hash)) != 0) {
     89 		printf("hash_nt_password_hash failed\n");
     90 		errors++;
     91 	}
     92 
     93 	generate_authenticator_response(password, strlen(password),
     94 					peer_challenge, auth_challenge,
     95 					username, strlen(username),
     96 					nt_response, buf);
     97 	if (memcmp(authenticator_response, buf, sizeof(authenticator_response))
     98 	    != 0) {
     99 		printf("generate_authenticator_response failed\n");
    100 		errors++;
    101 	}
    102 
    103 	get_master_key(password_hash_hash, nt_response, buf);
    104 	if (memcmp(master_key, buf, sizeof(master_key)) != 0) {
    105 		printf("get_master_key failed\n");
    106 		errors++;
    107 	}
    108 
    109 	get_asymetric_start_key(master_key, buf, sizeof(send_start_key), 1, 1);
    110 	if (memcmp(send_start_key, buf, sizeof(send_start_key)) != 0) {
    111 		printf("get_asymetric_start_key failed\n");
    112 		errors++;
    113 	}
    114 
    115 	if (errors)
    116 		printf("FAILED! %d errors\n", errors);
    117 
    118 	return errors;
    119 }
    120