Ignore:
Timestamp:
Jul 4, 2017 5:22:51 AM (7 years ago)
Author:
nanang
Message:

Close #1993: Updated bundled libSRTP version to 2.1.0.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/third_party/srtp/crypto/replay/rdb.c

    r5261 r5614  
    99 
    1010/* 
    11  *       
    12  * Copyright (c) 2001-2006, Cisco Systems, Inc. 
     11 * 
     12 * Copyright (c) 2001-2017, Cisco Systems, Inc. 
    1313 * All rights reserved. 
    14  *  
     14 * 
    1515 * Redistribution and use in source and binary forms, with or without 
    1616 * modification, are permitted provided that the following conditions 
    1717 * are met: 
    18  *  
     18 * 
    1919 *   Redistributions of source code must retain the above copyright 
    2020 *   notice, this list of conditions and the following disclaimer. 
    21  *  
     21 * 
    2222 *   Redistributions in binary form must reproduce the above 
    2323 *   copyright notice, this list of conditions and the following 
    2424 *   disclaimer in the documentation and/or other materials provided 
    2525 *   with the distribution. 
    26  *  
     26 * 
    2727 *   Neither the name of the Cisco Systems, Inc. nor the names of its 
    2828 *   contributors may be used to endorse or promote products derived 
    2929 *   from this software without specific prior written permission. 
    30  *  
     30 * 
    3131 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    3232 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
     
    5454/* 
    5555 * this implementation of a replay database works as follows: 
    56  *  
     56 * 
    5757 * window_start is the index of the first packet in the window 
    5858 * bitmask      a bit-buffer, containing the most recently entered 
    59  *              index as the leftmost bit  
     59 *              index as the leftmost bit 
    6060 * 
    6161 */ 
    6262 
    63 /* rdb_init initalizes rdb */ 
    64  
    65 err_status_t 
    66 rdb_init(rdb_t *rdb) { 
    67   v128_set_to_zero(&rdb->bitmask); 
    68   rdb->window_start = 0; 
    69   return err_status_ok; 
     63/* srtp_rdb_init initalizes rdb */ 
     64srtp_err_status_t srtp_rdb_init (srtp_rdb_t *rdb) 
     65{ 
     66    v128_set_to_zero(&rdb->bitmask); 
     67    rdb->window_start = 0; 
     68    return srtp_err_status_ok; 
    7069} 
    7170 
    7271/* 
    73  * rdb_check checks to see if index appears in rdb 
     72 * srtp_rdb_check checks to see if index appears in rdb 
    7473 */ 
     74srtp_err_status_t srtp_rdb_check (const srtp_rdb_t *rdb, uint32_t p_index) 
     75{ 
    7576 
    76 err_status_t 
    77 rdb_check(const rdb_t *rdb, uint32_t p_index) { 
    78    
    79   /* if the index appears after (or at very end of) the window, its good */ 
    80   if (p_index >= rdb->window_start + rdb_bits_in_bitmask) 
    81     return err_status_ok; 
    82    
    83   /* if the index appears before the window, its bad */ 
    84   if (p_index < rdb->window_start) 
    85     return err_status_replay_old; 
     77    /* if the index appears after (or at very end of) the window, its good */ 
     78    if (p_index >= rdb->window_start + rdb_bits_in_bitmask) { 
     79        return srtp_err_status_ok; 
     80    } 
    8681 
    87   /* otherwise, the index appears within the window, so check the bitmask */ 
    88   if (v128_get_bit(&rdb->bitmask, (p_index - rdb->window_start)) == 1) 
    89     return err_status_replay_fail;     
    90        
    91   /* otherwise, the index is okay */ 
    92   return err_status_ok; 
     82    /* if the index appears before the window, its bad */ 
     83    if (p_index < rdb->window_start) { 
     84        return srtp_err_status_replay_old; 
     85    } 
     86 
     87    /* otherwise, the index appears within the window, so check the bitmask */ 
     88    if (v128_get_bit(&rdb->bitmask, (p_index - rdb->window_start)) == 1) { 
     89        return srtp_err_status_replay_fail; 
     90    } 
     91 
     92    /* otherwise, the index is okay */ 
     93    return srtp_err_status_ok; 
    9394} 
    9495 
    9596/* 
    96  * rdb_add_index adds index to rdb_t (and does *not* check if 
     97 * srtp_rdb_add_index adds index to srtp_rdb_t (and does *not* check if 
    9798 * index appears in db) 
    9899 * 
    99  * this function should be called only after rdb_check has 
     100 * this function should be called only after srtp_rdb_check has 
    100101 * indicated that the index does not appear in the rdb, e.g., a mutex 
    101102 * should protect the rdb between these calls 
    102103 */ 
     104srtp_err_status_t srtp_rdb_add_index (srtp_rdb_t *rdb, uint32_t p_index) 
     105{ 
     106    int delta; 
    103107 
    104 err_status_t 
    105 rdb_add_index(rdb_t *rdb, uint32_t p_index) { 
    106   int delta;   
     108    /* here we *assume* that p_index > rdb->window_start */ 
    107109 
    108   /* here we *assume* that p_index > rdb->window_start */ 
     110    delta = (p_index - rdb->window_start); 
     111    if (delta < rdb_bits_in_bitmask) { 
    109112 
    110   delta = (p_index - rdb->window_start);     
    111   if (delta < rdb_bits_in_bitmask) { 
     113        /* if the p_index is within the window, set the appropriate bit */ 
     114        v128_set_bit(&rdb->bitmask, delta); 
    112115 
    113     /* if the p_index is within the window, set the appropriate bit */ 
    114     v128_set_bit(&rdb->bitmask, delta); 
     116    } else { 
    115117 
    116   } else {  
    117      
    118     delta -= rdb_bits_in_bitmask - 1; 
     118        delta -= rdb_bits_in_bitmask - 1; 
    119119 
    120     /* shift the window forward by delta bits*/ 
    121     v128_left_shift(&rdb->bitmask, delta); 
    122     v128_set_bit(&rdb->bitmask, rdb_bits_in_bitmask-1); 
    123     rdb->window_start += delta; 
     120        /* shift the window forward by delta bits*/ 
     121        v128_left_shift(&rdb->bitmask, delta); 
     122        v128_set_bit(&rdb->bitmask, rdb_bits_in_bitmask - 1); 
     123        rdb->window_start += delta; 
    124124 
    125   }     
     125    } 
    126126 
    127   return err_status_ok; 
     127    return srtp_err_status_ok; 
    128128} 
    129129 
    130 err_status_t 
    131 rdb_increment(rdb_t *rdb) { 
     130srtp_err_status_t srtp_rdb_increment (srtp_rdb_t *rdb) 
     131{ 
    132132 
    133   if (rdb->window_start++ > 0x7fffffff) 
    134     return err_status_key_expired; 
    135   return err_status_ok; 
     133    if (rdb->window_start >= 0x7fffffff) { 
     134        return srtp_err_status_key_expired; 
     135    } 
     136    ++rdb->window_start; 
     137    return srtp_err_status_ok; 
    136138} 
    137139 
    138 uint32_t 
    139 rdb_get_value(const rdb_t *rdb) { 
    140   return rdb->window_start; 
     140uint32_t srtp_rdb_get_value (const srtp_rdb_t *rdb) 
     141{ 
     142    return rdb->window_start; 
    141143} 
Note: See TracChangeset for help on using the changeset viewer.