mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-08-06 11:53:39 +08:00
Merge branch 'master' of https://github.com/guanzhi/GmSSL
This commit is contained in:
@@ -91,21 +91,6 @@ if (NOT MSVC)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (APPLE)
|
||||
include(CheckCSourceCompiles)
|
||||
set(GMSSL_CMAKE_REQUIRED_LIBRARIES_SAVE "${CMAKE_REQUIRED_LIBRARIES}")
|
||||
set(CMAKE_REQUIRED_LIBRARIES "-framework OpenCL")
|
||||
check_c_source_compiles(
|
||||
"#include <OpenCL/OpenCL.h>
|
||||
int main(void) { cl_uint n = 0; clGetPlatformIDs(0, 0, &n); return 0; }"
|
||||
GMSSL_HAVE_MACOS_OPENCL)
|
||||
set(CMAKE_REQUIRED_LIBRARIES "${GMSSL_CMAKE_REQUIRED_LIBRARIES_SAVE}")
|
||||
if (GMSSL_HAVE_MACOS_OPENCL)
|
||||
set(GMSSL_DEFAULT_ENABLE_LMS_CL ON)
|
||||
set(GMSSL_DEFAULT_ENABLE_XMSS_CL ON)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
option(ENABLE_TEST_SPEED "Enable test speed" OFF)
|
||||
option(ENABLE_SLOW_TEST "Enable slow tests" OFF)
|
||||
|
||||
@@ -165,7 +150,11 @@ option(ENABLE_GHASH "Enable standalone GHASH command and test" ON)
|
||||
option(ENABLE_SKF "Enable SKF module" ON)
|
||||
option(ENABLE_SDF "Enable SDF module" ON)
|
||||
|
||||
if (APPLE)
|
||||
option(ENABLE_ASM_UNDERSCORE_PREFIX "Add prefix `_` to assembly symbols" ON)
|
||||
else()
|
||||
option(ENABLE_ASM_UNDERSCORE_PREFIX "Add prefix `_` to assembly symbols" OFF)
|
||||
endif()
|
||||
|
||||
option(ENABLE_TLS "Enable TLS and TLCP protocol support" ON)
|
||||
option(ENABLE_QUIC "Enable QUIC support" ON)
|
||||
|
||||
@@ -21,9 +21,9 @@ endif()
|
||||
|
||||
if(ENABLE_XMSS)
|
||||
gmssl_signature_roundtrip(tool_xmss xmsskeygen xmsssign xmssverify
|
||||
KEYGEN_ARGS -xmss_type XMSS_SHA2_10_256)
|
||||
KEYGEN_ARGS -xmss_type XMSS_SM3_10_256)
|
||||
gmssl_signature_roundtrip(tool_xmssmt xmssmtkeygen xmssmtsign xmssmtverify
|
||||
KEYGEN_ARGS -xmssmt_type XMSSMT_SHA2_20_2_256)
|
||||
KEYGEN_ARGS -xmssmt_type XMSSMT_SM3_20_2_256)
|
||||
endif()
|
||||
|
||||
if(ENABLE_SPHINCS)
|
||||
|
||||
@@ -1526,6 +1526,8 @@ int secp256r1_ecdsa_signature_from_der(SECP256R1_ECDSA_SIGNATURE *sig, const uin
|
||||
const uint8_t *d;
|
||||
const uint8_t *r;
|
||||
const uint8_t *s;
|
||||
uint8_t rbuf[32] = {0};
|
||||
uint8_t sbuf[32] = {0};
|
||||
size_t dlen, rlen, slen;
|
||||
|
||||
if ((ret = asn1_sequence_from_der(&d, &dlen, in, inlen)) != 1) {
|
||||
@@ -1541,8 +1543,10 @@ int secp256r1_ecdsa_signature_from_der(SECP256R1_ECDSA_SIGNATURE *sig, const uin
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (secp256r1_from_32bytes(sig->r, r) != 1
|
||||
|| secp256r1_from_32bytes(sig->s, s) != 1) {
|
||||
memcpy(rbuf + sizeof(rbuf) - rlen, r, rlen);
|
||||
memcpy(sbuf + sizeof(sbuf) - slen, s, slen);
|
||||
if (secp256r1_from_32bytes(sig->r, rbuf) != 1
|
||||
|| secp256r1_from_32bytes(sig->s, sbuf) != 1) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ void sm3_compress_blocks(uint32_t digest[8], const uint8_t *data, size_t blocks)
|
||||
|
||||
for (j = 0; j < 16; j += 4) {
|
||||
words = vld1q_u32((uint32_t *)data + j);
|
||||
words = vrev32q_u8(words);
|
||||
words = (uint32x4_t)vrev32q_u8((uint8x16_t)words);
|
||||
vst1q_u32(W + j, words);
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ void sm4_encrypt(const SM4_KEY *key, const unsigned char in[16], unsigned char o
|
||||
uint8x16x4_t S1 = vld1q_u8_x4(S + 64);
|
||||
uint8x16x4_t S2 = vld1q_u8_x4(S + 128);
|
||||
uint8x16x4_t S3 = vld1q_u8_x4(S + 192);
|
||||
uint8x16_t vx;
|
||||
uint32x4_t vx;
|
||||
uint8x16_t vt;
|
||||
uint32_t X0, X1, X2, X3, X4;
|
||||
int i;
|
||||
@@ -156,10 +156,10 @@ void sm4_encrypt(const SM4_KEY *key, const unsigned char in[16], unsigned char o
|
||||
|
||||
// const time X4 = S32(X4)
|
||||
vx = vdupq_n_u32(X4);
|
||||
vt = vqtbl4q_u8(S0, vx);
|
||||
vt = vqtbx4q_u8(vt, S1, veorq_u8(vx, vdupq_n_u8(0x40)));
|
||||
vt = vqtbx4q_u8(vt, S2, veorq_u8(vx, vdupq_n_u8(0x80)));
|
||||
vx = vqtbx4q_u8(vt, S3, veorq_u8(vx, vdupq_n_u8(0xc0)));
|
||||
vt = vqtbl4q_u8(S0, (uint8x16_t)vx);
|
||||
vt = vqtbx4q_u8(vt, S1, veorq_u8((uint8x16_t)vx, vdupq_n_u8(0x40)));
|
||||
vt = vqtbx4q_u8(vt, S2, veorq_u8((uint8x16_t)vx, vdupq_n_u8(0x80)));
|
||||
vx = (uint32x4_t)vqtbx4q_u8(vt, S3, veorq_u8((uint8x16_t)vx, vdupq_n_u8(0xc0)));
|
||||
X4 = vgetq_lane_u32(vx, 0);
|
||||
|
||||
X4 = X0 ^ L32(X4);
|
||||
@@ -278,7 +278,7 @@ void sm4_ctr32_encrypt_4blocks(const SM4_KEY *key, uint8_t iv[16], const uint8_t
|
||||
|
||||
memcpy(buf, iv, 16);
|
||||
ctr = vld1q_u32(buf);
|
||||
ctr = vrev32q_u8(ctr);
|
||||
ctr = (uint32x4_t)vrev32q_u8((uint8x16_t)ctr);
|
||||
|
||||
ctr0 = vdupq_n_u32(vgetq_lane_u32(ctr, 0));
|
||||
ctr1 = vdupq_n_u32(vgetq_lane_u32(ctr, 1));
|
||||
@@ -301,10 +301,10 @@ void sm4_ctr32_encrypt_4blocks(const SM4_KEY *key, uint8_t iv[16], const uint8_t
|
||||
x4 = veorq_u32(veorq_u32(x1, x2), veorq_u32(x3, rk));
|
||||
|
||||
// X4 = SBOX(X4)
|
||||
xt = vqtbl4q_u8(S0, x4);
|
||||
xt = vqtbx4q_u8(xt, S1, veorq_u8(x4, vdupq_n_u8(0x40)));
|
||||
xt = vqtbx4q_u8(xt, S2, veorq_u8(x4, vdupq_n_u8(0x80)));
|
||||
x4 = vqtbx4q_u8(xt, S3, veorq_u8(x4, vdupq_n_u8(0xc0)));
|
||||
xt = (uint32x4_t)vqtbl4q_u8(S0, (uint8x16_t)x4);
|
||||
xt = (uint32x4_t)vqtbx4q_u8((uint8x16_t)xt, S1, veorq_u8((uint8x16_t)x4, vdupq_n_u8(0x40)));
|
||||
xt = (uint32x4_t)vqtbx4q_u8((uint8x16_t)xt, S2, veorq_u8((uint8x16_t)x4, vdupq_n_u8(0x80)));
|
||||
x4 = (uint32x4_t)vqtbx4q_u8((uint8x16_t)xt, S3, veorq_u8((uint8x16_t)x4, vdupq_n_u8(0xc0)));
|
||||
|
||||
// X4 = L(X4)
|
||||
xt = veorq_u32(x4, vrolq_n_u32(x4, 2));
|
||||
@@ -326,16 +326,16 @@ void sm4_ctr32_encrypt_4blocks(const SM4_KEY *key, uint8_t iv[16], const uint8_t
|
||||
x01 = vzipq_u32(x02.val[0], x13.val[0]);
|
||||
x23 = vzipq_u32(x02.val[1], x13.val[1]);
|
||||
|
||||
x0 = vrev32q_u8(x01.val[0]);
|
||||
x0 = (uint32x4_t)vrev32q_u8((uint8x16_t)x01.val[0]);
|
||||
vst1q_u32(buf, x0);
|
||||
|
||||
x1 = vrev32q_u8(x01.val[1]);
|
||||
x1 = (uint32x4_t)vrev32q_u8((uint8x16_t)x01.val[1]);
|
||||
vst1q_u32(buf + 4, x1);
|
||||
|
||||
x2 = vrev32q_u8(x23.val[0]);
|
||||
x2 = (uint32x4_t)vrev32q_u8((uint8x16_t)x23.val[0]);
|
||||
vst1q_u32(buf + 8, x2);
|
||||
|
||||
x3 = vrev32q_u8(x23.val[1]);
|
||||
x3 = (uint32x4_t)vrev32q_u8((uint8x16_t)x23.val[1]);
|
||||
vst1q_u32(buf + 12, x3);
|
||||
|
||||
// xor with plaintext
|
||||
|
||||
@@ -5874,9 +5874,9 @@ int tls13_recv_certificate_request(TLS_CONNECT *conn)
|
||||
int signed_certificate_timestamp = 0;
|
||||
|
||||
int common_sig_algs[4];
|
||||
size_t common_sig_algs_cnt;
|
||||
size_t common_sig_algs_cnt = 0;
|
||||
int common_sig_algs_cert[4];
|
||||
size_t common_sig_algs_cert_cnt;
|
||||
size_t common_sig_algs_cert_cnt = 0;
|
||||
const uint8_t *ca_names = NULL;
|
||||
size_t ca_names_len = 0;
|
||||
const uint8_t *filters = NULL;
|
||||
|
||||
@@ -75,6 +75,8 @@ static int test_secp384r1(void)
|
||||
{
|
||||
secp384r1_t a;
|
||||
secp384r1_t b;
|
||||
secp384r1_t p;
|
||||
secp384r1_t n;
|
||||
uint8_t buf[48];
|
||||
|
||||
if (secp384r1_set_zero(a) != 1 || !secp384r1_is_zero(a)) {
|
||||
@@ -101,9 +103,12 @@ static int test_secp384r1(void)
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
if (secp384r1_check_hex(SECP384R1_P, secp384r1_p) != 1
|
||||
|| secp384r1_check_hex(SECP384R1_B, secp384r1_b) != 1
|
||||
|| secp384r1_check_hex(SECP384R1_N, secp384r1_n) != 1) {
|
||||
if (secp384r1_from_hex(p, secp384r1_p) != 1
|
||||
|| secp384r1_from_hex(b, secp384r1_b) != 1
|
||||
|| secp384r1_from_hex(n, secp384r1_n) != 1
|
||||
|| secp384r1_check_hex(p, secp384r1_p) != 1
|
||||
|| secp384r1_check_hex(b, secp384r1_b) != 1
|
||||
|| secp384r1_check_hex(n, secp384r1_n) != 1) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
@@ -232,6 +237,7 @@ static int test_secp384r1_point(void)
|
||||
SECP384R1_POINT Q;
|
||||
SECP384R1_POINT R;
|
||||
secp384r1_t k;
|
||||
secp384r1_t n;
|
||||
uint8_t octets[97];
|
||||
|
||||
if (secp384r1_point_set_xy(&P, SECP384R1_POINT_G.X, SECP384R1_POINT_G.Y) != 1
|
||||
@@ -261,7 +267,8 @@ static int test_secp384r1_point(void)
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
if (secp384r1_point_mul_generator(&R, SECP384R1_N) != 1
|
||||
if (secp384r1_from_hex(n, secp384r1_n) != 1
|
||||
|| secp384r1_point_mul_generator(&R, n) != 1
|
||||
|| !secp384r1_point_is_at_infinity(&R)) {
|
||||
error_print();
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user