#ifndef GMCRYPTO_H_
#define GMCRYPTO_H_
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#define GMCRYPTO_OK 0
#define GMCRYPTO_ERR -1
#define GMCRYPTO_SM3_DIGEST_SIZE 32
#define GMCRYPTO_SM4_BLOCK_SIZE 16
#define GMCRYPTO_SM4_KEY_SIZE 16
#define GMCRYPTO_SM2_SEC1_UNCOMPRESSED_SIZE 65
#define GMCRYPTO_SM2_SCALAR_SIZE 32
typedef struct gmcrypto_hmac_sm3_t gmcrypto_hmac_sm3_t;
typedef struct gmcrypto_sm2_privkey_t gmcrypto_sm2_privkey_t;
typedef struct gmcrypto_sm2_pubkey_t gmcrypto_sm2_pubkey_t;
typedef struct gmcrypto_sm3_t gmcrypto_sm3_t;
typedef struct gmcrypto_sm4_t gmcrypto_sm4_t;
const char *gmcrypto_version(void) ;
int gmcrypto_sm3_hash(const uint8_t *msg, uintptr_t msg_len, uint8_t *out_digest) ;
gmcrypto_sm3_t *gmcrypto_sm3_new(void) ;
int gmcrypto_sm3_update(gmcrypto_sm3_t *hasher, const uint8_t *data, uintptr_t data_len) ;
int gmcrypto_sm3_finalize(gmcrypto_sm3_t *hasher, uint8_t *out_digest) ;
void gmcrypto_sm3_free(gmcrypto_sm3_t *hasher) ;
int gmcrypto_hmac_sm3(const uint8_t *key,
uintptr_t key_len,
const uint8_t *msg,
uintptr_t msg_len,
uint8_t *out_tag)
;
gmcrypto_hmac_sm3_t *gmcrypto_hmac_sm3_new(const uint8_t *key, uintptr_t key_len) ;
int gmcrypto_hmac_sm3_update(gmcrypto_hmac_sm3_t *mac, const uint8_t *data, uintptr_t data_len) ;
int gmcrypto_hmac_sm3_finalize(gmcrypto_hmac_sm3_t *mac, uint8_t *out_tag) ;
int gmcrypto_hmac_sm3_verify(gmcrypto_hmac_sm3_t *mac, const uint8_t *expected_tag) ;
void gmcrypto_hmac_sm3_free(gmcrypto_hmac_sm3_t *mac) ;
int gmcrypto_pbkdf2_hmac_sm3(const uint8_t *pwd,
uintptr_t pwd_len,
const uint8_t *salt,
uintptr_t salt_len,
uint32_t iterations,
uint8_t *out,
uintptr_t out_len)
;
gmcrypto_sm4_t *gmcrypto_sm4_new(const uint8_t *key) ;
int gmcrypto_sm4_encrypt_block(const gmcrypto_sm4_t *cipher, uint8_t *block) ;
int gmcrypto_sm4_decrypt_block(const gmcrypto_sm4_t *cipher, uint8_t *block) ;
void gmcrypto_sm4_free(gmcrypto_sm4_t *cipher) ;
int gmcrypto_sm4_cbc_encrypt(const uint8_t *key,
const uint8_t *iv,
const uint8_t *pt,
uintptr_t pt_len,
uint8_t *out,
uintptr_t out_capacity,
uintptr_t *out_actual_len)
;
int gmcrypto_sm4_cbc_decrypt(const uint8_t *key,
const uint8_t *iv,
const uint8_t *ct,
uintptr_t ct_len,
uint8_t *out,
uintptr_t out_capacity,
uintptr_t *out_actual_len)
;
gmcrypto_sm2_privkey_t *gmcrypto_sm2_privkey_new(const uint8_t *d_be) ;
gmcrypto_sm2_pubkey_t *gmcrypto_sm2_pubkey_new(const uint8_t *sec1_uncompressed) ;
int gmcrypto_sm2_privkey_to_sec1_be(const gmcrypto_sm2_privkey_t *key, uint8_t *out) ;
int gmcrypto_sm2_pubkey_to_sec1_uncompressed(const gmcrypto_sm2_pubkey_t *key, uint8_t *out) ;
void gmcrypto_sm2_privkey_free(gmcrypto_sm2_privkey_t *key) ;
void gmcrypto_sm2_pubkey_free(gmcrypto_sm2_pubkey_t *key) ;
int gmcrypto_sm2_privkey_to_pkcs8(const gmcrypto_sm2_privkey_t *key,
const uint8_t *password,
uintptr_t pwd_len,
uint32_t pbkdf2_iters,
uint8_t *out_pem,
uintptr_t out_capacity,
uintptr_t *out_actual_len)
;
int gmcrypto_sm2_privkey_from_pkcs8(const uint8_t *pem,
uintptr_t pem_len,
const uint8_t *password,
uintptr_t pwd_len,
gmcrypto_sm2_privkey_t **out_key)
;
int gmcrypto_sm2_sign(const gmcrypto_sm2_privkey_t *key,
const uint8_t *signer_id,
uintptr_t signer_id_len,
const uint8_t *msg,
uintptr_t msg_len,
uint8_t *out_der_sig,
uintptr_t out_capacity,
uintptr_t *out_actual_len)
;
int gmcrypto_sm2_verify(const gmcrypto_sm2_pubkey_t *key,
const uint8_t *signer_id,
uintptr_t signer_id_len,
const uint8_t *msg,
uintptr_t msg_len,
const uint8_t *der_sig,
uintptr_t der_sig_len)
;
int gmcrypto_sm2_encrypt(const gmcrypto_sm2_pubkey_t *key,
const uint8_t *pt,
uintptr_t pt_len,
uint8_t *out_der_ct,
uintptr_t out_capacity,
uintptr_t *out_actual_len)
;
int gmcrypto_sm2_decrypt(const gmcrypto_sm2_privkey_t *key,
const uint8_t *der_ct,
uintptr_t der_ct_len,
uint8_t *out_pt,
uintptr_t out_capacity,
uintptr_t *out_actual_len)
;
#endif