@@ -167,49 +167,59 @@ impl FieldElement {
167
167
}
168
168
169
169
/// Add elements.
170
- pub ( crate ) const fn add ( & self , rhs : & Self ) -> LooseFieldElement {
170
+ #[ allow( dead_code) ] // TODO(tarcieri): use this
171
+ pub ( crate ) const fn add_loose ( & self , rhs : & Self ) -> LooseFieldElement {
171
172
LooseFieldElement ( fiat_p521_add ( & self . 0 , & rhs. 0 ) )
172
173
}
173
174
174
- /// Subtract elements.
175
- pub ( crate ) const fn sub ( & self , rhs : & Self ) -> LooseFieldElement {
175
+ /// Double element (add it to itself).
176
+ #[ allow( dead_code) ] // TODO(tarcieri): use this
177
+ #[ must_use]
178
+ pub ( crate ) const fn double_loose ( & self ) -> LooseFieldElement {
179
+ Self :: add_loose ( self , self )
180
+ }
181
+
182
+ /// Subtract elements, returning a loose field element.
183
+ #[ allow( dead_code) ] // TODO(tarcieri): use this
184
+ pub ( crate ) const fn sub_loose ( & self , rhs : & Self ) -> LooseFieldElement {
176
185
LooseFieldElement ( fiat_p521_sub ( & self . 0 , & rhs. 0 ) )
177
186
}
178
187
179
- /// Negate element.
180
- pub ( crate ) const fn neg ( & self ) -> LooseFieldElement {
188
+ /// Negate element, returning a loose field element.
189
+ #[ allow( dead_code) ] // TODO(tarcieri): use this
190
+ pub ( crate ) const fn neg_loose ( & self ) -> LooseFieldElement {
181
191
LooseFieldElement ( fiat_p521_opp ( & self . 0 ) )
182
192
}
183
193
184
- /// Add elements and carry .
185
- pub const fn add_carry ( & self , rhs : & Self ) -> Self {
186
- self . add ( rhs) . carry ( )
194
+ /// Add two field elements .
195
+ pub const fn add ( & self , rhs : & Self ) -> Self {
196
+ Self ( fiat_p521_carry_add ( & self . 0 , & rhs. 0 ) )
187
197
}
188
198
189
- /// Subtract elements and carry .
190
- pub const fn sub_carry ( & self , rhs : & Self ) -> Self {
191
- self . sub ( rhs) . carry ( )
199
+ /// Subtract field elements .
200
+ pub const fn sub ( & self , rhs : & Self ) -> Self {
201
+ Self ( fiat_p521_carry_sub ( & self . 0 , & rhs. 0 ) )
192
202
}
193
203
194
- /// Negate element and carry .
195
- pub const fn neg_carry ( & self ) -> Self {
196
- self . neg ( ) . carry ( )
204
+ /// Negate element.
205
+ pub const fn neg ( & self ) -> Self {
206
+ Self ( fiat_p521_carry_opp ( & self . 0 ) )
197
207
}
198
208
199
209
/// Double element (add it to itself).
200
210
#[ must_use]
201
211
pub const fn double ( & self ) -> Self {
202
- self . add_carry ( self )
212
+ self . add ( self )
203
213
}
204
214
205
215
/// Multiply elements.
206
- pub const fn multiply ( & self , rhs : & Self ) -> Self {
207
- self . relax ( ) . carry_mul ( & rhs. relax ( ) )
216
+ pub const fn mul ( & self , rhs : & Self ) -> Self {
217
+ LooseFieldElement :: mul ( & self . relax ( ) , & rhs. relax ( ) )
208
218
}
209
219
210
220
/// Square element.
211
221
pub const fn square ( & self ) -> Self {
212
- self . relax ( ) . carry_square ( )
222
+ self . relax ( ) . square ( )
213
223
}
214
224
215
225
/// Returns `self^exp`, where `exp` is a little-endian integer exponent.
@@ -230,7 +240,7 @@ impl FieldElement {
230
240
res = res. square ( ) ;
231
241
232
242
if ( ( exp[ i] >> j) & 1 ) == 1 {
233
- res = res . multiply ( self ) ;
243
+ res = Self :: mul ( & res , self ) ;
234
244
}
235
245
}
236
246
}
@@ -393,7 +403,7 @@ impl Add for FieldElement {
393
403
394
404
#[ inline]
395
405
fn add ( self , rhs : FieldElement ) -> FieldElement {
396
- self . add_carry ( & rhs)
406
+ Self :: add ( & self , & rhs)
397
407
}
398
408
}
399
409
@@ -402,7 +412,7 @@ impl Add<&FieldElement> for FieldElement {
402
412
403
413
#[ inline]
404
414
fn add ( self , rhs : & FieldElement ) -> FieldElement {
405
- self . add_carry ( rhs)
415
+ Self :: add ( & self , rhs)
406
416
}
407
417
}
408
418
@@ -411,7 +421,7 @@ impl Add<&FieldElement> for &FieldElement {
411
421
412
422
#[ inline]
413
423
fn add ( self , rhs : & FieldElement ) -> FieldElement {
414
- self . add_carry ( rhs)
424
+ FieldElement :: add ( self , rhs)
415
425
}
416
426
}
417
427
@@ -434,7 +444,7 @@ impl Sub for FieldElement {
434
444
435
445
#[ inline]
436
446
fn sub ( self , rhs : FieldElement ) -> FieldElement {
437
- self . sub_carry ( & rhs)
447
+ Self :: sub ( & self , & rhs)
438
448
}
439
449
}
440
450
@@ -443,7 +453,7 @@ impl Sub<&FieldElement> for FieldElement {
443
453
444
454
#[ inline]
445
455
fn sub ( self , rhs : & FieldElement ) -> FieldElement {
446
- self . sub_carry ( rhs)
456
+ Self :: sub ( & self , rhs)
447
457
}
448
458
}
449
459
@@ -452,7 +462,7 @@ impl Sub<&FieldElement> for &FieldElement {
452
462
453
463
#[ inline]
454
464
fn sub ( self , rhs : & FieldElement ) -> FieldElement {
455
- self . sub_carry ( rhs)
465
+ FieldElement :: sub ( self , rhs)
456
466
}
457
467
}
458
468
@@ -475,7 +485,7 @@ impl Mul for FieldElement {
475
485
476
486
#[ inline]
477
487
fn mul ( self , rhs : FieldElement ) -> FieldElement {
478
- self . relax ( ) . carry_mul ( & rhs. relax ( ) )
488
+ self . relax ( ) . mul ( & rhs. relax ( ) )
479
489
}
480
490
}
481
491
@@ -484,7 +494,7 @@ impl Mul<&FieldElement> for FieldElement {
484
494
485
495
#[ inline]
486
496
fn mul ( self , rhs : & FieldElement ) -> FieldElement {
487
- self . relax ( ) . carry_mul ( & rhs. relax ( ) )
497
+ self . relax ( ) . mul ( & rhs. relax ( ) )
488
498
}
489
499
}
490
500
@@ -493,7 +503,7 @@ impl Mul<&FieldElement> for &FieldElement {
493
503
494
504
#[ inline]
495
505
fn mul ( self , rhs : & FieldElement ) -> FieldElement {
496
- self . relax ( ) . carry_mul ( & rhs. relax ( ) )
506
+ self . relax ( ) . mul ( & rhs. relax ( ) )
497
507
}
498
508
}
499
509
@@ -516,7 +526,7 @@ impl Neg for FieldElement {
516
526
517
527
#[ inline]
518
528
fn neg ( self ) -> FieldElement {
519
- self . neg_carry ( )
529
+ Self :: neg ( & self )
520
530
}
521
531
}
522
532
0 commit comments