📄 basics.xml
字号:
<chapter><title>PBC Basics</title><para>This chapter gives a high-level view of the library, and explainsvarious design choices and conventions.</para><section><title>Headers and Libraries</title><para>Programs using the PBC library should include the file<filename>pbc.h</filename>:</para><programlisting>#include <pbc.h></programlisting><para>and linked against the PBC library, e.g.</para><screen>gcc program.c -L. -lpbc</screen><para>The file <filename>pbc.h</filename> includes <filename>gmp.h</filename>thus all GMP functions are available.</para><para>To catch certain bugs, first define the PBC_DEBUG symbol before including<filename>pbc.h</filename>:</para><programlisting>#define PBC_DEBUG#include <pbc.h></programlisting><para>The program will now abort when PBC detects a statement incorrectlymixing elements from different algebraic structures. Note these checks areperformed at runtime, so this feature should be disabled for productionbuilds.</para></section><section><title>Types</title><para>Since the PBC library is built on top of GMP, the GMP typesare available. PBC types are similar to GMP types.The following example is paraphrased from an example in the GMPmanual, and shows how to declare the PBC data type<type>element_t</type>.</para><programlisting> element_t sum; struct foo { element_t x, y; }; element_t vec[20];</programlisting><para>The <type>pairing_t</type> data type holds bilinear pairingparameter information. There are other data types but for manypairing-based cryptography applications they are only needed internally.</para><para>Examples of other data types defined by PBC are <type>field_t</type>for rings and fields and <type>mpc_t</type> for complex arbitraryprecision floats.</para></section><section><title>Function Classes</title><para>PBC contains several classes of functions.</para><orderedlist> <listitem><para>Functions for dealing with bilinear pairing parameters begin with<function>pairing_</function>.</para> </listitem> <listitem><para>Functions for operating on elements of groups, rings and fields beginwith <function>element_</function>.</para> </listitem> <listitem><para>Functions that generate pairing parameters, that is, find elliptic curveswhere efficiently computable bilinear pairings exist.The sample parameters bundledare adequate for many cryptosystems, but there may be a need to generatemore.</para> </listitem> <listitem><para>Miscellaneous functions, such as ones controlling how random bits aregenerated.</para> </listitem> <listitem><para>Auxiliary functions that work on abstract data types such dynamicarrays and symbol tables mostly used internally by PBC, but may have someuse in applications.</para> </listitem></orderedlist></section><section><title>Conventions</title><para>PBC follows GMP in several respects:</para><orderedlist> <listitem><para>Output arguments generally precede input arguments.</para> </listitem> <listitem><para>The same variable can be used as input and output in one call.</para> </listitem> <listitem><para>Before a variable may be used it must be initialized exactly once.When no longer needed it must be cleared. For efficiency, unnecessaryinitializating and clearing should be avoided.</para> </listitem> <listitem><para>PBC variables ending with <type>_t</type> behave the same asGMP variables in function calls, that is effectively as call-by references.In other words, as in GMP, if a function that modifies an input variable,that variable remains modified when control return is returned to the caller.</para> </listitem> <listitem><para>Like GMP, variables automatically allocate memory when needed.By default. <function>malloc()</function> and friendsare called but this can be changed.</para> </listitem> <listitem><para>The <type>element_t</type> type is small (but certain other typesare not).</para> </listitem> <listitem><para>PBC functions are mostly reentrant.</para> </listitem></orderedlist><para>Recall GMP has the <type>mpz_t</type> type for integers, <type>mpq_t</type> forrationals and so on.In contrast, PBC uses the <type>element_t</type>data type for elements of differentalgebraic structures, such as elliptic curve groups, polynomial ringsand finite fields. Many functions assume the inputs come from thesame algebraic structure and trouble can arise if for example oneattempts to add a polynomial to a point on an elliptic curve.</para><para>The algebraic structure that an <type>element_t</type> variable belongsto is specified in an initialization call.</para></section></chapter>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -