From d719ee486266cac1ad3586d37b92214f0dbce057 Mon Sep 17 00:00:00 2001 From: Zhi Guan Date: Sat, 25 May 2024 18:06:16 +0800 Subject: [PATCH] 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 ``` --- include/gmssl/endian.h | 2 +- include/gmssl/file.h | 2 +- include/gmssl/oid.h | 2 +- include/gmssl/pkcs8.h | 4 ++-- include/gmssl/sm2.h | 4 ++-- include/gmssl/sm2_key_share.h | 2 +- include/gmssl/sm2_recover.h | 2 +- include/gmssl/sm2_ring.h | 2 +- include/gmssl/tls.h | 4 +--- include/gmssl/x509.h | 2 +- include/gmssl/x509_cer.h | 2 +- src/file.c | 2 +- src/http.c | 2 +- src/sm2_key.c | 2 +- src/sm2_z256.c | 7 +++---- src/sm4_ce.c | 2 +- src/sm9_key.c | 6 +++--- src/socket.c | 2 +- src/x509_crl.c | 4 ++-- 19 files changed, 26 insertions(+), 29 deletions(-) diff --git a/include/gmssl/endian.h b/include/gmssl/endian.h index 8f4345c2..6d0003b9 100644 --- a/include/gmssl/endian.h +++ b/include/gmssl/endian.h @@ -35,7 +35,7 @@ (uint64_t)(p)[7]) -// 注意:PUTU32(buf, val++) 会出错! +// WARNING: must not write PUTU32(buf, val++) #define PUTU16(p,V) \ ((p)[0] = (uint8_t)((V) >> 8), \ (p)[1] = (uint8_t)(V)) diff --git a/include/gmssl/file.h b/include/gmssl/file.h index 435c37c6..a065e05a 100644 --- a/include/gmssl/file.h +++ b/include/gmssl/file.h @@ -1,4 +1,4 @@ -/* +/* * Copyright 2014-2023 The GmSSL Project. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the License); you may diff --git a/include/gmssl/oid.h b/include/gmssl/oid.h index f7336768..ae817ef5 100644 --- a/include/gmssl/oid.h +++ b/include/gmssl/oid.h @@ -147,7 +147,7 @@ enum { OID_aes192_cbc, OID_aes256_cbc, - OID_aes128, // 没有OID + OID_aes128, // No OID OID_ecdsa_with_sha1, OID_ecdsa_with_sha224, diff --git a/include/gmssl/pkcs8.h b/include/gmssl/pkcs8.h index 9233b5c5..e4a27f10 100644 --- a/include/gmssl/pkcs8.h +++ b/include/gmssl/pkcs8.h @@ -1,4 +1,4 @@ -/* +/* * Copyright 2014-2022 The GmSSL Project. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the License); you may @@ -34,7 +34,7 @@ PBKDF2-params ::= SEQUENCE { otherSource AlgorithmIdentifier {{PBKDF2-SaltSources}} }, iterationCount INTEGER (1..MAX), - keyLength INTEGER (1..MAX) OPTIONAL, -- 这个参数可以由函数指定 + keyLength INTEGER (1..MAX) OPTIONAL, prf AlgorithmIdentifier {{PBKDF2-PRFs}} DEFAULT algid-hmacWithSHA1 } diff --git a/include/gmssl/sm2.h b/include/gmssl/sm2.h index 545722f9..82be46bc 100644 --- a/include/gmssl/sm2.h +++ b/include/gmssl/sm2.h @@ -1,4 +1,4 @@ -/* +/* * Copyright 2014-2024 The GmSSL Project. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the License); you may @@ -45,7 +45,7 @@ from RFC 5915 ECPrivateKey ::= SEQUENCE { 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, -- ONLY namedCurve OID is permitted, by RFC 5480 -- MUST always include this field, by RFC 5915 diff --git a/include/gmssl/sm2_key_share.h b/include/gmssl/sm2_key_share.h index 7288d324..574b2c4f 100644 --- a/include/gmssl/sm2_key_share.h +++ b/include/gmssl/sm2_key_share.h @@ -1,4 +1,4 @@ -/* +/* * Copyright 2014-2022 The GmSSL Project. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the License); you may diff --git a/include/gmssl/sm2_recover.h b/include/gmssl/sm2_recover.h index 92d2c01d..93315608 100644 --- a/include/gmssl/sm2_recover.h +++ b/include/gmssl/sm2_recover.h @@ -1,4 +1,4 @@ -/* +/* * Copyright 2014-2022 The GmSSL Project. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the License); you may diff --git a/include/gmssl/sm2_ring.h b/include/gmssl/sm2_ring.h index 6ce4e49c..0c3a3670 100644 --- a/include/gmssl/sm2_ring.h +++ b/include/gmssl/sm2_ring.h @@ -1,4 +1,4 @@ -/* +/* * Copyright 2014-2022 The GmSSL Project. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the License); you may diff --git a/include/gmssl/tls.h b/include/gmssl/tls.h index ced6d752..59d3864b 100644 --- a/include/gmssl/tls.h +++ b/include/gmssl/tls.h @@ -75,7 +75,7 @@ typedef enum { TLS_cipher_sm4_ccm_sm3 = 0x00c7, // 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_ecc_sm4_cbc_sm3 = 0xe013, TLS_cipher_ecc_sm4_gcm_sm3 = 0xe053, @@ -253,8 +253,6 @@ typedef enum { const char *tls_curve_type_name(int type); -// 与其支持v2,还不如直接修改v2,让v2和v3兼容 - typedef enum { TLS_curve_secp256k1 = 22, TLS_curve_secp256r1 = 23, diff --git a/include/gmssl/x509.h b/include/gmssl/x509.h index 1b57971c..e16f72f9 100644 --- a/include/gmssl/x509.h +++ b/include/gmssl/x509.h @@ -1,4 +1,4 @@ -/* +/* * Copyright 2014-2023 The GmSSL Project. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the License); you may diff --git a/include/gmssl/x509_cer.h b/include/gmssl/x509_cer.h index f8d3857f..eb29de9c 100644 --- a/include/gmssl/x509_cer.h +++ b/include/gmssl/x509_cer.h @@ -1,4 +1,4 @@ -/* +/* * Copyright 2014-2023 The GmSSL Project. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the License); you may diff --git a/src/file.c b/src/file.c index c9327a6b..149724cc 100644 --- a/src/file.c +++ b/src/file.c @@ -1,4 +1,4 @@ -/* +/* * Copyright 2014-2023 The GmSSL Project. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the License); you may diff --git a/src/http.c b/src/http.c index ce24c4f7..403cb201 100644 --- a/src/http.c +++ b/src/http.c @@ -1,4 +1,4 @@ -/* +/* * Copyright 2014-2023 The GmSSL Project. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the License); you may diff --git a/src/sm2_key.c b/src/sm2_key.c index 3fd93ab1..94ebbb3f 100644 --- a/src/sm2_key.c +++ b/src/sm2_key.c @@ -1,4 +1,4 @@ -/* +/* * Copyright 2014-2024 The GmSSL Project. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the License); you may diff --git a/src/sm2_z256.c b/src/sm2_z256.c index ce718324..e6ff43f9 100644 --- a/src/sm2_z256.c +++ b/src/sm2_z256.c @@ -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] = { 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) { @@ -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] = { 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) { @@ -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); 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(Z1sqr, in1_z); /* Z1^2 */ diff --git a/src/sm4_ce.c b/src/sm4_ce.c index ab06835b..27417e15 100644 --- a/src/sm4_ce.c +++ b/src/sm4_ce.c @@ -1,4 +1,4 @@ -/* +/* * Copyright 2014-2024 The GmSSL Project. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the License); you may diff --git a/src/sm9_key.c b/src/sm9_key.c index fdde3351..dded5514 100644 --- a/src/sm9_key.c +++ b/src/sm9_key.c @@ -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_modn_add(t, t, msk->ks); 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(); return -1; } @@ -494,7 +494,7 @@ int sm9_oid_to_der(int oid, uint8_t **out, size_t *outlen) { const ASN1_OID_INFO *info; if (oid == -1) { - // TODO: 检查其他的oid_to_der是否支持这个default == -1 的特性 + // FIXME: check if other oid_to_der support this default == -1 behavior return 0; } 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); if (sm4_cbc_padding_decrypt(&sm4_key, iv, enced_pkey_info, enced_pkey_info_len, 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 || asn1_length_is_zero(pkey_info_len) != 1) { error_print(); diff --git a/src/socket.c b/src/socket.c index 4c8fe6d7..e785a926 100644 --- a/src/socket.c +++ b/src/socket.c @@ -1,4 +1,4 @@ -/* +/* * Copyright 2014-2023 The GmSSL Project. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the License); you may diff --git a/src/x509_crl.c b/src/x509_crl.c index 8c6ab300..ec6d49ad 100644 --- a/src/x509_crl.c +++ b/src/x509_crl.c @@ -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 || 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_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(5, only_contains_attr_certs, NULL, &len) < 0 || 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 || 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_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(5, only_contains_attr_certs, out, outlen) < 0) { error_print();