mirror of
				https://github.com/wangyu-/udp2raw.git
				synced 2025-10-31 18:25:35 +08:00 
			
		
		
		
	added wrapper.c
This commit is contained in:
		| @@ -1221,6 +1221,7 @@ int aes_self_test( int verbose ) | ||||
| 
 | ||||
|         memset( buf, 0, 16 ); | ||||
| 
 | ||||
| 
 | ||||
|         if( v == AES_DECRYPT ) | ||||
|         { | ||||
|             aes_setkey_dec( &ctx, key, 128 + u * 64 ); | ||||
							
								
								
									
										65
									
								
								lib/aes_faster_c/wrapper.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								lib/aes_faster_c/wrapper.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,65 @@ | ||||
| #include "aes.h" | ||||
| #include <stdio.h> | ||||
| #include <stdlib.h> | ||||
|  | ||||
| #if defined(AES256) && (AES256 == 1) | ||||
| #define AES_KEYSIZE 256 | ||||
| #elif defined(AES192) && (AES192 == 1) | ||||
| #define AES_KEYSIZE 192 | ||||
| #else | ||||
| #define AES_KEYSIZE 128 | ||||
| #endif | ||||
|  | ||||
|  | ||||
| static aes_context ctx_de; | ||||
| static aes_context ctx_en; | ||||
| inline void init_de() | ||||
| { | ||||
| 	static int done=0; | ||||
| 	if(done==0) | ||||
| 	{ | ||||
| 		aes_init( &ctx_de ); | ||||
| 		done=1; | ||||
| 	} | ||||
| } | ||||
| inline void init_en() | ||||
| { | ||||
| 	static int done=0; | ||||
| 	if(done==0) | ||||
| 	{ | ||||
| 		aes_init( &ctx_en); | ||||
| 		done=1; | ||||
| 	} | ||||
| } | ||||
| void AES_ECB_encrypt(const uint8_t* input, const uint8_t* key, uint8_t *output, const uint32_t length) | ||||
| { | ||||
| 	init_en(); | ||||
| 	printf("AES_ECB_encrypt not implemented\n"); | ||||
| 	exit(-1); | ||||
| } | ||||
| void AES_ECB_decrypt(const uint8_t* input, const uint8_t* key, uint8_t *output, const uint32_t length) | ||||
| { | ||||
| 	init_de(); | ||||
| 	printf("AES_ECB_encrypt not implemented\n"); | ||||
| 	exit(-1); | ||||
| } | ||||
|  | ||||
| void AES_CBC_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv) | ||||
| { | ||||
| 	char tmp_iv[16]; | ||||
| 	init_en(); | ||||
| 	if(key!=0) aes_setkey_enc(&ctx_en,key,AES_KEYSIZE); | ||||
|  | ||||
| 	memcpy(tmp_iv,iv,16); | ||||
| 	aes_crypt_cbc( &ctx_en, AES_ENCRYPT, length, (unsigned char* )tmp_iv, (const unsigned char*)input,(unsigned char*) output ); | ||||
| 	return ; | ||||
| } | ||||
| void AES_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv) | ||||
| { | ||||
| 	char tmp_iv[16]; | ||||
| 	init_de(); | ||||
| 	if(key!=0) aes_setkey_dec(&ctx_de,key,AES_KEYSIZE); | ||||
| 	memcpy(tmp_iv,iv,16); | ||||
| 	aes_crypt_cbc( &ctx_de, AES_DECRYPT, length, (unsigned char*)tmp_iv, (const unsigned char*)input, (unsigned char*) output ); | ||||
| 	return; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user