mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-22 16:26:28 +08:00
SKF Wrapper
This commit is contained in:
@@ -17,13 +17,12 @@ TEST=eciestest.c
|
||||
APPS=
|
||||
|
||||
LIB=$(TOP)/libcrypto.a
|
||||
LIBSRC= ecies_lib.c ecies_asn1.c ecies_err.c kdf_x9_63.c
|
||||
|
||||
LIBOBJ= ecies_lib.o ecies_asn1.o ecies_err.o kdf_x9_63.o
|
||||
LIBSRC= ecies_lib.c ecies_asn1.c ecies_err.c
|
||||
LIBOBJ= ecies_lib.o ecies_asn1.o ecies_err.o
|
||||
|
||||
SRC= $(LIBSRC)
|
||||
|
||||
EXHEADER= ecies.h kdf.h
|
||||
EXHEADER= ecies.h
|
||||
HEADER= ecies_locl.h $(EXHEADER)
|
||||
|
||||
ALL= $(GENERAL) $(SRC) $(HEADER)
|
||||
@@ -77,66 +76,50 @@ clean:
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
ecs_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
|
||||
ecs_asn1.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
|
||||
ecs_asn1.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
|
||||
ecs_asn1.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
|
||||
ecs_asn1.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
|
||||
ecs_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
|
||||
ecs_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
|
||||
ecs_asn1.o: ../../include/openssl/symhacks.h ecs_asn1.c ecs_locl.h
|
||||
ecs_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
|
||||
ecs_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
|
||||
ecs_err.o: ../../include/openssl/ec.h ../../include/openssl/ecdsa.h
|
||||
ecs_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
|
||||
ecs_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
|
||||
ecs_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
|
||||
ecs_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
|
||||
ecs_err.o: ecs_err.c
|
||||
ecs_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
|
||||
ecs_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
|
||||
ecs_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
|
||||
ecs_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
|
||||
ecs_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
|
||||
ecs_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
|
||||
ecs_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
|
||||
ecs_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
|
||||
ecs_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
|
||||
ecs_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
|
||||
ecs_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
|
||||
ecs_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
|
||||
ecs_lib.o: ../../include/openssl/x509_vfy.h ecs_lib.c ecs_locl.h
|
||||
ecs_ossl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
|
||||
ecs_ossl.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
|
||||
ecs_ossl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
|
||||
ecs_ossl.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
|
||||
ecs_ossl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
|
||||
ecs_ossl.o: ../../include/openssl/opensslconf.h
|
||||
ecs_ossl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
|
||||
ecs_ossl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
|
||||
ecs_ossl.o: ../../include/openssl/symhacks.h ecs_locl.h ecs_ossl.c
|
||||
ecs_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
|
||||
ecs_sign.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
|
||||
ecs_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
|
||||
ecs_sign.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
|
||||
ecs_sign.o: ../../include/openssl/engine.h ../../include/openssl/evp.h
|
||||
ecs_sign.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
|
||||
ecs_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
|
||||
ecs_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
|
||||
ecs_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
|
||||
ecs_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
|
||||
ecs_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
|
||||
ecs_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
|
||||
ecs_sign.o: ecs_locl.h ecs_sign.c
|
||||
ecs_vrf.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
|
||||
ecs_vrf.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
|
||||
ecs_vrf.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
|
||||
ecs_vrf.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
|
||||
ecs_vrf.o: ../../include/openssl/engine.h ../../include/openssl/evp.h
|
||||
ecs_vrf.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
|
||||
ecs_vrf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
|
||||
ecs_vrf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
|
||||
ecs_vrf.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
|
||||
ecs_vrf.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
|
||||
ecs_vrf.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
|
||||
ecs_vrf.o: ../../include/openssl/x509_vfy.h ecs_locl.h ecs_vrf.c
|
||||
ecies_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
|
||||
ecies_asn1.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
|
||||
ecies_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
|
||||
ecies_asn1.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
|
||||
ecies_asn1.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
|
||||
ecies_asn1.o: ../../include/openssl/evp.h ../../include/openssl/kdf.h
|
||||
ecies_asn1.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
|
||||
ecies_asn1.o: ../../include/openssl/objects.h
|
||||
ecies_asn1.o: ../../include/openssl/opensslconf.h
|
||||
ecies_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
|
||||
ecies_asn1.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
|
||||
ecies_asn1.o: ../../include/openssl/sha.h ../../include/openssl/sm2.h
|
||||
ecies_asn1.o: ../../include/openssl/sm3.h ../../include/openssl/stack.h
|
||||
ecies_asn1.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
|
||||
ecies_asn1.o: ../../include/openssl/x509_vfy.h ecies.h ecies_asn1.c
|
||||
ecies_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
|
||||
ecies_err.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
|
||||
ecies_err.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
|
||||
ecies_err.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
|
||||
ecies_err.o: ../../include/openssl/ecies.h ../../include/openssl/err.h
|
||||
ecies_err.o: ../../include/openssl/evp.h ../../include/openssl/kdf.h
|
||||
ecies_err.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
|
||||
ecies_err.o: ../../include/openssl/objects.h
|
||||
ecies_err.o: ../../include/openssl/opensslconf.h
|
||||
ecies_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
|
||||
ecies_err.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
|
||||
ecies_err.o: ../../include/openssl/sha.h ../../include/openssl/sm2.h
|
||||
ecies_err.o: ../../include/openssl/sm3.h ../../include/openssl/stack.h
|
||||
ecies_err.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
|
||||
ecies_err.o: ../../include/openssl/x509_vfy.h ecies_err.c
|
||||
ecies_lib.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
|
||||
ecies_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
|
||||
ecies_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
|
||||
ecies_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
|
||||
ecies_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/ecies.h
|
||||
ecies_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
|
||||
ecies_lib.o: ../../include/openssl/hmac.h ../../include/openssl/kdf.h
|
||||
ecies_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
|
||||
ecies_lib.o: ../../include/openssl/objects.h
|
||||
ecies_lib.o: ../../include/openssl/opensslconf.h
|
||||
ecies_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
|
||||
ecies_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
|
||||
ecies_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
|
||||
ecies_lib.o: ../../include/openssl/sm2.h ../../include/openssl/sm3.h
|
||||
ecies_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
|
||||
ecies_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
|
||||
ecies_lib.o: ecies_lib.c
|
||||
|
||||
@@ -142,31 +142,34 @@ int ECIES_decrypt_with_recommended(unsigned char *out, size_t *outlen,
|
||||
|
||||
void ERR_load_ECIES_strings(void);
|
||||
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/*
|
||||
* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
* made after this point may be overwritten when the script is next run.
|
||||
*/
|
||||
void ERR_load_ECIES_strings(void);
|
||||
|
||||
/* Error codes for the ECIES functions. */
|
||||
|
||||
/* Function codes. */
|
||||
#define ECIES_F_I2D_ECIESPARAMETERS 100
|
||||
#define ECIES_F_D2I_ECIESPARAMETERS 101
|
||||
#define ECIES_F_ECIES_SET_PARAMETERS 102
|
||||
#define ECIES_F_ECIES_GET_PARAMETERS 103
|
||||
#define ECIES_F_ECIES_DO_ENCRYPT 104
|
||||
#define ECIES_F_ECIES_DO_DECRYPT 105
|
||||
#define ECIES_F_ECIES_ENCRYPT 106
|
||||
#define ECIES_F_ECIES_DECRYPT 107
|
||||
# define ECIES_F_D2I_ECIESPARAMETERS 100
|
||||
# define ECIES_F_ECIES_DECRYPT 101
|
||||
# define ECIES_F_ECIES_DO_DECRYPT 102
|
||||
# define ECIES_F_ECIES_DO_ENCRYPT 103
|
||||
# define ECIES_F_ECIES_ENCRYPT 104
|
||||
# define ECIES_F_I2D_ECIESPARAMETERS 105
|
||||
|
||||
/* Reason codes. */
|
||||
#define ECIES_R_BAD_DATA 100
|
||||
#define ECIES_R_UNKNOWN_CIPHER_TYPE 101
|
||||
#define ECIES_R_ENCRYPT_FAILED 102
|
||||
#define ECIES_R_DECRYPT_FAILED 103
|
||||
#define ECIES_R_UNKNOWN_MAC_TYPE 104
|
||||
#define ECIES_R_GEN_MAC_FAILED 105
|
||||
#define ECIES_R_VERIFY_MAC_FAILED 106
|
||||
#define ECIES_R_ECDH_FAILED 107
|
||||
#define ECIES_R_BUFFER_TOO_SMALL 108
|
||||
# define ECIES_R_BAD_DATA 100
|
||||
# define ECIES_R_BUFFER_TOO_SMALL 101
|
||||
# define ECIES_R_DECRYPT_FAILED 102
|
||||
# define ECIES_R_ECDH_FAILED 103
|
||||
# define ECIES_R_ENCRYPT_FAILED 104
|
||||
# define ECIES_R_GEN_MAC_FAILED 105
|
||||
# define ECIES_R_VERIFY_MAC_FAILED 106
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* crypto/ecies/ecies_err.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2007 - 2015 The GmSSL Project. All rights reserved.
|
||||
* Copyright (c) 1999-2016 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -16,27 +16,27 @@
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the GmSSL Project.
|
||||
* (http://gmssl.org/)"
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* 4. The name "GmSSL Project" must not be used to endorse or promote
|
||||
* products derived from this software without prior written
|
||||
* permission. For written permission, please contact
|
||||
* guanzhi1980@gmail.com.
|
||||
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please contact
|
||||
* openssl-core@OpenSSL.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "GmSSL"
|
||||
* nor may "GmSSL" appear in their names without prior written
|
||||
* permission of the GmSSL Project.
|
||||
* 5. Products derived from this software may not be called "OpenSSL"
|
||||
* nor may "OpenSSL" appear in their names without prior written
|
||||
* permission of the OpenSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the GmSSL Project
|
||||
* (http://gmssl.org/)"
|
||||
* "This product includes software developed by the OpenSSL Project
|
||||
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
|
||||
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
@@ -47,40 +47,47 @@
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* NOTE: this file was auto generated by the mkerr.pl script: any changes
|
||||
* made to it will be overwritten when the script next updates this file,
|
||||
* only reason strings will be preserved.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <openssl/err.h>
|
||||
#include "ecies.h"
|
||||
#include <openssl/ecies.h>
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
|
||||
#define ERR_FUNC(func) ERR_PACK(ERR_LIB_ECIES,func,0)
|
||||
#define ERR_REASON(reason) ERR_PACK(ERR_LIB_ECIES,0,reason)
|
||||
|
||||
# define ERR_FUNC(func) ERR_PACK(ERR_LIB_ECIES,func,0)
|
||||
# define ERR_REASON(reason) ERR_PACK(ERR_LIB_ECIES,0,reason)
|
||||
|
||||
static ERR_STRING_DATA ECIES_str_functs[] = {
|
||||
{ERR_FUNC(ECIES_F_ECIES_SET_PARAMETERS),"ECIES_set_parameters"},
|
||||
{ERR_FUNC(ECIES_F_ECIES_GET_PARAMETERS),"ECIES_get_parameters"},
|
||||
{ERR_FUNC(ECIES_F_ECIES_DO_ENCRYPT), "ECIES_do_encrypt"},
|
||||
{ERR_FUNC(ECIES_F_ECIES_DO_DECRYPT), "ECIES_do_decrypt"},
|
||||
{ERR_FUNC(ECIES_F_ECIES_ENCRYPT), "ECIES_encrypt"},
|
||||
{ERR_FUNC(ECIES_F_ECIES_DECRYPT), "ECIES_decrypt"},
|
||||
{0,NULL}
|
||||
{ERR_FUNC(ECIES_F_D2I_ECIESPARAMETERS), "d2i_ECIESParameters"},
|
||||
{ERR_FUNC(ECIES_F_ECIES_DECRYPT), "ECIES_decrypt"},
|
||||
{ERR_FUNC(ECIES_F_ECIES_DO_DECRYPT), "ECIES_do_decrypt"},
|
||||
{ERR_FUNC(ECIES_F_ECIES_DO_ENCRYPT), "ECIES_do_encrypt"},
|
||||
{ERR_FUNC(ECIES_F_ECIES_ENCRYPT), "ECIES_encrypt"},
|
||||
{ERR_FUNC(ECIES_F_I2D_ECIESPARAMETERS), "i2d_ECIESParameters"},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
static ERR_STRING_DATA ECIES_str_reasons[] = {
|
||||
{ERR_REASON(ECIES_R_BAD_DATA), "bad data"},
|
||||
{ERR_REASON(ECIES_R_UNKNOWN_CIPHER_TYPE),"unknown cipher type"},
|
||||
{ERR_REASON(ECIES_R_ENCRYPT_FAILED), "encrypt failed"},
|
||||
{ERR_REASON(ECIES_R_DECRYPT_FAILED), "decrypt failed"},
|
||||
{ERR_REASON(ECIES_R_UNKNOWN_MAC_TYPE), "unknown MAC type"},
|
||||
{ERR_REASON(ECIES_R_GEN_MAC_FAILED), "MAC generation failed"},
|
||||
{ERR_REASON(ECIES_R_VERIFY_MAC_FAILED), "MAC verification failed"},
|
||||
{ERR_REASON(ECIES_R_ECDH_FAILED), "ECDH failed"},
|
||||
{ERR_REASON(ECIES_R_BUFFER_TOO_SMALL), "buffer too small"},
|
||||
{0,NULL}
|
||||
{ERR_REASON(ECIES_R_BAD_DATA), "bad data"},
|
||||
{ERR_REASON(ECIES_R_BUFFER_TOO_SMALL), "buffer too small"},
|
||||
{ERR_REASON(ECIES_R_DECRYPT_FAILED), "decrypt failed"},
|
||||
{ERR_REASON(ECIES_R_ECDH_FAILED), "ECDH failed"},
|
||||
{ERR_REASON(ECIES_R_ENCRYPT_FAILED), "encrypt failed"},
|
||||
{ERR_REASON(ECIES_R_GEN_MAC_FAILED), "MAC generation failed"},
|
||||
{ERR_REASON(ECIES_R_VERIFY_MAC_FAILED), "MAC verification failed"},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -89,10 +96,9 @@ void ERR_load_ECIES_strings(void)
|
||||
{
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
|
||||
if (ERR_func_error_string(ECIES_str_functs[0].error) == NULL) {
|
||||
ERR_load_strings(0,ECIES_str_functs);
|
||||
ERR_load_strings(0,ECIES_str_reasons);
|
||||
}
|
||||
if (ERR_func_error_string(ECIES_str_functs[0].error) == NULL) {
|
||||
ERR_load_strings(0, ECIES_str_functs);
|
||||
ERR_load_strings(0, ECIES_str_reasons);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -57,8 +57,8 @@
|
||||
#include <openssl/hmac.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/ecdh.h>
|
||||
#include "ecies.h"
|
||||
#include "kdf.h"
|
||||
#include <openssl/kdf.h>
|
||||
#include <openssl/ecies.h>
|
||||
|
||||
|
||||
static void *ecies_data_dup(void *data) {
|
||||
@@ -342,7 +342,7 @@ int ECIES_do_decrypt(const ECIES_CIPHERTEXT_VALUE *cv,
|
||||
}
|
||||
if (!(ephem_point = EC_POINT_new(EC_KEY_get0_group(pri_key))))
|
||||
{
|
||||
ECIESerr(ECIES_F_ECIES_DO_ENCRYPT, ERR_R_MALLOC_FAILURE);
|
||||
ECIESerr(ECIES_F_ECIES_DO_DECRYPT, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
if (!EC_POINT_oct2point(EC_KEY_get0_group(pri_key), ephem_point,
|
||||
@@ -397,7 +397,7 @@ int ECIES_do_decrypt(const ECIES_CIPHERTEXT_VALUE *cv,
|
||||
ECIESerr(ECIES_F_ECIES_DO_DECRYPT, ECIES_R_VERIFY_MAC_FAILED);
|
||||
goto err;
|
||||
}
|
||||
if (memcmp(cv->mactag->data, mac, len))
|
||||
if (OPENSSL_memcmp(cv->mactag->data, mac, len))
|
||||
{
|
||||
ECIESerr(ECIES_F_ECIES_DO_DECRYPT, ECIES_R_VERIFY_MAC_FAILED);
|
||||
goto err;
|
||||
@@ -507,12 +507,12 @@ int ECIES_decrypt(const ECIES_PARAMS *param,
|
||||
const unsigned char *p = in;
|
||||
|
||||
if (!(cv = d2i_ECIES_CIPHERTEXT_VALUE(NULL, &p, (long)inlen))) {
|
||||
ECIESerr(ECIES_F_ECIES_ENCRYPT, ECIES_R_ENCRYPT_FAILED);
|
||||
ECIESerr(ECIES_F_ECIES_DECRYPT, ECIES_R_ENCRYPT_FAILED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!ECIES_do_decrypt(cv, param, out, outlen, ec_key)) {
|
||||
ECIESerr(ECIES_F_ECIES_ENCRYPT, ECIES_R_ENCRYPT_FAILED);
|
||||
ECIESerr(ECIES_F_ECIES_DECRYPT, ECIES_R_ENCRYPT_FAILED);
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -554,4 +554,3 @@ int ECIES_decrypt_with_recommended(unsigned char *out, size_t *outlen,
|
||||
return ECIES_decrypt(¶m, out, outlen, in, inlen, ec_key);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
/* crypto/ecies/kdf.h */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2007 - 2015 The GmSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the GmSSL Project.
|
||||
* (http://gmssl.org/)"
|
||||
*
|
||||
* 4. The name "GmSSL Project" must not be used to endorse or promote
|
||||
* products derived from this software without prior written
|
||||
* permission. For written permission, please contact
|
||||
* guanzhi1980@gmail.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "GmSSL"
|
||||
* nor may "GmSSL" appear in their names without prior written
|
||||
* permission of the GmSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the GmSSL Project
|
||||
* (http://gmssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HEADER_KDF_H
|
||||
#define HEADER_KDF_H
|
||||
|
||||
#include <openssl/evp.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef void *(*KDF_FUNC)(const void *in, size_t inlen, void *out, size_t *outlen);
|
||||
|
||||
KDF_FUNC KDF_get_x9_63(const EVP_MD *md);
|
||||
KDF_FUNC KDF_get_nist_concatenation(void);
|
||||
KDF_FUNC KDF_get_tls_kdf(void);
|
||||
KDF_FUNC KDF_get_ikev2_kdf(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,170 +0,0 @@
|
||||
/* crypto/ecies/kdf_x9_63.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2007 - 2015 The GmSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. All advertising materials mentioning features or use of this
|
||||
* software must display the following acknowledgment:
|
||||
* "This product includes software developed by the GmSSL Project.
|
||||
* (http://gmssl.org/)"
|
||||
*
|
||||
* 4. The name "GmSSL Project" must not be used to endorse or promote
|
||||
* products derived from this software without prior written
|
||||
* permission. For written permission, please contact
|
||||
* guanzhi1980@gmail.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "GmSSL"
|
||||
* nor may "GmSSL" appear in their names without prior written
|
||||
* permission of the GmSSL Project.
|
||||
*
|
||||
* 6. Redistributions of any form whatsoever must retain the following
|
||||
* acknowledgment:
|
||||
* "This product includes software developed by the GmSSL Project
|
||||
* (http://gmssl.org/)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
|
||||
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include "kdf.h"
|
||||
|
||||
|
||||
#ifdef CPU_BIGENDIAN
|
||||
#define cpu_to_be16(v) (v)
|
||||
#define cpu_to_be32(v) (v)
|
||||
#else
|
||||
#define cpu_to_be16(v) ((v << 8) | (v >> 8))
|
||||
#define cpu_to_be32(v) ((cpu_to_be16(v) << 16) | cpu_to_be16(v >> 16))
|
||||
#endif
|
||||
|
||||
static void *x963_kdf(const EVP_MD *md, const void *in, size_t inlen,
|
||||
void *out, size_t *outlen)
|
||||
{
|
||||
EVP_MD_CTX ctx;
|
||||
uint32_t counter = 1;
|
||||
uint32_t counter_be;
|
||||
unsigned char dgst[EVP_MAX_MD_SIZE];
|
||||
unsigned int dgstlen;
|
||||
size_t rlen = *outlen;
|
||||
size_t len;
|
||||
|
||||
EVP_MD_CTX_init(&ctx);
|
||||
|
||||
//FIXME: it might be wrong
|
||||
while (rlen > 0) {
|
||||
counter_be = cpu_to_be32(counter);
|
||||
counter++;
|
||||
|
||||
EVP_DigestInit(&ctx, md);
|
||||
EVP_DigestUpdate(&ctx, in, inlen);
|
||||
EVP_DigestUpdate(&ctx, &counter_be, sizeof(counter_be));
|
||||
EVP_DigestFinal(&ctx, dgst, &dgstlen);
|
||||
|
||||
len = dgstlen <= rlen ? dgstlen : rlen;
|
||||
memcpy(out, dgst, len);
|
||||
rlen -= len;
|
||||
out += len;
|
||||
}
|
||||
|
||||
EVP_MD_CTX_cleanup(&ctx);
|
||||
return out;
|
||||
}
|
||||
|
||||
static void *x963_md5kdf(const void *in, size_t inlen,
|
||||
void *out, size_t *outlen)
|
||||
{
|
||||
return x963_kdf(EVP_md5(), in, inlen, out, outlen);
|
||||
}
|
||||
|
||||
static void *x963_rmd160kdf(const void *in, size_t inlen,
|
||||
void *out, size_t *outlen)
|
||||
{
|
||||
return x963_kdf(EVP_ripemd160(), in, inlen, out, outlen);
|
||||
}
|
||||
|
||||
static void *x963_sha1kdf(const void *in, size_t inlen,
|
||||
void *out, size_t *outlen)
|
||||
{
|
||||
return x963_kdf(EVP_sha1(), in, inlen, out, outlen);
|
||||
}
|
||||
|
||||
static void *x963_sha224kdf(const void *in, size_t inlen,
|
||||
void *out, size_t *outlen)
|
||||
{
|
||||
return x963_kdf(EVP_sha224(), in, inlen, out, outlen);
|
||||
}
|
||||
|
||||
static void *x963_sha256kdf(const void *in, size_t inlen,
|
||||
void *out, size_t *outlen)
|
||||
{
|
||||
return x963_kdf(EVP_sha256(), in, inlen, out, *outlen);
|
||||
}
|
||||
|
||||
static void *x963_sha384kdf(const void *in, size_t inlen,
|
||||
void *out, size_t *outlen)
|
||||
{
|
||||
return x963_kdf(EVP_sha384(), in, inlen, out, outlen);
|
||||
}
|
||||
|
||||
static void *x963_sha512kdf(const void *in, size_t inlen,
|
||||
void *out, size_t *outlen)
|
||||
{
|
||||
return x963_kdf(EVP_sha512(), in, inlen, out, outlen);
|
||||
}
|
||||
|
||||
static void *x963_sm3kdf(const void *in, size_t inlen,
|
||||
void *out, size_t *outlen)
|
||||
{
|
||||
return x963_kdf(EVP_sm3(), in, inlen, out, outlen);
|
||||
}
|
||||
|
||||
//FIXME: whirlpool
|
||||
|
||||
KDF_FUNC KDF_get_x9_63(const EVP_MD *md)
|
||||
{
|
||||
if (md == EVP_md5())
|
||||
return x963_md5kdf;
|
||||
else if (md == EVP_ripemd160())
|
||||
return x963_rmd160kdf;
|
||||
else if (md == EVP_sha1())
|
||||
return x963_sha1kdf;
|
||||
else if (md == EVP_sha224())
|
||||
return x963_sha224kdf;
|
||||
else if (md == EVP_sha256())
|
||||
return x963_sha256kdf;
|
||||
else if (md == EVP_sha384())
|
||||
return x963_sha384kdf;
|
||||
else if (md == EVP_sha512())
|
||||
return x963_sha512kdf;
|
||||
else if (md == EVP_sm3())
|
||||
return x963_sm3kdf;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <openssl/kdf.h>
|
||||
#include <openssl/rand.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
KDF_FUNC kdf = KDF_get_x9_63(EVP_sm3());
|
||||
unsigned char buf[1024];
|
||||
unsigned char key[128];
|
||||
size_t keylen = 12;
|
||||
int i;
|
||||
|
||||
memset(buf, 0x32, sizeof(buf));
|
||||
kdf(buf, sizeof(buf), key, &keylen);
|
||||
|
||||
for (i = 0; i < keylen; i++) {
|
||||
printf("%02x", key[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user