BigIntegerScalarOps.java 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * EdDSA-Java by str4d
  3. *
  4. * To the extent possible under law, the person who associated CC0 with
  5. * EdDSA-Java has waived all copyright and related or neighboring rights
  6. * to EdDSA-Java.
  7. *
  8. * You should have received a copy of the CC0 legalcode along with this
  9. * work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
  10. *
  11. */
  12. package com.fuzamei.eddsa.math.bigint;
  13. import java.math.BigInteger;
  14. import com.fuzamei.eddsa.math.Field;
  15. import com.fuzamei.eddsa.math.ScalarOps;
  16. public class BigIntegerScalarOps implements ScalarOps {
  17. private final BigInteger l;
  18. private final BigIntegerLittleEndianEncoding enc;
  19. public BigIntegerScalarOps(Field f, BigInteger l) {
  20. this.l = l;
  21. enc = new BigIntegerLittleEndianEncoding();
  22. enc.setField(f);
  23. }
  24. public byte[] reduce(byte[] s) {
  25. return enc.encode(enc.toBigInteger(s).mod(l));
  26. }
  27. public byte[] multiplyAndAdd(byte[] a, byte[] b, byte[] c) {
  28. return enc.encode(enc.toBigInteger(a).multiply(enc.toBigInteger(b)).add(enc.toBigInteger(c)).mod(l));
  29. }
  30. }