| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
package net.i2p.crypto.eddsa.math.bigint; |
| 13 |
|
| 14 |
import java.math.BigInteger; |
| 15 |
|
| 16 |
import net.i2p.crypto.eddsa.math.Field; |
| 17 |
import net.i2p.crypto.eddsa.math.ScalarOps; |
| 18 |
|
| 19 |
public class BigIntegerScalarOps implements ScalarOps { |
| 20 |
private final BigInteger l; |
| 21 |
private final BigIntegerLittleEndianEncoding enc; |
| 22 |
|
| 23 |
public BigIntegerScalarOps(Field f, BigInteger l) { |
| 24 |
this.l = l; |
| 25 |
enc = new BigIntegerLittleEndianEncoding(); |
| 26 |
enc.setField(f); |
| 27 |
} |
| 28 |
|
| 29 |
public byte[] reduce(byte[] s) { |
| 30 |
return enc.encode(enc.toBigInteger(s).mod(l)); |
| 31 |
} |
| 32 |
|
| 33 |
public byte[] multiplyAndAdd(byte[] a, byte[] b, byte[] c) { |
| 34 |
return enc.encode(enc.toBigInteger(a).multiply(enc.toBigInteger(b)).add(enc.toBigInteger(c)).mod(l)); |
| 35 |
} |
| 36 |
|
| 37 |
} |