Revert "Merge branch 'upstream' into tizen"
[platform/upstream/nettle.git] / nettle-internal.h
1 /* nettle-internal.h
2  *
3  * Things that are used only by the testsuite and benchmark, and
4  * subject to change.
5  */
6
7 /* nettle, low-level cryptographics library
8  *
9  * Copyright (C) 2002 Niels Möller
10  *  
11  * The nettle library is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation; either version 2.1 of the License, or (at your
14  * option) any later version.
15  * 
16  * The nettle library is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
19  * License for more details.
20  * 
21  * You should have received a copy of the GNU Lesser General Public License
22  * along with the nettle library; see the file COPYING.LIB.  If not, write to
23  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24  * MA 02111-1301, USA.
25  */
26
27 #ifndef NETTLE_INTERNAL_H_INCLUDED
28 #define NETTLE_INTERNAL_H_INCLUDED
29
30 #include "nettle-meta.h"
31
32 /* Temporary allocation, for systems that don't support alloca. Note
33  * that the allocation requests should always be reasonably small, so
34  * that they can fit on the stack. For non-alloca systems, we use a
35  * fix maximum size, and abort if we ever need anything larger. */
36
37 #if HAVE_ALLOCA
38 # define TMP_DECL(name, type, max) type *name
39 # define TMP_ALLOC(name, size) (name = alloca(sizeof (*name) * (size)))
40 #else /* !HAVE_ALLOCA */
41 # define TMP_DECL(name, type, max) type name[max]
42 # define TMP_ALLOC(name, size) \
43   do { if ((size) > (sizeof(name) / sizeof(name[0]))) abort(); } while (0)
44 #endif 
45
46 /* Arbitrary limits which apply to systems that don't have alloca */
47 #define NETTLE_MAX_BIGNUM_BITS 10000
48 #define NETTLE_MAX_BIGNUM_SIZE ((NETTLE_MAX_BIGNUM_BITS + 7)/8)
49 #define NETTLE_MAX_HASH_BLOCK_SIZE 128
50 #define NETTLE_MAX_HASH_DIGEST_SIZE 64
51 #define NETTLE_MAX_SEXP_ASSOC 17
52 #define NETTLE_MAX_CIPHER_BLOCK_SIZE 32
53
54 /* Doesn't quite fit with the other algorithms, because of the weak
55  * keys. Weak keys are not reported, the functions will simply crash
56  * if you try to use a weak key. */
57
58 extern const struct nettle_cipher nettle_des;
59 extern const struct nettle_cipher nettle_des3;
60
61 extern const struct nettle_cipher nettle_blowfish128;
62
63 /* For benchmarking only, sets no iv and lies about the block size. */
64 extern const struct nettle_cipher nettle_salsa20;
65 extern const struct nettle_cipher nettle_salsa20r12;
66
67 /* Glue to openssl, for comparative benchmarking. Code in
68  * examples/nettle-openssl.c. */
69 extern const struct nettle_cipher nettle_openssl_aes128;
70 extern const struct nettle_cipher nettle_openssl_aes192;
71 extern const struct nettle_cipher nettle_openssl_aes256;
72 extern const struct nettle_cipher nettle_openssl_arcfour128;
73 extern const struct nettle_cipher nettle_openssl_blowfish128;
74 extern const struct nettle_cipher nettle_openssl_des;
75 extern const struct nettle_cipher nettle_openssl_cast128;
76
77 extern const struct nettle_hash nettle_openssl_md5;
78 extern const struct nettle_hash nettle_openssl_sha1;
79
80 /* Tentative interface for "authenticated encryption with associated
81    data" algorithms. Should be moved to nettle-meta.h when stable. */
82 struct nettle_aead
83 {
84   const char *name;
85   
86   unsigned context_size;
87   /* Block size of the input, and the size of the output digest */
88   unsigned block_size;
89
90   /* Suggested key size; other sizes are sometimes possible. */
91   unsigned key_size;
92
93   nettle_set_key_func *set_key;
94   nettle_set_key_func *set_iv;
95   nettle_hash_update_func *update;
96   nettle_crypt_func *encrypt;
97   nettle_crypt_func *decrypt;
98   nettle_hash_digest_func *digest;
99 };
100
101 #define _NETTLE_AEAD(type, TYPE, name, key_size) {      \
102   #type "-" #name #key_size,                            \
103   sizeof(struct type##_##name##_ctx),                   \
104   TYPE##_BLOCK_SIZE,                                    \
105   key_size / 8,                                         \
106   (nettle_set_key_func *) type##_##name##_set_key,      \
107   (nettle_set_key_func *) type##_##name##_set_iv,       \
108   (nettle_hash_update_func *) type##_##name##_update,   \
109   (nettle_crypt_func *) type##_##name##_encrypt,        \
110   (nettle_crypt_func *) type##_##name##_decrypt,        \
111   (nettle_hash_digest_func *) type##_##name##_digest,   \
112 }
113
114 extern const struct nettle_aead nettle_gcm_aes128;
115 extern const struct nettle_aead nettle_gcm_aes192;
116 extern const struct nettle_aead nettle_gcm_aes256;
117
118 extern const struct nettle_aead nettle_gcm_camellia128;
119 extern const struct nettle_aead nettle_gcm_camellia192;
120 extern const struct nettle_aead nettle_gcm_camellia256;
121
122 extern const struct nettle_aead nettle_gcm_serpent128;
123 extern const struct nettle_aead nettle_gcm_serpent192;
124 extern const struct nettle_aead nettle_gcm_serpent256;
125
126 extern const struct nettle_aead nettle_gcm_twofish128;
127 extern const struct nettle_aead nettle_gcm_twofish192;
128 extern const struct nettle_aead nettle_gcm_twofish256;
129
130 #endif /* NETTLE_INTERNAL_H_INCLUDED */