XFontMgr* XFontMgr_FontMgr(geEngine* theEngine){ XFontMgr* mgr = 0; int i; mgr = SAFE_ALLOC(XFontMgr); for ( i = 0; i < kFontMax; i++ ) mgr->m_fonts[i] = 0; XFontMgr_Create(mgr, theEngine); return mgr; }
EpidStatus CreatePrivKey(PrivKey const* priv_key_str, EcGroup* G1, FiniteField* Fp, PrivKey_** priv_key) { EpidStatus result = kEpidErr; PrivKey_* priv_key_ = NULL; // check parameters if (!priv_key_str || !G1 || !Fp || !priv_key) return kEpidBadArgErr; do { priv_key_ = SAFE_ALLOC(sizeof(*priv_key_)); if (!priv_key_) { result = kEpidMemAllocErr; break; } result = NewEcPoint(G1, &priv_key_->A); if (kEpidNoErr != result) break; result = NewFfElement(Fp, &priv_key_->x); if (kEpidNoErr != result) break; result = NewFfElement(Fp, &priv_key_->f); if (kEpidNoErr != result) break; if (0 != memcpy_S(&priv_key_->gid, sizeof(priv_key_->gid), &priv_key_str->gid, sizeof(priv_key_str->gid))) { result = kEpidBadArgErr; break; } result = ReadEcPoint(G1, &priv_key_str->A, sizeof(priv_key_str->A), priv_key_->A); if (kEpidNoErr != result) break; result = ReadFfElement(Fp, &priv_key_str->x, sizeof(priv_key_str->x), priv_key_->x); if (kEpidNoErr != result) break; result = ReadFfElement(Fp, &priv_key_str->f, sizeof(priv_key_str->f), priv_key_->f); if (kEpidNoErr != result) break; *priv_key = priv_key_; result = kEpidNoErr; } while (0); if (kEpidNoErr != result) { DeletePrivKey(&priv_key_); } return (result); }
LADSPA_Handle saturationInstantiate(const LADSPA_Descriptor* desc, unsigned long ulSampleRate) { Saturator* pSaturator; SAFE_ALLOC(pSaturator, Saturator); memset(pSaturator, 0xff, sizeof(Saturator)); pSaturator->m_ulSampleRate = ulSampleRate; return pSaturator; }
XFont* XFont_Font(){ XFont* font; int i; font = SAFE_ALLOC(XFont); font->m_world = NULL; font->m_size = 0; font->m_anti = GE_FALSE; strcpy( font->m_name, "" ); for ( i = kFontLowRange; i <= kFontHighRange; i++ ) font->m_chars[i].bitmap = NULL; font->m_spaceWidth = 0; return font; }
void PrintBigNum(BigNum const* big_num, char const* var_name) { IppStatus sts = ippStsNoErr; unsigned char* buf = NULL; int ipp_word_buf_size; if (!var_name) { var_name = "<no name>"; } PRINT("%s (BigNum):\n", var_name); if (!big_num) { MAKE_INDENT(); PRINT("<null>\n"); return; } if (!big_num->ipp_bn) { MAKE_INDENT(); PRINT("<invalid>\n"); return; } sts = ippsGetSize_BN(big_num->ipp_bn, &ipp_word_buf_size); if (ippStsNoErr != sts) { MAKE_INDENT(); PRINT("<invalid>\n"); return; } do { buf = SAFE_ALLOC(ipp_word_buf_size * sizeof(Ipp32u)); if (!buf) { MAKE_INDENT(); PRINT("<invalid>\n"); break; } sts = ippsGetOctString_BN((Ipp8u*)buf, ipp_word_buf_size * sizeof(Ipp32u), big_num->ipp_bn); if (ippStsNoErr != sts) { MAKE_INDENT(); PRINT("<invalid>\n"); break; } if (0 != PrintBuf((const void*)buf, ipp_word_buf_size * sizeof(Ipp32u))) { MAKE_INDENT(); PRINT("<invalid>\n"); break; } } while (0); SAFE_FREE(buf); }
///////////////////////////////////////////////////////////////////////////// // CRow::GetObjectDesc // ///////////////////////////////////////////////////////////////////////////// WCHAR* CRow::GetObjectDesc() { HRESULT hr = S_OK; if(!m_strObjectDesc && m_hSourceRow) { WCHAR* pwszValue = NULL; //0x00000000 = 1 Byte = 2 Asci Chars + "0x" + NULL Terminator SAFE_ALLOC(pwszValue, WCHAR, POINTER_DISPLAYSIZE); StringFormat(pwszValue, POINTER_DISPLAYSIZE, L"0x%p", (HANDLE)m_hSourceRow); m_strObjectDesc.Attach(pwszValue); } CLEANUP: return m_strObjectDesc; }
EpidStatus EpidSignBasic(MemberCtx const* ctx, void const* msg, size_t msg_len, void const* basename, size_t basename_len, BasicSignature* sig, BigNumStr* rnd_bsn) { EpidStatus sts = kEpidErr; EcPoint* B = NULL; EcPoint* t = NULL; // temp value in G1 EcPoint* k = NULL; EcPoint* e = NULL; FfElement* R2 = NULL; FfElement* p2y = NULL; FfElement* t1 = NULL; FfElement* t2 = NULL; FfElement* a = NULL; FfElement* b = NULL; FfElement* rx = NULL; FfElement* ra = NULL; FfElement* rb = NULL; struct p2x_t { uint32_t i; uint8_t bsn[1]; }* p2x = NULL; FfElement* t3 = NULL; // temporary for multiplication FfElement* c = NULL; uint8_t* digest = NULL; PreComputedSignature curr_presig = {0}; if (!ctx || !sig) { return kEpidBadArgErr; } if (!msg && (0 != msg_len)) { // if message is non-empty it must have both length and content return kEpidBadArgErr; } if (!basename && (0 != basename_len)) { // if basename is non-empty it must have both length and content return kEpidBadArgErr; } if (!ctx->epid2_params) { return kEpidBadArgErr; } do { FiniteField* Fp = ctx->epid2_params->Fp; SignCommitOutput commit_out = {0}; FpElemStr c_str = {0}; EcGroup* G1 = ctx->epid2_params->G1; FiniteField* GT = ctx->epid2_params->GT; FiniteField* Fq = ctx->epid2_params->Fq; PairingState* ps_ctx = ctx->epid2_params->pairing_state; const BigNumStr kOne = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; BigNumStr t1_str = {0}; BigNumStr t2_str = {0}; size_t digest_size = 0; uint16_t* rf_ctr = (uint16_t*)&ctx->rf_ctr; FfElement const* x = ctx->x; if (basename) { if (!IsBasenameAllowed(ctx->allowed_basenames, basename, basename_len)) { sts = kEpidBadArgErr; BREAK_ON_EPID_ERROR(sts); } } sts = NewEcPoint(G1, &B); BREAK_ON_EPID_ERROR(sts); sts = NewEcPoint(G1, &k); BREAK_ON_EPID_ERROR(sts); sts = NewEcPoint(G1, &t); BREAK_ON_EPID_ERROR(sts); sts = NewEcPoint(G1, &e); BREAK_ON_EPID_ERROR(sts); sts = NewFfElement(GT, &R2); BREAK_ON_EPID_ERROR(sts); sts = NewFfElement(Fq, &p2y); BREAK_ON_EPID_ERROR(sts); sts = NewFfElement(Fp, &t1); BREAK_ON_EPID_ERROR(sts); sts = NewFfElement(Fp, &t2); BREAK_ON_EPID_ERROR(sts); p2x = (struct p2x_t*)SAFE_ALLOC(sizeof(struct p2x_t) + basename_len - 1); if (!p2x) { sts = kEpidMemAllocErr; break; } sts = NewFfElement(Fp, &a); BREAK_ON_EPID_ERROR(sts); sts = NewFfElement(Fp, &b); BREAK_ON_EPID_ERROR(sts); sts = NewFfElement(Fp, &rx); BREAK_ON_EPID_ERROR(sts); sts = NewFfElement(Fp, &ra); BREAK_ON_EPID_ERROR(sts); sts = NewFfElement(Fp, &rb); BREAK_ON_EPID_ERROR(sts); sts = MemberGetPreSig((MemberCtx*)ctx, &curr_presig); BREAK_ON_EPID_ERROR(sts); // 3. If the pre-computed signature pre-sigma exists, the member // loads (B, K, T, a, b, rx, rf, ra, rb, R1, R2) from // pre-sigma. Refer to Section 4.4 for the computation of // these values. sts = ReadFfElement(Fp, &curr_presig.a, sizeof(curr_presig.a), a); BREAK_ON_EPID_ERROR(sts); sts = ReadFfElement(Fp, &curr_presig.b, sizeof(curr_presig.b), b); BREAK_ON_EPID_ERROR(sts); sts = ReadFfElement(Fp, &curr_presig.rx, sizeof(curr_presig.rx), rx); BREAK_ON_EPID_ERROR(sts); sts = ReadFfElement(Fp, &curr_presig.ra, sizeof(curr_presig.ra), ra); BREAK_ON_EPID_ERROR(sts); sts = ReadFfElement(Fp, &curr_presig.rb, sizeof(curr_presig.rb), rb); BREAK_ON_EPID_ERROR(sts); // If the basename is provided, use it, otherwise use presig B if (basename) { // 3.a. The member computes (B, i2, y2) = G1.tpmHash(bsn). sts = EcHash(G1, basename, basename_len, ctx->hash_alg, B, &p2x->i); BREAK_ON_EPID_ERROR(sts); p2x->i = htonl(p2x->i); sts = WriteEcPoint(G1, B, &commit_out.B, sizeof(commit_out.B)); BREAK_ON_EPID_ERROR(sts); sts = ReadFfElement(Fq, &commit_out.B.y, sizeof(commit_out.B.y), p2y); BREAK_ON_EPID_ERROR(sts); // b.i. (KTPM, LTPM, ETPM, counterTPM) = TPM2_Commit(P1=h1,(s2, y2) = (i2 // || bsn, y2)). // b.ii.K = KTPM. if (0 != memcpy_S((void*)p2x->bsn, basename_len, basename, basename_len)) { sts = kEpidBadArgErr; break; } sts = Tpm2Commit(ctx->tpm2_ctx, ctx->h1, p2x, sizeof(p2x->i) + basename_len, p2y, k, t, e, (uint16_t*)&ctx->rf_ctr); BREAK_ON_EPID_ERROR(sts); sts = WriteEcPoint(G1, k, &commit_out.K, sizeof(commit_out.K)); BREAK_ON_EPID_ERROR(sts); // c.i. The member computes R1 = LTPM. sts = WriteEcPoint(G1, t, &commit_out.R1, sizeof(commit_out.R1)); BREAK_ON_EPID_ERROR(sts); // c.ii. e12rf = pairing(ETPM, g2) sts = Pairing(ps_ctx, e, ctx->epid2_params->g2, R2); BREAK_ON_EPID_ERROR(sts); // c.iii. R2 = GT.sscmMultiExp(ea2, t1, e12rf, 1, e22, t2, e2w,ra). // 4.i. The member computes t1 = (- rx) mod p. sts = FfNeg(Fp, rx, t1); BREAK_ON_EPID_ERROR(sts); // 4.j. The member computes t2 = (rb - a * rx) mod p. sts = FfMul(Fp, a, rx, t2); BREAK_ON_EPID_ERROR(sts); sts = FfNeg(Fp, t2, t2); BREAK_ON_EPID_ERROR(sts); sts = FfAdd(Fp, rb, t2, t2); BREAK_ON_EPID_ERROR(sts); sts = WriteFfElement(Fp, t1, &t1_str, sizeof(t1_str)); BREAK_ON_EPID_ERROR(sts); sts = WriteFfElement(Fp, t2, &t2_str, sizeof(t2_str)); BREAK_ON_EPID_ERROR(sts); { FfElement const* points[4]; BigNumStr const* exponents[4]; points[0] = ctx->ea2; points[1] = R2; points[2] = ctx->e22; points[3] = ctx->e2w; exponents[0] = &t1_str; exponents[1] = &kOne; exponents[2] = &t2_str; exponents[3] = (BigNumStr*)&curr_presig.ra; sts = FfMultiExp(GT, points, exponents, COUNT_OF(points), R2); BREAK_ON_EPID_ERROR(sts); } sts = WriteFfElement(GT, R2, &commit_out.R2, sizeof(commit_out.R2)); BREAK_ON_EPID_ERROR(sts); // d. The member over-writes the counterTPM, B, K, R1 and R2 values. } else { if (!rnd_bsn) { sts = kEpidBadArgErr; break; } sts = ReadEcPoint(G1, &curr_presig.B, sizeof(curr_presig.B), B); BREAK_ON_EPID_ERROR(sts); commit_out.B = curr_presig.B; commit_out.K = curr_presig.K; commit_out.R1 = curr_presig.R1; ((MemberCtx*)ctx)->rf_ctr = curr_presig.rf_ctr; commit_out.R2 = curr_presig.R2; *rnd_bsn = curr_presig.rnd_bsn; } commit_out.T = curr_presig.T; sts = HashSignCommitment(Fp, ctx->hash_alg, &ctx->pub_key, &commit_out, msg, msg_len, &c_str); BREAK_ON_EPID_ERROR(sts); digest_size = EpidGetHashSize(ctx->hash_alg); digest = (uint8_t*)SAFE_ALLOC(digest_size); if (!digest) { sts = kEpidNoMemErr; break; } memcpy_S(digest + digest_size - sizeof(c_str), sizeof(c_str), &c_str, sizeof(c_str)); sts = NewFfElement(Fp, &t3); BREAK_ON_EPID_ERROR(sts); sts = NewFfElement(Fp, &c); BREAK_ON_EPID_ERROR(sts); sts = ReadFfElement(Fp, &c_str, sizeof(c_str), c); BREAK_ON_EPID_ERROR(sts); // 7. The member computes sx = (rx + c * x) mod p. sts = FfMul(Fp, c, x, t3); BREAK_ON_EPID_ERROR(sts); sts = FfAdd(Fp, rx, t3, t3); BREAK_ON_EPID_ERROR(sts); sts = WriteFfElement(Fp, t3, &sig->sx, sizeof(sig->sx)); BREAK_ON_EPID_ERROR(sts); // 8. The member computes sf = (rf + c * f) mod p. sts = Tpm2Sign(ctx->tpm2_ctx, digest, digest_size, *rf_ctr, NULL, t3); BREAK_ON_EPID_ERROR(sts); sts = WriteFfElement(Fp, t3, &sig->sf, sizeof(sig->sf)); BREAK_ON_EPID_ERROR(sts); // 9. The member computes sa = (ra + c * a) mod p. sts = FfMul(Fp, c, a, t3); BREAK_ON_EPID_ERROR(sts); sts = FfAdd(Fp, ra, t3, t3); BREAK_ON_EPID_ERROR(sts); sts = WriteFfElement(Fp, t3, &sig->sa, sizeof(sig->sa)); BREAK_ON_EPID_ERROR(sts); // 10. The member computes sb = (rb + c * b) mod p. sts = FfMul(Fp, c, b, t3); BREAK_ON_EPID_ERROR(sts); sts = FfAdd(Fp, rb, t3, t3); BREAK_ON_EPID_ERROR(sts); sts = WriteFfElement(Fp, t3, &sig->sb, sizeof(sig->sb)); BREAK_ON_EPID_ERROR(sts); sig->B = commit_out.B; sig->K = commit_out.K; sig->T = commit_out.T; sig->c = c_str; sts = kEpidNoErr; } while (0); if (sts != kEpidNoErr) { (void)Tpm2ReleaseCounter(ctx->tpm2_ctx, (uint16_t)ctx->rf_ctr); (void)Tpm2ReleaseCounter(ctx->tpm2_ctx, curr_presig.rf_ctr); } else if (basename) { (void)Tpm2ReleaseCounter(ctx->tpm2_ctx, curr_presig.rf_ctr); } EpidZeroMemory(&curr_presig, sizeof(curr_presig)); DeleteEcPoint(&B); DeleteEcPoint(&k); DeleteEcPoint(&t); DeleteEcPoint(&e); DeleteFfElement(&R2); DeleteFfElement(&p2y); DeleteFfElement(&t1); DeleteFfElement(&t2); DeleteFfElement(&a); DeleteFfElement(&b); DeleteFfElement(&rx); DeleteFfElement(&ra); DeleteFfElement(&rb); SAFE_FREE(p2x); DeleteFfElement(&t3); DeleteFfElement(&c); SAFE_FREE(digest); return sts; }
// CImpIDBInfo::GetLiteralInfo ----------------------------------------- // // @mfunc Returns information about literals used in text command // // @rdesc HRESULT // @flag S_OK | cLiterals was 0 // @flag E_INVALIDARG | cLiterals not equal to 0 and rgLiterals was NULL or // | pcLiteralInfo, prgLiteralInfo, or ppCharBuffer was NULL // @flag E_UNEXPECTED | Can not be called unless initialized // @flag DB_E_ERRORSOCCURRED | None of the requested literals are supported // STDMETHODIMP CImpIDBInfo::GetLiteralInfo ( ULONG cLiterals, //@parm IN | # of literals const DBLITERAL rgLiterals[], //@parm IN | Array of literals ULONG* pcLiteralInfo, //@parm OUT | # of literals returned DBLITERALINFO** prgLiteralInfo, //@parm OUT | Array of info structures WCHAR** ppCharBuffer //@parm OUT | Buffer for characters ) { HRESULT hr = DB_E_ERRORSOCCURRED; ULONG ulIndex = 0; // // Asserts // assert(m_pObj); // // Check in-params and NULL out-params in case of error // if( pcLiteralInfo ) *pcLiteralInfo = 0; if( prgLiteralInfo ) *prgLiteralInfo = NULL; if( ppCharBuffer ) *ppCharBuffer = NULL; // // Check input and output values pointers // if( cLiterals && !rgLiterals ) return E_INVALIDARG; if( !pcLiteralInfo || !prgLiteralInfo || !ppCharBuffer ) return E_INVALIDARG; // // Check to see if initialized // if( !m_pObj->m_fDSOInitialized ) return E_UNEXPECTED; // // If cLiterals is 0, ignore rgLiterals // return all supported values // if( cLiterals == 0 ) return S_OK; // // Allocate memory for DBLITERALINFO array // SAFE_ALLOC(*prgLiteralInfo, DBLITERALINFO, cLiterals); // // Process each of the DBLITERAL values that are in the restriction array // *pcLiteralInfo = cLiterals; for(ulIndex=0; ulIndex < cLiterals; ulIndex++) { (*prgLiteralInfo)[ulIndex].lt = rgLiterals[ulIndex]; (*prgLiteralInfo)[ulIndex].fSupported = FALSE; (*prgLiteralInfo)[ulIndex].pwszLiteralValue = NULL; (*prgLiteralInfo)[ulIndex].pwszInvalidChars = NULL; (*prgLiteralInfo)[ulIndex].pwszInvalidStartingChars = NULL; (*prgLiteralInfo)[ulIndex].cchMaxLen = 0; } CLEANUP: return hr; }
///////////////////////////////////////////////////////////////// // HRESULT CRow::SetupColAccess // ///////////////////////////////////////////////////////////////// HRESULT CRow::SetupColAccess(BINDCOLS eBindCols) { HRESULT hr = S_OK; DBLENGTH dwOffset = 0; ULONG i; //Only capable of the Following Converions (for Display) DWORD dwMaxLength = GetOptions()->m_dwMaxLength; DWORD dwAccessorOpts = GetOptions()->m_dwAccessorOpts; if(m_pIColumnsInfo == NULL) return E_FAIL; //GetColumnInfo GetColInfo(); //Alloc the space to hold the ColumnAccess structs ULONG cBindings = 0; DBBINDING* rgBindings = NULL; SAFE_ALLOC(m_rgColAccess, DBCOLUMNACCESS, m_ColumnInfo.GetCount()); SAFE_ALLOC(rgBindings, DBBINDING, m_ColumnInfo.GetCount()); //Figure out how big to make the buffer... for(i=0; i<m_ColumnInfo.GetCount(); i++) { //Offset m_rgColAccess[i].cbMaxLen = GetMaxDisplaySize(GetOptions()->GetBindingType(m_ColumnInfo[i].wType), m_ColumnInfo[i].wType, m_ColumnInfo[i].ulColumnSize, dwMaxLength); dwOffset = ROUNDUP( dwOffset + m_rgColAccess[i].cbMaxLen ); } //Size for pData SAFE_REALLOC(m_pData, BYTE, dwOffset); dwOffset = 0; m_cColAccess = 0; cBindings = 0; for(i=0; i<m_ColumnInfo.GetCount(); i++) { DBCOLUMNINFO* pColInfo = &m_ColumnInfo[i]; DBCOLUMNACCESS* pColAccess = &m_rgColAccess[m_cColAccess]; DBBINDING* pBinding = &rgBindings[cBindings]; //Setup the Bindings pColAccess->columnid = pColInfo->columnid; pColAccess->bPrecision = pColInfo->bPrecision; pColAccess->bScale = pColInfo->bScale; pColAccess->wType = GetOptions()->GetBindingType(pColInfo->wType); pColAccess->cbDataLen = 0; //NOTE: This is setup above in the Previous for loop... pColAccess->cbMaxLen = m_rgColAccess[i].cbMaxLen; //BLOB or IUnknown Bindings if(pColAccess->wType == DBTYPE_IUNKNOWN || pColInfo->wType == DBTYPE_IUNKNOWN || (pColInfo->dwFlags & DBCOLUMNFLAGS_ISLONG && (dwAccessorOpts & (ACCESSOR_BLOB_ISEQSTREAM|ACCESSOR_BLOB_ILOCKBYTES|ACCESSOR_BLOB_ISTORAGE|ACCESSOR_BLOB_ISTREAM)))) { pColAccess->wType = DBTYPE_IUNKNOWN; pColAccess->cbMaxLen = sizeof(IUnknown*); } //If the consumer requested not to bind the Value in Options, then set pData = NULL //This is how the 2.5 spec says to indicate VALUE is not bound (since their is no dwPart). pColAccess->pData = NULL; if(dwAccessorOpts & ACCESSOR_BIND_VALUE) pColAccess->pData = (BYTE*)m_pData + dwOffset; //Initialize the Status to an error, so we don't end up freeing outofline //data we haven't retreived yet... pColAccess->dwStatus = DBSTATUS_E_UNAVAILABLE; //Special Handling for other non-OLE DB defined convertable types to WSTR //NOTE: The spec requires all supported types to be converted to //WSTR, but this only applies where the OLE DB conversion is defined. //Some are not defined so we need to bind nativly. switch(pColInfo->wType) { case DBTYPE_IUNKNOWN: case DBTYPE_IDISPATCH: pColAccess->wType = pColInfo->wType; pColAccess->cbMaxLen = sizeof(IUnknown*); break; case DBTYPE_HCHAPTER: pColAccess->wType = pColInfo->wType; pColAccess->cbMaxLen = sizeof(HCHAPTER); break; default: //DBTYPE_VECTOR if(pColInfo->wType & DBTYPE_VECTOR) { pColAccess->wType = pColInfo->wType; pColAccess->cbMaxLen= sizeof(DBVECTOR); } //DBTYPE_ARRAY if(pColInfo->wType & DBTYPE_ARRAY) { pColAccess->wType = pColInfo->wType; pColAccess->cbMaxLen= sizeof(SAFEARRAY*); } break; }; //Offset dwOffset += pColAccess->cbMaxLen; dwOffset = ROUNDUP( dwOffset ); //Build a real simple binding on top of this ColumnAccess struct. //The reason is all of our data manipulations routines deal with binding structs, so instead //have having numerous code lines, we will just map this to a binding struct... pBinding->iOrdinal = pColInfo->iOrdinal; pBinding->obStatus = (DBBYTEOFFSET)((BYTE*)&pColAccess->dwStatus - (BYTE*)m_pData); pBinding->obLength = (DBBYTEOFFSET)((BYTE*)&pColAccess->cbDataLen - (BYTE*)m_pData); pBinding->obValue = (DBBYTEOFFSET)((BYTE*)pColAccess->pData - (BYTE*)m_pData); pBinding->pTypeInfo = NULL; pBinding->pObject = NULL; pBinding->pBindExt = NULL; pBinding->dwPart = DBPART_LENGTH|DBPART_STATUS; if(pColAccess->pData) pBinding->dwPart |= DBPART_VALUE; pBinding->dwMemOwner = (dwAccessorOpts & ACCESSOR_OWNED_PROVIDER) ? DBMEMOWNER_PROVIDEROWNED : DBMEMOWNER_CLIENTOWNED; pBinding->eParamIO = DBPARAMIO_NOTPARAM; pBinding->cbMaxLen = pColAccess->cbMaxLen; pBinding->dwFlags = 0; pBinding->wType = pColAccess->wType; pBinding->bPrecision = pColAccess->bPrecision; pBinding->bScale = pColAccess->bScale; //Do we real want this column? switch(eBindCols) { case BIND_ALLCOLS: m_cColAccess++; cBindings++; break; case BIND_ALLCOLSEXPECTBOOKMARK: if(pColInfo->iOrdinal != 0) { m_cColAccess++; cBindings++; } break; case BIND_UPDATEABLECOLS: if(pColInfo->dwFlags & DBCOLUMNFLAGS_WRITE || pColInfo->dwFlags & DBCOLUMNFLAGS_WRITEUNKNOWN) { m_cColAccess++; cBindings++; } break; default: ASSERT(!"Unhandled Type!"); break; } } CLEANUP: m_Bindings.Attach(cBindings, rgBindings); return hr; }
//-------------------------------------------------------------------- // @mfunc Tokenize the column info // // @rdesc BOOL // @flag TRUE | Parsing yielded no Error // BOOL CParseInitFile::GetColumns ( CHAR* pszInput ) { ASSERT(pszInput); WCHAR* pwszColName = NULL; WCHAR* pwszColIDName = NULL; WCHAR* pwszTempGuid = NULL; WCHAR* pwszPrefix = NULL; WCHAR* pwszSuffix = NULL; CCol NewCol; DBID dbidCol; GUID* pGuid = NULL; GUID guid; HRESULT hr = S_OK; CHAR* pszStart = pszInput; CHAR* pszEndData = strchr(pszStart, ','); CHAR* pszEnd = pszStart + strlen(pszStart); TRACE_CALL(L"PRIVLIB: CParseInitFile::GetColumns.\n"); memset(&dbidCol, 0, sizeof(DBID)); //Initialize NewCol to default values InitializeNewCol(NewCol); //Error checking if(pszStart==NULL || pszEndData==NULL || pszEndData > pszEnd) { odtLog << "ERROR: Unable to find Column Name, Seperators, or End Markers in INI <File:" << m_pszFileName << ">" << ENDL; odtLog << "ERROR: Make sure your using a correctly generated INI File from TableDump.exe" << ENDL; return FALSE; } //Loop over all column info for(ULONG i=0; i<=COL_SUFFIX; i++) { //Place the NULL Terminator pszEndData[0] = '\0'; //Fill in Appropiate column info if(i==COL_NAME) { //Column Names can be NULL PROVIDER_FREE(pwszColName); if(pszStart != pszEndData) { //Convert to WCHAR pwszColName = ConvertToWCHAR(pszStart); } //Store the column name NewCol.SetColName(pwszColName); } else if(i==COL_NUMBER) { // column num NewCol.SetColNum(strtoul(pszStart, NULL, 10)); } else if(i==COL_DBTYPE) { // column DBTYPE NewCol.SetProviderType(ConvertToDBTYPE(pszStart)); } else if(i==COL_SIZE) { DBLENGTH ulValue = strtoul(pszStart, NULL, 10); //set the column size NewCol.SetColumnSize(ulValue); } else if(i==COL_PRECISION) { ULONG ulValue = strtoul(pszStart, NULL, 10); // set the actual column precision NewCol.SetPrecision((BYTE)ulValue); } else if(i==COL_SCALE) { // column scale NewCol.SetScale((BYTE)strtol(pszStart, NULL, 10)); } else if(i==COL_FLAGS) { // column Flags ParseFlags(pszStart, NewCol); } else if(i==COL_PREFIX) { //if the ini has null here (which is marked as '(null)' then set //it the way it should be if (strcmp("(null)",pszStart)) { // column Flags PROVIDER_FREE(pwszPrefix) pwszPrefix = ConvertToWCHAR(pszStart); NewCol.SetPrefix(pwszPrefix); } else { // column Flags PROVIDER_FREE(pwszPrefix) pwszPrefix = ConvertToWCHAR(""); NewCol.SetPrefix(pwszPrefix); } } else if(i==COL_SUFFIX) { //if the ini has null here (which is marked as '(null)' then set //it the way it should be if (strcmp("(null)",pszStart)) { // column Flags PROVIDER_FREE(pwszSuffix) pwszSuffix = ConvertToWCHAR(pszStart); NewCol.SetSuffix(pwszSuffix); } else { // column Flags PROVIDER_FREE(pwszSuffix) pwszSuffix = ConvertToWCHAR(""); NewCol.SetSuffix(pwszSuffix); } } else if((i==COL_IDKIND) && (pszStart != pszEndData)) { dbidCol.eKind = strtoul(pszStart, NULL, 10); } else if((i==COL_IDGUID) && (pszStart != pszEndData)) { if(dbidCol.eKind == DBKIND_PGUID_NAME || dbidCol.eKind == DBKIND_PGUID_PROPID) { SAFE_ALLOC(pGuid, GUID, 1); PROVIDER_FREE(pwszTempGuid); pwszTempGuid = ConvertToWCHAR(pszStart); hr = CLSIDFromString(pwszTempGuid, pGuid); dbidCol.uGuid.pguid = pGuid; } else { PROVIDER_FREE(pwszTempGuid); pwszTempGuid = ConvertToWCHAR(pszStart); hr = CLSIDFromString(pwszTempGuid, &guid); dbidCol.uGuid.guid = guid; } } else if((i==COL_IDNAME) && (pszStart != pszEndData)) { if(dbidCol.eKind == DBKIND_PGUID_NAME || dbidCol.eKind == DBKIND_GUID_NAME || dbidCol.eKind == DBKIND_NAME ) { PROVIDER_FREE(pwszColIDName); pwszColIDName = ConvertToWCHAR(pszStart); dbidCol.uName.pwszName = pwszColIDName; } else { dbidCol.uName.ulPropid = strtoul(pszStart, NULL, 10); } } //Find the next Info Piece if(i<COL_SUFFIX) { pszStart = pszEndData+1; pszEndData = strchr(pszStart, ','); if((i==COL_FLAGS) && (!pszEndData)) goto END; if(pszEndData == NULL) pszEndData = pszEnd; //Error checking if(pszStart==NULL || pszEndData==NULL || pszEndData > pszEnd) { odtLog << "ERROR: Unable to find Column Name, Seperators, or End Markers in INI <File:" << m_pszFileName << ">" << ENDL; odtLog << "ERROR: Make sure your using a correctly generated INI File from TableDump.exe" << ENDL; return FALSE; } } } END: //Add the new columnInfo at the end fo the list NewCol.SetColID(&dbidCol); m_ColData.AddTail(NewCol); CLEANUP: PROVIDER_FREE(pwszColName); PROVIDER_FREE(pGuid); PROVIDER_FREE(pwszColIDName); PROVIDER_FREE(pwszTempGuid); PROVIDER_FREE(pwszPrefix); PROVIDER_FREE(pwszSuffix); return TRUE; }
// CImpIColumnsInfo::GetColumnInfo ------------------------------------------- // // @mfunc Returns the column metadata needed by most consumers. // // @rdesc HRESULT // @flag S_OK | The method succeeded // @flag E_OUTOFMEMORY | Out of memory // @flag E_INVALIDARG | pcColumns or prginfo or ppStringsbuffer was NULL // STDMETHODIMP CImpIColumnsInfo::GetColumnInfo ( DBORDINAL* pcColumns, //@parm OUT | Number of columns in rowset DBCOLUMNINFO** prgInfo, //@parm OUT | Array of DBCOLUMNINFO Structures WCHAR** ppStringsBuffer //@parm OUT | Storage for all string values ) { HRESULT hr = S_OK; DBORDINAL cCols = 0; DBORDINAL cExtraCols = 0; DBORDINAL cbHeapUsed = 0; DBORDINAL cIter = 0; BYTE * pbHeap = NULL; WCHAR * pwstrBuffer = NULL; DBCOLUMNINFO * rgdbcolinfo = NULL; DBCOLUMNINFO * rgdbInternalcolinfo = NULL; DBCOLUMNINFO * rgdbExtracolinfo = NULL; CRowset * pCRowset = NULL; CFileIO * pFileio = NULL; // // Asserts // assert(m_pObj); // // Check in-params and NULL out-params in case of error // if( pcColumns ) *pcColumns = 0; if( prgInfo ) *prgInfo = NULL; if( ppStringsBuffer ) *ppStringsBuffer = NULL; if( !pcColumns || !prgInfo || !ppStringsBuffer ) return E_INVALIDARG; // // Get the Column Information off of the Command or Rowset // if( m_pObj->GetBaseObjectType() == BOT_COMMAND ) { // // Asserts // assert(((CCommand *) m_pObj)->m_pCSession); assert(((CCommand *) m_pObj)->m_pCSession->m_pCDataSource); // // Check that a command has been set // if( !((CCommand *) m_pObj)->IsCommandSet() ) return DB_E_NOCOMMAND; // // Try to open the file... // hr = ((CCommand *) m_pObj)->m_pCSession->m_pCDataSource->OpenFile( ((CCommand *) m_pObj)->GetCommandText(), &pFileio); if( FAILED(hr) ) return hr; } else { if( m_pObj->GetBaseObjectType() == BOT_ROWSET ) pFileio = ((CRowset *) m_pObj)->GetFileObj(); else { pFileio = ((CRow *) m_pObj)->GetFileObj(); cExtraCols = ((CRow *) m_pObj)->GetExtraColCount(); rgdbExtracolinfo = ((CRow *) m_pObj)->GetExtraColumnInfo(); } } // // Get the column count and delete unneeded info // cCols = pFileio->GetColumnCnt(); pbHeap = pFileio->GetColNameHeap(); cbHeapUsed = pFileio->GetColNameHeapSize(); rgdbInternalcolinfo = pFileio->GetColInfo(); // // Return the column information // SAFE_ALLOC(rgdbcolinfo, DBCOLUMNINFO, (cCols + cExtraCols) * sizeof(DBCOLUMNINFO)); SAFE_ALLOC(pwstrBuffer, WCHAR, cbHeapUsed); memcpy(rgdbcolinfo, &(rgdbInternalcolinfo[1]), cCols*sizeof(DBCOLUMNINFO)); memcpy(rgdbcolinfo+cCols, rgdbExtracolinfo, cExtraCols*sizeof(DBCOLUMNINFO)); // // Need to fix up column ordinals for extra columns // for (cIter=cCols; cIter < cCols+cExtraCols; cIter++) rgdbcolinfo[cIter].iOrdinal = cIter+1; // // Copy the heap for column names. // if( cbHeapUsed ) { ptrdiff_t dp; memcpy(pwstrBuffer, pbHeap, cbHeapUsed); dp = (DBBYTEOFFSET)pwstrBuffer - (DBBYTEOFFSET)(pbHeap); dp >>= 1; // Loop through columns and adjust pointers to column names. for (ULONG icol=0; icol < cCols; icol++) { if( rgdbcolinfo[icol].pwszName ) rgdbcolinfo[icol].pwszName += dp; } } // // Assign in the values // *pcColumns = cCols + cExtraCols; *prgInfo = rgdbcolinfo; *ppStringsBuffer = pwstrBuffer; CLEANUP: // // Cleanup the File Information // if( m_pObj->GetBaseObjectType() == BOT_COMMAND ) SAFE_DELETE(pFileio); if( FAILED(hr) ) { SAFE_DELETE(rgdbcolinfo); SAFE_DELETE(pwstrBuffer); } return hr; }
EpidStatus EpidVerifierCreate(GroupPubKey const* pubkey, VerifierPrecomp const* precomp, VerifierCtx** ctx) { EpidStatus result = kEpidErr; VerifierCtx* verifier_ctx = NULL; if (!pubkey || !ctx) { return kEpidBadArgErr; } do { // Allocate memory for VerifierCtx verifier_ctx = SAFE_ALLOC(sizeof(VerifierCtx)); if (!verifier_ctx) { result = kEpidMemAllocErr; break; } // set SHA512 as the default hash algorithm verifier_ctx->hash_alg = kSha512; // Internal representation of Epid2Params result = CreateEpid2Params(&verifier_ctx->epid2_params); if (kEpidNoErr != result) { break; } // Internal representation of Group Pub Key result = CreateGroupPubKey(pubkey, verifier_ctx->epid2_params->G1, verifier_ctx->epid2_params->G2, &verifier_ctx->pub_key); if (kEpidNoErr != result) { break; } // Store group public key strings for later use result = SetKeySpecificCommitValues(pubkey, &verifier_ctx->commit_values); if (kEpidNoErr != result) { break; } // Allocate verifier_ctx->e12 result = NewFfElement(verifier_ctx->epid2_params->GT, &verifier_ctx->e12); if (kEpidNoErr != result) { break; } // Allocate verifier_ctx->e22 result = NewFfElement(verifier_ctx->epid2_params->GT, &verifier_ctx->e22); if (kEpidNoErr != result) { break; } // Allocate verifier_ctx->e2w result = NewFfElement(verifier_ctx->epid2_params->GT, &verifier_ctx->e2w); if (kEpidNoErr != result) { break; } // Allocate verifier_ctx->eg12 result = NewFfElement(verifier_ctx->epid2_params->GT, &verifier_ctx->eg12); if (kEpidNoErr != result) { break; } // precomputation if (precomp != NULL) { result = ReadPrecomputation(precomp, verifier_ctx); } else { result = DoPrecomputation(verifier_ctx); } if (kEpidNoErr != result) { break; } verifier_ctx->sig_rl = NULL; verifier_ctx->group_rl = NULL; verifier_ctx->priv_rl = NULL; verifier_ctx->verifier_rl = NULL; *ctx = verifier_ctx; result = kEpidNoErr; } while (0); if (kEpidNoErr != result && verifier_ctx) { DeleteFfElement(&verifier_ctx->eg12); DeleteFfElement(&verifier_ctx->e2w); DeleteFfElement(&verifier_ctx->e22); DeleteFfElement(&verifier_ctx->e12); DeleteEpid2Params(&verifier_ctx->epid2_params); DeleteGroupPubKey(&verifier_ctx->pub_key); SAFE_FREE(verifier_ctx); } return result; }
EpidStatus CreateEpid2Params(Epid2Params_** params) { EpidStatus result = kEpidErr; Epid2Params_* internal_param = NULL; BigNumStr t_str = {0}; Epid2Params params_str = { #include "epid/common/epid2params_ate.inc" }; if (!params) { return kEpidBadArgErr; } do { internal_param = SAFE_ALLOC(sizeof(Epid2Params_)); if (!internal_param) { result = kEpidMemAllocErr; break; } result = NewBigNum(sizeof(params_str.p), &internal_param->p); if (kEpidNoErr != result) { break; } result = ReadBigNum(¶ms_str.p, sizeof(params_str.p), internal_param->p); if (kEpidNoErr != result) { break; } result = NewBigNum(sizeof(params_str.q), &internal_param->q); if (kEpidNoErr != result) { break; } result = ReadBigNum(¶ms_str.q, sizeof(params_str.q), internal_param->q); if (kEpidNoErr != result) { break; } result = NewBigNum(sizeof(params_str.t), &internal_param->t); if (kEpidNoErr != result) { break; } result = ReadBigNum(¶ms_str.t, sizeof(params_str.t), internal_param->t); if (kEpidNoErr != result) { break; } internal_param->neg = (params_str.neg.data[0]) ? true : false; result = NewFp(¶ms_str, &internal_param->Fp); if (kEpidNoErr != result) { break; } result = NewFq(¶ms_str, &internal_param->Fq); if (kEpidNoErr != result) { break; } result = NewFq2(¶ms_str, internal_param->Fq, &internal_param->Fq2); if (kEpidNoErr != result) { break; } result = NewFfElement(internal_param->Fq2, &internal_param->xi); if (kEpidNoErr != result) { break; } result = ReadFfElement(internal_param->Fq2, ¶ms_str.xi, sizeof(params_str.xi), internal_param->xi); if (kEpidNoErr != result) { break; } result = NewFq6(¶ms_str, internal_param->Fq2, internal_param->xi, &internal_param->Fq6); if (kEpidNoErr != result) { break; } result = NewGT(internal_param->Fq6, &internal_param->GT); if (kEpidNoErr != result) { break; } result = NewG1(¶ms_str, internal_param->Fq, &internal_param->G1); if (kEpidNoErr != result) { break; } result = NewEcPoint(internal_param->G1, &internal_param->g1); if (kEpidNoErr != result) { break; } result = ReadEcPoint(internal_param->G1, ¶ms_str.g1, sizeof(params_str.g1), internal_param->g1); if (kEpidNoErr != result) { break; } result = NewG2(¶ms_str, internal_param->p, internal_param->q, internal_param->Fq, internal_param->Fq2, &internal_param->G2); if (kEpidNoErr != result) { break; } result = NewEcPoint(internal_param->G2, &internal_param->g2); if (kEpidNoErr != result) { break; } result = ReadEcPoint(internal_param->G2, ¶ms_str.g2, sizeof(params_str.g2), internal_param->g2); if (kEpidNoErr != result) { break; } result = WriteBigNum(internal_param->t, sizeof(t_str), &t_str); if (kEpidNoErr != result) { break; } result = NewPairingState(internal_param->G1, internal_param->G2, internal_param->GT, &t_str, internal_param->neg, &internal_param->pairing_state); if (kEpidNoErr != result) { break; } *params = internal_param; result = kEpidNoErr; } while (0); if (kEpidNoErr != result && internal_param) { DeletePairingState(&internal_param->pairing_state); DeleteEcPoint(&internal_param->g2); DeleteEcPoint(&internal_param->g1); DeleteBigNum(&internal_param->p); DeleteBigNum(&internal_param->q); DeleteBigNum(&internal_param->t); DeleteFp(&internal_param->Fp); DeleteFq(&internal_param->Fq); DeleteFq2(&internal_param->Fq2); DeleteFq6(&internal_param->Fq6); DeleteGT(&internal_param->GT); DeleteG1(&internal_param->G1); DeleteG2(&internal_param->G2); SAFE_FREE(internal_param); } return result; }
EpidStatus EcdsaSignBuffer(void const* buf, size_t buf_len, EcdsaPrivateKey const* privkey, BitSupplier rnd_func, void* rnd_param, EcdsaSignature* sig) { EpidStatus result = kEpidMathErr; IppsECCPState* ec_ctx = NULL; BigNum* bn_ec_order = NULL; BigNum* bn_hash = NULL; BigNum* bn_reg_private = NULL; BigNum* bn_eph_private = NULL; IppsECCPPointState* ecp_eph_public = NULL; BigNum* bn_sig_x = NULL; BigNum* bn_sig_y = NULL; do { EpidStatus epid_status = kEpidNoErr; IppStatus sts = ippStsNoErr; int ctxsize = 0; // order of EC secp256r1 const uint8_t secp256r1_r[32] = { 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84, 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51}; Ipp8u hash[IPP_SHA256_DIGEST_BITSIZE / 8] = {0}; unsigned int gen_loop_count = EPHKEYGEN_WATCHDOG; Ipp32u cmp0 = IS_ZERO; Ipp32u cmp_order = IS_ZERO; if ((0 != buf_len && !buf) || !privkey || !rnd_func || !sig) { result = kEpidBadArgErr; break; } if (buf_len > INT_MAX) { result = kEpidBadArgErr; break; } // Define standard elliptic curve secp256r1 sts = ippsECCPGetSizeStd256r1(&ctxsize); if (ippStsNoErr != sts) break; ec_ctx = (IppsECCPState*)SAFE_ALLOC(ctxsize); if (!ec_ctx) { result = kEpidMemAllocErr; break; } sts = ippsECCPInitStd256r1(ec_ctx); if (ippStsNoErr != sts) break; sts = ippsECCPSetStd256r1(ec_ctx); if (ippStsNoErr != sts) break; // Create big number for order of elliptic curve secp256r1 epid_status = NewBigNum(sizeof(secp256r1_r), &bn_ec_order); if (kEpidMemAllocErr == epid_status) { result = kEpidMemAllocErr; break; } if (kEpidNoErr != epid_status) break; epid_status = ReadBigNum(secp256r1_r, sizeof(secp256r1_r), bn_ec_order); if (kEpidNoErr != epid_status) break; // Calculate hash for input message sts = ippsSHA256MessageDigest(buf, (int)buf_len, hash); if (ippStsNoErr != sts) break; // Create big number for hash epid_status = NewBigNum(sizeof(hash), &bn_hash); if (kEpidMemAllocErr == epid_status) { result = kEpidMemAllocErr; break; } if (kEpidNoErr != epid_status) break; epid_status = ReadBigNum(hash, sizeof(hash), bn_hash); if (kEpidNoErr != epid_status) break; sts = ippsMod_BN(bn_hash->ipp_bn, bn_ec_order->ipp_bn, bn_hash->ipp_bn); if (ippStsNoErr != sts) break; // Create big number for regular private key epid_status = NewBigNum(sizeof(*privkey), &bn_reg_private); if (kEpidMemAllocErr == epid_status) { result = kEpidMemAllocErr; break; } if (kEpidNoErr != epid_status) break; epid_status = ReadBigNum(privkey, sizeof(*privkey), bn_reg_private); if (kEpidNoErr != epid_status) break; // Validate private key is in range [1, bn_ec_order-1] sts = ippsCmpZero_BN(bn_reg_private->ipp_bn, &cmp0); if (ippStsNoErr != sts) break; sts = ippsCmp_BN(bn_reg_private->ipp_bn, bn_ec_order->ipp_bn, &cmp_order); if (ippStsNoErr != sts) break; if (IS_ZERO == cmp0 || LESS_THAN_ZERO != cmp_order) { result = kEpidBadArgErr; break; } // Create big number for ephemeral private key epid_status = NewBigNum(sizeof(secp256r1_r), &bn_eph_private); if (kEpidMemAllocErr == epid_status) { result = kEpidMemAllocErr; break; } if (kEpidNoErr != epid_status) break; // Create EC point for ephemeral public key sts = ippsECCPPointGetSize(256, &ctxsize); if (ippStsNoErr != sts) break; ecp_eph_public = (IppsECCPPointState*)SAFE_ALLOC(ctxsize); if (!ecp_eph_public) { result = kEpidMemAllocErr; break; } sts = ippsECCPPointInit(256, ecp_eph_public); if (ippStsNoErr != sts) break; // Create big numbers for signature epid_status = NewBigNum(sizeof(secp256r1_r), &bn_sig_x); if (kEpidMemAllocErr == epid_status) { result = kEpidMemAllocErr; break; } if (kEpidNoErr != epid_status) break; epid_status = NewBigNum(sizeof(secp256r1_r), &bn_sig_y); if (kEpidMemAllocErr == epid_status) { result = kEpidMemAllocErr; break; } if (kEpidNoErr != epid_status) break; do { // Generate ephemeral key pair sts = ippsECCPGenKeyPair(bn_eph_private->ipp_bn, ecp_eph_public, ec_ctx, (IppBitSupplier)rnd_func, rnd_param); if (ippStsNoErr != sts) break; // Set ephemeral key pair sts = ippsECCPSetKeyPair(bn_eph_private->ipp_bn, ecp_eph_public, ippFalse, ec_ctx); if (ippStsNoErr != sts) break; // Compute signature sts = ippsECCPSignDSA(bn_hash->ipp_bn, bn_reg_private->ipp_bn, bn_sig_x->ipp_bn, bn_sig_y->ipp_bn, ec_ctx); if (ippStsEphemeralKeyErr != sts) break; } while (--gen_loop_count); if (ippStsEphemeralKeyErr == sts) { result = kEpidRandMaxIterErr; break; } if (ippStsNoErr != sts) break; sts = ippsGetOctString_BN(sig->x.data, sizeof(sig->x), bn_sig_x->ipp_bn); if (ippStsNoErr != sts) break; sts = ippsGetOctString_BN(sig->y.data, sizeof(sig->y), bn_sig_y->ipp_bn); if (ippStsNoErr != sts) break; result = kEpidNoErr; } while (0); DeleteBigNum(&bn_ec_order); DeleteBigNum(&bn_hash); DeleteBigNum(&bn_reg_private); DeleteBigNum(&bn_eph_private); DeleteBigNum(&bn_sig_x); DeleteBigNum(&bn_sig_y); SAFE_FREE(ec_ctx); SAFE_FREE(ecp_eph_public); return result; }