Codebase list libcryptx-perl / 009c518
removing unused crypt_constants.c crypt_sizes.c Karel Miko 8 years ago
2 changed file(s) with 0 addition(s) and 542 deletion(s). Raw diff Collapse all Expand all
+0
-231
src/ltc/misc/crypt/crypt_constants.c less more
0 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
1 *
2 * LibTomCrypt is a library that provides various cryptographic
3 * algorithms in a highly modular and flexible manner.
4 *
5 * The library is free for all purposes without any express
6 * guarantee it works.
7 *
8 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
9 */
10 #include "tomcrypt.h"
11
12 /**
13 @file crypt_constants.c
14
15 Make various constants available to dynamic languages
16 like Python - Larry Bugbee, February 2013
17
18 LB - Dec 2013 - revised to include compiler define options
19 LB - Mar 2014 - added endianness and word size
20 */
21
22 typedef struct {
23 const char *name;
24 const int value;
25 } crypt_constant;
26
27 #define _C_STRINGIFY(s) { #s, s }
28
29 static const crypt_constant _crypt_constants[] = {
30 _C_STRINGIFY(PK_PUBLIC),
31 _C_STRINGIFY(PK_PRIVATE),
32
33 _C_STRINGIFY(PKA_RSA),
34 _C_STRINGIFY(PKA_DSA),
35
36 #ifdef LTC_PKCS_1
37 {"LTC_PKCS_1", 1},
38 /* Block types */
39 _C_STRINGIFY(LTC_PKCS_1_EMSA),
40 _C_STRINGIFY(LTC_PKCS_1_EME),
41
42 /* Padding types */
43 _C_STRINGIFY(LTC_PKCS_1_V1_5),
44 _C_STRINGIFY(LTC_PKCS_1_OAEP),
45 _C_STRINGIFY(LTC_PKCS_1_PSS),
46 #else
47 {"LTC_PKCS_1", 0},
48 #endif
49
50 #ifdef LTC_MRSA
51 {"LTC_MRSA", 1},
52 _C_STRINGIFY(MIN_RSA_SIZE),
53 _C_STRINGIFY(MAX_RSA_SIZE),
54 #else
55 {"LTC_MRSA", 0},
56 #endif
57
58 #ifdef LTC_MKAT
59 {"LTC_MKAT", 1},
60 _C_STRINGIFY(MIN_KAT_SIZE),
61 _C_STRINGIFY(MAX_KAT_SIZE),
62 #else
63 {"LTC_MKAT", 0},
64 #endif
65
66 #ifdef LTC_MECC
67 {"LTC_MECC", 1},
68 _C_STRINGIFY(ECC_BUF_SIZE),
69 _C_STRINGIFY(ECC_MAXSIZE),
70 #else
71 {"LTC_MECC", 0},
72 #endif
73
74 #ifdef LTC_MDSA
75 {"LTC_MDSA", 1},
76 _C_STRINGIFY(LTC_MDSA_DELTA),
77 _C_STRINGIFY(LTC_MDSA_MAX_GROUP),
78 #else
79 {"LTC_MDSA", 0},
80 #endif
81
82 #ifdef LTC_CTR_MODE
83 {"LTC_CTR_MODE", 1},
84 _C_STRINGIFY(CTR_COUNTER_LITTLE_ENDIAN),
85 _C_STRINGIFY(CTR_COUNTER_BIG_ENDIAN),
86 _C_STRINGIFY(LTC_CTR_RFC3686),
87 #else
88 {"LTC_CTR_MODE", 0},
89 #endif
90
91 _C_STRINGIFY(MAXBLOCKSIZE),
92 _C_STRINGIFY(TAB_SIZE),
93 _C_STRINGIFY(ARGTYPE),
94
95 #ifdef LTM_DESC
96 {"LTM_DESC", 1},
97 #else
98 {"LTM_DESC", 0},
99 #endif
100 #ifdef TFM_DESC
101 {"TFM_DESC", 1},
102 #else
103 {"TFM_DESC", 0},
104 #endif
105 #ifdef GMP_DESC
106 {"GMP_DESC", 1},
107 #else
108 {"GMP_DESC", 0},
109 #endif
110
111 #ifdef LTC_FAST
112 {"LTC_FAST", 1},
113 #else
114 {"LTC_FAST", 0},
115 #endif
116
117 #ifdef LTC_NO_FILE
118 {"LTC_NO_FILE", 1},
119 #else
120 {"LTC_NO_FILE", 0},
121 #endif
122
123 #ifdef ENDIAN_LITTLE
124 {"ENDIAN_LITTLE", 1},
125 #else
126 {"ENDIAN_LITTLE", 0},
127 #endif
128
129 #ifdef ENDIAN_BIG
130 {"ENDIAN_BIG", 1},
131 #else
132 {"ENDIAN_BIG", 0},
133 #endif
134
135 #ifdef ENDIAN_32BITWORD
136 {"ENDIAN_32BITWORD", 1},
137 #else
138 {"ENDIAN_32BITWORD", 0},
139 #endif
140
141 #ifdef ENDIAN_64BITWORD
142 {"ENDIAN_64BITWORD", 1},
143 #else
144 {"ENDIAN_64BITWORD", 0},
145 #endif
146
147 #ifdef ENDIAN_NEUTRAL
148 {"ENDIAN_NEUTRAL", 1},
149 #else
150 {"ENDIAN_NEUTRAL", 0},
151 #endif
152 };
153
154
155 /* crypt_get_constant()
156 * valueout will be the value of the named constant
157 * return -1 if named item not found
158 */
159 int crypt_get_constant(const char* namein, int *valueout) {
160 int i;
161 int _crypt_constants_len = sizeof(_crypt_constants) / sizeof(_crypt_constants[0]);
162 for (i=0; i<_crypt_constants_len; i++) {
163 if (strcmp(_crypt_constants[i].name, namein) == 0) {
164 *valueout = _crypt_constants[i].value;
165 return 0;
166 }
167 }
168 return 1;
169 }
170
171 /* crypt_list_all_constants()
172 * if names_list is NULL, names_list_size will be the minimum
173 * number of bytes needed to receive the complete names_list
174 * if names_list is NOT NULL, names_list must be the addr of
175 * sufficient memory allocated into which the names_list
176 * is to be written. Also, the value in names_list_size
177 * sets the upper bound of the number of characters to be
178 * written.
179 * a -1 return value signifies insufficient space made available
180 */
181 int crypt_list_all_constants(char *names_list, unsigned int *names_list_size) {
182 int i;
183 unsigned int total_len = 0;
184 char number[32];
185 int number_len;
186 int count = sizeof(_crypt_constants) / sizeof(_crypt_constants[0]);
187
188 /* calculate amount of memory required for the list */
189 for (i=0; i<count; i++) {
190 total_len += strlen(_crypt_constants[i].name) + 1;
191 /* the above +1 is for the commas */
192 number_len = snprintf(number, sizeof(number), "%d", _crypt_constants[i].value);
193 if ((number_len < 0) ||
194 ((unsigned int)number_len >= sizeof(number)))
195 return -1;
196 total_len += number_len + 1;
197 /* this last +1 is for newlines (and ending NULL) */
198 }
199
200 if (names_list == NULL) {
201 *names_list_size = total_len;
202 } else {
203 if (total_len > *names_list_size) {
204 return -1;
205 }
206 /* build the names list */
207 char *ptr = names_list;
208 for (i=0; i<count; i++) {
209 strcpy(ptr, _crypt_constants[i].name);
210 ptr += strlen(_crypt_constants[i].name);
211 strcpy(ptr, ",");
212 ptr += 1;
213
214 number_len = snprintf(number, sizeof(number), "%d", _crypt_constants[i].value);
215 strcpy(ptr, number);
216 ptr += number_len;
217 strcpy(ptr, "\n");
218 ptr += 1;
219 }
220 /* to remove the trailing new-line */
221 ptr -= 1;
222 *ptr = 0;
223 }
224 return 0;
225 }
226
227
228 /* $Source$ */
229 /* $Revision$ */
230 /* $Date$ */
+0
-311
src/ltc/misc/crypt/crypt_sizes.c less more
0 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
1 *
2 * LibTomCrypt is a library that provides various cryptographic
3 * algorithms in a highly modular and flexible manner.
4 *
5 * The library is free for all purposes without any express
6 * guarantee it works.
7 *
8 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
9 */
10 #include "tomcrypt.h"
11
12 /**
13 @file crypt_sizes.c
14
15 Make various struct sizes available to dynamic languages
16 like Python - Larry Bugbee, February 2013
17
18 LB - Dec 2013 - revised to include compiler define options
19 */
20
21
22 typedef struct {
23 const char *name;
24 const unsigned int size;
25 } crypt_size;
26
27 #define _SZ_STRINGIFY_S(s) { #s, sizeof(struct s) }
28 #define _SZ_STRINGIFY_T(s) { #s, sizeof(s) }
29
30 static const crypt_size _crypt_sizes[] = {
31 // hash state sizes
32 _SZ_STRINGIFY_S(ltc_hash_descriptor),
33 _SZ_STRINGIFY_T(hash_state),
34 #ifdef LTC_SHA256
35 _SZ_STRINGIFY_S(sha256_state),
36 #endif
37 #ifdef LTC_SHA512
38 _SZ_STRINGIFY_S(sha512_state),
39 #endif
40 #ifdef LTC_WHIRLPOOL
41 _SZ_STRINGIFY_S(whirlpool_state),
42 #endif
43 #ifdef LTC_MD2
44 _SZ_STRINGIFY_S(md2_state),
45 #endif
46 #ifdef LTC_MD4
47 _SZ_STRINGIFY_S(md4_state),
48 #endif
49 #ifdef LTC_MD5
50 _SZ_STRINGIFY_S(md5_state),
51 #endif
52 #ifdef LTC_RIPEMD128
53 _SZ_STRINGIFY_S(rmd128_state),
54 #endif
55 #ifdef LTC_RIPEMD160
56 _SZ_STRINGIFY_S(rmd160_state),
57 #endif
58 #ifdef LTC_RIPEMD256
59 _SZ_STRINGIFY_S(rmd256_state),
60 #endif
61 #ifdef LTC_RIPEMD320
62 _SZ_STRINGIFY_S(rmd320_state),
63 #endif
64 #ifdef LTC_SHA1
65 _SZ_STRINGIFY_S(sha1_state),
66 #endif
67 #ifdef LTC_TIGER
68 _SZ_STRINGIFY_S(tiger_state),
69 #endif
70 #ifdef LTC_CHC_HASH
71 _SZ_STRINGIFY_S(chc_state),
72 #endif
73
74 // block cipher key sizes
75 _SZ_STRINGIFY_S(ltc_cipher_descriptor),
76 _SZ_STRINGIFY_T(symmetric_key),
77 #ifdef LTC_ANUBIS
78 _SZ_STRINGIFY_S(anubis_key),
79 #endif
80 #ifdef LTC_CAMELLIA
81 _SZ_STRINGIFY_S(camellia_key),
82 #endif
83 #ifdef LTC_BLOWFISH
84 _SZ_STRINGIFY_S(blowfish_key),
85 #endif
86 #ifdef LTC_CAST5
87 _SZ_STRINGIFY_S(cast5_key),
88 #endif
89 #ifdef LTC_DES
90 _SZ_STRINGIFY_S(des_key),
91 _SZ_STRINGIFY_S(des3_key),
92 #endif
93 #ifdef LTC_KASUMI
94 _SZ_STRINGIFY_S(kasumi_key),
95 #endif
96 #ifdef LTC_KHAZAD
97 _SZ_STRINGIFY_S(khazad_key),
98 #endif
99 #ifdef LTC_KSEED
100 _SZ_STRINGIFY_S(kseed_key),
101 #endif
102 #ifdef LTC_MULTI2
103 _SZ_STRINGIFY_S(multi2_key),
104 #endif
105 #ifdef LTC_NOEKEON
106 _SZ_STRINGIFY_S(noekeon_key),
107 #endif
108 #ifdef LTC_RC2
109 _SZ_STRINGIFY_S(rc2_key),
110 #endif
111 #ifdef LTC_RC5
112 _SZ_STRINGIFY_S(rc5_key),
113 #endif
114 #ifdef LTC_RC6
115 _SZ_STRINGIFY_S(rc6_key),
116 #endif
117 #ifdef LTC_SKIPJACK
118 _SZ_STRINGIFY_S(skipjack_key),
119 #endif
120 #ifdef LTC_XTEA
121 _SZ_STRINGIFY_S(xtea_key),
122 #endif
123 #ifdef LTC_RIJNDAEL
124 _SZ_STRINGIFY_S(rijndael_key),
125 #endif
126 #ifdef LTC_SAFER
127 _SZ_STRINGIFY_S(safer_key),
128 #endif
129 #ifdef LTC_SAFERP
130 _SZ_STRINGIFY_S(saferp_key),
131 #endif
132 #ifdef LTC_TWOFISH
133 _SZ_STRINGIFY_S(twofish_key),
134 #endif
135
136 // mode sizes
137 #ifdef LTC_CBC_MODE
138 _SZ_STRINGIFY_T(symmetric_CBC),
139 #endif
140 #ifdef LTC_CFB_MODE
141 _SZ_STRINGIFY_T(symmetric_CFB),
142 #endif
143 #ifdef LTC_CTR_MODE
144 _SZ_STRINGIFY_T(symmetric_CTR),
145 #endif
146 #ifdef LTC_ECB_MODE
147 _SZ_STRINGIFY_T(symmetric_ECB),
148 #endif
149 #ifdef LTC_F8_MODE
150 _SZ_STRINGIFY_T(symmetric_F8),
151 #endif
152 #ifdef LTC_LRW_MODE
153 _SZ_STRINGIFY_T(symmetric_LRW),
154 #endif
155 #ifdef LTC_OFB_MODE
156 _SZ_STRINGIFY_T(symmetric_OFB),
157 #endif
158
159 // MAC sizes -- no states for ccm, lrw
160 #ifdef LTC_F9_MODE
161 _SZ_STRINGIFY_T(f9_state),
162 #endif
163 #ifdef LTC_HMAC
164 _SZ_STRINGIFY_T(hmac_state),
165 #endif
166 #ifdef LTC_OMAC
167 _SZ_STRINGIFY_T(omac_state),
168 #endif
169 #ifdef LTC_PELICAN
170 _SZ_STRINGIFY_T(pelican_state),
171 #endif
172 #ifdef LTC_PMAC
173 _SZ_STRINGIFY_T(pmac_state),
174 #endif
175 #ifdef LTC_XCBC
176 _SZ_STRINGIFY_T(xcbc_state),
177 #endif
178 #ifdef LTC_OCB_MODE
179 _SZ_STRINGIFY_T(ocb_state),
180 #endif
181 #ifdef LTC_OCB3_MODE
182 _SZ_STRINGIFY_T(ocb3_state),
183 #endif
184 #ifdef LTC_GCM_MODE
185 _SZ_STRINGIFY_T(gcm_state),
186 #endif
187 #ifdef LTC_EAX_MODE
188 _SZ_STRINGIFY_T(eax_state),
189 #endif
190 #ifdef LTC_CCM_MODE
191 // not defined
192 #endif
193 #ifdef LRW_MODE
194 // not defined
195 #endif
196
197 // asymmetric keys
198 #ifdef LTC_MRSA
199 _SZ_STRINGIFY_T(rsa_key),
200 #endif
201 #ifdef LTC_MDSA
202 _SZ_STRINGIFY_T(dsa_key),
203 #endif
204 #ifdef LTC_MDH
205 _SZ_STRINGIFY_T(dh_key),
206 #endif
207 #ifdef LTC_MECC
208 _SZ_STRINGIFY_T(ltc_ecc_set_type),
209 _SZ_STRINGIFY_T(ecc_key),
210 _SZ_STRINGIFY_T(ecc_point),
211 #endif
212 #ifdef LTC_MKAT
213 _SZ_STRINGIFY_T(katja_key),
214 #endif
215
216 // prng state sizes
217 _SZ_STRINGIFY_S(ltc_prng_descriptor),
218 _SZ_STRINGIFY_T(prng_state),
219 #ifdef LTC_FORTUNA
220 _SZ_STRINGIFY_S(fortuna_prng),
221 #endif
222 #ifdef LTC_RC4
223 _SZ_STRINGIFY_S(rc4_prng),
224 #endif
225 #ifdef LTC_SOBER128
226 _SZ_STRINGIFY_S(sober128_prng),
227 #endif
228 #ifdef LTC_YARROW
229 _SZ_STRINGIFY_S(yarrow_prng),
230 #endif
231 // sprng has no state as it uses other potentially available sources
232 // like /dev/random. See Developers Guide for more info.
233 };
234
235 /* crypt_get_size()
236 * sizeout will be the size (bytes) of the named struct or union
237 * return -1 if named item not found
238 */
239 int crypt_get_size(const char* namein, unsigned int *sizeout) {
240 int i;
241 int count = sizeof(_crypt_sizes) / sizeof(_crypt_sizes[0]);
242 for (i=0; i<count; i++) {
243 if (strcmp(_crypt_sizes[i].name, namein) == 0) {
244 *sizeout = _crypt_sizes[i].size;
245 return 0;
246 }
247 }
248 return -1;
249 }
250
251 /* crypt_list_all_sizes()
252 * if names_list is NULL, names_list_size will be the minimum
253 * size needed to receive the complete names_list
254 * if names_list is NOT NULL, names_list must be the addr with
255 * sufficient memory allocated into which the names_list
256 * is to be written. Also, the value in names_list_size
257 * sets the upper bound of the number of characters to be
258 * written.
259 * a -1 return value signifies insufficient space made available
260 */
261 int crypt_list_all_sizes(char *names_list, unsigned int *names_list_size) {
262 int i;
263 unsigned int total_len = 0;
264 char number[32];
265 int number_len;
266 int count = sizeof(_crypt_sizes) / sizeof(_crypt_sizes[0]);
267
268 /* calculate amount of memory required for the list */
269 for (i=0; i<count; i++) {
270 total_len += strlen(_crypt_sizes[i].name) + 1;
271 /* the above +1 is for the commas */
272 number_len = snprintf(number, sizeof(number), "%u", _crypt_sizes[i].size);
273 if ((number_len < 0) ||
274 ((unsigned int)number_len >= sizeof(number)))
275 return -1;
276 total_len += strlen(number) + 1;
277 /* this last +1 is for newlines (and ending NULL) */
278 }
279
280 if (names_list == NULL) {
281 *names_list_size = total_len;
282 } else {
283 if (total_len > *names_list_size) {
284 return -1;
285 }
286 /* build the names list */
287 char *ptr = names_list;
288 for (i=0; i<count; i++) {
289 strcpy(ptr, _crypt_sizes[i].name);
290 ptr += strlen(_crypt_sizes[i].name);
291 strcpy(ptr, ",");
292 ptr += 1;
293
294 number_len = snprintf(number, sizeof(number), "%u", _crypt_sizes[i].size);
295 strcpy(ptr, number);
296 ptr += number_len;
297 strcpy(ptr, "\n");
298 ptr += 1;
299 }
300 /* to remove the trailing new-line */
301 ptr -= 1;
302 *ptr = 0;
303 }
304 return 0;
305 }
306
307
308 /* $Source$ */
309 /* $Revision$ */
310 /* $Date$ */