123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- #include "sgx_ecc256_common.h"
- IppStatus sgx_ipp_newBN(const Ipp32u *p_data, int size_in_bytes, IppsBigNumState **p_new_BN)
- {
- IppsBigNumState *pBN = 0;
- int bn_size = 0;
- if (p_new_BN == NULL || (size_in_bytes <= 0) || ((size_in_bytes % sizeof(Ipp32u)) != 0))
- return ippStsBadArgErr;
-
- IppStatus error_code = ippsBigNumGetSize(size_in_bytes/(int)sizeof(Ipp32u), &bn_size);
- if (error_code != ippStsNoErr)
- {
- *p_new_BN = 0;
- return error_code;
- }
- pBN = (IppsBigNumState *)malloc(bn_size);
- if (!pBN)
- {
- error_code = ippStsMemAllocErr;
- *p_new_BN = 0;
- return error_code;
- }
-
- error_code = ippsBigNumInit(size_in_bytes/(int)sizeof(Ipp32u), pBN);
- if (error_code != ippStsNoErr)
- {
- free(pBN);
- *p_new_BN = 0;
- return error_code;
- }
- if (p_data)
- {
- error_code = ippsSet_BN(IppsBigNumPOS, size_in_bytes/(int)sizeof(Ipp32u), p_data, pBN);
- if (error_code != ippStsNoErr)
- {
- *p_new_BN = 0;
- free(pBN);
- return error_code;
- }
- }
- *p_new_BN = pBN;
- return error_code;
- }
- void sgx_ipp_secure_free_BN(IppsBigNumState *pBN, int size_in_bytes)
- {
- if (pBN == NULL || size_in_bytes <= 0 || ((size_in_bytes % sizeof(Ipp32u)) != 0))
- {
- if (pBN)
- {
- free(pBN);
- }
- return;
- }
- int bn_size = 0;
-
-
- IppStatus error_code = ippsBigNumGetSize(size_in_bytes/(int)sizeof(Ipp32u), &bn_size);
- if (error_code != ippStsNoErr)
- {
- free(pBN);
- return;
- }
-
- memset_s(pBN, bn_size, 0, bn_size);
- free(pBN);
- return;
- }
- IppStatus __STDCALL sgx_ipp_DRNGen(Ipp32u* pRandBNU, int nBits, void* pCtx)
- {
- sgx_status_t sgx_ret;
- UNUSED(pCtx);
- if (0 != nBits % 8)
- {
-
- return ippStsSizeErr;
- }
- if (!pRandBNU)
- {
- return ippStsNullPtrErr;
- }
- sgx_ret = sgx_read_rand((uint8_t*)pRandBNU, (uint32_t)nBits / 8);
- if (SGX_SUCCESS != sgx_ret)
- {
- return ippStsErr;
- }
- return ippStsNoErr;
- }
|