mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-08-07 12:33:39 +08:00
Conv from UTF-8 to ASCII
`file *.c` to see file types (ASCII or UTF-8), convert UTF-8 (with BOM) to ASCII ```sh sed '1s/^\xEF\xBB\xBF//' sm4.c | iconv -f UTF-8 -t ASCII//TRANSLIT > temp.c mv temp.c sm4.c ```
This commit is contained in:
@@ -35,7 +35,7 @@
|
|||||||
(uint64_t)(p)[7])
|
(uint64_t)(p)[7])
|
||||||
|
|
||||||
|
|
||||||
// 注意:PUTU32(buf, val++) 会出错!
|
// WARNING: must not write PUTU32(buf, val++)
|
||||||
#define PUTU16(p,V) \
|
#define PUTU16(p,V) \
|
||||||
((p)[0] = (uint8_t)((V) >> 8), \
|
((p)[0] = (uint8_t)((V) >> 8), \
|
||||||
(p)[1] = (uint8_t)(V))
|
(p)[1] = (uint8_t)(V))
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
|
* Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ enum {
|
|||||||
OID_aes192_cbc,
|
OID_aes192_cbc,
|
||||||
OID_aes256_cbc,
|
OID_aes256_cbc,
|
||||||
|
|
||||||
OID_aes128, // 没有OID
|
OID_aes128, // No OID
|
||||||
|
|
||||||
OID_ecdsa_with_sha1,
|
OID_ecdsa_with_sha1,
|
||||||
OID_ecdsa_with_sha224,
|
OID_ecdsa_with_sha224,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
|
* Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
@@ -34,7 +34,7 @@ PBKDF2-params ::= SEQUENCE {
|
|||||||
otherSource AlgorithmIdentifier {{PBKDF2-SaltSources}}
|
otherSource AlgorithmIdentifier {{PBKDF2-SaltSources}}
|
||||||
},
|
},
|
||||||
iterationCount INTEGER (1..MAX),
|
iterationCount INTEGER (1..MAX),
|
||||||
keyLength INTEGER (1..MAX) OPTIONAL, -- 这个参数可以由函数指定
|
keyLength INTEGER (1..MAX) OPTIONAL,
|
||||||
prf AlgorithmIdentifier {{PBKDF2-PRFs}} DEFAULT algid-hmacWithSHA1
|
prf AlgorithmIdentifier {{PBKDF2-PRFs}} DEFAULT algid-hmacWithSHA1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2024 The GmSSL Project. All Rights Reserved.
|
* Copyright 2014-2024 The GmSSL Project. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
@@ -45,7 +45,7 @@ from RFC 5915
|
|||||||
|
|
||||||
ECPrivateKey ::= SEQUENCE {
|
ECPrivateKey ::= SEQUENCE {
|
||||||
version INTEGER, -- value MUST be (1)
|
version INTEGER, -- value MUST be (1)
|
||||||
privateKey OCTET STRING, -- big endian encoding of integer 这里不是以INTEGER编码的,因此长度固定
|
privateKey OCTET STRING, -- big endian encoding of integer, fixed length
|
||||||
parameters [0] EXPLICIT ECParameters OPTIONAL,
|
parameters [0] EXPLICIT ECParameters OPTIONAL,
|
||||||
-- ONLY namedCurve OID is permitted, by RFC 5480
|
-- ONLY namedCurve OID is permitted, by RFC 5480
|
||||||
-- MUST always include this field, by RFC 5915
|
-- MUST always include this field, by RFC 5915
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
|
* Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
|
* Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
|
* Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ typedef enum {
|
|||||||
TLS_cipher_sm4_ccm_sm3 = 0x00c7,
|
TLS_cipher_sm4_ccm_sm3 = 0x00c7,
|
||||||
|
|
||||||
// TLCP, GB/T 38636-2020, GM/T 0024-2012
|
// TLCP, GB/T 38636-2020, GM/T 0024-2012
|
||||||
TLS_cipher_ecdhe_sm4_cbc_sm3 = 0xe011, // 可以让TLSv1.2使用这个
|
TLS_cipher_ecdhe_sm4_cbc_sm3 = 0xe011, // TODO: let TLSv1.2 use this as default cipher suite
|
||||||
TLS_cipher_ecdhe_sm4_gcm_sm3 = 0xe051,
|
TLS_cipher_ecdhe_sm4_gcm_sm3 = 0xe051,
|
||||||
TLS_cipher_ecc_sm4_cbc_sm3 = 0xe013,
|
TLS_cipher_ecc_sm4_cbc_sm3 = 0xe013,
|
||||||
TLS_cipher_ecc_sm4_gcm_sm3 = 0xe053,
|
TLS_cipher_ecc_sm4_gcm_sm3 = 0xe053,
|
||||||
@@ -253,8 +253,6 @@ typedef enum {
|
|||||||
const char *tls_curve_type_name(int type);
|
const char *tls_curve_type_name(int type);
|
||||||
|
|
||||||
|
|
||||||
// 与其支持v2,还不如直接修改v2,让v2和v3兼容
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TLS_curve_secp256k1 = 22,
|
TLS_curve_secp256k1 = 22,
|
||||||
TLS_curve_secp256r1 = 23,
|
TLS_curve_secp256r1 = 23,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
|
* Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
|
* Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
|
* Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
|
* Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2024 The GmSSL Project. All Rights Reserved.
|
* Copyright 2014-2024 The GmSSL Project. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
|
|||||||
@@ -386,8 +386,7 @@ int sm2_z256_print(FILE *fp, int ind, int fmt, const char *label, const sm2_z256
|
|||||||
const uint64_t SM2_Z256_P[4] = {
|
const uint64_t SM2_Z256_P[4] = {
|
||||||
0xffffffffffffffff, 0xffffffff00000000, 0xffffffffffffffff, 0xfffffffeffffffff,
|
0xffffffffffffffff, 0xffffffff00000000, 0xffffffffffffffff, 0xfffffffeffffffff,
|
||||||
};
|
};
|
||||||
// 注意这里 SM2_Z256_P[0] 和 SM2_Z256_P[2] 是特殊值,在汇编中可以根据这个特殊值做特定的实现
|
// TODO: SM2_Z256_P[0] and SM2_Z256_P[2] are special values (fff...f), use this to optimize the ASM code
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const uint64_t *sm2_z256_prime(void) {
|
const uint64_t *sm2_z256_prime(void) {
|
||||||
@@ -969,7 +968,7 @@ void sm2_z256_modn_exp(sm2_z256_t r, const sm2_z256_t a, const sm2_z256_t e)
|
|||||||
const uint64_t SM2_Z256_N_MINUS_TWO[4] = {
|
const uint64_t SM2_Z256_N_MINUS_TWO[4] = {
|
||||||
0x53bbf40939d54121, 0x7203df6b21c6052b, 0xffffffffffffffff, 0xfffffffeffffffff,
|
0x53bbf40939d54121, 0x7203df6b21c6052b, 0xffffffffffffffff, 0xfffffffeffffffff,
|
||||||
};
|
};
|
||||||
// exp都是从高位开始的,如果都是1的话,那么就是都要平方和乘
|
// TODO: use the special form of SM2_Z256_N_MINUS_TWO[2, 3]
|
||||||
|
|
||||||
void sm2_z256_modn_mont_inv(sm2_z256_t r, const sm2_z256_t a)
|
void sm2_z256_modn_mont_inv(sm2_z256_t r, const sm2_z256_t a)
|
||||||
{
|
{
|
||||||
@@ -1266,7 +1265,7 @@ void sm2_z256_point_add(SM2_Z256_POINT *r, const SM2_Z256_POINT *a, const SM2_Z2
|
|||||||
in1infty = is_zero(in1infty);
|
in1infty = is_zero(in1infty);
|
||||||
in2infty = is_zero(in2infty);
|
in2infty = is_zero(in2infty);
|
||||||
|
|
||||||
// 这里很明显有极好的并行性
|
// TODO: can we parallel on the following code?
|
||||||
sm2_z256_modp_mont_sqr(Z2sqr, in2_z); /* Z2^2 */
|
sm2_z256_modp_mont_sqr(Z2sqr, in2_z); /* Z2^2 */
|
||||||
sm2_z256_modp_mont_sqr(Z1sqr, in1_z); /* Z1^2 */
|
sm2_z256_modp_mont_sqr(Z1sqr, in1_z); /* Z1^2 */
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2024 The GmSSL Project. All Rights Reserved.
|
* Copyright 2014-2024 The GmSSL Project. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
|
|||||||
@@ -389,7 +389,7 @@ int sm9_sign_master_key_extract_key(SM9_SIGN_MASTER_KEY *msk, const char *id, si
|
|||||||
sm9_z256_hash1(t, id, idlen, SM9_HID_SIGN);
|
sm9_z256_hash1(t, id, idlen, SM9_HID_SIGN);
|
||||||
sm9_z256_modn_add(t, t, msk->ks);
|
sm9_z256_modn_add(t, t, msk->ks);
|
||||||
if (sm9_z256_is_zero(t)) {
|
if (sm9_z256_is_zero(t)) {
|
||||||
// 这是一个严重问题,意味着整个msk都需要作废了
|
// TODO: when this happen, the admin should re-generate the MSK. Some speciall error/warning should return on this!
|
||||||
error_print();
|
error_print();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -494,7 +494,7 @@ int sm9_oid_to_der(int oid, uint8_t **out, size_t *outlen)
|
|||||||
{
|
{
|
||||||
const ASN1_OID_INFO *info;
|
const ASN1_OID_INFO *info;
|
||||||
if (oid == -1) {
|
if (oid == -1) {
|
||||||
// TODO: 检查其他的oid_to_der是否支持这个default == -1 的特性
|
// FIXME: check if other oid_to_der support this default == -1 behavior
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!(info = asn1_oid_info_from_oid(sm9_oids, sm9_oids_count, oid))) {
|
if (!(info = asn1_oid_info_from_oid(sm9_oids, sm9_oids_count, oid))) {
|
||||||
@@ -686,7 +686,7 @@ static int sm9_private_key_info_decrypt_from_der(int *alg, int *params, uint8_t
|
|||||||
sm4_set_decrypt_key(&sm4_key, key);
|
sm4_set_decrypt_key(&sm4_key, key);
|
||||||
if (sm4_cbc_padding_decrypt(&sm4_key, iv, enced_pkey_info, enced_pkey_info_len,
|
if (sm4_cbc_padding_decrypt(&sm4_key, iv, enced_pkey_info, enced_pkey_info_len,
|
||||||
pkey_info, &pkey_info_len) != 1
|
pkey_info, &pkey_info_len) != 1
|
||||||
|| sm9_private_key_info_from_der(alg, params, &cp_prikey, prikey_len, // 注意这里的是const uint8_t *,必须拷贝到外面
|
|| sm9_private_key_info_from_der(alg, params, &cp_prikey, prikey_len, // the const uint8_t *, must be copy outside
|
||||||
&cp, &pkey_info_len) != 1
|
&cp, &pkey_info_len) != 1
|
||||||
|| asn1_length_is_zero(pkey_info_len) != 1) {
|
|| asn1_length_is_zero(pkey_info_len) != 1) {
|
||||||
error_print();
|
error_print();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
|
* Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||||
|
|||||||
@@ -802,14 +802,14 @@ int x509_issuing_distribution_point_to_der(
|
|||||||
if (x509_uri_as_explicit_distribution_point_name_to_der(0, dist_point_uri, dist_point_uri_len, NULL, &len) < 0
|
if (x509_uri_as_explicit_distribution_point_name_to_der(0, dist_point_uri, dist_point_uri_len, NULL, &len) < 0
|
||||||
|| asn1_implicit_boolean_to_der(1, only_contains_user_certs, NULL, &len) < 0
|
|| asn1_implicit_boolean_to_der(1, only_contains_user_certs, NULL, &len) < 0
|
||||||
|| asn1_implicit_boolean_to_der(2, only_contains_ca_certs, NULL, &len) < 0
|
|| asn1_implicit_boolean_to_der(2, only_contains_ca_certs, NULL, &len) < 0
|
||||||
|| asn1_implicit_bits_to_der(3, only_some_reasons, NULL, &len) < 0 // TODO: 特化的类型
|
|| asn1_implicit_bits_to_der(3, only_some_reasons, NULL, &len) < 0 // TODO: create a new type, instead of use bits
|
||||||
|| asn1_implicit_boolean_to_der(4, indirect_crl, NULL, &len) < 0
|
|| asn1_implicit_boolean_to_der(4, indirect_crl, NULL, &len) < 0
|
||||||
|| asn1_implicit_boolean_to_der(5, only_contains_attr_certs, NULL, &len) < 0
|
|| asn1_implicit_boolean_to_der(5, only_contains_attr_certs, NULL, &len) < 0
|
||||||
|| asn1_sequence_header_to_der(len, out, outlen) != 1
|
|| asn1_sequence_header_to_der(len, out, outlen) != 1
|
||||||
|| x509_uri_as_explicit_distribution_point_name_to_der(0, dist_point_uri, dist_point_uri_len, out, outlen) < 0
|
|| x509_uri_as_explicit_distribution_point_name_to_der(0, dist_point_uri, dist_point_uri_len, out, outlen) < 0
|
||||||
|| asn1_implicit_boolean_to_der(1, only_contains_user_certs, out, outlen) < 0
|
|| asn1_implicit_boolean_to_der(1, only_contains_user_certs, out, outlen) < 0
|
||||||
|| asn1_implicit_boolean_to_der(2, only_contains_ca_certs, out, outlen) < 0
|
|| asn1_implicit_boolean_to_der(2, only_contains_ca_certs, out, outlen) < 0
|
||||||
|| asn1_implicit_bits_to_der(3, only_some_reasons, out, outlen) < 0 // TODO: 特化的类型
|
|| asn1_implicit_bits_to_der(3, only_some_reasons, out, outlen) < 0 // TODO: create a new type, instead of use bits
|
||||||
|| asn1_implicit_boolean_to_der(4, indirect_crl, out, outlen) < 0
|
|| asn1_implicit_boolean_to_der(4, indirect_crl, out, outlen) < 0
|
||||||
|| asn1_implicit_boolean_to_der(5, only_contains_attr_certs, out, outlen) < 0) {
|
|| asn1_implicit_boolean_to_der(5, only_contains_attr_certs, out, outlen) < 0) {
|
||||||
error_print();
|
error_print();
|
||||||
|
|||||||
Reference in New Issue
Block a user