46 #define DATA(...) { __VA_ARGS__ } 55 #define RANGE( START, END ) { .start = START, .end = END } 64 #define TRIM( START, END ) { .start = START, .end = END } 116 #define PEERDIST_INFO_TEST( name, DATA, DIGEST, DIGESTSIZE, RANGE, \ 118 static const uint8_t name ## _data[] = DATA; \ 119 static struct peerdist_info_test name = { \ 120 .data = name ## _data, \ 121 .len = sizeof ( name ## _data ), \ 122 .expected_digest = DIGEST, \ 123 .expected_digestsize = DIGESTSIZE, \ 124 .expected_range = RANGE, \ 125 .expected_trim = TRIM, \ 126 .expected_segments = SEGMENTS, \ 160 #define PEERDIST_INFO_SEGMENT_TEST( name, INDEX, RANGE, BLOCKS, \ 161 BLKSIZE, HASH, SECRET, ID ) \ 162 static struct peerdist_info_segment_test name = { \ 164 .expected_range = RANGE, \ 165 .expected_blocks = BLOCKS, \ 166 .expected_blksize = BLKSIZE, \ 167 .expected_hash = HASH, \ 168 .expected_secret = SECRET, \ 194 #define PEERDIST_INFO_BLOCK_TEST( name, INDEX, RANGE, TRIM, HASH ) \ 195 static struct peerdist_info_block_test name = { \ 197 .expected_range = RANGE, \ 198 .expected_trim = TRIM, \ 199 .expected_hash = HASH, \ 232 #define SERVER_PASSPHRASE( name, DATA ) \ 233 static uint8_t name[] = DATA 237 DATA ( 0x2a, 0x3d, 0x73, 0xeb, 0x43, 0x5e, 0x9f, 0x2b, 0x8a, 0x34, 0x42,
238 0x67, 0xe7, 0x46, 0x7a, 0x3c, 0x73, 0x85, 0xc6, 0xe0, 0x55, 0xe2,
239 0xb4, 0xd3, 0x0d, 0xfe, 0xc7, 0xc3, 0x8b, 0x0e, 0xd7, 0x2c ) );
243 DATA ( 0x00, 0x01, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
244 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
245 0x00, 0x00, 0x00, 0x00, 0x7e, 0x85, 0x01, 0x00, 0x00, 0x00, 0x01,
246 0x00, 0xd8, 0xd9, 0x76, 0x35, 0x4a, 0x48, 0x72, 0xe9, 0x25, 0x76,
247 0x18, 0x03, 0xf4, 0x58, 0xd9, 0xda, 0xaa, 0x67, 0xf8, 0xe3, 0x1c,
248 0x63, 0x0f, 0xb7, 0x4e, 0x6a, 0x31, 0x2e, 0xf8, 0xa2, 0x5a, 0xba,
249 0x11, 0xaf, 0xc0, 0xd7, 0x94, 0x92, 0x43, 0xf9, 0x4f, 0x9c, 0x1f,
250 0xab, 0x35, 0xd9, 0xfd, 0x1e, 0x33, 0x1f, 0xcf, 0x78, 0x11, 0xa2,
251 0xe0, 0x1d, 0x35, 0x87, 0xb3, 0x8d, 0x77, 0x0a, 0x29, 0xe2, 0x02,
252 0x00, 0x00, 0x00, 0x73, 0xc1, 0x8a, 0xb8, 0x54, 0x91, 0x10, 0xf8,
253 0xe9, 0x0e, 0x71, 0xbb, 0xc3, 0xab, 0x2a, 0xa8, 0xc4, 0x4d, 0x13,
254 0xf4, 0x92, 0x94, 0x99, 0x25, 0x5b, 0x66, 0x0f, 0x24, 0xec, 0x77,
255 0x80, 0x0b, 0x97, 0x4b, 0xdd, 0x65, 0x56, 0x7f, 0xde, 0xec, 0xcd,
256 0xaf, 0xe4, 0x57, 0xa9, 0x50, 0x3b, 0x45, 0x48, 0xf6, 0x6e, 0xd3,
257 0xb1, 0x88, 0xdc, 0xfd, 0xa0, 0xac, 0x38, 0x2b, 0x09, 0x71, 0x1a,
263 RANGE ( 0, 99710 ), 2, 65536,
264 DATA ( 0xd8, 0xd9, 0x76, 0x35, 0x4a, 0x48, 0x72, 0xe9, 0x25, 0x76, 0x18,
265 0x03, 0xf4, 0x58, 0xd9, 0xda, 0xaa, 0x67, 0xf8, 0xe3, 0x1c, 0x63,
266 0x0f, 0xb7, 0x4e, 0x6a, 0x31, 0x2e, 0xf8, 0xa2, 0x5a, 0xba ),
267 DATA ( 0x11, 0xaf, 0xc0, 0xd7, 0x94, 0x92, 0x43, 0xf9, 0x4f, 0x9c, 0x1f,
268 0xab, 0x35, 0xd9, 0xfd, 0x1e, 0x33, 0x1f, 0xcf, 0x78, 0x11, 0xa2,
269 0xe0, 0x1d, 0x35, 0x87, 0xb3, 0x8d, 0x77, 0x0a, 0x29, 0xe2 ),
270 DATA ( 0x49, 0x1b, 0x21, 0x7d, 0xbe, 0xe2, 0xb5, 0xf1, 0x2c, 0xa7, 0x9b,
271 0x01, 0x5e, 0x06, 0xf4, 0xbb, 0xe6, 0x4f, 0x97, 0x45, 0xba, 0xd7,
272 0x86, 0x7a, 0xef, 0x17, 0xde, 0x59, 0x92, 0x7e, 0xdc, 0xe9 ) );
278 DATA ( 0x73, 0xc1, 0x8a, 0xb8, 0x54, 0x91, 0x10, 0xf8, 0xe9, 0x0e, 0x71,
279 0xbb, 0xc3, 0xab, 0x2a, 0xa8, 0xc4, 0x4d, 0x13, 0xf4, 0x92, 0x94,
280 0x99, 0x25, 0x5b, 0x66, 0x0f, 0x24, 0xec, 0x77, 0x80, 0x0b ) );
284 RANGE ( 65536, 99710 ),
285 TRIM ( 65536, 99710 ),
286 DATA ( 0x97, 0x4b, 0xdd, 0x65, 0x56, 0x7f, 0xde, 0xec, 0xcd, 0xaf, 0xe4,
287 0x57, 0xa9, 0x50, 0x3b, 0x45, 0x48, 0xf6, 0x6e, 0xd3, 0xb1, 0x88,
288 0xdc, 0xfd, 0xa0, 0xac, 0x38, 0x2b, 0x09, 0x71, 0x1a, 0xcc ) );
292 DATA ( 0x00, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
294 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
295 0x00, 0x00, 0x88, 0x00, 0x00, 0x99, 0xde, 0xe0, 0xd0, 0xc3, 0x58,
296 0xe2, 0x68, 0x4b, 0x62, 0x33, 0x0d, 0x32, 0xb5, 0xf1, 0x97, 0x87,
297 0x24, 0xa0, 0xd0, 0xa5, 0x2b, 0xdc, 0x5e, 0x78, 0x1f, 0xae, 0x71,
298 0xff, 0x57, 0xa8, 0xbe, 0x3d, 0xd4, 0x58, 0x03, 0x7e, 0xd4, 0x04,
299 0x11, 0x6b, 0xb6, 0x16, 0xd9, 0xb1, 0x41, 0x16, 0x08, 0x85, 0x20,
300 0xc4, 0x7c, 0xdc, 0x50, 0xab, 0xce, 0xa3, 0xfa, 0xe1, 0x88, 0xa9,
301 0x8e, 0xa2, 0x2d, 0xf3, 0xc0, 0x00, 0x00, 0xeb, 0xa0, 0x33, 0x81,
302 0xd0, 0xd0, 0xcb, 0x74, 0xf4, 0xb6, 0x13, 0xd8, 0x21, 0x0f, 0x37,
303 0xf0, 0x02, 0xa0, 0x6f, 0x39, 0x10, 0x58, 0x60, 0x96, 0xa1, 0x30,
304 0xd3, 0x43, 0x98, 0xc0, 0x8e, 0x66, 0xd7, 0xbc, 0xb8, 0xb6, 0xeb,
305 0x77, 0x83, 0xe4, 0xf8, 0x07, 0x64, 0x7b, 0x63, 0xf1, 0x46, 0xb5,
306 0x2f, 0x4a, 0xc8, 0x9c, 0xcc, 0x7a, 0xbf, 0x5f, 0xa1, 0x1a, 0xca,
307 0xfc, 0x2a, 0xcf, 0x50, 0x28, 0x58, 0x6c ),
312 RANGE ( 0, 39390 ), 1, 39390,
313 DATA ( 0xe0, 0xd0, 0xc3, 0x58, 0xe2, 0x68, 0x4b, 0x62, 0x33, 0x0d, 0x32,
314 0xb5, 0xf1, 0x97, 0x87, 0x24, 0xa0, 0xd0, 0xa5, 0x2b, 0xdc, 0x5e,
315 0x78, 0x1f, 0xae, 0x71, 0xff, 0x57, 0xa8, 0xbe, 0x3d, 0xd4 ),
316 DATA ( 0x58, 0x03, 0x7e, 0xd4, 0x04, 0x11, 0x6b, 0xb6, 0x16, 0xd9, 0xb1,
317 0x41, 0x16, 0x08, 0x85, 0x20, 0xc4, 0x7c, 0xdc, 0x50, 0xab, 0xce,
318 0xa3, 0xfa, 0xe1, 0x88, 0xa9, 0x8e, 0xa2, 0x2d, 0xf3, 0xc0 ),
319 DATA ( 0x33, 0x71, 0xbb, 0xea, 0xdd, 0xb6, 0x23, 0x53, 0xad, 0xce, 0xf9,
320 0x70, 0xa0, 0x6f, 0xdf, 0x65, 0x00, 0x1e, 0x04, 0x21, 0xf4, 0xc7,
321 0x10, 0x82, 0x76, 0xb0, 0xc3, 0x7a, 0x9f, 0x9e, 0xc1, 0x0f ) );
327 DATA ( 0xe0, 0xd0, 0xc3, 0x58, 0xe2, 0x68, 0x4b, 0x62, 0x33, 0x0d, 0x32,
328 0xb5, 0xf1, 0x97, 0x87, 0x24, 0xa0, 0xd0, 0xa5, 0x2b, 0xdc, 0x5e,
329 0x78, 0x1f, 0xae, 0x71, 0xff, 0x57, 0xa8, 0xbe, 0x3d, 0xd4 ) );
333 RANGE ( 39390, 99710 ), 1, 60320,
334 DATA ( 0x33, 0x81, 0xd0, 0xd0, 0xcb, 0x74, 0xf4, 0xb6, 0x13, 0xd8, 0x21,
335 0x0f, 0x37, 0xf0, 0x02, 0xa0, 0x6f, 0x39, 0x10, 0x58, 0x60, 0x96,
336 0xa1, 0x30, 0xd3, 0x43, 0x98, 0xc0, 0x8e, 0x66, 0xd7, 0xbc ),
337 DATA ( 0xb8, 0xb6, 0xeb, 0x77, 0x83, 0xe4, 0xf8, 0x07, 0x64, 0x7b, 0x63,
338 0xf1, 0x46, 0xb5, 0x2f, 0x4a, 0xc8, 0x9c, 0xcc, 0x7a, 0xbf, 0x5f,
339 0xa1, 0x1a, 0xca, 0xfc, 0x2a, 0xcf, 0x50, 0x28, 0x58, 0x6c ),
340 DATA ( 0xd7, 0xe9, 0x24, 0x42, 0x5e, 0x8f, 0x4f, 0x88, 0xf0, 0x1d, 0xc6,
341 0xa9, 0xbb, 0x1b, 0xc3, 0x7b, 0xe1, 0x13, 0xec, 0x79, 0x17, 0xc7,
342 0x45, 0xd4, 0x96, 0x5c, 0x2b, 0x55, 0xfa, 0x16, 0x3a, 0x6e ) );
346 RANGE ( 39390, 99710 ),
347 TRIM ( 39390, 99710 ),
348 DATA ( 0x33, 0x81, 0xd0, 0xd0, 0xcb, 0x74, 0xf4, 0xb6, 0x13, 0xd8, 0x21,
349 0x0f, 0x37, 0xf0, 0x02, 0xa0, 0x6f, 0x39, 0x10, 0x58, 0x60, 0x96,
350 0xa1, 0x30, 0xd3, 0x43, 0x98, 0xc0, 0x8e, 0x66, 0xd7, 0xbc ) );
362 const char *file,
unsigned int line ) {
366 info ) == 0, file, line );
371 okx (
info->digest ==
test->expected_digest, file, line );
372 okx (
info->digestsize ==
test->expected_digestsize, file, line );
373 okx (
info->range.start ==
test->expected_range.start, file, line );
374 okx (
info->range.end ==
test->expected_range.end, file, line );
375 okx (
info->trim.start ==
test->expected_trim.start, file, line );
376 okx (
info->trim.end ==
test->expected_trim.end, file, line );
377 okx (
info->trim.start >=
info->range.start, file, line );
378 okx (
info->trim.end <=
info->range.end, file, line );
379 okx (
info->segments ==
test->expected_segments, file, line );
381 #define peerdist_info_ok( test, info ) \ 382 peerdist_info_okx ( test, info, __FILE__, __LINE__ ) 396 const char *file,
unsigned int line ) {
406 okx (
segment->range.start ==
test->expected_range.start, file, line );
407 okx (
segment->range.end ==
test->expected_range.end, file, line );
417 #define peerdist_info_segment_ok( test, info, segment ) \ 418 peerdist_info_segment_okx ( test, info, segment, __FILE__, __LINE__ ) 433 const char *file,
unsigned int line ) {
444 okx (
block->range.start ==
test->expected_range.start, file, line );
445 okx (
block->range.end ==
test->expected_range.end, file, line );
446 okx (
block->trim.start ==
test->expected_trim.start, file, line );
447 okx (
block->trim.end ==
test->expected_trim.end, file, line );
451 #define peerdist_info_block_ok( test, segment, block ) \ 452 peerdist_info_block_okx ( test, segment, block, __FILE__, __LINE__ ) 467 uint8_t *pass,
size_t pass_len,
468 const char *file,
unsigned int line ) {
489 #define peerdist_info_passphrase_ok( test, info, pass, pass_len ) \ 490 peerdist_info_passphrase_okx ( test, info, pass, pass_len, \ 505 passphrase,
sizeof ( passphrase ) );
513 passphrase,
sizeof ( passphrase ) );
517 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.
Access to external ("user") memory.
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.
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
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.