| 
									
										
										
										
											2014-03-06 15:46:01 -08:00
										 |  |  | /* LibTomCrypt, modular cryptographic library -- Tom St Denis
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * LibTomCrypt is a library that provides various cryptographic | 
					
						
							|  |  |  |  * algorithms in a highly modular and flexible manner. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The library is free for all purposes without any express | 
					
						
							|  |  |  |  * guarantee it works. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #include "tomcrypt.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |   @file demo_crypt_constants.c | 
					
						
							| 
									
										
										
										
											2014-07-15 13:58:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Demo how to get various constants to dynamic languages | 
					
						
							| 
									
										
										
										
											2014-03-06 15:46:01 -08:00
										 |  |  |   like Python | 
					
						
							| 
									
										
										
										
											2014-07-15 13:58:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-06 15:46:01 -08:00
										 |  |  |   Larry Bugbee, February 2013 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int main(void) { | 
					
						
							|  |  |  |     // given a specific constant name, get and print its value
 | 
					
						
							|  |  |  |     char name[] = "CTR_COUNTER_BIG_ENDIAN"; | 
					
						
							|  |  |  |     int  value; | 
					
						
							| 
									
										
										
										
											2014-07-15 13:58:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (crypt_get_constant(name, &value) != 0) | 
					
						
							|  |  |  |       exit(EXIT_FAILURE); | 
					
						
							|  |  |  |     printf("\n  %s is %d \n\n", name, value); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-06 15:46:01 -08:00
										 |  |  |     // get and print the length of the names (and values) list
 | 
					
						
							|  |  |  |     char *names_list; | 
					
						
							| 
									
										
										
										
											2016-01-23 18:42:50 +01:00
										 |  |  |     unsigned int names_list_len; | 
					
						
							| 
									
										
										
										
											2014-07-15 13:58:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (crypt_list_all_constants(NULL, &names_list_len) != 0) | 
					
						
							|  |  |  |       exit(EXIT_FAILURE); | 
					
						
							| 
									
										
										
										
											2016-01-23 18:42:50 +01:00
										 |  |  |     printf("  need to allocate %u bytes \n\n", names_list_len); | 
					
						
							| 
									
										
										
										
											2014-07-15 13:58:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-06 15:46:01 -08:00
										 |  |  |     // get and print the names (and values) list
 | 
					
						
							| 
									
										
										
										
											2014-07-15 13:58:48 +02:00
										 |  |  |     if ((names_list = malloc(names_list_len)) == NULL) | 
					
						
							|  |  |  |       exit(EXIT_FAILURE); | 
					
						
							|  |  |  |     if (crypt_list_all_constants(names_list, &names_list_len) != 0) | 
					
						
							|  |  |  |       exit(EXIT_FAILURE); | 
					
						
							|  |  |  |     printf("  supported constants:\n\n%s\n\n", names_list); | 
					
						
							|  |  |  |     free(names_list); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 0; | 
					
						
							| 
									
										
										
										
											2014-03-06 15:46:01 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-15 13:58:48 +02:00
										 |  |  | /* $Source$ */ | 
					
						
							|  |  |  | /* $Revision$ */ | 
					
						
							|  |  |  | /* $Date$ */ |