update crypto

This commit is contained in:
Zhi Guan
2017-03-08 15:02:42 +08:00
parent 4d84dd7557
commit 002096751c
29 changed files with 1062 additions and 134 deletions

View File

@@ -50,15 +50,27 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/rand.h>
#include <openssl/ecies.h>
static int ECIES_PARAMS_init_with_type(ECIES_PARAMS *params, int type)
{
return 0;
}
int gmssl_ecies_encrypt(int type, const unsigned char *in, size_t inlen,
unsigned char *out, size_t *outlen, EC_KEY *ec_key)
{
ECIES_CIPHERTEXT_VALUE *cv = NULL;
ECIES_PARAMS params;
if (!ECIES_PARAMS_init_with_type(&params, type)) {
return 0;
}
RAND_seed(in, inlen);
if (!(cv = ECIES_do_encrypt(type, in, inlen, ec_key))) {
if (!(cv = ECIES_do_encrypt(&params, in, inlen, ec_key))) {
*outlen = 0;
return 0;
}
@@ -72,11 +84,16 @@ int gmssl_ecies_decrypt(int type, const unsigned char *in, size_t inlen,
unsigned char *out, size_t *outlen, EC_KEY *ec_key)
{
ECIES_CIPHERTEXT_VALUE *cv = NULL;
ECIES_PARAMS params;
const unsigned char *cp = in;
unsigned char *der = NULL;
int derlen = -1;
int ret = -1;
if (!ECIES_PARAMS_init_with_type(&params, type)) {
return -1;
}
if (!(cv = d2i_ECIES_CIPHERTEXT_VALUE(NULL, &cp, inlen))) {
return -1;
}
@@ -86,7 +103,7 @@ int gmssl_ecies_decrypt(int type, const unsigned char *in, size_t inlen,
goto end;
}
ret = ECIES_do_decrypt(type, cv, out, outlen, ec_key);
ret = ECIES_do_decrypt(&params, cv, out, outlen, ec_key);
end:
OPENSSL_clear_free(der, derlen);