mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-01-19 14:29:34 +08:00
Port OpenSSL asm code
This commit is contained in:
parent
20ab7d920d
commit
466ce76eca
112
lib/aesacc.c
112
lib/aesacc.c
@ -11,13 +11,19 @@
|
|||||||
|
|
||||||
#if defined(AES256) && (AES256 == 1)
|
#if defined(AES256) && (AES256 == 1)
|
||||||
#define AES_KEYSIZE 256
|
#define AES_KEYSIZE 256
|
||||||
#define aes_setkey_enc aesni_setkey_enc_256
|
#ifdef HAVE_AMD64
|
||||||
|
#define aes_setkey_enc aesni_setkey_enc_256
|
||||||
|
#endif
|
||||||
#elif defined(AES192) && (AES192 == 1)
|
#elif defined(AES192) && (AES192 == 1)
|
||||||
#define AES_KEYSIZE 192
|
#define AES_KEYSIZE 192
|
||||||
#define aes_setkey_enc aesni_setkey_enc_192
|
#ifdef HAVE_AMD64
|
||||||
|
#define aes_setkey_enc aesni_setkey_enc_192
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#define AES_KEYSIZE 128
|
#define AES_KEYSIZE 128
|
||||||
#define aes_setkey_enc aesni_setkey_enc_128
|
#ifdef HAVE_AMD64
|
||||||
|
#define aes_setkey_enc aesni_setkey_enc_128
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define AES_NR ((AES_KEYSIZE >> 5) + 6)
|
#define AES_NR ((AES_KEYSIZE >> 5) + 6)
|
||||||
@ -156,7 +162,87 @@ static void aes_inverse_key(uint8_t *invkey, const uint8_t *fwdkey)
|
|||||||
|
|
||||||
#endif /* HAVE_ARM64 */
|
#endif /* HAVE_ARM64 */
|
||||||
|
|
||||||
|
#ifdef HAVE_ASM
|
||||||
|
|
||||||
|
#define AES_MAXNR 14
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t rd_key[4 * (AES_MAXNR + 1)];
|
||||||
|
int rounds;
|
||||||
|
} AES_KEY;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
|
||||||
|
AES_KEY *key);
|
||||||
|
int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
|
||||||
|
AES_KEY *key);
|
||||||
|
|
||||||
|
void AES_encrypt(const unsigned char *in, unsigned char *out,
|
||||||
|
const AES_KEY *key);
|
||||||
|
void AES_decrypt(const unsigned char *in, unsigned char *out,
|
||||||
|
const AES_KEY *key);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int aes_supported(void)
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void aes_crypt_ecb( int nr,
|
||||||
|
unsigned char *rk,
|
||||||
|
int mode,
|
||||||
|
const unsigned char input[16],
|
||||||
|
unsigned char output[16] )
|
||||||
|
{
|
||||||
|
AES_KEY *ctx;
|
||||||
|
ctx = (AES_KEY *) rk;
|
||||||
|
ctx->rounds = nr;
|
||||||
|
if (mode == AES_DECRYPT) {
|
||||||
|
AES_decrypt(input, output, ctx);
|
||||||
|
} else {
|
||||||
|
AES_encrypt(input, output, ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void aes_setkey_enc(uint8_t *rk, const uint8_t *key)
|
||||||
|
{
|
||||||
|
AES_KEY *ctx;
|
||||||
|
ctx = (AES_KEY *) rk;
|
||||||
|
ctx->rounds = AES_NR;
|
||||||
|
AES_set_encrypt_key(key, AES_KEYSIZE, ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void aes_setkey_dec(uint8_t *rk, const uint8_t *key)
|
||||||
|
{
|
||||||
|
AES_KEY *ctx;
|
||||||
|
ctx = (AES_KEY *) rk;
|
||||||
|
ctx->rounds = AES_NR;
|
||||||
|
AES_set_decrypt_key(key, AES_KEYSIZE, ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_HARDAES
|
#ifdef HAVE_HARDAES
|
||||||
|
|
||||||
|
static void aes_setkey_dec(uint8_t *rk, const uint8_t *key)
|
||||||
|
{
|
||||||
|
uint8_t rk_tmp[AES_RKSIZE];
|
||||||
|
aes_setkey_enc(rk_tmp, key);
|
||||||
|
aes_inverse_key(rk, rk_tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_HARDAES) || defined(HAVE_ASM)
|
||||||
|
|
||||||
|
#define HAVE_ACC 1
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* AESNI-CBC buffer encryption/decryption
|
* AESNI-CBC buffer encryption/decryption
|
||||||
*/
|
*/
|
||||||
@ -204,11 +290,11 @@ static void aes_crypt_cbc( int mode,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* HAVE_HARDAES */
|
#endif /* HAVE_HARDAES or HAVE_ASM */
|
||||||
|
|
||||||
int AESACC_supported(void)
|
int AESACC_supported(void)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_HARDAES)
|
#if defined(HAVE_ACC)
|
||||||
return aes_supported();
|
return aes_supported();
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
@ -217,7 +303,7 @@ int AESACC_supported(void)
|
|||||||
|
|
||||||
void AESACC_CBC_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv)
|
void AESACC_CBC_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_HARDAES)
|
#if defined(HAVE_ACC)
|
||||||
uint8_t iv_tmp[16];
|
uint8_t iv_tmp[16];
|
||||||
uint8_t rk[AES_RKSIZE];
|
uint8_t rk[AES_RKSIZE];
|
||||||
|
|
||||||
@ -240,10 +326,9 @@ void AESACC_CBC_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length,
|
|||||||
|
|
||||||
void AESACC_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv)
|
void AESACC_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_HARDAES)
|
#if defined(HAVE_ACC)
|
||||||
uint8_t iv_tmp[16];
|
uint8_t iv_tmp[16];
|
||||||
uint8_t rk[AES_RKSIZE];
|
uint8_t rk[AES_RKSIZE];
|
||||||
uint8_t rk_tmp[AES_RKSIZE];
|
|
||||||
|
|
||||||
if (aes_supported())
|
if (aes_supported())
|
||||||
{
|
{
|
||||||
@ -252,8 +337,7 @@ void AESACC_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
memcpy(iv_tmp, iv, 16);
|
memcpy(iv_tmp, iv, 16);
|
||||||
aes_setkey_enc(rk_tmp, key);
|
aes_setkey_dec(rk, key);
|
||||||
aes_inverse_key(rk, rk_tmp);
|
|
||||||
aes_crypt_cbc(AES_DECRYPT, rk, \
|
aes_crypt_cbc(AES_DECRYPT, rk, \
|
||||||
length, iv_tmp, input, output);
|
length, iv_tmp, input, output);
|
||||||
return;
|
return;
|
||||||
@ -265,7 +349,7 @@ void AESACC_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length,
|
|||||||
|
|
||||||
void AESACC_ECB_encrypt(const uint8_t* input, const uint8_t* key, uint8_t* output, const uint32_t length)
|
void AESACC_ECB_encrypt(const uint8_t* input, const uint8_t* key, uint8_t* output, const uint32_t length)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_HARDAES)
|
#if defined(HAVE_ACC)
|
||||||
uint8_t rk[AES_RKSIZE];
|
uint8_t rk[AES_RKSIZE];
|
||||||
|
|
||||||
if (aes_supported())
|
if (aes_supported())
|
||||||
@ -285,9 +369,8 @@ void AESACC_ECB_encrypt(const uint8_t* input, const uint8_t* key, uint8_t* outpu
|
|||||||
|
|
||||||
void AESACC_ECB_decrypt(const uint8_t* input, const uint8_t* key, uint8_t *output, const uint32_t length)
|
void AESACC_ECB_decrypt(const uint8_t* input, const uint8_t* key, uint8_t *output, const uint32_t length)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_HARDAES)
|
#if defined(HAVE_ACC)
|
||||||
uint8_t rk[AES_RKSIZE];
|
uint8_t rk[AES_RKSIZE];
|
||||||
uint8_t rk_tmp[AES_RKSIZE];
|
|
||||||
|
|
||||||
if (aes_supported())
|
if (aes_supported())
|
||||||
{
|
{
|
||||||
@ -295,8 +378,7 @@ void AESACC_ECB_decrypt(const uint8_t* input, const uint8_t* key, uint8_t *outpu
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
aes_setkey_enc(rk_tmp, key);
|
aes_setkey_dec(rk, key);
|
||||||
aes_inverse_key(rk, rk_tmp);
|
|
||||||
aes_crypt_ecb(AES_NR, rk, AES_DECRYPT, input, output);
|
aes_crypt_ecb(AES_NR, rk, AES_DECRYPT, input, output);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,18 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
int AESACC_supported(void);
|
int AESACC_supported(void);
|
||||||
void AESACC_ECB_encrypt(const uint8_t* input, const uint8_t* key, uint8_t *output, const uint32_t length);
|
void AESACC_ECB_encrypt(const uint8_t* input, const uint8_t* key, uint8_t *output, const uint32_t length);
|
||||||
void AESACC_ECB_decrypt(const uint8_t* input, const uint8_t* key, uint8_t *output, const uint32_t length);
|
void AESACC_ECB_decrypt(const uint8_t* input, const uint8_t* key, uint8_t *output, const uint32_t length);
|
||||||
void AESACC_CBC_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv);
|
void AESACC_CBC_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv);
|
||||||
void AESACC_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv);
|
void AESACC_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _AESACC_H_ */
|
#endif /* _AESACC_H_ */
|
||||||
|
1194
lib/asm/arm.S
Normal file
1194
lib/asm/arm.S
Normal file
File diff suppressed because it is too large
Load Diff
83
lib/asm/arm_arch.h
Normal file
83
lib/asm/arm_arch.h
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||||
|
* this file except in compliance with the License. You can obtain a copy
|
||||||
|
* in the file LICENSE in the source distribution or at
|
||||||
|
* https://www.openssl.org/source/license.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ARM_ARCH_H__
|
||||||
|
# define __ARM_ARCH_H__
|
||||||
|
|
||||||
|
# if !defined(__ARM_ARCH__)
|
||||||
|
# if defined(__CC_ARM)
|
||||||
|
# define __ARM_ARCH__ __TARGET_ARCH_ARM
|
||||||
|
# if defined(__BIG_ENDIAN)
|
||||||
|
# define __ARMEB__
|
||||||
|
# else
|
||||||
|
# define __ARMEL__
|
||||||
|
# endif
|
||||||
|
# elif defined(__GNUC__)
|
||||||
|
# if defined(__aarch64__)
|
||||||
|
# define __ARM_ARCH__ 8
|
||||||
|
# if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
|
||||||
|
# define __ARMEB__
|
||||||
|
# else
|
||||||
|
# define __ARMEL__
|
||||||
|
# endif
|
||||||
|
/*
|
||||||
|
* Why doesn't gcc define __ARM_ARCH__? Instead it defines
|
||||||
|
* bunch of below macros. See all_architectires[] table in
|
||||||
|
* gcc/config/arm/arm.c. On a side note it defines
|
||||||
|
* __ARMEL__/__ARMEB__ for little-/big-endian.
|
||||||
|
*/
|
||||||
|
# elif defined(__ARM_ARCH)
|
||||||
|
# define __ARM_ARCH__ __ARM_ARCH
|
||||||
|
# elif defined(__ARM_ARCH_8A__)
|
||||||
|
# define __ARM_ARCH__ 8
|
||||||
|
# elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || \
|
||||||
|
defined(__ARM_ARCH_7R__)|| defined(__ARM_ARCH_7M__) || \
|
||||||
|
defined(__ARM_ARCH_7EM__)
|
||||||
|
# define __ARM_ARCH__ 7
|
||||||
|
# elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || \
|
||||||
|
defined(__ARM_ARCH_6K__)|| defined(__ARM_ARCH_6M__) || \
|
||||||
|
defined(__ARM_ARCH_6Z__)|| defined(__ARM_ARCH_6ZK__) || \
|
||||||
|
defined(__ARM_ARCH_6T2__)
|
||||||
|
# define __ARM_ARCH__ 6
|
||||||
|
# elif defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) || \
|
||||||
|
defined(__ARM_ARCH_5E__)|| defined(__ARM_ARCH_5TE__) || \
|
||||||
|
defined(__ARM_ARCH_5TEJ__)
|
||||||
|
# define __ARM_ARCH__ 5
|
||||||
|
# elif defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__)
|
||||||
|
# define __ARM_ARCH__ 4
|
||||||
|
# else
|
||||||
|
# error "unsupported ARM architecture"
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# if !defined(__ARM_MAX_ARCH__)
|
||||||
|
# define __ARM_MAX_ARCH__ __ARM_ARCH__
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# if __ARM_MAX_ARCH__<__ARM_ARCH__
|
||||||
|
# error "__ARM_MAX_ARCH__ can't be less than __ARM_ARCH__"
|
||||||
|
# elif __ARM_MAX_ARCH__!=__ARM_ARCH__
|
||||||
|
# if __ARM_ARCH__<7 && __ARM_MAX_ARCH__>=7 && defined(__ARMEB__)
|
||||||
|
# error "can't build universal big-endian binary"
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# if !__ASSEMBLER__
|
||||||
|
extern unsigned int OPENSSL_armcap_P;
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# define ARMV7_NEON (1<<0)
|
||||||
|
# define ARMV7_TICK (1<<1)
|
||||||
|
# define ARMV8_AES (1<<2)
|
||||||
|
# define ARMV8_SHA1 (1<<3)
|
||||||
|
# define ARMV8_SHA256 (1<<4)
|
||||||
|
# define ARMV8_PMULL (1<<5)
|
||||||
|
|
||||||
|
#endif
|
1835
lib/asm/mips.S
Normal file
1835
lib/asm/mips.S
Normal file
File diff suppressed because it is too large
Load Diff
3244
lib/asm/x86.S
Normal file
3244
lib/asm/x86.S
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user