mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-06 16:36:16 +08:00
Generate compiler compatible assembly symbols
Typically when compiling a function `foo`, GCC will add a prefix `_` to the symbol, i.e., generate `_foo`. But on some platforms, the compiler will not add prefix. option `ENABLE_ASM_UNDERSCORE_PREFIX` change the default name of global symbols in assembly code.
This commit is contained in:
@@ -20,9 +20,11 @@ option(ENABLE_SM4_CFB "Enable SM4 CFB mode" OFF)
|
|||||||
option(ENABLE_SM4_CBC_MAC "Enable SM4-CBC-MAC" OFF)
|
option(ENABLE_SM4_CBC_MAC "Enable SM4-CBC-MAC" OFF)
|
||||||
option(ENABLE_SM4_CCM "Enable SM4 CCM mode" OFF)
|
option(ENABLE_SM4_CCM "Enable SM4 CCM mode" OFF)
|
||||||
|
|
||||||
|
option(ENABLE_ASM_UNDERSCORE_PREFIX "Add prefix `_` to assembly symbols" ON)
|
||||||
option(ENABLE_GMUL_AARCH64 "Enable GF(2^128) Multiplication AArch64 assembly" OFF)
|
option(ENABLE_GMUL_AARCH64 "Enable GF(2^128) Multiplication AArch64 assembly" OFF)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
set(src
|
set(src
|
||||||
src/version.c
|
src/version.c
|
||||||
src/debug.c
|
src/debug.c
|
||||||
@@ -257,6 +259,10 @@ if (ENABLE_SM2_ALGOR_ID_ENCODE_NULL)
|
|||||||
add_definitions(-DENABLE_SM2_ALGOR_ID_ENCODE_NULL)
|
add_definitions(-DENABLE_SM2_ALGOR_ID_ENCODE_NULL)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (ENABLE_ASM_UNDERSCORE_PREFIX)
|
||||||
|
message(STATUS "ENABLE_ASM_UNDERSCORE_PREFIX is ON")
|
||||||
|
add_definitions(-DENABLE_ASM_UNDERSCORE_PREFIX)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (ENABLE_GMUL_AARCH64)
|
if (ENABLE_GMUL_AARCH64)
|
||||||
message(STATUS "ENABLE_GMUL_AARCH64 is ON")
|
message(STATUS "ENABLE_GMUL_AARCH64 is ON")
|
||||||
|
|||||||
20
include/gmssl/asm.h
Normal file
20
include/gmssl/asm.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014-2024 The GmSSL Project. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef GMSSL_ASM_H
|
||||||
|
#define GMSSL_ASM_H
|
||||||
|
|
||||||
|
#ifdef ENABLE_ASM_UNDERSCORE_PREFIX
|
||||||
|
# define func(foo) _##foo
|
||||||
|
#else
|
||||||
|
# define func(foo) foo
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -8,6 +8,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <gmssl/asm.h>
|
||||||
|
|
||||||
|
|
||||||
/* GF(2^128) defined by f(x) = x^128 + x^7 + x^2 + x + 1
|
/* GF(2^128) defined by f(x) = x^128 + x^7 + x^2 + x + 1
|
||||||
|
|
||||||
f0 = x^128 = x^7 + x^2 + x + 1
|
f0 = x^128 = x^7 + x^2 + x + 1
|
||||||
@@ -29,9 +32,11 @@
|
|||||||
= c + (e0 + w0) * x^64 + (d0 + w1) * f0
|
= c + (e0 + w0) * x^64 + (d0 + w1) * f0
|
||||||
*/
|
*/
|
||||||
.text
|
.text
|
||||||
.globl _gf128_mul
|
|
||||||
|
.globl func(gf128_mul)
|
||||||
.align 4
|
.align 4
|
||||||
_gf128_mul:
|
|
||||||
|
func(gf128_mul):
|
||||||
// load (a0, a1)
|
// load (a0, a1)
|
||||||
ld1 {v1.2d},[x1]
|
ld1 {v1.2d},[x1]
|
||||||
// load (b0, b1)
|
// load (b0, b1)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <gmssl/asm.h>
|
||||||
|
|
||||||
.align 7
|
.align 7
|
||||||
|
|
||||||
@@ -62,9 +63,10 @@ Llshift:
|
|||||||
.byte 4,5,6,7, 8,9,10,11, 12,13,14,15, 0,1,2,3
|
.byte 4,5,6,7, 8,9,10,11, 12,13,14,15, 0,1,2,3
|
||||||
|
|
||||||
|
|
||||||
.globl _sm4_set_encrypt_key
|
.globl func(sm4_set_encrypt_key)
|
||||||
.align 4
|
.align 4
|
||||||
_sm4_set_encrypt_key:
|
|
||||||
|
func(sm4_set_encrypt_key):
|
||||||
|
|
||||||
// load const v16..v31 = SBox
|
// load const v16..v31 = SBox
|
||||||
adr x3, LSBOX
|
adr x3, LSBOX
|
||||||
@@ -140,9 +142,10 @@ _sm4_set_encrypt_key:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
.globl _sm4_set_decrypt_key
|
.globl func(sm4_set_decrypt_key)
|
||||||
.align 4
|
.align 4
|
||||||
_sm4_set_decrypt_key:
|
|
||||||
|
func(sm4_set_decrypt_key):
|
||||||
|
|
||||||
// load const v16..v31 = SBox
|
// load const v16..v31 = SBox
|
||||||
adr x3,LSBOX
|
adr x3,LSBOX
|
||||||
@@ -221,10 +224,10 @@ _sm4_set_decrypt_key:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
.globl _sm4_encrypt
|
.globl func(sm4_encrypt)
|
||||||
|
|
||||||
.align 5
|
.align 5
|
||||||
_sm4_encrypt:
|
func(sm4_encrypt):
|
||||||
|
|
||||||
// load sbox
|
// load sbox
|
||||||
adr x3, LSBOX
|
adr x3, LSBOX
|
||||||
|
|||||||
Reference in New Issue
Block a user