Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:15

0001 /* nettle-meta.h
0002 
0003    Information about algorithms.
0004 
0005    Copyright (C) 2002, 2014, 2020 Niels Möller
0006 
0007    This file is part of GNU Nettle.
0008 
0009    GNU Nettle is free software: you can redistribute it and/or
0010    modify it under the terms of either:
0011 
0012      * the GNU Lesser General Public License as published by the Free
0013        Software Foundation; either version 3 of the License, or (at your
0014        option) any later version.
0015 
0016    or
0017 
0018      * the GNU General Public License as published by the Free
0019        Software Foundation; either version 2 of the License, or (at your
0020        option) any later version.
0021 
0022    or both in parallel, as here.
0023 
0024    GNU Nettle is distributed in the hope that it will be useful,
0025    but WITHOUT ANY WARRANTY; without even the implied warranty of
0026    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0027    General Public License for more details.
0028 
0029    You should have received copies of the GNU General Public License and
0030    the GNU Lesser General Public License along with this program.  If
0031    not, see http://www.gnu.org/licenses/.
0032 */
0033 
0034 #ifndef NETTLE_META_H_INCLUDED
0035 #define NETTLE_META_H_INCLUDED
0036 
0037 #include "nettle-types.h"
0038 
0039 #ifdef __cplusplus
0040 extern "C" {
0041 #endif
0042 
0043 
0044 struct nettle_cipher
0045 {
0046   const char *name;
0047   
0048   unsigned context_size;
0049   
0050   /* Zero for stream ciphers */
0051   unsigned block_size;
0052 
0053   /* Suggested key size; other sizes are sometimes possible. */
0054   unsigned key_size;
0055 
0056   nettle_set_key_func *set_encrypt_key;
0057   nettle_set_key_func *set_decrypt_key;
0058 
0059   nettle_cipher_func *encrypt;
0060   nettle_cipher_func *decrypt;
0061 };
0062 
0063 /* null-terminated list of ciphers implemented by this version of nettle */
0064 const struct nettle_cipher * const * _NETTLE_ATTRIBUTE_PURE
0065 nettle_get_ciphers (void);
0066 
0067 #define nettle_ciphers (nettle_get_ciphers())
0068 
0069 extern const struct nettle_cipher nettle_aes128;
0070 extern const struct nettle_cipher nettle_aes192;
0071 extern const struct nettle_cipher nettle_aes256;
0072 
0073 extern const struct nettle_cipher nettle_camellia128;
0074 extern const struct nettle_cipher nettle_camellia192;
0075 extern const struct nettle_cipher nettle_camellia256;
0076 
0077 extern const struct nettle_cipher nettle_cast128;
0078 
0079 extern const struct nettle_cipher nettle_serpent128;
0080 extern const struct nettle_cipher nettle_serpent192;
0081 extern const struct nettle_cipher nettle_serpent256;
0082 
0083 extern const struct nettle_cipher nettle_twofish128;
0084 extern const struct nettle_cipher nettle_twofish192;
0085 extern const struct nettle_cipher nettle_twofish256;
0086 
0087 extern const struct nettle_cipher nettle_arctwo40;
0088 extern const struct nettle_cipher nettle_arctwo64;
0089 extern const struct nettle_cipher nettle_arctwo128;
0090 extern const struct nettle_cipher nettle_arctwo_gutmann128;
0091 
0092 extern const struct nettle_cipher nettle_sm4;
0093 
0094 struct nettle_hash
0095 {
0096   const char *name;
0097 
0098   /* Size of the context struct */
0099   unsigned context_size;
0100 
0101   /* Size of digests */
0102   unsigned digest_size;
0103   
0104   /* Internal block size */
0105   unsigned block_size;
0106 
0107   nettle_hash_init_func *init;
0108   nettle_hash_update_func *update;
0109   nettle_hash_digest_func *digest;
0110 };
0111 
0112 #define _NETTLE_HASH(name, NAME) {      \
0113  #name,                     \
0114  sizeof(struct name##_ctx),         \
0115  NAME##_DIGEST_SIZE,                \
0116  NAME##_BLOCK_SIZE,             \
0117  (nettle_hash_init_func *) name##_init,     \
0118  (nettle_hash_update_func *) name##_update, \
0119  (nettle_hash_digest_func *) name##_digest  \
0120 } 
0121 
0122 /* null-terminated list of digests implemented by this version of nettle */
0123 const struct nettle_hash * const * _NETTLE_ATTRIBUTE_PURE
0124 nettle_get_hashes (void);
0125 
0126 #define nettle_hashes (nettle_get_hashes())
0127 
0128 const struct nettle_hash *
0129 nettle_lookup_hash (const char *name);
0130 
0131 extern const struct nettle_hash nettle_md2;
0132 extern const struct nettle_hash nettle_md4;
0133 extern const struct nettle_hash nettle_md5;
0134 extern const struct nettle_hash nettle_gosthash94;
0135 extern const struct nettle_hash nettle_gosthash94cp;
0136 extern const struct nettle_hash nettle_ripemd160;
0137 extern const struct nettle_hash nettle_sha1;
0138 extern const struct nettle_hash nettle_sha224;
0139 extern const struct nettle_hash nettle_sha256;
0140 extern const struct nettle_hash nettle_sha384;
0141 extern const struct nettle_hash nettle_sha512;
0142 extern const struct nettle_hash nettle_sha512_224;
0143 extern const struct nettle_hash nettle_sha512_256;
0144 extern const struct nettle_hash nettle_sha3_224;
0145 extern const struct nettle_hash nettle_sha3_256;
0146 extern const struct nettle_hash nettle_sha3_384;
0147 extern const struct nettle_hash nettle_sha3_512;
0148 extern const struct nettle_hash nettle_streebog256;
0149 extern const struct nettle_hash nettle_streebog512;
0150 extern const struct nettle_hash nettle_sm3;
0151 
0152 struct nettle_mac
0153 {
0154   const char *name;
0155 
0156   /* Size of the context struct */
0157   unsigned context_size;
0158 
0159   /* Size of digests */
0160   unsigned digest_size;
0161 
0162   /* Key size */
0163   unsigned key_size;
0164 
0165   nettle_set_key_func *set_key;
0166   nettle_hash_update_func *update;
0167   nettle_hash_digest_func *digest;
0168 };
0169 
0170 struct nettle_aead
0171 {
0172   const char *name;
0173   
0174   unsigned context_size;
0175   /* Block size for encrypt and decrypt. */
0176   unsigned block_size;
0177   unsigned key_size;
0178   unsigned nonce_size;
0179   unsigned digest_size;
0180 
0181   nettle_set_key_func *set_encrypt_key;
0182   nettle_set_key_func *set_decrypt_key;
0183   nettle_set_key_func *set_nonce;
0184   nettle_hash_update_func *update;
0185   nettle_crypt_func *encrypt;
0186   nettle_crypt_func *decrypt;
0187   /* FIXME: Drop length argument? */
0188   nettle_hash_digest_func *digest;
0189 };
0190 
0191 /* null-terminated list of aead constructions implemented by this
0192    version of nettle */
0193 const struct nettle_aead * const * _NETTLE_ATTRIBUTE_PURE
0194 nettle_get_aeads (void);
0195 
0196 #define nettle_aeads (nettle_get_aeads())
0197 
0198 extern const struct nettle_aead nettle_gcm_aes128;
0199 extern const struct nettle_aead nettle_gcm_aes192;
0200 extern const struct nettle_aead nettle_gcm_aes256;
0201 extern const struct nettle_aead nettle_gcm_camellia128;
0202 extern const struct nettle_aead nettle_gcm_camellia256;
0203 extern const struct nettle_aead nettle_gcm_sm4;
0204 extern const struct nettle_aead nettle_eax_aes128;
0205 extern const struct nettle_aead nettle_chacha_poly1305;
0206 
0207 struct nettle_armor
0208 {
0209   const char *name;
0210   unsigned encode_context_size;
0211   unsigned decode_context_size;
0212 
0213   unsigned encode_final_length;
0214 
0215   nettle_armor_init_func *encode_init;
0216   nettle_armor_length_func *encode_length;
0217   nettle_armor_encode_update_func *encode_update;
0218   nettle_armor_encode_final_func *encode_final;
0219   
0220   nettle_armor_init_func *decode_init;
0221   nettle_armor_length_func *decode_length;
0222   nettle_armor_decode_update_func *decode_update;
0223   nettle_armor_decode_final_func *decode_final;
0224 };
0225 
0226 #define _NETTLE_ARMOR(name, NAME) {             \
0227   #name,                            \
0228   sizeof(struct name##_encode_ctx),             \
0229   sizeof(struct name##_decode_ctx),             \
0230   NAME##_ENCODE_FINAL_LENGTH,                   \
0231   (nettle_armor_init_func *) name##_encode_init,        \
0232   (nettle_armor_length_func *) name##_encode_length,        \
0233   (nettle_armor_encode_update_func *) name##_encode_update, \
0234   (nettle_armor_encode_final_func *) name##_encode_final,   \
0235   (nettle_armor_init_func *) name##_decode_init,        \
0236   (nettle_armor_length_func *) name##_decode_length,        \
0237   (nettle_armor_decode_update_func *) name##_decode_update, \
0238   (nettle_armor_decode_final_func *) name##_decode_final,   \
0239 }
0240 
0241 #define _NETTLE_ARMOR_0(name, NAME) {               \
0242   #name,                            \
0243   0,                                \
0244   sizeof(struct name##_decode_ctx),             \
0245   NAME##_ENCODE_FINAL_LENGTH,                   \
0246   (nettle_armor_init_func *) name##_encode_init,        \
0247   (nettle_armor_length_func *) name##_encode_length,        \
0248   (nettle_armor_encode_update_func *) name##_encode_update, \
0249   (nettle_armor_encode_final_func *) name##_encode_final,   \
0250   (nettle_armor_init_func *) name##_decode_init,        \
0251   (nettle_armor_length_func *) name##_decode_length,        \
0252   (nettle_armor_decode_update_func *) name##_decode_update, \
0253   (nettle_armor_decode_final_func *) name##_decode_final,   \
0254 }
0255 
0256 /* null-terminated list of armor schemes implemented by this version of nettle */
0257 const struct nettle_armor * const * _NETTLE_ATTRIBUTE_PURE
0258 nettle_get_armors (void);
0259 
0260 #define nettle_armors (nettle_get_armors())
0261 
0262 extern const struct nettle_armor nettle_base64;
0263 extern const struct nettle_armor nettle_base64url;
0264 extern const struct nettle_armor nettle_base16;
0265 
0266 #define _NETTLE_HMAC(name, HASH) {      \
0267   #name,                    \
0268   sizeof(struct name##_ctx),            \
0269   HASH##_DIGEST_SIZE,               \
0270   HASH##_DIGEST_SIZE,               \
0271   name##_set_key_wrapper,           \
0272   (nettle_hash_update_func *) name##_update,    \
0273   (nettle_hash_digest_func *) name##_digest,    \
0274 }
0275 
0276 /* null-terminated list of macs implemented by this
0277    version of nettle */
0278 const struct nettle_mac * const * _NETTLE_ATTRIBUTE_PURE
0279 nettle_get_macs (void);
0280 
0281 #define nettle_macs (nettle_get_macs())
0282 
0283 extern const struct nettle_mac nettle_cmac_aes128;
0284 extern const struct nettle_mac nettle_cmac_aes256;
0285 extern const struct nettle_mac nettle_cmac_des3;
0286 
0287 /* HMAC variants with key size = digest size */
0288 extern const struct nettle_mac nettle_hmac_md5;
0289 extern const struct nettle_mac nettle_hmac_ripemd160;
0290 extern const struct nettle_mac nettle_hmac_sha1;
0291 extern const struct nettle_mac nettle_hmac_sha224;
0292 extern const struct nettle_mac nettle_hmac_sha256;
0293 extern const struct nettle_mac nettle_hmac_sha384;
0294 extern const struct nettle_mac nettle_hmac_sha512;
0295 extern const struct nettle_mac nettle_hmac_streebog256;
0296 extern const struct nettle_mac nettle_hmac_streebog512;
0297 extern const struct nettle_mac nettle_hmac_sm3;
0298 
0299 #ifdef __cplusplus
0300 }
0301 #endif
0302 
0303 #endif /* NETTLE_META_H_INCLUDED */