mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-06 16:36:16 +08:00
Fix MSVC warnings
This commit is contained in:
@@ -458,11 +458,15 @@ int tls_record_set_data(uint8_t *record, const uint8_t *data, size_t datalen);
|
||||
int tls_record_print(FILE *fp, const uint8_t *record, size_t recordlen, int format, int indent);
|
||||
int tlcp_record_print(FILE *fp, const uint8_t *record, size_t recordlen, int format, int indent);
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
int tls_record_send(const uint8_t* record, size_t recordlen, SOCKET sock);
|
||||
int tls_record_recv(uint8_t* record, size_t* recordlen, SOCKET sock);
|
||||
int tls12_record_recv(uint8_t* record, size_t* recordlen, SOCKET sock);
|
||||
#else
|
||||
int tls_record_send(const uint8_t *record, size_t recordlen, int sock);
|
||||
int tls_record_recv(uint8_t *record, size_t *recordlen, int sock);
|
||||
int tls12_record_recv(uint8_t *record, size_t *recordlen, int sock);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Handshake
|
||||
|
||||
11
src/cms.c
11
src/cms.c
@@ -389,7 +389,6 @@ int cms_enced_content_info_decrypt_from_der(
|
||||
const uint8_t **shared_info2, size_t *shared_info2_len,// 支持可选null输出
|
||||
const uint8_t **in, size_t *inlen)
|
||||
{
|
||||
int ret;
|
||||
SM4_KEY sm4_key;
|
||||
const uint8_t *iv;
|
||||
size_t ivlen;
|
||||
@@ -1055,7 +1054,6 @@ int cms_signed_data_sign_to_der(
|
||||
size_t digest_algors_cnt = sizeof(digest_algors)/sizeof(int);
|
||||
uint8_t content_header[256];
|
||||
size_t content_header_len;
|
||||
const uint8_t *certs;
|
||||
size_t certs_len = 0;
|
||||
uint8_t signer_infos[512];
|
||||
size_t signer_infos_len = 0;
|
||||
@@ -1334,7 +1332,6 @@ int cms_recipient_info_decrypt_from_der(
|
||||
uint8_t *out, size_t *outlen, size_t maxlen,
|
||||
const uint8_t **in, size_t *inlen)
|
||||
{
|
||||
int ret;
|
||||
int version;
|
||||
int pke_algor;
|
||||
const uint8_t *params;
|
||||
@@ -1485,7 +1482,7 @@ int cms_enveloped_data_from_der(
|
||||
|
||||
int cms_enveloped_data_print(FILE *fp, int fmt, int ind, const char *label, const uint8_t *d, size_t dlen)
|
||||
{
|
||||
int ret, val;
|
||||
int val;
|
||||
const uint8_t *p;
|
||||
size_t len;
|
||||
|
||||
@@ -1579,7 +1576,7 @@ int cms_enveloped_data_decrypt_from_der(
|
||||
const uint8_t **shared_info2, size_t *shared_info2_len,
|
||||
const uint8_t **in, size_t *inlen)
|
||||
{
|
||||
int ret;
|
||||
int ret = 0;
|
||||
int version;
|
||||
const uint8_t *rcpt_infos;
|
||||
size_t rcpt_infos_len;
|
||||
@@ -1594,7 +1591,7 @@ int cms_enveloped_data_decrypt_from_der(
|
||||
&enced_content_info, &enced_content_info_len,
|
||||
in, inlen) != 1
|
||||
|| asn1_check(version == CMS_version_v1) != 1) {
|
||||
return ret;
|
||||
return -1;
|
||||
}
|
||||
*recipient_infos = rcpt_infos;
|
||||
*recipient_infos_len = rcpt_infos_len;
|
||||
@@ -2370,8 +2367,6 @@ int cms_deenvelop_and_verify(const uint8_t *cms, size_t cmslen,
|
||||
int cms_type;
|
||||
const uint8_t *cms_content;
|
||||
size_t cms_content_len;
|
||||
int digest_algors[4];
|
||||
size_t digest_algors_cnt;
|
||||
|
||||
if (cms_content_info_from_der(&cms_type, &cms_content, &cms_content_len, &cms, &cmslen) != 1
|
||||
|| asn1_check(cms_type == OID_cms_signed_and_enveloped_data) != 1
|
||||
|
||||
@@ -125,7 +125,7 @@ int sdf_rand_bytes(SDF_DEVICE *dev, uint8_t *buf, size_t len)
|
||||
return -1;
|
||||
}
|
||||
if (SDF_OpenSession(dev->handle, &hSession) != SDR_OK
|
||||
|| SDF_GenerateRandom(hSession, len, buf) != SDR_OK) {
|
||||
|| SDF_GenerateRandom(hSession, (unsigned int)len, buf) != SDR_OK) {
|
||||
error_print();
|
||||
goto end;
|
||||
}
|
||||
@@ -149,7 +149,7 @@ int sdf_load_sign_key(SDF_DEVICE *dev, SDF_KEY *key, int index, const char *pass
|
||||
if (SDF_OpenSession(dev->handle, &hSession) != SDR_OK
|
||||
|| SDF_ExportSignPublicKey_ECC(hSession, index, &eccPublicKey) != SDR_OK
|
||||
|| SDF_ECCrefPublicKey_to_SM2_KEY(&eccPublicKey, &public_key) != SDR_OK
|
||||
|| SDF_GetPrivateKeyAccessRight(hSession, index, (unsigned char *)pass, strlen(pass)) != SDR_OK) {
|
||||
|| SDF_GetPrivateKeyAccessRight(hSession, index, (unsigned char *)pass, (unsigned int)strlen(pass)) != SDR_OK) {
|
||||
error_print();
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -210,8 +210,9 @@ int sm9_bn_equ(const sm9_bn_t a, const sm9_bn_t b)
|
||||
void sm9_fp_add(sm9_fp_t r, const sm9_fp_t a, const sm9_fp_t b)
|
||||
{
|
||||
sm9_bn_add(r, a, b);
|
||||
if (sm9_bn_cmp(r, SM9_P) >= 0)
|
||||
return sm9_bn_sub(r, r, SM9_P);
|
||||
if (sm9_bn_cmp(r, SM9_P) >= 0) {
|
||||
sm9_bn_sub(r, r, SM9_P);
|
||||
}
|
||||
}
|
||||
|
||||
void sm9_fp_sub(sm9_fp_t r, const sm9_fp_t a, const sm9_fp_t b)
|
||||
@@ -1204,7 +1205,7 @@ void sm9_fp2_conjugate(sm9_fp2_t r, const sm9_fp2_t a)
|
||||
|
||||
void sm9_fp2_frobenius(sm9_fp2_t r, const sm9_fp2_t a)
|
||||
{
|
||||
return sm9_fp2_conjugate(r, a);
|
||||
sm9_fp2_conjugate(r, a);
|
||||
}
|
||||
|
||||
// beta = 0x6c648de5dc0a3f2cf55acc93ee0baf159f9d411806dc5177f5b21fd3da24d011
|
||||
@@ -1236,7 +1237,7 @@ void sm9_fp4_conjugate(sm9_fp4_t r, const sm9_fp4_t a)
|
||||
|
||||
void sm9_fp4_frobenius2(sm9_fp4_t r, const sm9_fp4_t a)
|
||||
{
|
||||
return sm9_fp4_conjugate(r, a);
|
||||
sm9_fp4_conjugate(r, a);
|
||||
}
|
||||
|
||||
void sm9_fp4_frobenius3(sm9_fp4_t r, const sm9_fp4_t a)
|
||||
@@ -1777,10 +1778,12 @@ void sm9_twist_point_add_full(SM9_TWIST_POINT *R, const SM9_TWIST_POINT *P, cons
|
||||
sm9_fp2_sub(T1, T1, T2);
|
||||
|
||||
if (sm9_fp2_is_zero(T1) && sm9_fp2_is_zero(T3)) {
|
||||
return sm9_twist_point_dbl(R, P);
|
||||
sm9_twist_point_dbl(R, P);
|
||||
return;
|
||||
}
|
||||
if (sm9_fp2_is_zero(T1) && sm9_fp2_is_zero(T6)) {
|
||||
return sm9_twist_point_set_infinity(R);
|
||||
sm9_twist_point_set_infinity(R);
|
||||
return;
|
||||
}
|
||||
|
||||
sm9_fp2_sqr(T6, T1);
|
||||
@@ -2069,8 +2072,9 @@ void sm9_pairing(sm9_fp12_t r, const SM9_TWIST_POINT *Q, const SM9_POINT *P) {
|
||||
void sm9_fn_add(sm9_fn_t r, const sm9_fn_t a, const sm9_fn_t b)
|
||||
{
|
||||
sm9_bn_add(r, a, b);
|
||||
if (sm9_bn_cmp(r, SM9_N) >= 0)
|
||||
return sm9_bn_sub(r, r, SM9_N);
|
||||
if (sm9_bn_cmp(r, SM9_N) >= 0) {
|
||||
sm9_bn_sub(r, r, SM9_N);
|
||||
}
|
||||
}
|
||||
|
||||
void sm9_fn_sub(sm9_fn_t r, const sm9_fn_t a, const sm9_fn_t b)
|
||||
|
||||
45
src/tls.c
45
src/tls.c
@@ -263,7 +263,7 @@ int tls_record_set_length(uint8_t *record, size_t length)
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
tls_uint16_to_bytes(length, &p, &len);
|
||||
tls_uint16_to_bytes((uint16_t)length, &p, &len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -381,8 +381,8 @@ int tls_cbc_decrypt(const SM3_HMAC_CTX *inited_hmac_ctx, const SM4_KEY *dec_key,
|
||||
header[0] = enced_header[0];
|
||||
header[1] = enced_header[1];
|
||||
header[2] = enced_header[2];
|
||||
header[3] = (*outlen) >> 8;
|
||||
header[4] = (*outlen);
|
||||
header[3] = (uint8_t)((*outlen) >> 8);
|
||||
header[4] = (uint8_t)(*outlen);
|
||||
mac = padding - 32;
|
||||
|
||||
memcpy(&hmac_ctx, inited_hmac_ctx, sizeof(SM3_HMAC_CTX));
|
||||
@@ -411,8 +411,8 @@ int tls_record_encrypt(const SM3_HMAC_CTX *hmac_ctx, const SM4_KEY *cbc_key,
|
||||
out[0] = in[0];
|
||||
out[1] = in[1];
|
||||
out[2] = in[2];
|
||||
out[3] = (*outlen) >> 8;
|
||||
out[4] = (*outlen);
|
||||
out[3] = (uint8_t)((*outlen) >> 8);
|
||||
out[4] = (uint8_t)(*outlen);
|
||||
(*outlen) += 5;
|
||||
return 1;
|
||||
}
|
||||
@@ -431,8 +431,8 @@ int tls_record_decrypt(const SM3_HMAC_CTX *hmac_ctx, const SM4_KEY *cbc_key,
|
||||
out[0] = in[0];
|
||||
out[1] = in[1];
|
||||
out[2] = in[2];
|
||||
out[3] = (*outlen) >> 8;
|
||||
out[4] = (*outlen);
|
||||
out[3] = (uint8_t)((*outlen) >> 8);
|
||||
out[4] = (uint8_t)(*outlen);
|
||||
(*outlen) += 5;
|
||||
|
||||
return 1;
|
||||
@@ -627,12 +627,12 @@ int tls_record_set_handshake(uint8_t *record, size_t *recordlen,
|
||||
}
|
||||
handshakelen = TLS_HANDSHAKE_HEADER_SIZE + datalen;
|
||||
record[0] = TLS_record_handshake;
|
||||
record[3] = handshakelen >> 8;
|
||||
record[4] = handshakelen;
|
||||
record[5] = type;
|
||||
record[6] = datalen >> 16;
|
||||
record[7] = datalen >> 8;
|
||||
record[8] = datalen;
|
||||
record[3] = (uint8_t)(handshakelen >> 8);
|
||||
record[4] = (uint8_t)(handshakelen);
|
||||
record[5] = (uint8_t)(type);
|
||||
record[6] = (uint8_t)(datalen >> 16);
|
||||
record[7] = (uint8_t)(datalen >> 8);
|
||||
record[8] = (uint8_t)(datalen);
|
||||
if (data) {
|
||||
memcpy(tls_handshake_data(tls_record_data(record)), data, datalen);
|
||||
}
|
||||
@@ -739,7 +739,7 @@ int tls_record_set_handshake_client_hello(uint8_t *record, size_t *recordlen,
|
||||
tls_uint16_to_bytes((uint16_t)protocol, &p, &len);
|
||||
tls_array_to_bytes(random, 32, &p, &len);
|
||||
tls_uint8array_to_bytes(session_id, session_id_len, &p, &len);
|
||||
tls_uint16_to_bytes(cipher_suites_count * 2, &p, &len);
|
||||
tls_uint16_to_bytes((uint16_t)(cipher_suites_count * 2), &p, &len);
|
||||
while (cipher_suites_count--) {
|
||||
if (!tls_cipher_suite_name(*cipher_suites)) {
|
||||
error_print();
|
||||
@@ -1019,7 +1019,7 @@ int tls_record_set_handshake_certificate(uint8_t *record, size_t *recordlen,
|
||||
}
|
||||
tls_uint24array_to_bytes(cert, certlen, &p, &len);
|
||||
}
|
||||
tls_uint24_to_bytes(len, &data, &len);
|
||||
tls_uint24_to_bytes((uint24_t)len, &data, &len);
|
||||
tls_record_set_handshake(record, recordlen, type, NULL, datalen);
|
||||
return 1;
|
||||
}
|
||||
@@ -1460,7 +1460,11 @@ int tls_cipher_suite_in_list(int cipher, const int *list, size_t list_count)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
int tls_record_send(const uint8_t *record, size_t recordlen, SOCKET sock)
|
||||
#else
|
||||
int tls_record_send(const uint8_t *record, size_t recordlen, int sock)
|
||||
#endif
|
||||
{
|
||||
#ifdef WIN32
|
||||
int r;
|
||||
@@ -1490,14 +1494,17 @@ int tls_record_send(const uint8_t *record, size_t recordlen, int sock)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
int tls_record_do_recv(uint8_t *record, size_t *recordlen, SOCKET sock)
|
||||
#else
|
||||
int tls_record_do_recv(uint8_t *record, size_t *recordlen, int sock)
|
||||
#endif
|
||||
{
|
||||
#ifdef WIN32
|
||||
int r;
|
||||
#else
|
||||
ssize_t r;
|
||||
#endif
|
||||
int type;
|
||||
size_t len;
|
||||
|
||||
len = 5;
|
||||
@@ -1541,7 +1548,11 @@ int tls_record_do_recv(uint8_t *record, size_t *recordlen, int sock)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
int tls_record_recv(uint8_t *record, size_t *recordlen, SOCKET sock)
|
||||
#else
|
||||
int tls_record_recv(uint8_t *record, size_t *recordlen, int sock)
|
||||
#endif
|
||||
{
|
||||
retry:
|
||||
if (tls_record_do_recv(record, recordlen, sock) != 1) {
|
||||
@@ -1674,8 +1685,6 @@ int tls_send(TLS_CONNECT *conn, const uint8_t *in, size_t inlen, size_t *sentlen
|
||||
const SM4_KEY *enc_key;
|
||||
uint8_t *seq_num;
|
||||
uint8_t *record;
|
||||
size_t recordlen;
|
||||
uint8_t *data;
|
||||
size_t datalen;
|
||||
|
||||
if (!conn) {
|
||||
|
||||
@@ -298,8 +298,6 @@ int x509_signature_algor_from_der(int *oid, const uint8_t **in, size_t *inlen)
|
||||
const uint8_t *p;
|
||||
size_t len;
|
||||
const ASN1_OID_INFO *info;
|
||||
int has_null_obj;
|
||||
int i;
|
||||
|
||||
*oid = OID_undef;
|
||||
if ((ret = asn1_sequence_from_der(&p, &len, in, inlen)) != 1) {
|
||||
|
||||
@@ -1099,7 +1099,7 @@ int x509_crl_get_details(const uint8_t *a, size_t alen,
|
||||
return -1;
|
||||
}
|
||||
if (asn1_any_from_der(&tbs, &tbs_len, &d, &dlen) != 1
|
||||
|| x509_signature_algor_from_der(&sig_alg, &d, &dlen) != 1
|
||||
|| x509_signature_algor_from_der(&signature_algor, &d, &dlen) != 1
|
||||
|| asn1_bit_octets_from_der(&sig, &siglen, &d, &dlen) != 1
|
||||
|| asn1_length_is_zero(dlen) != 1) {
|
||||
error_print();
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
int test_aes(void)
|
||||
{
|
||||
AES_KEY aes_key;
|
||||
int i;
|
||||
|
||||
/* test 1 */
|
||||
uint8_t key128[16] = {
|
||||
|
||||
@@ -78,7 +78,7 @@ int main(int argc, char **argv)
|
||||
sha224_finish(&ctx, dgst);
|
||||
|
||||
if (memcmp(dgstbuf, dgst, sizeof(dgst)) != 0) {
|
||||
printf("sha224 test %lu failed\n", i+1);
|
||||
printf("sha224 test %zu failed\n", i+1);
|
||||
printf("%s\n", tests[i].dgsthex);
|
||||
for (j = 0; j < sizeof(dgst); j++) {
|
||||
printf("%02X", dgst[j]);
|
||||
@@ -86,7 +86,7 @@ int main(int argc, char **argv)
|
||||
printf("\n");
|
||||
err++;
|
||||
} else {
|
||||
printf("sha224 test %lu ok\n", i+1);
|
||||
printf("sha224 test %zu ok\n", i+1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ int main(int argc, char **argv)
|
||||
sha256_finish(&ctx, dgst);
|
||||
|
||||
if (memcmp(dgstbuf, dgst, sizeof(dgst)) != 0) {
|
||||
printf("sha256 test %lu failed\n", i+1);
|
||||
printf("sha256 test %zu failed\n", i+1);
|
||||
printf("%s\n", tests[i].dgsthex);
|
||||
for (j = 0; j < sizeof(dgst); j++) {
|
||||
printf("%02X", dgst[j]);
|
||||
@@ -85,7 +85,7 @@ int main(int argc, char **argv)
|
||||
printf("\n");
|
||||
err++;
|
||||
} else {
|
||||
printf("sha256 test %lu ok\n", i+1);
|
||||
printf("sha256 test %zu ok\n", i+1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ int main(void)
|
||||
sha384_finish(&ctx, dgst);
|
||||
|
||||
if (memcmp(dgstbuf, dgst, sizeof(dgst)) != 0) {
|
||||
printf("sha384 test %lu failed\n", i+1);
|
||||
printf("sha384 test %zu failed\n", i+1);
|
||||
printf("%s\n", tests[i].dgsthex);
|
||||
for (j = 0; j < sizeof(dgst); j++) {
|
||||
printf("%02x", dgst[j]);
|
||||
@@ -91,7 +91,7 @@ int main(void)
|
||||
printf("\n");
|
||||
err++;
|
||||
} else {
|
||||
printf("sha384 test %lu ok\n", i+1);
|
||||
printf("sha384 test %zu ok\n", i+1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ int main(void)
|
||||
sha512_finish(&ctx, dgst);
|
||||
|
||||
if (memcmp(dgstbuf, dgst, sizeof(dgst)) != 0) {
|
||||
printf("sha512 test %lu failed\n", i+1);
|
||||
printf("sha512 test %zu failed\n", i+1);
|
||||
printf("%s\n", tests[i].dgsthex);
|
||||
for (j = 0; j < sizeof(dgst); j++) {
|
||||
printf("%02x", dgst[j]);
|
||||
@@ -92,7 +92,7 @@ int main(void)
|
||||
printf("\n");
|
||||
err++;
|
||||
} else {
|
||||
printf("sha512 test %lu ok\n", i+1);
|
||||
printf("sha512 test %zu ok\n", i+1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,6 @@ int certgen_main(int argc, char **argv)
|
||||
size_t namelen;
|
||||
time_t not_before;
|
||||
time_t not_after;
|
||||
uint8_t uniq_id[32];
|
||||
uint8_t exts[512];
|
||||
size_t extslen = 0;
|
||||
FILE *keyfp = NULL;
|
||||
|
||||
@@ -55,16 +55,7 @@ int cmssign_main(int argc, char **argv)
|
||||
uint8_t *cms = NULL;
|
||||
size_t cmslen, cms_maxlen;
|
||||
CMS_CERTS_AND_KEY cert_and_key;
|
||||
|
||||
int content_type;
|
||||
uint8_t *content = NULL;
|
||||
size_t content_len;
|
||||
|
||||
const uint8_t *rcpt_infos;
|
||||
size_t rcpt_infos_len;
|
||||
const uint8_t *shared_info1;
|
||||
const uint8_t *shared_info2;
|
||||
size_t shared_info1_len, shared_info2_len;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
@@ -29,7 +29,6 @@ int rand_main(int argc, char **argv)
|
||||
char *outfile = NULL;
|
||||
FILE *outfp = stdout;
|
||||
uint8_t buf[2048];
|
||||
int i;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
@@ -79,7 +78,7 @@ bad:
|
||||
goto end;
|
||||
}
|
||||
|
||||
while (outlen) {
|
||||
while (outlen > 0) {
|
||||
size_t len = outlen < sizeof(buf) ? outlen : sizeof(buf);
|
||||
|
||||
if (rdrand) {
|
||||
@@ -107,7 +106,7 @@ bad:
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
outlen -= len;
|
||||
outlen -= (int)len;
|
||||
}
|
||||
if (hex) {
|
||||
fprintf(outfp, "\n");
|
||||
|
||||
Reference in New Issue
Block a user