MCPcopy Create free account
hub / github.com/cisco/libsrtp / cipher_driver_test_buffering

Function cipher_driver_test_buffering

crypto/test/cipher_driver.c:351–424  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

349
350#define INITIAL_BUFLEN 1024
351srtp_err_status_t cipher_driver_test_buffering(srtp_cipher_t *c)
352{
353 int i, j, num_trials = 1000;
354 unsigned len, buflen = INITIAL_BUFLEN;
355 uint8_t buffer0[INITIAL_BUFLEN], buffer1[INITIAL_BUFLEN], *current, *end;
356 uint8_t idx[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
357 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34 };
358 srtp_err_status_t status;
359
360 printf("testing output buffering for cipher %s...", c->type->description);
361
362 for (i = 0; i < num_trials; i++) {
363 /* set buffers to zero */
364 for (j = 0; j < (int)buflen; j++) {
365 buffer0[j] = buffer1[j] = 0;
366 }
367
368 /* initialize cipher */
369 status = srtp_cipher_set_iv(c, (uint8_t *)idx, srtp_direction_encrypt);
370 if (status)
371 return status;
372
373 /* generate 'reference' value by encrypting all at once */
374 status = srtp_cipher_encrypt(c, buffer0, &buflen);
375 if (status)
376 return status;
377
378 /* re-initialize cipher */
379 status = srtp_cipher_set_iv(c, (uint8_t *)idx, srtp_direction_encrypt);
380 if (status)
381 return status;
382
383 /* now loop over short lengths until buffer1 is encrypted */
384 current = buffer1;
385 end = buffer1 + buflen;
386 while (current < end) {
387 /* choose a short length */
388 len = srtp_cipher_rand_u32_for_tests() & 0x01f;
389
390 /* make sure that len doesn't cause us to overreach the buffer */
391 if (current + len > end)
392 len = (unsigned)(end - current);
393
394 status = srtp_cipher_encrypt(c, current, &len);
395 if (status)
396 return status;
397
398 /* advance pointer into buffer1 to reflect encryption */
399 current += len;
400
401 /* if buffer1 is all encrypted, break out of loop */
402 if (current == end)
403 break;
404 }
405
406 /* compare buffers */
407 for (j = 0; j < (int)buflen; j++) {
408 if (buffer0[j] != buffer1[j]) {

Callers 1

mainFunction · 0.85

Calls 4

srtp_cipher_set_ivFunction · 0.85
srtp_cipher_encryptFunction · 0.85
octet_string_hex_stringFunction · 0.85

Tested by

no test coverage detected