@@ -972,6 +972,7 @@ private boolean getPointAndGroup(ThreadContext context, IRubyObject groupOrPoint
972972
973973 if ( groupOrPoint instanceof Group ) {
974974 this .group = (Group ) groupOrPoint ;
975+ this .point = (ECPoint ) ((Group ) groupOrPoint ).generator (context );
975976 } else {
976977 throw runtime .newTypeError (groupOrPoint , _EC (runtime ).getClass ("Group" ));
977978 }
@@ -1068,6 +1069,53 @@ public IRubyObject inspect() {
10681069 return ObjectSupport .inspect (this , (List ) Collections .singletonList (entry ));
10691070 }
10701071
1072+ @ JRubyMethod (name = "mul" , required = 1 , optional = 2 )
1073+ public IRubyObject mul (final ThreadContext context , final IRubyObject [] args ) {
1074+ Ruby runtime = context .runtime ;
1075+
1076+ org .bouncycastle .math .ec .ECPoint pointSelf , pointResult ;
1077+
1078+ Group groupV = this .group ;
1079+
1080+ Point result ;
1081+
1082+ BigInteger bn_g = null ;
1083+
1084+ ECCurve selfCurve = EC5Util .convertCurve (group .getCurve ());
1085+ pointSelf = EC5Util .convertPoint (selfCurve , asECPoint ());
1086+
1087+ result = new Point (runtime , getMetaClass ());
1088+ result .initialize (context , groupV );
1089+ ECCurve resultCurve = EC5Util .convertCurve (result .group .getCurve ());
1090+ pointResult = EC5Util .convertPoint (resultCurve , result .point );
1091+
1092+ int argc = Arity .checkArgumentCount (runtime , args , 1 , 3 );
1093+ IRubyObject arg1 = args [0 ], arg2 = args [1 ], arg3 = args [2 ];
1094+ if (!(arg1 instanceof RubyArray )) {
1095+ BigInteger bn = ((BN ) arg1 ).getValue ();
1096+
1097+ if (!arg2 .isNil ()) {
1098+ bn_g = ((BN ) arg2 ).getValue ();
1099+ }
1100+
1101+ if (bn_g == null ) {
1102+ org .bouncycastle .math .ec .ECPoint mulPoint = ECAlgorithms .referenceMultiply (pointSelf , bn );
1103+ result = new Point (runtime , EC5Util .convertPoint (mulPoint ), result .group );
1104+ } else {
1105+ org .bouncycastle .math .ec .ECPoint mulPoint = ECAlgorithms .sumOfTwoMultiplies (pointResult , bn_g , pointSelf , bn );
1106+ result = new Point (runtime , EC5Util .convertPoint (mulPoint ), result .group );
1107+ }
1108+
1109+ if (result == null ) {
1110+ newECError (runtime , "bad multiply result" );
1111+ }
1112+ } else {
1113+ throw runtime .newNotImplementedError ("calling #mul with arrays is not supported by this OpenSSL version" );
1114+ }
1115+
1116+ return result ;
1117+ }
1118+
10711119 @ Deprecated
10721120 public IRubyObject initialize (final ThreadContext context , final IRubyObject [] args ) {
10731121 final int argc = Arity .checkArgumentCount (context .runtime , args , 1 , 2 );
0 commit comments