Crypto++ 8.6
Free C++ class library of cryptographic schemes
ecp.cpp
1// ecp.cpp - originally written and placed in the public domain by Wei Dai
2
3#include "pch.h"
4
5#ifndef CRYPTOPP_IMPORTS
6
7#include "ecp.h"
8#include "asn.h"
9#include "integer.h"
10#include "nbtheory.h"
11#include "modarith.h"
12#include "filters.h"
13#include "algebra.cpp"
14
15ANONYMOUS_NAMESPACE_BEGIN
16
17using CryptoPP::ECP;
18using CryptoPP::Integer;
19using CryptoPP::ModularArithmetic;
20
21#if defined(HAVE_GCC_INIT_PRIORITY)
22 #define INIT_ATTRIBUTE __attribute__ ((init_priority (CRYPTOPP_INIT_PRIORITY + 50)))
23 const ECP::Point g_identity INIT_ATTRIBUTE = ECP::Point();
24#elif defined(HAVE_MSC_INIT_PRIORITY)
25 #pragma warning(disable: 4075)
26 #pragma init_seg(".CRT$XCU")
27 const ECP::Point g_identity;
28 #pragma warning(default: 4075)
29#elif defined(HAVE_XLC_INIT_PRIORITY)
30 #pragma priority(290)
31 const ECP::Point g_identity;
32#endif
33
34inline ECP::Point ToMontgomery(const ModularArithmetic &mr, const ECP::Point &P)
35{
36 return P.identity ? P : ECP::Point(mr.ConvertIn(P.x), mr.ConvertIn(P.y));
37}
38
39inline ECP::Point FromMontgomery(const ModularArithmetic &mr, const ECP::Point &P)
40{
41 return P.identity ? P : ECP::Point(mr.ConvertOut(P.x), mr.ConvertOut(P.y));
42}
43
44inline Integer IdentityToInteger(bool val)
45{
46 return val ? Integer::One() : Integer::Zero();
47}
48
49struct ProjectivePoint
50{
51 ProjectivePoint() {}
52 ProjectivePoint(const Integer &x, const Integer &y, const Integer &z)
53 : x(x), y(y), z(z) {}
54
55 Integer x, y, z;
56};
57
58ANONYMOUS_NAMESPACE_END
59
60NAMESPACE_BEGIN(CryptoPP)
61
62ECP::ECP(const ECP &ecp, bool convertToMontgomeryRepresentation)
63{
64 if (convertToMontgomeryRepresentation && !ecp.GetField().IsMontgomeryRepresentation())
65 {
66 m_fieldPtr.reset(new MontgomeryRepresentation(ecp.GetField().GetModulus()));
67 m_a = GetField().ConvertIn(ecp.m_a);
68 m_b = GetField().ConvertIn(ecp.m_b);
69 }
70 else
71 operator=(ecp);
72}
73
75 : m_fieldPtr(new Field(bt))
76{
77 BERSequenceDecoder seq(bt);
78 GetField().BERDecodeElement(seq, m_a);
79 GetField().BERDecodeElement(seq, m_b);
80 // skip optional seed
81 if (!seq.EndReached())
82 {
83 SecByteBlock seed;
84 unsigned int unused;
85 BERDecodeBitString(seq, seed, unused);
86 }
87 seq.MessageEnd();
88}
89
91{
92 GetField().DEREncode(bt);
93 DERSequenceEncoder seq(bt);
94 GetField().DEREncodeElement(seq, m_a);
95 GetField().DEREncodeElement(seq, m_b);
96 seq.MessageEnd();
97}
98
99bool ECP::DecodePoint(ECP::Point &P, const byte *encodedPoint, size_t encodedPointLen) const
100{
101 StringStore store(encodedPoint, encodedPointLen);
102 return DecodePoint(P, store, encodedPointLen);
103}
104
105bool ECP::DecodePoint(ECP::Point &P, BufferedTransformation &bt, size_t encodedPointLen) const
106{
107 byte type;
108 if (encodedPointLen < 1 || !bt.Get(type))
109 return false;
110
111 switch (type)
112 {
113 case 0:
114 P.identity = true;
115 return true;
116 case 2:
117 case 3:
118 {
119 if (encodedPointLen != EncodedPointSize(true))
120 return false;
121
122 // Check for p is prime due to GH #1249
123 const Integer p = FieldSize();
125 if (!IsPrime(p))
126 return false;
127
128 P.identity = false;
129 P.x.Decode(bt, GetField().MaxElementByteLength());
130 P.y = ((P.x*P.x+m_a)*P.x+m_b) % p;
131
132 if (Jacobi(P.y, p) !=1)
133 return false;
134
135 P.y = ModularSquareRoot(P.y, p);
136
137 if ((type & 1) != P.y.GetBit(0))
138 P.y = p-P.y;
139
140 return true;
141 }
142 case 4:
143 {
144 if (encodedPointLen != EncodedPointSize(false))
145 return false;
146
147 unsigned int len = GetField().MaxElementByteLength();
148 P.identity = false;
149 P.x.Decode(bt, len);
150 P.y.Decode(bt, len);
151 return true;
152 }
153 default:
154 return false;
155 }
156}
157
158void ECP::EncodePoint(BufferedTransformation &bt, const Point &P, bool compressed) const
159{
160 if (P.identity)
161 NullStore().TransferTo(bt, EncodedPointSize(compressed));
162 else if (compressed)
163 {
164 bt.Put((byte)(2U + P.y.GetBit(0)));
165 P.x.Encode(bt, GetField().MaxElementByteLength());
166 }
167 else
168 {
169 unsigned int len = GetField().MaxElementByteLength();
170 bt.Put(4U); // uncompressed
171 P.x.Encode(bt, len);
172 P.y.Encode(bt, len);
173 }
174}
175
176void ECP::EncodePoint(byte *encodedPoint, const Point &P, bool compressed) const
177{
178 ArraySink sink(encodedPoint, EncodedPointSize(compressed));
179 EncodePoint(sink, P, compressed);
180 CRYPTOPP_ASSERT(sink.TotalPutLength() == EncodedPointSize(compressed));
181}
182
184{
185 SecByteBlock str;
186 BERDecodeOctetString(bt, str);
187 Point P;
188 if (!DecodePoint(P, str, str.size()))
190 return P;
191}
192
193void ECP::DEREncodePoint(BufferedTransformation &bt, const Point &P, bool compressed) const
194{
195 SecByteBlock str(EncodedPointSize(compressed));
196 EncodePoint(str, P, compressed);
197 DEREncodeOctetString(bt, str);
198}
199
200bool ECP::ValidateParameters(RandomNumberGenerator &rng, unsigned int level) const
201{
202 Integer p = FieldSize();
203
204 bool pass = p.IsOdd();
205 pass = pass && !m_a.IsNegative() && m_a<p && !m_b.IsNegative() && m_b<p;
206
207 if (level >= 1)
208 pass = pass && ((4*m_a*m_a*m_a+27*m_b*m_b)%p).IsPositive();
209
210 if (level >= 2)
211 pass = pass && VerifyPrime(rng, p);
212
213 return pass;
214}
215
216bool ECP::VerifyPoint(const Point &P) const
217{
218 const FieldElement &x = P.x, &y = P.y;
219 Integer p = FieldSize();
220 return P.identity ||
221 (!x.IsNegative() && x<p && !y.IsNegative() && y<p
222 && !(((x*x+m_a)*x+m_b-y*y)%p));
223}
224
225bool ECP::Equal(const Point &P, const Point &Q) const
226{
227 if (P.identity && Q.identity)
228 return true;
229
230 if (P.identity && !Q.identity)
231 return false;
232
233 if (!P.identity && Q.identity)
234 return false;
235
236 return (GetField().Equal(P.x,Q.x) && GetField().Equal(P.y,Q.y));
237}
238
239const ECP::Point& ECP::Identity() const
240{
241#if defined(HAVE_GCC_INIT_PRIORITY) || defined(HAVE_MSC_INIT_PRIORITY) || defined(HAVE_XLC_INIT_PRIORITY)
242 return g_identity;
243#elif defined(CRYPTOPP_CXX11_STATIC_INIT)
244 static const ECP::Point g_identity;
245 return g_identity;
246#else
247 return Singleton<Point>().Ref();
248#endif
249}
250
251const ECP::Point& ECP::Inverse(const Point &P) const
252{
253 if (P.identity)
254 return P;
255 else
256 {
257 m_R.identity = false;
258 m_R.x = P.x;
259 m_R.y = GetField().Inverse(P.y);
260 return m_R;
261 }
262}
263
264const ECP::Point& ECP::Add(const Point &P, const Point &Q) const
265{
266 if (P.identity) return Q;
267 if (Q.identity) return P;
268 if (GetField().Equal(P.x, Q.x))
269 return GetField().Equal(P.y, Q.y) ? Double(P) : Identity();
270
271 FieldElement t = GetField().Subtract(Q.y, P.y);
272 t = GetField().Divide(t, GetField().Subtract(Q.x, P.x));
273 FieldElement x = GetField().Subtract(GetField().Subtract(GetField().Square(t), P.x), Q.x);
274 m_R.y = GetField().Subtract(GetField().Multiply(t, GetField().Subtract(P.x, x)), P.y);
275
276 m_R.x.swap(x);
277 m_R.identity = false;
278 return m_R;
279}
280
281const ECP::Point& ECP::Double(const Point &P) const
282{
283 if (P.identity || P.y==GetField().Identity()) return Identity();
284
285 FieldElement t = GetField().Square(P.x);
286 t = GetField().Add(GetField().Add(GetField().Double(t), t), m_a);
287 t = GetField().Divide(t, GetField().Double(P.y));
288 FieldElement x = GetField().Subtract(GetField().Subtract(GetField().Square(t), P.x), P.x);
289 m_R.y = GetField().Subtract(GetField().Multiply(t, GetField().Subtract(P.x, x)), P.y);
290
291 m_R.x.swap(x);
292 m_R.identity = false;
293 return m_R;
294}
295
296template <class T, class Iterator> void ParallelInvert(const AbstractRing<T> &ring, Iterator begin, Iterator end)
297{
298 size_t n = end-begin;
299 if (n == 1)
300 *begin = ring.MultiplicativeInverse(*begin);
301 else if (n > 1)
302 {
303 std::vector<T> vec((n+1)/2);
304 unsigned int i;
305 Iterator it;
306
307 for (i=0, it=begin; i<n/2; i++, it+=2)
308 vec[i] = ring.Multiply(*it, *(it+1));
309 if (n%2 == 1)
310 vec[n/2] = *it;
311
312 ParallelInvert(ring, vec.begin(), vec.end());
313
314 for (i=0, it=begin; i<n/2; i++, it+=2)
315 {
316 if (!vec[i])
317 {
318 *it = ring.MultiplicativeInverse(*it);
319 *(it+1) = ring.MultiplicativeInverse(*(it+1));
320 }
321 else
322 {
323 std::swap(*it, *(it+1));
324 *it = ring.Multiply(*it, vec[i]);
325 *(it+1) = ring.Multiply(*(it+1), vec[i]);
326 }
327 }
328 if (n%2 == 1)
329 *it = vec[n/2];
330 }
331}
332
333class ProjectiveDoubling
334{
335public:
336 ProjectiveDoubling(const ModularArithmetic &m_mr, const Integer &m_a, const Integer &m_b, const ECPPoint &Q)
337 : mr(m_mr)
338 {
339 CRYPTOPP_UNUSED(m_b);
340 if (Q.identity)
341 {
342 sixteenY4 = P.x = P.y = mr.MultiplicativeIdentity();
343 aZ4 = P.z = mr.Identity();
344 }
345 else
346 {
347 P.x = Q.x;
348 P.y = Q.y;
349 sixteenY4 = P.z = mr.MultiplicativeIdentity();
350 aZ4 = m_a;
351 }
352 }
353
354 void Double()
355 {
356 twoY = mr.Double(P.y);
357 P.z = mr.Multiply(P.z, twoY);
358 fourY2 = mr.Square(twoY);
359 S = mr.Multiply(fourY2, P.x);
360 aZ4 = mr.Multiply(aZ4, sixteenY4);
361 M = mr.Square(P.x);
362 M = mr.Add(mr.Add(mr.Double(M), M), aZ4);
363 P.x = mr.Square(M);
364 mr.Reduce(P.x, S);
365 mr.Reduce(P.x, S);
366 mr.Reduce(S, P.x);
367 P.y = mr.Multiply(M, S);
368 sixteenY4 = mr.Square(fourY2);
369 mr.Reduce(P.y, mr.Half(sixteenY4));
370 }
371
372 const ModularArithmetic &mr;
373 ProjectivePoint P;
374 Integer sixteenY4, aZ4, twoY, fourY2, S, M;
375};
376
377struct ZIterator
378{
379 ZIterator() {}
380 ZIterator(std::vector<ProjectivePoint>::iterator it) : it(it) {}
381 Integer& operator*() {return it->z;}
382 int operator-(ZIterator it2) {return int(it-it2.it);}
383 ZIterator operator+(int i) {return ZIterator(it+i);}
384 ZIterator& operator+=(int i) {it+=i; return *this;}
385 std::vector<ProjectivePoint>::iterator it;
386};
387
388ECP::Point ECP::ScalarMultiply(const Point &P, const Integer &k) const
389{
390 Element result;
391 if (k.BitCount() <= 5)
393 else
394 ECP::SimultaneousMultiply(&result, P, &k, 1);
395 return result;
396}
397
398void ECP::SimultaneousMultiply(ECP::Point *results, const ECP::Point &P, const Integer *expBegin, unsigned int expCount) const
399{
400 if (!GetField().IsMontgomeryRepresentation())
401 {
402 ECP ecpmr(*this, true);
403 const ModularArithmetic &mr = ecpmr.GetField();
404 ecpmr.SimultaneousMultiply(results, ToMontgomery(mr, P), expBegin, expCount);
405 for (unsigned int i=0; i<expCount; i++)
406 results[i] = FromMontgomery(mr, results[i]);
407 return;
408 }
409
410 ProjectiveDoubling rd(GetField(), m_a, m_b, P);
411 std::vector<ProjectivePoint> bases;
412 std::vector<WindowSlider> exponents;
413 exponents.reserve(expCount);
414 std::vector<std::vector<word32> > baseIndices(expCount);
415 std::vector<std::vector<bool> > negateBase(expCount);
416 std::vector<std::vector<word32> > exponentWindows(expCount);
417 unsigned int i;
418
419 for (i=0; i<expCount; i++)
420 {
421 CRYPTOPP_ASSERT(expBegin->NotNegative());
422 exponents.push_back(WindowSlider(*expBegin++, InversionIsFast(), 5));
423 exponents[i].FindNextWindow();
424 }
425
426 unsigned int expBitPosition = 0;
427 bool notDone = true;
428
429 while (notDone)
430 {
431 notDone = false;
432 bool baseAdded = false;
433 for (i=0; i<expCount; i++)
434 {
435 if (!exponents[i].finished && expBitPosition == exponents[i].windowBegin)
436 {
437 if (!baseAdded)
438 {
439 bases.push_back(rd.P);
440 baseAdded =true;
441 }
442
443 exponentWindows[i].push_back(exponents[i].expWindow);
444 baseIndices[i].push_back((word32)bases.size()-1);
445 negateBase[i].push_back(exponents[i].negateNext);
446
447 exponents[i].FindNextWindow();
448 }
449 notDone = notDone || !exponents[i].finished;
450 }
451
452 if (notDone)
453 {
454 rd.Double();
455 expBitPosition++;
456 }
457 }
458
459 // convert from projective to affine coordinates
460 ParallelInvert(GetField(), ZIterator(bases.begin()), ZIterator(bases.end()));
461 for (i=0; i<bases.size(); i++)
462 {
463 if (bases[i].z.NotZero())
464 {
465 bases[i].y = GetField().Multiply(bases[i].y, bases[i].z);
466 bases[i].z = GetField().Square(bases[i].z);
467 bases[i].x = GetField().Multiply(bases[i].x, bases[i].z);
468 bases[i].y = GetField().Multiply(bases[i].y, bases[i].z);
469 }
470 }
471
472 std::vector<BaseAndExponent<Point, Integer> > finalCascade;
473 for (i=0; i<expCount; i++)
474 {
475 finalCascade.resize(baseIndices[i].size());
476 for (unsigned int j=0; j<baseIndices[i].size(); j++)
477 {
478 ProjectivePoint &base = bases[baseIndices[i][j]];
479 if (base.z.IsZero())
480 finalCascade[j].base.identity = true;
481 else
482 {
483 finalCascade[j].base.identity = false;
484 finalCascade[j].base.x = base.x;
485 if (negateBase[i][j])
486 finalCascade[j].base.y = GetField().Inverse(base.y);
487 else
488 finalCascade[j].base.y = base.y;
489 }
490 finalCascade[j].exponent = Integer(Integer::POSITIVE, 0, exponentWindows[i][j]);
491 }
492 results[i] = GeneralCascadeMultiplication(*this, finalCascade.begin(), finalCascade.end());
493 }
494}
495
496ECP::Point ECP::CascadeScalarMultiply(const Point &P, const Integer &k1, const Point &Q, const Integer &k2) const
497{
498 if (!GetField().IsMontgomeryRepresentation())
499 {
500 ECP ecpmr(*this, true);
501 const ModularArithmetic &mr = ecpmr.GetField();
502 return FromMontgomery(mr, ecpmr.CascadeScalarMultiply(ToMontgomery(mr, P), k1, ToMontgomery(mr, Q), k2));
503 }
504 else
506}
507
508NAMESPACE_END
509
510#endif
Classes and functions for working with ANS.1 objects.
CRYPTOPP_DLL size_t BERDecodeBitString(BufferedTransformation &bt, SecByteBlock &str, unsigned int &unusedBits)
DER decode bit string.
OID operator+(const OID &lhs, unsigned long rhs)
Append a value to an OID.
CRYPTOPP_DLL size_t DEREncodeOctetString(BufferedTransformation &bt, const byte *str, size_t strLen)
DER encode octet string.
CRYPTOPP_DLL size_t BERDecodeOctetString(BufferedTransformation &bt, SecByteBlock &str)
BER decode octet string.
void BERDecodeError()
Raises a BERDecodeErr.
Definition: asn.h:104
virtual Element CascadeScalarMultiply(const Element &x, const Integer &e1, const Element &y, const Integer &e2) const
TODO.
Definition: algebra.cpp:97
virtual void SimultaneousMultiply(Element *results, const Element &base, const Integer *exponents, unsigned int exponentsCount) const
Multiplies a base to multiple exponents in a group.
Definition: algebra.cpp:256
virtual const Element & Subtract(const Element &a, const Element &b) const
Subtracts elements in the group.
Definition: algebra.cpp:20
Abstract ring.
Definition: algebra.h:119
virtual const Element & Multiply(const Element &a, const Element &b) const =0
Multiplies elements in the group.
virtual const Element & MultiplicativeInverse(const Element &a) const =0
Calculate the multiplicative inverse of an element in the group.
Copy input to a memory buffer.
Definition: filters.h:1200
BER Sequence Decoder.
Definition: asn.h:525
Interface for buffered transformations.
Definition: cryptlib.h:1652
virtual size_t Get(byte &outByte)
Retrieve a 8-bit byte.
lword TransferTo(BufferedTransformation &target, lword transferMax=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL)
move transferMax bytes of the buffered output to target as input
Definition: cryptlib.h:1991
size_t Put(byte inByte, bool blocking=true)
Input a byte for processing.
Definition: cryptlib.h:1673
DER Sequence Encoder.
Definition: asn.h:557
Elliptic Curve over GF(p), where p is prime.
Definition: ecp.h:27
bool InversionIsFast() const
Determine if inversion is fast.
Definition: ecp.h:75
const Point & Double(const Point &P) const
Doubles an element in the group.
Point ScalarMultiply(const Point &P, const Integer &k) const
Performs a scalar multiplication.
void EncodePoint(byte *encodedPoint, const Point &P, bool compressed) const
Encodes an elliptic curve point.
ECP()
Construct an ECP.
Definition: ecp.h:36
bool Equal(const Point &P, const Point &Q) const
Compare two points.
void DEREncodePoint(BufferedTransformation &bt, const Point &P, bool compressed) const
DER Encodes an elliptic curve point.
bool VerifyPoint(const Point &P) const
Verifies points on elliptic curve.
Point CascadeScalarMultiply(const Point &P, const Integer &k1, const Point &Q, const Integer &k2) const
TODO.
const Point & Inverse(const Point &P) const
Inverts the element in the group.
const Point & Identity() const
Provides the Identity element.
Point BERDecodePoint(BufferedTransformation &bt) const
BER Decodes an elliptic curve point.
unsigned int EncodedPointSize(bool compressed=false) const
Determines encoded point size.
Definition: ecp.h:90
bool DecodePoint(Point &P, BufferedTransformation &bt, size_t len) const
Decodes an elliptic curve point.
void DEREncode(BufferedTransformation &bt) const
DER Encode.
const Point & Add(const Point &P, const Point &Q) const
Adds elements in the group.
void SimultaneousMultiply(Point *results, const Point &base, const Integer *exponents, unsigned int exponentsCount) const
Multiplies a base to multiple exponents in a group.
Multiple precision integer with arithmetic operations.
Definition: integer.h:50
unsigned int BitCount() const
Determines the number of bits required to represent the Integer.
bool NotNegative() const
Determines if the Integer is non-negative.
Definition: integer.h:342
void swap(Integer &a)
Swaps this Integer with another Integer.
bool IsNegative() const
Determines if the Integer is negative.
Definition: integer.h:339
@ POSITIVE
the value is positive or 0
Definition: integer.h:75
bool IsOdd() const
Determines if the Integer is odd parity.
Definition: integer.h:354
static const Integer & One()
Integer representing 1.
Ring of congruence classes modulo n.
Definition: modarith.h:44
const Integer & Square(const Integer &a) const
Square an element in the ring.
Definition: modarith.h:197
const Integer & Inverse(const Integer &a) const
Inverts the element in the ring.
unsigned int MaxElementByteLength() const
Provides the maximum byte size of an element in the ring.
Definition: modarith.h:248
void DEREncodeElement(BufferedTransformation &out, const Element &a) const
Encodes element in DER format.
virtual bool IsMontgomeryRepresentation() const
Retrieves the representation.
Definition: modarith.h:108
bool Equal(const Integer &a, const Integer &b) const
Compare two elements for equality.
Definition: modarith.h:135
const Integer & GetModulus() const
Retrieves the modulus.
Definition: modarith.h:99
const Integer & Multiply(const Integer &a, const Integer &b) const
Multiplies elements in the ring.
Definition: modarith.h:190
virtual Integer ConvertOut(const Integer &a) const
Reduces an element in the congruence class.
Definition: modarith.h:123
const Integer & Subtract(const Integer &a, const Integer &b) const
Subtracts elements in the ring.
const Integer & Divide(const Integer &a, const Integer &b) const
Divides elements in the ring.
Definition: modarith.h:218
const Integer & Add(const Integer &a, const Integer &b) const
Adds elements in the ring.
virtual Integer ConvertIn(const Integer &a) const
Reduces an element in the congruence class.
Definition: modarith.h:115
void DEREncode(BufferedTransformation &bt) const
Encodes in DER format.
Performs modular arithmetic in Montgomery representation for increased speed.
Definition: modarith.h:296
Empty store.
Definition: filters.h:1321
Interface for random number generators.
Definition: cryptlib.h:1435
size_type size() const
Provides the count of elements in the SecBlock.
Definition: secblock.h:867
SecBlock<byte> typedef.
Definition: secblock.h:1226
Restricts the instantiation of a class to one static object without locks.
Definition: misc.h:307
const T & Ref(...) const
Return a reference to the inner Singleton object.
Definition: misc.h:327
Square block cipher.
Definition: square.h:25
String-based implementation of Store interface.
Definition: filters.h:1259
unsigned int word32
32-bit unsigned datatype
Definition: config_int.h:62
Classes for Elliptic Curves over prime fields.
Implementation of BufferedTransformation's attachment interface.
Multiple precision integer with arithmetic operations.
Class file for performing modular arithmetic.
Crypto++ library namespace.
Classes and functions for number theoretic operations.
CRYPTOPP_DLL int Jacobi(const Integer &a, const Integer &b)
Calculate the Jacobi symbol.
CRYPTOPP_DLL bool IsPrime(const Integer &p)
Verifies a number is probably prime.
CRYPTOPP_DLL Integer ModularSquareRoot(const Integer &a, const Integer &p)
Extract a modular square root.
CRYPTOPP_DLL bool VerifyPrime(RandomNumberGenerator &rng, const Integer &p, unsigned int level=1)
Verifies a number is probably prime.
Precompiled header file.
Elliptical Curve Point over GF(p), where p is prime.
Definition: ecpoint.h:21
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
Definition: trap.h:68