src/modules/auth/nc.h
12690ddb
 /*
4ca850ad
  * Digest Authentication Module
12690ddb
  * nonce-count (nc) tracking
  *
  * Copyright (C) 2008 iptelorg GmbH
c4b6428c
  *
4ca850ad
  * This file is part of Kamailio, a free SIP server.
c4b6428c
  *
4ca850ad
  * Kamailio is free software; you can redistribute it and/or modify
12690ddb
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version
c4b6428c
  *
4ca850ad
  * Kamailio is distributed in the hope that it will be useful,
12690ddb
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
c4b6428c
  *
  * You should have received a copy of the GNU General Public License
4ca850ad
  * along with this program; if not, write to the Free Software
9e1ff448
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
4ca850ad
  *
12690ddb
  */
4ca850ad
 
12690ddb
 /*
c4b6428c
  * Defines:
12690ddb
  *  USE_NC   - if not defined no NC specific code will be compiled
  */
 
 #ifndef _nc_h
 #define _nc_h
 
 extern int nc_enabled;
 
 /* instead of storing only the 2^k size we store also k
  * for faster operations */
 extern unsigned nc_array_k;    /* array size bits (k in 2^k) */
 extern unsigned nc_array_size; /* 2^k == 1<<nc_array_bits */
 
 #ifdef USE_NC
 
 #include "nid.h" /* nid_t */
cf83221d
 #include "../../core/atomic_ops.h"
12690ddb
 
 
4593248a
 /* default number of maximum in-flight nonces */
12690ddb
 #define DEFAULT_NC_ARRAY_SIZE 1024*1024 /* uses 1Mb of memory */
 #define MIN_NC_ARRAY_SIZE        102400 /* warn if size < 100k */
 #define MAX_NC_ARRAY_SIZE 1024*1024*1024 /* warn if size > 1Gb */
 
 #define MIN_NC_ARRAY_PARTITION   65536 /* warn if a partition is < 65k */
 
 
 typedef unsigned char nc_t;
 
 int init_nonce_count();
 void destroy_nonce_count();
 
 
c4b6428c
 enum nc_check_ret{
 	NC_OK=0, NC_INV_POOL=-1, NC_ID_OVERFLOW=-2, NC_TOO_BIG=-3,
 	NC_REPLAY=-4
12690ddb
 };
 
4593248a
 /* check if nonce-count nc w/ index i is expected/valid and record its
12690ddb
  * value */
 enum nc_check_ret nc_check_val(nid_t i, unsigned pool, unsigned int nc);
 
 /* re-init the stored nc for nonce id in pool pool_no */
 nid_t nc_new(nid_t id, unsigned char pool_no);
 
 #endif /* USE_NC */
 #endif /* _nc_h */