@@ -769,6 +769,73 @@ func TestFieldNormalize(t *testing.T) {
769769 name : "Value > P with redux > P at mag 1 due to 1st and 2nd words and carry to bit 256" ,
770770 raw : [10 ]uint32 {0x03fffc30 , 0x03ffffc0 , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x07ffffff , 0x003fffff },
771771 normalized : [10 ]uint32 {0x00000001 , 0x00000001 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000000 , 0x00000001 },
772+ }, {
773+ // ---------------------------------------------------------------------
774+ // There are 3 main conditions that must be true if the final reduction
775+ // is needed after the initial reduction to magnitude 1 when there was
776+ // NOT a carry to bit 256 (in other words when the original value was <=
777+ // P):
778+ // 1) The final word of the reduced value is equal to the one of P
779+ // 2) The 3rd through 9th words are equal to those of P
780+ // 3) Either:
781+ // - The 2nd word is greater than the one of P; or
782+ // - The 2nd word is equal to that of P AND the 1st word is greater
783+ //
784+ // Therefore the eight possible combinations of those 3 main conditions
785+ // can be thought of in binary where each bit starting from the left
786+ // corresponds to the aforementioned conditions as such:
787+ // 000, 001, 010, 011, 100, 101, 110, 111
788+ //
789+ // For example, combination 6 is when both conditons 1 and 2 are true,
790+ // but condition 3 is NOT true.
791+ //
792+ // The following tests hit each of these combinations and refer to each
793+ // by its decimal equivalent for ease of reference.
794+ //
795+ // NOTE: The final combination (7) is already tested above since it only
796+ // happens when the original value is already the normalized
797+ // representation of P.
798+ // ---------------------------------------------------------------------
799+
800+ name : "Value <= P final reduction combination 0" ,
801+ raw : [10 ]uint32 {0x03fff85e , 0x03ffffbf , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03fffffe , 0x003ffffe },
802+ normalized : [10 ]uint32 {0x03fff85e , 0x03ffffbf , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03fffffe , 0x003ffffe },
803+ }, {
804+ name : "Value <= P final reduction combination 1 via 2nd word" ,
805+ raw : [10 ]uint32 {0x03fff85e , 0x03ffffc0 , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03fffffe , 0x003ffffe },
806+ normalized : [10 ]uint32 {0x03fff85e , 0x03ffffc0 , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03fffffe , 0x003ffffe },
807+ }, {
808+ name : "Value <= P final reduction combination 1 via 1st word" ,
809+ raw : [10 ]uint32 {0x03fffc2f , 0x03ffffbf , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03fffffe , 0x003ffffe },
810+ normalized : [10 ]uint32 {0x03fffc2f , 0x03ffffbf , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03fffffe , 0x003ffffe },
811+ }, {
812+ name : "Value <= P final reduction combination 2" ,
813+ raw : [10 ]uint32 {0x03fff85e , 0x03ffffbf , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x003ffffe },
814+ normalized : [10 ]uint32 {0x03fff85e , 0x03ffffbf , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x003ffffe },
815+ }, {
816+ name : "Value <= P final reduction combination 3 via 2nd word" ,
817+ raw : [10 ]uint32 {0x03fff85e , 0x03ffffc0 , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x003ffffe },
818+ normalized : [10 ]uint32 {0x03fff85e , 0x03ffffc0 , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x003ffffe },
819+ }, {
820+ name : "Value <= P final reduction combination 3 via 1st word" ,
821+ raw : [10 ]uint32 {0x03fffc2f , 0x03ffffbf , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x003ffffe },
822+ normalized : [10 ]uint32 {0x03fffc2f , 0x03ffffbf , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x003ffffe },
823+ }, {
824+ name : "Value <= P final reduction combination 4" ,
825+ raw : [10 ]uint32 {0x03fff85e , 0x03ffffbf , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03fffffe , 0x003fffff },
826+ normalized : [10 ]uint32 {0x03fff85e , 0x03ffffbf , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03fffffe , 0x003fffff },
827+ }, {
828+ name : "Value <= P final reduction combination 5 via 2nd word" ,
829+ raw : [10 ]uint32 {0x03fff85e , 0x03ffffc0 , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03fffffe , 0x003fffff },
830+ normalized : [10 ]uint32 {0x03fff85e , 0x03ffffc0 , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03fffffe , 0x003fffff },
831+ }, {
832+ name : "Value <= P final reduction combination 5 via 1st word" ,
833+ raw : [10 ]uint32 {0x03fffc2f , 0x03ffffbf , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03fffffe , 0x003fffff },
834+ normalized : [10 ]uint32 {0x03fffc2f , 0x03ffffbf , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03fffffe , 0x003fffff },
835+ }, {
836+ name : "Value <= P final reduction combination 6" ,
837+ raw : [10 ]uint32 {0x03fff85e , 0x03ffffbf , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x003fffff },
838+ normalized : [10 ]uint32 {0x03fff85e , 0x03ffffbf , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x03ffffff , 0x003fffff },
772839 }}
773840
774841 for _ , test := range tests {
0 commit comments