| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * xfm.h | |
| 3 * | |
| 4 * interface for abstract crypto transform | |
| 5 * | |
| 6 * David A. McGrew | |
| 7 * Cisco Systems, Inc. | |
| 8 */ | |
| 9 | |
| 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 */ | |
| 45 | |
| 46 #ifndef XFM_H | |
| 47 #define XFM_H | |
| 48 | |
| 49 #include "crypto_kernel.h" | |
| 50 #include "err.h" | |
| 51 | |
| 52 /** | |
| 53 * @defgroup Crypto Cryptography | |
| 54 * | |
| 55 * A simple interface to an abstract cryptographic transform that | |
| 56 * provides both confidentiality and message authentication. | |
| 57 * | |
| 58 * @{ | |
| 59 */ | |
| 60 | |
| 61 /** | |
| 62 * @brief applies a crypto transform | |
| 63 * | |
| 64 * The function pointer xfm_func_t points to a function that | |
| 65 * implements a crypto transform, and provides a uniform API for | |
| 66 * accessing crypto mechanisms. | |
| 67 * | |
| 68 * @param key location of secret key | |
| 69 * | |
| 70 * @param clear data to be authenticated only | |
| 71 * | |
| 72 * @param clear_len length of data to be authenticated only | |
| 73 * | |
| 74 * @param iv location to write the Initialization Vector (IV) | |
| 75 * | |
| 76 * @param protect location of the data to be encrypted and | |
| 77 * authenticated (before the function call), and the ciphertext | |
| 78 * and authentication tag (after the call) | |
| 79 * | |
| 80 * @param protected_len location of the length of the data to be | |
| 81 * encrypted and authenticated (before the function call), and the | |
| 82 * length of the ciphertext (after the call) | |
| 83 * | |
| 84 * @param auth_tag location to write auth tag | |
| 85 */ | |
| 86 | |
| 87 typedef err_status_t (*xfm_func_t) | |
| 88 (void *key, | |
| 89 void *clear, | |
| 90 unsigned clear_len, | |
| 91 void *iv, | |
| 92 void *protect, | |
| 93 unsigned *protected_len, | |
| 94 void *auth_tag | |
| 95 ); | |
| 96 | |
| 97 typedef | |
| 98 err_status_t (*xfm_inv_t) | |
| 99 (void *key, /* location of secret key */ | |
| 100 void *clear, /* data to be authenticated only */ | |
| 101 unsigned clear_len, /* length of data to be authenticated only */ | |
| 102 void *iv, /* location of iv */ | |
| 103 void *opaque, /* data to be decrypted and authenticated */ | |
| 104 unsigned *opaque_len, /* location of the length of data to be | |
| 105 * decrypted and authd (before and after) | |
| 106 */ | |
| 107 void *auth_tag /* location of auth tag */ | |
| 108 ); | |
| 109 | |
| 110 typedef struct xfm_ctx_t { | |
| 111 xfm_func_t func; | |
| 112 xfm_inv_t inv; | |
| 113 unsigned key_len; | |
| 114 unsigned iv_len; | |
| 115 unsigned auth_tag_len; | |
| 116 } xfm_ctx_t; | |
| 117 | |
| 118 typedef xfm_ctx_t *xfm_t; | |
| 119 | |
| 120 #define xfm_get_key_len(xfm) ((xfm)->key_len) | |
| 121 | |
| 122 #define xfm_get_iv_len(xfm) ((xfm)->iv_len) | |
| 123 | |
| 124 #define xfm_get_auth_tag_len(xfm) ((xfm)->auth_tag_len) | |
| 125 | |
| 126 | |
| 127 /* cryptoalgo - 5/28 */ | |
| 128 | |
| 129 typedef err_status_t (*cryptoalg_func_t) | |
| 130 (void *key, | |
| 131 void *clear, | |
| 132 unsigned clear_len, | |
| 133 void *iv, | |
| 134 void *opaque, | |
| 135 unsigned *opaque_len | |
| 136 ); | |
| 137 | |
| 138 typedef | |
| 139 err_status_t (*cryptoalg_inv_t) | |
| 140 (void *key, /* location of secret key */ | |
| 141 void *clear, /* data to be authenticated only */ | |
| 142 unsigned clear_len, /* length of data to be authenticated only */ | |
| 143 void *iv, /* location of iv */ | |
| 144 void *opaque, /* data to be decrypted and authenticated */ | |
| 145 unsigned *opaque_len /* location of the length of data to be | |
| 146 * decrypted and authd (before and after) | |
| 147 */ | |
| 148 ); | |
| 149 | |
| 150 typedef struct cryptoalg_ctx_t { | |
| 151 cryptoalg_func_t enc; | |
| 152 cryptoalg_inv_t dec; | |
| 153 unsigned key_len; | |
| 154 unsigned iv_len; | |
| 155 unsigned auth_tag_len; | |
| 156 unsigned max_expansion; | |
| 157 } cryptoalg_ctx_t; | |
| 158 | |
| 159 typedef cryptoalg_ctx_t *cryptoalg_t; | |
| 160 | |
| 161 #define cryptoalg_get_key_len(cryptoalg) ((cryptoalg)->key_len) | |
| 162 | |
| 163 #define cryptoalg_get_iv_len(cryptoalg) ((cryptoalg)->iv_len) | |
| 164 | |
| 165 #define cryptoalg_get_auth_tag_len(cryptoalg) ((cryptoalg)->auth_tag_len) | |
| 166 | |
| 167 | |
| 168 | |
| 169 /** | |
| 170 * @} | |
| 171 */ | |
| 172 | |
| 173 #endif /* XFM_H */ | |
| 174 | |
| 175 | |
| OLD | NEW |