Add SDF pkey encrypt/decrypt support

This commit is contained in:
Zhi Guan
2018-03-30 19:51:49 +08:00
parent 92971350c4
commit a94e307888
11 changed files with 5522 additions and 5360 deletions

View File

@@ -52,7 +52,7 @@
#include <openssl/gmsdf.h>
#include "internal/sdf_int.h"
#include "../../e_os.h"
#include "sdf_sansec.h"
static void print_str(const char *name, const void *value)
@@ -302,3 +302,41 @@ int SDF_ImportKey(
{
return 0;
}
int SDF_NewECCCipher(ECCCipher **cipher, size_t ulDataLen)
{
ECCCipher *ecc_cipher = NULL;
size_t len;
if (!cipher) {
SDFerr(SDF_F_SDF_NEWECCCIPHER, ERR_R_PASSED_NULL_PARAMETER);
return SDR_INARGERR;
}
if (!ulDataLen || ulDataLen > INT_MAX) {
SDFerr(SDF_F_SDF_NEWECCCIPHER,
SDF_R_INVALID_SM2_CIPHERTEXT_LENGTH);
return SDR_INARGERR;
}
len = sizeof(ECCCipher) - 1 + ulDataLen;
if (len < sizeof(SANSEC_ECCCipher)) {
len = sizeof(SANSEC_ECCCipher);
}
if (!(ecc_cipher = OPENSSL_zalloc(len))) {
SDFerr(SDF_F_SDF_NEWECCCIPHER, ERR_R_MALLOC_FAILURE);
return SDR_NOBUFFER;
}
ecc_cipher->L = (unsigned int)ulDataLen;
*cipher = ecc_cipher;
return SDR_OK;
}
int SDF_FreeECCCipher(ECCCipher *cipher)
{
OPENSSL_free(cipher);
return SDR_OK;
}