1 /* 2 * Copyright 2014-2022 The GmSSL Project. All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the License); you may 5 * not use this file except in compliance with the License. 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 */ 9 10 11 #ifndef GMSSL_SDF_H 12 #define GMSSL_SDF_H 13 14 #include <string.h> 15 #include <stdint.h> 16 #include <gmssl/sm2.h> 17 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 /* 24 SDF Public API 25 26 sdf_load_library 27 sdf_unload_library 28 29 SDF_DEVICE 30 sdf_open_device 31 sdf_close_device 32 sdf_print_device_info 33 sdf_rand_bytes 34 sdf_load_sign_key 35 36 SDF_KEY 37 sdf_sign 38 sdf_release_key 39 */ 40 41 typedef struct { 42 void *handle; 43 char issuer[41]; 44 char name[17]; 45 char serial[17]; 46 } SDF_DEVICE; 47 48 typedef struct { 49 SM2_KEY public_key; 50 void *session; 51 int index; 52 } SDF_KEY; 53 54 55 int sdf_load_library(const char *so_path, const char *vendor); 56 int sdf_open_device(SDF_DEVICE *dev); 57 int sdf_print_device_info(FILE *fp, int fmt, int ind, const char *lable, SDF_DEVICE *dev); 58 int sdf_rand_bytes(SDF_DEVICE *dev, uint8_t *buf, size_t len); 59 int sdf_load_sign_key(SDF_DEVICE *dev, SDF_KEY *key, int index, const char *pass); 60 int sdf_sign(SDF_KEY *key, const uint8_t dgst[32], uint8_t *sig, size_t *siglen); 61 int sdf_release_key(SDF_KEY *key); 62 int sdf_close_device(SDF_DEVICE *dev); 63 void sdf_unload_library(void); 64 65 66 #ifdef __cplusplus 67 } 68 #endif 69 #endif 70