Home | History | Annotate | Line # | Download | only in tests
packetProcessing.c revision 1.1.1.6
      1  1.1.1.5  christos /*	$NetBSD: packetProcessing.c,v 1.1.1.6 2016/05/01 15:57:23 christos Exp $	*/
      2  1.1.1.5  christos 
      3      1.1  christos #include "config.h"
      4  1.1.1.6  christos 
      5  1.1.1.6  christos /* need autokey for some of the tests, or the will create buffer overruns. */
      6  1.1.1.6  christos #ifndef AUTOKEY
      7  1.1.1.6  christos # define AUTOKEY 1
      8  1.1.1.6  christos #endif
      9  1.1.1.6  christos 
     10      1.1  christos #include "sntptest.h"
     11      1.1  christos #include "networking.h"
     12      1.1  christos #include "ntp_stdlib.h"
     13      1.1  christos #include "unity.h"
     14      1.1  christos 
     15  1.1.1.3  christos 
     16      1.1  christos const char * Version = "stub unit test Version string";
     17      1.1  christos 
     18      1.1  christos // Hacks into the key database.
     19      1.1  christos extern struct key* key_ptr;
     20      1.1  christos extern int key_cnt;
     21      1.1  christos 
     22      1.1  christos 
     23  1.1.1.3  christos void PrepareAuthenticationTest(int key_id,int key_len,const char* type,const void* key_seq);
     24  1.1.1.3  christos void PrepareAuthenticationTestMD5(int key_id,int key_len,const void* key_seq);
     25  1.1.1.3  christos void setUp(void);
     26  1.1.1.3  christos void tearDown(void);
     27  1.1.1.3  christos void test_TooShortLength(void);
     28  1.1.1.3  christos void test_LengthNotMultipleOfFour(void);
     29  1.1.1.3  christos void test_TooShortExtensionFieldLength(void);
     30  1.1.1.3  christos void test_UnauthenticatedPacketReject(void);
     31  1.1.1.3  christos void test_CryptoNAKPacketReject(void);
     32  1.1.1.3  christos void test_AuthenticatedPacketInvalid(void);
     33  1.1.1.3  christos void test_AuthenticatedPacketUnknownKey(void);
     34  1.1.1.3  christos void test_ServerVersionTooOld(void);
     35  1.1.1.3  christos void test_ServerVersionTooNew(void);
     36  1.1.1.3  christos void test_NonWantedMode(void);
     37  1.1.1.3  christos void test_KoDRate(void);
     38  1.1.1.3  christos void test_KoDDeny(void);
     39  1.1.1.3  christos void test_RejectUnsyncedServer(void);
     40  1.1.1.3  christos void test_RejectWrongResponseServerMode(void);
     41  1.1.1.3  christos void test_AcceptNoSentPacketBroadcastMode(void);
     42  1.1.1.3  christos void test_CorrectUnauthenticatedPacket(void);
     43  1.1.1.3  christos void test_CorrectAuthenticatedPacketMD5(void);
     44  1.1.1.3  christos void test_CorrectAuthenticatedPacketSHA1(void);
     45  1.1.1.3  christos 
     46  1.1.1.3  christos 
     47      1.1  christos static struct pkt testpkt;
     48      1.1  christos static struct pkt testspkt;
     49      1.1  christos static sockaddr_u testsock;
     50      1.1  christos bool restoreKeyDb;
     51      1.1  christos 
     52  1.1.1.3  christos 
     53  1.1.1.3  christos void
     54  1.1.1.6  christos PrepareAuthenticationTest(
     55  1.1.1.6  christos 	int		key_id,
     56  1.1.1.6  christos 	int		key_len,
     57  1.1.1.6  christos 	const char *	type,
     58  1.1.1.6  christos 	const void *	key_seq
     59  1.1.1.6  christos 	)
     60  1.1.1.6  christos {
     61      1.1  christos 	char str[25];
     62  1.1.1.3  christos 	snprintf(str, 25, "%d", key_id);
     63      1.1  christos 	ActivateOption("-a", str);
     64      1.1  christos 
     65      1.1  christos 	key_cnt = 1;
     66  1.1.1.3  christos 	key_ptr = emalloc(sizeof(struct key));
     67      1.1  christos 	key_ptr->next = NULL;
     68      1.1  christos 	key_ptr->key_id = key_id;
     69      1.1  christos 	key_ptr->key_len = key_len;
     70      1.1  christos 	memcpy(key_ptr->type, "MD5", 3);
     71      1.1  christos 
     72      1.1  christos 	TEST_ASSERT_TRUE(key_len < sizeof(key_ptr->key_seq));
     73      1.1  christos 
     74      1.1  christos 	memcpy(key_ptr->key_seq, key_seq, key_ptr->key_len);
     75      1.1  christos 	restoreKeyDb = true;
     76      1.1  christos }
     77      1.1  christos 
     78  1.1.1.3  christos 
     79  1.1.1.3  christos void
     80  1.1.1.6  christos PrepareAuthenticationTestMD5(
     81  1.1.1.6  christos 	int 		key_id,
     82  1.1.1.6  christos 	int 		key_len,
     83  1.1.1.6  christos 	const void *	key_seq
     84  1.1.1.6  christos 	)
     85  1.1.1.6  christos {
     86      1.1  christos 	PrepareAuthenticationTest(key_id, key_len, "MD5", key_seq);
     87      1.1  christos }
     88      1.1  christos 
     89  1.1.1.3  christos 
     90  1.1.1.3  christos void
     91  1.1.1.6  christos setUp(void)
     92  1.1.1.6  christos {
     93      1.1  christos 
     94      1.1  christos 	sntptest();
     95      1.1  christos 	restoreKeyDb = false;
     96      1.1  christos 
     97      1.1  christos 	/* Initialize the test packet and socket,
     98  1.1.1.6  christos 	 * so they contain at least some valid data.
     99  1.1.1.6  christos 	 */
    100      1.1  christos 	testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING, NTP_VERSION,
    101      1.1  christos 										MODE_SERVER);
    102      1.1  christos 	testpkt.stratum = STRATUM_REFCLOCK;
    103      1.1  christos 	memcpy(&testpkt.refid, "GPS\0", 4);
    104      1.1  christos 
    105      1.1  christos 	/* Set the origin timestamp of the received packet to the
    106  1.1.1.6  christos 	 * same value as the transmit timestamp of the sent packet.
    107  1.1.1.6  christos 	 */
    108      1.1  christos 	l_fp tmp;
    109      1.1  christos 	tmp.l_ui = 1000UL;
    110      1.1  christos 	tmp.l_uf = 0UL;
    111      1.1  christos 
    112      1.1  christos 	HTONL_FP(&tmp, &testpkt.org);
    113      1.1  christos 	HTONL_FP(&tmp, &testspkt.xmt);
    114      1.1  christos }
    115      1.1  christos 
    116  1.1.1.3  christos 
    117  1.1.1.3  christos void
    118  1.1.1.6  christos tearDown(void)
    119  1.1.1.6  christos {
    120      1.1  christos 	if (restoreKeyDb) {
    121      1.1  christos 		key_cnt = 0;
    122      1.1  christos 		free(key_ptr);
    123      1.1  christos 		key_ptr = NULL;
    124      1.1  christos 	}
    125      1.1  christos 
    126  1.1.1.6  christos 	sntptest_destroy(); /* only on the final test!! if counter == 0 etc... */
    127      1.1  christos }
    128      1.1  christos 
    129      1.1  christos 
    130  1.1.1.3  christos void
    131  1.1.1.6  christos test_TooShortLength(void)
    132  1.1.1.6  christos {
    133      1.1  christos 	TEST_ASSERT_EQUAL(PACKET_UNUSEABLE,
    134      1.1  christos 			  process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC - 1,
    135  1.1.1.6  christos 				      MODE_SERVER, &testspkt, "UnitTest"));
    136      1.1  christos 	TEST_ASSERT_EQUAL(PACKET_UNUSEABLE,
    137      1.1  christos 			  process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC - 1,
    138  1.1.1.6  christos 				      MODE_BROADCAST, &testspkt, "UnitTest"));
    139      1.1  christos }
    140      1.1  christos 
    141  1.1.1.3  christos 
    142  1.1.1.3  christos void
    143  1.1.1.6  christos test_LengthNotMultipleOfFour(void)
    144  1.1.1.6  christos {
    145      1.1  christos 	TEST_ASSERT_EQUAL(PACKET_UNUSEABLE,
    146      1.1  christos 			  process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC + 6,
    147  1.1.1.6  christos 				      MODE_SERVER, &testspkt, "UnitTest"));
    148      1.1  christos 	TEST_ASSERT_EQUAL(PACKET_UNUSEABLE,
    149      1.1  christos 			  process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC + 3,
    150  1.1.1.6  christos 				      MODE_BROADCAST, &testspkt, "UnitTest"));
    151      1.1  christos }
    152      1.1  christos 
    153  1.1.1.3  christos 
    154  1.1.1.3  christos void
    155  1.1.1.6  christos test_TooShortExtensionFieldLength(void)
    156  1.1.1.6  christos {
    157      1.1  christos 	/* The lower 16-bits are the length of the extension field.
    158      1.1  christos 	 * This lengths must be multiples of 4 bytes, which gives
    159  1.1.1.6  christos 	 * a minimum of 4 byte extension field length.
    160  1.1.1.6  christos 	 */
    161  1.1.1.6  christos 	testpkt.exten[7] = htonl(3); /* 3 bytes is too short. */
    162      1.1  christos 
    163      1.1  christos 	/* We send in a pkt_len of header size + 4 byte extension
    164      1.1  christos 	 * header + 24 byte MAC, this prevents the length error to
    165  1.1.1.6  christos 	 * be caught at an earlier stage
    166  1.1.1.6  christos 	 */
    167      1.1  christos 	int pkt_len = LEN_PKT_NOMAC + 4 + 24;
    168      1.1  christos 
    169      1.1  christos 	TEST_ASSERT_EQUAL(PACKET_UNUSEABLE,
    170      1.1  christos 			  process_pkt(&testpkt, &testsock, pkt_len,
    171  1.1.1.6  christos 				      MODE_SERVER, &testspkt, "UnitTest"));
    172      1.1  christos }
    173      1.1  christos 
    174  1.1.1.3  christos 
    175  1.1.1.3  christos void
    176  1.1.1.6  christos test_UnauthenticatedPacketReject(void)
    177  1.1.1.6  christos {
    178  1.1.1.6  christos 	/* Activate authentication option */
    179      1.1  christos 	ActivateOption("-a", "123");
    180      1.1  christos 	TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
    181      1.1  christos 
    182      1.1  christos 	int pkt_len = LEN_PKT_NOMAC;
    183      1.1  christos 
    184  1.1.1.6  christos 	/* We demand authentication, but no MAC header is present. */
    185      1.1  christos 	TEST_ASSERT_EQUAL(SERVER_AUTH_FAIL,
    186      1.1  christos 			  process_pkt(&testpkt, &testsock, pkt_len,
    187  1.1.1.6  christos 				      MODE_SERVER, &testspkt, "UnitTest"));
    188      1.1  christos }
    189      1.1  christos 
    190  1.1.1.3  christos 
    191  1.1.1.3  christos void
    192  1.1.1.6  christos test_CryptoNAKPacketReject(void)
    193  1.1.1.6  christos {
    194  1.1.1.6  christos 	/* Activate authentication option */
    195      1.1  christos 	ActivateOption("-a", "123");
    196      1.1  christos 	TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
    197      1.1  christos 
    198  1.1.1.6  christos 	int pkt_len = LEN_PKT_NOMAC + 4; /* + 4 byte MAC = Crypto-NAK */
    199      1.1  christos 
    200      1.1  christos 	TEST_ASSERT_EQUAL(SERVER_AUTH_FAIL,
    201      1.1  christos 			  process_pkt(&testpkt, &testsock, pkt_len,
    202  1.1.1.6  christos 				      MODE_SERVER, &testspkt, "UnitTest"));
    203      1.1  christos }
    204      1.1  christos 
    205  1.1.1.3  christos 
    206  1.1.1.3  christos void
    207  1.1.1.6  christos test_AuthenticatedPacketInvalid(void)
    208  1.1.1.6  christos {
    209  1.1.1.6  christos 	/* Activate authentication option */
    210      1.1  christos 	PrepareAuthenticationTestMD5(50, 9, "123456789");
    211      1.1  christos 	TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
    212      1.1  christos 
    213  1.1.1.6  christos 	/* Prepare the packet. */
    214      1.1  christos 	int pkt_len = LEN_PKT_NOMAC;
    215      1.1  christos 
    216      1.1  christos 	testpkt.exten[0] = htonl(50);
    217  1.1.1.6  christos 	int mac_len = make_mac(&testpkt, pkt_len,
    218  1.1.1.6  christos 			       MAX_MD5_LEN, key_ptr,
    219  1.1.1.6  christos 			       &testpkt.exten[1]);
    220      1.1  christos 
    221      1.1  christos 	pkt_len += 4 + mac_len;
    222      1.1  christos 
    223  1.1.1.6  christos 	/* Now, alter the MAC so it becomes invalid. */
    224      1.1  christos 	testpkt.exten[1] += 1;
    225      1.1  christos 
    226      1.1  christos 	TEST_ASSERT_EQUAL(SERVER_AUTH_FAIL,
    227      1.1  christos 			  process_pkt(&testpkt, &testsock, pkt_len,
    228  1.1.1.6  christos 				      MODE_SERVER, &testspkt, "UnitTest"));
    229      1.1  christos }
    230      1.1  christos 
    231  1.1.1.3  christos 
    232  1.1.1.3  christos void
    233  1.1.1.6  christos test_AuthenticatedPacketUnknownKey(void)
    234  1.1.1.6  christos {
    235  1.1.1.6  christos 	/* Activate authentication option */
    236      1.1  christos 	PrepareAuthenticationTestMD5(30, 9, "123456789");
    237      1.1  christos 	TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
    238      1.1  christos 
    239  1.1.1.6  christos 	/* Prepare the packet. Note that the Key-ID expected is 30, but
    240  1.1.1.6  christos 	 * the packet has a key id of 50.
    241  1.1.1.6  christos 	 */
    242      1.1  christos 	int pkt_len = LEN_PKT_NOMAC;
    243      1.1  christos 
    244      1.1  christos 	testpkt.exten[0] = htonl(50);
    245  1.1.1.6  christos 	int mac_len = make_mac(&testpkt, pkt_len,
    246  1.1.1.6  christos 			       MAX_MD5_LEN, key_ptr,
    247  1.1.1.6  christos 			       &testpkt.exten[1]);
    248      1.1  christos 	pkt_len += 4 + mac_len;
    249      1.1  christos 
    250      1.1  christos 	TEST_ASSERT_EQUAL(SERVER_AUTH_FAIL,
    251      1.1  christos 			  process_pkt(&testpkt, &testsock, pkt_len,
    252  1.1.1.6  christos 				      MODE_SERVER, &testspkt, "UnitTest"));
    253      1.1  christos }
    254      1.1  christos 
    255  1.1.1.3  christos 
    256  1.1.1.3  christos void
    257  1.1.1.6  christos test_ServerVersionTooOld(void)
    258  1.1.1.6  christos {
    259      1.1  christos 	TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
    260      1.1  christos 
    261      1.1  christos 	testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING,
    262  1.1.1.6  christos 					    NTP_OLDVERSION - 1,
    263  1.1.1.6  christos 					    MODE_CLIENT);
    264      1.1  christos 	TEST_ASSERT_TRUE(PKT_VERSION(testpkt.li_vn_mode) < NTP_OLDVERSION);
    265      1.1  christos 
    266      1.1  christos 	int pkt_len = LEN_PKT_NOMAC;
    267      1.1  christos 
    268      1.1  christos 	TEST_ASSERT_EQUAL(SERVER_UNUSEABLE,
    269      1.1  christos 			  process_pkt(&testpkt, &testsock, pkt_len,
    270  1.1.1.6  christos 				      MODE_SERVER, &testspkt, "UnitTest"));
    271      1.1  christos }
    272      1.1  christos 
    273  1.1.1.3  christos 
    274  1.1.1.3  christos void
    275  1.1.1.6  christos test_ServerVersionTooNew(void)
    276  1.1.1.6  christos {
    277      1.1  christos 	TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
    278      1.1  christos 
    279      1.1  christos 	testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING,
    280  1.1.1.6  christos 					    NTP_VERSION + 1,
    281  1.1.1.6  christos 					    MODE_CLIENT);
    282      1.1  christos 	TEST_ASSERT_TRUE(PKT_VERSION(testpkt.li_vn_mode) > NTP_VERSION);
    283      1.1  christos 
    284      1.1  christos 	int pkt_len = LEN_PKT_NOMAC;
    285      1.1  christos 
    286      1.1  christos 	TEST_ASSERT_EQUAL(SERVER_UNUSEABLE,
    287      1.1  christos 			  process_pkt(&testpkt, &testsock, pkt_len,
    288  1.1.1.6  christos 				      MODE_SERVER, &testspkt, "UnitTest"));
    289      1.1  christos }
    290      1.1  christos 
    291  1.1.1.3  christos 
    292  1.1.1.3  christos void
    293  1.1.1.6  christos test_NonWantedMode(void)
    294  1.1.1.6  christos {
    295      1.1  christos 	TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
    296      1.1  christos 
    297      1.1  christos 	testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING,
    298  1.1.1.6  christos 					    NTP_VERSION,
    299  1.1.1.6  christos 					    MODE_CLIENT);
    300      1.1  christos 
    301  1.1.1.6  christos 	/* The packet has a mode of MODE_CLIENT, but process_pkt expects
    302  1.1.1.6  christos 	 * MODE_SERVER
    303  1.1.1.6  christos 	 */
    304      1.1  christos 	TEST_ASSERT_EQUAL(SERVER_UNUSEABLE,
    305      1.1  christos 			  process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC,
    306  1.1.1.6  christos 				      MODE_SERVER, &testspkt, "UnitTest"));
    307      1.1  christos }
    308      1.1  christos 
    309  1.1.1.3  christos 
    310      1.1  christos /* Tests bug 1597 */
    311  1.1.1.3  christos void
    312  1.1.1.6  christos test_KoDRate(void)
    313  1.1.1.6  christos {
    314      1.1  christos 	TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
    315      1.1  christos 
    316      1.1  christos 	testpkt.stratum = STRATUM_PKT_UNSPEC;
    317      1.1  christos 	memcpy(&testpkt.refid, "RATE", 4);
    318      1.1  christos 
    319      1.1  christos 	TEST_ASSERT_EQUAL(KOD_RATE,
    320      1.1  christos 			  process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC,
    321  1.1.1.6  christos 				      MODE_SERVER, &testspkt, "UnitTest"));
    322      1.1  christos }
    323      1.1  christos 
    324  1.1.1.3  christos 
    325  1.1.1.3  christos void
    326  1.1.1.6  christos test_KoDDeny(void)
    327  1.1.1.6  christos {
    328      1.1  christos 	TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
    329      1.1  christos 
    330      1.1  christos 	testpkt.stratum = STRATUM_PKT_UNSPEC;
    331      1.1  christos 	memcpy(&testpkt.refid, "DENY", 4);
    332      1.1  christos 
    333      1.1  christos 	TEST_ASSERT_EQUAL(KOD_DEMOBILIZE,
    334      1.1  christos 			  process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC,
    335  1.1.1.6  christos 				      MODE_SERVER, &testspkt, "UnitTest"));
    336      1.1  christos }
    337      1.1  christos 
    338  1.1.1.3  christos 
    339  1.1.1.3  christos void
    340  1.1.1.6  christos test_RejectUnsyncedServer(void)
    341  1.1.1.6  christos {
    342      1.1  christos 	TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
    343      1.1  christos 
    344      1.1  christos 	testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOTINSYNC,
    345  1.1.1.6  christos 					    NTP_VERSION,
    346  1.1.1.6  christos 					    MODE_SERVER);
    347      1.1  christos 
    348      1.1  christos 	TEST_ASSERT_EQUAL(SERVER_UNUSEABLE,
    349      1.1  christos 			  process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC,
    350  1.1.1.6  christos 				      MODE_SERVER, &testspkt, "UnitTest"));
    351      1.1  christos }
    352      1.1  christos 
    353  1.1.1.3  christos 
    354  1.1.1.3  christos void
    355  1.1.1.6  christos test_RejectWrongResponseServerMode(void)
    356  1.1.1.6  christos {
    357      1.1  christos 	TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
    358      1.1  christos 
    359      1.1  christos 	l_fp tmp;
    360      1.1  christos 	tmp.l_ui = 1000UL;
    361      1.1  christos 	tmp.l_uf = 0UL;
    362      1.1  christos 	HTONL_FP(&tmp, &testpkt.org);
    363      1.1  christos 
    364      1.1  christos 	tmp.l_ui = 2000UL;
    365      1.1  christos 	tmp.l_uf = 0UL;
    366      1.1  christos 	HTONL_FP(&tmp, &testspkt.xmt);
    367      1.1  christos 
    368      1.1  christos 	TEST_ASSERT_EQUAL(PACKET_UNUSEABLE,
    369      1.1  christos 			  process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC,
    370  1.1.1.6  christos 				      MODE_SERVER, &testspkt, "UnitTest"));
    371      1.1  christos }
    372      1.1  christos 
    373  1.1.1.3  christos 
    374  1.1.1.3  christos void
    375  1.1.1.6  christos test_AcceptNoSentPacketBroadcastMode(void)
    376  1.1.1.6  christos {
    377      1.1  christos 	TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
    378      1.1  christos 
    379      1.1  christos 	testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING,
    380      1.1  christos 					    NTP_VERSION,
    381      1.1  christos 					    MODE_BROADCAST);
    382      1.1  christos 
    383      1.1  christos 	TEST_ASSERT_EQUAL(LEN_PKT_NOMAC,
    384      1.1  christos 		  process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC,
    385      1.1  christos 			      MODE_BROADCAST, NULL, "UnitTest"));
    386      1.1  christos }
    387      1.1  christos 
    388  1.1.1.3  christos 
    389  1.1.1.3  christos void
    390  1.1.1.6  christos test_CorrectUnauthenticatedPacket(void)
    391  1.1.1.6  christos {
    392      1.1  christos 	TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
    393      1.1  christos 
    394      1.1  christos 	TEST_ASSERT_EQUAL(LEN_PKT_NOMAC,
    395      1.1  christos 			  process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC,
    396  1.1.1.6  christos 				      MODE_SERVER, &testspkt, "UnitTest"));
    397      1.1  christos }
    398      1.1  christos 
    399  1.1.1.3  christos 
    400  1.1.1.3  christos void
    401  1.1.1.6  christos test_CorrectAuthenticatedPacketMD5(void)
    402  1.1.1.6  christos {
    403      1.1  christos 	PrepareAuthenticationTestMD5(10, 15, "123456789abcdef");
    404      1.1  christos 	TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
    405      1.1  christos 
    406      1.1  christos 	int pkt_len = LEN_PKT_NOMAC;
    407      1.1  christos 
    408  1.1.1.6  christos 	/* Prepare the packet. */
    409      1.1  christos 	testpkt.exten[0] = htonl(10);
    410  1.1.1.6  christos 	int mac_len = make_mac(&testpkt, pkt_len,
    411  1.1.1.6  christos 			       MAX_MD5_LEN, key_ptr,
    412  1.1.1.6  christos 			       &testpkt.exten[1]);
    413      1.1  christos 
    414      1.1  christos 	pkt_len += 4 + mac_len;
    415      1.1  christos 
    416      1.1  christos 	TEST_ASSERT_EQUAL(pkt_len,
    417      1.1  christos 			  process_pkt(&testpkt, &testsock, pkt_len,
    418  1.1.1.6  christos 				      MODE_SERVER, &testspkt, "UnitTest"));
    419      1.1  christos }
    420      1.1  christos 
    421  1.1.1.3  christos 
    422  1.1.1.3  christos void
    423  1.1.1.6  christos test_CorrectAuthenticatedPacketSHA1(void)
    424  1.1.1.6  christos {
    425      1.1  christos 	PrepareAuthenticationTest(20, 15, "SHA1", "abcdefghijklmno");
    426      1.1  christos 	TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
    427      1.1  christos 
    428      1.1  christos 	int pkt_len = LEN_PKT_NOMAC;
    429      1.1  christos 
    430  1.1.1.6  christos 	/* Prepare the packet. */
    431      1.1  christos 	testpkt.exten[0] = htonl(20);
    432  1.1.1.6  christos 	int mac_len = make_mac(&testpkt, pkt_len,
    433  1.1.1.6  christos 			       MAX_MAC_LEN, key_ptr,
    434  1.1.1.6  christos 			       &testpkt.exten[1]);
    435      1.1  christos 
    436      1.1  christos 	pkt_len += 4 + mac_len;
    437      1.1  christos 
    438      1.1  christos 	TEST_ASSERT_EQUAL(pkt_len,
    439      1.1  christos 			  process_pkt(&testpkt, &testsock, pkt_len,
    440  1.1.1.6  christos 				      MODE_SERVER, &testspkt, "UnitTest"));
    441      1.1  christos }
    442