netwerk/srtp/src/crypto/include/cryptoalg.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  * cryptoalg.h
     3  *
     4  * API for authenticated encryption crypto algorithms
     5  * 
     6  * David A. McGrew
     7  * Cisco Systems, Inc.
     8  */
     9 /*
    10  *	
    11  * Copyright (c) 2001-2006 Cisco Systems, Inc.
    12  * All rights reserved.
    13  * 
    14  * Redistribution and use in source and binary forms, with or without
    15  * modification, are permitted provided that the following conditions
    16  * are met:
    17  * 
    18  *   Redistributions of source code must retain the above copyright
    19  *   notice, this list of conditions and the following disclaimer.
    20  * 
    21  *   Redistributions in binary form must reproduce the above
    22  *   copyright notice, this list of conditions and the following
    23  *   disclaimer in the documentation and/or other materials provided
    24  *   with the distribution.
    25  * 
    26  *   Neither the name of the Cisco Systems, Inc. nor the names of its
    27  *   contributors may be used to endorse or promote products derived
    28  *   from this software without specific prior written permission.
    29  * 
    30  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    31  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    32  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
    33  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    34  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
    35  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    36  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    37  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    40  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
    41  * OF THE POSSIBILITY OF SUCH DAMAGE.
    42  *
    43  */
    45 #ifndef CRYPTOALG_H
    46 #define CRYPTOALG_H
    48 #include "err.h"
    50 /**
    51  * @defgroup Crypto Cryptography
    52  *
    53  * Zed uses a simple interface to a cryptographic transform.
    54  *
    55  * @{
    56  */
    58 /**
    59  * @brief applies a crypto algorithm
    60  *
    61  * The function pointer cryptoalg_func_t points to a function that
    62  * implements a crypto transform, and provides a uniform API for
    63  * accessing crypto mechanisms.
    64  * 
    65  * @param key       location of secret key                  
    66  *
    67  * @param clear     data to be authenticated but not encrypted           
    68  *
    69  * @param clear_len length of data to be authenticated but not encrypted
    70  *
    71  * @param iv        location to write the Initialization Vector (IV)
    72  *
    73  * @param protect   location of the data to be encrypted and
    74  * authenticated (before the function call), and the ciphertext
    75  * and authentication tag (after the call)
    76  *
    77  * @param protected_len location of the length of the data to be
    78  * encrypted and authenticated (before the function call), and the
    79  * length of the ciphertext (after the call)
    80  *
    81  */
    83 typedef err_status_t (*cryptoalg_func_t) 
    84      (void *key,            
    85       const void *clear,          
    86       unsigned clear_len,   
    87       void *iv,             
    88       void *protect,         
    89       unsigned *protected_len);
    91 typedef 
    92 err_status_t (*cryptoalg_inv_t)
    93      (void *key,            /* location of secret key                  */
    94       const void *clear,     /* data to be authenticated only           */
    95       unsigned clear_len,   /* length of data to be authenticated only */
    96       void *iv,             /* location of iv                          */
    97       void *opaque,         /* data to be decrypted and authenticated  */
    98       unsigned *opaque_len  /* location of the length of data to be
    99 			     * decrypted and authd (before and after) 
   100 			     */
   101       );
   103 typedef struct cryptoalg_ctx_t {
   104   cryptoalg_func_t enc;
   105   cryptoalg_inv_t  dec;
   106   unsigned key_len;
   107   unsigned iv_len;
   108   unsigned auth_tag_len;
   109   unsigned max_expansion; 
   110 } cryptoalg_ctx_t;
   112 typedef cryptoalg_ctx_t *cryptoalg_t;
   114 #define cryptoalg_get_key_len(cryptoalg) ((cryptoalg)->key_len)
   116 #define cryptoalg_get_iv_len(cryptoalg) ((cryptoalg)->iv_len)
   118 #define cryptoalg_get_auth_tag_len(cryptoalg) ((cryptoalg)->auth_tag_len)
   120 int
   121 cryptoalg_get_id(cryptoalg_t c);
   123 cryptoalg_t 
   124 cryptoalg_find_by_id(int id);
   127 /**
   128  * @}
   129  */
   131 #endif /* CRYPTOALG_H */

mercurial