Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * xfm.h |
michael@0 | 3 | * |
michael@0 | 4 | * interface for abstract crypto transform |
michael@0 | 5 | * |
michael@0 | 6 | * David A. McGrew |
michael@0 | 7 | * Cisco Systems, Inc. |
michael@0 | 8 | */ |
michael@0 | 9 | /* |
michael@0 | 10 | * |
michael@0 | 11 | * Copyright (c) 2001-2006, Cisco Systems, Inc. |
michael@0 | 12 | * All rights reserved. |
michael@0 | 13 | * |
michael@0 | 14 | * Redistribution and use in source and binary forms, with or without |
michael@0 | 15 | * modification, are permitted provided that the following conditions |
michael@0 | 16 | * are met: |
michael@0 | 17 | * |
michael@0 | 18 | * Redistributions of source code must retain the above copyright |
michael@0 | 19 | * notice, this list of conditions and the following disclaimer. |
michael@0 | 20 | * |
michael@0 | 21 | * Redistributions in binary form must reproduce the above |
michael@0 | 22 | * copyright notice, this list of conditions and the following |
michael@0 | 23 | * disclaimer in the documentation and/or other materials provided |
michael@0 | 24 | * with the distribution. |
michael@0 | 25 | * |
michael@0 | 26 | * Neither the name of the Cisco Systems, Inc. nor the names of its |
michael@0 | 27 | * contributors may be used to endorse or promote products derived |
michael@0 | 28 | * from this software without specific prior written permission. |
michael@0 | 29 | * |
michael@0 | 30 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 31 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
michael@0 | 32 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
michael@0 | 33 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
michael@0 | 34 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
michael@0 | 35 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
michael@0 | 36 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
michael@0 | 37 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
michael@0 | 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
michael@0 | 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
michael@0 | 40 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
michael@0 | 41 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 42 | * |
michael@0 | 43 | */ |
michael@0 | 44 | |
michael@0 | 45 | #ifndef XFM_H |
michael@0 | 46 | #define XFM_H |
michael@0 | 47 | |
michael@0 | 48 | #include "crypto_kernel.h" |
michael@0 | 49 | #include "err.h" |
michael@0 | 50 | |
michael@0 | 51 | /** |
michael@0 | 52 | * @defgroup Crypto Cryptography |
michael@0 | 53 | * |
michael@0 | 54 | * A simple interface to an abstract cryptographic transform that |
michael@0 | 55 | * provides both confidentiality and message authentication. |
michael@0 | 56 | * |
michael@0 | 57 | * @{ |
michael@0 | 58 | */ |
michael@0 | 59 | |
michael@0 | 60 | /** |
michael@0 | 61 | * @brief applies a crypto transform |
michael@0 | 62 | * |
michael@0 | 63 | * The function pointer xfm_func_t points to a function that |
michael@0 | 64 | * implements a crypto transform, and provides a uniform API for |
michael@0 | 65 | * accessing crypto mechanisms. |
michael@0 | 66 | * |
michael@0 | 67 | * @param key location of secret key |
michael@0 | 68 | * |
michael@0 | 69 | * @param clear data to be authenticated only |
michael@0 | 70 | * |
michael@0 | 71 | * @param clear_len length of data to be authenticated only |
michael@0 | 72 | * |
michael@0 | 73 | * @param iv location to write the Initialization Vector (IV) |
michael@0 | 74 | * |
michael@0 | 75 | * @param protect location of the data to be encrypted and |
michael@0 | 76 | * authenticated (before the function call), and the ciphertext |
michael@0 | 77 | * and authentication tag (after the call) |
michael@0 | 78 | * |
michael@0 | 79 | * @param protected_len location of the length of the data to be |
michael@0 | 80 | * encrypted and authenticated (before the function call), and the |
michael@0 | 81 | * length of the ciphertext (after the call) |
michael@0 | 82 | * |
michael@0 | 83 | * @param auth_tag location to write auth tag |
michael@0 | 84 | */ |
michael@0 | 85 | |
michael@0 | 86 | typedef err_status_t (*xfm_func_t) |
michael@0 | 87 | (void *key, |
michael@0 | 88 | void *clear, |
michael@0 | 89 | unsigned clear_len, |
michael@0 | 90 | void *iv, |
michael@0 | 91 | void *protect, |
michael@0 | 92 | unsigned *protected_len, |
michael@0 | 93 | void *auth_tag |
michael@0 | 94 | ); |
michael@0 | 95 | |
michael@0 | 96 | typedef |
michael@0 | 97 | err_status_t (*xfm_inv_t) |
michael@0 | 98 | (void *key, /* location of secret key */ |
michael@0 | 99 | void *clear, /* data to be authenticated only */ |
michael@0 | 100 | unsigned clear_len, /* length of data to be authenticated only */ |
michael@0 | 101 | void *iv, /* location of iv */ |
michael@0 | 102 | void *opaque, /* data to be decrypted and authenticated */ |
michael@0 | 103 | unsigned *opaque_len, /* location of the length of data to be |
michael@0 | 104 | * decrypted and authd (before and after) |
michael@0 | 105 | */ |
michael@0 | 106 | void *auth_tag /* location of auth tag */ |
michael@0 | 107 | ); |
michael@0 | 108 | |
michael@0 | 109 | typedef struct xfm_ctx_t { |
michael@0 | 110 | xfm_func_t func; |
michael@0 | 111 | xfm_inv_t inv; |
michael@0 | 112 | unsigned key_len; |
michael@0 | 113 | unsigned iv_len; |
michael@0 | 114 | unsigned auth_tag_len; |
michael@0 | 115 | } xfm_ctx_t; |
michael@0 | 116 | |
michael@0 | 117 | typedef xfm_ctx_t *xfm_t; |
michael@0 | 118 | |
michael@0 | 119 | #define xfm_get_key_len(xfm) ((xfm)->key_len) |
michael@0 | 120 | |
michael@0 | 121 | #define xfm_get_iv_len(xfm) ((xfm)->iv_len) |
michael@0 | 122 | |
michael@0 | 123 | #define xfm_get_auth_tag_len(xfm) ((xfm)->auth_tag_len) |
michael@0 | 124 | |
michael@0 | 125 | |
michael@0 | 126 | /* cryptoalgo - 5/28 */ |
michael@0 | 127 | |
michael@0 | 128 | typedef err_status_t (*cryptoalg_func_t) |
michael@0 | 129 | (void *key, |
michael@0 | 130 | void *clear, |
michael@0 | 131 | unsigned clear_len, |
michael@0 | 132 | void *iv, |
michael@0 | 133 | void *opaque, |
michael@0 | 134 | unsigned *opaque_len |
michael@0 | 135 | ); |
michael@0 | 136 | |
michael@0 | 137 | typedef |
michael@0 | 138 | err_status_t (*cryptoalg_inv_t) |
michael@0 | 139 | (void *key, /* location of secret key */ |
michael@0 | 140 | void *clear, /* data to be authenticated only */ |
michael@0 | 141 | unsigned clear_len, /* length of data to be authenticated only */ |
michael@0 | 142 | void *iv, /* location of iv */ |
michael@0 | 143 | void *opaque, /* data to be decrypted and authenticated */ |
michael@0 | 144 | unsigned *opaque_len /* location of the length of data to be |
michael@0 | 145 | * decrypted and authd (before and after) |
michael@0 | 146 | */ |
michael@0 | 147 | ); |
michael@0 | 148 | |
michael@0 | 149 | typedef struct cryptoalg_ctx_t { |
michael@0 | 150 | cryptoalg_func_t enc; |
michael@0 | 151 | cryptoalg_inv_t dec; |
michael@0 | 152 | unsigned key_len; |
michael@0 | 153 | unsigned iv_len; |
michael@0 | 154 | unsigned auth_tag_len; |
michael@0 | 155 | unsigned max_expansion; |
michael@0 | 156 | } cryptoalg_ctx_t; |
michael@0 | 157 | |
michael@0 | 158 | typedef cryptoalg_ctx_t *cryptoalg_t; |
michael@0 | 159 | |
michael@0 | 160 | #define cryptoalg_get_key_len(cryptoalg) ((cryptoalg)->key_len) |
michael@0 | 161 | |
michael@0 | 162 | #define cryptoalg_get_iv_len(cryptoalg) ((cryptoalg)->iv_len) |
michael@0 | 163 | |
michael@0 | 164 | #define cryptoalg_get_auth_tag_len(cryptoalg) ((cryptoalg)->auth_tag_len) |
michael@0 | 165 | |
michael@0 | 166 | |
michael@0 | 167 | |
michael@0 | 168 | /** |
michael@0 | 169 | * @} |
michael@0 | 170 | */ |
michael@0 | 171 | |
michael@0 | 172 | #endif /* XFM_H */ |
michael@0 | 173 | |
michael@0 | 174 |