java.lang.Object
org.bouncycastle.pqc.crypto.mlkem.Reduce
Polynomial reduction operations for ML-KEM cryptography. Provides Montgomery reduction and Barrett reduction for polynomial arithmetic.
Constructor Summary
ConstructorsConstructorDescriptionReduce()Both reductions are static and the class holds no fields, so an instance carries nothing; it exists only to give the helper class a documented entry point.Method Summary
All MethodsModifier and TypeMethodDescriptionstatic shortbarretReduce(short a) Barrett-reduces a coefficient into the range -q/2 to q/2.static shortconditionalSubQ(short a) Adds q to a negative coefficient to make it non-negative.static shortmontgomeryReduce(int a) Scales a wide value down into the Montgomery representation.
Constructor Details
Reduce
Reduce()Both reductions are static and the class holds no fields, so an instance carries nothing; it exists only to give the helper class a documented entry point.
Method Details
montgomeryReduce
public static short montgomeryReduce(int a) Scales a wide value down into the Montgomery representation.- Parameters:
a- the value to reduce, wide enough to hold the intermediate product- Returns:
- a scaled down into the Montgomery representation, as a short
barretReduce
public static short barretReduce(short a) Barrett-reduces a coefficient into the range -q/2 to q/2.- Parameters:
a- the coefficient to centre into the range -q/2 to q/2- Returns:
- the reduced coefficient, as a short
conditionalSubQ
public static short conditionalSubQ(short a) Adds q to a negative coefficient to make it non-negative.- Parameters:
a- the coefficient that may need q subtracting to become non-negative- Returns:
- a if it was already non-negative, otherwise a plus q, as a short