[Git][NTPsec/ntpsec][master] 2 commits: remove nts_lib, lint

Eric S. Raymond gitlab at mg.gitlab.com
Sat Feb 23 17:24:03 UTC 2019


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
a3a7440d by James Browning at 2019-02-23T16:54:20Z
remove nts_lib, lint

- - - - -
b3fd5384 by James Browning at 2019-02-23T16:54:34Z
theory based test replacements

- - - - -


8 changed files:

- include/nts.h
- − include/nts_lib.h
- − ntpd/nts_lib.c
- ntpd/wscript
- tests/common/tests_main.c
- tests/ntpd/nts.c
- − tests/ntpd/nts_lib.c
- tests/wscript


Changes:

=====================================
include/nts.h
=====================================
@@ -5,6 +5,7 @@
 #define GUARD_NTS_H
 
 #include <stdbool.h>
+#include <stdint.h>
 #include <openssl/ssl.h>
 
 #define NTS_MAX_KEYLEN		64	/* used in cookies */


=====================================
include/nts_lib.h deleted
=====================================
@@ -1,58 +0,0 @@
-#ifndef GUARD_NTS_LIB_H
-#define GUARD_NTS_LIB_H
-
-#include <stdint.h>
-#include <openssl/evp.h>
-#include <stdbool.h>
-
-#include "nts.h"
-
-typedef struct {
-  void *key_c2s;
-  void *key_s2c;
-  void *nonce;
-  char *plaintext;
-  void *ciphertext;
-  char *cookie;
-  void *iv;
-  void *bit; // pointer for mempcpy, upf
-  uint8_t addr_peer[16];
-
-  int tally;
-
-  uint16_t size_iv;
-  uint16_t size_key_csc;
-  uint16_t size_nonce;
-  uint16_t size_ciphertext;
-  uint16_t size_plaintext;
-  uint16_t nts_algo;
-  uint16_t cookie_key_id;
-  uint16_t recipe;
-  uint16_t countdown;
-  uint16_t now; // network order word
-} cookie_bits;
-
-typedef struct {
-  uint8_t *next;
-  uint8_t *record;
-  uint8_t *body;
-  uint8_t *bit; // pointer for mempcpy, upf
-
-  uint16_t body_length;
-  uint16_t record_type;
-  uint16_t record_length;
-  uint16_t now; // network order word
-  bool critical;
-} record_bits;
-
-extern uint8_t *upf(void *src, void *dest, size_t n);
-
-extern int nts_record_form(record_bits *in);
-extern int nts_record_parse(record_bits *in);
-
-extern int nts_cookie_prep(cookie_bits *input);
-extern int nts_cookie_clean(cookie_bits *a);
-extern int nts_cookie_plaintext_parse(cookie_bits *out);
-extern int nts_cookie_plaintext_form(cookie_bits *in);
-
-#endif // GUARD_NTS_LIB_H


