netwerk/srtp/src/crypto/include/rdb.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/srtp/src/crypto/include/rdb.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,129 @@
     1.4 +/*
     1.5 + * replay-database.h
     1.6 + *
     1.7 + * interface for a replay database for packet security
     1.8 + *
     1.9 + * David A. McGrew
    1.10 + * Cisco Systems, Inc.
    1.11 + */
    1.12 +/*
    1.13 + *	
    1.14 + * Copyright (c) 2001-2006, Cisco Systems, Inc.
    1.15 + * All rights reserved.
    1.16 + * 
    1.17 + * Redistribution and use in source and binary forms, with or without
    1.18 + * modification, are permitted provided that the following conditions
    1.19 + * are met:
    1.20 + * 
    1.21 + *   Redistributions of source code must retain the above copyright
    1.22 + *   notice, this list of conditions and the following disclaimer.
    1.23 + * 
    1.24 + *   Redistributions in binary form must reproduce the above
    1.25 + *   copyright notice, this list of conditions and the following
    1.26 + *   disclaimer in the documentation and/or other materials provided
    1.27 + *   with the distribution.
    1.28 + * 
    1.29 + *   Neither the name of the Cisco Systems, Inc. nor the names of its
    1.30 + *   contributors may be used to endorse or promote products derived
    1.31 + *   from this software without specific prior written permission.
    1.32 + * 
    1.33 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.34 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.35 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
    1.36 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    1.37 + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
    1.38 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    1.39 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    1.40 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    1.41 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    1.42 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    1.43 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
    1.44 + * OF THE POSSIBILITY OF SUCH DAMAGE.
    1.45 + *
    1.46 + */
    1.47 +
    1.48 +
    1.49 +#ifndef REPLAY_DB_H
    1.50 +#define REPLAY_DB_H
    1.51 +
    1.52 +#include "integers.h"         /* for uint32_t     */
    1.53 +#include "datatypes.h"        /* for v128_t       */
    1.54 +#include "err.h"              /* for err_status_t */
    1.55 +
    1.56 +/*
    1.57 + * if the ith least significant bit is one, then the packet index
    1.58 + * window_end-i is in the database
    1.59 + */
    1.60 +
    1.61 +typedef struct {
    1.62 +  uint32_t window_start;   /* packet index of the first bit in bitmask */
    1.63 +  v128_t bitmask;  
    1.64 +} rdb_t;
    1.65 +
    1.66 +#define rdb_bits_in_bitmask (8*sizeof(v128_t))   
    1.67 +
    1.68 +/*
    1.69 + * rdb init
    1.70 + *
    1.71 + * initalizes rdb
    1.72 + *
    1.73 + * returns err_status_ok on success, err_status_t_fail otherwise
    1.74 + */
    1.75 +
    1.76 +err_status_t
    1.77 +rdb_init(rdb_t *rdb);
    1.78 +
    1.79 +
    1.80 +/*
    1.81 + * rdb_check
    1.82 + *
    1.83 + * checks to see if index appears in rdb
    1.84 + *
    1.85 + * returns err_status_fail if the index already appears in rdb,
    1.86 + * returns err_status_ok otherwise
    1.87 + */
    1.88 +
    1.89 +err_status_t
    1.90 +rdb_check(const rdb_t *rdb, uint32_t rdb_index);  
    1.91 +
    1.92 +/*
    1.93 + * rdb_add_index
    1.94 + *
    1.95 + * adds index to rdb_t (and does *not* check if index appears in db)
    1.96 + *
    1.97 + * returns err_status_ok on success, err_status_fail otherwise
    1.98 + *
    1.99 + */
   1.100 +
   1.101 +err_status_t
   1.102 +rdb_add_index(rdb_t *rdb, uint32_t rdb_index);
   1.103 +
   1.104 +/*
   1.105 + * the functions rdb_increment() and rdb_get_value() are for use by 
   1.106 + * senders, not receivers - DO NOT use these functions on the same
   1.107 + * rdb_t upon which rdb_add_index is used!
   1.108 + */
   1.109 +
   1.110 +
   1.111 +/*
   1.112 + * rdb_increment(db) increments the sequence number in db, if it is 
   1.113 + * not too high
   1.114 + *
   1.115 + * return values:
   1.116 + * 
   1.117 + *    err_status_ok            no problem
   1.118 + *    err_status_key_expired   sequence number too high
   1.119 + *
   1.120 + */
   1.121 +err_status_t
   1.122 +rdb_increment(rdb_t *rdb);
   1.123 +
   1.124 +/*
   1.125 + * rdb_get_value(db) returns the current sequence number of db
   1.126 + */
   1.127 +
   1.128 +uint32_t
   1.129 +rdb_get_value(const rdb_t *rdb);
   1.130 +
   1.131 +
   1.132 +#endif /* REPLAY_DB_H */ 

mercurial