add ecies

ECIES share the same err num with EC
This commit is contained in:
Zhi Guan
2017-02-15 00:03:52 +08:00
parent 9d485003bd
commit 83321f9755
14 changed files with 1440 additions and 96 deletions

View File

@@ -1368,6 +1368,7 @@ int ERR_load_EC_strings(void);
/* Function codes. */
# define EC_F_BN_TO_FELEM 224
# define EC_F_D2I_ECIESPARAMETERS 270
# define EC_F_D2I_ECPARAMETERS 144
# define EC_F_D2I_ECPKPARAMETERS 145
# define EC_F_D2I_ECPRIVATEKEY 146
@@ -1382,6 +1383,14 @@ int ERR_load_EC_strings(void);
# define EC_F_ECDSA_SIGN_SETUP 248
# define EC_F_ECDSA_SIG_NEW 265
# define EC_F_ECDSA_VERIFY 253
# define EC_F_ECIES_DECRYPT 271
# define EC_F_ECIES_DO_DECRYPT 272
# define EC_F_ECIES_DO_ENCRYPT 273
# define EC_F_ECIES_ENCRYPT 274
# define EC_F_ECIES_PARAMS_GET_ENC 275
# define EC_F_ECIES_PARAMS_GET_KDF 276
# define EC_F_ECIES_PARAMS_GET_MAC 277
# define EC_F_ECIES_PARAMS_INIT_WITH_RECOMMENDED 278
# define EC_F_ECKEY_PARAM2TYPE 223
# define EC_F_ECKEY_PARAM_DECODE 212
# define EC_F_ECKEY_PRIV_DECODE 213
@@ -1493,6 +1502,7 @@ int ERR_load_EC_strings(void);
# define EC_F_EC_PRE_COMP_NEW 196
# define EC_F_EC_WNAF_MUL 187
# define EC_F_EC_WNAF_PRECOMPUTE_MULT 188
# define EC_F_I2D_ECIESPARAMETERS 279
# define EC_F_I2D_ECPARAMETERS 190
# define EC_F_I2D_ECPKPARAMETERS 191
# define EC_F_I2D_ECPRIVATEKEY 192
@@ -1518,16 +1528,27 @@ int ERR_load_EC_strings(void);
# define EC_R_BAD_SIGNATURE 156
# define EC_R_BIGNUM_OUT_OF_RANGE 144
# define EC_R_BUFFER_TOO_SMALL 100
# define EC_R_CMAC_FINAL_FAILURE 136
# define EC_R_CMAC_INIT_FAILURE 153
# define EC_R_CMAC_UPDATE_FAILURE 162
# define EC_R_COORDINATES_OUT_OF_RANGE 146
# define EC_R_CURVE_DOES_NOT_SUPPORT_ECDH 160
# define EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING 159
# define EC_R_D2I_ECPKPARAMETERS_FAILURE 117
# define EC_R_DECODE_ERROR 142
# define EC_R_DECRYPT_FAILED 163
# define EC_R_DISCRIMINANT_IS_ZERO 118
# define EC_R_ECDH_FAILED 164
# define EC_R_ECDH_FAILURE 165
# define EC_R_ECIES_DECRYPT_INIT_FAILURE 166
# define EC_R_ECIES_VERIFY_MAC_FAILURE 167
# define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE 119
# define EC_R_ENCRYPT_FAILED 168
# define EC_R_FIELD_TOO_LARGE 143
# define EC_R_GEN_MAC_FAILED 169
# define EC_R_GF2M_NOT_SUPPORTED 147
# define EC_R_GROUP2PKPARAMETERS_FAILURE 120
# define EC_R_HMAC_FAILURE 170
# define EC_R_I2D_ECPKPARAMETERS_FAILURE 121
# define EC_R_INCOMPATIBLE_OBJECTS 101
# define EC_R_INVALID_ARGUMENT 112
@@ -1536,6 +1557,8 @@ int ERR_load_EC_strings(void);
# define EC_R_INVALID_CURVE 141
# define EC_R_INVALID_DIGEST 151
# define EC_R_INVALID_DIGEST_TYPE 138
# define EC_R_INVALID_ECIES_CIPHERTEXT 171
# define EC_R_INVALID_ECIES_PARAMETERS 172
# define EC_R_INVALID_ENCODING 102
# define EC_R_INVALID_FIELD 103
# define EC_R_INVALID_FORM 104

165
include/openssl/ecies.h Normal file
View File

