static void sample_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; // Get the size of the IppsBigNumState context in bytes // Since we have checked the size_in_bytes before and the &bn_size is not NULL, ippsBigNumGetSize never returns failure ippsBigNumGetSize(size_in_bytes/(int)sizeof(Ipp32u), &bn_size); if (bn_size <= 0) { free(pBN); return; } // Clear the buffer before free. memset_s(pBN, bn_size, 0, bn_size); free(pBN); return; }
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; // Get the size of the IppsBigNumState context in bytes // Since we have checked the size_in_bytes before and the &bn_size is not NULL, ippsBigNumGetSize never returns failure IppStatus error_code = ippsBigNumGetSize(size_in_bytes/(int)sizeof(Ipp32u), &bn_size); if (error_code != ippStsNoErr) { free(pBN); return; } // Clear the buffer before free. memset_s(pBN, bn_size, 0, bn_size); free(pBN); return; }
IppsBigNumState* bnNew(const char* sBN, const int size){ // get the size of the Big Number context int ctxSize; const int strSize = (const int)(strlen(sBN)+7)/8; if ( strSize > size ){ std::cerr << "Caution in IppsBigNumState* bnNew(const char* sBN, int size):\n\t size of string number representation greater then params size supplied\n"; std::cerr << sBN << std::endl; } IppStatus res; res = ippsBigNumGetSize(size, &ctxSize); if (res != ippStsNoErr ) std::cerr << res; // allocate the Big Number context IppsBigNumState* pBN = (IppsBigNumState*) ( new Ipp8u[ctxSize] ); // and initialize one res = ippsBigNumInit(size, pBN); if (res != ippStsNoErr ) std::cerr << res; Ipp8u* octetStr = new Ipp8u[(strlen(sBN)-1)/2+1+1]; strtoIpp8u( sBN, octetStr); res = ippsSetOctString_BN(octetStr, (int)(strlen(sBN)-1)/2+1, pBN); if (res != ippStsNoErr ) std::cerr << res; delete[] octetStr; // return pointer to the Big Number context for future use return pBN; }
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; // Get the size of the IppsBigNumState context in bytes 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; } // Initialize context and partition allocated buffer 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; }
IppsBigNumState* bnNew(const int size, const Ipp8u *pData){ // get the size of the Big Number context int ctxSize; IppStatus res; res = ippsBigNumGetSize(size, &ctxSize); if (res != ippStsNoErr ) std::cerr << res; // allocate the Big Number context IppsBigNumState* pBN = (IppsBigNumState*) ( new Ipp8u[ctxSize] ); // and initialize one res = ippsBigNumInit(size, pBN); if (res != ippStsNoErr ) std::cerr << res; res = ippsSetOctString_BN(pData, 4*size, pBN); if (res != ippStsNoErr ) std::cerr << res; // return pointer to the Big Number context for future use return pBN; }
extern "C" IppStatus newBN(const Ipp32u *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)) return ippStsBadArgErr; /* Get the size of the IppsBigNumState context in bytes */ 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; } /* Initializes context and partitions allocated buffer */ error_code = ippsBigNumInit(size_in_bytes / (int)sizeof(Ipp32u), pBN); if (error_code != ippStsNoErr) { SAFE_FREE_MM(pBN); *p_new_BN = 0; return error_code; } if (data) { error_code = ippsSet_BN(IppsBigNumPOS, size_in_bytes / (int)sizeof(Ipp32u), data, pBN); if (error_code != ippStsNoErr) { SAFE_FREE_MM(pBN); *p_new_BN = 0; return error_code; } } *p_new_BN = pBN; return error_code; }
IppsBigNumState* bnNew(const int size, const Ipp32u* pData){ // get the size of the Big Number context int ctxSize; IppStatus res; res = ippsBigNumGetSize(size, &ctxSize); if (res != ippStsNoErr ) std::cerr << res; // allocate the Big Number context IppsBigNumState* pBN = (IppsBigNumState*) ( new Ipp8u[ctxSize] ); // and initialize one res = ippsBigNumInit(size, pBN); if (res != ippStsNoErr ) std::cerr << res; // if any data was supplied, then set up the Big Number value if(pData){ res = ippsSet_BN(IppsBigNumPOS, size, pData, pBN); if (res != ippStsNoErr ) std::cerr << res; } // return pointer to the Big Number context for future use return pBN; }
extern "C" void secure_free_BN(IppsBigNumState *pBN, int size_in_bytes) { if (pBN == NULL || size_in_bytes <= 0 || size_in_bytes % sizeof(Ipp32u)) { if (pBN) { free(pBN); } return; } int bn_size = 0; /* Get the size of the IppsBigNumState context in bytes * Since we have checked the size_in_bytes before and the &bn_size is not NULL, * ippsBigNumGetSize never returns failure */ if (ippsBigNumGetSize(size_in_bytes / (int)sizeof(Ipp32u), &bn_size) != ippStsNoErr) { free(pBN); return; } /* Clear the buffer before free. */ memset_s(pBN, bn_size, 0, bn_size); free(pBN); return; }
void bnCopy(IppsBigNumState *pDest, const IppsBigNumState *pSource, const int size){ int iCtxSize; ippsBigNumGetSize (size, &iCtxSize ); memcpy( pDest, pSource, iCtxSize ) ; }