mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-06-23 05:33:39 +08:00
Update Windows support
This commit is contained in:
0
src/skf/skf.c
Normal file → Executable file
0
src/skf/skf.c
Normal file → Executable file
0
src/skf/skf.h
Normal file → Executable file
0
src/skf/skf.h
Normal file → Executable file
0
src/skf/skf_dummy.c
Normal file → Executable file
0
src/skf/skf_dummy.c
Normal file → Executable file
0
src/skf/skf_ext.c
Normal file → Executable file
0
src/skf/skf_ext.c
Normal file → Executable file
0
src/skf/skf_ext.h
Normal file → Executable file
0
src/skf/skf_ext.h
Normal file → Executable file
8
src/skf/skf_int.h
Normal file → Executable file
8
src/skf/skf_int.h
Normal file → Executable file
@@ -14,6 +14,10 @@
|
||||
#include "../sgd.h"
|
||||
#include "skf.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
typedef ULONG (DEVAPI *SKF_WaitForDevEvent_FuncPtr)(
|
||||
LPSTR szDevName,
|
||||
@@ -472,7 +476,11 @@ typedef ULONG (DEVAPI *SKF_CloseHandle_FuncPtr)(
|
||||
|
||||
typedef struct skf_method_st {
|
||||
char *name;
|
||||
#ifdef WIN32
|
||||
HMODULE dso;
|
||||
#else
|
||||
void *dso;
|
||||
#endif
|
||||
SKF_WaitForDevEvent_FuncPtr WaitForDevEvent;
|
||||
SKF_CancelWaitForDevEvent_FuncPtr CancelWaitForDevEvent;
|
||||
SKF_EnumDev_FuncPtr EnumDev;
|
||||
|
||||
6
src/skf/skf_lib.c
Normal file → Executable file
6
src/skf/skf_lib.c
Normal file → Executable file
@@ -23,7 +23,7 @@ extern SKF_VENDOR skf_wisec;
|
||||
#define SKFerr(f,e)
|
||||
|
||||
|
||||
ULONG SKF_LoadLibrary(LPSTR so_path, LPSTR vendor)
|
||||
ULONG DEVAPI SKF_LoadLibrary(LPSTR so_path, LPSTR vendor)
|
||||
{
|
||||
if (skf_method) {
|
||||
SKF_METHOD_free(skf_method);
|
||||
@@ -47,7 +47,7 @@ ULONG SKF_LoadLibrary(LPSTR so_path, LPSTR vendor)
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG SKF_UnloadLibrary(void)
|
||||
ULONG DEVAPI SKF_UnloadLibrary(void)
|
||||
{
|
||||
SKF_METHOD_free(skf_method);
|
||||
skf_method = NULL;
|
||||
@@ -126,7 +126,7 @@ static unsigned long skf_get_error_reason(ULONG ulError)
|
||||
return 0;
|
||||
}
|
||||
|
||||
ULONG SKF_GetErrorString(ULONG ulError, LPSTR *szErrorStr)
|
||||
ULONG DEVAPI SKF_GetErrorString(ULONG ulError, LPSTR *szErrorStr)
|
||||
{
|
||||
unsigned long reason;
|
||||
|
||||
|
||||
18
src/skf/skf_meth.c
Normal file → Executable file
18
src/skf/skf_meth.c
Normal file → Executable file
@@ -11,15 +11,24 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
#include "skf.h"
|
||||
#include "skf_ext.h"
|
||||
#include "skf_int.h"
|
||||
|
||||
#define SKFerr(e,r)
|
||||
|
||||
#ifdef WIN32
|
||||
#define SKF_METHOD_BIND_FUNCTION_EX(func,name) \
|
||||
skf->func = (SKF_##func##_FuncPtr)GetProcAddress(skf->dso, "SKF_"#name)
|
||||
#else
|
||||
#define SKF_METHOD_BIND_FUNCTION_EX(func,name) \
|
||||
skf->func = (SKF_##func##_FuncPtr)dlsym(skf->dso, "SKF_"#name)
|
||||
#endif
|
||||
|
||||
#define SKF_METHOD_BIND_FUNCTION(func) \
|
||||
SKF_METHOD_BIND_FUNCTION_EX(func,func)
|
||||
@@ -34,10 +43,17 @@ SKF_METHOD *SKF_METHOD_load_library(const char *so_path)
|
||||
SKFerr(SKF_F_SKF_METHOD_LOAD_LIBRARY, ERR_R_MALLOC_FAILURE);
|
||||
goto end;
|
||||
}
|
||||
if (!(skf->dso = dlopen(so_path, RTLD_LAZY))) {
|
||||
#ifdef WIN32
|
||||
if ((skf->dso = LoadLibraryA(so_path)) == NULL) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
#else
|
||||
if (!(skf->dso = dlopen(so_path, 0/*RTLD_LAZY*/))) {//FIXME:dlopen not in windows
|
||||
SKFerr(SKF_F_SKF_METHOD_LOAD_LIBRARY, SKF_R_DSO_LOAD_FAILURE);
|
||||
goto end;
|
||||
}
|
||||
#endif
|
||||
|
||||
SKF_METHOD_BIND_FUNCTION(WaitForDevEvent);
|
||||
SKF_METHOD_BIND_FUNCTION(CancelWaitForDevEvent);
|
||||
|
||||
18
src/skf/skf_prn.c
Normal file → Executable file
18
src/skf/skf_prn.c
Normal file → Executable file
@@ -48,7 +48,7 @@ static char *skf_algor_name(ULONG ulAlgID)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ULONG SKF_GetDevStateName(ULONG ulDevState, LPSTR *szDevStateName)
|
||||
ULONG DEVAPI SKF_GetDevStateName(ULONG ulDevState, LPSTR *szDevStateName)
|
||||
{
|
||||
if (!szDevStateName) {
|
||||
return SAR_INDATALENERR;
|
||||
@@ -72,7 +72,7 @@ ULONG SKF_GetDevStateName(ULONG ulDevState, LPSTR *szDevStateName)
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG SKF_GetContainerTypeName(ULONG ulContainerType, LPSTR *szName)
|
||||
ULONG DEVAPI SKF_GetContainerTypeName(ULONG ulContainerType, LPSTR *szName)
|
||||
{
|
||||
switch (ulContainerType) {
|
||||
case SKF_CONTAINER_TYPE_UNDEF:
|
||||
@@ -130,7 +130,7 @@ static table_item_t skf_pkey_caps[] = {
|
||||
{ SGD_SM2_3, "sm2encrypt" }
|
||||
};
|
||||
|
||||
ULONG SKF_PrintDevInfo(FILE *fp, const DEVINFO *devInfo)
|
||||
ULONG DEVAPI SKF_PrintDevInfo(FILE *fp, const DEVINFO *devInfo)
|
||||
{
|
||||
size_t i, n;
|
||||
int fmt = 0, ind = 4;
|
||||
@@ -205,7 +205,7 @@ ULONG SKF_PrintDevInfo(FILE *fp, const DEVINFO *devInfo)
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG SKF_PrintRSAPublicKey(FILE *fp, const RSAPUBLICKEYBLOB *blob)
|
||||
ULONG DEVAPI SKF_PrintRSAPublicKey(FILE *fp, const RSAPUBLICKEYBLOB *blob)
|
||||
{
|
||||
int fmt = 0, ind = 4;
|
||||
format_print(fp, fmt, ind, "AlgID: %s\n", skf_algor_name(blob->AlgID));
|
||||
@@ -215,7 +215,7 @@ ULONG SKF_PrintRSAPublicKey(FILE *fp, const RSAPUBLICKEYBLOB *blob)
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG SKF_PrintRSAPrivateKey(FILE *fp, const RSAPRIVATEKEYBLOB *blob)
|
||||
ULONG DEVAPI SKF_PrintRSAPrivateKey(FILE *fp, const RSAPRIVATEKEYBLOB *blob)
|
||||
{
|
||||
int fmt = 0, ind = 4;
|
||||
format_print(fp, fmt, ind, "AlgID: %s\n", skf_algor_name(blob->AlgID));
|
||||
@@ -231,7 +231,7 @@ ULONG SKF_PrintRSAPrivateKey(FILE *fp, const RSAPRIVATEKEYBLOB *blob)
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG SKF_PrintECCPublicKey(FILE *fp, const ECCPUBLICKEYBLOB *blob)
|
||||
ULONG DEVAPI SKF_PrintECCPublicKey(FILE *fp, const ECCPUBLICKEYBLOB *blob)
|
||||
{
|
||||
int fmt = 0, ind = 4;
|
||||
format_print(fp, fmt, ind, "BitLen: %u\n", blob->BitLen);
|
||||
@@ -240,7 +240,7 @@ ULONG SKF_PrintECCPublicKey(FILE *fp, const ECCPUBLICKEYBLOB *blob)
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG SKF_PrintECCPrivateKey(FILE *fp, const ECCPRIVATEKEYBLOB *blob)
|
||||
ULONG DEVAPI SKF_PrintECCPrivateKey(FILE *fp, const ECCPRIVATEKEYBLOB *blob)
|
||||
{
|
||||
int fmt = 0, ind = 4;
|
||||
format_print(fp, fmt, ind, "BitLen: %u\n", blob->BitLen);
|
||||
@@ -248,7 +248,7 @@ ULONG SKF_PrintECCPrivateKey(FILE *fp, const ECCPRIVATEKEYBLOB *blob)
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG SKF_PrintECCCipher(FILE *fp, const ECCCIPHERBLOB *blob)
|
||||
ULONG DEVAPI SKF_PrintECCCipher(FILE *fp, const ECCCIPHERBLOB *blob)
|
||||
{
|
||||
int fmt = 0, ind = 4;
|
||||
format_bytes(fp, fmt, ind, "XCoordinate", blob->XCoordinate, ECC_MAX_XCOORDINATE_BITS_LEN/8);
|
||||
@@ -259,7 +259,7 @@ ULONG SKF_PrintECCCipher(FILE *fp, const ECCCIPHERBLOB *blob)
|
||||
return SAR_OK;
|
||||
}
|
||||
|
||||
ULONG SKF_PrintECCSignature(FILE *fp, const ECCSIGNATUREBLOB *blob)
|
||||
ULONG DEVAPI SKF_PrintECCSignature(FILE *fp, const ECCSIGNATUREBLOB *blob)
|
||||
{
|
||||
int fmt = 0, ind = 4;
|
||||
format_bytes(fp, fmt, ind, "r", blob->r, ECC_MAX_XCOORDINATE_BITS_LEN/8);
|
||||
|
||||
0
src/skf/skf_wisec.c
Normal file → Executable file
0
src/skf/skf_wisec.c
Normal file → Executable file
0
src/skf/skf_wisec.h
Normal file → Executable file
0
src/skf/skf_wisec.h
Normal file → Executable file
Reference in New Issue
Block a user