=====================================
ntpd/nts_lib.c deleted
=====================================
@@ -1,118 +0,0 @@
-#include "nts_lib.h"
-#include "config.h"
-#include "nts_lib.h"
-#include "ntp_types.h"
-#include "ntpd.h"
-#include <arpa/inet.h>
-#include <stdlib.h>
-#include <string.h>
-
-// a binary unpack function it should sort of reverse memcpy
-uint8_t *upf(void *src, void *dest, size_t n) {
-	(void)memcpy(dest, src, n);
-	return (uint8_t *)src + n;
-}
-
-/* parse an NTS record to retrieve the body, body_length and record_type
- *
- * Assumes the record field is set to an appropriate value.
- *
- * sets the record_length, record_type and body fields
- *
- * returns 0 on success
- */
-int nts_record_parse(record_bits *in) {
-	in->bit = upf(in->record, &in->now, sizeof(uint16_t));
-
-	if (0x80 & in->record[0]) {          // FIXME
-		in->critical = true;
-		in->now &= htons(0x7FFF);    // FIXME
-	}
-	in->record_type = ntohs(in->now);
-
-	in->bit = upf(in->bit, &in->now, sizeof(uint16_t));
-	in->body_length = ntohs(in->now);
-	if (0 != in->body_length) {
-		in->body = in->bit;
-		in->bit += in->body_length;
-	} else {
-		in->body = NULL;
-	}
-	return 0;
-}
-
-/* form an NTS record
- *
- * Assumes the record_length, record_type and body fields are set to appropriate
- * values
- *
- * sets the record_length and record fields.
- *
- * returns 0 on success
- * returns 1 on memory allocation failure;
- */
-int nts_record_form(record_bits *in) {
-	in->record_length = (4 + in->body_length);
-	in->record = malloc(in->record_length);
-	if (NULL == in->record) {
-		return 1;
-	}
-	in->now = htons(in->record_type);
-	if (in->critical) {
-		in->now |= htons(0x8000);
-	}
-	in->bit = in->record;
-	in->bit = memcpy(in->bit, &in->now, sizeof(uint16_t));
-	in->bit += sizeof(uint16_t);
-	in->now = htons(in->body_length);
-	memcpy(in->bit, &in->now, sizeof(uint16_t));
-	in->bit += sizeof(uint16_t);
-	if (0 < in->body_length) {
-		memcpy(in->bit, in->body, in->body_length);
-		in->bit += in->body_length;
-	}
-	return 0;
-}
-
-// Allocate & initialize structure & fields for NTS cookie generation/parsing
-int nts_cookie_prep(cookie_bits *input) {
-	UNUSED_ARG(input);
-	return 0;
-}
-
-// Free (most) storage used by NTS cookie generation/parsing routines
-int nts_cookie_clean(cookie_bits *a) {
-	UNUSED_ARG(a);
-	return 0;
-}
-
-/* Parse the plaintext to retrieve the AEAD algorithm to use when processing,
- * the c2s key used to decipher the AEAD extension from the client and the
- * s2c key used to encipher the AEAD extension returned to the client.
- *
- * Assumes the plaintext and recipe fields are set.
- *
- * Sets the key_c2s, key_s2c and size_key_csc fields
- * optionally sets fields addr_peer and countdown
- *
- * returns number of bytes remaining in the plaintext (should be 0)
- */
-int nts_cookie_plaintext_parse(cookie_bits *out) {
-	UNUSED_ARG(out);
-	return 0;
-}
-
-/* Form the cookie plaintext from the AEAD algorithm number, the c2s key and
- * the sc key extracted during the NTS-KE session.
- *
- * Assumes the key_c2s, key_s2c, recipe and size_key_csc fields are set
- * optionally uses fields addr_peer and countdown
- *
- * sets the plaintext and size_plaintext fields.
- *
- * returns 0 on success
- */
-int nts_cookie_plaintext_form(cookie_bits *in) {
-	UNUSED_ARG(in);
-	return 0;
-}


=====================================
ntpd/wscript
=====================================
@@ -61,7 +61,6 @@ def build(ctx):
         "nts_server.c",
         "nts_client.c",
         "nts_cookie.c",
-        "nts_lib.c",
     ]
 
     ctx(


=====================================
tests/common/tests_main.c
=====================================
@@ -73,7 +73,6 @@ static void RunAllTests(void)
 	RUN_TEST_GROUP(leapsec);
 	RUN_TEST_GROUP(hackrestrict);
 	RUN_TEST_GROUP(recvbuff);
-	RUN_TEST_GROUP(nts_lib);
 #endif
 
 }


=====================================
tests/ntpd/nts.c
=====================================
@@ -1,4 +1,3 @@
-#include "nts_lib.h"
 #include "nts.h"
 #include "unity.h"
 #include "unity_fixture.h"