@@ -0,0 +1,165 @@
/* ====================================================================
* Copyright (c) 2007 - 2017 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.
* ====================================================================
*/
/*
* Ellitpic Curve Integrated Encryption Scheme (ECIES)
* see http://www.secg.org/sec1-v2.pdf (section 5)
* SEC1: Elliptic Curve Cryptography version 2.0
*/
#ifndef HEADER_ECIES_H
#define HEADER_ECIES_H
#include <openssl/ec.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/x509.h>
#include <openssl/asn1.h>
#include <openssl/kdf2.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
ECIESAlgorithmSet ALGORITHM ::= {
{OID ecies-recommendedParameters} |
{OID ecies-specifiedParameters PARMS ECIESParameters},
... -- Future combinations may be added
}
*/
typedef struct ecies_params_st {
/*
KDFSet ALGORITHM ::= {
{ OID x9-63-kdf PARMS HashAlgorithm } |
{ OID nist-concatenation-kdf PARMS HashAlgorithm } |
{ OID tls-kdf PARMS HashAlgorithm } |
{ OID ikev2-kdf PARMS HashAlgorithm }
... -- Future combinations may be added
}
*/
int kdf_nid;
const EVP_MD *kdf_md;
/*
SYMENCSet ALGORITHM ::= {
{ OID xor-in-ecies } |
{ OID tdes-cbc-in-ecies } |
{ OID aes128-cbc-in-ecies } |
{ OID aes192-cbc-in-ecies } |
{ OID aes256-cbc-in-ecies } |
{ OID aes128-ctr-in-ecies } |
{ OID aes192-ctr-in-ecies } |
{ OID aes256-ctr-in-ecies } ,
... -- Future combinations may be added
}
*/
int enc_nid;
/*
MACSet ALGORITHM ::= {
{ OID hmac-full-ecies PARMS HashAlgorithm} |
{ OID hmac-half-ecies PARMS HashAlgorithm} |
{ OID cmac-aes128-ecies } |
{ OID cmac-aes192-ecies } |
{ OID cmac-aes256-ecies } ,
... -- Future combinations may be added
}
*/
int mac_nid;
const EVP_MD *hmac_md;
} ECIES_PARAMS;
ECIES_PARAMS *ECIES_PARAMS_new(void);
int ECIES_PARAMS_init_with_recommended(ECIES_PARAMS *param);
ECIES_PARAMS *ECIES_PARAMS_dup(const ECIES_PARAMS *param);
KDF_FUNC ECIES_PARAMS_get_kdf(const ECIES_PARAMS *param);
int ECIES_PARAMS_get_enc(const ECIES_PARAMS *param, size_t inlen,
const EVP_CIPHER **enc_cipher, size_t *enckeylen, size_t *ciphertextlen);
int ECIES_PARAMS_get_mac(const ECIES_PARAMS *param,
const EVP_MD **hmac_md, const EVP_CIPHER **cmac_cipher,
unsigned int *mackeylen, unsigned int *maclen);
void ECIES_PARAMS_free(ECIES_PARAMS *param);
int i2d_ECIESParameters(const ECIES_PARAMS *param, unsigned char **out);
ECIES_PARAMS *d2i_ECIESParameters(ECIES_PARAMS **param,
const unsigned char **in, long len);
typedef struct ecies_ciphertext_value_st {
ASN1_OCTET_STRING *ephem_point;
ASN1_OCTET_STRING *ciphertext;
ASN1_OCTET_STRING *mactag;
} ECIES_CIPHERTEXT_VALUE;
DECLARE_ASN1_FUNCTIONS(ECIES_CIPHERTEXT_VALUE)
ECIES_CIPHERTEXT_VALUE *ECIES_do_encrypt(const ECIES_PARAMS *param,
const unsigned char *in, size_t inlen, EC_KEY *ec_key);
int ECIES_do_decrypt(const ECIES_PARAMS *param, const ECIES_CIPHERTEXT_VALUE *in,
unsigned char *out, size_t *outlen, EC_KEY *ec_key);
int ECIES_encrypt(const ECIES_PARAMS *param,
const unsigned char *in, size_t inlen,
unsigned char *out, size_t *outlen, EC_KEY *ec_key);
int ECIES_decrypt(const ECIES_PARAMS *param,
const unsigned char *in, size_t inlen,
unsigned char *out, size_t *outlen, EC_KEY *ec_key);
int ECIES_encrypt_with_recommended(const unsigned char *in, size_t inlen,
unsigned char *out, size_t *outlen, EC_KEY *ec_key);
int ECIES_decrypt_with_recommended(const unsigned char *in, size_t inlen,
unsigned char *out, size_t *outlen, EC_KEY *ec_key);
#ifdef __cplusplus
}
#endif
#endif