1 diff -purN -x CVS -x '*~' -x '.*' -x 'obj-*' srtp-lin/crypto/include/crypto_math.h srtp/crypto/include/crypto_math.h 2 --- srtp-lin/crypto/include/crypto_math.h 2006-06-08 13:00:27.000000000 -0400 3 +++ srtp/crypto/include/crypto_math.h 2009-04-22 19:03:15.000000000 -0400 4 @@ -233,40 +233,6 @@ void 5 octet_string_set_to_zero(uint8_t *s, int len); 6 7 8 -/* 9 - * functions manipulating bit_vector_t 10 - * 11 - * A bitvector_t consists of an array of words and an integer 12 - * representing the number of significant bits stored in the array. 13 - * The bits are packed as follows: the least significant bit is that 14 - * of word[0], while the most significant bit is the nth most 15 - * significant bit of word[m], where length = bits_per_word * m + n. 16 - * 17 - */ 18 - 19 -#define bits_per_word 32 20 -#define bytes_per_word 4 21 - 22 -typedef struct { 23 - uint32_t length; 24 - uint32_t *word; 25 -} bitvector_t; 26 - 27 -int 28 -bitvector_alloc(bitvector_t *v, unsigned long length); 29 - 30 -void 31 -bitvector_set_bit(bitvector_t *v, int bit_index); 32 - 33 -int 34 -bitvector_get_bit(const bitvector_t *v, int bit_index); 35 - 36 -int 37 -bitvector_print_hex(const bitvector_t *v, FILE *stream); 38 - 39 -int 40 -bitvector_set_from_hex(bitvector_t *v, char *string); 41 - 42 #endif /* MATH_H */ 43 44 45 diff -purN -x CVS -x '*~' -x '.*' -x 'obj-*' srtp-lin/crypto/include/datatypes.h srtp/crypto/include/datatypes.h 46 --- srtp-lin/crypto/include/datatypes.h 2006-07-12 18:41:57.000000000 -0400 47 +++ srtp/crypto/include/datatypes.h 2009-04-22 19:20:01.000000000 -0400 48 @@ -424,4 +424,83 @@ static inline uint64_t be64_to_cpu(uint6 49 50 #endif /* WORDS_BIGENDIAN */ 51 52 +/* 53 + * functions manipulating bitvector_t 54 + * 55 + * A bitvector_t consists of an array of words and an integer 56 + * representing the number of significant bits stored in the array. 57 + * The bits are packed as follows: the least significant bit is that 58 + * of word[0], while the most significant bit is the nth most 59 + * significant bit of word[m], where length = bits_per_word * m + n. 60 + * 61 + */ 62 + 63 +#define bits_per_word 32 64 +#define bytes_per_word 4 65 + 66 +typedef struct { 67 + uint32_t length; 68 + uint32_t *word; 69 +} bitvector_t; 70 + 71 + 72 +#define _bitvector_get_bit(v, bit_index) \ 73 +( \ 74 + ((((v)->word[((bit_index) >> 5)]) >> ((bit_index) & 31)) & 1) \ 75 +) 76 + 77 + 78 +#define _bitvector_set_bit(v, bit_index) \ 79 +( \ 80 + (((v)->word[((bit_index) >> 5)] |= ((uint32_t)1 << ((bit_index) & 31)))) \ 81 +) 82 + 83 +#define _bitvector_clear_bit(v, bit_index) \ 84 +( \ 85 + (((v)->word[((bit_index) >> 5)] &= ~((uint32_t)1 << ((bit_index) & 31)))) \ 86 +) 87 + 88 +#define _bitvector_get_length(v) \ 89 +( \ 90 + ((v)->length) \ 91 +) 92 + 93 +#ifdef DATATYPES_USE_MACROS /* little functions are really macros */ 94 + 95 +#define bitvector_get_bit(v, bit_index) _bitvector_get_bit(v, bit_index) 96 +#define bitvector_set_bit(v, bit_index) _bitvector_set_bit(v, bit_index) 97 +#define bitvector_clear_bit(v, bit_index) _bitvector_clear_bit(v, bit_index) 98 +#define bitvector_get_length(v) _bitvector_get_length(v) 99 + 100 +#else 101 + 102 +int 103 +bitvector_get_bit(const bitvector_t *v, int bit_index); 104 + 105 +void 106 +bitvector_set_bit(bitvector_t *v, int bit_index); 107 + 108 +void 109 +bitvector_clear_bit(bitvector_t *v, int bit_index); 110 + 111 +unsigned long 112 +bitvector_get_length(const bitvector_t *v); 113 + 114 +#endif 115 + 116 +int 117 +bitvector_alloc(bitvector_t *v, unsigned long length); 118 + 119 +void 120 +bitvector_dealloc(bitvector_t *v); 121 + 122 +void 123 +bitvector_set_to_zero(bitvector_t *x); 124 + 125 +void 126 +bitvector_left_shift(bitvector_t *x, int index); 127 + 128 +char * 129 +bitvector_bit_string(bitvector_t *x, char* buf, int len); 130 + 131 #endif /* _DATATYPES_H */ 132 diff -purN -x CVS -x '*~' -x '.*' -x 'obj-*' srtp-lin/crypto/include/rdbx.h srtp/crypto/include/rdbx.h 133 --- srtp-lin/crypto/include/rdbx.h 2007-06-15 14:17:40.000000000 -0400 134 +++ srtp/crypto/include/rdbx.h 2009-04-22 19:03:15.000000000 -0400 135 @@ -46,19 +46,29 @@ typedef uint64_t xtd_seq_num_t; 136 137 typedef struct { 138 xtd_seq_num_t index; 139 - v128_t bitmask; 140 + bitvector_t bitmask; 141 } rdbx_t; 142 143 144 /* 145 - * rdbx_init(rdbx_ptr) 146 + * rdbx_init(rdbx_ptr, ws) 147 * 148 - * initializes the rdbx pointed to by its argument, setting the 149 - * rollover counter and sequence number to zero 150 + * initializes the rdbx pointed to by its argument with the window size ws, 151 + * setting the rollover counter and sequence number to zero 152 */ 153 154 err_status_t 155 -rdbx_init(rdbx_t *rdbx); 156 +rdbx_init(rdbx_t *rdbx, unsigned long ws); 157 + 158 + 159 +/* 160 + * rdbx_uninit(rdbx_ptr) 161 + * 162 + * frees memory associated with the rdbx 163 + */ 164 + 165 +err_status_t 166 +rdbx_uninit(rdbx_t *rdbx); 167 168 169 /* 170 @@ -127,6 +137,15 @@ rdbx_get_packet_index(const rdbx_t *rdbx 171 * api instead! 172 */ 173 174 +/* 175 + * rdbx_get_ws(rdbx_ptr) 176 + * 177 + * gets the window size which was used to initialize the rdbx 178 + */ 179 + 180 +unsigned long 181 +rdbx_get_window_size(const rdbx_t *rdbx); 182 + 183 184 /* index_init(&pi) initializes a packet index pi (sets it to zero) */ 185 186 diff -purN -x CVS -x '*~' -x '.*' -x 'obj-*' srtp-lin/crypto/math/datatypes.c srtp/crypto/math/datatypes.c 187 --- srtp-lin/crypto/math/datatypes.c 2006-07-18 15:45:46.000000000 -0400 188 +++ srtp/crypto/math/datatypes.c 2009-04-22 19:03:15.000000000 -0400 189 @@ -387,6 +387,124 @@ v128_left_shift(v128_t *x, int index) { 190 191 } 192 193 +/* functions manipulating bitvector_t */ 194 + 195 +#ifndef DATATYPES_USE_MACROS /* little functions are not macros */ 196 + 197 +int 198 +bitvector_get_bit(const bitvector_t *v, int bit_index) 199 +{ 200 + return _bitvector_get_bit(v, bit_index); 201 +} 202 + 203 +void 204 +bitvector_set_bit(bitvector_t *v, int bit_index) 205 +{ 206 + _bitvector_set_bit(v, bit_index); 207 +} 208 + 209 +void 210 +bitvector_clear_bit(bitvector_t *v, int bit_index) 211 +{ 212 + _bitvector_clear_bit(v, bit_index); 213 +} 214 + 215 + 216 +#endif /* DATATYPES_USE_MACROS */ 217 + 218 +int 219 +bitvector_alloc(bitvector_t *v, unsigned long length) { 220 + unsigned long l; 221 + 222 + /* Round length up to a multiple of bits_per_word */ 223 + length = (length + bits_per_word - 1) & ~(unsigned long)((bits_per_word - 1)); 224 + 225 + l = length / bits_per_word * bytes_per_word; 226 + 227 + /* allocate memory, then set parameters */ 228 + if (l == 0) 229 + v->word = NULL; 230 + else { 231 + v->word = (uint32_t*)crypto_alloc(l); 232 + if (v->word == NULL) { 233 + v->word = NULL; 234 + v->length = 0; 235 + return -1; 236 + } 237 + } 238 + v->length = length; 239 + 240 + /* initialize bitvector to zero */ 241 + bitvector_set_to_zero(v); 242 + 243 + return 0; 244 +} 245 + 246 + 247 +void 248 +bitvector_dealloc(bitvector_t *v) { 249 + if (v->word != NULL) 250 + crypto_free(v->word); 251 + v->word = NULL; 252 + v->length = 0; 253 +} 254 + 255 +void 256 +bitvector_set_to_zero(bitvector_t *x) 257 +{ 258 + /* C99 guarantees that memset(0) will set the value 0 for uint32_t */ 259 + memset(x->word, 0, x->length >> 3); 260 +} 261 + 262 +char * 263 +bitvector_bit_string(bitvector_t *x, char* buf, int len) { 264 + int j, index; 265 + uint32_t mask; 266 + 267 + for (j=index=0; j < (int)(x->length>>5) && index < len-1; j++) { 268 + for (mask=0x80000000; mask > 0; mask >>= 1) { 269 + if (x->word[j] & mask) 270 + buf[index] = '1'; 271 + else 272 + buf[index] = '0'; 273 + ++index; 274 + if (index >= len-1) 275 + break; 276 + } 277 + } 278 + buf[index] = 0; /* null terminate string */ 279 + 280 + return buf; 281 +} 282 + 283 +void 284 +bitvector_left_shift(bitvector_t *x, int index) { 285 + int i; 286 + const int base_index = index >> 5; 287 + const int bit_index = index & 31; 288 + const int word_length = x->length >> 5; 289 + 290 + if (index >= (int)x->length) { 291 + bitvector_set_to_zero(x); 292 + return; 293 + } 294 + 295 + if (bit_index == 0) { 296 + for (i=0; i < word_length - base_index; i++) 297 + x->word[i] = x->word[i+base_index]; 298 + } else { 299 + for (i=0; i < word_length - base_index - 1; i++) 300 + x->word[i] = (x->word[i+base_index] >> bit_index) ^ 301 + (x->word[i+base_index+1] << (32 - bit_index)); 302 + x->word[word_length - base_index-1] = x->word[word_length-1] >> bit_index; 303 + } 304 + 305 + /* now wrap up the final portion */ 306 + for (i = word_length - base_index; i < word_length; i++) 307 + x->word[i] = 0; 308 + 309 +} 310 + 311 312 int 313 octet_string_is_eq(uint8_t *a, uint8_t *b, int len) { 314 diff -purN -x CVS -x '*~' -x '.*' -x 'obj-*' srtp-lin/crypto/math/math.c srtp/crypto/math/math.c 315 --- srtp-lin/crypto/math/math.c 2006-06-08 13:00:28.000000000 -0400 316 +++ srtp/crypto/math/math.c 2009-04-22 19:03:15.000000000 -0400 317 @@ -43,7 +43,6 @@ 318 */ 319 320 #include "crypto_math.h" 321 -#include <stdlib.h> /* malloc() used in bitvector_alloc */ 322 323 int 324 octet_weight[256] = { 325 @@ -773,165 +772,6 @@ octet_string_set_to_zero(uint8_t *s, int 326 327 } 328 329 -/* functions manipulating bit_vector_t */ 330 - 331 -#define BITVECTOR_MAX_WORDS 5 332 - 333 -int 334 -bitvector_alloc(bitvector_t *v, unsigned long length) { 335 - unsigned long l = (length + bytes_per_word - 1) / bytes_per_word; 336 - int i; 337 - 338 - /* allocate memory, then set parameters */ 339 - if (l > BITVECTOR_MAX_WORDS) 340 - return -1; 341 - else 342 - l = BITVECTOR_MAX_WORDS; 343 - v->word = malloc(l); 344 - if (v->word == NULL) 345 - return -1; 346 - v->length = length; 347 - 348 - /* initialize bitvector to zero */ 349 - for (i=0; i < (length >> 5); i++) { 350 - v->word = 0; 351 - } 352 - 353 - return 0; 354 -} 355 - 356 -void 357 -bitvector_set_bit(bitvector_t *v, int bit_index) { 358 - 359 - v->word[(bit_index >> 5)] |= (1 << (bit_index & 31)); 360 - 361 -} 362 - 363 -int 364 -bitvector_get_bit(const bitvector_t *v, int bit_index) { 365 - 366 - return ((v->word[(bit_index >> 5)]) >> (bit_index & 31)) & 1; 367 - 368 -} 369 - 370 -#include <stdio.h> 371 - 372 -int 373 -bitvector_print_hex(const bitvector_t *v, FILE *stream) { 374 - int i; 375 - int m = v->length >> 5; 376 - int n = v->length & 31; 377 - char string[9]; 378 - uint32_t tmp; 379 - 380 - /* if length isn't a multiple of four, we can't hex_print */ 381 - if (n & 3) 382 - return -1; 383 - 384 - /* if the length is zero, do nothing */ 385 - if (v->length == 0) 386 - return 0; 387 - 388 - /* 389 - * loop over words from most significant to least significant - 390 - */ 391 - 392 - for (i=m; i > 0; i++) { 393 - char *str = string + 7; 394 - tmp = v->word[i]; 395 - 396 - /* null terminate string */ 397 - string[8] = 0; 398 - 399 - /* loop over nibbles */ 400 - *str-- = nibble_to_hex_char(tmp & 0xf); tmp >>= 4; 401 - *str-- = nibble_to_hex_char(tmp & 0xf); tmp >>= 4; 402 - *str-- = nibble_to_hex_char(tmp & 0xf); tmp >>= 4; 403 - *str-- = nibble_to_hex_char(tmp & 0xf); tmp >>= 4; 404 - *str-- = nibble_to_hex_char(tmp & 0xf); tmp >>= 4; 405 - *str-- = nibble_to_hex_char(tmp & 0xf); tmp >>= 4; 406 - *str-- = nibble_to_hex_char(tmp & 0xf); tmp >>= 4; 407 - *str-- = nibble_to_hex_char(tmp & 0xf); 408 - 409 - /* now print stream */ 410 - fprintf(stream, string); 411 - } 412 - 413 - return 0; 414 - 415 -} 416 - 417 - 418 -int 419 -hex_string_length(char *s) { 420 - int count = 0; 421 - 422 - /* ignore leading zeros */ 423 - while ((*s != 0) && *s == '0') 424 - s++; 425 - 426 - /* count remaining characters */ 427 - while (*s != 0) { 428 - if (hex_char_to_nibble(*s++) == -1) 429 - return -1; 430 - count++; 431 - } 432 - 433 - return count; 434 -} 435 - 436 -int 437 -bitvector_set_from_hex(bitvector_t *v, char *string) { 438 - int num_hex_chars, m, n, i, j; 439 - uint32_t tmp; 440 - 441 - num_hex_chars = hex_string_length(string); 442 - if (num_hex_chars == -1) 443 - return -1; 444 - 445 - /* set length */ 446 - v->length = num_hex_chars * 4; 447 - /* 448 - * at this point, we should subtract away a bit if the high 449 - * bit of the first character is zero, but we ignore that 450 - * for now and assume that we're four-bit aligned - DAM 451 - */ 452 - 453 - 454 - m = num_hex_chars / 8; /* number of words */ 455 - n = num_hex_chars % 8; /* number of nibbles in last word */ 456 - 457 - /* if the length is greater than the bitvector, return an error */ 458 - if (m > BITVECTOR_MAX_WORDS) 459 - return -1; 460 - 461 - /* 462 - * loop over words from most significant - first word is a special 463 - * case 464 - */ 465 - 466 - if (n) { 467 - tmp = 0; 468 - for (i=0; i < n; i++) { 469 - tmp = hex_char_to_nibble(*string++); 470 - tmp <<= 4; 471 - } 472 - v->word[m] = tmp; 473 - } 474 - 475 - /* now loop over the rest of the words */ 476 - for (i=m-1; i >= 0; i--) { 477 - tmp = 0; 478 - for (j=0; j < 8; j++) { 479 - tmp = hex_char_to_nibble(*string++); 480 - tmp <<= 4; 481 - } 482 - v->word[i] = tmp; 483 - } 484 - 485 - return 0; 486 -} 487 - 488 489 /* functions below not yet tested! */ 490 491 diff -purN -x CVS -x '*~' -x '.*' -x 'obj-*' srtp-lin/crypto/replay/rdbx.c srtp/crypto/replay/rdbx.c 492 --- srtp-lin/crypto/replay/rdbx.c 2007-06-15 14:17:40.000000000 -0400 493 +++ srtp/crypto/replay/rdbx.c 2009-04-22 19:03:15.000000000 -0400 494 @@ -45,7 +45,6 @@ 495 496 #include "rdbx.h" 497 498 -#define rdbx_high_bit_in_bitmask 127 499 500 /* 501 * from draft-ietf-avt-srtp-00.txt: 502 @@ -180,17 +179,32 @@ index_guess(const xtd_seq_num_t *local, 503 504 505 /* 506 - * rdbx_init(&r) initalizes the rdbx_t pointed to by r 507 + * rdbx_init(&r, ws) initializes the rdbx_t pointed to by r with window size ws 508 */ 509 510 err_status_t 511 -rdbx_init(rdbx_t *rdbx) { 512 - v128_set_to_zero(&rdbx->bitmask); 513 +rdbx_init(rdbx_t *rdbx, unsigned long ws) { 514 + if (ws == 0) 515 + return err_status_bad_param; 516 + 517 + if (bitvector_alloc(&rdbx->bitmask, ws) != 0) 518 + return err_status_alloc_fail; 519 + 520 index_init(&rdbx->index); 521 522 return err_status_ok; 523 } 524 525 +/* 526 + * rdbx_uninit(&r) uninitializes the rdbx_t pointed to by r 527 + */ 528 + 529 +err_status_t 530 +rdbx_uninit(rdbx_t *rdbx) { 531 + bitvector_dealloc(&rdbx->bitmask); 532 + 533 + return err_status_ok; 534 +} 535 536 /* 537 * rdbx_set_roc(rdbx, roc) initalizes the rdbx_t at the location rdbx 538 @@ -202,7 +216,7 @@ rdbx_init(rdbx_t *rdbx) { 539 540 err_status_t 541 rdbx_set_roc(rdbx_t *rdbx, uint32_t roc) { 542 - v128_set_to_zero(&rdbx->bitmask); 543 + bitvector_set_to_zero(&rdbx->bitmask); 544 545 #ifdef NO_64BIT_MATH 546 #error not yet implemented 547 @@ -231,6 +245,17 @@ rdbx_get_packet_index(const rdbx_t *rdbx 548 } 549 550 /* 551 + * rdbx_get_window_size(rdbx) returns the value of the window size 552 + * for the rdbx_t pointed to by rdbx 553 + * 554 + */ 555 + 556 +unsigned long 557 +rdbx_get_window_size(const rdbx_t *rdbx) { 558 + return bitvector_get_length(&rdbx->bitmask); 559 +} 560 + 561 +/* 562 * rdbx_check(&r, delta) checks to see if the xtd_seq_num_t 563 * which is at rdbx->index + delta is in the rdb 564 */ 565 @@ -240,11 +265,11 @@ rdbx_check(const rdbx_t *rdbx, int delta 566 567 if (delta > 0) { /* if delta is positive, it's good */ 568 return err_status_ok; 569 - } else if (rdbx_high_bit_in_bitmask + delta < 0) { 570 + } else if ((int)(bitvector_get_length(&rdbx->bitmask) - 1) + delta < 0) { 571 /* if delta is lower than the bitmask, it's bad */ 572 return err_status_replay_old; 573 - } else if (v128_get_bit(&rdbx->bitmask, 574 - rdbx_high_bit_in_bitmask + delta) == 1) { 575 + } else if (bitvector_get_bit(&rdbx->bitmask, 576 + (int)(bitvector_get_length(&rdbx->bitmask) - 1) + delta) == 1) { 577 /* delta is within the window, so check the bitmask */ 578 return err_status_replay_fail; 579 } 580 @@ -268,11 +293,11 @@ rdbx_add_index(rdbx_t *rdbx, int delta) 581 if (delta > 0) { 582 /* shift forward by delta */ 583 index_advance(&rdbx->index, delta); 584 - v128_left_shift(&rdbx->bitmask, delta); 585 - v128_set_bit(&rdbx->bitmask, 127); 586 + bitvector_left_shift(&rdbx->bitmask, delta); 587 + bitvector_set_bit(&rdbx->bitmask, bitvector_get_length(&rdbx->bitmask) - 1); 588 } else { 589 /* delta is in window, so flip bit in bitmask */ 590 - v128_set_bit(&rdbx->bitmask, -delta); 591 + bitvector_set_bit(&rdbx->bitmask, -delta); 592 } 593 594 /* note that we need not consider the case that delta == 0 */ 595 diff -purN -x CVS -x '*~' -x '.*' -x 'obj-*' srtp-lin/include/srtp.h srtp/include/srtp.h 596 --- srtp-lin/include/srtp.h 2007-06-15 14:17:40.000000000 -0400 597 +++ srtp/include/srtp.h 2009-04-22 19:06:22.000000000 -0400 598 @@ -223,6 +223,8 @@ typedef struct srtp_policy_t { 599 * this stream. */ 600 ekt_policy_t ekt; /**< Pointer to the EKT policy structure 601 * for this stream (if any) */ 602 + unsigned long window_size; /**< The window size to use for replay 603 + * protection. */ 604 struct srtp_policy_t *next; /**< Pointer to next stream policy. */ 605 } srtp_policy_t; 606 607 diff -purN -x CVS -x '*~' -x '.*' -x 'obj-*' srtp-lin/srtp/srtp.c srtp/srtp/srtp.c 608 --- srtp-lin/srtp/srtp.c 2007-06-15 14:17:40.000000000 -0400 609 +++ srtp/srtp/srtp.c 2009-04-22 19:18:43.000000000 -0400 610 @@ -275,7 +275,10 @@ srtp_stream_clone(const srtp_stream_ctx_ 611 return status; 612 613 /* initialize replay databases */ 614 - rdbx_init(&str->rtp_rdbx); 615 + status = rdbx_init(&str->rtp_rdbx, 616 + rdbx_get_window_size(&stream_template->rtp_rdbx)); 617 + if (status) 618 + return status; 619 rdb_init(&str->rtcp_rdb); 620 621 /* set ssrc to that provided */ 622 @@ -491,7 +494,8 @@ srtp_stream_init(srtp_stream_ctx_t *srtp 623 p->ssrc.value); 624 625 /* initialize replay database */ 626 - rdbx_init(&srtp->rtp_rdbx); 627 + err = rdbx_init(&srtp->rtp_rdbx, p->window_size); 628 + if (err) return err; 629 630 /* initialize key limit to maximum value */ 631 #ifdef NO_64BIT_MATH 632 @@ -525,14 +529,20 @@ srtp_stream_init(srtp_stream_ctx_t *srtp 633 634 /* initialize keys */ 635 err = srtp_stream_init_keys(srtp, p->key); 636 - if (err) return err; 637 + if (err) { 638 + rdbx_uninit(&srtp->rtp_rdbx); 639 + return err; 640 + } 641 642 /* 643 * if EKT is in use, then initialize the EKT data associated with 644 * the stream 645 */ 646 err = ekt_stream_init_from_policy(srtp->ekt, p->ekt); 647 - if (err) return err; 648 + if (err) { 649 + rdbx_uninit(&srtp->rtp_rdbx); 650 + return err; 651 + } 652 653 return err_status_ok; 654 } 655 diff -purN -x CVS -x '*~' -x '.*' -x 'obj-*' srtp-lin/test/dtls_srtp_driver.c srtp/test/dtls_srtp_driver.c 656 --- srtp-lin/test/dtls_srtp_driver.c 2009-04-23 15:50:26.000000000 -0400 657 +++ srtp/test/dtls_srtp_driver.c 2009-04-23 15:50:48.000000000 -0400 658 @@ -184,6 +184,7 @@ test_dtls_srtp() { 659 if (err) return err; 660 policy.ssrc.type = ssrc_any_inbound; 661 policy.ekt = NULL; 662 + policy.window_size = 128; 663 policy.next = NULL; 664 665 err = srtp_add_stream(s, &policy); 666 diff -purN -x CVS -x '*~' -x '.*' -x 'obj-*' srtp-lin/test/rdbx_driver.c srtp/test/rdbx_driver.c 667 --- srtp-lin/test/rdbx_driver.c 2006-07-17 16:41:22.000000000 -0400 668 +++ srtp/test/rdbx_driver.c 2009-04-22 19:22:21.000000000 -0400 669 @@ -55,10 +55,10 @@ 670 #include "ut_sim.h" 671 672 err_status_t 673 -test_replay_dbx(int num_trials); 674 +test_replay_dbx(int num_trials, unsigned long ws); 675 676 double 677 -rdbx_check_adds_per_second(int num_trials); 678 +rdbx_check_adds_per_second(int num_trials, unsigned long ws); 679 680 void 681 usage(char *prog_name) { 682 @@ -99,9 +99,18 @@ main (int argc, char *argv[]) { 683 usage(argv[0]); 684 685 if (do_validation) { 686 - printf("testing rdbx_t...\n"); 687 + printf("testing rdbx_t (ws=128)...\n"); 688 689 - status = test_replay_dbx(1 << 12); 690 + status = test_replay_dbx(1 << 12, 128); 691 + if (status) { 692 + printf("failed\n"); 693 + exit(1); 694 + } 695 + printf("passed\n"); 696 + 697 + printf("testing rdbx_t (ws=1024)...\n"); 698 + 699 + status = test_replay_dbx(1 << 12, 1024); 700 if (status) { 701 printf("failed\n"); 702 exit(1); 703 @@ -110,8 +119,10 @@ main (int argc, char *argv[]) { 704 } 705 706 if (do_timing_test) { 707 - rate = rdbx_check_adds_per_second(1 << 18); 708 - printf("rdbx_check/replay_adds per second: %e\n", rate); 709 + rate = rdbx_check_adds_per_second(1 << 18, 128); 710 + printf("rdbx_check/replay_adds per second (ws=128): %e\n", rate); 711 + rate = rdbx_check_adds_per_second(1 << 18, 1024); 712 + printf("rdbx_check/replay_adds per second (ws=1024): %e\n", rate); 713 } 714 715 return 0; 716 @@ -119,8 +130,11 @@ main (int argc, char *argv[]) { 717 718 void 719 print_rdbx(rdbx_t *rdbx) { 720 + char buf[2048]; 721 printf("rdbx: {%llu, %s}\n", 722 - (unsigned long long)(rdbx->index), v128_bit_string(&rdbx->bitmask)); 723 + (unsigned long long)(rdbx->index), 724 + bitvector_bit_string(&rdbx->bitmask, buf, sizeof(buf)) 725 +); 726 } 727 728 729 @@ -194,17 +208,15 @@ rdbx_check_unordered(rdbx_t *rdbx, uint3 730 return err_status_ok; 731 } 732 733 -#define MAX_IDX 160 734 - 735 err_status_t 736 -test_replay_dbx(int num_trials) { 737 +test_replay_dbx(int num_trials, unsigned long ws) { 738 rdbx_t rdbx; 739 uint32_t idx, ircvd; 740 ut_connection utc; 741 err_status_t status; 742 int num_fp_trials; 743 744 - status = rdbx_init(&rdbx); 745 + status = rdbx_init(&rdbx, ws); 746 if (status) { 747 printf("replay_init failed with error code %d\n", status); 748 exit(1); 749 @@ -241,7 +253,9 @@ test_replay_dbx(int num_trials) { 750 printf("passed\n"); 751 752 /* re-initialize */ 753 - if (rdbx_init(&rdbx) != err_status_ok) { 754 + rdbx_uninit(&rdbx); 755 + 756 + if (rdbx_init(&rdbx, ws) != err_status_ok) { 757 printf("replay_init failed\n"); 758 return err_status_init_fail; 759 } 760 @@ -263,6 +277,8 @@ test_replay_dbx(int num_trials) { 761 } 762 printf("passed\n"); 763 764 + rdbx_uninit(&rdbx); 765 + 766 return err_status_ok; 767 } 768 769 @@ -272,7 +288,7 @@ test_replay_dbx(int num_trials) { 770 #include <stdlib.h> /* for random() */ 771 772 double 773 -rdbx_check_adds_per_second(int num_trials) { 774 +rdbx_check_adds_per_second(int num_trials, unsigned long ws) { 775 uint32_t i; 776 int delta; 777 rdbx_t rdbx; 778 @@ -280,7 +296,7 @@ rdbx_check_adds_per_second(int num_trial 779 clock_t timer; 780 int failures; /* count number of failures */ 781 782 - if (rdbx_init(&rdbx) != err_status_ok) { 783 + if (rdbx_init(&rdbx, ws) != err_status_ok) { 784 printf("replay_init failed\n"); 785 exit(1); 786 } 787 @@ -301,6 +317,8 @@ rdbx_check_adds_per_second(int num_trial 788 789 printf("number of failures: %d \n", failures); 790 791 + rdbx_uninit(&rdbx); 792 + 793 return (double) CLOCKS_PER_SEC * num_trials / timer; 794 } 795 796 diff -purN -x CVS -x '*~' -x '.*' -x 'obj-*' srtp-lin/test/rtpw.c srtp/test/rtpw.c 797 --- srtp-lin/test/rtpw.c 2006-07-17 16:41:22.000000000 -0400 798 +++ srtp/test/rtpw.c 2009-04-22 19:16:52.000000000 -0400 799 @@ -330,6 +330,7 @@ main (int argc, char *argv[]) { 800 policy.ssrc.value = ssrc; 801 policy.key = (uint8_t *) key; 802 policy.next = NULL; 803 + policy.window_size = 128; 804 policy.rtp.sec_serv = sec_servs; 805 policy.rtcp.sec_serv = sec_serv_none; /* we don't do RTCP anyway */ 806 807 @@ -382,6 +383,7 @@ main (int argc, char *argv[]) { 808 policy.rtcp.auth_key_len = 0; 809 policy.rtcp.auth_tag_len = 0; 810 policy.rtcp.sec_serv = sec_serv_none; 811 + policy.window_size = 0; 812 policy.next = NULL; 813 } 814 815 diff -purN -x CVS -x '*~' -x '.*' -x 'obj-*' srtp-lin/test/srtp_driver.c srtp/test/srtp_driver.c 816 --- srtp-lin/test/srtp_driver.c 2009-04-22 18:20:27.000000000 -0400 817 +++ srtp/test/srtp_driver.c 2009-04-22 19:16:52.000000000 -0400 818 @@ -321,6 +321,8 @@ main (int argc, char *argv[]) { 819 policy.ssrc.type = ssrc_specific; 820 policy.ssrc.value = 0xdecafbad; 821 policy.key = test_key; 822 + policy.ekt = NULL; 823 + policy.window_size = 128; 824 policy.next = NULL; 825 826 printf("mips estimate: %e\n", mips); 827 @@ -989,14 +991,16 @@ srtp_session_print_policy(srtp_t srtp) { 828 "# rtp services: %s\r\n" 829 "# rtcp cipher: %s\r\n" 830 "# rtcp auth: %s\r\n" 831 - "# rtcp services: %s\r\n", 832 + "# rtcp services: %s\r\n" 833 + "# window size: %lu\r\n", 834 direction[stream->direction], 835 stream->rtp_cipher->type->description, 836 stream->rtp_auth->type->description, 837 serv_descr[stream->rtp_services], 838 stream->rtcp_cipher->type->description, 839 stream->rtcp_auth->type->description, 840 - serv_descr[stream->rtcp_services]); 841 + serv_descr[stream->rtcp_services], 842 + rdbx_get_window_size(&stream->rtp_rdbx)); 843 } 844 845 /* loop over streams in session, printing the policy of each */ 846 @@ -1011,14 +1015,16 @@ srtp_session_print_policy(srtp_t srtp) { 847 "# rtp services: %s\r\n" 848 "# rtcp cipher: %s\r\n" 849 "# rtcp auth: %s\r\n" 850 - "# rtcp services: %s\r\n", 851 + "# rtcp services: %s\r\n" 852 + "# window size: %lu\r\n", 853 stream->ssrc, 854 stream->rtp_cipher->type->description, 855 stream->rtp_auth->type->description, 856 serv_descr[stream->rtp_services], 857 stream->rtcp_cipher->type->description, 858 stream->rtcp_auth->type->description, 859 - serv_descr[stream->rtcp_services]); 860 + serv_descr[stream->rtcp_services], 861 + rdbx_get_window_size(&stream->rtp_rdbx)); 862 863 /* advance to next stream in the list */ 864 stream = stream->next; 865 @@ -1172,6 +1178,8 @@ srtp_validate() { 866 policy.ssrc.type = ssrc_specific; 867 policy.ssrc.value = 0xcafebabe; 868 policy.key = test_key; 869 + policy.ekt = NULL; 870 + policy.window_size = 128; 871 policy.next = NULL; 872 873 status = srtp_create(&srtp_snd, &policy); 874 @@ -1328,6 +1336,7 @@ const srtp_policy_t default_policy = { 875 }, 876 test_key, 877 NULL, /* indicates that EKT is not in use */ 878 + 128, /* replay window size */ 879 NULL 880 }; 881 882 @@ -1351,6 +1360,7 @@ const srtp_policy_t aes_tmmh_policy = { 883 }, 884 test_key, 885 NULL, /* indicates that EKT is not in use */ 886 + 128, /* replay window size */ 887 NULL 888 }; 889 890 @@ -1374,6 +1384,7 @@ const srtp_policy_t tmmh_only_policy = { 891 }, 892 test_key, 893 NULL, /* indicates that EKT is not in use */ 894 + 128, /* replay window size */ 895 NULL 896 }; 897 898 @@ -1397,6 +1408,7 @@ const srtp_policy_t aes_only_policy = { 899 }, 900 test_key, 901 NULL, /* indicates that EKT is not in use */ 902 + 128, /* replay window size */ 903 NULL 904 }; 905 906 @@ -1420,6 +1432,7 @@ const srtp_policy_t hmac_only_policy = { 907 }, 908 test_key, 909 NULL, /* indicates that EKT is not in use */ 910 + 128, /* replay window size */ 911 NULL 912 }; 913 914 @@ -1443,6 +1456,7 @@ const srtp_policy_t null_policy = { 915 }, 916 test_key, 917 NULL, /* indicates that EKT is not in use */ 918 + 128, /* replay window size */ 919 NULL 920 }; 921 922 @@ -1480,6 +1494,7 @@ const srtp_policy_t hmac_only_with_ekt_p 923 }, 924 test_key, 925 &ekt_test_policy, /* indicates that EKT is not in use */ 926 + 128, /* replay window size */ 927 NULL 928 }; 929 930 @@ -1531,5 +1546,7 @@ const srtp_policy_t wildcard_policy = { 931 sec_serv_conf_and_auth /* security services flag */ 932 }, 933 test_key, 934 + NULL, 935 + 128, /* replay window size */ 936 NULL 937 }; 938