@@ -21,12 +20,12 @@ TEST(nts, nts_append_record_null) {
   // Run test
   nts_append_record_null(&cursor, 0xFA7E);
   // Check
-  TEST_ASSERT_EQUAL(buf[0], 0xFA);
-  TEST_ASSERT_EQUAL(buf[1], 0x7E);
-  TEST_ASSERT_EQUAL(buf[2], 0);
-  TEST_ASSERT_EQUAL(buf[3], 0);
-  TEST_ASSERT_EQUAL(cursor.next, &buf[4]);
-  TEST_ASSERT_EQUAL(cursor.left, 124);
+  TEST_ASSERT_EQUAL_UINT8(buf[0], 0xFA);
+  TEST_ASSERT_EQUAL_UINT8(buf[1], 0x7E);
+  TEST_ASSERT_EQUAL_UINT8(buf[2], 0);
+  TEST_ASSERT_EQUAL_UINT8(buf[3], 0);
+  TEST_ASSERT_POINTERS_EQUAL(cursor.next, &buf[4]);
+  TEST_ASSERT_EQUAL_INT(cursor.left, 124);
 }
 
 TEST(nts, nts_append_record_uint16) {
@@ -40,21 +39,21 @@ TEST(nts, nts_append_record_uint16) {
   // Run test
   nts_append_record_uint16(&cursor, 0xCAFE, 0x1234);
   // Check
-  TEST_ASSERT_EQUAL(buf[0], 0xCA);
-  TEST_ASSERT_EQUAL(buf[1], 0xFE);
-  TEST_ASSERT_EQUAL(buf[2], 0x12);
-  TEST_ASSERT_EQUAL(buf[3], 0x34);
-  TEST_ASSERT_EQUAL(cursor.next, &buf[4]);
-  TEST_ASSERT_EQUAL(cursor.left, 12);
+  TEST_ASSERT_EQUAL_UINT8(buf[0], 0xCA);
+  TEST_ASSERT_EQUAL_UINT8(buf[1], 0xFE);
+  TEST_ASSERT_EQUAL_UINT8(buf[2], 0x12);
+  TEST_ASSERT_EQUAL_UINT8(buf[3], 0x34);
+  TEST_ASSERT_POINTERS_EQUAL(cursor.next, &buf[4]);
+  TEST_ASSERT_EQUAL_INT(cursor.left, 12);
   // Test no change
   // Setup
   cursor.left = 0;
   // Run test
   nts_append_record_uint16(&cursor, 0xCAFE, 0x1234);
   // Check
-  TEST_ASSERT_EQUAL(buf[4], 0);
-  TEST_ASSERT_EQUAL(cursor.next, &buf[4]);
-  TEST_ASSERT_EQUAL(cursor.left, 0);
+  TEST_ASSERT_EQUAL_UINT8(buf[4], 0);
+  TEST_ASSERT_POINTERS_EQUAL(cursor.next, &buf[4]);
+  TEST_ASSERT_EQUAL_INT(cursor.left, 0);
 }
 
 TEST(nts, nts_append_record_bytes) {
@@ -69,25 +68,25 @@ TEST(nts, nts_append_record_bytes) {
   // Run test
   nts_append_record_bytes(&cursor, 0xCAFE, data, 6);
   // Check
-  TEST_ASSERT_EQUAL(buf[0], 0xCA);
-  TEST_ASSERT_EQUAL(buf[1], 0xFE);
-  TEST_ASSERT_EQUAL(buf[2], 0);
-  TEST_ASSERT_EQUAL(buf[3], 1);
-  TEST_ASSERT_EQUAL(buf[4], 2);
-  TEST_ASSERT_EQUAL(buf[5], 3);
-  TEST_ASSERT_EQUAL(buf[6], 4);
-  TEST_ASSERT_EQUAL(buf[7], 5);
-  TEST_ASSERT_EQUAL(cursor.next, &buf[8]);
-  TEST_ASSERT_EQUAL(cursor.left, 8);
+  TEST_ASSERT_EQUAL_UINT8(buf[0], 0xCA);
+  TEST_ASSERT_EQUAL_UINT8(buf[1], 0xFE);
+  TEST_ASSERT_EQUAL_UINT8(buf[2], 0);
+  TEST_ASSERT_EQUAL_UINT8(buf[3], 1);
+  TEST_ASSERT_EQUAL_UINT8(buf[4], 2);
+  TEST_ASSERT_EQUAL_UINT8(buf[5], 3);
+  TEST_ASSERT_EQUAL_UINT8(buf[6], 4);
+  TEST_ASSERT_EQUAL_UINT8(buf[7], 5);
+  TEST_ASSERT_POINTERS_EQUAL(cursor.next, &buf[8]);
+  TEST_ASSERT_EQUAL_INT(cursor.left, 8);
   // Test no change
   // Setup
   cursor.left = 0;
   // Run test
   nts_append_record_bytes(&cursor, 0xCAFE, data, 6);
   // Check
-  TEST_ASSERT_EQUAL(buf[8], 0);
-  TEST_ASSERT_EQUAL(cursor.next, &buf[8]);
-  TEST_ASSERT_EQUAL(cursor.left, 0);
+  TEST_ASSERT_EQUAL_UINT8(buf[8], 0);
+  TEST_ASSERT_POINTERS_EQUAL(cursor.next, &buf[8]);
+  TEST_ASSERT_EQUAL_INT(cursor.left, 0);
 }
 
 TEST(nts, nts_append_header) {
@@ -100,22 +99,22 @@ TEST(nts, nts_append_header) {
   // Run test
   nts_append_header(&cursor, 0xFADE, 0x1234);
   // Check
-  TEST_ASSERT_EQUAL(buf[0], 0xFA);
-  TEST_ASSERT_EQUAL(buf[1], 0xDE);
-  TEST_ASSERT_EQUAL(buf[2], 0x12);
-  TEST_ASSERT_EQUAL(buf[3], 0x34);
-  TEST_ASSERT_EQUAL(buf[4], 0);
-  TEST_ASSERT_EQUAL(cursor.next, &buf[4]);
-  TEST_ASSERT_EQUAL(cursor.left, 12);
+  TEST_ASSERT_EQUAL_UINT8(buf[0], 0xFA);
+  TEST_ASSERT_EQUAL_UINT8(buf[1], 0xDE);
+  TEST_ASSERT_EQUAL_UINT8(buf[2], 0x12);
+  TEST_ASSERT_EQUAL_UINT8(buf[3], 0x34);
+  TEST_ASSERT_EQUAL_UINT8(buf[4], 0);
+  TEST_ASSERT_POINTERS_EQUAL(cursor.next, &buf[4]);
+  TEST_ASSERT_EQUAL_INT(cursor.left, 12);
   // Test no change
   // Setup
   cursor.left = 0;
   // Run test
   nts_append_header(&cursor, 0xFEED, 0xABCD);
   // Check
-  TEST_ASSERT_EQUAL(buf[4], 0);
-  TEST_ASSERT_EQUAL(cursor.next, &buf[4]);
-  TEST_ASSERT_EQUAL(cursor.left, 0);
+  TEST_ASSERT_EQUAL_UINT8(buf[4], 0);
+  TEST_ASSERT_POINTERS_EQUAL(cursor.next, &buf[4]);
+  TEST_ASSERT_EQUAL_INT(cursor.left, 0);
 }
 
 TEST(nts, nts_append_uint16) {
@@ -129,19 +128,19 @@ TEST(nts, nts_append_uint16) {
   // Run test
   nts_append_uint16(&cursor, 0x1234);
   // Check
-  TEST_ASSERT_EQUAL(buf[0], 0x12);
-  TEST_ASSERT_EQUAL(buf[1], 0x34);
-  TEST_ASSERT_EQUAL(cursor.next, &buf[2]);
-  TEST_ASSERT_EQUAL(cursor.left, 14);
+  TEST_ASSERT_EQUAL_UINT8(buf[0], 0x12);
+  TEST_ASSERT_EQUAL_UINT8(buf[1], 0x34);
+  TEST_ASSERT_POINTERS_EQUAL(cursor.next, &buf[2]);
+  TEST_ASSERT_EQUAL_INT(cursor.left, 14);
   // Test no change
   // Setup
   cursor.left = 0;
   // Run test
   nts_append_uint16(&cursor, 0x5678);
   // Check
-  TEST_ASSERT_EQUAL(buf[2], 0);
-  TEST_ASSERT_EQUAL(cursor.next, &buf[2]);
-  TEST_ASSERT_EQUAL(cursor.left, 0);
+  TEST_ASSERT_EQUAL_UINT8(buf[2], 0);
+  TEST_ASSERT_POINTERS_EQUAL(cursor.next, &buf[2]);
+  TEST_ASSERT_EQUAL_INT(cursor.left, 0);
 }
 
 TEST(nts, nts_append_bytes) {
@@ -156,23 +155,23 @@ TEST(nts, nts_append_bytes) {
   // Run test
   nts_append_bytes(&cursor, data, 6);
   // Check
-  TEST_ASSERT_EQUAL(buf[0], 0);
-  TEST_ASSERT_EQUAL(buf[1], 1);
-  TEST_ASSERT_EQUAL(buf[2], 2);
-  TEST_ASSERT_EQUAL(buf[3], 3);
-  TEST_ASSERT_EQUAL(buf[4], 4);
-  TEST_ASSERT_EQUAL(buf[5], 5);
-  TEST_ASSERT_EQUAL(cursor.next, &buf[6]);
-  TEST_ASSERT_EQUAL(cursor.left, 10);
+  TEST_ASSERT_EQUAL_UINT8(buf[0], 0);
+  TEST_ASSERT_EQUAL_UINT8(buf[1], 1);
+  TEST_ASSERT_EQUAL_UINT8(buf[2], 2);
+  TEST_ASSERT_EQUAL_UINT8(buf[3], 3);
+  TEST_ASSERT_EQUAL_UINT8(buf[4], 4);
+  TEST_ASSERT_EQUAL_UINT8(buf[5], 5);
+  TEST_ASSERT_POINTERS_EQUAL(cursor.next, &buf[6]);
+  TEST_ASSERT_EQUAL_INT(cursor.left, 10);
   // Test no change
   // Setup
   cursor.left = 0;
   // Run test
   nts_append_bytes(&cursor, data, 6);
   // Check
-  TEST_ASSERT_EQUAL(buf[6], 0);
-  TEST_ASSERT_EQUAL(cursor.next, &buf[6]);
-  TEST_ASSERT_EQUAL(cursor.left, 0);
+  TEST_ASSERT_EQUAL_UINT8(buf[6], 0);
+  TEST_ASSERT_POINTERS_EQUAL(cursor.next, &buf[6]);
+  TEST_ASSERT_EQUAL_INT(cursor.left, 0);
 }
 
 TEST(nts, nts_next_record) {
@@ -187,10 +186,10 @@ TEST(nts, nts_next_record) {
   // Run test
   type = nts_next_record(&cursor, &length);
   // Check
-  TEST_ASSERT_EQUAL(length, 4);
-  TEST_ASSERT_EQUAL(type, 0xFACE);
-  TEST_ASSERT_EQUAL(cursor.next, &buf[4]);
-  TEST_ASSERT_EQUAL(cursor.left, 12);
+  TEST_ASSERT_EQUAL_INT(length, 4);
+  TEST_ASSERT_EQUAL_INT(type, 0xFACE);
+  TEST_ASSERT_POINTERS_EQUAL(cursor.next, &buf[4]);
+  TEST_ASSERT_EQUAL_INT(cursor.left, 12);
 }
 
 TEST(nts, nts_next_uint16) {
@@ -204,9 +203,9 @@ TEST(nts, nts_next_uint16) {
   // Run test
   data = nts_next_uint16(&cursor);
   // Check
-  TEST_ASSERT_EQUAL(data, 0xFACE);
-  TEST_ASSERT_EQUAL(cursor.next, &buf[2]);
-  TEST_ASSERT_EQUAL(cursor.left, 14);
+  TEST_ASSERT_EQUAL_UINT8(data, 0xFACE);
+  TEST_ASSERT_POINTERS_EQUAL(cursor.next, &buf[2]);
+  TEST_ASSERT_EQUAL_INT(cursor.left, 14);
 }
 
 TEST(nts, nts_next_bytes) {
@@ -221,17 +220,17 @@ TEST(nts, nts_next_bytes) {
   // Run test
   length = nts_next_bytes(&cursor, data, 8);
   // Check
-  TEST_ASSERT_EQUAL(length, 8);
-  TEST_ASSERT_EQUAL(data[0], 0xFA);
-  TEST_ASSERT_EQUAL(data[1], 0xCE);
-  TEST_ASSERT_EQUAL(data[2], 0);
-  TEST_ASSERT_EQUAL(data[3], 4);
-  TEST_ASSERT_EQUAL(data[4], 0xFF);
-  TEST_ASSERT_EQUAL(data[5], 0xEE);
-  TEST_ASSERT_EQUAL(data[6], 0xDD);
-  TEST_ASSERT_EQUAL(data[7], 0xCC);
-  TEST_ASSERT_EQUAL(cursor.next, &buf[8]);
-  TEST_ASSERT_EQUAL(cursor.left, 8);
+  TEST_ASSERT_EQUAL_INT(length, 8);
+  TEST_ASSERT_EQUAL_UINT8(data[0], 0xFA);
+  TEST_ASSERT_EQUAL_UINT8(data[1], 0xCE);
+  TEST_ASSERT_EQUAL_UINT8(data[2], 0);
+  TEST_ASSERT_EQUAL_UINT8(data[3], 4);
+  TEST_ASSERT_EQUAL_UINT8(data[4], 0xFF);
+  TEST_ASSERT_EQUAL_UINT8(data[5], 0xEE);
+  TEST_ASSERT_EQUAL_UINT8(data[6], 0xDD);
+  TEST_ASSERT_EQUAL_UINT8(data[7], 0xCC);
+  TEST_ASSERT_POINTERS_EQUAL(cursor.next, &buf[8]);
+  TEST_ASSERT_EQUAL_INT(cursor.left, 8);
 }
 
 TEST_GROUP_RUNNER(nts) {


=====================================
tests/ntpd/nts_lib.c deleted
=====================================
@@ -1,294 +0,0 @@
-#include "nts_lib.h"
-#include "unity.h"
-#include "unity_fixture.h"
-#include <arpa/inet.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-TEST_GROUP(nts_lib);
-
-TEST_SETUP(nts_lib) {}
-
-TEST_TEAR_DOWN(nts_lib) {}
-
-TEST(nts_lib, record_decode_null) {
-	uint8_t expected[4] = {0x80, 0, 0, 0};
-	record_bits *record;
-
-	record = calloc(1, sizeof(record_bits));
-	if (NULL == record) {
-		TEST_FAIL_MESSAGE("record malloc");
-		return;
-	}
-	record->record = malloc(4);
-	if (NULL == record->record) {
-		TEST_FAIL_MESSAGE("record value malloc");
-		return;
-	}
-	memcpy(record->record, expected, 4);
-	record->record_length = 4;
-
-	nts_record_parse(record);
-
-	TEST_ASSERT_TRUE(record->critical);
-	TEST_ASSERT_EQUAL_INT16(0, record->record_type);
-	TEST_ASSERT_EQUAL_INT16(0, record->body_length);
-	TEST_ASSERT_NULL(record->body);
-	record->body = NULL;
-
-	free(record->record);
-	free(record);
-}
-
-TEST(nts_lib, record_decode_u16) {
-	uint8_t expected[6] = {0, nts_port_negotiation, 0, 2, 0, 123};
-	record_bits *record;
-	int lints[1];
-
-	record = calloc(1, sizeof(record_bits));
-	if (NULL == record) {
-		TEST_FAIL_MESSAGE("record malloc");
-		return;
-	}
-	record->record = malloc(6);
-	if (NULL == record->record) {
-		TEST_FAIL_MESSAGE("record value malloc");
-		return;
-	}
-	memcpy(record->record, expected, 6);
-	record->record_length = 6;
-
-	nts_record_parse(record);
-	if (record->body_length & 1) {
-		TEST_FAIL_MESSAGE("odd byte out");
-	}
-	memcpy(lints, record->body, 2);
-
-	TEST_ASSERT_FALSE(record->critical);
-	TEST_ASSERT_EQUAL_INT16(nts_port_negotiation, record->record_type);
-	TEST_ASSERT_EQUAL_INT16(2, record->body_length);
-	TEST_ASSERT_NOT_NULL(record->body);
-
-	TEST_ASSERT_EQUAL_INT16(123, ntohs(lints[0]));
-	record->body = NULL;
-
-	free(record->record);
-	free(record);
-}
-
-TEST(nts_lib, record_decode_u16s) {
-	uint8_t expected[8] = {0, nts_algorithm_negotiation, 0, 4,
-			       0, AEAD_AES_SIV_CMAC_512, 0, AEAD_CHACHA20_POLY1305};
-	record_bits *record;
-	int lints[2];
-	void *there;
-
-	record = calloc(1, sizeof(record_bits));
-	if (NULL == record) {
-		TEST_FAIL_MESSAGE("record malloc");
-		return;
-	}
-	record->record = malloc(8);
-	if (NULL == record->record) {
-		TEST_FAIL_MESSAGE("record value malloc");
-		return;
-	}
-	memcpy(record->record, expected, 8);
-	record->record_length = 8;
-
-	nts_record_parse(record);
-	there = record->body;
-	if (record->body_length & 1) {
-		TEST_FAIL_MESSAGE("odd byte out");
-	}
-	for (int count = 0; (count * 2) < record->body_length; count++) {
-		there = upf(there, &lints[count], 2);
-	}
-
-	TEST_ASSERT_FALSE(record->critical);
-	TEST_ASSERT_EQUAL_INT16(nts_algorithm_negotiation, record->record_type);
-	TEST_ASSERT_EQUAL_INT16(4, record->body_length);
-	TEST_ASSERT_NOT_NULL(record->body);
-
-	TEST_ASSERT_EQUAL_INT16(AEAD_AES_SIV_CMAC_512, ntohs(lints[0]));
-	TEST_ASSERT_EQUAL_INT16(AEAD_CHACHA20_POLY1305, ntohs(lints[1]));
-	record->body = NULL;
-
-	free(record->record);
-	free(record);
-}
-
-TEST(nts_lib, record_decode_text) {
-	record_bits *record;
-	const char *expserv = "asus.internal.jamesb192.com";
-	uint8_t expected[31] = {0,   nts_server_negotiation,
-				0,   27,
-				'a', 's', 'u', 's', '.', 'i', 'n', 't', 'e',
-				'r', 'n', 'a', 'l', '.', 'j', 'a', 'm', 'e',
-				's', 'b', '1', '9', '2', '.', 'c', 'o', 'm'
-	};
-	record = calloc(1, sizeof(record_bits));
-	if (NULL == record) {
-		TEST_FAIL_MESSAGE("record malloc");
-		return;
-	}
-	record->record = malloc(31);
-	if (NULL == record->record) {
-		TEST_FAIL_MESSAGE("record value malloc");
-		return;
-	}
-	memcpy(record->record, expected, 31);
-	record->record_length = 31;
-
-	nts_record_parse(record);
-
-	TEST_ASSERT_FALSE(record->critical);
-	TEST_ASSERT_EQUAL_INT16(nts_server_negotiation, record->record_type);
-	TEST_ASSERT_EQUAL_INT16(27, record->body_length);
-	TEST_ASSERT_NOT_NULL(record->body);
-
-	TEST_ASSERT_EQUAL_STRING_LEN(expserv, record->body, 27);
-	record->body = NULL;
-
-	free(record->record);
-	free(record);
-}
-
-TEST(nts_lib, record_encode_null) {
-	uint8_t expected[4] = {0x80, nts_end_of_message, 0, 0};
-	record_bits *record;
-
-	record = calloc(1, sizeof(record_bits));
-	if (NULL == record) {
-		TEST_FAIL_MESSAGE("record malloc");
-		return;
-	}
-	record->critical = true;
-	record->body_length = 0;
-	record->record_type = nts_end_of_message;
-
-	nts_record_form(record);
-
-	TEST_ASSERT_EQUAL_UINT16(4, record->record_length);
-	TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, record->record, 4);
-
-	free(record->body);
-	free(record);
-}
-
-TEST(nts_lib, record_encode_u16) {
-	uint8_t expected[6] = {0, nts_port_negotiation, 0, 2, 0, 123};
-	uint16_t exp_port = htons(123);
-	record_bits *record;
-
-	record = calloc(1, sizeof(record_bits));
-	if (NULL == record) {
-		TEST_FAIL_MESSAGE("record malloc");
-		return;
-	}
-	record->critical = false;
-	record->body_length = 2;
-	record->record_type = nts_port_negotiation;
-	record->body = malloc(2);
-	if (NULL == record->body) {
-		TEST_FAIL_MESSAGE("body malloc");
-		return;
-	}
-	memcpy(record->body, &exp_port, 2);
-
-	nts_record_form(record);
-
-	TEST_ASSERT_EQUAL_UINT16(6, record->record_length);
-	TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, record->record, 6);
-
-	free(record->body);
-	free(record);
-}
-
-TEST(nts_lib, record_encode_u16s) {
-	uint8_t expected[8] = {0, nts_algorithm_negotiation, 0, 4, 0, 2, 0, 4};
-	uint16_t exp_algos[2] = {htons(2), htons(4)};
-	record_bits *record;
-
-	record = calloc(1, sizeof(record_bits));
-	if (NULL == record) {
-		TEST_FAIL_MESSAGE("record malloc");
-		return;
-	}
-	record->critical = false;
-	record->body_length = 4;
-	record->record_type = nts_algorithm_negotiation;
-	record->body = malloc(4);
-	if (NULL == record->body) {
-		TEST_FAIL_MESSAGE("body malloc");
-		return;
-	}
-	memcpy(record->body, &exp_algos, 4);
-
-	nts_record_form(record);
-
-	TEST_ASSERT_EQUAL_UINT16(8, record->record_length);
-	TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, record->record, 8);
-
-	free(record->body);
-	free(record);
-}
-
-TEST(nts_lib, record_encode_text) {
-	const char *expserv = "asus.internal.jamesb192.com";
-	uint8_t expected[31] = {  0,  nts_server_negotiation,
-				  0,  27,
-				  'a', 's', 'u', 's', '.', 'i', 'n', 't', 'e',
-				  'r', 'n', 'a', 'l', '.', 'j', 'a', 'm', 'e',
-				  's', 'b', '1', '9', '2', '.', 'c', 'o', 'm'
-	};
-	record_bits *record;
-
-	record = calloc(1, sizeof(record_bits));
-	if (NULL == record) {
-		TEST_FAIL_MESSAGE("record malloc");
-		return;
-	}
-	record->critical = false;
-	record->body_length = 27;
-	record->record_type = nts_server_negotiation;
-	record->body = malloc(27);
-	if (NULL == record->body) {
-		TEST_FAIL_MESSAGE("body calloc");
-		return;
-	}
-	memcpy(record->body, expserv, 27);
-
-	nts_record_form(record);
-
-	TEST_ASSERT_EQUAL_UINT16(31, record->record_length);
-	TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, record->record, 31);
-
-	free(record->body);
-	free(record);
-}
-
-/*TEST(nts_lib, existence) {
-  TEST_ASSERT_NOT_NULL(upf);
-  TEST_ASSERT_NOT_NULL(nts_record_form)
-  TEST_ASSERT_NOT_NULL(nts_record_parse)
-  TEST_ASSERT_NOT_NULL(nts_cookie_prep);
-  TEST_ASSERT_NOT_NULL(nts_cookie_clean);
-  TEST_ASSERT_NOT_NULL(nts_cookie_plaintext_parse);
-  TEST_ASSERT_NOT_NULL(nts_cookie_plaintext_form);
-}*/
-
-TEST_GROUP_RUNNER(nts_lib) {
-//  RUN_TEST_CASE(nts_lib, existence);
-
-	RUN_TEST_CASE(nts_lib, record_decode_null);
-	RUN_TEST_CASE(nts_lib, record_decode_u16);
-	RUN_TEST_CASE(nts_lib, record_decode_u16s);
-	RUN_TEST_CASE(nts_lib, record_decode_text);
-
-	RUN_TEST_CASE(nts_lib, record_encode_null);
-	RUN_TEST_CASE(nts_lib, record_encode_u16);
-	RUN_TEST_CASE(nts_lib, record_encode_u16s);
-	RUN_TEST_CASE(nts_lib, record_encode_text);
-}


=====================================
tests/wscript
=====================================
@@ -101,8 +101,7 @@ def build(ctx):
         "ntpd/leapsec.c",
         "ntpd/restrict.c",
         "ntpd/recvbuff.c",
-        "ntpd/nts_lib.c",
-		"ntpd/nts.c"
+        "ntpd/nts.c",
     ] + common_source
 
     ctx.ntp_test(



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/429d8c0e9c5647bb079b73ca1b8125eabdbca972...b3fd5384cfe9c5b721a313437eb7942bca7b34b4

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/429d8c0e9c5647bb079b73ca1b8125eabdbca972...b3fd5384cfe9c5b721a313437eb7942bca7b34b4
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20190223/2b688aac/attachment-0001.html>


More information about the vc mailing list