first step of v2 final release

This commit is contained in:
Zhi Guan
2017-11-05 21:00:36 +08:00
parent 480b9e8d88
commit 27bde477a5
395 changed files with 26341 additions and 31364 deletions

View File

@@ -65,6 +65,8 @@ int SAF_GenEccKeyPair(
{
int ret = -1;
SAF_APP *app = (SAF_APP *)hAppHandle;
EVP_PKEY_CTX *pctx = NULL;
EVP_PKEY *pkey = NULL;
/* check arguments */
if (!hAppHandle || !pucContainerName) {
@@ -91,8 +93,6 @@ int SAF_GenEccKeyPair(
}
/* process */
EVP_PKEY_CTX *pctx = NULL;
EVP_PKEY *pkey = NULL;
if (!(pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, app->engine))
|| EVP_PKEY_keygen_init(pctx) <= 0
@@ -132,6 +132,9 @@ int SAF_GetEccPublicKey(
{
int ret = SAR_UnknownErr;
SAF_APP *app = (SAF_APP *)hAppHandle;
EVP_PKEY *pkey = NULL;
char key_id[1024];
int len;
/* check arguments */
if (!hAppHandle || !pucContainerName || !pucPublicKey ||
@@ -160,9 +163,6 @@ int SAF_GetEccPublicKey(
}
/* process */
EVP_PKEY *pkey = NULL;
char key_id[1024];
int len;
/*
@@ -202,6 +202,10 @@ int SAF_EccSign(
{
int ret = SAR_UnknownErr;
SAF_APP *app = (SAF_APP *)hAppHandle;
char key_id[1024];
EVP_PKEY *pkey = NULL;
EVP_PKEY_CTX *pctx = NULL;
size_t siglen;
/* check arguments */
if (!hAppHandle || !pucContainerName || !pucInData ||
@@ -230,10 +234,6 @@ int SAF_EccSign(
}
/* process */
char key_id[1024];
EVP_PKEY *pkey = NULL;
EVP_PKEY_CTX *pctx = NULL;
size_t siglen;
/*
snprintf(key_id, sizeof(key_id), "%s.sign", (char *)pucContainerName);
@@ -267,6 +267,8 @@ int SAF_EccVerifySign(
unsigned int uiSignDataLen)
{
int ret = SAR_UnknownErr;
EVP_PKEY *pkey = NULL;
EVP_PKEY_CTX *pctx = NULL;
/* check arguments */
if (!pucPublicKey || !pucInData || !pucSignData) {
@@ -291,8 +293,6 @@ int SAF_EccVerifySign(
}
/* process */
EVP_PKEY *pkey = NULL;
EVP_PKEY_CTX *pctx = NULL;
if (!(pkey = d2i_PUBKEY(NULL, (const unsigned char **)&pucPublicKey, (long)uiPublicKeyLen))
|| !(pctx = EVP_PKEY_CTX_new(pkey, NULL))
@@ -320,6 +320,9 @@ int SAF_EccPublicKeyEnc(
unsigned int *puiOutDataLen)
{
int ret = -1;
EVP_PKEY *pkey = NULL;
EVP_PKEY_CTX *pctx = NULL;
size_t outlen = *puiOutDataLen;
/* check arguments */
if (!pucPublicKey || !pucInData || !pucOutData || !puiOutDataLen) {
@@ -337,7 +340,7 @@ int SAF_EccPublicKeyEnc(
SAF_R_INVALID_ALGOR);
return SAR_AlgoTypeErr;
}
if (uiInDataLen <= 0 || uiInDataLen > ECCref_MAX_CIPHER_LEN) {
if (uiInDataLen <= 0 || uiInDataLen > SAF_MAX_EC_CIPHERTEXT_LENGTH) {
SAFerr(SAF_F_SAF_ECCPUBLICKEYENC,
SAF_R_INVALID_INPUT_LENGTH);
return SAR_IndataLenErr;
@@ -349,9 +352,6 @@ int SAF_EccPublicKeyEnc(
}
/* precess */
EVP_PKEY *pkey = NULL;
EVP_PKEY_CTX *pctx = NULL;
size_t outlen = *puiOutDataLen;
if (!(pkey = d2i_PUBKEY(NULL, (const unsigned char **)&pucPublicKey, (long)uiPublicKeyLen))
|| !(pctx = EVP_PKEY_CTX_new(pkey, NULL))
@@ -381,6 +381,10 @@ int SAF_EccPublicKeyEncByCert(
unsigned int *puiOutDataLen)
{
int ret = SAR_UnknownErr;
X509 *x509 = NULL;
unsigned char pubkey[1024];
unsigned char *p = pubkey;
int len;
/* check arguments */
if (!pucCertificate || !pucInData || !pucOutData || !puiOutDataLen) {
@@ -398,7 +402,7 @@ int SAF_EccPublicKeyEncByCert(
SAF_R_INVALID_ALGOR);
return SAR_AlgoTypeErr;
}
if (uiInDataLen <= 0 || uiInDataLen > ECCref_MAX_CIPHER_LEN) {
if (uiInDataLen <= 0 || uiInDataLen > SAF_MAX_EC_CIPHERTEXT_LENGTH) {
SAFerr(SAF_F_SAF_ECCPUBLICKEYENCBYCERT,
SAF_R_INVALID_INPUT_LENGTH);
return SAR_IndataLenErr;
@@ -410,10 +414,6 @@ int SAF_EccPublicKeyEncByCert(
}
/* process */
X509 *x509 = NULL;
unsigned char pubkey[1024];
unsigned char *p = pubkey;
int len;
if (!(x509 = d2i_X509(NULL, (const unsigned char **)&pucCertificate, (long)uiCertificateLen))) {
SAFerr(SAF_F_SAF_ECCPUBLICKEYENCBYCERT, ERR_R_X509_LIB);
@@ -453,6 +453,11 @@ int SAF_EccVerifySignByCert(
unsigned int uiSignDataLen)
{
int ret = SAR_UnknownErr;
X509 *x509 = NULL;
unsigned char pucPublicKey[1024];
unsigned int uiPublicKeyLen;
unsigned char *p = pucPublicKey;
int len;
/* check arguments */
if (!pucCertificate || !pucInData || !pucSignData) {
@@ -482,11 +487,6 @@ int SAF_EccVerifySignByCert(
}
/* process */
X509 *x509 = NULL;
unsigned char pucPublicKey[1024];
unsigned int uiPublicKeyLen;
unsigned char *p = pucPublicKey;
int len;
if (!(x509 = d2i_X509(NULL, (const unsigned char **)&pucCertificate, (long)uiCertificateLen))) {
SAFerr(SAF_F_SAF_ECCVERIFYSIGNBYCERT, ERR_R_X509_LIB);

View File

@@ -78,7 +78,9 @@ int SAF_SymmEncryptUpdate(
if (!hkey->cipher_ctx) {
const EVP_CIPHER *cipher;
if (!(cipher = EVP_get_cipherbysgd(hkey->hSymmKeyObj->uiCryptoAlgID))) {
// FIXME: get ulFeedBitLen from key handle
if (!(cipher = EVP_get_cipherbysgd(hkey->hSymmKeyObj->uiCryptoAlgID, 0))) {
SAFerr(SAF_F_SAF_SYMMENCRYPTUPDATE, SAF_R_INVALID_KEY_HANDLE);
ret = SAR_IndataErr;
goto end;
@@ -172,7 +174,8 @@ int SAF_SymmDecryptUpdate(
if (!hkey->cipher_ctx) {
const EVP_CIPHER *cipher;
if (!(cipher = EVP_get_cipherbysgd(hkey->hSymmKeyObj->uiCryptoAlgID))) {
//Get feedbitlen from keyhandle
if (!(cipher = EVP_get_cipherbysgd(hkey->hSymmKeyObj->uiCryptoAlgID, 0))) {
SAFerr(SAF_F_SAF_SYMMDECRYPTUPDATE, SAF_R_INVALID_KEY_HANDLE);
ret = SAR_IndataErr;
goto end;

View File

@@ -85,7 +85,7 @@ int SAF_GenerateKeyWithEPK(
}
outlen = (size_t)*puiSymmKeyLen;
if (!(cipher = EVP_get_cipherbysgd(obj->uiCryptoAlgID))
if (!(cipher = EVP_get_cipherbysgd(obj->uiCryptoAlgID, 0)) //fixme: feedbitlen
|| !RAND_bytes(keybuf, EVP_CIPHER_key_length(cipher))
|| !(pkey = d2i_PUBKEY(NULL, (const unsigned char **)&pucPublicKey, (long)uiPublicKeyLen))
|| !(pkctx = EVP_PKEY_CTX_new(pkey, NULL))

View File

@@ -75,7 +75,8 @@ int SAF_MacUpdate(
if (!hkey->cmac_ctx) {
const EVP_CIPHER *cipher;
if (!(cipher = EVP_get_cipherbysgd(hkey->hSymmKeyObj->uiCryptoAlgID))) {
//Fixme: feedbitlen
if (!(cipher = EVP_get_cipherbysgd(hkey->hSymmKeyObj->uiCryptoAlgID, 0))) {
SAFerr(SAF_F_SAF_MACUPDATE, SAF_R_INVALID_KEY_HANDLE);
ret = SAR_IndataErr;
goto end;

View File

@@ -581,12 +581,15 @@ int SAF_Pkcs7_DecodeDigestedData(
p7dgst = p7->d.digest;
/* output digset algor */
//EVP_MD_sgd
#if 0
if ((*puiDigestAlgorithm = EVP_MD_sgd(
EVP_get_digestbyobj(p7dgst->md->algorithm))) <= 0) {
SAFerr(SAF_F_SAF_PKCS7_DECODEDIGESTEDDATA, SAF_R_UNSUPPORTED_DIGEST_ALGOR);
ret = SAR_IndataErr;
goto end;
}
#endif
/* output digested data */
if (!PKCS7_type_is_data(p7dgst->contents)) {