Fix SDF vendor feature

This commit is contained in:
Zhi Guan
2018-01-26 23:56:18 +08:00
parent 342603d169
commit 25d4ff1afb
4 changed files with 70 additions and 31 deletions

View File

@@ -577,7 +577,7 @@ int SDF_GenerateKeyPair_ECC(
} }
if (sdf_vendor) { if (sdf_vendor) {
if (!(uiAlgID = sdf_vendor->get_pkey_algor(uiAlgID))) { if (!(uiAlgID = sdf_vendor->pkey_std2vendor(uiAlgID))) {
SDFerr(SDF_F_SDF_GENERATEKEYPAIR_ECC, SDFerr(SDF_F_SDF_GENERATEKEYPAIR_ECC,
SDF_R_NOT_SUPPORTED_ECC_ALGOR); SDF_R_NOT_SUPPORTED_ECC_ALGOR);
return SDR_ALGNOTSUPPORT; return SDR_ALGNOTSUPPORT;
@@ -641,7 +641,7 @@ int SDF_GenerateKeyWithEPK_ECC(
} }
if (sdf_vendor) { if (sdf_vendor) {
if (!(uiAlgID = sdf_vendor->get_cipher_algor(uiAlgID))) { if (!(uiAlgID = sdf_vendor->cipher_std2vendor(uiAlgID))) {
SDFerr(SDF_F_SDF_GENERATEKEYWITHEPK_ECC, SDFerr(SDF_F_SDF_GENERATEKEYWITHEPK_ECC,
SDF_R_NOT_SUPPORTED_CIPHER_ALGOR); SDF_R_NOT_SUPPORTED_CIPHER_ALGOR);
return SDR_ALGNOTSUPPORT; return SDR_ALGNOTSUPPORT;
@@ -816,7 +816,7 @@ int SDF_ExchangeDigitEnvelopeBaseOnECC(
} }
if (sdf_vendor) { if (sdf_vendor) {
if (!(uiAlgID = sdf_vendor->get_cipher_algor(uiAlgID))) { if (!(uiAlgID = sdf_vendor->cipher_std2vendor(uiAlgID))) {
SDFerr(SDF_F_SDF_EXCHANGEDIGITENVELOPEBASEONECC, SDFerr(SDF_F_SDF_EXCHANGEDIGITENVELOPEBASEONECC,
SDF_R_NOT_SUPPORTED_CIPHER_ALGOR); SDF_R_NOT_SUPPORTED_CIPHER_ALGOR);
return SDR_ALGNOTSUPPORT; return SDR_ALGNOTSUPPORT;
@@ -856,7 +856,7 @@ int SDF_GenerateKeyWithKEK(
} }
if (sdf_vendor) { if (sdf_vendor) {
if (!(uiAlgID = sdf_vendor->get_cipher_algor(uiAlgID))) { if (!(uiAlgID = sdf_vendor->cipher_std2vendor(uiAlgID))) {
SDFerr(SDF_F_SDF_GENERATEKEYWITHKEK, SDFerr(SDF_F_SDF_GENERATEKEYWITHKEK,
SDF_R_NOT_SUPPORTED_CIPHER_ALGOR); SDF_R_NOT_SUPPORTED_CIPHER_ALGOR);
return SDR_ALGNOTSUPPORT; return SDR_ALGNOTSUPPORT;
@@ -895,7 +895,7 @@ int SDF_ImportKeyWithKEK(
} }
if (sdf_vendor) { if (sdf_vendor) {
if (!(uiAlgID = sdf_vendor->get_cipher_algor(uiAlgID))) { if (!(uiAlgID = sdf_vendor->cipher_std2vendor(uiAlgID))) {
SDFerr(SDF_F_SDF_IMPORTKEYWITHKEK, SDFerr(SDF_F_SDF_IMPORTKEYWITHKEK,
SDF_R_NOT_SUPPORTED_CIPHER_ALGOR); SDF_R_NOT_SUPPORTED_CIPHER_ALGOR);
return SDR_ALGNOTSUPPORT; return SDR_ALGNOTSUPPORT;
@@ -1046,7 +1046,7 @@ int SDF_ExternalVerify_ECC(
} }
if (sdf_vendor) { if (sdf_vendor) {
if (!(uiAlgID = sdf_vendor->get_pkey_algor(uiAlgID))) { if (!(uiAlgID = sdf_vendor->pkey_std2vendor(uiAlgID))) {
SDFerr(SDF_F_SDF_EXTERNALVERIFY_ECC, SDFerr(SDF_F_SDF_EXTERNALVERIFY_ECC,
SDF_R_NOT_SUPPORTED_PKEY_ALGOR); SDF_R_NOT_SUPPORTED_PKEY_ALGOR);
return SDR_ALGNOTSUPPORT; return SDR_ALGNOTSUPPORT;
@@ -1140,7 +1140,7 @@ int SDF_ExternalEncrypt_ECC(
} }
if (sdf_vendor) { if (sdf_vendor) {
if (!(uiAlgID = sdf_vendor->get_pkey_algor(uiAlgID))) { if (!(uiAlgID = sdf_vendor->pkey_std2vendor(uiAlgID))) {
SDFerr(SDF_F_SDF_EXTERNALENCRYPT_ECC, SDFerr(SDF_F_SDF_EXTERNALENCRYPT_ECC,
SDF_R_NOT_SUPPORTED_PKEY_ALGOR); SDF_R_NOT_SUPPORTED_PKEY_ALGOR);
return SDR_ALGNOTSUPPORT; return SDR_ALGNOTSUPPORT;
@@ -1210,7 +1210,7 @@ int SDF_Encrypt(
} }
if (sdf_vendor) { if (sdf_vendor) {
if (!(uiAlgID = sdf_vendor->get_cipher_algor(uiAlgID))) { if (!(uiAlgID = sdf_vendor->cipher_std2vendor(uiAlgID))) {
SDFerr(SDF_F_SDF_ENCRYPT, SDFerr(SDF_F_SDF_ENCRYPT,
SDF_R_NOT_SUPPORTED_CIPHER_ALGOR); SDF_R_NOT_SUPPORTED_CIPHER_ALGOR);
return SDR_ALGNOTSUPPORT; return SDR_ALGNOTSUPPORT;
@@ -1251,7 +1251,7 @@ int SDF_Decrypt(
} }
if (sdf_vendor) { if (sdf_vendor) {
if (!(uiAlgID = sdf_vendor->get_cipher_algor(uiAlgID))) { if (!(uiAlgID = sdf_vendor->cipher_std2vendor(uiAlgID))) {
SDFerr(SDF_F_SDF_DECRYPT, SDF_R_NOT_SUPPORTED_CIPHER_ALGOR); SDFerr(SDF_F_SDF_DECRYPT, SDF_R_NOT_SUPPORTED_CIPHER_ALGOR);
return SDR_ALGNOTSUPPORT; return SDR_ALGNOTSUPPORT;
} }
@@ -1291,7 +1291,7 @@ int SDF_CalculateMAC(
} }
if (sdf_vendor) { if (sdf_vendor) {
if (!(uiAlgID = sdf_vendor->get_cipher_algor(uiAlgID))) { if (!(uiAlgID = sdf_vendor->cipher_std2vendor(uiAlgID))) {
SDFerr(SDF_F_SDF_CALCULATEMAC, SDFerr(SDF_F_SDF_CALCULATEMAC,
SDF_R_NOT_SUPPORTED_CIPHER_ALGOR); SDF_R_NOT_SUPPORTED_CIPHER_ALGOR);
return SDR_ALGNOTSUPPORT; return SDR_ALGNOTSUPPORT;
@@ -1329,7 +1329,7 @@ int SDF_HashInit(
} }
if (sdf_vendor) { if (sdf_vendor) {
if (!(uiAlgID = sdf_vendor->get_digest_algor(uiAlgID))) { if (!(uiAlgID = sdf_vendor->digest_std2vendor(uiAlgID))) {
SDFerr(SDF_F_SDF_HASHINIT, SDF_R_NOT_SUPPORTED_DIGEST_ALGOR); SDFerr(SDF_F_SDF_HASHINIT, SDF_R_NOT_SUPPORTED_DIGEST_ALGOR);
return SDR_ALGNOTSUPPORT; return SDR_ALGNOTSUPPORT;
} }

View File

@@ -97,7 +97,7 @@ static SDF_ALGOR_PAIR sansec_ciphers[] = {
{ 0, SANSEC_3DES_MAC }, { 0, SANSEC_3DES_MAC },
}; };
static unsigned int sansec_get_cipher_algor(unsigned int vendor_id) static unsigned int sansec_cipher_vendor2std(unsigned int vendor_id)
{ {
int i; int i;
for (i = 0; i < OSSL_NELEM(sansec_ciphers); i++) { for (i = 0; i < OSSL_NELEM(sansec_ciphers); i++) {
@@ -108,7 +108,18 @@ static unsigned int sansec_get_cipher_algor(unsigned int vendor_id)
return 0; return 0;
} }
static unsigned int sansec_get_cipher_cap(unsigned int vendor_cap) static unsigned int sansec_cipher_std2vendor(unsigned int std_id)
{
int i;
for (i = 0; i < OSSL_NELEM(sansec_ciphers); i++) {
if (std_id == sansec_ciphers[i].std_id) {
return sansec_ciphers[i].vendor_id;
}
}
return 0;
}
static unsigned int sansec_cipher_cap(unsigned int vendor_cap)
{ {
unsigned int std_cap = 0; unsigned int std_cap = 0;
int i; int i;
@@ -132,7 +143,7 @@ static SDF_ALGOR_PAIR sansec_digests[] = {
{ 0, SANSEC_MD5 }, { 0, SANSEC_MD5 },
}; };
static unsigned int sansec_get_digest_algor(unsigned int vendor_id) static unsigned int sansec_digest_vendor2std(unsigned int vendor_id)
{ {
int i; int i;
for (i = 0; i < OSSL_NELEM(sansec_digests); i++) { for (i = 0; i < OSSL_NELEM(sansec_digests); i++) {
@@ -143,7 +154,18 @@ static unsigned int sansec_get_digest_algor(unsigned int vendor_id)
return 0; return 0;
} }
static unsigned int sansec_get_digest_cap(unsigned int vendor_cap) static unsigned int sansec_digest_std2vendor(unsigned int std_id)
{
int i;
for (i = 0; i < OSSL_NELEM(sansec_digests); i++) {
if (std_id == sansec_digests[i].std_id) {
return sansec_digests[i].vendor_id;
}
}
return 0;
}
static unsigned int sansec_digest_cap(unsigned int vendor_cap)
{ {
unsigned int std_cap = 0; unsigned int std_cap = 0;
int i; int i;
@@ -167,7 +189,7 @@ static SDF_ALGOR_PAIR sansec_pkeys[] = {
{ SGD_SM2_3,SANSEC_SM2_3 }, { SGD_SM2_3,SANSEC_SM2_3 },
}; };
static unsigned int sansec_get_pkey_algor(unsigned int vendor_id) static unsigned int sansec_pkey_vendor2std(unsigned int vendor_id)
{ {
int i; int i;
for (i = 0; i < OSSL_NELEM(sansec_pkeys); i++) { for (i = 0; i < OSSL_NELEM(sansec_pkeys); i++) {
@@ -178,7 +200,18 @@ static unsigned int sansec_get_pkey_algor(unsigned int vendor_id)
return 0; return 0;
} }
static unsigned int sansec_get_pkey_cap(unsigned int vendor_cap) static unsigned int sansec_pkey_std2vendor(unsigned int std_id)
{
int i;
for (i = 0; i < OSSL_NELEM(sansec_pkeys); i++) {
if (std_id == sansec_pkeys[i].std_id) {
return sansec_pkeys[i].vendor_id;
}
}
return 0;
}
static unsigned int sansec_pkey_cap(unsigned int vendor_cap)
{ {
unsigned int std_cap = 0; unsigned int std_cap = 0;
int i; int i;
@@ -318,12 +351,15 @@ static unsigned long sansec_get_error_reason(int err)
SDF_VENDOR sdf_sansec = { SDF_VENDOR sdf_sansec = {
"sansec", "sansec",
sansec_get_cipher_algor, sansec_cipher_vendor2std,
sansec_get_cipher_cap, sansec_cipher_std2vendor,
sansec_get_digest_algor, sansec_cipher_cap,
sansec_get_digest_cap, sansec_digest_vendor2std,
sansec_get_pkey_algor, sansec_digest_std2vendor,
sansec_get_pkey_cap, sansec_digest_cap,
sansec_pkey_vendor2std,
sansec_pkey_std2vendor,
sansec_pkey_cap,
sansec_encode_ecccipher, sansec_encode_ecccipher,
sansec_decode_ecccipher, sansec_decode_ecccipher,
sansec_get_error_reason, sansec_get_error_reason,

View File

@@ -445,12 +445,15 @@ void SDF_METHOD_free(SDF_METHOD *meth);
typedef struct sdf_vendor_st { typedef struct sdf_vendor_st {
char *name; char *name;
unsigned int (*get_cipher_algor)(unsigned int vendor_id); unsigned int (*cipher_vendor2std)(unsigned int vendor_id);
unsigned int (*get_digest_algor)(unsigned int vendor_id); unsigned int (*cipher_std2vendor)(unsigned int std_id);
unsigned int (*get_pkey_algor)(unsigned int vendor_id); unsigned int (*cipher_cap)(unsigned int vendor_cap);
unsigned int (*get_cipher_cap)(unsigned int vendor_cap); unsigned int (*digest_vendor2std)(unsigned int vendor_id);
unsigned int (*get_digest_cap)(unsigned int vendor_cap); unsigned int (*digest_std2vendor)(unsigned int std_id);
unsigned int (*get_pkey_cap)(unsigned int vendor_cap); unsigned int (*digest_cap)(unsigned int vendor_cap);
unsigned int (*pkey_vendor2std)(unsigned int vendor_id);
unsigned int (*pkey_std2vendor)(unsigned int std_id);
unsigned int (*pkey_cap)(unsigned int vendor_cap);
int (*encode_ecccipher)(const ECCCipher *a, void *buf); int (*encode_ecccipher)(const ECCCipher *a, void *buf);
int (*decode_ecccipher)(ECCCipher *a, const void *buf); int (*decode_ecccipher)(ECCCipher *a, const void *buf);
unsigned long (*get_error_reason)(int err); unsigned long (*get_error_reason)(int err);

View File

@@ -41,9 +41,9 @@ extern "C" {
*/ */
# define OPENSSL_VERSION_NUMBER 0x1010004fL # define OPENSSL_VERSION_NUMBER 0x1010004fL
# ifdef OPENSSL_FIPS # ifdef OPENSSL_FIPS
# define OPENSSL_VERSION_TEXT "GmSSL 2.1.0 - OpenSSL 1.1.0d-fips 07 Jan 2018" # define OPENSSL_VERSION_TEXT "GmSSL 2.1.1 - OpenSSL 1.1.0d-fips 26 Jan 2018"
# else # else
# define OPENSSL_VERSION_TEXT "GmSSL 2.1.0 - OpenSSL 1.1.0d 07 Jan 2018" # define OPENSSL_VERSION_TEXT "GmSSL 2.1.1 - OpenSSL 1.1.0d 26 Jan 2018"
# endif # endif
/*- /*-