📄 elementfns.xml
字号:
<chapter><title>Element Functions</title><para>Elements of groups, rings and fields are stored in the <type>element_t</type>data type. Variables of this typemust be initialized before use, and should be cleared after they are no longerneeded.</para><para>The <function>element_</function> functions must be used with caution.Just as division by zero does not make sense for integers,some operations may not make sense for particular elements. For example,in a ring, one cannot in general invert elements.</para><para>Another caveat is that many of these functions assume their arguments comefrom the same ring, group or field. No implicit type casting is performed.</para><para>Because of the way PBC is designed, checking that elementsfrom different algberaic structures have not been mistakenly mixed isnot easy to do at compile-time. Instead, runtime checks are performed ifPBC_DEBUG is defined before the PBC header file is included:</para><programlisting>#define PBC_DEBUG#include <pbc.h></programlisting><para>Note performance will be impaired, so this debugging features should bedisabled in the final build.</para><section><title>Initializing Elements</title><para>When an element is initialized it is associated with an algebraic structure,such as a particular finite field or elliptic curve group.</para><variablelist>&einit;</variablelist></section><section><title>Assigning Elements</title><para>These functions assign values to elements. When integers are assigned,they are mapped to algebraic structures canonically if it makes sense(e.g. rings and fields).</para><variablelist>&eassign;</variablelist></section><section><title>Converting Elements</title><variablelist>&econvert;</variablelist></section><section><title>Element Arithmetic</title><para>Unless otherwise stated,all <type>element_t</type> arguments to these functions must have beeninitialized to be from the same algebraic structure.When one of these functions expects its arguments to be fromparticular algebraic structures, this is reflected in the name of thefunction.</para><para>The addition and multiplication functions perform addition and multiplicationoperations in rings and fields. For groups of points on an ellitpic curve,such as the G1 and G2 groups associated with pairings, both addition andmultiplication represent the group operation (and similarly both 0 and 1represent the identity element).It is recommended that programs choose andone convention and stick with it to avoid confusion.</para><para>In contrast, the GT group is currentlyimplemented as a subgroup of a finite field, so only multiplicative operationsshould be used for GT.</para><variablelist>&earith;</variablelist></section><section><title>Exponentiating Elements</title><para>Exponentiation and multiexponentiation functions.If it is known in advance that a particular element will be exponentiatedseveral times in the future, time can be saved in the long run byfirst calling the preprocessing function:</para><screen> element_pp_t g_pp; element_pp_init(g_pp, g); element_pp_pow(h, pow1, g_pp); // h = g^pow1 element_pp_pow(h, pow2, g_pp); // h = g^pow2 element_pp_pow(h, pow3, g_pp); // h = g^pow3 element_pp_clear(g_pp);</screen><variablelist>&epow;</variablelist></section><section><title>Comparing Elements</title><para>These functions compare elements from the same algebraic structure.</para><variablelist>&ecmp;</variablelist></section><section><title>I/O of Elements</title><para>Functions for producing human-readable outputs for elements.Converting elements to and from bytes are discussed later.</para><variablelist>&eio;</variablelist></section><section><title>Random Elements</title><para>Only works for finite algebraic structures. Effecton polynomial rings, fields of characteristic zero, etc. undefined.</para><para>See the chapter on randomness functions on where PBC gets random bitsfrom and how to select a different source of random bits.</para><variablelist>&erandom;</variablelist></section><section><title>Element Import/Export</title><para>Functions for serializing and deserializing elements.</para><variablelist>&etrade;</variablelist></section></chapter>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -