|
58 | 58 | import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec;
|
59 | 59 | import org.bouncycastle.jce.spec.ECNamedCurveSpec;
|
60 | 60 |
|
| 61 | +import org.bouncycastle.math.ec.ECAlgorithms; |
| 62 | +import org.bouncycastle.math.ec.ECCurve; |
61 | 63 | import org.jruby.Ruby;
|
62 | 64 | import org.jruby.RubyArray;
|
63 | 65 | import org.jruby.RubyBoolean;
|
@@ -972,6 +974,7 @@ private boolean getPointAndGroup(ThreadContext context, IRubyObject groupOrPoint
|
972 | 974 |
|
973 | 975 | if ( groupOrPoint instanceof Group) {
|
974 | 976 | this.group = (Group) groupOrPoint;
|
| 977 | + this.point = (ECPoint) ((Group) groupOrPoint).generator(context); |
975 | 978 | } else {
|
976 | 979 | throw runtime.newTypeError(groupOrPoint, _EC(runtime).getClass("Group"));
|
977 | 980 | }
|
@@ -1068,6 +1071,53 @@ public IRubyObject inspect() {
|
1068 | 1071 | return ObjectSupport.inspect(this, (List) Collections.singletonList(entry));
|
1069 | 1072 | }
|
1070 | 1073 |
|
| 1074 | + @JRubyMethod(name = "mul", required = 1, optional = 2) |
| 1075 | + public IRubyObject mul(final ThreadContext context, final IRubyObject[] args) { |
| 1076 | + Ruby runtime = context.runtime; |
| 1077 | + |
| 1078 | + org.bouncycastle.math.ec.ECPoint pointSelf, pointResult; |
| 1079 | + |
| 1080 | + Group groupV = this.group; |
| 1081 | + |
| 1082 | + Point result; |
| 1083 | + |
| 1084 | + BigInteger bn_g = null; |
| 1085 | + |
| 1086 | + ECCurve selfCurve = EC5Util.convertCurve(group.getCurve()); |
| 1087 | + pointSelf = EC5Util.convertPoint(selfCurve, asECPoint()); |
| 1088 | + |
| 1089 | + result = new Point(runtime, getMetaClass()); |
| 1090 | + result.initialize(context, groupV); |
| 1091 | + ECCurve resultCurve = EC5Util.convertCurve(result.group.getCurve()); |
| 1092 | + pointResult = EC5Util.convertPoint(resultCurve, result.point); |
| 1093 | + |
| 1094 | + int argc = Arity.checkArgumentCount(runtime, args, 1, 3); |
| 1095 | + IRubyObject arg1 = args[0], arg2 = args[1], arg3 = args[2]; |
| 1096 | + if (!(arg1 instanceof RubyArray)) { |
| 1097 | + BigInteger bn = ((BN) arg1).getValue(); |
| 1098 | + |
| 1099 | + if (!arg2.isNil()) { |
| 1100 | + bn_g = ((BN) arg2).getValue(); |
| 1101 | + } |
| 1102 | + |
| 1103 | + if (bn_g == null) { |
| 1104 | + org.bouncycastle.math.ec.ECPoint mulPoint = ECAlgorithms.referenceMultiply(pointSelf, bn); |
| 1105 | + result = new Point(runtime, EC5Util.convertPoint(mulPoint), result.group); |
| 1106 | + } else { |
| 1107 | + org.bouncycastle.math.ec.ECPoint mulPoint = ECAlgorithms.sumOfTwoMultiplies(pointResult, bn_g, pointSelf, bn); |
| 1108 | + result = new Point(runtime, EC5Util.convertPoint(mulPoint), result.group); |
| 1109 | + } |
| 1110 | + |
| 1111 | + if (result == null) { |
| 1112 | + newECError(runtime, "bad multiply result"); |
| 1113 | + } |
| 1114 | + } else { |
| 1115 | + throw runtime.newNotImplementedError("calling #mul with arrays is not supported by this OpenSSL version"); |
| 1116 | + } |
| 1117 | + |
| 1118 | + return result; |
| 1119 | + } |
| 1120 | + |
1071 | 1121 | @Deprecated
|
1072 | 1122 | public IRubyObject initialize(final ThreadContext context, final IRubyObject[] args) {
|
1073 | 1123 | final int argc = Arity.checkArgumentCount(context.runtime, args, 1, 2);
|
|
0 commit comments