add gmssl command

This commit is contained in:
Zhi Guan
2022-04-16 22:18:45 +08:00
parent 7e4dd76839
commit 22639fce28
33 changed files with 786 additions and 216 deletions

View File

@@ -55,6 +55,9 @@
#define GMSSL_GF128_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
@@ -62,28 +65,24 @@
extern "C" {
#endif
#define GMSSL_HAVE_UINT128
#ifdef GMSSL_HAVE_UINT128
typedef unsigned __int128 gf128_t;
#else
//typedef unsigned __int128 gf128_t;
typedef struct {
uint64_t hi;
uint64_t lo;
} gf128_t;
#endif
// Note: send by value is comptabile with uint128_t and sse2
gf128_t gf128_from_hex(const char *s);
int gf128_equ_hex(gf128_t a, const char *s);
gf128_t gf128_zero(void);
gf128_t gf128_add(gf128_t a, gf128_t b);
gf128_t gf128_mul(gf128_t a, gf128_t b);
gf128_t gf128_mul2(gf128_t a);
gf128_t gf128_from_bytes(const uint8_t p[16]);
void gf128_to_bytes(gf128_t a, uint8_t p[16]);
void gf128_print(const char *s, gf128_t a);
int gf128_print(FILE *fp, int fmt ,int ind, const char *label, gf128_t a);
#ifdef __cplusplus

View File

@@ -1,4 +1,4 @@
/*
/*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -53,6 +53,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <limits.h>
#include <gmssl/hmac.h>
#ifdef __cplusplus
@@ -61,7 +62,8 @@ extern "C" {
#define PBKDF2_MIN_ITER 10000
#define PBKDF2_MIN_SALT_SIZE 64
#define PBKDF2_MAX_ITER (INT_MAX)
#define PBKDF2_MAX_SALT_SIZE 64
#define PBKDF2_DEFAULT_SALT_SIZE 8

View File

@@ -124,6 +124,22 @@ int sm4_cbc_decrypt_update(SM4_CBC_CTX *ctx, const uint8_t *in, size_t inlen, ui
int sm4_cbc_decrypt_finish(SM4_CBC_CTX *ctx, uint8_t *out, size_t *outlen);
typedef struct {
SM4_KEY sm4_key;
uint8_t ctr[SM4_BLOCK_SIZE];
uint8_t block[SM4_BLOCK_SIZE];
size_t block_nbytes;
} SM4_CTR_CTX;
int sm4_ctr_encrypt_init(SM4_CTR_CTX *ctx, const uint8_t key[SM4_BLOCK_SIZE], const uint8_t ctr[SM4_BLOCK_SIZE]);
int sm4_ctr_encrypt_update(SM4_CTR_CTX *ctx, const uint8_t *in, size_t inlen, uint8_t *out, size_t *outlen);
int sm4_ctr_encrypt_finish(SM4_CTR_CTX *ctx, uint8_t *out, size_t *outlen);
#define sm4_ctr_decrypt_init(ctx,key,ctr) sm4_ctr_encrypt_init(ctx,key,ctr)
#define sm4_ctr_decrypt_update(ctx,in,inlen,out,outlen) sm4_ctr_encrypt_update(ctx,in,inlen,out,outlen)
#define sm4_ctr_decrypt_finish(ctx,out,outlen) sm4_ctr_encrypt_finish(ctx,out,outlen)
#ifdef __cplusplus
}
#endif