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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2  * auth.h
     3  *
     4  * common interface to authentication functions
     5  *
     6  * David A. McGrew
     7  * Cisco Systems, Inc.
     8  */
    10 /*
    11  *	
    12  * Copyright (c) 2001-2006, Cisco Systems, Inc.
    13  * All rights reserved.
    14  * 
    15  * Redistribution and use in source and binary forms, with or without
    16  * modification, are permitted provided that the following conditions
    17  * are met:
    18  * 
    19  *   Redistributions of source code must retain the above copyright
    20  *   notice, this list of conditions and the following disclaimer.
    21  * 
    22  *   Redistributions in binary form must reproduce the above
    23  *   copyright notice, this list of conditions and the following
    24  *   disclaimer in the documentation and/or other materials provided
    25  *   with the distribution.
    26  * 
    27  *   Neither the name of the Cisco Systems, Inc. nor the names of its
    28  *   contributors may be used to endorse or promote products derived
    29  *   from this software without specific prior written permission.
    30  * 
    31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
    34  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    35  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
    36  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    37  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    38  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    40  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    41  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
    42  * OF THE POSSIBILITY OF SUCH DAMAGE.
    43  *
    44  */
    46 #ifndef AUTH_H
    47 #define AUTH_H
    49 #include "datatypes.h"          
    50 #include "err.h"                /* error codes    */
    51 #include "crypto.h"		/* for auth_type_id_t */
    52 #include "crypto_types.h"	/* for values of auth_type_id_t */
    54 typedef struct auth_type_t *auth_type_pointer;
    55 typedef struct auth_t      *auth_pointer_t;
    57 typedef err_status_t (*auth_alloc_func)
    58      (auth_pointer_t *ap, int key_len, int out_len);
    60 typedef err_status_t (*auth_init_func)
    61      (void *state, const uint8_t *key, int key_len);
    63 typedef err_status_t (*auth_dealloc_func)(auth_pointer_t ap);
    65 typedef err_status_t (*auth_compute_func)
    66      (void *state, uint8_t *buffer, int octets_to_auth, 
    67       int tag_len, uint8_t *tag);
    69 typedef err_status_t (*auth_update_func)
    70      (void *state, uint8_t *buffer, int octets_to_auth);
    72 typedef err_status_t (*auth_start_func)(void *state);
    74 /* some syntactic sugar on these function types */
    76 #define auth_type_alloc(at, a, klen, outlen)                        \
    77                  ((at)->alloc((a), (klen), (outlen)))
    79 #define auth_init(a, key)                                           \
    80                  (((a)->type)->init((a)->state, (key), ((a)->key_len)))
    82 #define auth_compute(a, buf, len, res)                              \
    83        (((a)->type)->compute((a)->state, (buf), (len), (a)->out_len, (res)))
    85 #define auth_update(a, buf, len)                                    \
    86        (((a)->type)->update((a)->state, (buf), (len)))
    88 #define auth_start(a)(((a)->type)->start((a)->state))
    90 #define auth_dealloc(c) (((c)->type)->dealloc(c))
    92 /* functions to get information about a particular auth_t */
    94 int
    95 auth_get_key_length(const struct auth_t *a);
    97 int
    98 auth_get_tag_length(const struct auth_t *a);
   100 int
   101 auth_get_prefix_length(const struct auth_t *a);
   103 /*
   104  * auth_test_case_t is a (list of) key/message/tag values that are
   105  * known to be correct for a particular cipher.  this data can be used
   106  * to test an implementation in an on-the-fly self test of the
   107  * correcness of the implementation.  (see the auth_type_self_test()
   108  * function below)
   109  */
   111 typedef struct auth_test_case_t {
   112   int key_length_octets;                    /* octets in key            */
   113   uint8_t *key;                             /* key                      */
   114   int data_length_octets;                   /* octets in data           */ 
   115   uint8_t *data;                            /* data                     */
   116   int tag_length_octets;                    /* octets in tag            */
   117   uint8_t *tag;                             /* tag                      */
   118   struct auth_test_case_t *next_test_case;  /* pointer to next testcase */
   119 } auth_test_case_t;
   121 /* auth_type_t */
   123 typedef struct auth_type_t {
   124   auth_alloc_func      alloc;
   125   auth_dealloc_func    dealloc;
   126   auth_init_func       init;
   127   auth_compute_func    compute;
   128   auth_update_func     update;
   129   auth_start_func      start;
   130   char                *description;
   131   int                  ref_count;
   132   auth_test_case_t    *test_data;
   133   debug_module_t      *debug;
   134   auth_type_id_t       id;
   135 } auth_type_t;
   137 typedef struct auth_t {
   138   auth_type_t *type;
   139   void        *state;                   
   140   int          out_len;           /* length of output tag in octets */
   141   int          key_len;           /* length of key in octets        */
   142   int          prefix_len;        /* length of keystream prefix     */
   143 } auth_t;
   145 /* 
   146  * auth_type_self_test() tests an auth_type against test cases
   147  * provided in an array of values of key/message/tag that is known to
   148  * be good
   149  */
   151 err_status_t
   152 auth_type_self_test(const auth_type_t *at);
   154 /* 
   155  * auth_type_test() tests an auth_type against external test cases
   156  * provided in an array of values of key/message/tag that is known to
   157  * be good
   158  */
   160 err_status_t
   161 auth_type_test(const auth_type_t *at, const auth_test_case_t *test_data);
   163 /*
   164  * auth_type_get_ref_count(at) returns the reference count (the number
   165  * of instantiations) of the auth_type_t at
   166  */
   168 int
   169 auth_type_get_ref_count(const auth_type_t *at);
   171 #endif /* AUTH_H */

mercurial