Skip to content

Commit

Permalink
Add sdfsign command
Browse files Browse the repository at this point in the history
  • Loading branch information
guanzhi committed Jun 7, 2024
1 parent 4363740 commit c4e5cf0
Show file tree
Hide file tree
Showing 6 changed files with 330 additions and 155 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ if (ENABLE_SDF)
src/sdf/sdf_meth.c
src/sdf/sdf_ext.c
src/sdf/sdf_sansec.c)
list(APPEND tools tools/sdfutil.c tools/sdfinfo.c tools/sdfexport.c tools/sdftest.c)
list(APPEND tools tools/sdfinfo.c tools/sdfexport.c tools/sdfsign.c tools/sdftest.c)
endif()


Expand Down
24 changes: 17 additions & 7 deletions include/gmssl/sdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,18 @@ typedef struct {
} SDF_DEVICE;

typedef struct {
SM2_KEY public_key;
SM2_Z256_POINT public_key;
void *session;
int index;
} SDF_KEY;
} SDF_SIGN_KEY;

typedef struct {
SM3_CTX sm3_ctx;
SM3_CTX saved_sm3_ctx;
SDF_SIGN_KEY key;
} SDF_SIGN_CTX;

/*
typedef struct {
void *hSession;
} SDF_SM3_CTX;
Expand All @@ -54,17 +61,20 @@ typedef struct {
uint8_t passlen;
unsigned char pass[26 + 1];
} SDF_PRIVATE_KEY;
*/


int sdf_load_library(const char *so_path, const char *vendor);
int sdf_open_device(SDF_DEVICE *dev);
int sdf_print_device_info(FILE *fp, int fmt, int ind, const char *lable, SDF_DEVICE *dev);
int sdf_rand_bytes(SDF_DEVICE *dev, uint8_t *buf, size_t len);
int sdf_export_sign_public_key(SDF_DEVICE *dev, int key_index, SM2_KEY *public_key);
int sdf_export_enc_public_key(SDF_DEVICE *dev, int key_index, SM2_KEY *public_key);
int sdf_load_sign_key(SDF_DEVICE *dev, SDF_KEY *key, int index, const char *pass);
int sdf_sign(SDF_KEY *key, const uint8_t dgst[32], uint8_t *sig, size_t *siglen);
int sdf_release_key(SDF_KEY *key);
int sdf_load_sign_key(SDF_DEVICE *dev, SDF_SIGN_KEY *key, int key_index, const char *pass);
int sdf_sign(SDF_SIGN_KEY *key, const uint8_t dgst[32], uint8_t *sig, size_t *siglen);
int sdf_sign_init(SDF_SIGN_CTX *ctx, const SDF_SIGN_KEY *key, const char *id, size_t idlen);
int sdf_sign_update(SDF_SIGN_CTX *ctx, const uint8_t *data, size_t datalen);
int sdf_sign_finish(SDF_SIGN_CTX *ctx, uint8_t *sig, size_t *siglen);
int sdf_sign_reset(SDF_SIGN_CTX *ctx);
int sdf_release_sign_key(SDF_SIGN_KEY *key);
int sdf_close_device(SDF_DEVICE *dev);
void sdf_unload_library(void);

Expand Down
Loading

0 comments on commit c4e5cf0

Please sign in to comment.