Fix Visual Studio related bugs

This commit is contained in:
Zhi Guan
2022-10-09 12:55:32 +08:00
parent dc58a88588
commit 6faeb627ed
16 changed files with 91 additions and 28 deletions

View File

@@ -11,6 +11,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <windows.h>
#include <wincrypt.h>
#include <gmssl/error.h>
@@ -37,7 +38,7 @@ int rand_bytes(uint8_t *buf, size_t len)
error_print();
goto end;
}
ret = 1
ret = 1;
end:
if (CryptReleaseContext(hCryptProv, 0) != TRUE) {
error_print();

View File

@@ -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
@@ -19,21 +19,21 @@
#include <gmssl/endian.h>
#define sm2_print_bn(label,a) sm2_bn_print(stderr,0,0,label,a) // 这个不应该放在这里,应该放在测试文件中
#define sm2_print_bn(label,a) sm2_bn_print(stderr,0,0,label,a) // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>÷<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
const SM2_BN SM2_P = {
extern const SM2_BN SM2_P = {
0xffffffff, 0xffffffff, 0x00000000, 0xffffffff,
0xffffffff, 0xffffffff, 0xffffffff, 0xfffffffe,
};
const SM2_BN SM2_B = {
extern const SM2_BN SM2_B = {
0x4d940e93, 0xddbcbd41, 0x15ab8f92, 0xf39789f5,
0xcf6509a7, 0x4d5a9e4b, 0x9d9f5e34, 0x28e9fa9e,
};
const SM2_JACOBIAN_POINT _SM2_G = {
extern SM2_JACOBIAN_POINT _SM2_G = {
{
0x334c74c7, 0x715a4589, 0xf2660be1, 0x8fe30bbf,
0x6a39c994, 0x5f990446, 0x1f198119, 0x32c4ae2c,
@@ -46,9 +46,9 @@ const SM2_JACOBIAN_POINT _SM2_G = {
1, 0, 0, 0, 0, 0, 0, 0,
},
};
const SM2_JACOBIAN_POINT *SM2_G = &_SM2_G;
extern SM2_JACOBIAN_POINT * SM2_G = &_SM2_G;
const SM2_BN SM2_N = {
extern const SM2_BN SM2_N = {
0x39d54123, 0x53bbf409, 0x21c6052b, 0x7203df6b,
0xffffffff, 0xffffffff, 0xffffffff, 0xfffffffe,
};

View File

@@ -18,6 +18,7 @@
#include <gmssl/sm9.h>
#include <gmssl/error.h>
#include <gmssl/endian.h>
#include <gmssl/rand.h>
const sm9_bn_t SM9_ZERO = {0,0,0,0,0,0,0,0};
@@ -187,15 +188,12 @@ void sm9_bn_sub(sm9_bn_t ret, const sm9_bn_t a, const sm9_bn_t b)
int sm9_bn_rand_range(sm9_bn_t r, const sm9_bn_t range)
{
FILE *fp;
uint8_t buf[256];
fp = fopen("/dev/urandom", "rb");
do {
fread(buf, 1, 256, fp);
rand_bytes(buf, sizeof(buf));
sm9_bn_from_bytes(r, buf);
} while (sm9_bn_cmp(r, range) >= 0);
fclose(fp);
return 1;
}