45 #define DATA(...) { __VA_ARGS__ } 54 #define RANGE( START, END ) { .start = START, .end = END } 63 #define TRIM( START, END ) { .start = START, .end = END } 115 #define PEERDIST_INFO_TEST( name, DATA, DIGEST, DIGESTSIZE, RANGE, \ 117 static const uint8_t name ## _data[] = DATA; \ 118 static struct peerdist_info_test name = { \ 119 .data = name ## _data, \ 120 .len = sizeof ( name ## _data ), \ 121 .expected_digest = DIGEST, \ 122 .expected_digestsize = DIGESTSIZE, \ 123 .expected_range = RANGE, \ 124 .expected_trim = TRIM, \ 125 .expected_segments = SEGMENTS, \ 159 #define PEERDIST_INFO_SEGMENT_TEST( name, INDEX, RANGE, BLOCKS, \ 160 BLKSIZE, HASH, SECRET, ID ) \ 161 static struct peerdist_info_segment_test name = { \ 163 .expected_range = RANGE, \ 164 .expected_blocks = BLOCKS, \ 165 .expected_blksize = BLKSIZE, \ 166 .expected_hash = HASH, \ 167 .expected_secret = SECRET, \ 193 #define PEERDIST_INFO_BLOCK_TEST( name, INDEX, RANGE, TRIM, HASH ) \ 194 static struct peerdist_info_block_test name = { \ 196 .expected_range = RANGE, \ 197 .expected_trim = TRIM, \ 198 .expected_hash = HASH, \ 231 #define SERVER_PASSPHRASE( name, DATA ) \ 232 static uint8_t name[] = DATA 236 DATA ( 0x2a, 0x3d, 0x73, 0xeb, 0x43, 0x5e, 0x9f, 0x2b, 0x8a, 0x34, 0x42,
237 0x67, 0xe7, 0x46, 0x7a, 0x3c, 0x73, 0x85, 0xc6, 0xe0, 0x55, 0xe2,
238 0xb4, 0xd3, 0x0d, 0xfe, 0xc7, 0xc3, 0x8b, 0x0e, 0xd7, 0x2c ) );
242 DATA ( 0x00, 0x01, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
243 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
244 0x00, 0x00, 0x00, 0x00, 0x7e, 0x85, 0x01, 0x00, 0x00, 0x00, 0x01,
245 0x00, 0xd8, 0xd9, 0x76, 0x35, 0x4a, 0x48, 0x72, 0xe9, 0x25, 0x76,
246 0x18, 0x03, 0xf4, 0x58, 0xd9, 0xda, 0xaa, 0x67, 0xf8, 0xe3, 0x1c,
247 0x63, 0x0f, 0xb7, 0x4e, 0x6a, 0x31, 0x2e, 0xf8, 0xa2, 0x5a, 0xba,
248 0x11, 0xaf, 0xc0, 0xd7, 0x94, 0x92, 0x43, 0xf9, 0x4f, 0x9c, 0x1f,
249 0xab, 0x35, 0xd9, 0xfd, 0x1e, 0x33, 0x1f, 0xcf, 0x78, 0x11, 0xa2,
250 0xe0, 0x1d, 0x35, 0x87, 0xb3, 0x8d, 0x77, 0x0a, 0x29, 0xe2, 0x02,
251 0x00, 0x00, 0x00, 0x73, 0xc1, 0x8a, 0xb8, 0x54, 0x91, 0x10, 0xf8,
252 0xe9, 0x0e, 0x71, 0xbb, 0xc3, 0xab, 0x2a, 0xa8, 0xc4, 0x4d, 0x13,
253 0xf4, 0x92, 0x94, 0x99, 0x25, 0x5b, 0x66, 0x0f, 0x24, 0xec, 0x77,
254 0x80, 0x0b, 0x97, 0x4b, 0xdd, 0x65, 0x56, 0x7f, 0xde, 0xec, 0xcd,
255 0xaf, 0xe4, 0x57, 0xa9, 0x50, 0x3b, 0x45, 0x48, 0xf6, 0x6e, 0xd3,
256 0xb1, 0x88, 0xdc, 0xfd, 0xa0, 0xac, 0x38, 0x2b, 0x09, 0x71, 0x1a,
262 RANGE ( 0, 99710 ), 2, 65536,
263 DATA ( 0xd8, 0xd9, 0x76, 0x35, 0x4a, 0x48, 0x72, 0xe9, 0x25, 0x76, 0x18,
264 0x03, 0xf4, 0x58, 0xd9, 0xda, 0xaa, 0x67, 0xf8, 0xe3, 0x1c, 0x63,
265 0x0f, 0xb7, 0x4e, 0x6a, 0x31, 0x2e, 0xf8, 0xa2, 0x5a, 0xba ),
266 DATA ( 0x11, 0xaf, 0xc0, 0xd7, 0x94, 0x92, 0x43, 0xf9, 0x4f, 0x9c, 0x1f,
267 0xab, 0x35, 0xd9, 0xfd, 0x1e, 0x33, 0x1f, 0xcf, 0x78, 0x11, 0xa2,
268 0xe0, 0x1d, 0x35, 0x87, 0xb3, 0x8d, 0x77, 0x0a, 0x29, 0xe2 ),
269 DATA ( 0x49, 0x1b, 0x21, 0x7d, 0xbe, 0xe2, 0xb5, 0xf1, 0x2c, 0xa7, 0x9b,
270 0x01, 0x5e, 0x06, 0xf4, 0xbb, 0xe6, 0x4f, 0x97, 0x45, 0xba, 0xd7,
271 0x86, 0x7a, 0xef, 0x17, 0xde, 0x59, 0x92, 0x7e, 0xdc, 0xe9 ) );
277 DATA ( 0x73, 0xc1, 0x8a, 0xb8, 0x54, 0x91, 0x10, 0xf8, 0xe9, 0x0e, 0x71,
278 0xbb, 0xc3, 0xab, 0x2a, 0xa8, 0xc4, 0x4d, 0x13, 0xf4, 0x92, 0x94,
279 0x99, 0x25, 0x5b, 0x66, 0x0f, 0x24, 0xec, 0x77, 0x80, 0x0b ) );
283 RANGE ( 65536, 99710 ),
284 TRIM ( 65536, 99710 ),
285 DATA ( 0x97, 0x4b, 0xdd, 0x65, 0x56, 0x7f, 0xde, 0xec, 0xcd, 0xaf, 0xe4,
286 0x57, 0xa9, 0x50, 0x3b, 0x45, 0x48, 0xf6, 0x6e, 0xd3, 0xb1, 0x88,
287 0xdc, 0xfd, 0xa0, 0xac, 0x38, 0x2b, 0x09, 0x71, 0x1a, 0xcc ) );
291 DATA ( 0x00, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
294 0x00, 0x00, 0x88, 0x00, 0x00, 0x99, 0xde, 0xe0, 0xd0, 0xc3, 0x58,
295 0xe2, 0x68, 0x4b, 0x62, 0x33, 0x0d, 0x32, 0xb5, 0xf1, 0x97, 0x87,
296 0x24, 0xa0, 0xd0, 0xa5, 0x2b, 0xdc, 0x5e, 0x78, 0x1f, 0xae, 0x71,
297 0xff, 0x57, 0xa8, 0xbe, 0x3d, 0xd4, 0x58, 0x03, 0x7e, 0xd4, 0x04,
298 0x11, 0x6b, 0xb6, 0x16, 0xd9, 0xb1, 0x41, 0x16, 0x08, 0x85, 0x20,
299 0xc4, 0x7c, 0xdc, 0x50, 0xab, 0xce, 0xa3, 0xfa, 0xe1, 0x88, 0xa9,
300 0x8e, 0xa2, 0x2d, 0xf3, 0xc0, 0x00, 0x00, 0xeb, 0xa0, 0x33, 0x81,
301 0xd0, 0xd0, 0xcb, 0x74, 0xf4, 0xb6, 0x13, 0xd8, 0x21, 0x0f, 0x37,
302 0xf0, 0x02, 0xa0, 0x6f, 0x39, 0x10, 0x58, 0x60, 0x96, 0xa1, 0x30,
303 0xd3, 0x43, 0x98, 0xc0, 0x8e, 0x66, 0xd7, 0xbc, 0xb8, 0xb6, 0xeb,
304 0x77, 0x83, 0xe4, 0xf8, 0x07, 0x64, 0x7b, 0x63, 0xf1, 0x46, 0xb5,
305 0x2f, 0x4a, 0xc8, 0x9c, 0xcc, 0x7a, 0xbf, 0x5f, 0xa1, 0x1a, 0xca,
306 0xfc, 0x2a, 0xcf, 0x50, 0x28, 0x58, 0x6c ),
311 RANGE ( 0, 39390 ), 1, 39390,
312 DATA ( 0xe0, 0xd0, 0xc3, 0x58, 0xe2, 0x68, 0x4b, 0x62, 0x33, 0x0d, 0x32,
313 0xb5, 0xf1, 0x97, 0x87, 0x24, 0xa0, 0xd0, 0xa5, 0x2b, 0xdc, 0x5e,
314 0x78, 0x1f, 0xae, 0x71, 0xff, 0x57, 0xa8, 0xbe, 0x3d, 0xd4 ),
315 DATA ( 0x58, 0x03, 0x7e, 0xd4, 0x04, 0x11, 0x6b, 0xb6, 0x16, 0xd9, 0xb1,
316 0x41, 0x16, 0x08, 0x85, 0x20, 0xc4, 0x7c, 0xdc, 0x50, 0xab, 0xce,
317 0xa3, 0xfa, 0xe1, 0x88, 0xa9, 0x8e, 0xa2, 0x2d, 0xf3, 0xc0 ),
318 DATA ( 0x33, 0x71, 0xbb, 0xea, 0xdd, 0xb6, 0x23, 0x53, 0xad, 0xce, 0xf9,
319 0x70, 0xa0, 0x6f, 0xdf, 0x65, 0x00, 0x1e, 0x04, 0x21, 0xf4, 0xc7,
320 0x10, 0x82, 0x76, 0xb0, 0xc3, 0x7a, 0x9f, 0x9e, 0xc1, 0x0f ) );
326 DATA ( 0xe0, 0xd0, 0xc3, 0x58, 0xe2, 0x68, 0x4b, 0x62, 0x33, 0x0d, 0x32,
327 0xb5, 0xf1, 0x97, 0x87, 0x24, 0xa0, 0xd0, 0xa5, 0x2b, 0xdc, 0x5e,
328 0x78, 0x1f, 0xae, 0x71, 0xff, 0x57, 0xa8, 0xbe, 0x3d, 0xd4 ) );
332 RANGE ( 39390, 99710 ), 1, 60320,
333 DATA ( 0x33, 0x81, 0xd0, 0xd0, 0xcb, 0x74, 0xf4, 0xb6, 0x13, 0xd8, 0x21,
334 0x0f, 0x37, 0xf0, 0x02, 0xa0, 0x6f, 0x39, 0x10, 0x58, 0x60, 0x96,
335 0xa1, 0x30, 0xd3, 0x43, 0x98, 0xc0, 0x8e, 0x66, 0xd7, 0xbc ),
336 DATA ( 0xb8, 0xb6, 0xeb, 0x77, 0x83, 0xe4, 0xf8, 0x07, 0x64, 0x7b, 0x63,
337 0xf1, 0x46, 0xb5, 0x2f, 0x4a, 0xc8, 0x9c, 0xcc, 0x7a, 0xbf, 0x5f,
338 0xa1, 0x1a, 0xca, 0xfc, 0x2a, 0xcf, 0x50, 0x28, 0x58, 0x6c ),
339 DATA ( 0xd7, 0xe9, 0x24, 0x42, 0x5e, 0x8f, 0x4f, 0x88, 0xf0, 0x1d, 0xc6,
340 0xa9, 0xbb, 0x1b, 0xc3, 0x7b, 0xe1, 0x13, 0xec, 0x79, 0x17, 0xc7,
341 0x45, 0xd4, 0x96, 0x5c, 0x2b, 0x55, 0xfa, 0x16, 0x3a, 0x6e ) );
345 RANGE ( 39390, 99710 ),
346 TRIM ( 39390, 99710 ),
347 DATA ( 0x33, 0x81, 0xd0, 0xd0, 0xcb, 0x74, 0xf4, 0xb6, 0x13, 0xd8, 0x21,
348 0x0f, 0x37, 0xf0, 0x02, 0xa0, 0x6f, 0x39, 0x10, 0x58, 0x60, 0x96,
349 0xa1, 0x30, 0xd3, 0x43, 0x98, 0xc0, 0x8e, 0x66, 0xd7, 0xbc ) );
361 const char *file,
unsigned int line ) {
369 okx (
info->digest ==
test->expected_digest, file, line );
370 okx (
info->digestsize ==
test->expected_digestsize, file, line );
371 okx (
info->range.start ==
test->expected_range.start, file, line );
372 okx (
info->range.end ==
test->expected_range.end, file, line );
373 okx (
info->trim.start ==
test->expected_trim.start, file, line );
374 okx (
info->trim.end ==
test->expected_trim.end, file, line );
375 okx (
info->trim.start >=
info->range.start, file, line );
376 okx (
info->trim.end <=
info->range.end, file, line );
377 okx (
info->segments ==
test->expected_segments, file, line );
379 #define peerdist_info_ok( test, info ) \ 380 peerdist_info_okx ( test, info, __FILE__, __LINE__ ) 394 const char *file,
unsigned int line ) {
404 okx (
segment->range.start ==
test->expected_range.start, file, line );
405 okx (
segment->range.end ==
test->expected_range.end, file, line );
415 #define peerdist_info_segment_ok( test, info, segment ) \ 416 peerdist_info_segment_okx ( test, info, segment, __FILE__, __LINE__ ) 431 const char *file,
unsigned int line ) {
442 okx (
block->range.start ==
test->expected_range.start, file, line );
443 okx (
block->range.end ==
test->expected_range.end, file, line );
444 okx (
block->trim.start ==
test->expected_trim.start, file, line );
445 okx (
block->trim.end ==
test->expected_trim.end, file, line );
449 #define peerdist_info_block_ok( test, segment, block ) \ 450 peerdist_info_block_okx ( test, segment, block, __FILE__, __LINE__ ) 465 uint8_t *pass,
size_t pass_len,
466 const char *file,
unsigned int line ) {
487 #define peerdist_info_passphrase_ok( test, info, pass, pass_len ) \ 488 peerdist_info_passphrase_okx ( test, info, pass, pass_len, \ 503 passphrase,
sizeof ( passphrase ) );
511 passphrase,
sizeof ( passphrase ) );
515 passphrase,
sizeof ( passphrase ) );
#define TRIM(START, END)
Define an inline trimmed content range.
void hmac_init(struct digest_algorithm *digest, void *ctx, const void *key, size_t key_len)
Initialise HMAC.
uint16_t segment
Code segment.
static void digest_update(struct digest_algorithm *digest, void *ctx, const void *data, size_t len)
#define peerdist_info_ok(test, info)
A content information segment.
unsigned int index
Block index.
struct digest_algorithm sha512_algorithm
SHA-512 algorithm.
struct peerdist_range expected_range
Expected content range.
static void digest_final(struct digest_algorithm *digest, void *ctx, void *out)
uint8_t expected_id[PEERDIST_DIGEST_MAX_SIZE]
Expected segment identifier.
unsigned int expected_blocks
Expected number of blocks.
Self-test infrastructure.
const char * name
Test set name.
struct peerdist_range expected_trim
Expected trimmed content range.
uint8_t expected_hash[PEERDIST_DIGEST_MAX_SIZE]
Expected segment hash of data.
struct golan_eq_context ctx
unsigned int index
Segment index.
struct peerdist_range expected_range
Expected content range.
static void peerdist_info_segment_okx(struct peerdist_info_segment_test *test, const struct peerdist_info *info, struct peerdist_info_segment *segment, const char *file, unsigned int line)
Report content information segment test result.
#define PEERDIST_INFO_BLOCK_TEST(name, INDEX, RANGE, TRIM, HASH)
Define a content information block test.
size_t expected_digestsize
Expected digest size.
A content information block.
#define okx(success, file, line)
Report test result.
Keyed-Hashing for Message Authentication.
#define SERVER_PASSPHRASE(name, DATA)
Define a server passphrase.
#define peerdist_info_passphrase_ok(test, info, pass, pass_len)
static void peerdist_info_block_okx(struct peerdist_info_block_test *test, const struct peerdist_info_segment *segment, struct peerdist_info_block *block, const char *file, unsigned int line)
Report content information block test result.
static void digest_init(struct digest_algorithm *digest, void *ctx)
Peer Content Caching and Retrieval: Content Identification [MS-PCCRC].
unsigned int expected_segments
Expected number of segments.
static void hmac_update(struct digest_algorithm *digest, void *ctx, const void *data, size_t len)
Update HMAC.
#define PEERDIST_INFO_SEGMENT_TEST(name, INDEX, RANGE, BLOCKS, BLKSIZE, HASH, SECRET, ID)
Define a content information segment test.
static size_t hmac_ctxsize(struct digest_algorithm *digest)
Calculate HMAC context size.
static void peerdist_info_passphrase_okx(struct peerdist_info_segment_test *test, const struct peerdist_info *info, uint8_t *pass, size_t pass_len, const char *file, unsigned int line)
Report server passphrase test result.
A content information block test.
struct peerdist_range expected_range
Expected content range.
A content information segment test.
#define RANGE(START, END)
Define an inline content range.
struct self_test peerdist_info_test __self_test
Content information self-test.
#define peerdist_info_segment_ok(test, info, segment)
uint8_t expected_secret[PEERDIST_DIGEST_MAX_SIZE]
Expected segment secret.
#define PEERDIST_DIGEST_MAX_SIZE
Maximum digest size for any supported algorithm.
A content information test.
struct digest_algorithm sha256_algorithm
SHA-256 algorithm.
uint8_t block[3][8]
DES-encrypted blocks.
size_t digestsize
Digest size.
#define PEERDIST_INFO_TEST(name, DATA, DIGEST, DIGESTSIZE, RANGE, TRIM, SEGMENTS)
Define a content information test.
A message digest algorithm.
void hmac_final(struct digest_algorithm *digest, void *ctx, void *hmac)
Finalise HMAC.
struct digest_algorithm * expected_digest
Expected digest algorithm.
#define peerdist_info_block_ok(test, segment, block)
struct peerdist_range expected_trim
Expected trimmed content range.
size_t expected_blksize
Expected block size.
uint32_t digestsize
Digest size (i.e.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define DATA(...)
Define inline raw data.
static void peerdist_info_test_exec(void)
Perform content information self-tests.
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
const void * data
Raw content information.
size_t len
Length of raw content information.
uint8_t expected_hash[PEERDIST_DIGEST_MAX_SIZE]
Expected hash of data.
static void peerdist_info_okx(struct peerdist_info_test *test, struct peerdist_info *info, const char *file, unsigned int line)
Report content information test result.