bool CppECGroup::IsProbablyValid() const { return IsElement(GetGenerator()) && IsIdentity(Exponentiate(GetGenerator(), GetOrder())) && CryptoPP::IsPrime(_curve.FieldSize()) && GetOrder().IsPrime(); }
Element IntegerGroup::EncodeBytes(const QByteArray &in) const { // We can store p bytes minus 2 bytes for padding and one more to be safe const int can_read = BytesPerElement(); if(can_read < 1) qFatal("Illegal parameters"); if(in.count() > can_read) qFatal("Cannot encode: string is too long"); // Add initial 0xff byte and trailing 0x00 byte QByteArray padded; padded.append(0xff); padded.append(in.left(can_read)); padded.append((char)0x00); padded.append(0xff); // Change byte of padded string until the // integer represented by the byte arry is a quadratic // residue. We need to be sure that every plaintext // message is a quadratic residue modulo p const int last = padded.count()-2; for(unsigned char pad=0x00; pad < 0xff; pad++) { padded[last] = pad; Element element(new IntegerElementData(Integer(padded))); if(IsElement(element)) { return element; } } qFatal("Could not encode message as quadratic residue"); return Element(new IntegerElementData(Integer(1))); }
bool ByteGroup::IsIdentity(const Element &a) const { if(!IsElement(a)) return false; const QByteArray b = GetByteArray(a); const int c = b.count(); qDebug() << "bytes" << b.toHex(); for(int i=0; i<c; i++) { if(b[i] != 0) return false; } return true; }
// // Return a bolean value indicating whether or not the set in question intersects the set passed as argument: "set" // i.e., is there at least one element of set that is also an element of "this" set. // bool SymbolSet::Intersects(SymbolSet &set) { for (int i = 0; i < set.symbol_pool.Length(); i++) { ShadowSymbol *shadow = set.symbol_pool[i]; Symbol *symbol = shadow -> symbol; for (int k = 0; symbol; symbol = (Symbol *) (k < shadow -> NumConflicts() ? shadow -> Conflict(k++) : NULL)) if (IsElement(symbol)) return true; } return false; }
BOOL MemoryPool::IsAllocatedElement(void *element) { if (!IsElement(element)) return FALSE; // // Now, make sure the element isn't // in the free list. // #if _DEBUG // // In a debug build, all objects on the free list // will be marked with deadbeef. This means that // if the object is not deadbeef, it's not on the // free list. // // This check will give us decent performance in // a debug build for FreeElement, since we // always expect to return TRUE in that case. // if (((Element*)element)->deadBeef != (int) 0xdeadBeef) return TRUE; #endif Element *f = m_freeList; while (f != NULL) { if (f == element) return FALSE; f = f->next; } #if _DEBUG // // We should never get here in a debug build, because // all free elements should be deadbeefed. // _ASSERTE(0); #endif return TRUE; }
bool IntegerGroup::IsGenerator(const Element &a) const { return IsElement(a) && ((Exponentiate(a, GetOrder()) == GetIdentity())) && (!(Exponentiate(a, Integer(2)) == GetIdentity())); }