1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/srtp/src/crypto/include/xfm.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,174 @@ 1.4 +/* 1.5 + * xfm.h 1.6 + * 1.7 + * interface for abstract crypto transform 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 +#ifndef XFM_H 1.49 +#define XFM_H 1.50 + 1.51 +#include "crypto_kernel.h" 1.52 +#include "err.h" 1.53 + 1.54 +/** 1.55 + * @defgroup Crypto Cryptography 1.56 + * 1.57 + * A simple interface to an abstract cryptographic transform that 1.58 + * provides both confidentiality and message authentication. 1.59 + * 1.60 + * @{ 1.61 + */ 1.62 + 1.63 +/** 1.64 + * @brief applies a crypto transform 1.65 + * 1.66 + * The function pointer xfm_func_t points to a function that 1.67 + * implements a crypto transform, and provides a uniform API for 1.68 + * accessing crypto mechanisms. 1.69 + * 1.70 + * @param key location of secret key 1.71 + * 1.72 + * @param clear data to be authenticated only 1.73 + * 1.74 + * @param clear_len length of data to be authenticated only 1.75 + * 1.76 + * @param iv location to write the Initialization Vector (IV) 1.77 + * 1.78 + * @param protect location of the data to be encrypted and 1.79 + * authenticated (before the function call), and the ciphertext 1.80 + * and authentication tag (after the call) 1.81 + * 1.82 + * @param protected_len location of the length of the data to be 1.83 + * encrypted and authenticated (before the function call), and the 1.84 + * length of the ciphertext (after the call) 1.85 + * 1.86 + * @param auth_tag location to write auth tag 1.87 + */ 1.88 + 1.89 +typedef err_status_t (*xfm_func_t) 1.90 + (void *key, 1.91 + void *clear, 1.92 + unsigned clear_len, 1.93 + void *iv, 1.94 + void *protect, 1.95 + unsigned *protected_len, 1.96 + void *auth_tag 1.97 + ); 1.98 + 1.99 +typedef 1.100 +err_status_t (*xfm_inv_t) 1.101 + (void *key, /* location of secret key */ 1.102 + void *clear, /* data to be authenticated only */ 1.103 + unsigned clear_len, /* length of data to be authenticated only */ 1.104 + void *iv, /* location of iv */ 1.105 + void *opaque, /* data to be decrypted and authenticated */ 1.106 + unsigned *opaque_len, /* location of the length of data to be 1.107 + * decrypted and authd (before and after) 1.108 + */ 1.109 + void *auth_tag /* location of auth tag */ 1.110 + ); 1.111 + 1.112 +typedef struct xfm_ctx_t { 1.113 + xfm_func_t func; 1.114 + xfm_inv_t inv; 1.115 + unsigned key_len; 1.116 + unsigned iv_len; 1.117 + unsigned auth_tag_len; 1.118 +} xfm_ctx_t; 1.119 + 1.120 +typedef xfm_ctx_t *xfm_t; 1.121 + 1.122 +#define xfm_get_key_len(xfm) ((xfm)->key_len) 1.123 + 1.124 +#define xfm_get_iv_len(xfm) ((xfm)->iv_len) 1.125 + 1.126 +#define xfm_get_auth_tag_len(xfm) ((xfm)->auth_tag_len) 1.127 + 1.128 + 1.129 +/* cryptoalgo - 5/28 */ 1.130 + 1.131 +typedef err_status_t (*cryptoalg_func_t) 1.132 + (void *key, 1.133 + void *clear, 1.134 + unsigned clear_len, 1.135 + void *iv, 1.136 + void *opaque, 1.137 + unsigned *opaque_len 1.138 + ); 1.139 + 1.140 +typedef 1.141 +err_status_t (*cryptoalg_inv_t) 1.142 + (void *key, /* location of secret key */ 1.143 + void *clear, /* data to be authenticated only */ 1.144 + unsigned clear_len, /* length of data to be authenticated only */ 1.145 + void *iv, /* location of iv */ 1.146 + void *opaque, /* data to be decrypted and authenticated */ 1.147 + unsigned *opaque_len /* location of the length of data to be 1.148 + * decrypted and authd (before and after) 1.149 + */ 1.150 + ); 1.151 + 1.152 +typedef struct cryptoalg_ctx_t { 1.153 + cryptoalg_func_t enc; 1.154 + cryptoalg_inv_t dec; 1.155 + unsigned key_len; 1.156 + unsigned iv_len; 1.157 + unsigned auth_tag_len; 1.158 + unsigned max_expansion; 1.159 +} cryptoalg_ctx_t; 1.160 + 1.161 +typedef cryptoalg_ctx_t *cryptoalg_t; 1.162 + 1.163 +#define cryptoalg_get_key_len(cryptoalg) ((cryptoalg)->key_len) 1.164 + 1.165 +#define cryptoalg_get_iv_len(cryptoalg) ((cryptoalg)->iv_len) 1.166 + 1.167 +#define cryptoalg_get_auth_tag_len(cryptoalg) ((cryptoalg)->auth_tag_len) 1.168 + 1.169 + 1.170 + 1.171 +/** 1.172 + * @} 1.173 + */ 1.174 + 1.175 +#endif /* XFM_H */ 1.176 + 1.177 +